aaccoder.c File Reference

AAC coefficients encoder. More...

#include "libavutil/libm.h"
#include <float.h>
#include "libavutil/mathematics.h"
#include "avcodec.h"
#include "put_bits.h"
#include "aac.h"
#include "aacenc.h"
#include "aactab.h"
Include dependency graph for aaccoder.c:

Go to the source code of this file.

Data Structures

struct  BandCodingPath
 structure used in optimal codebook search More...
 
struct  TrellisPath
 

Macros

#define QUANTIZE_AND_ENCODE_BAND_COST_FUNC(NAME, BT_ZERO, BT_UNSIGNED, BT_PAIR, BT_ESC)
 
#define quantize_and_encode_band_cost(s, pb, in, scaled, size, scale_idx, cb, lambda, uplim, bits)
 
#define TRELLIS_STAGES   121
 
#define TRELLIS_STATES   (SCALE_MAX_DIFF+1)
 

Typedefs

typedef struct BandCodingPath BandCodingPath
 structure used in optimal codebook search More...
 
typedef struct TrellisPath TrellisPath
 

Functions

static av_always_inline int quant (float coef, const float Q)
 Quantize one coefficient. More...
 
static void quantize_bands (int *out, const float *in, const float *scaled, int size, float Q34, int is_signed, int maxval)
 
static void abs_pow34_v (float *out, const float *in, const int size)
 
static av_always_inline float quantize_and_encode_band_cost_template (struct AACEncContext *s, PutBitContext *pb, const float *in, const float *scaled, int size, int scale_idx, int cb, const float lambda, const float uplim, int *bits, int BT_ZERO, int BT_UNSIGNED, int BT_PAIR, int BT_ESC)
 Calculate rate distortion cost for quantizing with given codebook. More...
 
static float quantize_band_cost (struct AACEncContext *s, const float *in, const float *scaled, int size, int scale_idx, int cb, const float lambda, const float uplim, int *bits)
 
static void quantize_and_encode_band (struct AACEncContext *s, PutBitContext *pb, const float *in, int size, int scale_idx, int cb, const float lambda)
 
static float find_max_val (int group_len, int swb_size, const float *scaled)
 
static int find_min_book (float maxval, int sf)
 
static void encode_window_bands_info (AACEncContext *s, SingleChannelElement *sce, int win, int group_len, const float lambda)
 Encode band info for single window group bands. More...
 
static void codebook_trellis_rate (AACEncContext *s, SingleChannelElement *sce, int win, int group_len, const float lambda)
 
static av_always_inline uint8_t coef2minsf (float coef)
 Return the minimum scalefactor where the quantized coef does not clip. More...
 
static av_always_inline uint8_t coef2maxsf (float coef)
 Return the maximum scalefactor where the quantized coef is not zero. More...
 
static void search_for_quantizers_anmr (AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, const float lambda)
 
static void search_for_quantizers_twoloop (AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, const float lambda)
 two-loop quantizers search taken from ISO 13818-7 Appendix C More...
 
static void search_for_quantizers_faac (AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, const float lambda)
 
static void search_for_quantizers_fast (AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, const float lambda)
 
static void search_for_ms (AACEncContext *s, ChannelElement *cpe, const float lambda)
 

Variables

static const uint8_t run_value_bits_long [64]
 bits needed to code codebook run value for long windows More...
 
static const uint8_t run_value_bits_short [16]
 bits needed to code codebook run value for short windows More...
 
static const uint8_trun_value_bits [2]
 
static const uint8_t aac_cb_range [12] = {0, 3, 3, 3, 3, 9, 9, 8, 8, 13, 13, 17}
 
static const uint8_t aac_cb_maxval [12] = {0, 1, 1, 2, 2, 4, 4, 7, 7, 12, 12, 16}
 
static float(*const quantize_and_encode_band_cost_arr [])(struct AACEncContext *s, PutBitContext *pb, const float *in, const float *scaled, int size, int scale_idx, int cb, const float lambda, const float uplim, int *bits)
 
AACCoefficientsEncoder ff_aac_coders [AAC_CODER_NB]
 

Detailed Description

AAC coefficients encoder.

Definition in file aaccoder.c.

Macro Definition Documentation

#define quantize_and_encode_band_cost (   s,
  pb,
  in,
  scaled,
  size,
  scale_idx,
  cb,
  lambda,
  uplim,
  bits 
)
Value:
s, pb, in, scaled, size, scale_idx, cb, \
lambda, uplim, bits)
const char * s
Definition: avisynth_c.h:668
About Git write you should know how to use GIT properly Luckily Git comes with excellent documentation git help man git shows you the available git< command > help man git< command > shows information about the subcommand< command > The most comprehensive manual is the website Git Reference visit they are quite exhaustive You do not need a special username or password All you need is to provide a ssh public key to the Git server admin What follows now is a basic introduction to Git and some FFmpeg specific guidelines Read it at least if you are granted commit privileges to the FFmpeg project you are expected to be familiar with these rules I if not You can get git from etc no matter how small Every one of them has been saved from looking like a fool by this many times It s very easy for stray debug output or cosmetic modifications to slip in
Definition: git-howto.txt:5
uint8_t bits
Definition: crc.c:216
int size
FIXME Range Coding of cb
Definition: snow.txt:367
static float(*const quantize_and_encode_band_cost_arr[])(struct AACEncContext *s, PutBitContext *pb, const float *in, const float *scaled, int size, int scale_idx, int cb, const float lambda, const float uplim, int *bits)
Definition: aaccoder.c:230

Definition at line 250 of file aaccoder.c.

Referenced by quantize_and_encode_band(), and quantize_band_cost().

#define QUANTIZE_AND_ENCODE_BAND_COST_FUNC (   NAME,
  BT_ZERO,
  BT_UNSIGNED,
  BT_PAIR,
  BT_ESC 
)
Value:
static float quantize_and_encode_band_cost_ ## NAME( \
struct AACEncContext *s, \
PutBitContext *pb, const float *in, \
const float *scaled, int size, int scale_idx, \
int cb, const float lambda, const float uplim, \
int *bits) { \
s, pb, in, scaled, size, scale_idx, \
BT_ESC ? ESC_BT : cb, lambda, uplim, bits, \
BT_ZERO, BT_UNSIGNED, BT_PAIR, BT_ESC); \
}
const char * s
Definition: avisynth_c.h:668
About Git write you should know how to use GIT properly Luckily Git comes with excellent documentation git help man git shows you the available git< command > help man git< command > shows information about the subcommand< command > The most comprehensive manual is the website Git Reference visit they are quite exhaustive You do not need a special username or password All you need is to provide a ssh public key to the Git server admin What follows now is a basic introduction to Git and some FFmpeg specific guidelines Read it at least if you are granted commit privileges to the FFmpeg project you are expected to be familiar with these rules I if not You can get git from etc no matter how small Every one of them has been saved from looking like a fool by this many times It s very easy for stray debug output or cosmetic modifications to slip in
Definition: git-howto.txt:5
AAC encoder context.
Definition: aacenc.h:57
uint8_t bits
Definition: crc.c:216
static av_always_inline float quantize_and_encode_band_cost_template(struct AACEncContext *s, PutBitContext *pb, const float *in, const float *scaled, int size, int scale_idx, int cb, const float lambda, const float uplim, int *bits, int BT_ZERO, int BT_UNSIGNED, int BT_PAIR, int BT_ESC)
Calculate rate distortion cost for quantizing with given codebook.
Definition: aaccoder.c:105
int size
FIXME Range Coding of cb
Definition: snow.txt:367
Spectral data are coded with an escape sequence.
Definition: aac.h:78
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame This method is called when a frame is wanted on an output For an it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return it should return

Definition at line 210 of file aaccoder.c.

#define TRELLIS_STAGES   121

Definition at line 551 of file aaccoder.c.

Referenced by search_for_quantizers_anmr().

#define TRELLIS_STATES   (SCALE_MAX_DIFF+1)

Definition at line 552 of file aaccoder.c.

Referenced by search_for_quantizers_anmr().

Typedef Documentation

structure used in optimal codebook search

typedef struct TrellisPath TrellisPath

Function Documentation

static void abs_pow34_v ( float *  out,
const float *  in,
const int  size 
)
static
static void codebook_trellis_rate ( AACEncContext s,
SingleChannelElement sce,
int  win,
int  group_len,
const float  lambda 
)
static

Definition at line 413 of file aaccoder.c.

static av_always_inline uint8_t coef2maxsf ( float  coef)
static

Return the maximum scalefactor where the quantized coef is not zero.

Definition at line 542 of file aaccoder.c.

Referenced by search_for_quantizers_anmr().

static av_always_inline uint8_t coef2minsf ( float  coef)
static

Return the minimum scalefactor where the quantized coef does not clip.

Definition at line 537 of file aaccoder.c.

Referenced by search_for_quantizers_anmr().

static void encode_window_bands_info ( AACEncContext s,
SingleChannelElement sce,
int  win,
int  group_len,
const float  lambda 
)
static

Encode band info for single window group bands.

Definition at line 312 of file aaccoder.c.

static float find_max_val ( int  group_len,
int  swb_size,
const float *  scaled 
)
static

Definition at line 274 of file aaccoder.c.

Referenced by search_for_quantizers_anmr(), and search_for_quantizers_twoloop().

static int find_min_book ( float  maxval,
int  sf 
)
static

Definition at line 285 of file aaccoder.c.

Referenced by search_for_quantizers_anmr(), and search_for_quantizers_twoloop().

static av_always_inline int quant ( float  coef,
const float  Q 
)
static

Quantize one coefficient.

Returns
absolute value of the quantized coefficient
See also
3GPP TS26.403 5.6.2 "Scalefactor determination"

Definition at line 66 of file aaccoder.c.

Referenced by quantize_and_encode_band_cost_template(), and search_for_quantizers_faac().

static void quantize_and_encode_band ( struct AACEncContext s,
PutBitContext pb,
const float *  in,
int  size,
int  scale_idx,
int  cb,
const float  lambda 
)
static

Definition at line 266 of file aaccoder.c.

static av_always_inline float quantize_and_encode_band_cost_template ( struct AACEncContext s,
PutBitContext pb,
const float *  in,
const float *  scaled,
int  size,
int  scale_idx,
int  cb,
const float  lambda,
const float  uplim,
int *  bits,
int  BT_ZERO,
int  BT_UNSIGNED,
int  BT_PAIR,
int  BT_ESC 
)
static

Calculate rate distortion cost for quantizing with given codebook.

Returns
quantization distortion

Definition at line 105 of file aaccoder.c.

static float quantize_band_cost ( struct AACEncContext s,
const float *  in,
const float *  scaled,
int  size,
int  scale_idx,
int  cb,
const float  lambda,
const float  uplim,
int *  bits 
)
static
static void quantize_bands ( int *  out,
const float *  in,
const float *  scaled,
int  size,
float  Q34,
int  is_signed,
int  maxval 
)
static

Definition at line 72 of file aaccoder.c.

Referenced by quantize_and_encode_band_cost_template().

static void search_for_ms ( AACEncContext s,
ChannelElement cpe,
const float  lambda 
)
static

Definition at line 1054 of file aaccoder.c.

static void search_for_quantizers_anmr ( AVCodecContext avctx,
AACEncContext s,
SingleChannelElement sce,
const float  lambda 
)
static

Definition at line 554 of file aaccoder.c.

static void search_for_quantizers_faac ( AVCodecContext avctx,
AACEncContext s,
SingleChannelElement sce,
const float  lambda 
)
static

Definition at line 852 of file aaccoder.c.

static void search_for_quantizers_fast ( AVCodecContext avctx,
AACEncContext s,
SingleChannelElement sce,
const float  lambda 
)
static

Definition at line 1020 of file aaccoder.c.

static void search_for_quantizers_twoloop ( AVCodecContext avctx,
AACEncContext s,
SingleChannelElement sce,
const float  lambda 
)
static

two-loop quantizers search taken from ISO 13818-7 Appendix C

Definition at line 707 of file aaccoder.c.

Variable Documentation

const uint8_t aac_cb_maxval[12] = {0, 1, 1, 2, 2, 4, 4, 7, 7, 12, 12, 16}
static

Definition at line 98 of file aaccoder.c.

Referenced by quantize_and_encode_band_cost_template().

const uint8_t aac_cb_range[12] = {0, 3, 3, 3, 3, 9, 9, 8, 8, 13, 13, 17}
static

Definition at line 97 of file aaccoder.c.

Referenced by quantize_and_encode_band_cost_template().

Initial value:
= {
{
},
{
},
{
},
{
},
}
static void encode_window_bands_info(AACEncContext *s, SingleChannelElement *sce, int win, int group_len, const float lambda)
Encode band info for single window group bands.
Definition: aaccoder.c:312
static void search_for_quantizers_fast(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, const float lambda)
Definition: aaccoder.c:1020
static void search_for_ms(AACEncContext *s, ChannelElement *cpe, const float lambda)
Definition: aaccoder.c:1054
static void search_for_quantizers_anmr(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, const float lambda)
Definition: aaccoder.c:554
static void quantize_and_encode_band(struct AACEncContext *s, PutBitContext *pb, const float *in, int size, int scale_idx, int cb, const float lambda)
Definition: aaccoder.c:266
static void codebook_trellis_rate(AACEncContext *s, SingleChannelElement *sce, int win, int group_len, const float lambda)
Definition: aaccoder.c:413
static void search_for_quantizers_faac(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, const float lambda)
Definition: aaccoder.c:852
static void search_for_quantizers_twoloop(AVCodecContext *avctx, AACEncContext *s, SingleChannelElement *sce, const float lambda)
two-loop quantizers search taken from ISO 13818-7 Appendix C
Definition: aaccoder.c:707

Definition at line 1115 of file aaccoder.c.

Referenced by aac_encode_init().

float(*const quantize_and_encode_band_cost_arr[])(struct AACEncContext *s, PutBitContext *pb, const float *in, const float *scaled, int size, int scale_idx, int cb, const float lambda, const float uplim, int *bits)
static
Initial value:
= {
quantize_and_encode_band_cost_ZERO,
quantize_and_encode_band_cost_SQUAD,
quantize_and_encode_band_cost_SQUAD,
quantize_and_encode_band_cost_UQUAD,
quantize_and_encode_band_cost_UQUAD,
quantize_and_encode_band_cost_SPAIR,
quantize_and_encode_band_cost_SPAIR,
quantize_and_encode_band_cost_UPAIR,
quantize_and_encode_band_cost_UPAIR,
quantize_and_encode_band_cost_UPAIR,
quantize_and_encode_band_cost_UPAIR,
quantize_and_encode_band_cost_ESC,
}

Definition at line 230 of file aaccoder.c.

const uint8_t* run_value_bits[2]
static
Initial value:
= {
}
static const uint8_t run_value_bits_long[64]
bits needed to code codebook run value for long windows
Definition: aaccoder.c:44
static const uint8_t run_value_bits_short[16]
bits needed to code codebook run value for short windows
Definition: aaccoder.c:52

Definition at line 56 of file aaccoder.c.

Referenced by codebook_trellis_rate(), and encode_window_bands_info().

const uint8_t run_value_bits_long[64]
static
Initial value:
= {
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 15
}

bits needed to code codebook run value for long windows

Definition at line 44 of file aaccoder.c.

const uint8_t run_value_bits_short[16]
static
Initial value:
= {
3, 3, 3, 3, 3, 3, 3, 6, 6, 6, 6, 6, 6, 6, 6, 9
}

bits needed to code codebook run value for short windows

Definition at line 52 of file aaccoder.c.