FFmpeg
Data Structures | Macros | Typedefs | Functions | Variables
dcaenc.c File Reference
#include "libavutil/avassert.h"
#include "libavutil/channel_layout.h"
#include "libavutil/common.h"
#include "libavutil/ffmath.h"
#include "libavutil/mem_internal.h"
#include "libavutil/opt.h"
#include "libavutil/thread.h"
#include "libavutil/tx.h"
#include "avcodec.h"
#include "codec_internal.h"
#include "dca.h"
#include "dcaadpcm.h"
#include "dcamath.h"
#include "dca_core.h"
#include "dcadata.h"
#include "dcaenc.h"
#include "encode.h"
#include "put_bits.h"

Go to the source code of this file.

Data Structures

struct  CompressionOptions
 
struct  DCAEncContext
 

Macros

#define MAX_CHANNELS   6
 
#define DCA_MAX_FRAME_SIZE   16384
 
#define DCA_HEADER_SIZE   13
 
#define DCA_LFE_SAMPLES   8
 
#define DCAENC_SUBBANDS   32
 
#define SUBFRAMES   1
 
#define SUBSUBFRAMES   2
 
#define SUBBAND_SAMPLES   (SUBFRAMES * SUBSUBFRAMES * 8)
 
#define AUBANDS   25
 
#define COS_T(x)   (c->cos_table[(x) & 2047])
 
#define USED_1ABITS   1
 
#define USED_26ABITS   4
 
#define DCAENC_FLAGS   AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM
 

Typedefs

typedef void(* walk_band_t) (DCAEncContext *c, int band1, int band2, int f, int32_t spectrum1, int32_t spectrum2, int channel, int32_t *arg)
 

Functions

static double hom (double f)
 
static double gammafilter (int i, double f)
 
static int subband_bufer_alloc (DCAEncContext *c)
 
static void subband_bufer_free (DCAEncContext *c)
 
static av_cold void create_enc_table (uint16_t dst[][2], unsigned count, const uint8_t(**src_tablep)[2])
 
static av_cold void dcaenc_init_static_tables (void)
 
static int encode_init (AVCodecContext *avctx)
 
static av_cold int encode_close (AVCodecContext *avctx)
 
static void subband_transform (DCAEncContext *c, const int32_t *input)
 
static void lfe_downsample (DCAEncContext *c, const int32_t *input)
 
static uint32_t dca_vlc_calc_alloc_bits (const int values[], uint8_t n, uint8_t sel)
 
static void dca_vlc_enc_alloc (PutBitContext *pb, const int values[], uint8_t n, uint8_t sel)
 
static uint32_t dca_vlc_calc_quant_bits (const int values[], uint8_t n, uint8_t sel, uint8_t table)
 
static void dca_vlc_enc_quant (PutBitContext *pb, const int values[], uint8_t n, uint8_t sel, uint8_t table)
 
static int32_t get_cb (DCAEncContext *c, int32_t in)
 
static int32_t add_cb (DCAEncContext *c, int32_t a, int32_t b)
 
static void calc_power (DCAEncContext *c, const int32_t in[2 *256], int32_t power[256])
 
static void adjust_jnd (DCAEncContext *c, const int32_t in[512], int32_t out_cb[256])
 
static void walk_band_low (DCAEncContext *c, int band, int channel, walk_band_t walk, int32_t *arg)
 
static void walk_band_high (DCAEncContext *c, int band, int channel, walk_band_t walk, int32_t *arg)
 
static void update_band_masking (DCAEncContext *c, int band1, int band2, int f, int32_t spectrum1, int32_t spectrum2, int channel, int32_t *arg)
 
static void calc_masking (DCAEncContext *c, const int32_t *input)
 
static int32_t find_peak (DCAEncContext *c, const int32_t *in, int len)
 
static void find_peaks (DCAEncContext *c)
 
static void adpcm_analysis (DCAEncContext *c)
 
static int32_t get_step_size (DCAEncContext *c, int ch, int band)
 
static int calc_one_scale (DCAEncContext *c, int32_t peak_cb, int abits, softfloat *quant)
 
static void quantize_adpcm_subband (DCAEncContext *c, int ch, int band)
 
static void quantize_adpcm (DCAEncContext *c)
 
static void quantize_pcm (DCAEncContext *c)
 
static void accumulate_huff_bit_consumption (int abits, int32_t *quantized, uint32_t *result)
 
static uint32_t set_best_code (uint32_t vlc_bits[DCA_CODE_BOOKS][7], uint32_t clc_bits[DCA_CODE_BOOKS], int32_t res[DCA_CODE_BOOKS])
 
static uint32_t set_best_abits_code (int abits[DCAENC_SUBBANDS], int bands, int32_t *res)
 
static int init_quantization_noise (DCAEncContext *c, int noise, int forbid_zero)
 
static void assign_bits (DCAEncContext *c)
 
static void shift_history (DCAEncContext *c, const int32_t *input)
 
static void fill_in_adpcm_bufer (DCAEncContext *c)
 
static void calc_lfe_scales (DCAEncContext *c)
 
static void put_frame_header (DCAEncContext *c)
 
static void put_primary_audio_header (DCAEncContext *c)
 
static void put_subframe_samples (DCAEncContext *c, int ss, int band, int ch)
 
static void put_subframe (DCAEncContext *c, int subframe)
 
static int encode_frame (AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
 

Variables

static uint16_t bitalloc_12_table [DCA_BITALLOC_12_COUNT][12+1][2]
 
static uint16_t bitalloc_table [DCA_NUM_BITALLOC_CODES][2]
 
static const uint16_t(*[DCA_CODE_BOOKS][8] bitalloc_tables )[2]
 
static const int snr_fudge = 128
 
static const AVOption options []
 
static const AVClass dcaenc_class
 
static const FFCodecDefault defaults []
 
const FFCodec ff_dca_encoder
 

Macro Definition Documentation

◆ MAX_CHANNELS

#define MAX_CHANNELS   6

Definition at line 43 of file dcaenc.c.

◆ DCA_MAX_FRAME_SIZE

#define DCA_MAX_FRAME_SIZE   16384

Definition at line 44 of file dcaenc.c.

◆ DCA_HEADER_SIZE

#define DCA_HEADER_SIZE   13

Definition at line 45 of file dcaenc.c.

◆ DCA_LFE_SAMPLES

#define DCA_LFE_SAMPLES   8

Definition at line 46 of file dcaenc.c.

◆ DCAENC_SUBBANDS

#define DCAENC_SUBBANDS   32

Definition at line 48 of file dcaenc.c.

◆ SUBFRAMES

#define SUBFRAMES   1

Definition at line 49 of file dcaenc.c.

◆ SUBSUBFRAMES

#define SUBSUBFRAMES   2

Definition at line 50 of file dcaenc.c.

◆ SUBBAND_SAMPLES

#define SUBBAND_SAMPLES   (SUBFRAMES * SUBSUBFRAMES * 8)

Definition at line 51 of file dcaenc.c.

◆ AUBANDS

#define AUBANDS   25

Definition at line 52 of file dcaenc.c.

◆ COS_T

#define COS_T (   x)    (c->cos_table[(x) & 2047])

Definition at line 54 of file dcaenc.c.

◆ USED_1ABITS

#define USED_1ABITS   1

Definition at line 675 of file dcaenc.c.

◆ USED_26ABITS

#define USED_26ABITS   4

Definition at line 676 of file dcaenc.c.

◆ DCAENC_FLAGS

Definition at line 1294 of file dcaenc.c.

Typedef Documentation

◆ walk_band_t

typedef void(* walk_band_t) (DCAEncContext *c, int band1, int band2, int f, int32_t spectrum1, int32_t spectrum2, int channel, int32_t *arg)

Definition at line 545 of file dcaenc.c.

Function Documentation

◆ hom()

static double hom ( double  f)
static

Definition at line 113 of file dcaenc.c.

Referenced by encode_init().

◆ gammafilter()

static double gammafilter ( int  i,
double  f 
)
static

Definition at line 123 of file dcaenc.c.

Referenced by encode_init().

◆ subband_bufer_alloc()

static int subband_bufer_alloc ( DCAEncContext c)
static

Definition at line 132 of file dcaenc.c.

Referenced by encode_init().

◆ subband_bufer_free()

static void subband_bufer_free ( DCAEncContext c)
static

Definition at line 153 of file dcaenc.c.

Referenced by encode_close().

◆ create_enc_table()

static av_cold void create_enc_table ( uint16_t  dst[][2],
unsigned  count,
const uint8_t(**)  src_tablep[2] 
)
static

Definition at line 167 of file dcaenc.c.

Referenced by dcaenc_init_static_tables().

◆ dcaenc_init_static_tables()

static av_cold void dcaenc_init_static_tables ( void  )
static

Definition at line 184 of file dcaenc.c.

Referenced by encode_init().

◆ encode_init()

static int encode_init ( AVCodecContext avctx)
static

Definition at line 202 of file dcaenc.c.

◆ encode_close()

static av_cold int encode_close ( AVCodecContext avctx)
static

Definition at line 354 of file dcaenc.c.

◆ subband_transform()

static void subband_transform ( DCAEncContext c,
const int32_t input 
)
static

Definition at line 364 of file dcaenc.c.

Referenced by encode_frame().

◆ lfe_downsample()

static void lfe_downsample ( DCAEncContext c,
const int32_t input 
)
static

Definition at line 414 of file dcaenc.c.

Referenced by encode_frame().

◆ dca_vlc_calc_alloc_bits()

static uint32_t dca_vlc_calc_alloc_bits ( const int  values[],
uint8_t  n,
uint8_t  sel 
)
static

Definition at line 444 of file dcaenc.c.

Referenced by set_best_abits_code().

◆ dca_vlc_enc_alloc()

static void dca_vlc_enc_alloc ( PutBitContext pb,
const int  values[],
uint8_t  n,
uint8_t  sel 
)
static

Definition at line 452 of file dcaenc.c.

Referenced by put_subframe().

◆ dca_vlc_calc_quant_bits()

static uint32_t dca_vlc_calc_quant_bits ( const int  values[],
uint8_t  n,
uint8_t  sel,
uint8_t  table 
)
static

Definition at line 460 of file dcaenc.c.

Referenced by accumulate_huff_bit_consumption().

◆ dca_vlc_enc_quant()

static void dca_vlc_enc_quant ( PutBitContext pb,
const int  values[],
uint8_t  n,
uint8_t  sel,
uint8_t  table 
)
static

Definition at line 469 of file dcaenc.c.

Referenced by put_subframe_samples().

◆ get_cb()

static int32_t get_cb ( DCAEncContext c,
int32_t  in 
)
static

Definition at line 477 of file dcaenc.c.

Referenced by calc_power(), and find_peak().

◆ add_cb()

static int32_t add_cb ( DCAEncContext c,
int32_t  a,
int32_t  b 
)
static

Definition at line 489 of file dcaenc.c.

Referenced by adjust_jnd(), and calc_power().

◆ calc_power()

static void calc_power ( DCAEncContext c,
const int32_t  in[2 *256],
int32_t  power[256] 
)
static

Definition at line 499 of file dcaenc.c.

Referenced by adjust_jnd().

◆ adjust_jnd()

static void adjust_jnd ( DCAEncContext c,
const int32_t  in[512],
int32_t  out_cb[256] 
)
static

Definition at line 516 of file dcaenc.c.

Referenced by calc_masking().

◆ walk_band_low()

static void walk_band_low ( DCAEncContext c,
int  band,
int  channel,
walk_band_t  walk,
int32_t arg 
)
static

Definition at line 549 of file dcaenc.c.

Referenced by calc_masking().

◆ walk_band_high()

static void walk_band_high ( DCAEncContext c,
int  band,
int  channel,
walk_band_t  walk,
int32_t arg 
)
static

Definition at line 564 of file dcaenc.c.

Referenced by calc_masking().

◆ update_band_masking()

static void update_band_masking ( DCAEncContext c,
int  band1,
int  band2,
int  f,
int32_t  spectrum1,
int32_t  spectrum2,
int  channel,
int32_t arg 
)
static

Definition at line 579 of file dcaenc.c.

Referenced by calc_masking().

◆ calc_masking()

static void calc_masking ( DCAEncContext c,
const int32_t input 
)
static

Definition at line 589 of file dcaenc.c.

Referenced by encode_frame().

◆ find_peak()

static int32_t find_peak ( DCAEncContext c,
const int32_t in,
int  len 
)
inlinestatic

Definition at line 624 of file dcaenc.c.

Referenced by adpcm_analysis(), and find_peaks().

◆ find_peaks()

static void find_peaks ( DCAEncContext c)
static

Definition at line 636 of file dcaenc.c.

Referenced by encode_frame().

◆ adpcm_analysis()

static void adpcm_analysis ( DCAEncContext c)
static

Definition at line 650 of file dcaenc.c.

Referenced by encode_frame().

◆ get_step_size()

static int32_t get_step_size ( DCAEncContext c,
int  ch,
int  band 
)
inlinestatic

Definition at line 678 of file dcaenc.c.

Referenced by fill_in_adpcm_bufer(), and quantize_adpcm_subband().

◆ calc_one_scale()

static int calc_one_scale ( DCAEncContext c,
int32_t  peak_cb,
int  abits,
softfloat quant 
)
static

Definition at line 690 of file dcaenc.c.

Referenced by calc_lfe_scales(), init_quantization_noise(), and quantize_adpcm_subband().

◆ quantize_adpcm_subband()

static void quantize_adpcm_subband ( DCAEncContext c,
int  ch,
int  band 
)
inlinestatic

Definition at line 723 of file dcaenc.c.

Referenced by quantize_adpcm().

◆ quantize_adpcm()

static void quantize_adpcm ( DCAEncContext c)
static

Definition at line 740 of file dcaenc.c.

Referenced by init_quantization_noise().

◆ quantize_pcm()

static void quantize_pcm ( DCAEncContext c)
static

Definition at line 750 of file dcaenc.c.

Referenced by init_quantization_noise().

◆ accumulate_huff_bit_consumption()

static void accumulate_huff_bit_consumption ( int  abits,
int32_t quantized,
uint32_t *  result 
)
static

Definition at line 767 of file dcaenc.c.

Referenced by init_quantization_noise().

◆ set_best_code()

static uint32_t set_best_code ( uint32_t  vlc_bits[DCA_CODE_BOOKS][7],
uint32_t  clc_bits[DCA_CODE_BOOKS],
int32_t  res[DCA_CODE_BOOKS] 
)
static

Definition at line 776 of file dcaenc.c.

Referenced by init_quantization_noise().

◆ set_best_abits_code()

static uint32_t set_best_abits_code ( int  abits[DCAENC_SUBBANDS],
int  bands,
int32_t res 
)
static

Definition at line 817 of file dcaenc.c.

Referenced by init_quantization_noise().

◆ init_quantization_noise()

static int init_quantization_noise ( DCAEncContext c,
int  noise,
int  forbid_zero 
)
static

Definition at line 845 of file dcaenc.c.

Referenced by assign_bits().

◆ assign_bits()

static void assign_bits ( DCAEncContext c)
static

Definition at line 924 of file dcaenc.c.

Referenced by encode_frame().

◆ shift_history()

static void shift_history ( DCAEncContext c,
const int32_t input 
)
static

Definition at line 966 of file dcaenc.c.

Referenced by encode_frame().

◆ fill_in_adpcm_bufer()

static void fill_in_adpcm_bufer ( DCAEncContext c)
static

Definition at line 978 of file dcaenc.c.

Referenced by encode_frame().

◆ calc_lfe_scales()

static void calc_lfe_scales ( DCAEncContext c)
static

Definition at line 1014 of file dcaenc.c.

Referenced by encode_frame().

◆ put_frame_header()

static void put_frame_header ( DCAEncContext c)
static

Definition at line 1020 of file dcaenc.c.

Referenced by encode_frame().

◆ put_primary_audio_header()

static void put_primary_audio_header ( DCAEncContext c)
static

Definition at line 1103 of file dcaenc.c.

Referenced by encode_frame().

◆ put_subframe_samples()

static void put_subframe_samples ( DCAEncContext c,
int  ss,
int  band,
int  ch 
)
static

Definition at line 1150 of file dcaenc.c.

Referenced by put_subframe().

◆ put_subframe()

static void put_subframe ( DCAEncContext c,
int  subframe 
)
static

Definition at line 1184 of file dcaenc.c.

Referenced by encode_frame().

◆ encode_frame()

static int encode_frame ( AVCodecContext avctx,
AVPacket avpkt,
const AVFrame frame,
int got_packet_ptr 
)
static

Definition at line 1256 of file dcaenc.c.

Variable Documentation

◆ bitalloc_12_table

uint16_t bitalloc_12_table[DCA_BITALLOC_12_COUNT][12+1][2]
static

Definition at line 162 of file dcaenc.c.

Referenced by dca_vlc_calc_alloc_bits(), dca_vlc_enc_alloc(), and dcaenc_init_static_tables().

◆ bitalloc_table

uint16_t bitalloc_table[DCA_NUM_BITALLOC_CODES][2]
static

Definition at line 164 of file dcaenc.c.

Referenced by dcaenc_init_static_tables().

◆ bitalloc_tables

const uint16_t(*[DCA_CODE_BOOKS][8] bitalloc_tables)[2]
static

Definition at line 165 of file dcaenc.c.

Referenced by dca_vlc_calc_quant_bits(), dca_vlc_enc_quant(), and dcaenc_init_static_tables().

◆ snr_fudge

const int snr_fudge = 128
static

Definition at line 674 of file dcaenc.c.

Referenced by assign_bits().

◆ options

const AVOption options[]
static
Initial value:
= {
{ "dca_adpcm", "Use ADPCM encoding", 0x42, AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, DCAENC_FLAGS },
{ NULL },
}

Definition at line 1296 of file dcaenc.c.

◆ dcaenc_class

const AVClass dcaenc_class
static
Initial value:
= {
.class_name = "DCA (DTS Coherent Acoustics)",
.item_name = av_default_item_name,
.option = options,
}

Definition at line 1301 of file dcaenc.c.

◆ defaults

const FFCodecDefault defaults[]
static
Initial value:
= {
{ "b", "1411200" },
{ NULL },
}

Definition at line 1308 of file dcaenc.c.

◆ ff_dca_encoder

const FFCodec ff_dca_encoder
Initial value:

Definition at line 1313 of file dcaenc.c.

FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
AV_CHANNEL_LAYOUT_STEREO
#define AV_CHANNEL_LAYOUT_STEREO
Definition: channel_layout.h:369
options
static const AVOption options[]
Definition: dcaenc.c:1296
AV_CH_LAYOUT_MONO
#define AV_CH_LAYOUT_MONO
Definition: channel_layout.h:210
AV_CHANNEL_LAYOUT_2_2
#define AV_CHANNEL_LAYOUT_2_2
Definition: channel_layout.h:376
encode_frame
static int encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Definition: dcaenc.c:1256
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:315
AV_CH_LAYOUT_STEREO
#define AV_CH_LAYOUT_STEREO
Definition: channel_layout.h:211
AV_CODEC_CAP_EXPERIMENTAL
#define AV_CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
Definition: codec.h:105
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:365
AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This codec takes the reordered_opaque field from input AVFrames and returns it in the corresponding f...
Definition: codec.h:176
CODEC_OLD_CHANNEL_LAYOUTS
#define CODEC_OLD_CHANNEL_LAYOUTS(...)
Definition: codec_internal.h:302
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
NULL
#define NULL
Definition: coverity.c:32
av_default_item_name
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:237
AV_CH_LAYOUT_5POINT1
#define AV_CH_LAYOUT_5POINT1
Definition: channel_layout.h:221
defaults
static const FFCodecDefault defaults[]
Definition: dcaenc.c:1308
encode_close
static av_cold int encode_close(AVCodecContext *avctx)
Definition: dcaenc.c:354
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:301
AV_CODEC_ID_DTS
@ AV_CODEC_ID_DTS
Definition: codec_id.h:441
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
encode_init
static int encode_init(AVCodecContext *avctx)
Definition: dcaenc.c:202
sample_rates
sample_rates
Definition: ffmpeg_filter.c:156
AV_CH_LAYOUT_5POINT0
#define AV_CH_LAYOUT_5POINT0
Definition: channel_layout.h:220
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
DCAEncContext
Definition: dcaenc.c:60
AV_CHANNEL_LAYOUT_MONO
#define AV_CHANNEL_LAYOUT_MONO
Definition: channel_layout.h:368
AV_OPT_TYPE_BOOL
@ AV_OPT_TYPE_BOOL
Definition: opt.h:244
AV_CHANNEL_LAYOUT_5POINT0
#define AV_CHANNEL_LAYOUT_5POINT0
Definition: channel_layout.h:378
AV_CHANNEL_LAYOUT_5POINT1
#define AV_CHANNEL_LAYOUT_5POINT1
Definition: channel_layout.h:379
AV_SAMPLE_FMT_S32
@ AV_SAMPLE_FMT_S32
signed 32 bits
Definition: samplefmt.h:59
AV_CH_LAYOUT_2_2
#define AV_CH_LAYOUT_2_2
Definition: channel_layout.h:218
DCAENC_FLAGS
#define DCAENC_FLAGS
Definition: dcaenc.c:1294
dcaenc_class
static const AVClass dcaenc_class
Definition: dcaenc.c:1301