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 "internal.h"

Go to the source code of this file.

Data Structures

struct  TrellisPath
 
struct  TrellisNode
 
struct  ADPCMEncodeContext
 

Macros

#define FREEZE_INTERVAL   128
 
#define STORE_NODE(NAME, STEP_INDEX)
 
#define LOOP_NODES(NAME, STEP_TABLE, STEP_INDEX)
 
#define ADPCM_ENCODER(id_, 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_argo_compress_nibble (const ADPCMChannelStatus *cs, int16_t s, int shift, int flag)
 
static int64_t adpcm_argo_compress_block (ADPCMChannelStatus *cs, PutBitContext *pb, const int16_t *samples, int nsamples, int shift, int flag)
 
static int adpcm_encode_frame (AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
 
 ADPCM_ENCODER (AV_CODEC_ID_ADPCM_ARGO, adpcm_argo, sample_fmts_p, 0, "ADPCM Argonaut Games")
 
 ADPCM_ENCODER (AV_CODEC_ID_ADPCM_IMA_AMV, adpcm_ima_amv, sample_fmts, 0, "ADPCM IMA AMV")
 
 ADPCM_ENCODER (AV_CODEC_ID_ADPCM_IMA_APM, adpcm_ima_apm, sample_fmts, AV_CODEC_CAP_SMALL_LAST_FRAME, "ADPCM IMA Ubisoft APM")
 
 ADPCM_ENCODER (AV_CODEC_ID_ADPCM_IMA_ALP, adpcm_ima_alp, sample_fmts, AV_CODEC_CAP_SMALL_LAST_FRAME, "ADPCM IMA High Voltage Software ALP")
 
 ADPCM_ENCODER (AV_CODEC_ID_ADPCM_IMA_QT, adpcm_ima_qt, sample_fmts_p, 0, "ADPCM IMA QuickTime")
 
 ADPCM_ENCODER (AV_CODEC_ID_ADPCM_IMA_SSI, adpcm_ima_ssi, sample_fmts, AV_CODEC_CAP_SMALL_LAST_FRAME, "ADPCM IMA Simon & Schuster Interactive")
 
 ADPCM_ENCODER (AV_CODEC_ID_ADPCM_IMA_WAV, adpcm_ima_wav, sample_fmts_p, 0, "ADPCM IMA WAV")
 
 ADPCM_ENCODER (AV_CODEC_ID_ADPCM_MS, adpcm_ms, sample_fmts, 0, "ADPCM Microsoft")
 
 ADPCM_ENCODER (AV_CODEC_ID_ADPCM_SWF, adpcm_swf, sample_fmts, 0, "ADPCM Shockwave Flash")
 
 ADPCM_ENCODER (AV_CODEC_ID_ADPCM_YAMAHA, adpcm_yamaha, sample_fmts, 0, "ADPCM Yamaha")
 

Variables

static enum AVSampleFormat sample_fmts []
 
static enum AVSampleFormat sample_fmts_p []
 
static const AVOption options []
 

Detailed Description

ADPCM encoders See ADPCM decoder reference documents for codec information.

Definition in file adpcmenc.c.

Macro Definition Documentation

◆ FREEZE_INTERVAL

#define FREEZE_INTERVAL   128

Definition at line 64 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

#define ADPCM_ENCODER (   id_,
  name_,
  sample_fmts_,
  capabilities_,
  long_name_ 
)
Value:
static const AVClass name_ ## _encoder_class = { \
.class_name = #name_, \
.item_name = av_default_item_name, \
.option = options, \
.version = LIBAVUTIL_VERSION_INT, \
}; \
\
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_, \
.priv_class = &name_ ## _encoder_class, \
}

Definition at line 948 of file adpcmenc.c.

Function Documentation

◆ adpcm_encode_init()

static av_cold int adpcm_encode_init ( AVCodecContext avctx)
static

Definition at line 66 of file adpcmenc.c.

◆ adpcm_encode_close()

static av_cold int adpcm_encode_close ( AVCodecContext avctx)
static

Definition at line 202 of file adpcmenc.c.

◆ adpcm_ima_compress_sample()

static uint8_t adpcm_ima_compress_sample ( ADPCMChannelStatus c,
int16_t  sample 
)
inlinestatic

Definition at line 214 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 227 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 246 of file adpcmenc.c.

◆ adpcm_ms_compress_sample()

static uint8_t adpcm_ms_compress_sample ( ADPCMChannelStatus c,
int16_t  sample 
)
inlinestatic

Definition at line 283 of file adpcmenc.c.

◆ adpcm_yamaha_compress_sample()

static uint8_t adpcm_yamaha_compress_sample ( ADPCMChannelStatus c,
int16_t  sample 
)
inlinestatic

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

◆ adpcm_argo_compress_nibble()

static int adpcm_argo_compress_nibble ( const ADPCMChannelStatus cs,
int16_t  s,
int  shift,
int  flag 
)
inlinestatic

Definition at line 526 of file adpcmenc.c.

Referenced by adpcm_encode_frame().

◆ adpcm_argo_compress_block()

static int64_t adpcm_argo_compress_block ( ADPCMChannelStatus cs,
PutBitContext pb,
const int16_t *  samples,
int  nsamples,
int  shift,
int  flag 
)
static

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

◆ ADPCM_ENCODER() [1/10]

ADPCM_ENCODER ( AV_CODEC_ID_ADPCM_ARGO  ,
adpcm_argo  ,
sample_fmts_p  ,
,
"ADPCM Argonaut Games"   
)

◆ ADPCM_ENCODER() [2/10]

ADPCM_ENCODER ( AV_CODEC_ID_ADPCM_IMA_AMV  ,
adpcm_ima_amv  ,
sample_fmts  ,
,
"ADPCM IMA AMV"   
)

◆ ADPCM_ENCODER() [3/10]

ADPCM_ENCODER ( AV_CODEC_ID_ADPCM_IMA_APM  ,
adpcm_ima_apm  ,
sample_fmts  ,
AV_CODEC_CAP_SMALL_LAST_FRAME  ,
"ADPCM IMA Ubisoft APM"   
)

◆ ADPCM_ENCODER() [4/10]

ADPCM_ENCODER ( AV_CODEC_ID_ADPCM_IMA_ALP  ,
adpcm_ima_alp  ,
sample_fmts  ,
AV_CODEC_CAP_SMALL_LAST_FRAME  ,
"ADPCM IMA High Voltage Software ALP"   
)

◆ ADPCM_ENCODER() [5/10]

ADPCM_ENCODER ( AV_CODEC_ID_ADPCM_IMA_QT  ,
adpcm_ima_qt  ,
sample_fmts_p  ,
,
"ADPCM IMA QuickTime"   
)

◆ ADPCM_ENCODER() [6/10]

ADPCM_ENCODER ( AV_CODEC_ID_ADPCM_IMA_SSI  ,
adpcm_ima_ssi  ,
sample_fmts  ,
AV_CODEC_CAP_SMALL_LAST_FRAME  ,
"ADPCM IMA Simon & Schuster Interactive"   
)

◆ ADPCM_ENCODER() [7/10]

ADPCM_ENCODER ( AV_CODEC_ID_ADPCM_IMA_WAV  ,
adpcm_ima_wav  ,
sample_fmts_p  ,
,
"ADPCM IMA WAV"   
)

◆ ADPCM_ENCODER() [8/10]

ADPCM_ENCODER ( AV_CODEC_ID_ADPCM_MS  ,
adpcm_ms  ,
sample_fmts  ,
,
"ADPCM Microsoft"   
)

◆ ADPCM_ENCODER() [9/10]

ADPCM_ENCODER ( AV_CODEC_ID_ADPCM_SWF  ,
adpcm_swf  ,
sample_fmts  ,
,
"ADPCM Shockwave Flash"   
)

◆ ADPCM_ENCODER() [10/10]

ADPCM_ENCODER ( AV_CODEC_ID_ADPCM_YAMAHA  ,
adpcm_yamaha  ,
sample_fmts  ,
,
"ADPCM Yamaha"   
)

Variable Documentation

◆ sample_fmts

enum AVSampleFormat sample_fmts[]
static

◆ sample_fmts_p

enum AVSampleFormat sample_fmts_p[]
static
Initial value:

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

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:41
av_clip
#define av_clip
Definition: common.h:122
init
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:31
sample_fmts
static enum AVSampleFormat sample_fmts[]
Definition: adpcmenc.c:926
options
static const AVOption options[]
Definition: adpcmenc.c:934
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:278
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AV_OPT_FLAG_AUDIO_PARAM
#define AV_OPT_FLAG_AUDIO_PARAM
Definition: opt.h:280
LIBAVUTIL_VERSION_INT
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:67
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
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:163
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:49
AV_SAMPLE_FMT_S16
@ AV_SAMPLE_FMT_S16
signed 16 bits
Definition: samplefmt.h:61
adpcm_encode_frame
static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Definition: adpcmenc.c:566
AVClass::class_name
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
ADPCMEncodeContext
Definition: adpcmenc.c:53
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:225
adpcm_encode_init
static av_cold int adpcm_encode_init(AVCodecContext *avctx)
Definition: adpcmenc.c:66
adpcm_encode_close
static av_cold int adpcm_encode_close(AVCodecContext *avctx)
Definition: adpcmenc.c:202