2 #include "libavutil/opt.h"
3 #include "libavutil/samplefmt.h"
7 typedef struct CombineContext{
8 AVClass *av_class; ///< AVClass used for AVOption
9 AC3EncOptions options; ///< encoding options
14 #define OFFSET(param) offsetof(CombineContext, options.param)
15 #define AC3ENC_PARAM (AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
17 #define AC3ENC_TYPE_AC3_FIXED 0
18 #define AC3ENC_TYPE_AC3 1
19 #define AC3ENC_TYPE_EAC3 2
21 #define AC3ENC_TYPE 12354
23 /* common option values */
24 #define AC3ENC_OPT_NONE -1
25 #define AC3ENC_OPT_AUTO -1
26 #define AC3ENC_OPT_OFF 0
27 #define AC3ENC_OPT_ON 1
28 #define AC3ENC_OPT_NOT_INDICATED 0
29 #define AC3ENC_OPT_MODE_ON 1
30 #define AC3ENC_OPT_MODE_OFF 2
32 /* specific option values */
33 #define AC3ENC_OPT_LARGE_ROOM 1
34 #define AC3ENC_OPT_SMALL_ROOM 2
35 #define AC3ENC_OPT_DOWNMIX_LTRT 1
36 #define AC3ENC_OPT_DOWNMIX_LORO 2
37 #define AC3ENC_OPT_ADCONV_STANDARD 0
38 #define AC3ENC_OPT_ADCONV_HDCD 1
40 #include "ac3enc_opts_template.c"
42 static AVClass ac3enc_class = { "AC-3 Encoder", av_default_item_name,
43 eac3_options, LIBAVUTIL_VERSION_INT };
45 static av_cold AVCodec *get_codec(enum AVSampleFormat s){
46 #if CONFIG_AC3_FIXED_ENCODER
47 if(s==AV_SAMPLE_FMT_S16) return &ff_ac3_fixed_encoder;
49 #if CONFIG_AC3_FLOAT_ENCODER
50 if(s==AV_SAMPLE_FMT_FLT) return &ff_ac3_float_encoder;
56 static av_cold int encode_init(AVCodecContext *avctx)
58 CombineContext *c= avctx->priv_data;
60 int offset= (uint8_t*)&c->options - (uint8_t*)c;
62 c->codec= get_codec(avctx->sample_fmt);
64 av_log(avctx, AV_LOG_ERROR, "Unsupported sample format\n");
67 c->ctx= av_mallocz(c->codec->priv_data_size);
68 memcpy((uint8_t*)c->ctx + offset, &c->options, (uint8_t*)&c->ctx - (uint8_t*)&c->options);
69 FFSWAP(void *,avctx->priv_data, c->ctx);
70 ret= c->codec->init(avctx);
71 FFSWAP(void *,avctx->priv_data, c->ctx);
75 static int encode_frame(AVCodecContext *avctx, unsigned char *frame,
76 int buf_size, void *data)
78 CombineContext *c= avctx->priv_data;
81 FFSWAP(void *,avctx->priv_data, c->ctx);
82 ret= c->codec->encode(avctx, frame, buf_size, data);
83 FFSWAP(void *,avctx->priv_data, c->ctx);
87 static av_cold int encode_close(AVCodecContext *avctx)
89 CombineContext *c= avctx->priv_data;
92 FFSWAP(void *,avctx->priv_data, c->ctx);
93 ret= c->codec->close(avctx);
94 FFSWAP(void *,avctx->priv_data, c->ctx);
98 AVCodec ff_ac3_encoder = {
102 sizeof(CombineContext),
107 .sample_fmts = (const enum AVSampleFormat[]){
108 #if CONFIG_AC3_FLOAT_ENCODER
111 #if CONFIG_AC3_FIXED_ENCODER
115 .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"),
116 .priv_class = &ac3enc_class,
117 .channel_layouts = ff_ac3_channel_layouts,