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 static AVClass ac3enc_class = { "AC-3 Encoder", av_default_item_name,
15 ff_ac3_options, LIBAVUTIL_VERSION_INT };
17 static av_cold AVCodec *get_codec(enum AVSampleFormat s){
18 #if CONFIG_AC3_FIXED_ENCODER
19 if(s==AV_SAMPLE_FMT_S16) return &ff_ac3_fixed_encoder;
21 #if CONFIG_AC3_FLOAT_ENCODER
22 if(s==AV_SAMPLE_FMT_FLT) return &ff_ac3_float_encoder;
28 static av_cold int encode_init(AVCodecContext *avctx)
30 CombineContext *c= avctx->priv_data;
32 int offset= (uint8_t*)&c->options - (uint8_t*)c;
34 c->codec= get_codec(avctx->sample_fmt);
36 av_log(avctx, AV_LOG_ERROR, "Unsupported sample format\n");
39 c->ctx= av_mallocz(c->codec->priv_data_size);
40 memcpy((uint8_t*)c->ctx + offset, &c->options, (uint8_t*)&c->ctx - (uint8_t*)&c->options);
41 FFSWAP(void *,avctx->priv_data, c->ctx);
42 ret= c->codec->init(avctx);
43 FFSWAP(void *,avctx->priv_data, c->ctx);
47 static int encode_frame(AVCodecContext *avctx, unsigned char *frame,
48 int buf_size, void *data)
50 CombineContext *c= avctx->priv_data;
53 FFSWAP(void *,avctx->priv_data, c->ctx);
54 ret= c->codec->encode(avctx, frame, buf_size, data);
55 FFSWAP(void *,avctx->priv_data, c->ctx);
59 static av_cold int encode_close(AVCodecContext *avctx)
61 CombineContext *c= avctx->priv_data;
64 FFSWAP(void *,avctx->priv_data, c->ctx);
65 ret= c->codec->close(avctx);
66 FFSWAP(void *,avctx->priv_data, c->ctx);
70 AVCodec ff_ac3_encoder = {
74 sizeof(CombineContext),
79 .sample_fmts = (const enum AVSampleFormat[]){
80 #if CONFIG_AC3_FLOAT_ENCODER
83 #if CONFIG_AC3_FIXED_ENCODER
87 .long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"),
88 .priv_class = &ac3enc_class,
89 .channel_layouts = ff_ac3_channel_layouts,