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
575 avctx->bits_per_raw_sample = alac->sample_size;575 avctx->bits_per_raw_sample = alac->sample_size;
576 avctx->sample_rate = alac->sample_rate;576 avctx->sample_rate = alac->sample_rate;
577 577
578 if (alac->channels < 1) {578 if (alac->channels < 1 || alac->channels > ALAC_MAX_CHANNELS) {
579 av_log(avctx, AV_LOG_WARNING, "Invalid channel count\n");579 av_log(avctx, AV_LOG_WARNING, "Invalid channel count\n");
580 alac->channels = avctx->channels;580 alac->channels = avctx->ch_layout.nb_channels;
581 } else {
582 if (alac->channels > ALAC_MAX_CHANNELS)
583 alac->channels = avctx->channels;
584 else
585 avctx->channels = alac->channels;
586 }581 }
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 ) {
588 avpriv_report_missing_feature(avctx, "Channel count %d",583 avpriv_report_missing_feature(avctx, "Channel count %d",
589 avctx->channels);584 avctx->ch_layout.nb_channels);
590 return AVERROR_PATCHWELCOME;585 return AVERROR_PATCHWELCOME;
591 }586 }
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];
593 589
594 if ((ret = allocate_buffers(alac)) < 0) {590 if ((ret = allocate_buffers(alac)) < 0) {
595 av_log(avctx, AV_LOG_ERROR, "Error allocating buffers\n");591 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
32 { 2, 6, 7, 0, 1, 4, 5, 3 }32 { 2, 6, 7, 0, 1, 4, 5, 3 }
33};33};
34 34
35const uint64_t ff_alac_channel_layouts[ALAC_MAX_CHANNELS + 1] = {35const AVChannelLayout ff_alac_ch_layouts[ALAC_MAX_CHANNELS + 1] = {
36 AV_CH_LAYOUT_MONO,36 AV_CHANNEL_LAYOUT_MONO,
37 AV_CH_LAYOUT_STEREO,37 AV_CHANNEL_LAYOUT_STEREO,
38 AV_CH_LAYOUT_SURROUND,38 AV_CHANNEL_LAYOUT_SURROUND,
39 AV_CH_LAYOUT_4POINT0,39 AV_CHANNEL_LAYOUT_4POINT0,
40 AV_CH_LAYOUT_5POINT0_BACK,40 AV_CHANNEL_LAYOUT_5POINT0_BACK,
41 AV_CH_LAYOUT_5POINT1_BACK,41 AV_CHANNEL_LAYOUT_5POINT1_BACK,
42 AV_CH_LAYOUT_6POINT1_BACK,42 AV_CHANNEL_LAYOUT_6POINT1_BACK,
43 AV_CH_LAYOUT_7POINT1_WIDE_BACK,43 AV_CHANNEL_LAYOUT_7POINT1_WIDE_BACK,
44 044 { 0 }
45};45};
46 46
47const enum AlacRawDataBlockType ff_alac_channel_elements[ALAC_MAX_CHANNELS][5] = {47const enum AlacRawDataBlockType ff_alac_channel_elements[ALAC_MAX_CHANNELS][5] = {
libavcodec/alac_data.h+3−1
@@ -23,6 +23,8 @@ · 22 unmodified lines
23 23
24#include <stdint.h>24#include <stdint.h>
25 25
26#include "libavutil/channel_layout.h"
27
26enum AlacRawDataBlockType {28enum AlacRawDataBlockType {
27 /* At the moment, only SCE, CPE, LFE, and END are recognized. */29 /* At the moment, only SCE, CPE, LFE, and END are recognized. */
28 TYPE_SCE,30 TYPE_SCE,
@@ -39,7 +41,7 @@ enum AlacRawDataBlockType { · 10 unmodified lines
39 41
40extern const uint8_t ff_alac_channel_layout_offsets[ALAC_MAX_CHANNELS][ALAC_MAX_CHANNELS];42extern const uint8_t ff_alac_channel_layout_offsets[ALAC_MAX_CHANNELS][ALAC_MAX_CHANNELS];
41 43
42extern const uint64_t ff_alac_channel_layouts[ALAC_MAX_CHANNELS + 1];44extern const AVChannelLayout ff_alac_ch_layouts[ALAC_MAX_CHANNELS + 1];
43 45
44extern const enum AlacRawDataBlockType ff_alac_channel_elements[ALAC_MAX_CHANNELS][5];46extern const enum AlacRawDataBlockType ff_alac_channel_elements[ALAC_MAX_CHANNELS][5];
45 47
libavcodec/alacenc.c+29−8
@@ -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 bitrate552 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 fields555 // 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 else591 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
621static 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_PARAM636#define AE AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
621static const AVOption options[] = {637static 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
651FF_DISABLE_DEPRECATION_WARNINGS
635const AVCodec ff_alac_encoder = {652const 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};
672FF_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