diff --git a/libavcodec/8svx.c b/libavcodec/8svx.c index 6ef8cd73fe..6ef7921274 100644 --- a/libavcodec/8svx.c +++ b/libavcodec/8svx.c @@ -88,38 +88,39 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data, { EightSvxContext *esc = avctx->priv_data; AVFrame *frame = data; + int channels = avctx->ch_layout.nb_channels; int buf_size; int ch, ret; int hdr_size = 2; /* decode and interleave the first packet */ if (!esc->data[0] && avpkt) { - int chan_size = avpkt->size / avctx->channels - hdr_size; + int chan_size = avpkt->size / channels - hdr_size; - if (avpkt->size % avctx->channels) { + if (avpkt->size % channels) { av_log(avctx, AV_LOG_WARNING, "Packet with odd size, ignoring last byte\n"); } - if (avpkt->size < (hdr_size + 1) * avctx->channels) { + if (avpkt->size < (hdr_size + 1) * channels) { av_log(avctx, AV_LOG_ERROR, "packet size is too small\n"); return AVERROR_INVALIDDATA; } esc->fib_acc[0] = avpkt->data[1] + 128; - if (avctx->channels == 2) + if (channels == 2) esc->fib_acc[1] = avpkt->data[2+chan_size+1] + 128; esc->data_idx = 0; esc->data_size = chan_size; if (!(esc->data[0] = av_malloc(chan_size))) return AVERROR(ENOMEM); - if (avctx->channels == 2) { + if (channels == 2) { if (!(esc->data[1] = av_malloc(chan_size))) { av_freep(&esc->data[0]); return AVERROR(ENOMEM); } } memcpy(esc->data[0], &avpkt->data[hdr_size], chan_size); - if (avctx->channels == 2) + if (channels == 2) memcpy(esc->data[1], &avpkt->data[2*hdr_size+chan_size], chan_size); } if (!esc->data[0]) { @@ -139,7 +140,7 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data, if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) return ret; - for (ch = 0; ch < avctx->channels; ch++) { + for (ch = 0; ch < channels; ch++) { delta_decode(frame->data[ch], &esc->data[ch][esc->data_idx], buf_size, &esc->fib_acc[ch], esc->table); } @@ -148,14 +149,14 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data, *got_frame_ptr = 1; - return ((avctx->frame_number == 0)*hdr_size + buf_size)*avctx->channels; + return ((avctx->frame_number == 0) * hdr_size + buf_size) * channels; } static av_cold int eightsvx_decode_init(AVCodecContext *avctx) { EightSvxContext *esc = avctx->priv_data; - if (avctx->channels < 1 || avctx->channels > 2) { + if (avctx->ch_layout.nb_channels < 1 || avctx->ch_layout.nb_channels > 2) { av_log(avctx, AV_LOG_ERROR, "8SVX does not support more than 2 channels\n"); return AVERROR_INVALIDDATA; }