FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
mlpenc.c File Reference
#include "avcodec.h"
#include "encode.h"
#include "internal.h"
#include "put_bits.h"
#include "audio_frame_queue.h"
#include "libavutil/channel_layout.h"
#include "libavutil/crc.h"
#include "libavutil/avstring.h"
#include "libavutil/intmath.h"
#include "libavutil/samplefmt.h"
#include "libavutil/thread.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 Copyright (c) 2016-2019 Jai Luthra. 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 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)   (-(int)(1u << (bits)))
 
#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)
 
static void clear_decoding_params (DecodingParams *decoding_params)
 Clears a DecodingParams struct the way it should be after a restart header. More...
 
static void clear_channel_params (ChannelParams channel_params[MAX_CHANNELS], int nb_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)
 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 void mlp_encode_init_static (void)
 
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_t * write_substr (MLPEncodeContext *ctx, uint8_t *buf, int buf_size, int restart_frame, uint16_t substream_data_len[MAX_SUBSTREAMS])
 Writes the substream 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[1])
 Writes the access unit and substream headers to the bitstream. More...
 
static 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 (const BestOffset *prev, const 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 const 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...
 

Macro Definition Documentation

◆ MAJOR_HEADER_INTERVAL

#define MAJOR_HEADER_INTERVAL   16

MLP encoder Copyright (c) 2008 Ramiro Polla Copyright (c) 2016-2019 Jai Luthra.

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 37 of file mlpenc.c.

◆ MLP_MIN_LPC_ORDER

#define MLP_MIN_LPC_ORDER   1

Definition at line 39 of file mlpenc.c.

◆ MLP_MAX_LPC_ORDER

#define MLP_MAX_LPC_ORDER   8

Definition at line 40 of file mlpenc.c.

◆ MLP_MIN_LPC_SHIFT

#define MLP_MIN_LPC_SHIFT   8

Definition at line 41 of file mlpenc.c.

◆ MLP_MAX_LPC_SHIFT

#define MLP_MAX_LPC_SHIFT   15

Definition at line 42 of file mlpenc.c.

◆ HUFF_OFFSET_MIN

#define HUFF_OFFSET_MIN   (-16384)

Definition at line 101 of file mlpenc.c.

◆ HUFF_OFFSET_MAX

#define HUFF_OFFSET_MAX   ( 16383)

Definition at line 102 of file mlpenc.c.

◆ NUM_CODEBOOKS

#define NUM_CODEBOOKS   4

Number of possible codebooks (counting "no codebooks")

Definition at line 105 of file mlpenc.c.

◆ SYNC_MAJOR

#define SYNC_MAJOR   0xf8726f

Definition at line 214 of file mlpenc.c.

◆ MAJOR_SYNC_INFO_SIGNATURE

#define MAJOR_SYNC_INFO_SIGNATURE   0xB752

Definition at line 215 of file mlpenc.c.

◆ FLAGS_DVDA

#define FLAGS_DVDA   0x4000

Definition at line 218 of file mlpenc.c.

◆ FLAGS_CONST

#define FLAGS_CONST   0x8000

Definition at line 220 of file mlpenc.c.

◆ SUBSTREAM_INFO_MAX_2_CHAN

#define SUBSTREAM_INFO_MAX_2_CHAN   0x01

Definition at line 222 of file mlpenc.c.

◆ SUBSTREAM_INFO_HIGH_RATE

#define SUBSTREAM_INFO_HIGH_RATE   0x02

Definition at line 223 of file mlpenc.c.

◆ SUBSTREAM_INFO_ALWAYS_SET

#define SUBSTREAM_INFO_ALWAYS_SET   0x04

Definition at line 224 of file mlpenc.c.

◆ SUBSTREAM_INFO_2_SUBSTREAMS

#define SUBSTREAM_INFO_2_SUBSTREAMS   0x08

Definition at line 225 of file mlpenc.c.

◆ SAMPLE_MAX

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

Definition at line 1718 of file mlpenc.c.

◆ SAMPLE_MIN

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

Definition at line 1719 of file mlpenc.c.

◆ MSB_MASK

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

Definition at line 1721 of file mlpenc.c.

◆ CODEBOOK_CHANGE_BITS

#define CODEBOOK_CHANGE_BITS   21

Definition at line 1854 of file mlpenc.c.

Enumeration Type Documentation

◆ ParamFlags

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 71 of file mlpenc.c.

◆ InputBitDepth

Enumerator
BITS_16 
BITS_20 
BITS_24 

Definition at line 457 of file mlpenc.c.

◆ MLPChMode

enum MLPChMode
Enumerator
MLP_CHMODE_LEFT_RIGHT 
MLP_CHMODE_LEFT_SIDE 
MLP_CHMODE_RIGHT_SIDE 
MLP_CHMODE_MID_SIDE 

Definition at line 1370 of file mlpenc.c.

Function Documentation

◆ compare_filter_params()

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 234 of file mlpenc.c.

Referenced by compare_decoding_params().

◆ compare_matrix_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 258 of file mlpenc.c.

Referenced by compare_decoding_params().

◆ 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 287 of file mlpenc.c.

Referenced by set_major_params().

◆ copy_filter_params()

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

Definition at line 340 of file mlpenc.c.

Referenced by copy_restart_frame_params().

◆ copy_matrix_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().

◆ copy_restart_frame_params()

static void copy_restart_frame_params ( MLPEncodeContext ctx)
static

Definition at line 377 of file mlpenc.c.

Referenced by analyze_sample_buffer().

◆ clear_decoding_params()

static void clear_decoding_params ( DecodingParams decoding_params)
static

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

Definition at line 398 of file mlpenc.c.

Referenced by default_decoding_params(), and mlp_encode_init_static().

◆ clear_channel_params()

static void clear_channel_params ( ChannelParams  channel_params[MAX_CHANNELS],
int  nb_channels 
)
static

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

Definition at line 410 of file mlpenc.c.

Referenced by mlp_encode_frame(), and mlp_encode_init_static().

◆ default_decoding_params()

static void default_decoding_params ( MLPEncodeContext ctx,
DecodingParams decoding_params 
)
static

Sets default vales in our encoder for a DecodingParams struct.

Definition at line 425 of file mlpenc.c.

Referenced by mlp_encode_frame().

◆ number_sbits()

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 449 of file mlpenc.c.

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

◆ mlp_peak_bitrate()

static int mlp_peak_bitrate ( int  peak_bitrate,
int  sample_rate 
)
static

Definition at line 463 of file mlpenc.c.

Referenced by mlp_encode_init().

◆ mlp_encode_init_static()

static av_cold void mlp_encode_init_static ( void  )
static

Definition at line 468 of file mlpenc.c.

Referenced by mlp_encode_init().

◆ mlp_encode_init()

static av_cold int mlp_encode_init ( AVCodecContext avctx)
static

Definition at line 475 of file mlpenc.c.

◆ write_major_sync()

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 709 of file mlpenc.c.

Referenced by write_access_unit().

◆ write_restart_header()

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 768 of file mlpenc.c.

Referenced by write_substr().

◆ write_matrix_params()

static void write_matrix_params ( MLPEncodeContext ctx,
PutBitContext pb 
)
static

Writes matrix params for all primitive matrices to the bitstream.

Definition at line 804 of file mlpenc.c.

Referenced by write_decoding_params().

◆ write_filter_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 833 of file mlpenc.c.

Referenced by write_decoding_params().

◆ 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 859 of file mlpenc.c.

Referenced by write_substr().

◆ write_block_data()

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 959 of file mlpenc.c.

Referenced by write_substr().

◆ write_substr()

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

Writes the substream data to the bitstream.

Definition at line 1006 of file mlpenc.c.

Referenced by write_access_unit().

◆ write_frame_headers()

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[1] 
)
static

Writes the access unit and substream headers to the bitstream.

Definition at line 1096 of file mlpenc.c.

Referenced by write_access_unit().

◆ write_access_unit()

static 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 1134 of file mlpenc.c.

Referenced by mlp_encode_frame().

◆ input_data_internal()

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 1176 of file mlpenc.c.

Referenced by input_data().

◆ 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 1214 of file mlpenc.c.

Referenced by apng_do_inverse_blend(), convert_samples(), mlp_encode_frame(), and write_picture().

◆ input_to_sample_buffer()

static void input_to_sample_buffer ( MLPEncodeContext ctx)
static

Definition at line 1222 of file mlpenc.c.

Referenced by mlp_encode_frame().

◆ number_trailing_zeroes()

static int number_trailing_zeroes ( int32_t  sample)
static

Counts the number of trailing zeroes in a value.

Definition at line 1244 of file mlpenc.c.

Referenced by determine_quant_step_size().

◆ 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 1259 of file mlpenc.c.

Referenced by analyze_sample_buffer().

◆ code_filter_coeffs()

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 1284 of file mlpenc.c.

Referenced by set_filter_params().

◆ 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 1313 of file mlpenc.c.

Referenced by apply_filters(), and determine_filters().

◆ 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 1360 of file mlpenc.c.

Referenced by analyze_sample_buffer().

◆ estimate_stereo_mode()

static enum MLPChMode estimate_stereo_mode ( MLPEncodeContext ctx)
static

Definition at line 1377 of file mlpenc.c.

Referenced by lossless_matrix_coeffs().

◆ code_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 1410 of file mlpenc.c.

Referenced by lossless_matrix_coeffs().

◆ lossless_matrix_coeffs()

static void lossless_matrix_coeffs ( MLPEncodeContext ctx)
static

Determines best coefficients to use for the lossless matrix.

Definition at line 1428 of file mlpenc.c.

Referenced by analyze_sample_buffer().

◆ no_codebook_bits_offset()

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 1486 of file mlpenc.c.

Referenced by determine_bits().

◆ no_codebook_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 1515 of file mlpenc.c.

Referenced by determine_bits().

◆ codebook_bits_offset()

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 1555 of file mlpenc.c.

Referenced by codebook_bits(), and determine_bits().

◆ codebook_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 1618 of file mlpenc.c.

Referenced by determine_bits().

◆ 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 1658 of file mlpenc.c.

Referenced by analyze_sample_buffer().

◆ apply_filter()

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 (24), the samples buffer is left as is and the function returns -1.

Definition at line 1728 of file mlpenc.c.

Referenced by apply_filters().

◆ apply_filters()

static void apply_filters ( MLPEncodeContext ctx)
static

Definition at line 1781 of file mlpenc.c.

Referenced by analyze_sample_buffer(), and process_major_frame().

◆ generate_2_noise_channels()

static void generate_2_noise_channels ( MLPEncodeContext ctx)
static

Generates two noise channels worth of data.

Definition at line 1797 of file mlpenc.c.

Referenced by analyze_sample_buffer(), and process_major_frame().

◆ rematrix_channels()

static void rematrix_channels ( MLPEncodeContext ctx)
static

Rematrixes all channels using chosen coefficients.

Definition at line 1817 of file mlpenc.c.

Referenced by analyze_sample_buffer(), and process_major_frame().

◆ clear_path_counter()

static void clear_path_counter ( PathCounter path_counter)
static

Definition at line 1856 of file mlpenc.c.

Referenced by set_best_codebook().

◆ compare_best_offset()

static int compare_best_offset ( const BestOffset prev,
const BestOffset cur 
)
static

Definition at line 1861 of file mlpenc.c.

Referenced by best_codebook_path_cost(), and set_best_codebook().

◆ best_codebook_path_cost()

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

Definition at line 1866 of file mlpenc.c.

Referenced by set_best_codebook().

◆ set_best_codebook()

static void set_best_codebook ( MLPEncodeContext ctx)
static

Definition at line 1885 of file mlpenc.c.

Referenced by analyze_sample_buffer().

◆ set_major_params()

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 1966 of file mlpenc.c.

Referenced by mlp_encode_frame().

◆ analyze_sample_buffer()

static void analyze_sample_buffer ( MLPEncodeContext ctx)
static

Definition at line 2013 of file mlpenc.c.

Referenced by mlp_encode_frame().

◆ process_major_frame()

static void process_major_frame ( MLPEncodeContext ctx)
static

Definition at line 2056 of file mlpenc.c.

Referenced by mlp_encode_frame().

◆ mlp_encode_frame()

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

Definition at line 2076 of file mlpenc.c.

◆ mlp_encode_close()

static av_cold int mlp_encode_close ( AVCodecContext avctx)
static

Definition at line 2194 of file mlpenc.c.

Variable Documentation

◆ restart_channel_params

ChannelParams restart_channel_params[MAX_CHANNELS]
static

Definition at line 210 of file mlpenc.c.

Referenced by mlp_encode_init_static(), and set_major_params().

◆ restart_decoding_params

DecodingParams restart_decoding_params[MAX_SUBSTREAMS]
static

Definition at line 211 of file mlpenc.c.

Referenced by mlp_encode_init_static(), and set_major_params().

◆ restart_best_offset

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

Definition at line 212 of file mlpenc.c.

Referenced by best_codebook_path_cost(), and set_best_codebook().

◆ codebook_extremes

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 1479 of file mlpenc.c.

Referenced by codebook_bits_offset().