Unified · Split
| @@ -38,7 +38,7 @@ void ff_adx_calculate_coeffs(int cutoff, int sample_rate, int bits, int *coeff) · 37 unmodified lines | |||
| 38 | int ff_adx_decode_header(AVCodecContext *avctx, const uint8_t *buf, | 38 | int ff_adx_decode_header(AVCodecContext *avctx, const uint8_t *buf, |
| 39 | int bufsize, int *header_size, int *coeff) | 39 | int bufsize, int *header_size, int *coeff) |
| 40 | { | 40 | { |
| 41 | int offset, cutoff; | 41 | int offset, cutoff, channels; |
| 42 | 42 | ||
| 43 | if (bufsize < 24) | 43 | if (bufsize < 24) |
| 44 | return AVERROR_INVALIDDATA; | 44 | return AVERROR_INVALIDDATA; |
| @@ -58,18 +58,24 @@ int ff_adx_decode_header(AVCodecContext *avctx, const uint8_t *buf, · 13 unmodified lines | |||
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | /* channels */ | 60 | /* channels */ |
| 61 | avctx->channels = buf[7]; | 61 | channels = buf[7]; |
| 62 | if (avctx->channels <= 0 || avctx->channels > 2) | 62 | if (channels <= 0 || channels > 2) |
| 63 | return AVERROR_INVALIDDATA; | 63 | return AVERROR_INVALIDDATA; |
| 64 | 64 | ||
| 65 | if (avctx->ch_layout.nb_channels != channels) { | ||
| 66 | av_channel_layout_uninit(&avctx->ch_layout); | ||
| 67 | avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; | ||
| 68 | avctx->ch_layout.nb_channels = channels; | ||
| 69 | } | ||
| 70 | |||
| 65 | /* sample rate */ | 71 | /* sample rate */ |
| 66 | avctx->sample_rate = AV_RB32(buf + 8); | 72 | avctx->sample_rate = AV_RB32(buf + 8); |
| 67 | if (avctx->sample_rate < 1 || | 73 | if (avctx->sample_rate < 1 || |
| 68 | avctx->sample_rate > INT_MAX / (avctx->channels * BLOCK_SIZE * 8)) | 74 | avctx->sample_rate > INT_MAX / (channels * BLOCK_SIZE * 8)) |
| 69 | return AVERROR_INVALIDDATA; | 75 | return AVERROR_INVALIDDATA; |
| 70 | 76 | ||
| 71 | /* bit rate */ | 77 | /* bit rate */ |
| 72 | avctx->bit_rate = avctx->sample_rate * avctx->channels * BLOCK_SIZE * 8 / BLOCK_SAMPLES; | 78 | avctx->bit_rate = avctx->sample_rate * channels * BLOCK_SIZE * 8 / BLOCK_SAMPLES; |
| 73 | 79 | ||
| 74 | /* LPC coefficients */ | 80 | /* LPC coefficients */ |
| 75 | if (coeff) { | 81 | if (coeff) { |
| @@ -46,7 +46,7 @@ static av_cold int adx_decode_init(AVCodecContext *avctx) · 45 unmodified lines | |||
| 46 | av_log(avctx, AV_LOG_ERROR, "error parsing ADX header\n"); | 46 | av_log(avctx, AV_LOG_ERROR, "error parsing ADX header\n"); |
| 47 | return AVERROR_INVALIDDATA; | 47 | return AVERROR_INVALIDDATA; |
| 48 | } | 48 | } |
| 49 | c->channels = avctx->channels; | 49 | c->channels = avctx->ch_layout.nb_channels; |
| 50 | c->header_parsed = 1; | 50 | c->header_parsed = 1; |
| 51 | } | 51 | } |
| 52 | 52 | ||
| @@ -132,7 +132,7 @@ static int adx_decode_frame(AVCodecContext *avctx, void *data, · 79 unmodified lines | |||
| 132 | av_log(avctx, AV_LOG_ERROR, "error parsing ADX header\n"); | 132 | av_log(avctx, AV_LOG_ERROR, "error parsing ADX header\n"); |
| 133 | return AVERROR_INVALIDDATA; | 133 | return AVERROR_INVALIDDATA; |
| 134 | } | 134 | } |
| 135 | c->channels = avctx->channels; | 135 | c->channels = avctx->ch_layout.nb_channels; |
| 136 | c->header_parsed = 1; | 136 | c->header_parsed = 1; |
| 137 | if (buf_size < header_size) | 137 | if (buf_size < header_size) |
| 138 | return AVERROR_INVALIDDATA; | 138 | return AVERROR_INVALIDDATA; |
| @@ -147,7 +147,7 @@ static int adx_decode_frame(AVCodecContext *avctx, void *data, · 8 unmodified lines | |||
| 147 | 147 | ||
| 148 | /* if the packet is not an even multiple of BLOCK_SIZE, check for an EOF | 148 | /* if the packet is not an even multiple of BLOCK_SIZE, check for an EOF |
| 149 | packet */ | 149 | packet */ |
| 150 | if (!num_blocks || buf_size % (BLOCK_SIZE * avctx->channels)) { | 150 | if (!num_blocks || buf_size % (BLOCK_SIZE * c->channels)) { |
| 151 | if (buf_size >= 4 && (AV_RB16(buf) & 0x8000)) { | 151 | if (buf_size >= 4 && (AV_RB16(buf) & 0x8000)) { |
| 152 | c->eof = 1; | 152 | c->eof = 1; |
| 153 | *got_frame_ptr = 0; | 153 | *got_frame_ptr = 0; |
| @@ -107,7 +107,7 @@ static int adx_encode_header(AVCodecContext *avctx, uint8_t *buf, int bufsize) · 106 unmodified lines | |||
| 107 | bytestream_put_byte(&buf, 3); /* encoding */ | 107 | bytestream_put_byte(&buf, 3); /* encoding */ |
| 108 | bytestream_put_byte(&buf, BLOCK_SIZE); /* block size */ | 108 | bytestream_put_byte(&buf, BLOCK_SIZE); /* block size */ |
| 109 | bytestream_put_byte(&buf, 4); /* sample size */ | 109 | bytestream_put_byte(&buf, 4); /* sample size */ |
| 110 | bytestream_put_byte(&buf, avctx->channels); /* channels */ | 110 | bytestream_put_byte(&buf, avctx->ch_layout.nb_channels); /* channels */ |
| 111 | bytestream_put_be32(&buf, avctx->sample_rate); /* sample rate */ | 111 | bytestream_put_be32(&buf, avctx->sample_rate); /* sample rate */ |
| 112 | bytestream_put_be32(&buf, 0); /* total sample count */ | 112 | bytestream_put_be32(&buf, 0); /* total sample count */ |
| 113 | bytestream_put_be16(&buf, c->cutoff); /* cutoff frequency */ | 113 | bytestream_put_be16(&buf, c->cutoff); /* cutoff frequency */ |
| @@ -125,7 +125,7 @@ static av_cold int adx_encode_init(AVCodecContext *avctx) · 11 unmodified lines | |||
| 125 | { | 125 | { |
| 126 | ADXContext *c = avctx->priv_data; | 126 | ADXContext *c = avctx->priv_data; |
| 127 | 127 | ||
| 128 | if (avctx->channels > 2) { | 128 | if (avctx->ch_layout.nb_channels > 2) { |
| 129 | av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n"); | 129 | av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n"); |
| 130 | return AVERROR(EINVAL); | 130 | return AVERROR(EINVAL); |
| 131 | } | 131 | } |
| @@ -144,6 +144,7 @@ static int adx_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 12 unmodified lines | |||
| 144 | ADXContext *c = avctx->priv_data; | 144 | ADXContext *c = avctx->priv_data; |
| 145 | const int16_t *samples = frame ? (const int16_t *)frame->data[0] : NULL; | 145 | const int16_t *samples = frame ? (const int16_t *)frame->data[0] : NULL; |
| 146 | uint8_t *dst; | 146 | uint8_t *dst; |
| 147 | int channels = avctx->ch_layout.nb_channels; | ||
| 147 | int ch, out_size, ret; | 148 | int ch, out_size, ret; |
| 148 | 149 | ||
| 149 | if (!samples) { | 150 | if (!samples) { |
| @@ -162,7 +163,7 @@ static int adx_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 12 unmodified lines | |||
| 162 | return 0; | 163 | return 0; |
| 163 | } | 164 | } |
| 164 | 165 | ||
| 165 | out_size = BLOCK_SIZE * avctx->channels + !c->header_parsed * HEADER_SIZE; | 166 | out_size = BLOCK_SIZE * channels + !c->header_parsed * HEADER_SIZE; |
| 166 | if ((ret = ff_get_encode_buffer(avctx, avpkt, out_size, 0)) < 0) | 167 | if ((ret = ff_get_encode_buffer(avctx, avpkt, out_size, 0)) < 0) |
| 167 | return ret; | 168 | return ret; |
| 168 | dst = avpkt->data; | 169 | dst = avpkt->data; |
| @@ -177,8 +178,8 @@ static int adx_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 8 unmodified lines | |||
| 177 | c->header_parsed = 1; | 178 | c->header_parsed = 1; |
| 178 | } | 179 | } |
| 179 | 180 | ||
| 180 | for (ch = 0; ch < avctx->channels; ch++) { | 181 | for (ch = 0; ch < channels; ch++) { |
| 181 | adx_encode(c, dst, samples + ch, &c->prev[ch], avctx->channels); | 182 | adx_encode(c, dst, samples + ch, &c->prev[ch], channels); |
| 182 | dst += BLOCK_SIZE; | 183 | dst += BLOCK_SIZE; |
| 183 | } | 184 | } |
| 184 | 185 | ||