FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Enumerations | Functions | Variables
af_hdcd.c File Reference

HDCD decoding filter. More...

#include "libavutil/opt.h"
#include "libavutil/avassert.h"
#include "avfilter.h"
#include "internal.h"
#include "audio.h"

Go to the source code of this file.

Data Structures

struct  hdcd_state
 
struct  hdcd_detection_data
 
struct  HDCDContext
 

Macros

#define PEAK_EXT_LEVEL   0x5981 /* + sizeof(peaktab)-1 = 0x8000 */
 
#define HDCD_PROCESS_STEREO_DEFAULT   1
 
#define HDCD_MAX_CHANNELS   2
 
#define GAINTOFLOAT(g)   (g) ? -(float)(g>>1) - ((g & 1) ? 0.5 : 0.0) : 0.0
 convert to float from 4-bit (3.1) fixed-point the always-negative value is stored positive, so make it negative More...
 
#define APPLY_GAIN(s, g)   do{int64_t s64 = s; s64 *= gaintab[g]; s = (int32_t)(s64 >> 23); }while(0);
 apply gain, 11-bit (3.8) fixed point, always negative but stored positive. More...
 
#define TONEGEN16(sn, f, sr, a)   (int16_t)(sin((6.28318530718 * (sn) * (f)) /(sr)) * (a) * 0x7fff)
 tone generator: sample_number, frequency, sample_rate, amplitude More...
 
#define HDCD_ANA_OFF_DESC   "disabled"
 analyze mode descriptions: macro for AVOption definitions, array of const char for mapping mode to string More...
 
#define HDCD_ANA_LLE_DESC   "gain adjustment level at each sample"
 
#define HDCD_ANA_PE_DESC   "samples where peak extend occurs"
 
#define HDCD_ANA_CDT_DESC   "samples where the code detect timer is active"
 
#define HDCD_ANA_TGM_DESC   "samples where the target gain does not match between channels"
 
#define OFFSET(x)   offsetof(HDCDContext, x)
 
#define A   AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
 

Enumerations

enum  hdcd_pe { HDCD_PE_NEVER = 0, HDCD_PE_INTERMITTENT = 1, HDCD_PE_PERMANENT = 2 }
 
enum  hdcd_dv { HDCD_NONE = 0, HDCD_NO_EFFECT = 1, HDCD_EFFECTUAL = 2 }
 
enum  hdcd_pf { HDCD_PVER_NONE = 0, HDCD_PVER_A = 1, HDCD_PVER_B = 2, HDCD_PVER_MIX = 3 }
 
enum  hdcd_ana_mode {
  HDCD_ANA_OFF = 0, HDCD_ANA_LLE = 1, HDCD_ANA_PE = 2, HDCD_ANA_CDT = 3,
  HDCD_ANA_TGM = 4, HDCD_ANA_TOP = 5
}
 
enum  hdcd_control_result { HDCD_OK =0, HDCD_TG_MISMATCH }
 

Functions

 AVFILTER_DEFINE_CLASS (hdcd)
 
static void hdcd_reset (hdcd_state *state, unsigned rate, unsigned cdt_ms)
 
static int hdcd_integrate (HDCDContext *ctx, hdcd_state *states, int channels, int *flag, const int32_t *samples, int count, int stride)
 
static int hdcd_scan (HDCDContext *ctx, hdcd_state *states, int channels, const int32_t *samples, int max, int stride)
 
static void hdcd_analyze_prepare (hdcd_state *state, int32_t *samples, int count, int stride)
 replace audio with solid tone, but save LSBs More...
 
static int32_t hdcd_analyze_gen (int32_t sample, unsigned int v, unsigned int maxv)
 encode a value in the given sample by adjusting the amplitude More...
 
static int hdcd_analyze (int32_t *samples, int count, int stride, int gain, int target_gain, int extend, int mode, int cdt_active, int tg_mismatch)
 behaves like hdcd_envelope(), but encodes processing information in a way that is audible (and visible in an audio editor) to aid analysis. More...
 
static int hdcd_envelope (int32_t *samples, int count, int stride, int vbits, int gain, int target_gain, int extend)
 apply HDCD decoding parameters to a series of samples More...
 
static void hdcd_control (HDCDContext *ctx, hdcd_state *state, int *peak_extend, int *target_gain)
 extract fields from control code More...
 
static hdcd_control_result hdcd_control_stereo (HDCDContext *ctx, int *peak_extend0, int *peak_extend1)
 
static void hdcd_process (HDCDContext *ctx, hdcd_state *state, int32_t *samples, int count, int stride)
 
static void hdcd_process_stereo (HDCDContext *ctx, int32_t *samples, int count)
 
static void hdcd_detect_reset (hdcd_detection_data *detect)
 
static void hdcd_detect_start (hdcd_detection_data *detect)
 
static void hdcd_detect_onech (hdcd_state *state, hdcd_detection_data *detect)
 
static void hdcd_detect_end (hdcd_detection_data *detect, int channels)
 
static int filter_frame (AVFilterLink *inlink, AVFrame *in)
 
static int query_formats (AVFilterContext *ctx)
 
static av_cold void uninit (AVFilterContext *ctx)
 
static av_cold int init (AVFilterContext *ctx)
 
static int config_input (AVFilterLink *inlink)
 

Variables

static const uint32_t peaktab [0x2680]
 
static const uint8_t readaheadtab []
 
static const int32_t gaintab []
 
static const char *const pe_str []
 
static const char *const pf_str []
 
static const char *const ana_mode_str []
 
static const AVOption hdcd_options []
 
static const AVFilterPad avfilter_af_hdcd_inputs []
 
static const AVFilterPad avfilter_af_hdcd_outputs []
 
AVFilter ff_af_hdcd
 

Detailed Description

HDCD decoding filter.

Definition in file af_hdcd.c.

Macro Definition Documentation

#define PEAK_EXT_LEVEL   0x5981 /* + sizeof(peaktab)-1 = 0x8000 */

Definition at line 52 of file af_hdcd.c.

Referenced by hdcd_analyze_prepare(), and hdcd_envelope().

#define HDCD_PROCESS_STEREO_DEFAULT   1

Definition at line 826 of file af_hdcd.c.

#define HDCD_MAX_CHANNELS   2

Definition at line 827 of file af_hdcd.c.

Referenced by config_input(), hdcd_integrate(), hdcd_scan(), and uninit().

#define GAINTOFLOAT (   g)    (g) ? -(float)(g>>1) - ((g & 1) ? 0.5 : 0.0) : 0.0

convert to float from 4-bit (3.1) fixed-point the always-negative value is stored positive, so make it negative

Definition at line 831 of file af_hdcd.c.

Referenced by hdcd_control_stereo(), hdcd_detect_onech(), and uninit().

#define APPLY_GAIN (   s,
  g 
)    do{int64_t s64 = s; s64 *= gaintab[g]; s = (int32_t)(s64 >> 23); }while(0);

apply gain, 11-bit (3.8) fixed point, always negative but stored positive.

Definition at line 835 of file af_hdcd.c.

Referenced by hdcd_envelope().

#define TONEGEN16 (   sn,
  f,
  sr,
  a 
)    (int16_t)(sin((6.28318530718 * (sn) * (f)) /(sr)) * (a) * 0x7fff)

tone generator: sample_number, frequency, sample_rate, amplitude

Definition at line 838 of file af_hdcd.c.

Referenced by hdcd_analyze_prepare().

#define HDCD_ANA_OFF_DESC   "disabled"

analyze mode descriptions: macro for AVOption definitions, array of const char for mapping mode to string

Definition at line 930 of file af_hdcd.c.

#define HDCD_ANA_LLE_DESC   "gain adjustment level at each sample"

Definition at line 931 of file af_hdcd.c.

#define HDCD_ANA_PE_DESC   "samples where peak extend occurs"

Definition at line 932 of file af_hdcd.c.

#define HDCD_ANA_CDT_DESC   "samples where the code detect timer is active"

Definition at line 933 of file af_hdcd.c.

#define HDCD_ANA_TGM_DESC   "samples where the target gain does not match between channels"

Definition at line 934 of file af_hdcd.c.

#define OFFSET (   x)    offsetof(HDCDContext, x)

Definition at line 984 of file af_hdcd.c.

Definition at line 985 of file af_hdcd.c.

Enumeration Type Documentation

enum hdcd_pe
Enumerator
HDCD_PE_NEVER 

All valid packets have PE set to off.

HDCD_PE_INTERMITTENT 

Some valid packets have PE set to on.

HDCD_PE_PERMANENT 

All valid packets have PE set to on.

Definition at line 878 of file af_hdcd.c.

enum hdcd_dv
Enumerator
HDCD_NONE 

HDCD packets do not (yet) appear.

HDCD_NO_EFFECT 

HDCD packets appear, but all control codes are NOP.

HDCD_EFFECTUAL 

HDCD packets appear, and change the output in some way.

Definition at line 890 of file af_hdcd.c.

enum hdcd_pf
Enumerator
HDCD_PVER_NONE 

No packets (yet) discovered.

HDCD_PVER_A 

Packets of type A (8-bit control) discovered.

HDCD_PVER_B 

Packets of type B (8-bit control, 8-bit XOR) discovered.

HDCD_PVER_MIX 

Packets of type A and B discovered, most likely an encoding error.

Definition at line 896 of file af_hdcd.c.

Enumerator
HDCD_ANA_OFF 
HDCD_ANA_LLE 
HDCD_ANA_PE 
HDCD_ANA_CDT 
HDCD_ANA_TGM 
HDCD_ANA_TOP 

used in max value of AVOption

Definition at line 920 of file af_hdcd.c.

Enumerator
HDCD_OK 
HDCD_TG_MISMATCH 

Definition at line 1341 of file af_hdcd.c.

Function Documentation

AVFILTER_DEFINE_CLASS ( hdcd  )
static void hdcd_reset ( hdcd_state state,
unsigned  rate,
unsigned  cdt_ms 
)
static

Definition at line 1012 of file af_hdcd.c.

Referenced by config_input().

static int hdcd_integrate ( HDCDContext ctx,
hdcd_state states,
int  channels,
int flag,
const int32_t samples,
int  count,
int  stride 
)
static

Definition at line 1041 of file af_hdcd.c.

Referenced by hdcd_scan().

static int hdcd_scan ( HDCDContext ctx,
hdcd_state states,
int  channels,
const int32_t samples,
int  max,
int  stride 
)
static

Definition at line 1126 of file af_hdcd.c.

Referenced by hdcd_process(), and hdcd_process_stereo().

static void hdcd_analyze_prepare ( hdcd_state state,
int32_t samples,
int  count,
int  stride 
)
static

replace audio with solid tone, but save LSBs

Definition at line 1178 of file af_hdcd.c.

Referenced by hdcd_process(), and hdcd_process_stereo().

static int32_t hdcd_analyze_gen ( int32_t  sample,
unsigned int  v,
unsigned int  maxv 
)
static

encode a value in the given sample by adjusting the amplitude

Definition at line 1196 of file af_hdcd.c.

Referenced by hdcd_analyze().

static int hdcd_analyze ( int32_t samples,
int  count,
int  stride,
int  gain,
int  target_gain,
int  extend,
int  mode,
int  cdt_active,
int  tg_mismatch 
)
static

behaves like hdcd_envelope(), but encodes processing information in a way that is audible (and visible in an audio editor) to aid analysis.

Definition at line 1206 of file af_hdcd.c.

Referenced by hdcd_process(), and hdcd_process_stereo().

static int hdcd_envelope ( int32_t samples,
int  count,
int  stride,
int  vbits,
int  gain,
int  target_gain,
int  extend 
)
static

apply HDCD decoding parameters to a series of samples

Definition at line 1266 of file af_hdcd.c.

Referenced by hdcd_process(), and hdcd_process_stereo().

static void hdcd_control ( HDCDContext ctx,
hdcd_state state,
int peak_extend,
int target_gain 
)
static

extract fields from control code

Definition at line 1335 of file af_hdcd.c.

Referenced by hdcd_control_stereo(), and hdcd_process().

static hdcd_control_result hdcd_control_stereo ( HDCDContext ctx,
int peak_extend0,
int peak_extend1 
)
static

Definition at line 1346 of file af_hdcd.c.

Referenced by hdcd_process_stereo().

static void hdcd_process ( HDCDContext ctx,
hdcd_state state,
int32_t samples,
int  count,
int  stride 
)
static

Definition at line 1365 of file af_hdcd.c.

Referenced by filter_frame().

static void hdcd_process_stereo ( HDCDContext ctx,
int32_t samples,
int  count 
)
static

Definition at line 1406 of file af_hdcd.c.

Referenced by filter_frame().

static void hdcd_detect_reset ( hdcd_detection_data detect)
static

Definition at line 1471 of file af_hdcd.c.

Referenced by config_input().

static void hdcd_detect_start ( hdcd_detection_data detect)
static

Definition at line 1483 of file af_hdcd.c.

Referenced by filter_frame().

static void hdcd_detect_onech ( hdcd_state state,
hdcd_detection_data detect 
)
static

Definition at line 1490 of file af_hdcd.c.

Referenced by filter_frame().

static void hdcd_detect_end ( hdcd_detection_data detect,
int  channels 
)
static

Definition at line 1516 of file af_hdcd.c.

Referenced by filter_frame().

static int filter_frame ( AVFilterLink inlink,
AVFrame in 
)
static

Definition at line 1527 of file af_hdcd.c.

static int query_formats ( AVFilterContext ctx)
static

Definition at line 1602 of file af_hdcd.c.

static av_cold void uninit ( AVFilterContext ctx)
static

Definition at line 1654 of file af_hdcd.c.

static av_cold int init ( AVFilterContext ctx)
static

Definition at line 1696 of file af_hdcd.c.

static int config_input ( AVFilterLink inlink)
static

Definition at line 1711 of file af_hdcd.c.

Variable Documentation

const uint32_t peaktab[0x2680]
static

Definition at line 53 of file af_hdcd.c.

Referenced by hdcd_envelope().

const uint8_t readaheadtab[]
static
Initial value:
= {
0x03, 0x02, 0x01, 0x01, 0x1f, 0x1e, 0x1f, 0x11, 0x1f, 0x1e, 0x1f, 0x1d, 0x1f, 0x1e, 0x1f,
0x10, 0x1f, 0x1e, 0x1f, 0x1d, 0x1f, 0x1e, 0x1f, 0x1c, 0x1f, 0x1e, 0x1f, 0x1d, 0x1f, 0x1e,
0x1f, 0x0f, 0x1f, 0x1e, 0x1f, 0x1d, 0x1f, 0x1e, 0x1f, 0x1c, 0x1f, 0x1e, 0x1f, 0x1d, 0x1f,
0x1e, 0x1f, 0x1b, 0x1f, 0x1e, 0x1f, 0x1d, 0x1f, 0x1e, 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f, 0x1d, 0x1f, 0x1e, 0x1f, 0x1c, 0x0a, 0x1e, 0x1f, 0x1d, 0x1f, 0x1e, 0x1f, 0x1b,
0x15, 0x1e, 0x1f, 0x1d, 0x0b, 0x1e, 0x1f, 0x1c, 0x16, 0x1e, 0x0c, 0x1d, 0x17, 0x1e, 0x1f,
0x20
}

Definition at line 672 of file af_hdcd.c.

Referenced by hdcd_integrate().

const int32_t gaintab[]
static

Definition at line 694 of file af_hdcd.c.

const char* const pe_str[]
static
Initial value:
= {
"never enabled",
"enabled intermittently",
"enabled permanently"
}

Definition at line 884 of file af_hdcd.c.

Referenced by uninit().

const char* const pf_str[]
static
Initial value:
= {
"?", "A", "B", "A+B"
}

Definition at line 903 of file af_hdcd.c.

Referenced by uninit().

const char* const ana_mode_str[]
static
Initial value:
= {
}
#define HDCD_ANA_PE_DESC
Definition: af_hdcd.c:932
#define HDCD_ANA_TGM_DESC
Definition: af_hdcd.c:934
#define HDCD_ANA_CDT_DESC
Definition: af_hdcd.c:933
#define HDCD_ANA_LLE_DESC
Definition: af_hdcd.c:931
#define HDCD_ANA_OFF_DESC
analyze mode descriptions: macro for AVOption definitions, array of const char for mapping mode to st...
Definition: af_hdcd.c:930

Definition at line 935 of file af_hdcd.c.

Referenced by config_input().

const AVOption hdcd_options[]
static
Initial value:
= {
{ "disable_autoconvert", "Disable any format conversion or resampling in the filter graph.",
OFFSET(disable_autoconvert), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, A },
{ "process_stereo", "Process stereo channels together. Only apply target_gain when both channels match.",
OFFSET(process_stereo), AV_OPT_TYPE_BOOL, { .i64 = HDCD_PROCESS_STEREO_DEFAULT }, 0, 1, A },
{ "cdt_ms", "Code detect timer period in ms.",
OFFSET(cdt_ms), AV_OPT_TYPE_INT, { .i64 = 2000 }, 100, 60000, A },
{ "force_pe", "Always extend peaks above -3dBFS even when PE is not signaled.",
OFFSET(force_pe), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, A },
{ "analyze_mode", "Replace audio with solid tone and signal some processing aspect in the amplitude.",
OFFSET(analyze_mode), AV_OPT_TYPE_INT, { .i64=HDCD_ANA_OFF }, 0, HDCD_ANA_TOP-1, A, "analyze_mode"},
{ "off", HDCD_ANA_OFF_DESC, 0, AV_OPT_TYPE_CONST, {.i64=HDCD_ANA_OFF}, 0, 0, A, "analyze_mode" },
{ "lle", HDCD_ANA_LLE_DESC, 0, AV_OPT_TYPE_CONST, {.i64=HDCD_ANA_LLE}, 0, 0, A, "analyze_mode" },
{ "pe", HDCD_ANA_PE_DESC, 0, AV_OPT_TYPE_CONST, {.i64=HDCD_ANA_PE}, 0, 0, A, "analyze_mode" },
{ "cdt", HDCD_ANA_CDT_DESC, 0, AV_OPT_TYPE_CONST, {.i64=HDCD_ANA_CDT}, 0, 0, A, "analyze_mode" },
{ "tgm", HDCD_ANA_TGM_DESC, 0, AV_OPT_TYPE_CONST, {.i64=HDCD_ANA_TGM}, 0, 0, A, "analyze_mode" },
{ "bits_per_sample", "Valid bits per sample (location of the true LSB).",
OFFSET(bits_per_sample), AV_OPT_TYPE_INT, { .i64=16 }, 16, 24, A, "bits_per_sample"},
{ "16", "16-bit (in s32 or s16)", 0, AV_OPT_TYPE_CONST, {.i64=16}, 0, 0, A, "bits_per_sample" },
{ "20", "20-bit (in s32)", 0, AV_OPT_TYPE_CONST, {.i64=20}, 0, 0, A, "bits_per_sample" },
{ "24", "24-bit (in s32)", 0, AV_OPT_TYPE_CONST, {.i64=24}, 0, 0, A, "bits_per_sample" },
{NULL}
}
#define NULL
Definition: coverity.c:32
used in max value of AVOption
Definition: af_hdcd.c:926
#define HDCD_ANA_PE_DESC
Definition: af_hdcd.c:932
#define HDCD_ANA_TGM_DESC
Definition: af_hdcd.c:934
#define HDCD_ANA_CDT_DESC
Definition: af_hdcd.c:933
#define HDCD_ANA_LLE_DESC
Definition: af_hdcd.c:931
#define OFFSET(x)
Definition: af_hdcd.c:984
#define A
Definition: af_hdcd.c:985
#define HDCD_PROCESS_STEREO_DEFAULT
Definition: af_hdcd.c:826
#define HDCD_ANA_OFF_DESC
analyze mode descriptions: macro for AVOption definitions, array of const char for mapping mode to st...
Definition: af_hdcd.c:930

Definition at line 986 of file af_hdcd.c.

const AVFilterPad avfilter_af_hdcd_inputs[]
static
Initial value:
= {
{
.name = "default",
.filter_frame = filter_frame,
.config_props = config_input,
},
{ NULL }
}
#define NULL
Definition: coverity.c:32
static int filter_frame(AVFilterLink *inlink, AVFrame *in)
Definition: af_hdcd.c:1527
static int config_input(AVFilterLink *inlink)
Definition: af_hdcd.c:1711

Definition at line 1757 of file af_hdcd.c.

const AVFilterPad avfilter_af_hdcd_outputs[]
static
Initial value:
= {
{
.name = "default",
},
{ NULL }
}
#define NULL
Definition: coverity.c:32

Definition at line 1767 of file af_hdcd.c.

AVFilter ff_af_hdcd
Initial value:
= {
.name = "hdcd",
.description = NULL_IF_CONFIG_SMALL("Apply High Definition Compatible Digital (HDCD) decoding."),
.priv_size = sizeof(HDCDContext),
.priv_class = &hdcd_class,
.init = init,
}
static av_cold int init(AVFilterContext *ctx)
Definition: af_hdcd.c:1696
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:179
static const AVFilterPad avfilter_af_hdcd_outputs[]
Definition: af_hdcd.c:1767
static av_cold void uninit(AVFilterContext *ctx)
Definition: af_hdcd.c:1654
static const AVFilterPad outputs[]
Definition: af_afftfilt.c:386
static const AVFilterPad avfilter_af_hdcd_inputs[]
Definition: af_hdcd.c:1757
static const AVFilterPad inputs[]
Definition: af_afftfilt.c:376
static int query_formats(AVFilterContext *ctx)
Definition: af_hdcd.c:1602

Definition at line 1775 of file af_hdcd.c.