* The simplest AC-3 encoder.
*/
-//#define ASSERT_LEVEL 2
-
#include <stdint.h>
-#include "libavutil/audioconvert.h"
+#include "libavutil/attributes.h"
#include "libavutil/avassert.h"
#include "libavutil/avstring.h"
+#include "libavutil/channel_layout.h"
#include "libavutil/crc.h"
+#include "libavutil/internal.h"
#include "libavutil/opt.h"
#include "avcodec.h"
+#include "me_cmp.h"
#include "put_bits.h"
-#include "dsputil.h"
+#include "audiodsp.h"
#include "ac3dsp.h"
#include "ac3.h"
-#include "audioconvert.h"
#include "fft.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;
* bit allocation parameters do not change between blocks
* no delta bit allocation
* no skipped data
- * no auxilliary data
+ * no auxiliary data
* no E-AC-3 metadata
*/
* 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;
s->mdct_end(s);
- av_freep(&avctx->coded_frame);
return 0;
}
return AVERROR(EINVAL);
ch_layout = *channel_layout;
if (!ch_layout)
- ch_layout = avcodec_guess_channel_layout(channels, CODEC_ID_AC3, NULL);
+ ch_layout = av_get_default_channel_layout(channels);
s->lfe_on = !!(ch_layout & AV_CH_LOW_FREQUENCY);
s->channels = channels;
s->bit_alloc.sr_code = i % 3;
s->bitstream_id = s->eac3 ? 16 : 8 + s->bit_alloc.sr_shift;
+ /* select a default bit rate if not set by the user */
+ if (!avctx->bit_rate) {
+ switch (s->fbw_channels) {
+ case 1: avctx->bit_rate = 96000; break;
+ case 2: avctx->bit_rate = 192000; break;
+ case 3: avctx->bit_rate = 320000; break;
+ case 4: avctx->bit_rate = 384000; break;
+ case 5: avctx->bit_rate = 448000; break;
+ }
+ }
+
/* validate bit rate */
if (s->eac3) {
int max_br, min_br, wpf, min_br_dist, min_br_code;
s->avctx = avctx;
- s->eac3 = avctx->codec_id == CODEC_ID_EAC3;
+ s->eac3 = avctx->codec_id == AV_CODEC_ID_EAC3;
ff_ac3_common_init();
return ret;
avctx->frame_size = AC3_BLOCK_SIZE * s->num_blocks;
+ avctx->delay = AC3_BLOCK_SIZE;
s->bitstream_mode = avctx->audio_service_type;
if (s->bitstream_mode == AV_AUDIO_SERVICE_TYPE_KARAOKE)
if (ret)
goto init_fail;
- avctx->coded_frame= avcodec_alloc_frame();
-
- ff_dsputil_init(&s->dsp, avctx);
+ ff_audiodsp_init(&s->adsp);
+ ff_me_cmp_init(&s->mecc, avctx);
ff_ac3dsp_init(&s->ac3dsp, avctx->flags & CODEC_FLAG_BITEXACT);
dprint_options(s);