History

adpcm: convert to new channel layout API

Anton Khirnov committed 13 years ago

Commit 984612a1 parent 111ed1b2 files · +141 −132Browse files

Unified · Split

2 files
  1. libavcodec/adpcm.c +78 −73
  2. libavcodec/adpcmenc.c +63 −59
libavcodec/adpcm.c+78−73
@@ -271,14 +271,15 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx) · 270 unmodified lines
271271 case AV_CODEC_ID_ADPCM_MTAF:
272272 min_channels = 2;
273273 max_channels = 8;
274− if (avctx->channels & 1) {
275− avpriv_request_sample(avctx, "channel count %d", avctx->channels);
274+ if (avctx->ch_layout.nb_channels & 1) {
275+ avpriv_request_sample(avctx, "channel count %d", avctx->ch_layout.nb_channels);
276276 return AVERROR_PATCHWELCOME;
277277 }
278278 break;
279279 case AV_CODEC_ID_ADPCM_PSX:
280280 max_channels = 8;
281− if (avctx->channels <= 0 || avctx->block_align % (16 * avctx->channels))
281+ if (avctx->ch_layout.nb_channels <= 0 ||
282+ avctx->block_align % (16 * avctx->ch_layout.nb_channels))
282283 return AVERROR_INVALIDDATA;
283284 break;
284285 case AV_CODEC_ID_ADPCM_IMA_DAT4:
@@ -287,7 +288,8 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx) · 2 unmodified lines
287288 max_channels = 14;
288289 break;
289290 }
290− if (avctx->channels < min_channels || avctx->channels > max_channels) {
291+ if (avctx->ch_layout.nb_channels < min_channels ||
292+ avctx->ch_layout.nb_channels > max_channels) {
291293 av_log(avctx, AV_LOG_ERROR, "Invalid number of channels\n");
292294 return AVERROR(EINVAL);
293295 }
@@ -298,7 +300,8 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx) · 4 unmodified lines
298300 return AVERROR_INVALIDDATA;
299301 break;
300302 case AV_CODEC_ID_ADPCM_ARGO:
301− if (avctx->bits_per_coded_sample != 4 || avctx->block_align != 17 * avctx->channels)
303+ if (avctx->bits_per_coded_sample != 4 ||
304+ avctx->block_align != 17 * avctx->ch_layout.nb_channels)
302305 return AVERROR_INVALIDDATA;
303306 break;
304307 case AV_CODEC_ID_ADPCM_ZORK:
@@ -336,7 +339,7 @@ static av_cold int adpcm_decode_init(AVCodecContext * avctx) · 31 unmodified lines
336339 AV_SAMPLE_FMT_S16;
337340 break;
338341 case AV_CODEC_ID_ADPCM_MS:
339− avctx->sample_fmt = avctx->channels > 2 ? AV_SAMPLE_FMT_S16P :
342+ avctx->sample_fmt = avctx->ch_layout.nb_channels > 2 ? AV_SAMPLE_FMT_S16P :
340343 AV_SAMPLE_FMT_S16;
341344 break;
342345 default:
@@ -755,6 +758,7 @@ static void adpcm_swf_decode(AVCodecContext *avctx, const uint8_t *buf, int buf_ · 412 unmodified lines
755758 ADPCMDecodeContext *c = avctx->priv_data;
756759 GetBitContext gb;
757760 const int8_t *table;
761+ int channels = avctx->ch_layout.nb_channels;
758762 int k0, signmask, nb_bits, count;
759763 int size = buf_size*8;
760764 int i;
@@ -767,16 +771,16 @@ static void adpcm_swf_decode(AVCodecContext *avctx, const uint8_t *buf, int buf_ · 6 unmodified lines
767771 k0 = 1 << (nb_bits-2);
768772 signmask = 1 << (nb_bits-1);
769773
770− while (get_bits_count(&gb) <= size - 22*avctx->channels) {
771− for (i = 0; i < avctx->channels; i++) {
774+ while (get_bits_count(&gb) <= size - 22 * channels) {
775+ for (i = 0; i < channels; i++) {
772776 *samples++ = c->status[i].predictor = get_sbits(&gb, 16);
773777 c->status[i].step_index = get_bits(&gb, 6);
774778 }
775779
776− for (count = 0; get_bits_count(&gb) <= size - nb_bits*avctx->channels && count < 4095; count++) {
780+ for (count = 0; get_bits_count(&gb) <= size - nb_bits * channels && count < 4095; count++) {
777781 int i;
778782
779− for (i = 0; i < avctx->channels; i++) {
783+ for (i = 0; i < channels; i++) {
780784 // similar to IMA adpcm
781785 int delta = get_bits(&gb, nb_bits);
782786 int step = ff_adpcm_step_table[c->status[i].step_index];
@@ -840,7 +844,7 @@ static int get_nb_samples(AVCodecContext *avctx, GetByteContext *gb, · 57 unmodified lines
840844 {
841845 ADPCMDecodeContext *s = avctx->priv_data;
842846 int nb_samples = 0;
843− int ch = avctx->channels;
847+ int ch = avctx->ch_layout.nb_channels;
844848 int has_coded_samples = 0;
845849 int header_size;
846850
@@ -1061,6 +1065,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 214 unmodified lines
10611065 const uint8_t *buf = avpkt->data;
10621066 int buf_size = avpkt->size;
10631067 ADPCMDecodeContext *c = avctx->priv_data;
1068+ int channels = avctx->ch_layout.nb_channels;
10641069 int16_t *samples;
10651070 int16_t **samples_p;
10661071 int st; /* stereo */
@@ -1089,13 +1094,13 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 22 unmodified lines
10891094 frame->nb_samples = nb_samples = coded_samples;
10901095 }
10911096
1092− st = avctx->channels == 2 ? 1 : 0;
1097+ st = channels == 2 ? 1 : 0;
10931098
10941099 switch(avctx->codec->id) {
10951100 CASE(ADPCM_IMA_QT,
10961101 /* In QuickTime, IMA is encoded by chunks of 34 bytes (=64 samples).
10971102 Channel data is interleaved per-chunk. */
1098− for (int channel = 0; channel < avctx->channels; channel++) {
1103+ for (int channel = 0; channel < channels; channel++) {
10991104 ADPCMChannelStatus *cs = &c->status[channel];
11001105 int predictor;
11011106 int step_index;
@@ -1134,7 +1139,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 32 unmodified lines
11341139 }
11351140 ) /* End of CASE */
11361141 CASE(ADPCM_IMA_WAV,
1137− for (int i = 0; i < avctx->channels; i++) {
1142+ for (int i = 0; i < channels; i++) {
11381143 ADPCMChannelStatus *cs = &c->status[i];
11391144 cs->predictor = samples_p[i][0] = sign_extend(bytestream2_get_le16u(&gb), 16);
11401145
@@ -1153,12 +1158,12 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 12 unmodified lines
11531158 GetBitContext g;
11541159
11551160 for (int n = 0; n < (nb_samples - 1) / samples_per_block; n++) {
1156− for (int i = 0; i < avctx->channels; i++) {
1161+ for (int i = 0; i < channels; i++) {
11571162 ADPCMChannelStatus *cs = &c->status[i];
11581163 samples = &samples_p[i][1 + n * samples_per_block];
11591164 for (int j = 0; j < block_size; j++) {
1160− temp[j] = buf[4 * avctx->channels + block_size * n * avctx->channels +
1161− (j % 4) + (j / 4) * (avctx->channels * 4) + i * 4];
1165+ temp[j] = buf[4 * channels + block_size * n * channels +
1166+ (j % 4) + (j / 4) * (channels * 4) + i * 4];
11621167 }
11631168 ret = init_get_bits8(&g, (const uint8_t *)&temp, block_size);
11641169 if (ret < 0)
@@ -1169,10 +1174,10 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 4 unmodified lines
11691174 }
11701175 }
11711176 }
1172− bytestream2_skip(&gb, avctx->block_align - avctx->channels * 4);
1177+ bytestream2_skip(&gb, avctx->block_align - channels * 4);
11731178 } else {
11741179 for (int n = 0; n < (nb_samples - 1) / 8; n++) {
1175− for (int i = 0; i < avctx->channels; i++) {
1180+ for (int i = 0; i < channels; i++) {
11761181 ADPCMChannelStatus *cs = &c->status[i];
11771182 samples = &samples_p[i][1 + n * 8];
11781183 for (int m = 0; m < 8; m += 2) {
@@ -1185,10 +1190,10 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 6 unmodified lines
11851190 }
11861191 ) /* End of CASE */
11871192 CASE(ADPCM_4XM,
1188− for (int i = 0; i < avctx->channels; i++)
1193+ for (int i = 0; i < channels; i++)
11891194 c->status[i].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
11901195
1191− for (int i = 0; i < avctx->channels; i++) {
1196+ for (int i = 0; i < channels; i++) {
11921197 c->status[i].step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
11931198 if (c->status[i].step_index > 88u) {
11941199 av_log(avctx, AV_LOG_ERROR, "ERROR: step_index[%d] = %i\n",
@@ -1197,7 +1202,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 2 unmodified lines
11971202 }
11981203 }
11991204
1200− for (int i = 0; i < avctx->channels; i++) {
1205+ for (int i = 0; i < channels; i++) {
12011206 ADPCMChannelStatus *cs = &c->status[i];
12021207 samples = (int16_t *)frame->data[i];
12031208 for (int n = nb_samples >> 1; n > 0; n--) {
@@ -1208,9 +1213,9 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 4 unmodified lines
12081213 }
12091214 ) /* End of CASE */
12101215 CASE(ADPCM_AGM,
1211− for (int i = 0; i < avctx->channels; i++)
1216+ for (int i = 0; i < channels; i++)
12121217 c->status[i].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
1213− for (int i = 0; i < avctx->channels; i++)
1218+ for (int i = 0; i < channels; i++)
12141219 c->status[i].step = sign_extend(bytestream2_get_le16u(&gb), 16);
12151220
12161221 for (int n = 0; n < nb_samples >> (1 - st); n++) {
@@ -1222,8 +1227,8 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 5 unmodified lines
12221227 CASE(ADPCM_MS,
12231228 int block_predictor;
12241229
1225− if (avctx->channels > 2) {
1226− for (int channel = 0; channel < avctx->channels; channel++) {
1230+ if (avctx->ch_layout.nb_channels > 2) {
1231+ for (int channel = 0; channel < avctx->ch_layout.nb_channels; channel++) {
12271232 samples = samples_p[channel];
12281233 block_predictor = bytestream2_get_byteu(&gb);
12291234 if (block_predictor > 6) {
@@ -1285,7 +1290,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 55 unmodified lines
12851290 }
12861291 ) /* End of CASE */
12871292 CASE(ADPCM_MTAF,
1288− for (int channel = 0; channel < avctx->channels; channel += 2) {
1293+ for (int channel = 0; channel < channels; channel += 2) {
12891294 bytestream2_skipu(&gb, 4);
12901295 c->status[channel ].step = bytestream2_get_le16u(&gb) & 0x1f;
12911296 c->status[channel + 1].step = bytestream2_get_le16u(&gb) & 0x1f;
@@ -1306,7 +1311,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 14 unmodified lines
13061311 }
13071312 ) /* End of CASE */
13081313 CASE(ADPCM_IMA_DK4,
1309− for (int channel = 0; channel < avctx->channels; channel++) {
1314+ for (int channel = 0; channel < channels; channel++) {
13101315 ADPCMChannelStatus *cs = &c->status[channel];
13111316 cs->predictor = *samples++ = sign_extend(bytestream2_get_le16u(&gb), 16);
13121317 cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
@@ -1338,7 +1343,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 25 unmodified lines
13381343 int nibble;
13391344 int decode_top_nibble_next = 0;
13401345 int diff_channel;
1341− const int16_t *samples_end = samples + avctx->channels * nb_samples;
1346+ const int16_t *samples_end = samples + channels * nb_samples;
13421347
13431348 bytestream2_skipu(&gb, 10);
13441349 c->status[0].predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
@@ -1385,7 +1390,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 40 unmodified lines
13851390 bytestream2_skip(&gb, 1);
13861391 ) /* End of CASE */
13871392 CASE(ADPCM_IMA_ISS,
1388− for (int channel = 0; channel < avctx->channels; channel++) {
1393+ for (int channel = 0; channel < channels; channel++) {
13891394 ADPCMChannelStatus *cs = &c->status[channel];
13901395 cs->predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
13911396 cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
@@ -1412,7 +1417,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 20 unmodified lines
14121417 }
14131418 ) /* End of CASE */
14141419 CASE(ADPCM_IMA_MOFLEX,
1415− for (int channel = 0; channel < avctx->channels; channel++) {
1420+ for (int channel = 0; channel < channels; channel++) {
14161421 ADPCMChannelStatus *cs = &c->status[channel];
14171422 cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
14181423 cs->predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
@@ -1424,7 +1429,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 5 unmodified lines
14241429 }
14251430
14261431 for (int subframe = 0; subframe < nb_samples / 256; subframe++) {
1427− for (int channel = 0; channel < avctx->channels; channel++) {
1432+ for (int channel = 0; channel < channels; channel++) {
14281433 samples = samples_p[channel] + 256 * subframe;
14291434 for (int n = 0; n < 256; n += 2) {
14301435 int v = bytestream2_get_byteu(&gb);
@@ -1435,7 +1440,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 4 unmodified lines
14351440 }
14361441 ) /* End of CASE */
14371442 CASE(ADPCM_IMA_DAT4,
1438− for (int channel = 0; channel < avctx->channels; channel++) {
1443+ for (int channel = 0; channel < channels; channel++) {
14391444 ADPCMChannelStatus *cs = &c->status[channel];
14401445 samples = samples_p[channel];
14411446 bytestream2_skip(&gb, 4);
@@ -1462,26 +1467,26 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 20 unmodified lines
14621467 ) /* End of CASE */
14631468 CASE(ADPCM_IMA_APM,
14641469 for (int n = nb_samples / 2; n > 0; n--) {
1465− for (int channel = 0; channel < avctx->channels; channel++) {
1470+ for (int channel = 0; channel < channels; channel++) {
14661471 int v = bytestream2_get_byteu(&gb);
14671472 *samples++ = adpcm_ima_qt_expand_nibble(&c->status[channel], v >> 4 );
14681473 samples[st] = adpcm_ima_qt_expand_nibble(&c->status[channel], v & 0x0F);
14691474 }
1470− samples += avctx->channels;
1475+ samples += channels;
14711476 }
14721477 ) /* End of CASE */
14731478 CASE(ADPCM_IMA_ALP,
14741479 for (int n = nb_samples / 2; n > 0; n--) {
1475− for (int channel = 0; channel < avctx->channels; channel++) {
1480+ for (int channel = 0; channel < channels; channel++) {
14761481 int v = bytestream2_get_byteu(&gb);
14771482 *samples++ = adpcm_ima_alp_expand_nibble(&c->status[channel], v >> 4 , 2);
14781483 samples[st] = adpcm_ima_alp_expand_nibble(&c->status[channel], v & 0x0F, 2);
14791484 }
1480− samples += avctx->channels;
1485+ samples += channels;
14811486 }
14821487 ) /* End of CASE */
14831488 CASE(ADPCM_IMA_CUNNING,
1484− for (int channel = 0; channel < avctx->channels; channel++) {
1489+ for (int channel = 0; channel < channels; channel++) {
14851490 int16_t *smp = samples_p[channel];
14861491 for (int n = 0; n < nb_samples / 2; n++) {
14871492 int v = bytestream2_get_byteu(&gb);
@@ -1498,7 +1503,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 10 unmodified lines
14981503 }
14991504 ) /* End of CASE */
15001505 CASE(ADPCM_IMA_RAD,
1501− for (int channel = 0; channel < avctx->channels; channel++) {
1506+ for (int channel = 0; channel < channels; channel++) {
15021507 ADPCMChannelStatus *cs = &c->status[channel];
15031508 cs->step_index = sign_extend(bytestream2_get_le16u(&gb), 16);
15041509 cs->predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
@@ -1514,17 +1519,17 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 9 unmodified lines
15141519 byte[0] = bytestream2_get_byteu(&gb);
15151520 if (st)
15161521 byte[1] = bytestream2_get_byteu(&gb);
1517− for (int channel = 0; channel < avctx->channels; channel++) {
1522+ for (int channel = 0; channel < channels; channel++) {
15181523 *samples++ = adpcm_ima_expand_nibble(&c->status[channel], byte[channel] & 0x0F, 3);
15191524 }
1520− for (int channel = 0; channel < avctx->channels; channel++) {
1525+ for (int channel = 0; channel < channels; channel++) {
15211526 *samples++ = adpcm_ima_expand_nibble(&c->status[channel], byte[channel] >> 4 , 3);
15221527 }
15231528 }
15241529 ) /* End of CASE */
15251530 CASE(ADPCM_IMA_WS,
15261531 if (c->vqa_version == 3) {
1527− for (int channel = 0; channel < avctx->channels; channel++) {
1532+ for (int channel = 0; channel < channels; channel++) {
15281533 int16_t *smp = samples_p[channel];
15291534
15301535 for (int n = nb_samples / 2; n > 0; n--) {
@@ -1535,12 +1540,12 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 4 unmodified lines
15351540 }
15361541 } else {
15371542 for (int n = nb_samples / 2; n > 0; n--) {
1538− for (int channel = 0; channel < avctx->channels; channel++) {
1543+ for (int channel = 0; channel < channels; channel++) {
15391544 int v = bytestream2_get_byteu(&gb);
15401545 *samples++ = adpcm_ima_expand_nibble(&c->status[channel], v & 0x0F, 3);
15411546 samples[st] = adpcm_ima_expand_nibble(&c->status[channel], v >> 4 , 3);
15421547 }
1543− samples += avctx->channels;
1548+ samples += channels;
15441549 }
15451550 }
15461551 bytestream2_seek(&gb, 0, SEEK_END);
@@ -1548,13 +1553,13 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 1 unmodified line
15481553 CASE(ADPCM_XA,
15491554 int16_t *out0 = samples_p[0];
15501555 int16_t *out1 = samples_p[1];
1551− int samples_per_block = 28 * (3 - avctx->channels) * 4;
1556+ int samples_per_block = 28 * (3 - channels) * 4;
15521557 int sample_offset = 0;
15531558 int bytes_remaining;
15541559 while (bytestream2_get_bytes_left(&gb) >= 128) {
15551560 if ((ret = xa_decode(avctx, out0, out1, buf + bytestream2_tell(&gb),
15561561 &c->status[0], &c->status[1],
1557− avctx->channels, sample_offset)) < 0)
1562+ channels, sample_offset)) < 0)
15581563 return ret;
15591564 bytestream2_skipu(&gb, 128);
15601565 sample_offset += samples_per_block;
@@ -1604,7 +1609,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 43 unmodified lines
16041609 /* Each EA ADPCM frame has a 12-byte header followed by 30-byte pieces,
16051610 each coding 28 stereo samples. */
16061611
1607− if(avctx->channels != 2)
1612+ if (channels != 2)
16081613 return AVERROR_INVALIDDATA;
16091614
16101615 current_left_sample = sign_extend(bytestream2_get_le16u(&gb), 16);
@@ -1649,7 +1654,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 38 unmodified lines
16491654 CASE(ADPCM_EA_MAXIS_XA,
16501655 int coeff[2][2], shift[2];
16511656
1652− for (int channel = 0; channel < avctx->channels; channel++) {
1657+ for (int channel = 0; channel < channels; channel++) {
16531658 int byte = bytestream2_get_byteu(&gb);
16541659 for (int i = 0; i < 2; i++)
16551660 coeff[channel][i] = ea_adpcm_table[(byte >> 4) + 4*i];
@@ -1661,7 +1666,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 5 unmodified lines
16611666 byte[0] = bytestream2_get_byteu(&gb);
16621667 if (st) byte[1] = bytestream2_get_byteu(&gb);
16631668 for (int i = 4; i >= 0; i-=4) { /* Pairwise samples LL RR (st) or LL LL (mono) */
1664− for (int channel = 0; channel < avctx->channels; channel++) {
1669+ for (int channel = 0; channel < channels; channel++) {
16651670 int sample = sign_extend(byte[channel] >> i, 4) * (1 << shift[channel]);
16661671 sample = (sample +
16671672 c->status[channel].sample1 * coeff[channel][0] +
@@ -1690,12 +1695,12 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 22 unmodified lines
16901695 int count = 0;
16911696 int offsets[6];
16921697
1693− for (unsigned channel = 0; channel < avctx->channels; channel++)
1698+ for (unsigned channel = 0; channel < channels; channel++)
16941699 offsets[channel] = (big_endian ? bytestream2_get_be32(&gb) :
16951700 bytestream2_get_le32(&gb)) +
1696− (avctx->channels + 1) * 4;
1701+ (channels + 1) * 4;
16971702
1698− for (unsigned channel = 0; channel < avctx->channels; channel++) {
1703+ for (unsigned channel = 0; channel < channels; channel++) {
16991704 int count1;
17001705
17011706 bytestream2_seek(&gb, offsets[channel], SEEK_SET);
@@ -1759,7 +1764,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 57 unmodified lines
17591764 }
17601765 #endif /* CONFIG_ADPCM_EA_Rx_DECODER */
17611766 CASE(ADPCM_EA_XAS,
1762− for (int channel=0; channel < avctx->channels; channel++) {
1767+ for (int channel=0; channel < channels; channel++) {
17631768 int coeff[2][4], shift[4];
17641769 int16_t *s = samples_p[channel];
17651770 for (int n = 0; n < 4; n++, s += 32) {
@@ -1791,7 +1796,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 25 unmodified lines
17911796 }
17921797 ) /* End of CASE */
17931798 CASE(ADPCM_IMA_ACORN,
1794− for (int channel = 0; channel < avctx->channels; channel++) {
1799+ for (int channel = 0; channel < channels; channel++) {
17951800 ADPCMChannelStatus *cs = &c->status[channel];
17961801 cs->predictor = sign_extend(bytestream2_get_le16u(&gb), 16);
17971802 cs->step_index = bytestream2_get_le16u(&gb) & 0xFF;
@@ -1808,7 +1813,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 10 unmodified lines
18081813 }
18091814 ) /* End of CASE */
18101815 CASE(ADPCM_IMA_AMV,
1811− av_assert0(avctx->channels == 1);
1816+ av_assert0(channels == 1);
18121817
18131818 /*
18141819 * Header format:
@@ -1848,7 +1853,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 33 unmodified lines
18481853 }
18491854 ) /* End of CASE */
18501855 CASE(ADPCM_IMA_SMJPEG,
1851− for (int i = 0; i < avctx->channels; i++) {
1856+ for (int i = 0; i < channels; i++) {
18521857 c->status[i].predictor = sign_extend(bytestream2_get_be16u(&gb), 16);
18531858 c->status[i].step_index = bytestream2_get_byteu(&gb);
18541859 bytestream2_skipu(&gb, 1);
@@ -1931,7 +1936,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 76 unmodified lines
19311936 }
19321937 ) /* End of CASE */
19331938 CASE(ADPCM_AICA,
1934− for (int channel = 0; channel < avctx->channels; channel++) {
1939+ for (int channel = 0; channel < channels; channel++) {
19351940 samples = samples_p[channel];
19361941 for (int n = nb_samples >> 1; n > 0; n--) {
19371942 int v = bytestream2_get_byteu(&gb);
@@ -1953,7 +1958,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 15 unmodified lines
19531958 }
19541959
19551960 for (int m = 0; m < blocks; m++) {
1956− for (int channel = 0; channel < avctx->channels; channel++) {
1961+ for (int channel = 0; channel < channels; channel++) {
19571962 int prev1 = c->status[channel].sample1;
19581963 int prev2 = c->status[channel].sample2;
19591964
@@ -2005,33 +2010,33 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 45 unmodified lines
20052010
20062011 if (avctx->extradata) {
20072012 GetByteContext tb;
2008− if (avctx->extradata_size < 32 * avctx->channels) {
2013+ if (avctx->extradata_size < 32 * channels) {
20092014 av_log(avctx, AV_LOG_ERROR, "Missing coeff table\n");
20102015 return AVERROR_INVALIDDATA;
20112016 }
20122017
20132018 bytestream2_init(&tb, avctx->extradata, avctx->extradata_size);
2014− for (int i = 0; i < avctx->channels; i++)
2019+ for (int i = 0; i < channels; i++)
20152020 for (int n = 0; n < 16; n++)
20162021 table[i][n] = THP_GET16(tb);
20172022 } else {
2018− for (int i = 0; i < avctx->channels; i++)
2023+ for (int i = 0; i < channels; i++)
20192024 for (int n = 0; n < 16; n++)
20202025 table[i][n] = THP_GET16(gb);
20212026
20222027 if (!c->has_status) {
20232028 /* Initialize the previous sample. */
2024− for (int i = 0; i < avctx->channels; i++) {
2029+ for (int i = 0; i < channels; i++) {
20252030 c->status[i].sample1 = THP_GET16(gb);
20262031 c->status[i].sample2 = THP_GET16(gb);
20272032 }
20282033 c->has_status = 1;
20292034 } else {
2030− bytestream2_skip(&gb, avctx->channels * 4);
2035+ bytestream2_skip(&gb, channels * 4);
20312036 }
20322037 }
20332038
2034− for (int ch = 0; ch < avctx->channels; ch++) {
2039+ for (int ch = 0; ch < channels; ch++) {
20352040 samples = samples_p[ch];
20362041
20372042 /* Read in every sample for this channel. */
@@ -2065,7 +2070,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 27 unmodified lines
20652070 }
20662071 #endif /* CONFIG_ADPCM_THP(_LE)_DECODER */
20672072 CASE(ADPCM_DTK,
2068− for (int channel = 0; channel < avctx->channels; channel++) {
2073+ for (int channel = 0; channel < channels; channel++) {
20692074 samples = samples_p[channel];
20702075
20712076 /* Read in every sample for this channel. */
@@ -2113,9 +2118,9 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 41 unmodified lines
21132118 }
21142119 ) /* End of CASE */
21152120 CASE(ADPCM_PSX,
2116− for (int block = 0; block < avpkt->size / FFMAX(avctx->block_align, 16 * avctx->channels); block++) {
2117− int nb_samples_per_block = 28 * FFMAX(avctx->block_align, 16 * avctx->channels) / (16 * avctx->channels);
2118− for (int channel = 0; channel < avctx->channels; channel++) {
2121+ for (int block = 0; block < avpkt->size / FFMAX(avctx->block_align, 16 * channels); block++) {
2122+ int nb_samples_per_block = 28 * FFMAX(avctx->block_align, 16 * channels) / (16 * channels);
2123+ for (int channel = 0; channel < channels; channel++) {
21192124 samples = samples_p[channel] + block * nb_samples_per_block;
21202125 av_assert0((block + 1) * nb_samples_per_block <= nb_samples);
21212126
@@ -2172,7 +2177,7 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 50 unmodified lines
21722177 * They should be 0 initially.
21732178 */
21742179 for (int block = 0; block < avpkt->size / avctx->block_align; block++) {
2175− for (int channel = 0; channel < avctx->channels; channel++) {
2180+ for (int channel = 0; channel < avctx->ch_layout.nb_channels; channel++) {
21762181 ADPCMChannelStatus *cs = c->status + channel;
21772182 int control, shift;
21782183
@@ -2191,19 +2196,19 @@ static int adpcm_decode_frame(AVCodecContext *avctx, void *data, · 12 unmodified lines
21912196 }
21922197 ) /* End of CASE */
21932198 CASE(ADPCM_ZORK,
2194− for (int n = 0; n < nb_samples * avctx->channels; n++) {
2199+ for (int n = 0; n < nb_samples * channels; n++) {
21952200 int v = bytestream2_get_byteu(&gb);
2196− *samples++ = adpcm_zork_expand_nibble(&c->status[n % avctx->channels], v);
2201+ *samples++ = adpcm_zork_expand_nibble(&c->status[n % channels], v);
21972202 }
21982203 ) /* End of CASE */
21992204 CASE(ADPCM_IMA_MTF,
22002205 for (int n = nb_samples / 2; n > 0; n--) {
2201− for (int channel = 0; channel < avctx->channels; channel++) {
2206+ for (int channel = 0; channel < channels; channel++) {
22022207 int v = bytestream2_get_byteu(&gb);
22032208 *samples++ = adpcm_ima_mtf_expand_nibble(&c->status[channel], v >> 4);
22042209 samples[st] = adpcm_ima_mtf_expand_nibble(&c->status[channel], v & 0x0F);
22052210 }
2206− samples += avctx->channels;
2211+ samples += channels;
22072212 }
22082213 ) /* End of CASE */
22092214 default:
libavcodec/adpcmenc.c+63−59
@@ -79,11 +79,7 @@ typedef struct ADPCMEncodeContext { · 78 unmodified lines
7979 static av_cold int adpcm_encode_init(AVCodecContext *avctx)
8080 {
8181 ADPCMEncodeContext *s = avctx->priv_data;
82−
83− if (avctx->channels > 2) {
84− av_log(avctx, AV_LOG_ERROR, "only stereo or mono is supported\n");
85− return AVERROR(EINVAL);
86− }
82+ int channels = avctx->ch_layout.nb_channels;
8783
8884 /*
8985 * AMV's block size has to match that of the corresponding video
@@ -130,8 +126,8 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) · 40 unmodified lines
130126 CASE(ADPCM_IMA_WAV,
131127 /* each 16 bits sample gives one nibble
132128 and we have 4 bytes per channel overhead */
133− avctx->frame_size = (s->block_size - 4 * avctx->channels) * 8 /
134− (4 * avctx->channels) + 1;
129+ avctx->frame_size = (s->block_size - 4 * channels) * 8 /
130+ (4 * channels) + 1;
135131 /* seems frame_size isn't taken into account...
136132 have to buffer the samples :-( */
137133 avctx->block_align = s->block_size;
@@ -139,13 +135,13 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) · 1 unmodified line
139135 ) /* End of CASE */
140136 CASE(ADPCM_IMA_QT,
141137 avctx->frame_size = 64;
142− avctx->block_align = 34 * avctx->channels;
138+ avctx->block_align = 34 * channels;
143139 ) /* End of CASE */
144140 CASE(ADPCM_MS,
145141 uint8_t *extradata;
146142 /* each 16 bits sample gives one nibble
147143 and we have 7 bytes per channel overhead */
148− avctx->frame_size = (s->block_size - 7 * avctx->channels) * 2 / avctx->channels + 2;
144+ avctx->frame_size = (s->block_size - 7 * channels) * 2 / channels + 2;
149145 avctx->bits_per_coded_sample = 4;
150146 avctx->block_align = s->block_size;
151147 if (!(avctx->extradata = av_malloc(32 + AV_INPUT_BUFFER_PADDING_SIZE)))
@@ -160,7 +156,7 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) · 8 unmodified lines
160156 }
161157 ) /* End of CASE */
162158 CASE(ADPCM_YAMAHA,
163− avctx->frame_size = s->block_size * 2 / avctx->channels;
159+ avctx->frame_size = s->block_size * 2 / channels;
164160 avctx->block_align = s->block_size;
165161 ) /* End of CASE */
166162 CASE(ADPCM_SWF,
@@ -172,11 +168,11 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) · 5 unmodified lines
172168 return AVERROR(EINVAL);
173169 }
174170 avctx->frame_size = 4096; /* Hardcoded according to the SWF spec. */
175− avctx->block_align = (2 + avctx->channels * (22 + 4 * (avctx->frame_size - 1)) + 7) / 8;
171+ avctx->block_align = (2 + channels * (22 + 4 * (avctx->frame_size - 1)) + 7) / 8;
176172 ) /* End of CASE */
177173 case AV_CODEC_ID_ADPCM_IMA_SSI:
178174 case AV_CODEC_ID_ADPCM_IMA_ALP:
179− avctx->frame_size = s->block_size * 2 / avctx->channels;
175+ avctx->frame_size = s->block_size * 2 / channels;
180176 avctx->block_align = s->block_size;
181177 break;
182178 CASE(ADPCM_IMA_AMV,
@@ -185,7 +181,7 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) · 2 unmodified lines
185181 return AVERROR(EINVAL);
186182 }
187183
188− if (avctx->channels != 1) {
184+ if (channels != 1) {
189185 av_log(avctx, AV_LOG_ERROR, "Only mono is supported\n");
190186 return AVERROR(EINVAL);
191187 }
@@ -194,7 +190,7 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) · 2 unmodified lines
194190 avctx->block_align = 8 + (FFALIGN(avctx->frame_size, 2) / 2);
195191 ) /* End of CASE */
196192 CASE(ADPCM_IMA_APM,
197− avctx->frame_size = s->block_size * 2 / avctx->channels;
193+ avctx->frame_size = s->block_size * 2 / channels;
198194 avctx->block_align = s->block_size;
199195
200196 if (!(avctx->extradata = av_mallocz(28 + AV_INPUT_BUFFER_PADDING_SIZE)))
@@ -203,11 +199,11 @@ static av_cold int adpcm_encode_init(AVCodecContext *avctx) · 2 unmodified lines
203199 ) /* End of CASE */
204200 CASE(ADPCM_ARGO,
205201 avctx->frame_size = 32;
206− avctx->block_align = 17 * avctx->channels;
202+ avctx->block_align = 17 * channels;
207203 ) /* End of CASE */
208204 CASE(ADPCM_IMA_WS,
209205 /* each 16 bits sample gives one nibble */
210− avctx->frame_size = s->block_size * 2 / avctx->channels;
206+ avctx->frame_size = s->block_size * 2 / channels;
211207 avctx->block_align = s->block_size;
212208 ) /* End of CASE */
213209 default:
@@ -606,16 +602,17 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 392 unmodified lines
606602 int16_t **samples_p;
607603 uint8_t *dst;
608604 ADPCMEncodeContext *c = avctx->priv_data;
605+ int channels = avctx->ch_layout.nb_channels;
609606
610607 samples = (const int16_t *)frame->data[0];
611608 samples_p = (int16_t **)frame->extended_data;
612− st = avctx->channels == 2;
609+ st = channels == 2;
613610
614611 if (avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_SSI ||
615612 avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_ALP ||
616613 avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_APM ||
617614 avctx->codec_id == AV_CODEC_ID_ADPCM_IMA_WS)
618− pkt_size = (frame->nb_samples * avctx->channels) / 2;
615+ pkt_size = (frame->nb_samples * channels) / 2;
619616 else
620617 pkt_size = avctx->block_align;
621618 if ((ret = ff_get_encode_buffer(avctx, avpkt, pkt_size, 0)) < 0)
@@ -626,7 +623,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 4 unmodified lines
626623 CASE(ADPCM_IMA_WAV,
627624 int blocks = (frame->nb_samples - 1) / 8;
628625
629− for (int ch = 0; ch < avctx->channels; ch++) {
626+ for (int ch = 0; ch < channels; ch++) {
630627 ADPCMChannelStatus *status = &c->status[ch];
631628 status->prev_sample = samples_p[ch][0];
632629 /* status->step_index = 0;
@@ -639,15 +636,15 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 6 unmodified lines
639636 /* stereo: 4 bytes (8 samples) for left, 4 bytes for right */
640637 if (avctx->trellis > 0) {
641638 uint8_t *buf;
642− if (!FF_ALLOC_TYPED_ARRAY(buf, avctx->channels * blocks * 8))
639+ if (!FF_ALLOC_TYPED_ARRAY(buf, channels * blocks * 8))
643640 return AVERROR(ENOMEM);
644− for (int ch = 0; ch < avctx->channels; ch++) {
641+ for (int ch = 0; ch < channels; ch++) {
645642 adpcm_compress_trellis(avctx, &samples_p[ch][1],
646643 buf + ch * blocks * 8, &c->status[ch],
647644 blocks * 8, 1);
648645 }
649646 for (int i = 0; i < blocks; i++) {
650− for (int ch = 0; ch < avctx->channels; ch++) {
647+ for (int ch = 0; ch < channels; ch++) {
651648 uint8_t *buf1 = buf + ch * blocks * 8 + i * 8;
652649 for (int j = 0; j < 8; j += 2)
653650 *dst++ = buf1[j] | (buf1[j + 1] << 4);
@@ -656,7 +653,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 2 unmodified lines
656653 av_free(buf);
657654 } else {
658655 for (int i = 0; i < blocks; i++) {
659− for (int ch = 0; ch < avctx->channels; ch++) {
656+ for (int ch = 0; ch < channels; ch++) {
660657 ADPCMChannelStatus *status = &c->status[ch];
661658 const int16_t *smp = &samples_p[ch][1 + i * 8];
662659 for (int j = 0; j < 8; j += 2) {
@@ -672,7 +669,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 9 unmodified lines
672669 PutBitContext pb;
673670 init_put_bits(&pb, dst, pkt_size);
674671
675− for (int ch = 0; ch < avctx->channels; ch++) {
672+ for (int ch = 0; ch < channels; ch++) {
676673 ADPCMChannelStatus *status = &c->status[ch];
677674 put_bits(&pb, 9, (status->prev_sample & 0xFFFF) >> 7);
678675 put_bits(&pb, 7, status->step_index);
@@ -703,7 +700,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 24 unmodified lines
703700 av_assert0(avctx->trellis == 0);
704701
705702 for (int i = 0; i < frame->nb_samples; i++) {
706− for (int ch = 0; ch < avctx->channels; ch++) {
703+ for (int ch = 0; ch < channels; ch++) {
707704 put_bits(&pb, 4, adpcm_ima_qt_compress_sample(c->status + ch, *samples++));
708705 }
709706 }
@@ -717,11 +714,11 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 7 unmodified lines
717714 av_assert0(avctx->trellis == 0);
718715
719716 for (int n = frame->nb_samples / 2; n > 0; n--) {
720− for (int ch = 0; ch < avctx->channels; ch++) {
717+ for (int ch = 0; ch < channels; ch++) {
721718 put_bits(&pb, 4, adpcm_ima_alp_compress_sample(c->status + ch, *samples++));
722719 put_bits(&pb, 4, adpcm_ima_alp_compress_sample(c->status + ch, samples[st]));
723720 }
724− samples += avctx->channels;
721+ samples += channels;
725722 }
726723
727724 flush_put_bits(&pb);
@@ -738,7 +735,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 10 unmodified lines
738735 put_bits(&pb, 2, 2); // set 4-bit flash adpcm format
739736
740737 // init the encoder state
741− for (int i = 0; i < avctx->channels; i++) {
738+ for (int i = 0; i < channels; i++) {
742739 // clip step so it fits 6 bits
743740 c->status[i].step_index = av_clip_uintp2(c->status[i].step_index, 6);
744741 put_sbits(&pb, 16, samples[i]);
@@ -748,22 +745,22 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 3 unmodified lines
748745
749746 if (avctx->trellis > 0) {
750747 uint8_t buf[8190 /* = 2 * n */];
751− adpcm_compress_trellis(avctx, samples + avctx->channels, buf,
752− &c->status[0], n, avctx->channels);
753− if (avctx->channels == 2)
754− adpcm_compress_trellis(avctx, samples + avctx->channels + 1,
748+ adpcm_compress_trellis(avctx, samples + channels, buf,
749+ &c->status[0], n, channels);
750+ if (channels == 2)
751+ adpcm_compress_trellis(avctx, samples + channels + 1,
755752 buf + n, &c->status[1], n,
756− avctx->channels);
753+ channels);
757754 for (int i = 0; i < n; i++) {
758755 put_bits(&pb, 4, buf[i]);
759− if (avctx->channels == 2)
756+ if (channels == 2)
760757 put_bits(&pb, 4, buf[n + i]);
761758 }
762759 } else {
763760 for (int i = 1; i < frame->nb_samples; i++) {
764761 put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[0],
765− samples[avctx->channels * i]));
766− if (avctx->channels == 2)
762+ samples[channels * i]));
763+ if (channels == 2)
767764 put_bits(&pb, 4, adpcm_ima_compress_sample(&c->status[1],
768765 samples[2 * i + 1]));
769766 }
@@ -771,47 +768,47 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 1 unmodified line
771768 flush_put_bits(&pb);
772769 ) /* End of CASE */
773770 CASE(ADPCM_MS,
774− for (int i = 0; i < avctx->channels; i++) {
771+ for (int i = 0; i < channels; i++) {
775772 int predictor = 0;
776773 *dst++ = predictor;
777774 c->status[i].coeff1 = ff_adpcm_AdaptCoeff1[predictor];
778775 c->status[i].coeff2 = ff_adpcm_AdaptCoeff2[predictor];
779776 }
780− for (int i = 0; i < avctx->channels; i++) {
777+ for (int i = 0; i < channels; i++) {
781778 if (c->status[i].idelta < 16)
782779 c->status[i].idelta = 16;
783780 bytestream_put_le16(&dst, c->status[i].idelta);
784781 }
785− for (int i = 0; i < avctx->channels; i++)
782+ for (int i = 0; i < channels; i++)
786783 c->status[i].sample2= *samples++;
787− for (int i = 0; i < avctx->channels; i++) {
784+ for (int i = 0; i < channels; i++) {
788785 c->status[i].sample1 = *samples++;
789786 bytestream_put_le16(&dst, c->status[i].sample1);
790787 }
791− for (int i = 0; i < avctx->channels; i++)
788+ for (int i = 0; i < channels; i++)
792789 bytestream_put_le16(&dst, c->status[i].sample2);
793790
794791 if (avctx->trellis > 0) {
795− const int n = avctx->block_align - 7 * avctx->channels;
792+ const int n = avctx->block_align - 7 * channels;
796793 uint8_t *buf = av_malloc(2 * n);
797794 if (!buf)
798795 return AVERROR(ENOMEM);
799− if (avctx->channels == 1) {
796+ if (channels == 1) {
800797 adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n,
801− avctx->channels);
798+ channels);
802799 for (int i = 0; i < n; i += 2)
803800 *dst++ = (buf[i] << 4) | buf[i + 1];
804801 } else {
805802 adpcm_compress_trellis(avctx, samples, buf,
806− &c->status[0], n, avctx->channels);
803+ &c->status[0], n, channels);
807804 adpcm_compress_trellis(avctx, samples + 1, buf + n,
808− &c->status[1], n, avctx->channels);
805+ &c->status[1], n, channels);
809806 for (int i = 0; i < n; i++)
810807 *dst++ = (buf[i] << 4) | buf[n + i];
811808 }
812809 av_free(buf);
813810 } else {
814− for (int i = 7 * avctx->channels; i < avctx->block_align; i++) {
811+ for (int i = 7 * channels; i < avctx->block_align; i++) {
815812 int nibble;
816813 nibble = adpcm_ms_compress_sample(&c->status[ 0], *samples++) << 4;
817814 nibble |= adpcm_ms_compress_sample(&c->status[st], *samples++);
@@ -826,22 +823,22 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 8 unmodified lines
826823 if (!buf)
827824 return AVERROR(ENOMEM);
828825 n *= 2;
829− if (avctx->channels == 1) {
826+ if (channels == 1) {
830827 adpcm_compress_trellis(avctx, samples, buf, &c->status[0], n,
831− avctx->channels);
828+ channels);
832829 for (int i = 0; i < n; i += 2)
833830 *dst++ = buf[i] | (buf[i + 1] << 4);
834831 } else {
835832 adpcm_compress_trellis(avctx, samples, buf,
836− &c->status[0], n, avctx->channels);
833+ &c->status[0], n, channels);
837834 adpcm_compress_trellis(avctx, samples + 1, buf + n,
838− &c->status[1], n, avctx->channels);
835+ &c->status[1], n, channels);
839836 for (int i = 0; i < n; i++)
840837 *dst++ = buf[i] | (buf[n + i] << 4);
841838 }
842839 av_free(buf);
843840 } else
844− for (n *= avctx->channels; n > 0; n--) {
841+ for (n *= channels; n > 0; n--) {
845842 int nibble;
846843 nibble = adpcm_yamaha_compress_sample(&c->status[ 0], *samples++);
847844 nibble |= adpcm_yamaha_compress_sample(&c->status[st], *samples++) << 4;
@@ -855,17 +852,17 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 7 unmodified lines
855852 av_assert0(avctx->trellis == 0);
856853
857854 for (int n = frame->nb_samples / 2; n > 0; n--) {
858− for (int ch = 0; ch < avctx->channels; ch++) {
855+ for (int ch = 0; ch < channels; ch++) {
859856 put_bits(&pb, 4, adpcm_ima_qt_compress_sample(c->status + ch, *samples++));
860857 put_bits(&pb, 4, adpcm_ima_qt_compress_sample(c->status + ch, samples[st]));
861858 }
862− samples += avctx->channels;
859+ samples += channels;
863860 }
864861
865862 flush_put_bits(&pb);
866863 ) /* End of CASE */
867864 CASE(ADPCM_IMA_AMV,
868− av_assert0(avctx->channels == 1);
865+ av_assert0(channels == 1);
869866
870867 c->status[0].prev_sample = *samples;
871868 bytestream_put_le16(&dst, c->status[0].prev_sample);
@@ -880,7 +877,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 8 unmodified lines
880877 if (!buf)
881878 return AVERROR(ENOMEM);
882879
883− adpcm_compress_trellis(avctx, samples, buf, &c->status[0], 2 * n, avctx->channels);
880+ adpcm_compress_trellis(avctx, samples, buf, &c->status[0], 2 * n, channels);
884881 for (int i = 0; i < n; i++)
885882 bytestream_put_byte(&dst, (buf[2 * i] << 4) | buf[2 * i + 1]);
886883
@@ -904,7 +901,7 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 17 unmodified lines
904901
905902 av_assert0(frame->nb_samples == 32);
906903
907− for (int ch = 0; ch < avctx->channels; ch++) {
904+ for (int ch = 0; ch < channels; ch++) {
908905 int64_t error = INT64_MAX, tmperr = INT64_MAX;
909906 int shift = 2, flag = 0;
910907 int saved1 = c->status[ch].sample1;
@@ -941,14 +938,14 @@ static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 30 unmodified lines
941938 av_assert0(avctx->trellis == 0);
942939 for (int n = frame->nb_samples / 2; n > 0; n--) {
943940 /* stereo: 1 byte (2 samples) for left, 1 byte for right */
944− for (int ch = 0; ch < avctx->channels; ch++) {
941+ for (int ch = 0; ch < channels; ch++) {
945942 int t1, t2;
946943 t1 = adpcm_ima_compress_sample(&c->status[ch], *samples++);
947944 t2 = adpcm_ima_compress_sample(&c->status[ch], samples[st]);
948945 put_bits(&pb, 4, t2);
949946 put_bits(&pb, 4, t1);
950947 }
951− samples += avctx->channels;
948+ samples += channels;
952949 }
953950 flush_put_bits(&pb);
954951 ) /* End of CASE */
@@ -968,6 +965,12 @@ static const enum AVSampleFormat sample_fmts_p[] = { · 13 unmodified lines
968965 AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_NONE
969966 };
970967
968+static const AVChannelLayout ch_layouts[] = {
969+ AV_CHANNEL_LAYOUT_MONO,
970+ AV_CHANNEL_LAYOUT_STEREO,
971+ { 0 },
972+};
973+
971974 static const AVOption options[] = {
972975 {
973976 .name = "block_size",
@@ -1001,6 +1004,7 @@ const AVCodec ff_ ## name_ ## _encoder = { \ · 27 unmodified lines
10011004 .encode2 = adpcm_encode_frame, \
10021005 .close = adpcm_encode_close, \
10031006 .sample_fmts = sample_fmts_, \
1007+ .ch_layouts = ch_layouts, \
10041008 .capabilities = capabilities_ | AV_CODEC_CAP_DR1, \
10051009 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_INIT_THREADSAFE, \
10061010 .priv_class = &adpcm_encoder_class, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t