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/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 |
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 |
#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
#define NUM_CODEBOOKS 4 |
#define SAMPLE_MIN | ( | bitdepth | ) | (~SAMPLE_MAX(bitdepth)) |
#define FLAGS AV_OPT_FLAG_ENCODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM |
#define OFFSET | ( | x | ) | offsetof(MLPEncodeContext, x) |
enum InputBitDepth |
|
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 |
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().
|
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 344 of file mlpenc.c.
Referenced by copy_restart_frame_params().
|
static |
Definition at line 362 of file mlpenc.c.
Referenced by copy_restart_frame_params().
|
static |
Definition at line 380 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 405 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 420 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 435 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 458 of file mlpenc.c.
Referenced by code_filter_coeffs(), input_data_internal(), no_codebook_bits(), and no_codebook_bits_offset().
Definition at line 469 of file mlpenc.c.
Referenced by mlp_encode_init().
|
static |
Definition at line 474 of file mlpenc.c.
Referenced by mlp_encode_init().
|
static |
|
static |
Writes a major sync header to the bitstream.
Definition at line 673 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 755 of file mlpenc.c.
Referenced by write_substr().
|
static |
Writes matrix params for all primitive matrices to the bitstream.
Definition at line 792 of file mlpenc.c.
Referenced by write_decoding_params().
|
static |
Writes filter parameters for one filter to the bitstream.
Definition at line 828 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 856 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 956 of file mlpenc.c.
Referenced by write_substr().
|
static |
Writes the substream data to the bitstream.
Definition at line 1011 of file mlpenc.c.
Referenced by write_access_unit().
|
static |
Writes the access unit and substream headers to the bitstream.
Definition at line 1096 of file mlpenc.c.
Referenced by write_access_unit().
|
static |
Writes an entire access unit to the bitstream.
Definition at line 1137 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 1185 of file mlpenc.c.
Referenced by input_data().
|
static |
Wrapper function for inputting data in two different bit-depths.
Definition at line 1224 of file mlpenc.c.
Referenced by apng_do_inverse_blend(), convert_samples(), mlp_encode_frame(), and write_picture().
|
static |
Definition at line 1229 of file mlpenc.c.
Referenced by analyze_sample_buffer().
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().
|
static |
Definition at line 1266 of file mlpenc.c.
Referenced by analyze_sample_buffer().
|
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().
|
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().
|
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().
|
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().
|
static |
Definition at line 1410 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 1491 of file mlpenc.c.
Referenced by lossless_matrix_coeffs().
|
static |
Determines best coefficients to use for the lossless matrix.
Definition at line 1506 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 1535 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 1564 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 1601 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 1663 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 1704 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 1775 of file mlpenc.c.
Referenced by apply_filters().
|
static |
Definition at line 1843 of file mlpenc.c.
Referenced by analyze_sample_buffer(), and process_major_frame().
|
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().
|
static |
Rematrixes all channels using chosen coefficients.
Definition at line 1879 of file mlpenc.c.
Referenced by analyze_sample_buffer(), and process_major_frame().
|
static |
Definition at line 1950 of file mlpenc.c.
Referenced by set_best_codebook().
|
static |
Definition at line 1955 of file mlpenc.c.
Referenced by best_codebook_path_cost(), and set_best_codebook().
|
static |
Definition at line 1960 of file mlpenc.c.
Referenced by set_best_codebook().
|
static |
Definition at line 1980 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 2061 of file mlpenc.c.
Referenced by mlp_encode_frame().
|
static |
Definition at line 2103 of file mlpenc.c.
Referenced by mlp_encode_frame().
|
static |
Definition at line 2137 of file mlpenc.c.
Referenced by mlp_encode_frame().
|
static |
|
static |
|
static |
Definition at line 206 of file mlpenc.c.
Referenced by compare_decoding_params(), and mlp_encode_init_static().
|
static |
Definition at line 207 of file mlpenc.c.
Referenced by compare_decoding_params(), and mlp_encode_init_static().
|
static |
Definition at line 208 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 1528 of file mlpenc.c.
Referenced by codebook_bits_offset().
|
static |
|
static |