| @@ -462,14 +462,15 @@ static int write_frame(AlacEncodeContext *s, AVPacket *avpkt, · 461 unmodified lines |
| 462 | uint8_t * const *samples) | 462 | uint8_t * const *samples) |
| 463 | { | 463 | { |
| 464 | PutBitContext *pb = &s->pbctx; | 464 | PutBitContext *pb = &s->pbctx; |
| 465 | const enum AlacRawDataBlockType *ch_elements = ff_alac_channel_elements[s->avctx->channels - 1]; | 465 | int channels = s->avctx->ch_layout.nb_channels; |
| 466 | const uint8_t *ch_map = ff_alac_channel_layout_offsets[s->avctx->channels - 1]; | 466 | const enum AlacRawDataBlockType *ch_elements = ff_alac_channel_elements[channels - 1]; |
| | 467 | const uint8_t *ch_map = ff_alac_channel_layout_offsets[channels - 1]; |
| 467 | int ch, element, sce, cpe; | 468 | int ch, element, sce, cpe; |
| 468 | | 469 | |
| 469 | init_put_bits(pb, avpkt->data, avpkt->size); | 470 | init_put_bits(pb, avpkt->data, avpkt->size); |
| 470 | | 471 | |
| 471 | ch = element = sce = cpe = 0; | 472 | ch = element = sce = cpe = 0; |
| 472 | while (ch < s->avctx->channels) { | 473 | while (ch < channels) { |
| 473 | if (ch_elements[element] == TYPE_CPE) { | 474 | if (ch_elements[element] == TYPE_CPE) { |
| 474 | write_element(s, TYPE_CPE, cpe, samples[ch_map[ch]], | 475 | write_element(s, TYPE_CPE, cpe, samples[ch_map[ch]], |
| 475 | samples[ch_map[ch + 1]]); | 476 | samples[ch_map[ch + 1]]); |
| @@ -532,7 +533,7 @@ static av_cold int alac_encode_init(AVCodecContext *avctx) · 56 unmodified lines |
| 532 | s->rc.rice_modifier = 4; | 533 | s->rc.rice_modifier = 4; |
| 533 | | 534 | |
| 534 | s->max_coded_frame_size = get_max_frame_size(avctx->frame_size, | 535 | s->max_coded_frame_size = get_max_frame_size(avctx->frame_size, |
| 535 | avctx->channels, | 536 | avctx->ch_layout.nb_channels, |
| 536 | avctx->bits_per_raw_sample); | 537 | avctx->bits_per_raw_sample); |
| 537 | | 538 | |
| 538 | avctx->extradata = av_mallocz(ALAC_EXTRADATA_SIZE + AV_INPUT_BUFFER_PADDING_SIZE); | 539 | avctx->extradata = av_mallocz(ALAC_EXTRADATA_SIZE + AV_INPUT_BUFFER_PADDING_SIZE); |
| @@ -545,10 +546,10 @@ static av_cold int alac_encode_init(AVCodecContext *avctx) · 6 unmodified lines |
| 545 | AV_WB32(alac_extradata+4, MKBETAG('a','l','a','c')); | 546 | AV_WB32(alac_extradata+4, MKBETAG('a','l','a','c')); |
| 546 | AV_WB32(alac_extradata+12, avctx->frame_size); | 547 | AV_WB32(alac_extradata+12, avctx->frame_size); |
| 547 | AV_WB8 (alac_extradata+17, avctx->bits_per_raw_sample); | 548 | AV_WB8 (alac_extradata+17, avctx->bits_per_raw_sample); |
| 548 | AV_WB8 (alac_extradata+21, avctx->channels); | 549 | AV_WB8 (alac_extradata+21, avctx->ch_layout.nb_channels); |
| 549 | AV_WB32(alac_extradata+24, s->max_coded_frame_size); | 550 | AV_WB32(alac_extradata+24, s->max_coded_frame_size); |
| 550 | AV_WB32(alac_extradata+28, | 551 | AV_WB32(alac_extradata+28, |
| 551 | avctx->sample_rate * avctx->channels * avctx->bits_per_raw_sample); // average bitrate | 552 | avctx->sample_rate * avctx->ch_layout.nb_channels * avctx->bits_per_raw_sample); // average bitrate |
| 552 | AV_WB32(alac_extradata+32, avctx->sample_rate); | 553 | AV_WB32(alac_extradata+32, avctx->sample_rate); |
| 553 | | 554 | |
| 554 | // Set relevant extradata fields | 555 | // Set relevant extradata fields |
| @@ -585,7 +586,7 @@ static int alac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 30 unmodified lines |
| 585 | s->frame_size = frame->nb_samples; | 586 | s->frame_size = frame->nb_samples; |
| 586 | | 587 | |
| 587 | if (frame->nb_samples < DEFAULT_FRAME_SIZE) | 588 | if (frame->nb_samples < DEFAULT_FRAME_SIZE) |
| 588 | max_frame_size = get_max_frame_size(s->frame_size, avctx->channels, | 589 | max_frame_size = get_max_frame_size(s->frame_size, avctx->ch_layout.nb_channels, |
| 589 | avctx->bits_per_raw_sample); | 590 | avctx->bits_per_raw_sample); |
| 590 | else | 591 | else |
| 591 | max_frame_size = s->max_coded_frame_size; | 592 | max_frame_size = s->max_coded_frame_size; |
| @@ -616,6 +617,21 @@ static int alac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 24 unmodified lines |
| 616 | return 0; | 617 | return 0; |
| 617 | } | 618 | } |
| 618 | | 619 | |
| | 620 | #if FF_API_OLD_CHANNEL_LAYOUT |
| | 621 | static const uint64_t alac_channel_layouts[ALAC_MAX_CHANNELS + 1] = { |
| | 622 | AV_CH_LAYOUT_MONO, |
| | 623 | AV_CH_LAYOUT_STEREO, |
| | 624 | AV_CH_LAYOUT_SURROUND, |
| | 625 | AV_CH_LAYOUT_4POINT0, |
| | 626 | AV_CH_LAYOUT_5POINT0_BACK, |
| | 627 | AV_CH_LAYOUT_5POINT1_BACK, |
| | 628 | AV_CH_LAYOUT_6POINT1_BACK, |
| | 629 | AV_CH_LAYOUT_7POINT1_WIDE_BACK, |
| | 630 | 0 |
| | 631 | }; |
| | 632 | #endif |
| | 633 | |
| | 634 | |
| 619 | #define OFFSET(x) offsetof(AlacEncodeContext, x) | 635 | #define OFFSET(x) offsetof(AlacEncodeContext, x) |
| 620 | #define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM | 636 | #define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM |
| 621 | static const AVOption options[] = { | 637 | static const AVOption options[] = { |
| @@ -632,6 +648,7 @@ static const AVClass alacenc_class = { · 10 unmodified lines |
| 632 | .version = LIBAVUTIL_VERSION_INT, | 648 | .version = LIBAVUTIL_VERSION_INT, |
| 633 | }; | 649 | }; |
| 634 | | 650 | |
| | 651 | FF_DISABLE_DEPRECATION_WARNINGS |
| 635 | const AVCodec ff_alac_encoder = { | 652 | const AVCodec ff_alac_encoder = { |
| 636 | .name = "alac", | 653 | .name = "alac", |
| 637 | .long_name = NULL_IF_CONFIG_SMALL("ALAC (Apple Lossless Audio Codec)"), | 654 | .long_name = NULL_IF_CONFIG_SMALL("ALAC (Apple Lossless Audio Codec)"), |
| @@ -643,9 +660,13 @@ const AVCodec ff_alac_encoder = { · 5 unmodified lines |
| 643 | .encode2 = alac_encode_frame, | 660 | .encode2 = alac_encode_frame, |
| 644 | .close = alac_encode_close, | 661 | .close = alac_encode_close, |
| 645 | .capabilities = AV_CODEC_CAP_SMALL_LAST_FRAME, | 662 | .capabilities = AV_CODEC_CAP_SMALL_LAST_FRAME, |
| 646 | .channel_layouts = ff_alac_channel_layouts, | 663 | #if FF_API_OLD_CHANNEL_LAYOUT |
| | 664 | .channel_layouts = alac_channel_layouts, |
| | 665 | #endif |
| | 666 | .ch_layouts = ff_alac_ch_layouts, |
| 647 | .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S32P, | 667 | .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S32P, |
| 648 | AV_SAMPLE_FMT_S16P, | 668 | AV_SAMPLE_FMT_S16P, |
| 649 | AV_SAMPLE_FMT_NONE }, | 669 | AV_SAMPLE_FMT_NONE }, |
| 650 | .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, | 670 | .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, |
| 651 | }; | 671 | }; |
| | 672 | FF_ENABLE_DEPRECATION_WARNINGS |