FFmpeg
|
#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/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 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, void *samples, int nb_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... | |
#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
#define NUM_CODEBOOKS 4 |
#define SAMPLE_MAX | ( | bitdepth | ) | ((1 << (bitdepth - 1)) - 1) |
#define SAMPLE_MIN | ( | bitdepth | ) | (~SAMPLE_MAX(bitdepth)) |
enum ParamFlags |
enum InputBitDepth |
enum MLPChMode |
|
static |
Compares two FilterParams structures and returns 1 if anything has changed.
Returns 0 if they are both equal.
Definition at line 236 of file mlpenc.c.
Referenced by compare_decoding_params().
|
static |
Compare two primitive matrices and returns 1 if anything has changed.
Returns 0 if they are both equal.
Definition at line 260 of file mlpenc.c.
Referenced by compare_decoding_params().
|
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().
|
static |
Definition at line 342 of file mlpenc.c.
Referenced by copy_restart_frame_params().
|
static |
Definition at line 360 of file mlpenc.c.
Referenced by copy_restart_frame_params().
|
static |
Definition at line 379 of file mlpenc.c.
Referenced by analyze_sample_buffer().
|
static |
Clears a DecodingParams struct the way it should be after a restart header.
Definition at line 400 of file mlpenc.c.
Referenced by default_decoding_params(), and mlp_encode_init_static().
|
static |
Clears a ChannelParams struct the way it should be after a restart header.
Definition at line 412 of file mlpenc.c.
Referenced by mlp_encode_frame(), and mlp_encode_init_static().
|
static |
Sets default vales in our encoder for a DecodingParams struct.
Definition at line 427 of file mlpenc.c.
Referenced by mlp_encode_frame().
Calculates the smallest number of bits it takes to encode a given signed value in two's complement.
Definition at line 451 of file mlpenc.c.
Referenced by code_filter_coeffs(), input_data_internal(), no_codebook_bits(), and no_codebook_bits_offset().
Definition at line 465 of file mlpenc.c.
Referenced by mlp_encode_init().
|
static |
Definition at line 470 of file mlpenc.c.
Referenced by mlp_encode_init().
|
static |
|
static |
Writes a major sync header to the bitstream.
Definition at line 700 of file mlpenc.c.
Referenced by write_access_unit().
|
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 759 of file mlpenc.c.
Referenced by write_substr().
|
static |
Writes matrix params for all primitive matrices to the bitstream.
Definition at line 795 of file mlpenc.c.
Referenced by write_decoding_params().
|
static |
Writes filter parameters for one filter to the bitstream.
Definition at line 824 of file mlpenc.c.
Referenced by write_decoding_params().
|
static |
Writes decoding parameters to the bitstream.
These change very often, usually at almost every frame.
Definition at line 850 of file mlpenc.c.
Referenced by write_substr().
|
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 950 of file mlpenc.c.
Referenced by write_substr().
|
static |
Writes the substream data to the bitstream.
Definition at line 997 of file mlpenc.c.
Referenced by write_access_unit().
|
static |
Writes the access unit and substream headers to the bitstream.
Definition at line 1087 of file mlpenc.c.
Referenced by write_access_unit().
|
static |
Writes an entire access unit to the bitstream.
Definition at line 1125 of file mlpenc.c.
Referenced by mlp_encode_frame().
|
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 1167 of file mlpenc.c.
Referenced by input_data().
|
static |
Wrapper function for inputting data in two different bit-depths.
Definition at line 1205 of file mlpenc.c.
Referenced by apng_do_inverse_blend(), convert_samples(), mlp_encode_frame(), and write_picture().
|
static |
Definition at line 1210 of file mlpenc.c.
Referenced by mlp_encode_frame().
Counts the number of trailing zeroes in a value.
Definition at line 1232 of file mlpenc.c.
Referenced by determine_quant_step_size().
|
static |
Determines how many bits are zero at the end of all samples so they can be shifted out.
Definition at line 1247 of file mlpenc.c.
Referenced by analyze_sample_buffer().
|
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 1272 of file mlpenc.c.
Referenced by set_filter_params().
|
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 1301 of file mlpenc.c.
Referenced by apply_filters(), and determine_filters().
|
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 1348 of file mlpenc.c.
Referenced by analyze_sample_buffer().
|
static |
Definition at line 1365 of file mlpenc.c.
Referenced by lossless_matrix_coeffs().
|
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 1398 of file mlpenc.c.
Referenced by lossless_matrix_coeffs().
|
static |
Determines best coefficients to use for the lossless matrix.
Definition at line 1416 of file mlpenc.c.
Referenced by analyze_sample_buffer().
|
static |
Determines the amount of bits needed to encode the samples using no codebooks and a specified offset.
Definition at line 1474 of file mlpenc.c.
Referenced by determine_bits().
|
static |
Determines the least amount of bits needed to encode the samples using no codebooks.
Definition at line 1503 of file mlpenc.c.
Referenced by determine_bits().
|
inlinestatic |
Determines the least amount of bits needed to encode the samples using a given codebook and a given offset.
Definition at line 1543 of file mlpenc.c.
Referenced by codebook_bits(), and determine_bits().
|
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 1606 of file mlpenc.c.
Referenced by determine_bits().
|
static |
Determines the least amount of bits needed to encode the samples using any or no codebook.
Definition at line 1646 of file mlpenc.c.
Referenced by analyze_sample_buffer().
|
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 1716 of file mlpenc.c.
Referenced by apply_filters().
|
static |
Definition at line 1769 of file mlpenc.c.
Referenced by analyze_sample_buffer(), and process_major_frame().
|
static |
Generates two noise channels worth of data.
Definition at line 1785 of file mlpenc.c.
Referenced by analyze_sample_buffer(), and process_major_frame().
|
static |
Rematrixes all channels using chosen coefficients.
Definition at line 1805 of file mlpenc.c.
Referenced by analyze_sample_buffer(), and process_major_frame().
|
static |
Definition at line 1844 of file mlpenc.c.
Referenced by set_best_codebook().
|
static |
Definition at line 1849 of file mlpenc.c.
Referenced by best_codebook_path_cost(), and set_best_codebook().
|
static |
Definition at line 1854 of file mlpenc.c.
Referenced by set_best_codebook().
|
static |
Definition at line 1873 of file mlpenc.c.
Referenced by analyze_sample_buffer().
|
static |
Analyzes all collected bitcounts and selects the best parameters for each individual access unit.
TODO This is just a stub!
Definition at line 1954 of file mlpenc.c.
Referenced by mlp_encode_frame().
|
static |
Definition at line 2002 of file mlpenc.c.
Referenced by mlp_encode_frame().
|
static |
Definition at line 2045 of file mlpenc.c.
Referenced by mlp_encode_frame().
|
static |
|
static |
|
static |
Definition at line 212 of file mlpenc.c.
Referenced by mlp_encode_init_static(), and set_major_params().
|
static |
Definition at line 213 of file mlpenc.c.
Referenced by mlp_encode_init_static(), and set_major_params().
|
static |
Definition at line 214 of file mlpenc.c.
Referenced by best_codebook_path_cost(), and set_best_codebook().
|
static |
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 1467 of file mlpenc.c.
Referenced by codebook_bits_offset().