FFmpeg
Data Structures | Macros | Functions | Variables
adpcmenc.c File Reference
#include "libavutil/opt.h"
#include "avcodec.h"
#include "put_bits.h"
#include "bytestream.h"
#include "adpcm.h"
#include "adpcm_data.h"
#include "encode.h"
#include "internal.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 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 41 of file adpcmenc.c.

◆ CASE_1

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

Definition at line 42 of file adpcmenc.c.

◆ CASE_2

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

Definition at line 46 of file adpcmenc.c.

◆ CASE_3

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

Definition at line 48 of file adpcmenc.c.

◆ CASE

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

Definition at line 50 of file adpcmenc.c.

◆ FREEZE_INTERVAL

#define FREEZE_INTERVAL   128

Definition at line 77 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 977 of file adpcmenc.c.

◆ ADPCM_ENCODER_1

#define ADPCM_ENCODER_1 (   id_,
  name_,
  sample_fmts_,
  capabilities_,
  long_name_ 
)
Value:
const AVCodec ff_ ## name_ ## _encoder = { \
.name = #name_, \
.long_name = NULL_IF_CONFIG_SMALL(long_name_), \
.type = AVMEDIA_TYPE_AUDIO, \
.id = id_, \
.priv_data_size = sizeof(ADPCMEncodeContext), \
.encode2 = adpcm_encode_frame, \
.close = adpcm_encode_close, \
.sample_fmts = sample_fmts_, \
.capabilities = capabilities_ | AV_CODEC_CAP_DR1, \
.priv_class = &adpcm_encoder_class, \
};

Definition at line 978 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 993 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 995 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 997 of file adpcmenc.c.

Function Documentation

◆ adpcm_encode_init()

static av_cold int adpcm_encode_init ( AVCodecContext avctx)
static

Definition at line 79 of file adpcmenc.c.

◆ adpcm_encode_close()

static av_cold int adpcm_encode_close ( AVCodecContext avctx)
static

Definition at line 220 of file adpcmenc.c.

◆ adpcm_ima_compress_sample()

static uint8_t adpcm_ima_compress_sample ( ADPCMChannelStatus c,
int16_t  sample 
)
inlinestatic

Definition at line 232 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 245 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 264 of file adpcmenc.c.

◆ adpcm_ms_compress_sample()

static uint8_t adpcm_ms_compress_sample ( ADPCMChannelStatus c,
int16_t  sample 
)
inlinestatic

Definition at line 301 of file adpcmenc.c.

◆ adpcm_yamaha_compress_sample()

static uint8_t adpcm_yamaha_compress_sample ( ADPCMChannelStatus c,
int16_t  sample 
)
inlinestatic

Definition at line 330 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 352 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 586 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.

◆ 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 956 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 970 of file adpcmenc.c.

AVCodec
AVCodec.
Definition: codec.h:202
FF_CODEC_CAP_INIT_THREADSAFE
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Definition: internal.h:42
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:96
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:948
adpcm_encoder_class
static const AVClass adpcm_encoder_class
Definition: adpcmenc.c:970
ADPCM_ENCODER_3
#define ADPCM_ENCODER_3(config, codec_id, name, sample_fmts, capabilities, long_name)
Definition: adpcmenc.c:995
init
static int init
Definition: av_tx.c:47
options
static const AVOption options[]
Definition: adpcmenc.c:956
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:277
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
codec_id
enum AVCodecID codec_id
Definition: vaapi_decode.c:369
AV_OPT_FLAG_AUDIO_PARAM
#define AV_OPT_FLAG_AUDIO_PARAM
Definition: opt.h:279
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:235
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
NULL_IF_CONFIG_SMALL
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:59
sample
#define sample
Definition: flacdsp_template.c:44
predictor
static void predictor(uint8_t *src, ptrdiff_t size)
Definition: exrenc.c:164
AV_SAMPLE_FMT_S16P
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
Definition: samplefmt.h:67
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: internal.h:50
AV_SAMPLE_FMT_S16
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition: samplefmt.h:61
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:209
adpcm_encode_frame
static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Definition: adpcmenc.c:586
ADPCMEncodeContext
Definition: adpcmenc.c:66
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:224
adpcm_encode_init
static av_cold int adpcm_encode_init(AVCodecContext *avctx)
Definition: adpcmenc.c:79
adpcm_encode_close
static av_cold int adpcm_encode_close(AVCodecContext *avctx)
Definition: adpcmenc.c:220