FFmpeg
Data Structures | Macros | Enumerations | Functions | Variables
mlpenc.c File Reference
#include "config_components.h"
#include "avcodec.h"
#include "codec_internal.h"
#include "encode.h"
#include "put_bits.h"
#include "audio_frame_queue.h"
#include "libavutil/avassert.h"
#include "libavutil/channel_layout.h"
#include "libavutil/crc.h"
#include "libavutil/avstring.h"
#include "libavutil/intmath.h"
#include "libavutil/opt.h"
#include "libavutil/samplefmt.h"
#include "libavutil/thread.h"
#include "mlp_parse.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  MLPBlock
 
struct  MLPSubstream
 
struct  MLPEncodeContext
 
struct  PathCounter
 

Macros

#define MAX_NCHANNELS   (MAX_CHANNELS + 2)
 MLP encoder Copyright (c) 2008 Ramiro Polla Copyright (c) 2016-2019 Jai Luthra. More...
 
#define MIN_HEADER_INTERVAL   8
 
#define MAX_HEADER_INTERVAL   128
 
#define MLP_MIN_LPC_ORDER   1
 
#define MLP_MAX_LPC_ORDER   8
 
#define MLP_MIN_LPC_SHIFT   0
 
#define MLP_MAX_LPC_SHIFT   15
 
#define PARAMS_DEFAULT   (0xff)
 
#define PARAM_PRESENCE_FLAGS   (1 << 8)
 
#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
 
#define FLAGS   AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM
 
#define OFFSET(x)   offsetof(MLPEncodeContext, x)
 

Enumerations

enum  InputBitDepth { BITS_16, BITS_20, BITS_24 }
 

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, MLPSubstream *s, 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, MLPSubstream *s, unsigned int index)
 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, MLPSubstream *s)
 
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, 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 *dp)
 Sets default vales in our encoder for a DecodingParams struct. More...
 
static int number_sbits (int32_t n)
 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, MLPSubstream *s, PutBitContext *pb)
 Writes a restart header to the bitstream. More...
 
static void write_matrix_params (MLPEncodeContext *ctx, MLPSubstream *s, DecodingParams *dp, PutBitContext *pb)
 Writes matrix params for all primitive matrices to the bitstream. More...
 
static void write_filter_params (MLPEncodeContext *ctx, ChannelParams *cp, PutBitContext *pb, int channel, unsigned int filter)
 Writes filter parameters for one filter to the bitstream. More...
 
static void write_decoding_params (MLPEncodeContext *ctx, MLPSubstream *s, PutBitContext *pb, int params_changed, unsigned int subblock_index)
 Writes decoding parameters to the bitstream. More...
 
static void write_block_data (MLPEncodeContext *ctx, MLPSubstream *s, PutBitContext *pb, unsigned int subblock_index)
 Writes the residuals to the bitstream. More...
 
static uint8_t * write_substr (MLPEncodeContext *ctx, MLPSubstream *s, uint8_t *buf, int buf_size, int restart_frame, uint16_t *substream_data_len)
 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[MAX_SUBSTREAMS])
 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, MLPSubstream *s, uint8_t **const samples, int nb_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, MLPSubstream *s, uint8_t **const samples, int nb_samples)
 Wrapper function for inputting data in two different bit-depths. More...
 
static void input_to_sample_buffer (MLPEncodeContext *ctx, MLPSubstream *s)
 
static int number_trailing_zeroes (int32_t sample, unsigned int max, unsigned int def)
 Counts the number of trailing zeroes in a value. More...
 
static void determine_output_shift (MLPEncodeContext *ctx, MLPSubstream *s)
 
static void determine_quant_step_size (MLPEncodeContext *ctx, MLPSubstream *s)
 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, const 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 (MLPEncodeContext *ctx, MLPSubstream *s, int channel, int retry_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, MLPSubstream *s)
 Tries to determine a good prediction filter, and applies it to the samples buffer if the filter is good enough. More...
 
static int estimate_coeff (MLPEncodeContext *ctx, MLPSubstream *s, MatrixParams *mp, int ch0, int ch1)
 
static void code_matrix_coeffs (MLPEncodeContext *ctx, MLPSubstream *s, DecodingParams *dp, unsigned int mat)
 Determines how many fractional bits are needed to encode matrix coefficients. More...
 
static void lossless_matrix_coeffs (MLPEncodeContext *ctx, MLPSubstream *s)
 Determines best coefficients to use for the lossless matrix. More...
 
static void no_codebook_bits_offset (MLPEncodeContext *ctx, DecodingParams *dp, int channel, int32_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, DecodingParams *dp, 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, DecodingParams *dp, int channel, int codebook, int32_t sample_min, int32_t sample_max, int32_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, DecodingParams *dp, 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, MLPSubstream *s)
 Determines the least amount of bits needed to encode the samples using any or no codebook. More...
 
static int apply_filter (MLPEncodeContext *ctx, MLPSubstream *s, 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, MLPSubstream *s)
 
static void generate_2_noise_channels (MLPEncodeContext *ctx, MLPSubstream *s)
 Generates two noise channels worth of data. More...
 
static void rematrix_channels (MLPEncodeContext *ctx, MLPSubstream *s)
 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 uint32_t best_codebook_path_cost (MLPEncodeContext *ctx, MLPSubstream *s, int channel, PathCounter *src, int cur_codebook)
 
static void set_best_codebook (MLPEncodeContext *ctx, MLPSubstream *s)
 
static void set_major_params (MLPEncodeContext *ctx, MLPSubstream *s)
 Analyzes all collected bitcounts and selects the best parameters for each individual access unit. More...
 
static void analyze_sample_buffer (MLPEncodeContext *ctx, MLPSubstream *s)
 
static void process_major_frame (MLPEncodeContext *ctx, MLPSubstream *s)
 
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 int8_t codebook_extremes [3][2]
 Min and max values that can be encoded with each codebook. More...
 
static const AVOption mlp_options []
 
static const AVClass mlp_class
 

Macro Definition Documentation

◆ MAX_NCHANNELS

#define MAX_NCHANNELS   (MAX_CHANNELS + 2)

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

◆ MIN_HEADER_INTERVAL

#define MIN_HEADER_INTERVAL   8

Definition at line 44 of file mlpenc.c.

◆ MAX_HEADER_INTERVAL

#define MAX_HEADER_INTERVAL   128

Definition at line 45 of file mlpenc.c.

◆ MLP_MIN_LPC_ORDER

#define MLP_MIN_LPC_ORDER   1

Definition at line 47 of file mlpenc.c.

◆ MLP_MAX_LPC_ORDER

#define MLP_MAX_LPC_ORDER   8

Definition at line 48 of file mlpenc.c.

◆ MLP_MIN_LPC_SHIFT

#define MLP_MIN_LPC_SHIFT   0

Definition at line 49 of file mlpenc.c.

◆ MLP_MAX_LPC_SHIFT

#define MLP_MAX_LPC_SHIFT   15

Definition at line 50 of file mlpenc.c.

◆ PARAMS_DEFAULT

#define PARAMS_DEFAULT   (0xff)

Definition at line 82 of file mlpenc.c.

◆ PARAM_PRESENCE_FLAGS

#define PARAM_PRESENCE_FLAGS   (1 << 8)

Definition at line 83 of file mlpenc.c.

◆ HUFF_OFFSET_MIN

#define HUFF_OFFSET_MIN   (-16384)

Definition at line 105 of file mlpenc.c.

◆ HUFF_OFFSET_MAX

#define HUFF_OFFSET_MAX   ( 16383)

Definition at line 106 of file mlpenc.c.

◆ NUM_CODEBOOKS

#define NUM_CODEBOOKS   4

Number of possible codebooks (counting "no codebooks")

Definition at line 109 of file mlpenc.c.

◆ SYNC_MAJOR

#define SYNC_MAJOR   0xf8726f

Definition at line 210 of file mlpenc.c.

◆ MAJOR_SYNC_INFO_SIGNATURE

#define MAJOR_SYNC_INFO_SIGNATURE   0xB752

Definition at line 211 of file mlpenc.c.

◆ FLAGS_DVDA

#define FLAGS_DVDA   0x4000

Definition at line 214 of file mlpenc.c.

◆ FLAGS_CONST

#define FLAGS_CONST   0x8000

Definition at line 216 of file mlpenc.c.

◆ SUBSTREAM_INFO_MAX_2_CHAN

#define SUBSTREAM_INFO_MAX_2_CHAN   0x01

Definition at line 218 of file mlpenc.c.

◆ SUBSTREAM_INFO_HIGH_RATE

#define SUBSTREAM_INFO_HIGH_RATE   0x02

Definition at line 219 of file mlpenc.c.

◆ SUBSTREAM_INFO_ALWAYS_SET

#define SUBSTREAM_INFO_ALWAYS_SET   0x04

Definition at line 220 of file mlpenc.c.

◆ SUBSTREAM_INFO_2_SUBSTREAMS

#define SUBSTREAM_INFO_2_SUBSTREAMS   0x08

Definition at line 221 of file mlpenc.c.

◆ SAMPLE_MAX

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

Definition at line 1765 of file mlpenc.c.

◆ SAMPLE_MIN

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

Definition at line 1766 of file mlpenc.c.

◆ MSB_MASK

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

Definition at line 1768 of file mlpenc.c.

◆ CODEBOOK_CHANGE_BITS

#define CODEBOOK_CHANGE_BITS   21

Definition at line 1948 of file mlpenc.c.

◆ FLAGS

Definition at line 2274 of file mlpenc.c.

◆ OFFSET

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

Definition at line 2275 of file mlpenc.c.

Enumeration Type Documentation

◆ InputBitDepth

Enumerator
BITS_16 
BITS_20 
BITS_24 

Definition at line 463 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 230 of file mlpenc.c.

Referenced by compare_decoding_params().

◆ compare_matrix_params()

static int compare_matrix_params ( MLPEncodeContext ctx,
MLPSubstream s,
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 254 of file mlpenc.c.

Referenced by compare_decoding_params().

◆ compare_decoding_params()

static int compare_decoding_params ( MLPEncodeContext ctx,
MLPSubstream s,
unsigned int  index 
)
static

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

Definition at line 289 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 344 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 362 of file mlpenc.c.

Referenced by copy_restart_frame_params().

◆ copy_restart_frame_params()

static void copy_restart_frame_params ( MLPEncodeContext ctx,
MLPSubstream s 
)
static

Definition at line 380 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 405 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,
int  nb_channels 
)
static

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

Definition at line 420 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 dp 
)
static

Sets default vales in our encoder for a DecodingParams struct.

Definition at line 435 of file mlpenc.c.

Referenced by mlp_encode_frame().

◆ number_sbits()

static int number_sbits ( int32_t  n)
inlinestatic

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

Definition at line 458 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 469 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 474 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 481 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 673 of file mlpenc.c.

Referenced by write_access_unit().

◆ write_restart_header()

static void write_restart_header ( MLPEncodeContext ctx,
MLPSubstream s,
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 755 of file mlpenc.c.

Referenced by write_substr().

◆ write_matrix_params()

static void write_matrix_params ( MLPEncodeContext ctx,
MLPSubstream s,
DecodingParams dp,
PutBitContext pb 
)
static

Writes matrix params for all primitive matrices to the bitstream.

Definition at line 792 of file mlpenc.c.

Referenced by write_decoding_params().

◆ write_filter_params()

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

Writes filter parameters for one filter to the bitstream.

Definition at line 828 of file mlpenc.c.

Referenced by write_decoding_params().

◆ write_decoding_params()

static void write_decoding_params ( MLPEncodeContext ctx,
MLPSubstream s,
PutBitContext pb,
int  params_changed,
unsigned int  subblock_index 
)
static

Writes decoding parameters to the bitstream.

These change very often, usually at almost every frame.

Definition at line 856 of file mlpenc.c.

Referenced by write_substr().

◆ write_block_data()

static void write_block_data ( MLPEncodeContext ctx,
MLPSubstream s,
PutBitContext pb,
unsigned int  subblock_index 
)
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 956 of file mlpenc.c.

Referenced by write_substr().

◆ write_substr()

static uint8_t* write_substr ( MLPEncodeContext ctx,
MLPSubstream s,
uint8_t *  buf,
int  buf_size,
int  restart_frame,
uint16_t *  substream_data_len 
)
static

Writes the substream data to the bitstream.

Definition at line 1011 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[MAX_SUBSTREAMS] 
)
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 1137 of file mlpenc.c.

Referenced by mlp_encode_frame().

◆ input_data_internal()

static void input_data_internal ( MLPEncodeContext ctx,
MLPSubstream s,
uint8_t **const  samples,
int  nb_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 1185 of file mlpenc.c.

Referenced by input_data().

◆ input_data()

static void input_data ( MLPEncodeContext ctx,
MLPSubstream s,
uint8_t **const  samples,
int  nb_samples 
)
static

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

Examples
transcode_aac.c.

Definition at line 1224 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,
MLPSubstream s 
)
static

Definition at line 1229 of file mlpenc.c.

Referenced by analyze_sample_buffer().

◆ number_trailing_zeroes()

static int number_trailing_zeroes ( int32_t  sample,
unsigned int  max,
unsigned int  def 
)
static

Counts the number of trailing zeroes in a value.

Definition at line 1261 of file mlpenc.c.

Referenced by code_matrix_coeffs(), determine_output_shift(), and determine_quant_step_size().

◆ determine_output_shift()

static void determine_output_shift ( MLPEncodeContext ctx,
MLPSubstream s 
)
static

Definition at line 1266 of file mlpenc.c.

Referenced by analyze_sample_buffer().

◆ determine_quant_step_size()

static void determine_quant_step_size ( MLPEncodeContext ctx,
MLPSubstream s 
)
static

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

Definition at line 1304 of file mlpenc.c.

Referenced by analyze_sample_buffer().

◆ code_filter_coeffs()

static void code_filter_coeffs ( MLPEncodeContext ctx,
FilterParams fp,
const 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 1331 of file mlpenc.c.

Referenced by set_filter().

◆ set_filter()

static void set_filter ( MLPEncodeContext ctx,
MLPSubstream s,
int  channel,
int  retry_filter 
)
static

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

Definition at line 1353 of file mlpenc.c.

Referenced by apply_filters(), and determine_filters().

◆ determine_filters()

static void determine_filters ( MLPEncodeContext ctx,
MLPSubstream s 
)
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 1402 of file mlpenc.c.

Referenced by analyze_sample_buffer().

◆ estimate_coeff()

static int estimate_coeff ( MLPEncodeContext ctx,
MLPSubstream s,
MatrixParams mp,
int  ch0,
int  ch1 
)
static

Definition at line 1410 of file mlpenc.c.

Referenced by lossless_matrix_coeffs().

◆ code_matrix_coeffs()

static void code_matrix_coeffs ( MLPEncodeContext ctx,
MLPSubstream s,
DecodingParams dp,
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 1491 of file mlpenc.c.

Referenced by lossless_matrix_coeffs().

◆ lossless_matrix_coeffs()

static void lossless_matrix_coeffs ( MLPEncodeContext ctx,
MLPSubstream s 
)
static

Determines best coefficients to use for the lossless matrix.

Definition at line 1506 of file mlpenc.c.

Referenced by analyze_sample_buffer().

◆ no_codebook_bits_offset()

static void no_codebook_bits_offset ( MLPEncodeContext ctx,
DecodingParams dp,
int  channel,
int32_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 1535 of file mlpenc.c.

Referenced by determine_bits().

◆ no_codebook_bits()

static void no_codebook_bits ( MLPEncodeContext ctx,
DecodingParams dp,
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 1564 of file mlpenc.c.

Referenced by determine_bits().

◆ codebook_bits_offset()

static void codebook_bits_offset ( MLPEncodeContext ctx,
DecodingParams dp,
int  channel,
int  codebook,
int32_t  sample_min,
int32_t  sample_max,
int32_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 1601 of file mlpenc.c.

Referenced by codebook_bits(), and determine_bits().

◆ codebook_bits()

static void codebook_bits ( MLPEncodeContext ctx,
DecodingParams dp,
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 1663 of file mlpenc.c.

Referenced by determine_bits().

◆ determine_bits()

static void determine_bits ( MLPEncodeContext ctx,
MLPSubstream s 
)
static

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

Definition at line 1704 of file mlpenc.c.

Referenced by analyze_sample_buffer().

◆ apply_filter()

static int apply_filter ( MLPEncodeContext ctx,
MLPSubstream s,
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 1775 of file mlpenc.c.

Referenced by apply_filters().

◆ apply_filters()

static void apply_filters ( MLPEncodeContext ctx,
MLPSubstream s 
)
static

Definition at line 1843 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,
MLPSubstream s 
)
static

Generates two noise channels worth of data.

Definition at line 1856 of file mlpenc.c.

Referenced by analyze_sample_buffer(), and process_major_frame().

◆ rematrix_channels()

static void rematrix_channels ( MLPEncodeContext ctx,
MLPSubstream s 
)
static

Rematrixes all channels using chosen coefficients.

Definition at line 1879 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 1950 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 1955 of file mlpenc.c.

Referenced by best_codebook_path_cost(), and set_best_codebook().

◆ best_codebook_path_cost()

static uint32_t best_codebook_path_cost ( MLPEncodeContext ctx,
MLPSubstream s,
int  channel,
PathCounter src,
int  cur_codebook 
)
static

Definition at line 1960 of file mlpenc.c.

Referenced by set_best_codebook().

◆ set_best_codebook()

static void set_best_codebook ( MLPEncodeContext ctx,
MLPSubstream s 
)
static

Definition at line 1980 of file mlpenc.c.

Referenced by analyze_sample_buffer().

◆ set_major_params()

static void set_major_params ( MLPEncodeContext ctx,
MLPSubstream s 
)
static

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

TODO This is just a stub!

Definition at line 2061 of file mlpenc.c.

Referenced by mlp_encode_frame().

◆ analyze_sample_buffer()

static void analyze_sample_buffer ( MLPEncodeContext ctx,
MLPSubstream s 
)
static

Definition at line 2103 of file mlpenc.c.

Referenced by mlp_encode_frame().

◆ process_major_frame()

static void process_major_frame ( MLPEncodeContext ctx,
MLPSubstream s 
)
static

Definition at line 2137 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 2151 of file mlpenc.c.

◆ mlp_encode_close()

static av_cold int mlp_encode_close ( AVCodecContext avctx)
static

Definition at line 2264 of file mlpenc.c.

Variable Documentation

◆ restart_channel_params

ChannelParams restart_channel_params[MAX_CHANNELS]
static

Definition at line 206 of file mlpenc.c.

Referenced by compare_decoding_params(), and mlp_encode_init_static().

◆ restart_decoding_params

DecodingParams restart_decoding_params[MAX_SUBSTREAMS]
static

Definition at line 207 of file mlpenc.c.

Referenced by compare_decoding_params(), and mlp_encode_init_static().

◆ restart_best_offset

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

Definition at line 208 of file mlpenc.c.

Referenced by best_codebook_path_cost(), and set_best_codebook().

◆ codebook_extremes

const int8_t 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 1528 of file mlpenc.c.

Referenced by codebook_bits_offset().

◆ mlp_options

const AVOption mlp_options[]
static
Initial value:
= {
{ "max_interval", "Max number of frames between each new header", OFFSET(max_restart_interval), AV_OPT_TYPE_INT, {.i64 = 16 }, MIN_HEADER_INTERVAL, MAX_HEADER_INTERVAL, FLAGS },
{ "lpc_coeff_precision", "LPC coefficient precision", OFFSET(lpc_coeff_precision), AV_OPT_TYPE_INT, {.i64 = 15 }, 0, 15, FLAGS },
{ "lpc_type", "LPC algorithm", OFFSET(lpc_type), AV_OPT_TYPE_INT, {.i64 = FF_LPC_TYPE_LEVINSON }, FF_LPC_TYPE_LEVINSON, FF_LPC_TYPE_CHOLESKY, FLAGS, .unit = "lpc_type" },
{ "levinson", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_LPC_TYPE_LEVINSON }, 0, 0, FLAGS, .unit = "lpc_type" },
{ "cholesky", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_LPC_TYPE_CHOLESKY }, 0, 0, FLAGS, .unit = "lpc_type" },
{ "lpc_passes", "Number of passes to use for Cholesky factorization during LPC analysis", OFFSET(lpc_passes), AV_OPT_TYPE_INT, {.i64 = 2 }, 1, INT_MAX, FLAGS },
{ "codebook_search", "Max number of codebook searches", OFFSET(max_codebook_search), AV_OPT_TYPE_INT, {.i64 = 3 }, 1, 100, FLAGS },
{ "prediction_order", "Search method for selecting prediction order", OFFSET(prediction_order), AV_OPT_TYPE_INT, {.i64 = ORDER_METHOD_EST }, ORDER_METHOD_EST, ORDER_METHOD_SEARCH, FLAGS, .unit = "predm" },
{ "estimation", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = ORDER_METHOD_EST }, 0, 0, FLAGS, .unit = "predm" },
{ "search", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = ORDER_METHOD_SEARCH }, 0, 0, FLAGS, .unit = "predm" },
{ "rematrix_precision", "Rematrix coefficient precision", OFFSET(rematrix_precision), AV_OPT_TYPE_INT, {.i64 = 1 }, 0, 14, FLAGS },
{ NULL },
}

Definition at line 2276 of file mlpenc.c.

◆ mlp_class

const AVClass mlp_class
static
Initial value:
= {
.class_name = "mlpenc",
.item_name = av_default_item_name,
.option = mlp_options,
}

Definition at line 2291 of file mlpenc.c.

OFFSET
#define OFFSET(x)
Definition: mlpenc.c:2275
FF_LPC_TYPE_CHOLESKY
@ FF_LPC_TYPE_CHOLESKY
Cholesky factorization.
Definition: lpc.h:47
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
ORDER_METHOD_SEARCH
#define ORDER_METHOD_SEARCH
Definition: lpc.h:33
FLAGS
#define FLAGS
Definition: mlpenc.c:2274
ORDER_METHOD_EST
#define ORDER_METHOD_EST
Definition: lpc.h:29
AV_OPT_TYPE_INT
@ AV_OPT_TYPE_INT
Definition: opt.h:235
MIN_HEADER_INTERVAL
#define MIN_HEADER_INTERVAL
Definition: mlpenc.c:44
mlp_options
static const AVOption mlp_options[]
Definition: mlpenc.c:2276
AV_OPT_TYPE_CONST
@ AV_OPT_TYPE_CONST
Definition: opt.h:244
FF_LPC_TYPE_LEVINSON
@ FF_LPC_TYPE_LEVINSON
Levinson-Durbin recursion.
Definition: lpc.h:46
MAX_HEADER_INTERVAL
#define MAX_HEADER_INTERVAL
Definition: mlpenc.c:45