History

alac: convert to new channel layout API

Anton Khirnov committed 13 years ago

Commit d1990991 parent 44070544 files · +48 −29Browse files

Unified · Split

4 files
  1. libavcodec/alac.c +6 −10
  2. libavcodec/alac_data.c +10 −10
  3. libavcodec/alac_data.h +3 −1
  4. libavcodec/alacenc.c +29 −8
libavcodec/alac.c+6−10
@@ -575,21 +575,17 @@ static av_cold int alac_decode_init(AVCodecContext * avctx) · 574 unmodified lines
575575 avctx->bits_per_raw_sample = alac->sample_size;
576576 avctx->sample_rate = alac->sample_rate;
577577
578− if (alac->channels < 1) {
578+ if (alac->channels < 1 || alac->channels > ALAC_MAX_CHANNELS) {
579579 av_log(avctx, AV_LOG_WARNING, "Invalid channel count\n");
580− alac->channels = avctx->channels;
581− } else {
582− if (alac->channels > ALAC_MAX_CHANNELS)
583− alac->channels = avctx->channels;
584− else
585− avctx->channels = alac->channels;
580+ alac->channels = avctx->ch_layout.nb_channels;
586581 }
587− if (avctx->channels > ALAC_MAX_CHANNELS || avctx->channels <= 0 ) {
582+ if (avctx->ch_layout.nb_channels > ALAC_MAX_CHANNELS || avctx->ch_layout.nb_channels <= 0 ) {
588583 avpriv_report_missing_feature(avctx, "Channel count %d",
589− avctx->channels);
584+ avctx->ch_layout.nb_channels);
590585 return AVERROR_PATCHWELCOME;
591586 }
592− avctx->channel_layout = ff_alac_channel_layouts[alac->channels - 1];
587+ av_channel_layout_uninit(&avctx->ch_layout);
588+ avctx->ch_layout = ff_alac_ch_layouts[alac->channels - 1];
593589
594590 if ((ret = allocate_buffers(alac)) < 0) {
595591 av_log(avctx, AV_LOG_ERROR, "Error allocating buffers\n");
libavcodec/alac_data.c+10−10
@@ -32,16 +32,16 @@ const uint8_t ff_alac_channel_layout_offsets[ALAC_MAX_CHANNELS][ALAC_MAX_CHANNEL · 31 unmodified lines
3232 { 2, 6, 7, 0, 1, 4, 5, 3 }
3333 };
3434
35−const uint64_t ff_alac_channel_layouts[ALAC_MAX_CHANNELS + 1] = {
36− AV_CH_LAYOUT_MONO,
37− AV_CH_LAYOUT_STEREO,
38− AV_CH_LAYOUT_SURROUND,
39− AV_CH_LAYOUT_4POINT0,
40− AV_CH_LAYOUT_5POINT0_BACK,
41− AV_CH_LAYOUT_5POINT1_BACK,
42− AV_CH_LAYOUT_6POINT1_BACK,
43− AV_CH_LAYOUT_7POINT1_WIDE_BACK,
44− 0
35+const AVChannelLayout ff_alac_ch_layouts[ALAC_MAX_CHANNELS + 1] = {
36+ AV_CHANNEL_LAYOUT_MONO,
37+ AV_CHANNEL_LAYOUT_STEREO,
38+ AV_CHANNEL_LAYOUT_SURROUND,
39+ AV_CHANNEL_LAYOUT_4POINT0,
40+ AV_CHANNEL_LAYOUT_5POINT0_BACK,
41+ AV_CHANNEL_LAYOUT_5POINT1_BACK,
42+ AV_CHANNEL_LAYOUT_6POINT1_BACK,
43+ AV_CHANNEL_LAYOUT_7POINT1_WIDE_BACK,
44+ { 0 }
4545 };
4646
4747 const enum AlacRawDataBlockType ff_alac_channel_elements[ALAC_MAX_CHANNELS][5] = {
libavcodec/alac_data.h+3−1
@@ -23,6 +23,8 @@ · 22 unmodified lines
2323
2424 #include <stdint.h>
2525
26+#include "libavutil/channel_layout.h"
27+
2628 enum AlacRawDataBlockType {
2729 /* At the moment, only SCE, CPE, LFE, and END are recognized. */
2830 TYPE_SCE,
@@ -39,7 +41,7 @@ enum AlacRawDataBlockType { · 10 unmodified lines
3941
4042 extern const uint8_t ff_alac_channel_layout_offsets[ALAC_MAX_CHANNELS][ALAC_MAX_CHANNELS];
4143
42−extern const uint64_t ff_alac_channel_layouts[ALAC_MAX_CHANNELS + 1];
44+extern const AVChannelLayout ff_alac_ch_layouts[ALAC_MAX_CHANNELS + 1];
4345
4446 extern const enum AlacRawDataBlockType ff_alac_channel_elements[ALAC_MAX_CHANNELS][5];
4547
libavcodec/alacenc.c+29−8
@@ -462,14 +462,15 @@ static int write_frame(AlacEncodeContext *s, AVPacket *avpkt, · 461 unmodified lines
462462 uint8_t * const *samples)
463463 {
464464 PutBitContext *pb = &s->pbctx;
465− const enum AlacRawDataBlockType *ch_elements = ff_alac_channel_elements[s->avctx->channels - 1];
466− const uint8_t *ch_map = ff_alac_channel_layout_offsets[s->avctx->channels - 1];
465+ int channels = s->avctx->ch_layout.nb_channels;
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];
467468 int ch, element, sce, cpe;
468469
469470 init_put_bits(pb, avpkt->data, avpkt->size);
470471
471472 ch = element = sce = cpe = 0;
472− while (ch < s->avctx->channels) {
473+ while (ch < channels) {
473474 if (ch_elements[element] == TYPE_CPE) {
474475 write_element(s, TYPE_CPE, cpe, samples[ch_map[ch]],
475476 samples[ch_map[ch + 1]]);
@@ -532,7 +533,7 @@ static av_cold int alac_encode_init(AVCodecContext *avctx) · 56 unmodified lines
532533 s->rc.rice_modifier = 4;
533534
534535 s->max_coded_frame_size = get_max_frame_size(avctx->frame_size,
535− avctx->channels,
536+ avctx->ch_layout.nb_channels,
536537 avctx->bits_per_raw_sample);
537538
538539 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
545546 AV_WB32(alac_extradata+4, MKBETAG('a','l','a','c'));
546547 AV_WB32(alac_extradata+12, avctx->frame_size);
547548 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);
549550 AV_WB32(alac_extradata+24, s->max_coded_frame_size);
550551 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
552553 AV_WB32(alac_extradata+32, avctx->sample_rate);
553554
554555 // Set relevant extradata fields
@@ -585,7 +586,7 @@ static int alac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 30 unmodified lines
585586 s->frame_size = frame->nb_samples;
586587
587588 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,
589590 avctx->bits_per_raw_sample);
590591 else
591592 max_frame_size = s->max_coded_frame_size;
@@ -616,6 +617,21 @@ static int alac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, · 24 unmodified lines
616617 return 0;
617618 }
618619
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+
619635 #define OFFSET(x) offsetof(AlacEncodeContext, x)
620636 #define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
621637 static const AVOption options[] = {
@@ -632,6 +648,7 @@ static const AVClass alacenc_class = { · 10 unmodified lines
632648 .version = LIBAVUTIL_VERSION_INT,
633649 };
634650
651+FF_DISABLE_DEPRECATION_WARNINGS
635652 const AVCodec ff_alac_encoder = {
636653 .name = "alac",
637654 .long_name = NULL_IF_CONFIG_SMALL("ALAC (Apple Lossless Audio Codec)"),
@@ -643,9 +660,13 @@ const AVCodec ff_alac_encoder = { · 5 unmodified lines
643660 .encode2 = alac_encode_frame,
644661 .close = alac_encode_close,
645662 .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,
647667 .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S32P,
648668 AV_SAMPLE_FMT_S16P,
649669 AV_SAMPLE_FMT_NONE },
650670 .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE,
651671 };
672+FF_ENABLE_DEPRECATION_WARNINGS

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