1/*
2 * AC-3 Audio Decoder
3 * This code was developed as part of Google Summer of Code 2006.
4 * E-AC-3 support was added as part of Google Summer of Code 2007.
5 *
6 * Copyright (c) 2006 Kartikey Mahendra BHATT (bhattkm at gmail dot com)
7 * Copyright (c) 2007-2008 Bartlomiej Wolowiec <bartek.wolowiec@gmail.com>
8 * Copyright (c) 2007 Justin Ruggles <justin.ruggles@gmail.com>
9 *
10 * This file is part of FFmpeg.
11 *
12 * FFmpeg is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Lesser General Public
14 * License as published by the Free Software Foundation; either
15 * version 2.1 of the License, or (at your option) any later version.
16 *
17 * FFmpeg is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
20 * Lesser General Public License for more details.
21 *
22 * You should have received a copy of the GNU Lesser General Public
23 * License along with FFmpeg; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
25 */
26
27/**
28 * Upmix delay samples from stereo to original channel layout.
29 */
30
31#include "config_components.h"
32
33#include "ac3dec.h"
34#include "codec_internal.h"
35#include "eac3dec.c"
36#include "ac3dec.c"
37
38static const AVOption options[] = {
39    { "cons_noisegen", "enable consistent noise generation", OFFSET(consistent_noise_generation), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, PAR },
40    { "drc_scale", "percentage of dynamic range compression to apply", OFFSET(drc_scale), AV_OPT_TYPE_FLOAT, {.dbl = 1.0}, 0.0, 6.0, PAR },
41    { "heavy_compr", "enable heavy dynamic range compression", OFFSET(heavy_compression), AV_OPT_TYPE_BOOL, {.i64 = 0 }, 0, 1, PAR },
42    { "target_level", "target level in -dBFS (0 not applied)", OFFSET(target_level), AV_OPT_TYPE_INT, {.i64 = 0 }, -31, 0, PAR },
43
44{"dmix_mode", "Preferred Stereo Downmix Mode", OFFSET(preferred_stereo_downmix), AV_OPT_TYPE_INT, {.i64 = -1 }, -1, 2, 0, "dmix_mode"},
45{"ltrt_cmixlev",   "Lt/Rt Center Mix Level",   OFFSET(ltrt_center_mix_level),    AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0},
46{"ltrt_surmixlev", "Lt/Rt Surround Mix Level", OFFSET(ltrt_surround_mix_level),  AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0},
47{"loro_cmixlev",   "Lo/Ro Center Mix Level",   OFFSET(loro_center_mix_level),    AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0},
48{"loro_surmixlev", "Lo/Ro Surround Mix Level", OFFSET(loro_surround_mix_level),  AV_OPT_TYPE_FLOAT, {.dbl = -1.0 }, -1.0, 2.0, 0},
49
50    { "downmix", "Request a specific channel layout from the decoder", OFFSET(downmix_layout), AV_OPT_TYPE_CHLAYOUT, {.str = NULL}, .flags = PAR },
51
52    { NULL},
53};
54
55static const AVClass ac3_eac3_decoder_class = {
56    .class_name = "(E-)AC3 decoder",
57    .item_name  = av_default_item_name,
58    .option     = options,
59    .version    = LIBAVUTIL_VERSION_INT,
60};
61
62const FFCodec ff_ac3_decoder = {
63    .p.name         = "ac3",
64    .p.type         = AVMEDIA_TYPE_AUDIO,
65    .p.id           = AV_CODEC_ID_AC3,
66    .priv_data_size = sizeof (AC3DecodeContext),
67    .init           = ac3_decode_init,
68    .close          = ac3_decode_end,
69    FF_CODEC_DECODE_CB(ac3_decode_frame),
70    .p.capabilities = AV_CODEC_CAP_CHANNEL_CONF |
71                      AV_CODEC_CAP_DR1,
72    .p.long_name    = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"),
73    .p.sample_fmts  = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
74                                                      AV_SAMPLE_FMT_NONE },
75    .p.priv_class   = &ac3_eac3_decoder_class,
76    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
77};
78
79#if CONFIG_EAC3_DECODER
80const FFCodec ff_eac3_decoder = {
81    .p.name         = "eac3",
82    .p.type         = AVMEDIA_TYPE_AUDIO,
83    .p.id           = AV_CODEC_ID_EAC3,
84    .priv_data_size = sizeof (AC3DecodeContext),
85    .init           = ac3_decode_init,
86    .close          = ac3_decode_end,
87    FF_CODEC_DECODE_CB(ac3_decode_frame),
88    .p.capabilities = AV_CODEC_CAP_CHANNEL_CONF |
89                      AV_CODEC_CAP_DR1,
90    .p.long_name    = NULL_IF_CONFIG_SMALL("ATSC A/52B (AC-3, E-AC-3)"),
91    .p.sample_fmts  = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
92                                                      AV_SAMPLE_FMT_NONE },
93    .p.priv_class   = &ac3_eac3_decoder_class,
94    .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,
95};
96#endif
97