ffmpeg/libavcodec/ac3enc_combined.c
Michael Niedermayer b8a43bc1b5 Merge remote-tracking branch 'qatar/master' into master
* qatar/master: (27 commits)
  ac3enc: fix LOCAL_ALIGNED usage in count_mantissa_bits()
  ac3dsp: do not use the ff_* prefix when referencing ff_ac3_bap_bits.
  ac3dsp: fix loop condition in ac3_update_bap_counts_c()
  ARM: unbreak build
  ac3enc: modify mantissa bit counting to keep bap counts for all values of bap instead of just 0 to 4.
  ac3enc: split mantissa bit counting into a separate function.
  ac3enc: store per-block/channel bap pointers by reference block in a 2D array rather than in the AC3Block struct.
  get_bits: add av_unused tag to cache variable
  sws: replace all long with int.
  ARM: aacdec: fix constraints on inline asm
  ARM: remove unnecessary volatile from inline asm
  ARM: add "cc" clobbers to inline asm where needed
  ARM: improve FASTDIV asm
  ac3enc: use LOCAL_ALIGNED macro
  APIchanges: fill in git hash for av_get_pix_fmt_name (0420bd7).
  lavu: add av_get_pix_fmt_name() convenience function
  cmdutils: remove OPT_FUNC2
  swscale: fix crash in bilinear scaling.
  vpxenc: add VP8E_SET_STATIC_THRESHOLD mapping
  webm: support stereo videos in matroska/webm muxer
  ...

Conflicts:
	Changelog
	cmdutils.c
	cmdutils.h
	doc/APIchanges
	doc/muxers.texi
	ffmpeg.c
	ffplay.c
	libavcodec/ac3enc.c
	libavcodec/ac3enc_float.c
	libavcodec/avcodec.h
	libavcodec/get_bits.h
	libavcodec/libvpxenc.c
	libavcodec/version.h
	libavdevice/libdc1394.c
	libavformat/matroskaenc.c
	libavutil/avutil.h
	libswscale/rgb2rgb.c
	libswscale/swscale.c
	libswscale/swscale_template.c
	libswscale/x86/swscale_template.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
2011-05-29 03:34:35 +02:00

101 lines
2.7 KiB
C

#include "libavutil/opt.h"
#include "libavutil/samplefmt.h"
#include "avcodec.h"
#include "ac3.h"
typedef struct CombineContext{
AVClass *av_class; ///< AVClass used for AVOption
AC3EncOptions options; ///< encoding options
void *ctx;
AVCodec *codec;
}CombineContext;
#define OFFSET(param) offsetof(CombineContext, options.param)
#define AC3ENC_PARAM (AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM)
#define AC3ENC_TYPE_AC3_FIXED 0
#define AC3ENC_TYPE_AC3 1
#define AC3ENC_TYPE_EAC3 2
#define AC3ENC_TYPE 12354
#include "ac3enc_opts_template.c"
static AVClass ac3enc_class = { "AC-3 Encoder", av_default_item_name,
eac3_options, LIBAVUTIL_VERSION_INT };
static av_cold AVCodec *get_codec(enum AVSampleFormat s){
#if CONFIG_AC3_FIXED_ENCODER
if(s==AV_SAMPLE_FMT_S16) return &ff_ac3_fixed_encoder;
#endif
#if CONFIG_AC3_FLOAT_ENCODER
if(s==AV_SAMPLE_FMT_FLT) return &ff_ac3_float_encoder;
#endif
return NULL;
}
static av_cold int encode_init(AVCodecContext *avctx)
{
CombineContext *c= avctx->priv_data;
int ret;
int offset= (uint8_t*)&c->options - (uint8_t*)c;
c->codec= get_codec(avctx->sample_fmt);
if(!c->codec){
av_log(avctx, AV_LOG_ERROR, "Unsupported sample format\n");
return -1;
}
c->ctx= av_mallocz(c->codec->priv_data_size);
memcpy((uint8_t*)c->ctx + offset, &c->options, (uint8_t*)&c->ctx - (uint8_t*)&c->options);
FFSWAP(void *,avctx->priv_data, c->ctx);
ret= c->codec->init(avctx);
FFSWAP(void *,avctx->priv_data, c->ctx);
return ret;
}
static int encode_frame(AVCodecContext *avctx, unsigned char *frame,
int buf_size, void *data)
{
CombineContext *c= avctx->priv_data;
int ret;
FFSWAP(void *,avctx->priv_data, c->ctx);
ret= c->codec->encode(avctx, frame, buf_size, data);
FFSWAP(void *,avctx->priv_data, c->ctx);
return ret;
}
static av_cold int encode_close(AVCodecContext *avctx)
{
CombineContext *c= avctx->priv_data;
int ret;
FFSWAP(void *,avctx->priv_data, c->ctx);
ret= c->codec->close(avctx);
FFSWAP(void *,avctx->priv_data, c->ctx);
return ret;
}
AVCodec ff_ac3_encoder = {
"ac3",
AVMEDIA_TYPE_AUDIO,
CODEC_ID_AC3,
sizeof(CombineContext),
encode_init,
encode_frame,
encode_close,
NULL,
.sample_fmts = (const enum AVSampleFormat[]){
#if CONFIG_AC3_FLOAT_ENCODER
AV_SAMPLE_FMT_FLT,
#endif
#if CONFIG_AC3_FIXED_ENCODER
AV_SAMPLE_FMT_S16,
#endif
AV_SAMPLE_FMT_NONE},
.long_name = NULL_IF_CONFIG_SMALL("ATSC A/52A (AC-3)"),
.priv_class = &ac3enc_class,
.channel_layouts = ff_ac3_channel_layouts,
};