FFmpeg
Data Structures | Macros | Functions | Variables
adpcmenc.c File Reference
#include "config_components.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "avcodec.h"
#include "put_bits.h"
#include "bytestream.h"
#include "adpcm.h"
#include "adpcm_data.h"
#include "codec_internal.h"
#include "encode.h"

Go to the source code of this file.

Data Structures

struct  TrellisPath
 
struct  TrellisNode
 
struct  ADPCMEncodeContext
 

Macros

#define CASE_0(codec_id, ...)
 
#define CASE_1(codec_id, ...)
 
#define CASE_2(enabled, codec_id, ...)   CASE_ ## enabled(codec_id, __VA_ARGS__)
 
#define CASE_3(config, codec_id, ...)   CASE_2(config, codec_id, __VA_ARGS__)
 
#define CASE(codec, ...)   CASE_3(CONFIG_ ## codec ## _ENCODER, AV_CODEC_ID_ ## codec, __VA_ARGS__)
 
#define FREEZE_INTERVAL   128
 
#define STORE_NODE(NAME, STEP_INDEX)
 
#define LOOP_NODES(NAME, STEP_TABLE, STEP_INDEX)
 
#define ADPCM_ENCODER_0(id_, name_, sample_fmts_, capabilities_, long_name_)
 
#define ADPCM_ENCODER_1(id_, name_, sample_fmts_, capabilities_, long_name_)
 
#define ADPCM_ENCODER_2(enabled, codec_id, name, sample_fmts, capabilities, long_name)   ADPCM_ENCODER_ ## enabled(codec_id, name, sample_fmts, capabilities, long_name)
 
#define ADPCM_ENCODER_3(config, codec_id, name, sample_fmts, capabilities, long_name)   ADPCM_ENCODER_2(config, codec_id, name, sample_fmts, capabilities, long_name)
 
#define ADPCM_ENCODER(codec, name, sample_fmts, capabilities, long_name)
 

Functions

static av_cold int adpcm_encode_init (AVCodecContext *avctx)
 
static av_cold int adpcm_encode_close (AVCodecContext *avctx)
 
static uint8_t adpcm_ima_compress_sample (ADPCMChannelStatus *c, int16_t sample)
 
static uint8_t adpcm_ima_alp_compress_sample (ADPCMChannelStatus *c, int16_t sample)
 
static uint8_t adpcm_ima_qt_compress_sample (ADPCMChannelStatus *c, int16_t sample)
 
static uint8_t adpcm_ms_compress_sample (ADPCMChannelStatus *c, int16_t sample)
 
static uint8_t adpcm_yamaha_compress_sample (ADPCMChannelStatus *c, int16_t sample)
 
static void adpcm_compress_trellis (AVCodecContext *avctx, const int16_t *samples, uint8_t *dst, ADPCMChannelStatus *c, int n, int stride)
 
static int adpcm_encode_frame (AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
 

Variables

static enum AVSampleFormat sample_fmts []
 
static enum AVSampleFormat sample_fmts_p []
 
static const AVChannelLayout ch_layouts []
 
static const AVOption options []
 
static const AVClass adpcm_encoder_class
 

Detailed Description

ADPCM encoders See ADPCM decoder reference documents for codec information.

Definition in file adpcmenc.c.

Macro Definition Documentation

◆ CASE_0

#define CASE_0 (   codec_id,
  ... 
)

Definition at line 44 of file adpcmenc.c.

◆ CASE_1

#define CASE_1 (   codec_id,
  ... 
)
Value:
case codec_id: \
{ __VA_ARGS__ } \
break;

Definition at line 45 of file adpcmenc.c.

◆ CASE_2

#define CASE_2 (   enabled,
  codec_id,
  ... 
)    CASE_ ## enabled(codec_id, __VA_ARGS__)

Definition at line 49 of file adpcmenc.c.

◆ CASE_3

#define CASE_3 (   config,
  codec_id,
  ... 
)    CASE_2(config, codec_id, __VA_ARGS__)

Definition at line 51 of file adpcmenc.c.

◆ CASE

#define CASE (   codec,
  ... 
)    CASE_3(CONFIG_ ## codec ## _ENCODER, AV_CODEC_ID_ ## codec, __VA_ARGS__)

Definition at line 53 of file adpcmenc.c.

◆ FREEZE_INTERVAL

#define FREEZE_INTERVAL   128

Definition at line 80 of file adpcmenc.c.

◆ STORE_NODE

#define STORE_NODE (   NAME,
  STEP_INDEX 
)

◆ LOOP_NODES

#define LOOP_NODES (   NAME,
  STEP_TABLE,
  STEP_INDEX 
)
Value:
const int predictor = nodes[j]->sample1;\
const int div = (sample - predictor) * 4 / STEP_TABLE;\
int nmin = av_clip(div - range, -7, 6);\
int nmax = av_clip(div + range, -6, 7);\
if (nmin <= 0)\
nmin--; /* distinguish -0 from +0 */\
if (nmax < 0)\
nmax--;\
for (nidx = nmin; nidx <= nmax; nidx++) {\
const int nibble = nidx < 0 ? 7 - nidx : nidx;\
int dec_sample = predictor +\
(STEP_TABLE *\
ff_adpcm_yamaha_difflookup[nibble]) / 8;\
STORE_NODE(NAME, STEP_INDEX);\
}

◆ ADPCM_ENCODER_0

#define ADPCM_ENCODER_0 (   id_,
  name_,
  sample_fmts_,
  capabilities_,
  long_name_ 
)

Definition at line 983 of file adpcmenc.c.

◆ ADPCM_ENCODER_1

#define ADPCM_ENCODER_1 (   id_,
  name_,
  sample_fmts_,
  capabilities_,
  long_name_ 
)
Value:
const FFCodec ff_ ## name_ ## _encoder = { \
.p.name = #name_, \
CODEC_LONG_NAME(long_name_), \
.p.type = AVMEDIA_TYPE_AUDIO, \
.p.id = id_, \
.p.sample_fmts = sample_fmts_, \
.p.ch_layouts = ch_layouts, \
.p.capabilities = capabilities_ | AV_CODEC_CAP_DR1 | \
AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE, \
.p.priv_class = &adpcm_encoder_class, \
.priv_data_size = sizeof(ADPCMEncodeContext), \
.close = adpcm_encode_close, \
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP, \
};

Definition at line 984 of file adpcmenc.c.

◆ ADPCM_ENCODER_2

#define ADPCM_ENCODER_2 (   enabled,
  codec_id,
  name,
  sample_fmts,
  capabilities,
  long_name 
)    ADPCM_ENCODER_ ## enabled(codec_id, name, sample_fmts, capabilities, long_name)

Definition at line 1001 of file adpcmenc.c.

◆ ADPCM_ENCODER_3

#define ADPCM_ENCODER_3 (   config,
  codec_id,
  name,
  sample_fmts,
  capabilities,
  long_name 
)    ADPCM_ENCODER_2(config, codec_id, name, sample_fmts, capabilities, long_name)

Definition at line 1003 of file adpcmenc.c.

◆ ADPCM_ENCODER

#define ADPCM_ENCODER (   codec,
  name,
  sample_fmts,
  capabilities,
  long_name 
)
Value:
ADPCM_ENCODER_3(CONFIG_ ## codec ## _ENCODER, AV_CODEC_ID_ ## codec, \
name, sample_fmts, capabilities, long_name)

Definition at line 1005 of file adpcmenc.c.

Function Documentation

◆ adpcm_encode_init()

static av_cold int adpcm_encode_init ( AVCodecContext avctx)
static

Definition at line 82 of file adpcmenc.c.

◆ adpcm_encode_close()

static av_cold int adpcm_encode_close ( AVCodecContext avctx)
static

Definition at line 219 of file adpcmenc.c.

◆ adpcm_ima_compress_sample()

static uint8_t adpcm_ima_compress_sample ( ADPCMChannelStatus c,
int16_t  sample 
)
inlinestatic

Definition at line 231 of file adpcmenc.c.

◆ adpcm_ima_alp_compress_sample()

static uint8_t adpcm_ima_alp_compress_sample ( ADPCMChannelStatus c,
int16_t  sample 
)
inlinestatic

Definition at line 244 of file adpcmenc.c.

◆ adpcm_ima_qt_compress_sample()

static uint8_t adpcm_ima_qt_compress_sample ( ADPCMChannelStatus c,
int16_t  sample 
)
inlinestatic

Definition at line 263 of file adpcmenc.c.

◆ adpcm_ms_compress_sample()

static uint8_t adpcm_ms_compress_sample ( ADPCMChannelStatus c,
int16_t  sample 
)
inlinestatic

Definition at line 300 of file adpcmenc.c.

◆ adpcm_yamaha_compress_sample()

static uint8_t adpcm_yamaha_compress_sample ( ADPCMChannelStatus c,
int16_t  sample 
)
inlinestatic

Definition at line 329 of file adpcmenc.c.

◆ adpcm_compress_trellis()

static void adpcm_compress_trellis ( AVCodecContext avctx,
const int16_t *  samples,
uint8_t *  dst,
ADPCMChannelStatus c,
int  n,
int  stride 
)
static

Definition at line 351 of file adpcmenc.c.

◆ adpcm_encode_frame()

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

Definition at line 585 of file adpcmenc.c.

Variable Documentation

◆ sample_fmts

enum AVSampleFormat sample_fmts[]
static

◆ sample_fmts_p

enum AVSampleFormat sample_fmts_p[]
static
Initial value:

Definition at line 952 of file adpcmenc.c.

◆ ch_layouts

const AVChannelLayout ch_layouts[]
static
Initial value:

Definition at line 956 of file adpcmenc.c.

Referenced by encode_preinit_audio(), and ff_make_channel_layout_list().

◆ options

const AVOption options[]
static
Initial value:
= {
{
.name = "block_size",
.help = "set the block size",
.offset = 0x42,
.type = AV_OPT_TYPE_INT,
.default_val = {.i64 = 1024},
.min = 32,
.max = 8192,
},
{ NULL }
}

Definition at line 962 of file adpcmenc.c.

◆ adpcm_encoder_class

const AVClass adpcm_encoder_class
static
Initial value:
= {
.class_name = "ADPCM encoder",
.item_name = av_default_item_name,
.option = options,
}

Definition at line 976 of file adpcmenc.c.

name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
av_clip
#define av_clip
Definition: common.h:100
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:43
AV_CHANNEL_LAYOUT_STEREO
#define AV_CHANNEL_LAYOUT_STEREO
Definition: channel_layout.h:387
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:948
adpcm_encoder_class
static const AVClass adpcm_encoder_class
Definition: adpcmenc.c:976
ADPCM_ENCODER_3
#define ADPCM_ENCODER_3(config, codec_id, name, sample_fmts, capabilities, long_name)
Definition: adpcmenc.c:1003
FFCodec
Definition: codec_internal.h:127
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:320
AV_OPT_FLAG_AUDIO_PARAM
#define AV_OPT_FLAG_AUDIO_PARAM
Definition: opt.h:357
options
static const AVOption options[]
Definition: adpcmenc.c:962
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:394
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_OPT_FLAG_ENCODING_PARAM
#define AV_OPT_FLAG_ENCODING_PARAM
A generic parameter which can be set by the user for muxing or encoding.
Definition: opt.h:352
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts.c:368
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
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
sample
#define sample
Definition: flacdsp_template.c:44
range
enum AVColorRange range
Definition: mediacodec_wrapper.c:2464
predictor
static void predictor(uint8_t *src, ptrdiff_t size)
Definition: exrenc.c:169
AV_SAMPLE_FMT_S16P
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
Definition: samplefmt.h:64
ch_layouts
static const AVChannelLayout ch_layouts[]
Definition: adpcmenc.c:956
AV_SAMPLE_FMT_S16
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition: samplefmt.h:58
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
adpcm_encode_frame
static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Definition: adpcmenc.c:585
ADPCMEncodeContext
Definition: adpcmenc.c:69
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
adpcm_encode_init
static av_cold int adpcm_encode_init(AVCodecContext *avctx)
Definition: adpcmenc.c:82
AV_CHANNEL_LAYOUT_MONO
#define AV_CHANNEL_LAYOUT_MONO
Definition: channel_layout.h:386
adpcm_encode_close
static av_cold int adpcm_encode_close(AVCodecContext *avctx)
Definition: adpcmenc.c:219