FFmpeg
Data Structures | Macros | Functions | Variables
alacenc.c File Reference
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "avcodec.h"
#include "codec_internal.h"
#include "encode.h"
#include "put_bits.h"
#include "lpc.h"
#include "mathops.h"
#include "alac_data.h"

Go to the source code of this file.

Data Structures

struct  RiceContext
 
struct  AlacLPCContext
 
struct  AlacEncodeContext
 

Macros

#define DEFAULT_FRAME_SIZE   4096
 
#define ALAC_EXTRADATA_SIZE   36
 
#define ALAC_FRAME_HEADER_SIZE   55
 
#define ALAC_FRAME_FOOTER_SIZE   3
 
#define ALAC_ESCAPE_CODE   0x1FF
 
#define ALAC_MAX_LPC_ORDER   30
 
#define DEFAULT_MAX_PRED_ORDER   6
 
#define DEFAULT_MIN_PRED_ORDER   4
 
#define ALAC_MAX_LPC_PRECISION   9
 
#define ALAC_MIN_LPC_SHIFT   0
 
#define ALAC_MAX_LPC_SHIFT   9
 
#define ALAC_CHMODE_LEFT_RIGHT   0
 
#define ALAC_CHMODE_LEFT_SIDE   1
 
#define ALAC_CHMODE_RIGHT_SIDE   2
 
#define ALAC_CHMODE_MID_SIDE   3
 
#define COPY_SAMPLES(type)
 
#define OFFSET(x)   offsetof(AlacEncodeContext, x)
 
#define AE   AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
 

Functions

static void init_sample_buffers (AlacEncodeContext *s, int channels, const uint8_t *samples[2])
 
static void encode_scalar (AlacEncodeContext *s, int x, int k, int write_sample_size)
 
static void write_element_header (AlacEncodeContext *s, enum AlacRawDataBlockType element, int instance)
 
static void calc_predictor_params (AlacEncodeContext *s, int ch)
 
static int estimate_stereo_mode (int32_t *left_ch, int32_t *right_ch, int n)
 
static void alac_stereo_decorrelation (AlacEncodeContext *s)
 
static void alac_linear_predictor (AlacEncodeContext *s, int ch)
 
static void alac_entropy_coder (AlacEncodeContext *s, int ch)
 
static void write_element (AlacEncodeContext *s, enum AlacRawDataBlockType element, int instance, const uint8_t *samples0, const uint8_t *samples1)
 
static int write_frame (AlacEncodeContext *s, AVPacket *avpkt, uint8_t *const *samples)
 
static av_always_inline int get_max_frame_size (int frame_size, int ch, int bps)
 
static av_cold int alac_encode_close (AVCodecContext *avctx)
 
static av_cold int alac_encode_init (AVCodecContext *avctx)
 
static int alac_encode_frame (AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
 

Variables

static const AVOption options []
 
static const AVClass alacenc_class
 
const FFCodec ff_alac_encoder
 

Macro Definition Documentation

◆ DEFAULT_FRAME_SIZE

#define DEFAULT_FRAME_SIZE   4096

Definition at line 33 of file alacenc.c.

◆ ALAC_EXTRADATA_SIZE

#define ALAC_EXTRADATA_SIZE   36

Definition at line 34 of file alacenc.c.

◆ ALAC_FRAME_HEADER_SIZE

#define ALAC_FRAME_HEADER_SIZE   55

Definition at line 35 of file alacenc.c.

◆ ALAC_FRAME_FOOTER_SIZE

#define ALAC_FRAME_FOOTER_SIZE   3

Definition at line 36 of file alacenc.c.

◆ ALAC_ESCAPE_CODE

#define ALAC_ESCAPE_CODE   0x1FF

Definition at line 38 of file alacenc.c.

◆ ALAC_MAX_LPC_ORDER

#define ALAC_MAX_LPC_ORDER   30

Definition at line 39 of file alacenc.c.

◆ DEFAULT_MAX_PRED_ORDER

#define DEFAULT_MAX_PRED_ORDER   6

Definition at line 40 of file alacenc.c.

◆ DEFAULT_MIN_PRED_ORDER

#define DEFAULT_MIN_PRED_ORDER   4

Definition at line 41 of file alacenc.c.

◆ ALAC_MAX_LPC_PRECISION

#define ALAC_MAX_LPC_PRECISION   9

Definition at line 42 of file alacenc.c.

◆ ALAC_MIN_LPC_SHIFT

#define ALAC_MIN_LPC_SHIFT   0

Definition at line 43 of file alacenc.c.

◆ ALAC_MAX_LPC_SHIFT

#define ALAC_MAX_LPC_SHIFT   9

Definition at line 44 of file alacenc.c.

◆ ALAC_CHMODE_LEFT_RIGHT

#define ALAC_CHMODE_LEFT_RIGHT   0

Definition at line 46 of file alacenc.c.

◆ ALAC_CHMODE_LEFT_SIDE

#define ALAC_CHMODE_LEFT_SIDE   1

Definition at line 47 of file alacenc.c.

◆ ALAC_CHMODE_RIGHT_SIDE

#define ALAC_CHMODE_RIGHT_SIDE   2

Definition at line 48 of file alacenc.c.

◆ ALAC_CHMODE_MID_SIDE

#define ALAC_CHMODE_MID_SIDE   3

Definition at line 49 of file alacenc.c.

◆ COPY_SAMPLES

#define COPY_SAMPLES (   type)
Value:
do { \
for (ch = 0; ch < channels; ch++) { \
int32_t *bptr = s->sample_buf[ch]; \
const type *sptr = (const type *)samples[ch]; \
for (i = 0; i < s->frame_size; i++) \
bptr[i] = sptr[i] >> shift; \
} \
} while (0)

◆ OFFSET

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

Definition at line 621 of file alacenc.c.

◆ AE

Definition at line 622 of file alacenc.c.

Function Documentation

◆ init_sample_buffers()

static void init_sample_buffers ( AlacEncodeContext s,
int  channels,
const uint8_t *  samples[2] 
)
static

Definition at line 86 of file alacenc.c.

Referenced by write_element().

◆ encode_scalar()

static void encode_scalar ( AlacEncodeContext s,
int  x,
int  k,
int  write_sample_size 
)
static

Definition at line 108 of file alacenc.c.

Referenced by alac_entropy_coder().

◆ write_element_header()

static void write_element_header ( AlacEncodeContext s,
enum AlacRawDataBlockType  element,
int  instance 
)
static

Definition at line 136 of file alacenc.c.

Referenced by write_element().

◆ calc_predictor_params()

static void calc_predictor_params ( AlacEncodeContext s,
int  ch 
)
static

Definition at line 155 of file alacenc.c.

Referenced by write_element().

◆ estimate_stereo_mode()

static int estimate_stereo_mode ( int32_t left_ch,
int32_t right_ch,
int  n 
)
static

Definition at line 186 of file alacenc.c.

Referenced by alac_stereo_decorrelation().

◆ alac_stereo_decorrelation()

static void alac_stereo_decorrelation ( AlacEncodeContext s)
static

Definition at line 219 of file alacenc.c.

Referenced by write_element().

◆ alac_linear_predictor()

static void alac_linear_predictor ( AlacEncodeContext s,
int  ch 
)
static

Definition at line 259 of file alacenc.c.

Referenced by write_element().

◆ alac_entropy_coder()

static void alac_entropy_coder ( AlacEncodeContext s,
int  ch 
)
static

Definition at line 323 of file alacenc.c.

Referenced by write_element().

◆ write_element()

static void write_element ( AlacEncodeContext s,
enum AlacRawDataBlockType  element,
int  instance,
const uint8_t *  samples0,
const uint8_t *  samples1 
)
static

Definition at line 367 of file alacenc.c.

Referenced by write_frame().

◆ write_frame()

static int write_frame ( AlacEncodeContext s,
AVPacket avpkt,
uint8_t *const *  samples 
)
static

Definition at line 462 of file alacenc.c.

Referenced by alac_encode_frame().

◆ get_max_frame_size()

static av_always_inline int get_max_frame_size ( int  frame_size,
int  ch,
int  bps 
)
static

Definition at line 494 of file alacenc.c.

Referenced by alac_encode_frame(), and alac_encode_init().

◆ alac_encode_close()

static av_cold int alac_encode_close ( AVCodecContext avctx)
static

Definition at line 500 of file alacenc.c.

◆ alac_encode_init()

static av_cold int alac_encode_init ( AVCodecContext avctx)
static

Definition at line 507 of file alacenc.c.

◆ alac_encode_frame()

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

Definition at line 581 of file alacenc.c.

Variable Documentation

◆ options

const AVOption options[]
static
Initial value:
= {
{ "min_prediction_order", NULL, OFFSET(min_prediction_order), AV_OPT_TYPE_INT, { .i64 = DEFAULT_MIN_PRED_ORDER }, MIN_LPC_ORDER, ALAC_MAX_LPC_ORDER, AE },
{ "max_prediction_order", NULL, OFFSET(max_prediction_order), AV_OPT_TYPE_INT, { .i64 = DEFAULT_MAX_PRED_ORDER }, MIN_LPC_ORDER, ALAC_MAX_LPC_ORDER, AE },
{ NULL },
}

Definition at line 623 of file alacenc.c.

◆ alacenc_class

const AVClass alacenc_class
static
Initial value:
= {
.class_name = "alacenc",
.item_name = av_default_item_name,
.option = options,
}

Definition at line 630 of file alacenc.c.

◆ ff_alac_encoder

const FFCodec ff_alac_encoder
Initial value:
= {
.p.name = "alac",
CODEC_LONG_NAME("ALAC (Apple Lossless Audio Codec)"),
.p.type = AVMEDIA_TYPE_AUDIO,
.priv_data_size = sizeof(AlacEncodeContext),
.p.priv_class = &alacenc_class,
.p.ch_layouts = ff_alac_ch_layouts,
.p.sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S32P,
}

Definition at line 637 of file alacenc.c.

OFFSET
#define OFFSET(x)
Definition: alacenc.c:621
DEFAULT_MIN_PRED_ORDER
#define DEFAULT_MIN_PRED_ORDER
Definition: alacenc.c:41
alac_encode_init
static av_cold int alac_encode_init(AVCodecContext *avctx)
Definition: alacenc.c:507
AV_SAMPLE_FMT_S32P
@ AV_SAMPLE_FMT_S32P
signed 32 bits, planar
Definition: samplefmt.h:65
AV_CODEC_ID_ALAC
@ AV_CODEC_ID_ALAC
Definition: codec_id.h:462
DEFAULT_MAX_PRED_ORDER
#define DEFAULT_MAX_PRED_ORDER
Definition: alacenc.c:40
type
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 type
Definition: writing_filters.txt:86
alacenc_class
static const AVClass alacenc_class
Definition: alacenc.c:630
FF_CODEC_ENCODE_CB
#define FF_CODEC_ENCODE_CB(func)
Definition: codec_internal.h:320
alac_encode_frame
static int alac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Definition: alacenc.c:581
s
#define s(width, name)
Definition: cbs_vp9.c:198
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
#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:159
channels
channels
Definition: aptx.h:31
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:296
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
AE
#define AE
Definition: alacenc.c:622
options
static const AVOption options[]
Definition: alacenc.c:623
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
shift
static int shift(int a, int b)
Definition: bonk.c:261
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
MIN_LPC_ORDER
#define MIN_LPC_ORDER
Definition: lpc.h:36
AV_SAMPLE_FMT_S16P
@ AV_SAMPLE_FMT_S16P
signed 16 bits, planar
Definition: samplefmt.h:64
ALAC_MAX_LPC_ORDER
#define ALAC_MAX_LPC_ORDER
Definition: alacenc.c:39
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:256
ff_alac_ch_layouts
const AVChannelLayout ff_alac_ch_layouts[ALAC_MAX_CHANNELS+1]
Definition: alac_data.c:35
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition: opt.h:259
samples
Filter the word “frame” indicates either a video frame or a group of audio samples
Definition: filter_design.txt:8
alac_encode_close
static av_cold int alac_encode_close(AVCodecContext *avctx)
Definition: alacenc.c:500
AlacEncodeContext
Definition: alacenc.c:64
AV_CODEC_CAP_SMALL_LAST_FRAME
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
Definition: codec.h:81