FFmpeg
Loading...
Searching...
No Matches
adpcmenc.c File Reference

ADPCM encoders See ADPCM decoder reference documents for codec information. More...

#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, ...)
 
#define CASE_3(config, codec_id, ...)
 
#define CASE(codec, ...)
 
#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, ...)
 
#define ADPCM_ENCODER_3(config, codec_id, name, sample_fmts, capabilities, long_name, ...)
 
#define ADPCM_ENCODER(codec, name, sample_fmts, capabilities, long_name, ...)
 
#define MONO_STEREO   CODEC_CH_LAYOUTS_ARRAY(ch_layouts_mono_stereo)
 
#define AVCLASS   .p.priv_class = &adpcm_encoder_class
 

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_mono_stereo []
 
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;
enum AVCodecID codec_id

Definition at line 45 of file adpcmenc.c.

◆ CASE_2

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

Definition at line 49 of file adpcmenc.c.

◆ CASE_3

#define CASE_3 ( config,
codec_id,
... )
Value:
CASE_2(config, codec_id, __VA_ARGS__)
#define CASE_2(enabled, codec_id,...)
Definition adpcm.c:76

Definition at line 51 of file adpcmenc.c.

◆ CASE

#define CASE ( codec,
... )
Value:
CASE_3(CONFIG_ ## codec ## _ENCODER, AV_CODEC_ID_ ## codec, __VA_ARGS__)
#define CASE_3(config, codec_id,...)
Definition adpcm.c:78

Definition at line 53 of file adpcmenc.c.

Referenced by adpcm_encode_init().

◆ FREEZE_INTERVAL

#define FREEZE_INTERVAL   128

◆ STORE_NODE

#define STORE_NODE ( NAME,
STEP_INDEX )

Referenced by adpcm_compress_trellis().

◆ 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 *\
STORE_NODE(NAME, STEP_INDEX);\
}
const int8_t ff_adpcm_yamaha_difflookup[]
Definition adpcm_data.c:74
#define av_clip
Definition common.h:100
static void predictor(uint8_t *src, ptrdiff_t size)
Definition exrenc.c:170
#define sample
enum AVColorRange range

Referenced by adpcm_compress_trellis().

◆ ADPCM_ENCODER_0

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

Definition at line 968 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.capabilities = capabilities_ | AV_CODEC_CAP_DR1 | \
CODEC_SAMPLEFMTS_ARRAY(sample_fmts_), \
.priv_data_size = sizeof(ADPCMEncodeContext), \
.close = adpcm_encode_close, \
.caps_internal = FF_CODEC_CAP_INIT_CLEANUP, \
__VA_ARGS__, \
};
static av_cold int adpcm_encode_init(AVCodecContext *avctx)
Definition adpcmenc.c:82
static int adpcm_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Definition adpcmenc.c:570
static av_cold int adpcm_encode_close(AVCodecContext *avctx)
Definition adpcmenc.c:204
#define FF_CODEC_ENCODE_CB(func)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
Definition codec.h:147
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201

Definition at line 969 of file adpcmenc.c.

◆ ADPCM_ENCODER_2

#define ADPCM_ENCODER_2 ( enabled,
codec_id,
name,
sample_fmts,
capabilities,
long_name,
... )
Value:
ADPCM_ENCODER_ ## enabled(codec_id, name, sample_fmts, capabilities, long_name, __VA_ARGS__)
static enum AVSampleFormat sample_fmts[]
Definition adpcmenc.c:933
const char * name
Definition qsvenc.c:142

Definition at line 985 of file adpcmenc.c.

◆ ADPCM_ENCODER_3

#define ADPCM_ENCODER_3 ( config,
codec_id,
name,
sample_fmts,
capabilities,
long_name,
... )
Value:
ADPCM_ENCODER_2(config, codec_id, name, sample_fmts, capabilities, long_name, __VA_ARGS__)
#define ADPCM_ENCODER_2(enabled, codec_id, name, sample_fmts, capabilities, long_name,...)
Definition adpcmenc.c:985

Definition at line 987 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, __VA_ARGS__)
#define ADPCM_ENCODER_3(config, codec_id, name, sample_fmts, capabilities, long_name,...)
Definition adpcmenc.c:987

Definition at line 989 of file adpcmenc.c.

◆ MONO_STEREO

Definition at line 993 of file adpcmenc.c.

◆ AVCLASS

#define AVCLASS   .p.priv_class = &adpcm_encoder_class

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

◆ adpcm_ima_compress_sample()

static uint8_t adpcm_ima_compress_sample ( ADPCMChannelStatus * c,
int16_t sample )
inlinestatic

Definition at line 216 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 229 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 248 of file adpcmenc.c.

◆ adpcm_ms_compress_sample()

static uint8_t adpcm_ms_compress_sample ( ADPCMChannelStatus * c,
int16_t sample )
inlinestatic

Definition at line 285 of file adpcmenc.c.

◆ adpcm_yamaha_compress_sample()

static uint8_t adpcm_yamaha_compress_sample ( ADPCMChannelStatus * c,
int16_t sample )
inlinestatic

Definition at line 314 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 336 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 570 of file adpcmenc.c.

Variable Documentation

◆ sample_fmts

◆ sample_fmts_p

enum AVSampleFormat sample_fmts_p[]
static
Initial value:
= {
}
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
Definition samplefmt.h:64

Definition at line 937 of file adpcmenc.c.

◆ ch_layouts_mono_stereo

const AVChannelLayout ch_layouts_mono_stereo[]
static
Initial value:
= {
{ 0 },
}
#define AV_CHANNEL_LAYOUT_STEREO
#define AV_CHANNEL_LAYOUT_MONO

Definition at line 941 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 }
}
#define NULL
Definition coverity.c:32
#define AV_OPT_FLAG_AUDIO_PARAM
Definition opt.h:356
#define AV_OPT_FLAG_ENCODING_PARAM
A generic parameter which can be set by the user for muxing or encoding.
Definition opt.h:351
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258

Definition at line 947 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,
}
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:241
#define LIBAVUTIL_VERSION_INT
Definition version.h:85

Definition at line 961 of file adpcmenc.c.