You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-11-23 21:54:53 +02:00
dca: convert to new channel layout API
Signed-off-by: James Almer <jamrial@gmail.com>
This commit is contained in:
committed by
James Almer
parent
fa0c8a753e
commit
b2af4bc807
@@ -2149,7 +2149,7 @@ static int filter_frame_fixed(DCACoreDecoder *s, AVFrame *frame)
|
|||||||
nsamples, s->ch_mask);
|
nsamples, s->ch_mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < avctx->channels; i++) {
|
for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
|
||||||
int32_t *samples = s->output_samples[s->ch_remap[i]];
|
int32_t *samples = s->output_samples[s->ch_remap[i]];
|
||||||
int32_t *plane = (int32_t *)frame->extended_data[i];
|
int32_t *plane = (int32_t *)frame->extended_data[i];
|
||||||
for (n = 0; n < nsamples; n++)
|
for (n = 0; n < nsamples; n++)
|
||||||
@@ -2181,11 +2181,11 @@ static int filter_frame_float(DCACoreDecoder *s, AVFrame *frame)
|
|||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
// Build reverse speaker to channel mapping
|
// Build reverse speaker to channel mapping
|
||||||
for (i = 0; i < avctx->channels; i++)
|
for (i = 0; i < avctx->ch_layout.nb_channels; i++)
|
||||||
output_samples[s->ch_remap[i]] = (float *)frame->extended_data[i];
|
output_samples[s->ch_remap[i]] = (float *)frame->extended_data[i];
|
||||||
|
|
||||||
// Allocate space for extra channels
|
// Allocate space for extra channels
|
||||||
nchannels = av_popcount(s->ch_mask) - avctx->channels;
|
nchannels = av_popcount(s->ch_mask) - avctx->ch_layout.nb_channels;
|
||||||
if (nchannels > 0) {
|
if (nchannels > 0) {
|
||||||
av_fast_malloc(&s->output_buffer, &s->output_size,
|
av_fast_malloc(&s->output_buffer, &s->output_size,
|
||||||
nsamples * nchannels * sizeof(float));
|
nsamples * nchannels * sizeof(float));
|
||||||
|
|||||||
@@ -108,10 +108,6 @@ static const uint8_t lfe_index[7] = {
|
|||||||
1, 2, 3, 0, 1, 2, 3
|
1, 2, 3, 0, 1, 2, 3
|
||||||
};
|
};
|
||||||
|
|
||||||
static const uint8_t channel_counts[7] = {
|
|
||||||
1, 2, 3, 2, 3, 4, 5
|
|
||||||
};
|
|
||||||
|
|
||||||
static const uint16_t channel_layouts[7] = {
|
static const uint16_t channel_layouts[7] = {
|
||||||
AV_CH_LAYOUT_MONO,
|
AV_CH_LAYOUT_MONO,
|
||||||
AV_CH_LAYOUT_STEREO,
|
AV_CH_LAYOUT_STEREO,
|
||||||
@@ -1732,9 +1728,8 @@ int ff_dca_lbr_filter_frame(DCALbrDecoder *s, AVFrame *frame)
|
|||||||
AVCodecContext *avctx = s->avctx;
|
AVCodecContext *avctx = s->avctx;
|
||||||
int i, ret, nchannels, ch_conf = (s->ch_mask & 0x7) - 1;
|
int i, ret, nchannels, ch_conf = (s->ch_mask & 0x7) - 1;
|
||||||
const int8_t *reorder;
|
const int8_t *reorder;
|
||||||
|
uint64_t channel_mask = channel_layouts[ch_conf];
|
||||||
|
|
||||||
avctx->channel_layout = channel_layouts[ch_conf];
|
|
||||||
avctx->channels = nchannels = channel_counts[ch_conf];
|
|
||||||
avctx->sample_rate = s->sample_rate;
|
avctx->sample_rate = s->sample_rate;
|
||||||
avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
|
avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
|
||||||
avctx->bits_per_raw_sample = 0;
|
avctx->bits_per_raw_sample = 0;
|
||||||
@@ -1742,13 +1737,22 @@ int ff_dca_lbr_filter_frame(DCALbrDecoder *s, AVFrame *frame)
|
|||||||
avctx->bit_rate = s->bit_rate_scaled;
|
avctx->bit_rate = s->bit_rate_scaled;
|
||||||
|
|
||||||
if (s->flags & LBR_FLAG_LFE_PRESENT) {
|
if (s->flags & LBR_FLAG_LFE_PRESENT) {
|
||||||
avctx->channel_layout |= AV_CH_LOW_FREQUENCY;
|
channel_mask |= AV_CH_LOW_FREQUENCY;
|
||||||
avctx->channels++;
|
|
||||||
reorder = channel_reorder_lfe[ch_conf];
|
reorder = channel_reorder_lfe[ch_conf];
|
||||||
} else {
|
} else {
|
||||||
reorder = channel_reorder_nolfe[ch_conf];
|
reorder = channel_reorder_nolfe[ch_conf];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
av_channel_layout_uninit(&avctx->ch_layout);
|
||||||
|
av_channel_layout_from_mask(&avctx->ch_layout, channel_mask);
|
||||||
|
#if FF_API_OLD_CHANNEL_LAYOUT
|
||||||
|
FF_DISABLE_DEPRECATION_WARNINGS
|
||||||
|
avctx->channels = avctx->ch_layout.nb_channels;
|
||||||
|
avctx->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
|
||||||
|
avctx->ch_layout.u.mask : 0;
|
||||||
|
FF_ENABLE_DEPRECATION_WARNINGS
|
||||||
|
#endif
|
||||||
|
|
||||||
frame->nb_samples = 1024 << s->freq_range;
|
frame->nb_samples = 1024 << s->freq_range;
|
||||||
if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
|
if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|||||||
@@ -1443,7 +1443,7 @@ int ff_dca_xll_filter_frame(DCAXllDecoder *s, AVFrame *frame)
|
|||||||
s->output_mask);
|
s->output_mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < avctx->channels; i++) {
|
for (i = 0; i < avctx->ch_layout.nb_channels; i++) {
|
||||||
int32_t *samples = s->output_samples[ch_remap[i]];
|
int32_t *samples = s->output_samples[ch_remap[i]];
|
||||||
if (frame->format == AV_SAMPLE_FMT_S16P) {
|
if (frame->format == AV_SAMPLE_FMT_S16P) {
|
||||||
int16_t *plane = (int16_t *)frame->extended_data[i];
|
int16_t *plane = (int16_t *)frame->extended_data[i];
|
||||||
|
|||||||
@@ -43,13 +43,17 @@ int ff_dca_set_channel_layout(AVCodecContext *avctx, int *ch_remap, int dca_mask
|
|||||||
13, 14, 3, 9, 10, 11, 12, 14, 16, 15, 17, 8, 4, 5,
|
13, 14, 3, 9, 10, 11, 12, 14, 16, 15, 17, 8, 4, 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
DCAContext *s = avctx->priv_data;
|
||||||
|
|
||||||
int dca_ch, wav_ch, nchannels = 0;
|
int dca_ch, wav_ch, nchannels = 0;
|
||||||
|
|
||||||
if (avctx->request_channel_layout & AV_CH_LAYOUT_NATIVE) {
|
av_channel_layout_uninit(&avctx->ch_layout);
|
||||||
|
if (s->output_channel_order == CHANNEL_ORDER_CODED) {
|
||||||
for (dca_ch = 0; dca_ch < DCA_SPEAKER_COUNT; dca_ch++)
|
for (dca_ch = 0; dca_ch < DCA_SPEAKER_COUNT; dca_ch++)
|
||||||
if (dca_mask & (1U << dca_ch))
|
if (dca_mask & (1U << dca_ch))
|
||||||
ch_remap[nchannels++] = dca_ch;
|
ch_remap[nchannels++] = dca_ch;
|
||||||
avctx->channel_layout = dca_mask;
|
avctx->ch_layout.order = AV_CHANNEL_ORDER_UNSPEC;
|
||||||
|
avctx->ch_layout.nb_channels = nchannels;
|
||||||
} else {
|
} else {
|
||||||
int wav_mask = 0;
|
int wav_mask = 0;
|
||||||
int wav_map[18];
|
int wav_map[18];
|
||||||
@@ -71,10 +75,18 @@ int ff_dca_set_channel_layout(AVCodecContext *avctx, int *ch_remap, int dca_mask
|
|||||||
for (wav_ch = 0; wav_ch < 18; wav_ch++)
|
for (wav_ch = 0; wav_ch < 18; wav_ch++)
|
||||||
if (wav_mask & (1 << wav_ch))
|
if (wav_mask & (1 << wav_ch))
|
||||||
ch_remap[nchannels++] = wav_map[wav_ch];
|
ch_remap[nchannels++] = wav_map[wav_ch];
|
||||||
avctx->channel_layout = wav_mask;
|
|
||||||
|
av_channel_layout_from_mask(&avctx->ch_layout, wav_mask);
|
||||||
}
|
}
|
||||||
|
|
||||||
avctx->channels = nchannels;
|
#if FF_API_OLD_CHANNEL_LAYOUT
|
||||||
|
FF_DISABLE_DEPRECATION_WARNINGS
|
||||||
|
avctx->channels = avctx->ch_layout.nb_channels;
|
||||||
|
avctx->channel_layout = avctx->ch_layout.order == AV_CHANNEL_ORDER_NATIVE ?
|
||||||
|
avctx->ch_layout.u.mask : 0;
|
||||||
|
FF_ENABLE_DEPRECATION_WARNINGS
|
||||||
|
#endif
|
||||||
|
|
||||||
return nchannels;
|
return nchannels;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -350,23 +362,28 @@ static av_cold int dcadec_init(AVCodecContext *avctx)
|
|||||||
|
|
||||||
s->crctab = av_crc_get_table(AV_CRC_16_CCITT);
|
s->crctab = av_crc_get_table(AV_CRC_16_CCITT);
|
||||||
|
|
||||||
switch (avctx->request_channel_layout & ~AV_CH_LAYOUT_NATIVE) {
|
#if FF_API_OLD_CHANNEL_LAYOUT
|
||||||
case 0:
|
FF_DISABLE_DEPRECATION_WARNINGS
|
||||||
s->request_channel_layout = 0;
|
if (avctx->request_channel_layout & AV_CH_LAYOUT_NATIVE)
|
||||||
break;
|
s->output_channel_order = CHANNEL_ORDER_CODED;
|
||||||
case AV_CH_LAYOUT_STEREO:
|
|
||||||
case AV_CH_LAYOUT_STEREO_DOWNMIX:
|
if (avctx->request_channel_layout & ~AV_CH_LAYOUT_NATIVE) {
|
||||||
s->request_channel_layout = DCA_SPEAKER_LAYOUT_STEREO;
|
av_channel_layout_uninit(&s->downmix_layout);
|
||||||
break;
|
av_channel_layout_from_mask(&s->downmix_layout, avctx->request_channel_layout & ~AV_CH_LAYOUT_NATIVE);
|
||||||
case AV_CH_LAYOUT_5POINT0:
|
}
|
||||||
s->request_channel_layout = DCA_SPEAKER_LAYOUT_5POINT0;
|
FF_ENABLE_DEPRECATION_WARNINGS
|
||||||
break;
|
#endif
|
||||||
case AV_CH_LAYOUT_5POINT1:
|
|
||||||
s->request_channel_layout = DCA_SPEAKER_LAYOUT_5POINT1;
|
if (s->downmix_layout.nb_channels) {
|
||||||
break;
|
if (!av_channel_layout_compare(&s->downmix_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO) ||
|
||||||
default:
|
!av_channel_layout_compare(&s->downmix_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO_DOWNMIX))
|
||||||
av_log(avctx, AV_LOG_WARNING, "Invalid request_channel_layout\n");
|
s->request_channel_layout = DCA_SPEAKER_LAYOUT_STEREO;
|
||||||
break;
|
else if (!av_channel_layout_compare(&s->downmix_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0))
|
||||||
|
s->request_channel_layout = DCA_SPEAKER_LAYOUT_5POINT0;
|
||||||
|
else if (!av_channel_layout_compare(&s->downmix_layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1))
|
||||||
|
s->request_channel_layout = DCA_SPEAKER_LAYOUT_5POINT1;
|
||||||
|
else
|
||||||
|
av_log(avctx, AV_LOG_WARNING, "Invalid downmix layout\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
ff_thread_once(&init_static_once, dcadec_init_static);
|
ff_thread_once(&init_static_once, dcadec_init_static);
|
||||||
@@ -379,6 +396,18 @@ static av_cold int dcadec_init(AVCodecContext *avctx)
|
|||||||
|
|
||||||
static const AVOption dcadec_options[] = {
|
static const AVOption dcadec_options[] = {
|
||||||
{ "core_only", "Decode core only without extensions", OFFSET(core_only), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, PARAM },
|
{ "core_only", "Decode core only without extensions", OFFSET(core_only), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, PARAM },
|
||||||
|
|
||||||
|
{ "channel_order", "Order in which the channels are to be exported",
|
||||||
|
OFFSET(output_channel_order), AV_OPT_TYPE_INT,
|
||||||
|
{ .i64 = CHANNEL_ORDER_DEFAULT }, 0, 1, PARAM, "channel_order" },
|
||||||
|
{ "default", "normal libavcodec channel order", 0, AV_OPT_TYPE_CONST,
|
||||||
|
{ .i64 = CHANNEL_ORDER_DEFAULT }, .flags = PARAM, "channel_order" },
|
||||||
|
{ "coded", "order in which the channels are coded in the bitstream",
|
||||||
|
0, AV_OPT_TYPE_CONST, { .i64 = CHANNEL_ORDER_CODED }, .flags = PARAM, "channel_order" },
|
||||||
|
|
||||||
|
{ "downmix", "Request a specific channel layout from the decoder", OFFSET(downmix_layout),
|
||||||
|
AV_OPT_TYPE_CHLAYOUT, {.str = NULL}, .flags = PARAM },
|
||||||
|
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -45,6 +45,11 @@
|
|||||||
#define DCA_PACKET_RECOVERY 0x10 ///< Sync error recovery flag
|
#define DCA_PACKET_RECOVERY 0x10 ///< Sync error recovery flag
|
||||||
#define DCA_PACKET_RESIDUAL 0x20 ///< Core valid for residual decoding
|
#define DCA_PACKET_RESIDUAL 0x20 ///< Core valid for residual decoding
|
||||||
|
|
||||||
|
enum DCAOutputChannelOrder {
|
||||||
|
CHANNEL_ORDER_DEFAULT,
|
||||||
|
CHANNEL_ORDER_CODED,
|
||||||
|
};
|
||||||
|
|
||||||
typedef struct DCAContext {
|
typedef struct DCAContext {
|
||||||
const AVClass *class; ///< class for AVOptions
|
const AVClass *class; ///< class for AVOptions
|
||||||
AVCodecContext *avctx;
|
AVCodecContext *avctx;
|
||||||
@@ -65,6 +70,8 @@ typedef struct DCAContext {
|
|||||||
|
|
||||||
int request_channel_layout; ///< Converted from avctx.request_channel_layout
|
int request_channel_layout; ///< Converted from avctx.request_channel_layout
|
||||||
int core_only; ///< Core only decoding flag
|
int core_only; ///< Core only decoding flag
|
||||||
|
int output_channel_order;
|
||||||
|
AVChannelLayout downmix_layout;
|
||||||
} DCAContext;
|
} DCAContext;
|
||||||
|
|
||||||
int ff_dca_set_channel_layout(AVCodecContext *avctx, int *ch_remap, int dca_mask);
|
int ff_dca_set_channel_layout(AVCodecContext *avctx, int *ch_remap, int dca_mask);
|
||||||
|
|||||||
@@ -163,15 +163,15 @@ static void subband_bufer_free(DCAEncContext *c)
|
|||||||
static int encode_init(AVCodecContext *avctx)
|
static int encode_init(AVCodecContext *avctx)
|
||||||
{
|
{
|
||||||
DCAEncContext *c = avctx->priv_data;
|
DCAEncContext *c = avctx->priv_data;
|
||||||
uint64_t layout = avctx->channel_layout;
|
AVChannelLayout layout = avctx->ch_layout;
|
||||||
int i, j, k, min_frame_bits;
|
int i, j, k, min_frame_bits;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if ((ret = subband_bufer_alloc(c)) < 0)
|
if ((ret = subband_bufer_alloc(c)) < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
c->fullband_channels = c->channels = avctx->channels;
|
c->fullband_channels = c->channels = layout.nb_channels;
|
||||||
c->lfe_channel = (avctx->channels == 3 || avctx->channels == 6);
|
c->lfe_channel = (c->channels == 3 || c->channels == 6);
|
||||||
c->band_interpolation = c->band_interpolation_tab[1];
|
c->band_interpolation = c->band_interpolation_tab[1];
|
||||||
c->band_spectrum = c->band_spectrum_tab[1];
|
c->band_spectrum = c->band_spectrum_tab[1];
|
||||||
c->worst_quantization_noise = -2047;
|
c->worst_quantization_noise = -2047;
|
||||||
@@ -181,19 +181,24 @@ static int encode_init(AVCodecContext *avctx)
|
|||||||
if (ff_dcaadpcm_init(&c->adpcm_ctx))
|
if (ff_dcaadpcm_init(&c->adpcm_ctx))
|
||||||
return AVERROR(ENOMEM);
|
return AVERROR(ENOMEM);
|
||||||
|
|
||||||
if (!layout) {
|
if (layout.order == AV_CHANNEL_ORDER_UNSPEC) {
|
||||||
av_log(avctx, AV_LOG_WARNING, "No channel layout specified. The "
|
av_log(avctx, AV_LOG_WARNING, "No channel layout specified. The "
|
||||||
"encoder will guess the layout, but it "
|
"encoder will guess the layout, but it "
|
||||||
"might be incorrect.\n");
|
"might be incorrect.\n");
|
||||||
layout = av_get_default_channel_layout(avctx->channels);
|
av_channel_layout_default(&layout, layout.nb_channels);
|
||||||
}
|
}
|
||||||
switch (layout) {
|
|
||||||
case AV_CH_LAYOUT_MONO: c->channel_config = 0; break;
|
if (!av_channel_layout_compare(&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_MONO))
|
||||||
case AV_CH_LAYOUT_STEREO: c->channel_config = 2; break;
|
c->channel_config = 0;
|
||||||
case AV_CH_LAYOUT_2_2: c->channel_config = 8; break;
|
else if (!av_channel_layout_compare(&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_STEREO))
|
||||||
case AV_CH_LAYOUT_5POINT0: c->channel_config = 9; break;
|
c->channel_config = 2;
|
||||||
case AV_CH_LAYOUT_5POINT1: c->channel_config = 9; break;
|
else if (!av_channel_layout_compare(&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_2_2))
|
||||||
default:
|
c->channel_config = 8;
|
||||||
|
else if (!av_channel_layout_compare(&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT0))
|
||||||
|
c->channel_config = 9;
|
||||||
|
else if (!av_channel_layout_compare(&layout, &(AVChannelLayout)AV_CHANNEL_LAYOUT_5POINT1))
|
||||||
|
c->channel_config = 9;
|
||||||
|
else {
|
||||||
av_log(avctx, AV_LOG_ERROR, "Unsupported channel layout!\n");
|
av_log(avctx, AV_LOG_ERROR, "Unsupported channel layout!\n");
|
||||||
return AVERROR_PATCHWELCOME;
|
return AVERROR_PATCHWELCOME;
|
||||||
}
|
}
|
||||||
@@ -1248,12 +1253,22 @@ const AVCodec ff_dca_encoder = {
|
|||||||
.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S32,
|
.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S32,
|
||||||
AV_SAMPLE_FMT_NONE },
|
AV_SAMPLE_FMT_NONE },
|
||||||
.supported_samplerates = sample_rates,
|
.supported_samplerates = sample_rates,
|
||||||
|
#if FF_API_OLD_CHANNEL_LAYOUT
|
||||||
.channel_layouts = (const uint64_t[]) { AV_CH_LAYOUT_MONO,
|
.channel_layouts = (const uint64_t[]) { AV_CH_LAYOUT_MONO,
|
||||||
AV_CH_LAYOUT_STEREO,
|
AV_CH_LAYOUT_STEREO,
|
||||||
AV_CH_LAYOUT_2_2,
|
AV_CH_LAYOUT_2_2,
|
||||||
AV_CH_LAYOUT_5POINT0,
|
AV_CH_LAYOUT_5POINT0,
|
||||||
AV_CH_LAYOUT_5POINT1,
|
AV_CH_LAYOUT_5POINT1,
|
||||||
0 },
|
0 },
|
||||||
|
#endif
|
||||||
|
.ch_layouts = (const AVChannelLayout[]){
|
||||||
|
AV_CHANNEL_LAYOUT_MONO,
|
||||||
|
AV_CHANNEL_LAYOUT_STEREO,
|
||||||
|
AV_CHANNEL_LAYOUT_2_2,
|
||||||
|
AV_CHANNEL_LAYOUT_5POINT0,
|
||||||
|
AV_CHANNEL_LAYOUT_5POINT1,
|
||||||
|
{ 0 },
|
||||||
|
},
|
||||||
.defaults = defaults,
|
.defaults = defaults,
|
||||||
.priv_class = &dcaenc_class,
|
.priv_class = &dcaenc_class,
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user