FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Enumerations | Functions | Variables
mlpenc.c File Reference
#include "avcodec.h"
#include "internal.h"
#include "put_bits.h"
#include "audio_frame_queue.h"
#include "libavutil/crc.h"
#include "libavutil/avstring.h"
#include "libavutil/samplefmt.h"
#include "mlp.h"
#include "lpc.h"

Go to the source code of this file.

Data Structures

struct  RestartHeader
 
struct  MatrixParams
 
struct  DecodingParams
 
struct  BestOffset
 
struct  MLPEncodeContext
 
struct  PathCounter
 

Macros

#define MAJOR_HEADER_INTERVAL   16
 MLP encoder Copyright (c) 2008 Ramiro Polla. More...
 
#define MLP_MIN_LPC_ORDER   1
 
#define MLP_MAX_LPC_ORDER   8
 
#define MLP_MIN_LPC_SHIFT   8
 
#define MLP_MAX_LPC_SHIFT   15
 
#define HUFF_OFFSET_MIN   -16384
 
#define HUFF_OFFSET_MAX   16383
 
#define NUM_CODEBOOKS   4
 Number of possible codebooks (counting "no codebooks") More...
 
#define SYNC_MAJOR   0xf8726f
 
#define MAJOR_SYNC_INFO_SIGNATURE   0xB752
 
#define SYNC_MLP   0xbb
 
#define SYNC_TRUEHD   0xba
 
#define FLAGS_DVDA   0x4000
 
#define FLAGS_CONST   0x8000
 
#define SUBSTREAM_INFO_MAX_2_CHAN   0x01
 
#define SUBSTREAM_INFO_HIGH_RATE   0x02
 
#define SUBSTREAM_INFO_ALWAYS_SET   0x04
 
#define SUBSTREAM_INFO_2_SUBSTREAMS   0x08
 
#define SAMPLE_MAX(bitdepth)   ((1 << (bitdepth - 1)) - 1)
 
#define SAMPLE_MIN(bitdepth)   (~SAMPLE_MAX(bitdepth))
 
#define MSB_MASK(bits)   (-1u << bits)
 
#define ZERO_PATH   '0'
 
#define CODEBOOK_CHANGE_BITS   21
 

Enumerations

enum  ParamFlags {
  PARAMS_DEFAULT = 0xff, PARAM_PRESENCE_FLAGS = 1 << 8, PARAM_BLOCKSIZE = 1 << 7, PARAM_MATRIX = 1 << 6,
  PARAM_OUTSHIFT = 1 << 5, PARAM_QUANTSTEP = 1 << 4, PARAM_FIR = 1 << 3, PARAM_IIR = 1 << 2,
  PARAM_HUFFOFFSET = 1 << 1, PARAM_PRESENT = 1 << 0
}
 
enum  InputBitDepth { BITS_16, BITS_20, BITS_24 }
 
enum  MLPChMode { MLP_CHMODE_LEFT_RIGHT, MLP_CHMODE_LEFT_SIDE, MLP_CHMODE_RIGHT_SIDE, MLP_CHMODE_MID_SIDE }
 

Functions

static int compare_filter_params (const ChannelParams *prev_cp, const ChannelParams *cp, int filter)
 Compares two FilterParams structures and returns 1 if anything has changed. More...
 
static int compare_matrix_params (MLPEncodeContext *ctx, const MatrixParams *prev, const MatrixParams *mp)
 Compare two primitive matrices and returns 1 if anything has changed. More...
 
static int compare_decoding_params (MLPEncodeContext *ctx)
 Compares two DecodingParams and ChannelParams structures to decide if a new decoding params header has to be written. More...
 
static void copy_filter_params (ChannelParams *dst_cp, ChannelParams *src_cp, int filter)
 
static void copy_matrix_params (MatrixParams *dst, MatrixParams *src)
 
static void copy_restart_frame_params (MLPEncodeContext *ctx, unsigned int substr)
 
static void clear_decoding_params (MLPEncodeContext *ctx, DecodingParams decoding_params[MAX_SUBSTREAMS])
 Clears a DecodingParams struct the way it should be after a restart header. More...
 
static void clear_channel_params (MLPEncodeContext *ctx, ChannelParams channel_params[MAX_CHANNELS])
 Clears a ChannelParams struct the way it should be after a restart header. More...
 
static void default_decoding_params (MLPEncodeContext *ctx, DecodingParams decoding_params[MAX_SUBSTREAMS])
 Sets default vales in our encoder for a DecodingParams struct. More...
 
static int number_sbits (int number)
 Calculates the smallest number of bits it takes to encode a given signed value in two's complement. More...
 
static int mlp_peak_bitrate (int peak_bitrate, int sample_rate)
 
static av_cold int mlp_encode_init (AVCodecContext *avctx)
 
static void write_major_sync (MLPEncodeContext *ctx, uint8_t *buf, int buf_size)
 Writes a major sync header to the bitstream. More...
 
static void write_restart_header (MLPEncodeContext *ctx, PutBitContext *pb)
 Writes a restart header to the bitstream. More...
 
static void write_matrix_params (MLPEncodeContext *ctx, PutBitContext *pb)
 Writes matrix params for all primitive matrices to the bitstream. More...
 
static void write_filter_params (MLPEncodeContext *ctx, PutBitContext *pb, unsigned int channel, unsigned int filter)
 Writes filter parameters for one filter to the bitstream. More...
 
static void write_decoding_params (MLPEncodeContext *ctx, PutBitContext *pb, int params_changed)
 Writes decoding parameters to the bitstream. More...
 
static void write_block_data (MLPEncodeContext *ctx, PutBitContext *pb)
 Writes the residuals to the bitstream. More...
 
static uint8_twrite_substrs (MLPEncodeContext *ctx, uint8_t *buf, int buf_size, int restart_frame, uint16_t substream_data_len[MAX_SUBSTREAMS])
 Writes the substreams data to the bitstream. More...
 
static void write_frame_headers (MLPEncodeContext *ctx, uint8_t *frame_header, uint8_t *substream_headers, unsigned int length, int restart_frame, uint16_t substream_data_len[MAX_SUBSTREAMS])
 Writes the access unit and substream headers to the bitstream. More...
 
static unsigned int write_access_unit (MLPEncodeContext *ctx, uint8_t *buf, int buf_size, int restart_frame)
 Writes an entire access unit to the bitstream. More...
 
static void input_data_internal (MLPEncodeContext *ctx, const uint8_t *samples, int is24)
 Inputs data from the samples passed by lavc into the context, shifts them appropriately depending on the bit-depth, and calculates the lossless_check_data that will be written to the restart header. More...
 
static void input_data (MLPEncodeContext *ctx, void *samples)
 Wrapper function for inputting data in two different bit-depths. More...
 
static void input_to_sample_buffer (MLPEncodeContext *ctx)
 
static int number_trailing_zeroes (int32_t sample)
 Counts the number of trailing zeroes in a value. More...
 
static void determine_quant_step_size (MLPEncodeContext *ctx)
 Determines how many bits are zero at the end of all samples so they can be shifted out. More...
 
static void code_filter_coeffs (MLPEncodeContext *ctx, FilterParams *fp, int32_t *fcoeff)
 Determines the smallest number of bits needed to encode the filter coefficients, and if it's possible to right-shift their values without losing any precision. More...
 
static void set_filter_params (MLPEncodeContext *ctx, unsigned int channel, unsigned int filter, int clear_filter)
 Determines the best filter parameters for the given data and writes the necessary information to the context. More...
 
static void determine_filters (MLPEncodeContext *ctx)
 Tries to determine a good prediction filter, and applies it to the samples buffer if the filter is good enough. More...
 
static enum MLPChMode estimate_stereo_mode (MLPEncodeContext *ctx)
 
static void code_matrix_coeffs (MLPEncodeContext *ctx, unsigned int mat)
 Determines how many fractional bits are needed to encode matrix coefficients. More...
 
static void lossless_matrix_coeffs (MLPEncodeContext *ctx)
 Determines best coefficients to use for the lossless matrix. More...
 
static void no_codebook_bits_offset (MLPEncodeContext *ctx, unsigned int channel, int16_t offset, int32_t min, int32_t max, BestOffset *bo)
 Determines the amount of bits needed to encode the samples using no codebooks and a specified offset. More...
 
static void no_codebook_bits (MLPEncodeContext *ctx, unsigned int channel, int32_t min, int32_t max, BestOffset *bo)
 Determines the least amount of bits needed to encode the samples using no codebooks. More...
 
static void codebook_bits_offset (MLPEncodeContext *ctx, unsigned int channel, int codebook, int32_t sample_min, int32_t sample_max, int16_t offset, BestOffset *bo)
 Determines the least amount of bits needed to encode the samples using a given codebook and a given offset. More...
 
static void codebook_bits (MLPEncodeContext *ctx, unsigned int channel, int codebook, int offset, int32_t min, int32_t max, BestOffset *bo, int direction)
 Determines the least amount of bits needed to encode the samples using a given codebook. More...
 
static void determine_bits (MLPEncodeContext *ctx)
 Determines the least amount of bits needed to encode the samples using any or no codebook. More...
 
static int apply_filter (MLPEncodeContext *ctx, unsigned int channel)
 Applies the filter to the current samples, and saves the residual back into the samples buffer. More...
 
static void apply_filters (MLPEncodeContext *ctx)
 
static void generate_2_noise_channels (MLPEncodeContext *ctx)
 Generates two noise channels worth of data. More...
 
static void rematrix_channels (MLPEncodeContext *ctx)
 Rematrixes all channels using chosen coefficients. More...
 
static void clear_path_counter (PathCounter *path_counter)
 
static int compare_best_offset (BestOffset *prev, BestOffset *cur)
 
static int best_codebook_path_cost (MLPEncodeContext *ctx, unsigned int channel, PathCounter *src, int cur_codebook)
 
static void set_best_codebook (MLPEncodeContext *ctx)
 
static void set_major_params (MLPEncodeContext *ctx)
 Analyzes all collected bitcounts and selects the best parameters for each individual access unit. More...
 
static void analyze_sample_buffer (MLPEncodeContext *ctx)
 
static void process_major_frame (MLPEncodeContext *ctx)
 
static int mlp_encode_frame (AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet)
 
static av_cold int mlp_encode_close (AVCodecContext *avctx)
 

Variables

static ChannelParams restart_channel_params [MAX_CHANNELS]
 
static DecodingParams restart_decoding_params [MAX_SUBSTREAMS]
 
static BestOffset restart_best_offset [NUM_CODEBOOKS] = {{0}}
 
static const int codebook_extremes [3][2]
 Min and max values that can be encoded with each codebook. More...
 
static const char * path_counter_codebook [] = { "0", "1", "2", "3", }
 

Macro Definition Documentation

#define MAJOR_HEADER_INTERVAL   16

MLP encoder Copyright (c) 2008 Ramiro Polla.

This file is part of FFmpeg.

FFmpeg is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.

FFmpeg is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with FFmpeg; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

Definition at line 32 of file mlpenc.c.

Referenced by mlp_encode_init(), and set_major_params().

#define MLP_MIN_LPC_ORDER   1

Definition at line 34 of file mlpenc.c.

Referenced by set_filter_params().

#define MLP_MAX_LPC_ORDER   8

Definition at line 35 of file mlpenc.c.

Referenced by mlp_encode_init(), and set_filter_params().

#define MLP_MIN_LPC_SHIFT   8

Definition at line 36 of file mlpenc.c.

Referenced by set_filter_params().

#define MLP_MAX_LPC_SHIFT   15

Definition at line 37 of file mlpenc.c.

Referenced by set_filter_params().

#define HUFF_OFFSET_MIN   -16384

Definition at line 96 of file mlpenc.c.

Referenced by codebook_bits(), codebook_bits_offset(), determine_bits(), and no_codebook_bits().

#define HUFF_OFFSET_MAX   16383

Definition at line 97 of file mlpenc.c.

Referenced by codebook_bits(), codebook_bits_offset(), determine_bits(), and no_codebook_bits().

#define NUM_CODEBOOKS   4

Number of possible codebooks (counting "no codebooks")

Definition at line 100 of file mlpenc.c.

Referenced by clear_path_counter(), determine_bits(), and set_best_codebook().

#define SYNC_MAJOR   0xf8726f

Definition at line 207 of file mlpenc.c.

Referenced by write_major_sync().

#define MAJOR_SYNC_INFO_SIGNATURE   0xB752

Definition at line 208 of file mlpenc.c.

Referenced by write_major_sync().

#define SYNC_MLP   0xbb

Definition at line 210 of file mlpenc.c.

Referenced by write_major_sync().

#define SYNC_TRUEHD   0xba

Definition at line 211 of file mlpenc.c.

Referenced by write_major_sync().

#define FLAGS_DVDA   0x4000

Definition at line 214 of file mlpenc.c.

Referenced by mlp_encode_init().

#define FLAGS_CONST   0x8000

Definition at line 216 of file mlpenc.c.

#define SUBSTREAM_INFO_MAX_2_CHAN   0x01

Definition at line 218 of file mlpenc.c.

Referenced by mlp_encode_init().

#define SUBSTREAM_INFO_HIGH_RATE   0x02

Definition at line 219 of file mlpenc.c.

Referenced by mlp_encode_init(), and set_filter_params().

#define SUBSTREAM_INFO_ALWAYS_SET   0x04

Definition at line 220 of file mlpenc.c.

Referenced by mlp_encode_init().

#define SUBSTREAM_INFO_2_SUBSTREAMS   0x08

Definition at line 221 of file mlpenc.c.

#define SAMPLE_MAX (   bitdepth)    ((1 << (bitdepth - 1)) - 1)

Definition at line 1796 of file mlpenc.c.

Referenced by apply_filter().

#define SAMPLE_MIN (   bitdepth)    (~SAMPLE_MAX(bitdepth))

Definition at line 1797 of file mlpenc.c.

Referenced by apply_filter().

#define MSB_MASK (   bits)    (-1u << bits)

Definition at line 1799 of file mlpenc.c.

Referenced by apply_filter(), and rematrix_channels().

#define ZERO_PATH   '0'

Definition at line 1953 of file mlpenc.c.

Referenced by best_codebook_path_cost(), clear_path_counter(), and set_best_codebook().

#define CODEBOOK_CHANGE_BITS   21

Definition at line 1954 of file mlpenc.c.

Referenced by best_codebook_path_cost().

Enumeration Type Documentation

enum ParamFlags
Enumerator
PARAMS_DEFAULT 
PARAM_PRESENCE_FLAGS 
PARAM_BLOCKSIZE 
PARAM_MATRIX 
PARAM_OUTSHIFT 
PARAM_QUANTSTEP 
PARAM_FIR 
PARAM_IIR 
PARAM_HUFFOFFSET 
PARAM_PRESENT 

Definition at line 66 of file mlpenc.c.

Enumerator
BITS_16 
BITS_20 
BITS_24 

Definition at line 475 of file mlpenc.c.

enum MLPChMode
Enumerator
MLP_CHMODE_LEFT_RIGHT 
MLP_CHMODE_LEFT_SIDE 
MLP_CHMODE_RIGHT_SIDE 
MLP_CHMODE_MID_SIDE 

Definition at line 1440 of file mlpenc.c.

Function Documentation

static int compare_filter_params ( const ChannelParams prev_cp,
const ChannelParams cp,
int  filter 
)
static

Compares two FilterParams structures and returns 1 if anything has changed.

Returns 0 if they are both equal.

Definition at line 230 of file mlpenc.c.

Referenced by compare_decoding_params().

static int compare_matrix_params ( MLPEncodeContext ctx,
const MatrixParams prev,
const MatrixParams mp 
)
static

Compare two primitive matrices and returns 1 if anything has changed.

Returns 0 if they are both equal.

Definition at line 255 of file mlpenc.c.

Referenced by compare_decoding_params().

static int compare_decoding_params ( MLPEncodeContext ctx)
static

Compares two DecodingParams and ChannelParams structures to decide if a new decoding params header has to be written.

Definition at line 285 of file mlpenc.c.

Referenced by set_major_params().

static void copy_filter_params ( ChannelParams dst_cp,
ChannelParams src_cp,
int  filter 
)
static

Definition at line 339 of file mlpenc.c.

Referenced by copy_restart_frame_params().

static void copy_matrix_params ( MatrixParams dst,
MatrixParams src 
)
static

Definition at line 358 of file mlpenc.c.

Referenced by copy_restart_frame_params().

static void copy_restart_frame_params ( MLPEncodeContext ctx,
unsigned int  substr 
)
static

Definition at line 379 of file mlpenc.c.

Referenced by analyze_sample_buffer().

static void clear_decoding_params ( MLPEncodeContext ctx,
DecodingParams  decoding_params[MAX_SUBSTREAMS] 
)
static

Clears a DecodingParams struct the way it should be after a restart header.

Definition at line 405 of file mlpenc.c.

Referenced by default_decoding_params(), and mlp_encode_init().

static void clear_channel_params ( MLPEncodeContext ctx,
ChannelParams  channel_params[MAX_CHANNELS] 
)
static

Clears a ChannelParams struct the way it should be after a restart header.

Definition at line 421 of file mlpenc.c.

Referenced by mlp_encode_frame(), and mlp_encode_init().

static void default_decoding_params ( MLPEncodeContext ctx,
DecodingParams  decoding_params[MAX_SUBSTREAMS] 
)
static

Sets default vales in our encoder for a DecodingParams struct.

Definition at line 438 of file mlpenc.c.

Referenced by mlp_encode_frame().

static int number_sbits ( int  number)
inlinestatic

Calculates the smallest number of bits it takes to encode a given signed value in two's complement.

Definition at line 467 of file mlpenc.c.

Referenced by code_filter_coeffs(), input_data_internal(), no_codebook_bits(), and no_codebook_bits_offset().

static int mlp_peak_bitrate ( int  peak_bitrate,
int  sample_rate 
)
static

Definition at line 481 of file mlpenc.c.

Referenced by mlp_encode_init().

static av_cold int mlp_encode_init ( AVCodecContext avctx)
static

Definition at line 486 of file mlpenc.c.

static void write_major_sync ( MLPEncodeContext ctx,
uint8_t buf,
int  buf_size 
)
static

Writes a major sync header to the bitstream.

Definition at line 748 of file mlpenc.c.

Referenced by write_access_unit().

static void write_restart_header ( MLPEncodeContext ctx,
PutBitContext pb 
)
static

Writes a restart header to the bitstream.

Damaged streams can start being decoded losslessly again after such a header and the subsequent decoding params header.

Definition at line 807 of file mlpenc.c.

Referenced by write_substrs().

static void write_matrix_params ( MLPEncodeContext ctx,
PutBitContext pb 
)
static

Writes matrix params for all primitive matrices to the bitstream.

Definition at line 844 of file mlpenc.c.

Referenced by write_decoding_params().

static void write_filter_params ( MLPEncodeContext ctx,
PutBitContext pb,
unsigned int  channel,
unsigned int  filter 
)
static

Writes filter parameters for one filter to the bitstream.

Definition at line 876 of file mlpenc.c.

Referenced by write_decoding_params().

static void write_decoding_params ( MLPEncodeContext ctx,
PutBitContext pb,
int  params_changed 
)
static

Writes decoding parameters to the bitstream.

These change very often, usually at almost every frame.

Definition at line 903 of file mlpenc.c.

Referenced by write_substrs().

static void write_block_data ( MLPEncodeContext ctx,
PutBitContext pb 
)
static

Writes the residuals to the bitstream.

That is, the VLC codes from the codebooks (if any is used), and then the residual.

Definition at line 1001 of file mlpenc.c.

Referenced by write_substrs().

static uint8_t* write_substrs ( MLPEncodeContext ctx,
uint8_t buf,
int  buf_size,
int  restart_frame,
uint16_t  substream_data_len[MAX_SUBSTREAMS] 
)
static

Writes the substreams data to the bitstream.

Definition at line 1052 of file mlpenc.c.

Referenced by write_access_unit().

static void write_frame_headers ( MLPEncodeContext ctx,
uint8_t frame_header,
uint8_t substream_headers,
unsigned int  length,
int  restart_frame,
uint16_t  substream_data_len[MAX_SUBSTREAMS] 
)
static

Writes the access unit and substream headers to the bitstream.

Definition at line 1144 of file mlpenc.c.

Referenced by write_access_unit().

static unsigned int write_access_unit ( MLPEncodeContext ctx,
uint8_t buf,
int  buf_size,
int  restart_frame 
)
static

Writes an entire access unit to the bitstream.

Definition at line 1183 of file mlpenc.c.

Referenced by mlp_encode_frame().

static void input_data_internal ( MLPEncodeContext ctx,
const uint8_t samples,
int  is24 
)
static

Inputs data from the samples passed by lavc into the context, shifts them appropriately depending on the bit-depth, and calculates the lossless_check_data that will be written to the restart header.

Definition at line 1231 of file mlpenc.c.

Referenced by input_data().

static void input_data ( MLPEncodeContext ctx,
void samples 
)
static

Wrapper function for inputting data in two different bit-depths.

Examples:
transcode_aac.c.

Definition at line 1275 of file mlpenc.c.

Referenced by apng_do_inverse_blend(), and mlp_encode_frame().

static void input_to_sample_buffer ( MLPEncodeContext ctx)
static

Definition at line 1283 of file mlpenc.c.

Referenced by mlp_encode_frame().

static int number_trailing_zeroes ( int32_t  sample)
static

Counts the number of trailing zeroes in a value.

Definition at line 1307 of file mlpenc.c.

Referenced by determine_quant_step_size().

static void determine_quant_step_size ( MLPEncodeContext ctx)
static

Determines how many bits are zero at the end of all samples so they can be shifted out.

Definition at line 1324 of file mlpenc.c.

Referenced by analyze_sample_buffer().

static void code_filter_coeffs ( MLPEncodeContext ctx,
FilterParams fp,
int32_t fcoeff 
)
static

Determines the smallest number of bits needed to encode the filter coefficients, and if it's possible to right-shift their values without losing any precision.

Definition at line 1351 of file mlpenc.c.

Referenced by set_filter_params().

static void set_filter_params ( MLPEncodeContext ctx,
unsigned int  channel,
unsigned int  filter,
int  clear_filter 
)
static

Determines the best filter parameters for the given data and writes the necessary information to the context.

TODO Add IIR filter predictor!

Definition at line 1381 of file mlpenc.c.

Referenced by apply_filters(), and determine_filters().

static void determine_filters ( MLPEncodeContext ctx)
static

Tries to determine a good prediction filter, and applies it to the samples buffer if the filter is good enough.

Sets the filter data to be cleared if no good filter was found.

Definition at line 1429 of file mlpenc.c.

Referenced by analyze_sample_buffer().

static enum MLPChMode estimate_stereo_mode ( MLPEncodeContext ctx)
static

Definition at line 1447 of file mlpenc.c.

Referenced by lossless_matrix_coeffs().

static void code_matrix_coeffs ( MLPEncodeContext ctx,
unsigned int  mat 
)
static

Determines how many fractional bits are needed to encode matrix coefficients.

Also shifts the coefficients to fit within 2.14 bits.

Definition at line 1480 of file mlpenc.c.

Referenced by lossless_matrix_coeffs().

static void lossless_matrix_coeffs ( MLPEncodeContext ctx)
static

Determines best coefficients to use for the lossless matrix.

Definition at line 1499 of file mlpenc.c.

Referenced by analyze_sample_buffer().

static void no_codebook_bits_offset ( MLPEncodeContext ctx,
unsigned int  channel,
int16_t  offset,
int32_t  min,
int32_t  max,
BestOffset bo 
)
static

Determines the amount of bits needed to encode the samples using no codebooks and a specified offset.

Definition at line 1559 of file mlpenc.c.

Referenced by determine_bits().

static void no_codebook_bits ( MLPEncodeContext ctx,
unsigned int  channel,
int32_t  min,
int32_t  max,
BestOffset bo 
)
static

Determines the least amount of bits needed to encode the samples using no codebooks.

Definition at line 1587 of file mlpenc.c.

Referenced by determine_bits().

static void codebook_bits_offset ( MLPEncodeContext ctx,
unsigned int  channel,
int  codebook,
int32_t  sample_min,
int32_t  sample_max,
int16_t  offset,
BestOffset bo 
)
inlinestatic

Determines the least amount of bits needed to encode the samples using a given codebook and a given offset.

Definition at line 1626 of file mlpenc.c.

Referenced by codebook_bits(), and determine_bits().

static void codebook_bits ( MLPEncodeContext ctx,
unsigned int  channel,
int  codebook,
int  offset,
int32_t  min,
int32_t  max,
BestOffset bo,
int  direction 
)
inlinestatic

Determines the least amount of bits needed to encode the samples using a given codebook.

Searches for the best offset to minimize the bits.

Definition at line 1690 of file mlpenc.c.

Referenced by determine_bits().

static void determine_bits ( MLPEncodeContext ctx)
static

Determines the least amount of bits needed to encode the samples using any or no codebook.

Definition at line 1734 of file mlpenc.c.

Referenced by analyze_sample_buffer().

static int apply_filter ( MLPEncodeContext ctx,
unsigned int  channel 
)
static

Applies the filter to the current samples, and saves the residual back into the samples buffer.

If the filter is too bad and overflows the maximum amount of bits allowed (16 or 24), the samples buffer is left as is and the function returns -1.

Definition at line 1806 of file mlpenc.c.

Referenced by apply_filters(), and process_major_frame().

static void apply_filters ( MLPEncodeContext ctx)
static

Definition at line 1874 of file mlpenc.c.

Referenced by analyze_sample_buffer().

static void generate_2_noise_channels ( MLPEncodeContext ctx)
static

Generates two noise channels worth of data.

Definition at line 1891 of file mlpenc.c.

Referenced by analyze_sample_buffer(), and process_major_frame().

static void rematrix_channels ( MLPEncodeContext ctx)
static

Rematrixes all channels using chosen coefficients.

Definition at line 1912 of file mlpenc.c.

Referenced by analyze_sample_buffer(), and process_major_frame().

static void clear_path_counter ( PathCounter path_counter)
static

Definition at line 1956 of file mlpenc.c.

Referenced by set_best_codebook().

static int compare_best_offset ( BestOffset prev,
BestOffset cur 
)
static

Definition at line 1967 of file mlpenc.c.

Referenced by best_codebook_path_cost(), and set_best_codebook().

static int best_codebook_path_cost ( MLPEncodeContext ctx,
unsigned int  channel,
PathCounter src,
int  cur_codebook 
)
static

Definition at line 1975 of file mlpenc.c.

Referenced by set_best_codebook().

static void set_best_codebook ( MLPEncodeContext ctx)
static

Definition at line 2000 of file mlpenc.c.

Referenced by analyze_sample_buffer().

static void set_major_params ( MLPEncodeContext ctx)
static

Analyzes all collected bitcounts and selects the best parameters for each individual access unit.

TODO This is just a stub!

Definition at line 2083 of file mlpenc.c.

Referenced by mlp_encode_frame().

static void analyze_sample_buffer ( MLPEncodeContext ctx)
static

Definition at line 2143 of file mlpenc.c.

Referenced by mlp_encode_frame().

static void process_major_frame ( MLPEncodeContext ctx)
static

Definition at line 2191 of file mlpenc.c.

Referenced by mlp_encode_frame().

static int mlp_encode_frame ( AVCodecContext avctx,
AVPacket avpkt,
const AVFrame frame,
int *  got_packet 
)
static

Definition at line 2220 of file mlpenc.c.

static av_cold int mlp_encode_close ( AVCodecContext avctx)
static

Definition at line 2367 of file mlpenc.c.

Variable Documentation

ChannelParams restart_channel_params[MAX_CHANNELS]
static

Definition at line 203 of file mlpenc.c.

Referenced by set_major_params().

DecodingParams restart_decoding_params[MAX_SUBSTREAMS]
static

Definition at line 204 of file mlpenc.c.

BestOffset restart_best_offset[NUM_CODEBOOKS] = {{0}}
static

Definition at line 205 of file mlpenc.c.

Referenced by best_codebook_path_cost(), and set_best_codebook().

const int codebook_extremes[3][2]
static
Initial value:
= {
{-9, 8}, {-8, 7}, {-15, 14},
}

Min and max values that can be encoded with each codebook.

The values for the third codebook take into account the fact that the sign shift for this codebook is outside the coded value, so it has one more bit of precision. It should actually be -7 -> 7, shifted down by 0.5.

Definition at line 1552 of file mlpenc.c.

Referenced by codebook_bits_offset().

const char* path_counter_codebook[] = { "0", "1", "2", "3", }
static

Definition at line 1951 of file mlpenc.c.

Referenced by set_best_codebook().