* The simplest AC-3 encoder.
*/
-//#define ASSERT_LEVEL 2
-
#include <stdint.h>
+#include "libavutil/attributes.h"
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
#include "libavutil/channel_layout.h"
#include "libavutil/internal.h"
#include "libavutil/opt.h"
#include "avcodec.h"
+#include "me_cmp.h"
#include "put_bits.h"
+#include "audiodsp.h"
#include "ac3dsp.h"
#include "ac3.h"
#include "fft.h"
+#include "internal.h"
#include "ac3enc.h"
#include "eac3enc.h"
exp_strategy[blk] = EXP_NEW;
continue;
}
- exp_diff = s->dsp.sad[0](NULL, exp, exp - AC3_MAX_COEFS, 16, 16);
+ exp_diff = s->mecc.sad[0](NULL, exp, exp - AC3_MAX_COEFS, 16, 16);
exp_strategy[blk] = EXP_REUSE;
if (ch == CPL_CH && exp_diff > (EXP_DIFF_THRESHOLD * (s->blocks[blk].end_freq[ch] - s->start_freq[ch]) / AC3_MAX_COEFS))
exp_strategy[blk] = EXP_NEW;
* Initialize bit allocation.
* Set default parameter codes and calculate parameter values.
*/
-static void bit_alloc_init(AC3EncodeContext *s)
+static av_cold void bit_alloc_init(AC3EncodeContext *s)
{
int ch;
}
+#ifdef DEBUG
static void dprint_options(AC3EncodeContext *s)
{
-#ifdef DEBUG
AVCodecContext *avctx = s->avctx;
AC3EncOptions *opt = &s->options;
char strbuf[32];
case 16: av_strlcpy(strbuf, "E-AC-3 (enhanced)", 32); break;
default: snprintf(strbuf, 32, "ERROR");
}
- av_dlog(avctx, "bitstream_id: %s (%d)\n", strbuf, s->bitstream_id);
- av_dlog(avctx, "sample_fmt: %s\n", av_get_sample_fmt_name(avctx->sample_fmt));
+ ff_dlog(avctx, "bitstream_id: %s (%d)\n", strbuf, s->bitstream_id);
+ ff_dlog(avctx, "sample_fmt: %s\n", av_get_sample_fmt_name(avctx->sample_fmt));
av_get_channel_layout_string(strbuf, 32, s->channels, avctx->channel_layout);
- av_dlog(avctx, "channel_layout: %s\n", strbuf);
- av_dlog(avctx, "sample_rate: %d\n", s->sample_rate);
- av_dlog(avctx, "bit_rate: %d\n", s->bit_rate);
- av_dlog(avctx, "blocks/frame: %d (code=%d)\n", s->num_blocks, s->num_blks_code);
+ ff_dlog(avctx, "channel_layout: %s\n", strbuf);
+ ff_dlog(avctx, "sample_rate: %d\n", s->sample_rate);
+ ff_dlog(avctx, "bit_rate: %d\n", s->bit_rate);
+ ff_dlog(avctx, "blocks/frame: %d (code=%d)\n", s->num_blocks, s->num_blks_code);
if (s->cutoff)
- av_dlog(avctx, "cutoff: %d\n", s->cutoff);
+ ff_dlog(avctx, "cutoff: %d\n", s->cutoff);
- av_dlog(avctx, "per_frame_metadata: %s\n",
+ ff_dlog(avctx, "per_frame_metadata: %s\n",
opt->allow_per_frame_metadata?"on":"off");
if (s->has_center)
- av_dlog(avctx, "center_mixlev: %0.3f (%d)\n", opt->center_mix_level,
+ ff_dlog(avctx, "center_mixlev: %0.3f (%d)\n", opt->center_mix_level,
s->center_mix_level);
else
- av_dlog(avctx, "center_mixlev: {not written}\n");
+ ff_dlog(avctx, "center_mixlev: {not written}\n");
if (s->has_surround)
- av_dlog(avctx, "surround_mixlev: %0.3f (%d)\n", opt->surround_mix_level,
+ ff_dlog(avctx, "surround_mixlev: %0.3f (%d)\n", opt->surround_mix_level,
s->surround_mix_level);
else
- av_dlog(avctx, "surround_mixlev: {not written}\n");
+ ff_dlog(avctx, "surround_mixlev: {not written}\n");
if (opt->audio_production_info) {
- av_dlog(avctx, "mixing_level: %ddB\n", opt->mixing_level);
+ ff_dlog(avctx, "mixing_level: %ddB\n", opt->mixing_level);
switch (opt->room_type) {
case AC3ENC_OPT_NOT_INDICATED: av_strlcpy(strbuf, "notindicated", 32); break;
case AC3ENC_OPT_LARGE_ROOM: av_strlcpy(strbuf, "large", 32); break;
case AC3ENC_OPT_SMALL_ROOM: av_strlcpy(strbuf, "small", 32); break;
default: snprintf(strbuf, 32, "ERROR (%d)", opt->room_type);
}
- av_dlog(avctx, "room_type: %s\n", strbuf);
+ ff_dlog(avctx, "room_type: %s\n", strbuf);
} else {
- av_dlog(avctx, "mixing_level: {not written}\n");
- av_dlog(avctx, "room_type: {not written}\n");
+ ff_dlog(avctx, "mixing_level: {not written}\n");
+ ff_dlog(avctx, "room_type: {not written}\n");
}
- av_dlog(avctx, "copyright: %s\n", opt->copyright?"on":"off");
- av_dlog(avctx, "dialnorm: %ddB\n", opt->dialogue_level);
+ ff_dlog(avctx, "copyright: %s\n", opt->copyright?"on":"off");
+ ff_dlog(avctx, "dialnorm: %ddB\n", opt->dialogue_level);
if (s->channel_mode == AC3_CHMODE_STEREO) {
switch (opt->dolby_surround_mode) {
case AC3ENC_OPT_NOT_INDICATED: av_strlcpy(strbuf, "notindicated", 32); break;
case AC3ENC_OPT_MODE_OFF: av_strlcpy(strbuf, "off", 32); break;
default: snprintf(strbuf, 32, "ERROR (%d)", opt->dolby_surround_mode);
}
- av_dlog(avctx, "dsur_mode: %s\n", strbuf);
+ ff_dlog(avctx, "dsur_mode: %s\n", strbuf);
} else {
- av_dlog(avctx, "dsur_mode: {not written}\n");
+ ff_dlog(avctx, "dsur_mode: {not written}\n");
}
- av_dlog(avctx, "original: %s\n", opt->original?"on":"off");
+ ff_dlog(avctx, "original: %s\n", opt->original?"on":"off");
if (s->bitstream_id == 6) {
if (opt->extended_bsi_1) {
case AC3ENC_OPT_DOWNMIX_LORO: av_strlcpy(strbuf, "loro", 32); break;
default: snprintf(strbuf, 32, "ERROR (%d)", opt->preferred_stereo_downmix);
}
- av_dlog(avctx, "dmix_mode: %s\n", strbuf);
- av_dlog(avctx, "ltrt_cmixlev: %0.3f (%d)\n",
+ ff_dlog(avctx, "dmix_mode: %s\n", strbuf);
+ ff_dlog(avctx, "ltrt_cmixlev: %0.3f (%d)\n",
opt->ltrt_center_mix_level, s->ltrt_center_mix_level);
- av_dlog(avctx, "ltrt_surmixlev: %0.3f (%d)\n",
+ ff_dlog(avctx, "ltrt_surmixlev: %0.3f (%d)\n",
opt->ltrt_surround_mix_level, s->ltrt_surround_mix_level);
- av_dlog(avctx, "loro_cmixlev: %0.3f (%d)\n",
+ ff_dlog(avctx, "loro_cmixlev: %0.3f (%d)\n",
opt->loro_center_mix_level, s->loro_center_mix_level);
- av_dlog(avctx, "loro_surmixlev: %0.3f (%d)\n",
+ ff_dlog(avctx, "loro_surmixlev: %0.3f (%d)\n",
opt->loro_surround_mix_level, s->loro_surround_mix_level);
} else {
- av_dlog(avctx, "extended bitstream info 1: {not written}\n");
+ ff_dlog(avctx, "extended bitstream info 1: {not written}\n");
}
if (opt->extended_bsi_2) {
switch (opt->dolby_surround_ex_mode) {
case AC3ENC_OPT_MODE_OFF: av_strlcpy(strbuf, "off", 32); break;
default: snprintf(strbuf, 32, "ERROR (%d)", opt->dolby_surround_ex_mode);
}
- av_dlog(avctx, "dsurex_mode: %s\n", strbuf);
+ ff_dlog(avctx, "dsurex_mode: %s\n", strbuf);
switch (opt->dolby_headphone_mode) {
case AC3ENC_OPT_NOT_INDICATED: av_strlcpy(strbuf, "notindicated", 32); break;
case AC3ENC_OPT_MODE_ON: av_strlcpy(strbuf, "on", 32); break;
case AC3ENC_OPT_MODE_OFF: av_strlcpy(strbuf, "off", 32); break;
default: snprintf(strbuf, 32, "ERROR (%d)", opt->dolby_headphone_mode);
}
- av_dlog(avctx, "dheadphone_mode: %s\n", strbuf);
+ ff_dlog(avctx, "dheadphone_mode: %s\n", strbuf);
switch (opt->ad_converter_type) {
case AC3ENC_OPT_ADCONV_STANDARD: av_strlcpy(strbuf, "standard", 32); break;
case AC3ENC_OPT_ADCONV_HDCD: av_strlcpy(strbuf, "hdcd", 32); break;
default: snprintf(strbuf, 32, "ERROR (%d)", opt->ad_converter_type);
}
- av_dlog(avctx, "ad_conv_type: %s\n", strbuf);
+ ff_dlog(avctx, "ad_conv_type: %s\n", strbuf);
} else {
- av_dlog(avctx, "extended bitstream info 2: {not written}\n");
+ ff_dlog(avctx, "extended bitstream info 2: {not written}\n");
}
}
-#endif
}
+#else
+#define dprint_options(x) do {} while(0)
+#endif
#define FLT_OPTION_THRESHOLD 0.01
return ret;
avctx->frame_size = AC3_BLOCK_SIZE * s->num_blocks;
- avctx->delay = AC3_BLOCK_SIZE;
+ avctx->initial_padding = AC3_BLOCK_SIZE;
s->bitstream_mode = avctx->audio_service_type;
if (s->bitstream_mode == AV_AUDIO_SERVICE_TYPE_KARAOKE)
if (ret)
goto init_fail;
- ff_dsputil_init(&s->dsp, avctx);
- avpriv_float_dsp_init(&s->fdsp, avctx->flags & CODEC_FLAG_BITEXACT);
- ff_ac3dsp_init(&s->ac3dsp, avctx->flags & CODEC_FLAG_BITEXACT);
+ ff_audiodsp_init(&s->adsp);
+ ff_me_cmp_init(&s->mecc, avctx);
+ ff_ac3dsp_init(&s->ac3dsp, avctx->flags & AV_CODEC_FLAG_BITEXACT);
dprint_options(s);