Go to the documentation of this file.
32 #define MAJOR_HEADER_INTERVAL 16
34 #define MLP_MIN_LPC_ORDER 1
35 #define MLP_MAX_LPC_ORDER 8
36 #define MLP_MIN_LPC_SHIFT 8
37 #define MLP_MAX_LPC_SHIFT 15
96 #define HUFF_OFFSET_MIN -16384
97 #define HUFF_OFFSET_MAX 16383
100 #define NUM_CODEBOOKS 4
110 int coded_sample_fmt [2];
111 int coded_sample_rate[2];
207 #define SYNC_MAJOR 0xf8726f
208 #define MAJOR_SYNC_INFO_SIGNATURE 0xB752
210 #define SYNC_MLP 0xbb
211 #define SYNC_TRUEHD 0xba
214 #define FLAGS_DVDA 0x4000
216 #define FLAGS_CONST 0x8000
218 #define SUBSTREAM_INFO_MAX_2_CHAN 0x01
219 #define SUBSTREAM_INFO_HIGH_RATE 0x02
220 #define SUBSTREAM_INFO_ALWAYS_SET 0x04
221 #define SUBSTREAM_INFO_2_SUBSTREAMS 0x08
245 for (
i = 0;
i <
fp->order;
i++)
270 for (mat = 0; mat < mp->
count; mat++) {
354 for (order = 0; order < dst->
order; order++)
409 for (substr = 0; substr <
ctx->num_substreams; substr++) {
445 for (substr = 0; substr <
ctx->num_substreams; substr++) {
447 uint8_t param_presence_flags = 0;
489 unsigned int substr,
index;
490 unsigned int sum = 0;
499 ctx->coded_sample_rate[0] = 0x08 + 0;
504 ctx->coded_sample_rate[0] = 0x08 + 1;
510 ctx->coded_sample_rate[0] = 0x08 + 2;
515 ctx->coded_sample_rate[0] = 0x00 + 0;
520 ctx->coded_sample_rate[0] = 0x00 + 1;
526 ctx->coded_sample_rate[0] = 0x00 + 2;
531 "sample rates are 44100, 88200, 176400, 48000, "
535 ctx->coded_sample_rate[1] = -1 & 0xf;
543 "Only mono and stereo are supported at the moment.\n");
554 ctx->wordlength = 16;
560 ctx->wordlength = 24;
565 "Only 16- and 24-bit samples are supported.\n");
568 ctx->coded_sample_fmt[1] = -1 & 0xf;
578 ctx->max_codebook_search = 3;
580 ctx->restart_intervals =
ctx->max_restart_interval /
ctx->min_restart_interval;
587 if (!
ctx->lpc_sample_buffer) {
589 "Not enough memory for buffering samples.\n");
593 size =
ctx->one_sample_buffer_size *
ctx->max_restart_interval;
596 if (!
ctx->major_scratch_buffer) {
598 "Not enough memory for buffering samples.\n");
603 if (!
ctx->major_inout_buffer) {
605 "Not enough memory for buffering samples.\n");
611 ctx->num_substreams = 1;
617 ctx->channel_arrangement = 0;
break;
619 ctx->channel_arrangement = 1;
break;
621 ctx->channel_arrangement = 2;
break;
623 ctx->channel_arrangement = 3;
break;
625 ctx->channel_arrangement = 4;
break;
627 ctx->channel_arrangement = 7;
break;
629 ctx->channel_arrangement = 8;
break;
631 ctx->channel_arrangement = 9;
break;
633 ctx->channel_arrangement = 10;
break;
635 ctx->channel_arrangement = 11;
break;
637 ctx->channel_arrangement = 12;
break;
649 ctx->ch_modifier_thd0 = 0;
650 ctx->ch_modifier_thd1 = 0;
651 ctx->ch_modifier_thd2 = 0;
652 ctx->channel_arrangement = 1;
655 ctx->ch_modifier_thd0 = 1;
656 ctx->ch_modifier_thd1 = 1;
657 ctx->ch_modifier_thd2 = 1;
658 ctx->channel_arrangement = 11;
661 ctx->ch_modifier_thd0 = 2;
662 ctx->ch_modifier_thd1 = 1;
663 ctx->ch_modifier_thd2 = 2;
664 ctx->channel_arrangement = 15;
671 ctx->channel_occupancy = 0;
672 ctx->summary_info = 0;
675 size =
sizeof(
unsigned int) *
ctx->max_restart_interval;
678 if (!
ctx->frame_size)
682 if (!
ctx->max_output_bits)
686 *
ctx->num_substreams *
ctx->max_restart_interval;
689 if (!
ctx->lossless_check_data)
697 ctx->sequence_size = sum;
699 *
ctx->restart_intervals *
ctx->sequence_size *
ctx->avctx->channels;
701 if (!
ctx->channel_params) {
703 "Not enough memory for analysis context.\n");
708 *
ctx->restart_intervals *
ctx->sequence_size *
ctx->num_substreams;
710 if (!
ctx->decoding_params) {
712 "Not enough memory for analysis context.\n");
716 for (substr = 0; substr <
ctx->num_substreams; substr++) {
734 "Not enough memory for LPC context.\n");
852 for (mat = 0; mat < mp->
count; mat++) {
891 for (
i = 0;
i <
fp->order;
i++) {
1019 sign_shift = lsb_bits[
ch] - 1;
1022 sign_huff_offset[
ch] -= 7 << lsb_bits[
ch];
1027 if (sign_shift >= 0)
1028 sign_huff_offset[
ch] -= 1 << sign_shift;
1037 if (codebook_index[
ch] >= 0) {
1048 ctx->write_buffer = sample_buffer;
1056 int32_t *lossless_check_data =
ctx->lossless_check_data;
1057 unsigned int substr;
1060 lossless_check_data +=
ctx->frame_index *
ctx->num_substreams;
1062 for (substr = 0; substr <
ctx->num_substreams; substr++) {
1063 unsigned int cur_subblock_index =
ctx->major_cur_subblock_index;
1064 unsigned int num_subblocks =
ctx->major_filter_state_subblock;
1065 unsigned int subblock;
1067 int substr_restart_frame = restart_frame;
1072 ctx->cur_restart_header = rh;
1076 for (subblock = 0; subblock <= num_subblocks; subblock++) {
1077 unsigned int subblock_index;
1079 subblock_index = cur_subblock_index++;
1081 ctx->cur_decoding_params = &
ctx->major_decoding_params[subblock_index][substr];
1082 ctx->cur_channel_params =
ctx->major_channel_params[subblock_index];
1084 params_changed =
ctx->major_params_changed[subblock_index][substr];
1086 if (substr_restart_frame || params_changed) {
1089 if (substr_restart_frame) {
1105 put_bits(&pb, 1, !substr_restart_frame);
1107 substr_restart_frame = 0;
1114 if (
ctx->last_frame ==
ctx->inout_buffer) {
1132 substream_data_len[substr] =
end;
1137 ctx->major_cur_subblock_index +=
ctx->major_filter_state_subblock + 1;
1138 ctx->major_filter_state_subblock = 0;
1149 uint16_t access_unit_header = 0;
1150 uint16_t parity_nibble = 0;
1151 unsigned int substr;
1153 parity_nibble =
ctx->dts;
1156 for (substr = 0; substr <
ctx->num_substreams; substr++) {
1157 uint16_t substr_hdr = 0;
1159 substr_hdr |= (0 << 15);
1160 substr_hdr |= (!restart_frame << 14);
1161 substr_hdr |= (1 << 13);
1162 substr_hdr |= (0 << 12);
1163 substr_hdr |= (substream_data_len[substr] / 2) & 0x0FFF;
1165 AV_WB16(substream_headers, substr_hdr);
1167 parity_nibble ^= *substream_headers++;
1168 parity_nibble ^= *substream_headers++;
1171 parity_nibble ^= parity_nibble >> 8;
1172 parity_nibble ^= parity_nibble >> 4;
1173 parity_nibble &= 0xF;
1175 access_unit_header |= (parity_nibble ^ 0xF) << 12;
1176 access_unit_header |=
length & 0xFFF;
1184 int buf_size,
int restart_frame)
1188 unsigned int substr;
1198 if (restart_frame) {
1209 for (substr = 0; substr <
ctx->num_substreams; substr++) {
1216 total_length =
buf - buf0;
1220 return total_length;
1234 int32_t *lossless_check_data =
ctx->lossless_check_data;
1236 const int16_t *samples_16 = (
const int16_t *)
samples;
1237 unsigned int substr;
1239 lossless_check_data +=
ctx->frame_index *
ctx->num_substreams;
1241 for (substr = 0; substr <
ctx->num_substreams; substr++) {
1244 int32_t temp_lossless_check_data = 0;
1245 uint32_t greatest = 0;
1249 for (
i = 0;
i <
ctx->frame_size[
ctx->frame_index];
i++) {
1251 uint32_t abs_sample;
1254 sample = is24 ? *samples_32++ >> 8 : *samples_16++ << 8;
1258 if (greatest < abs_sample)
1259 greatest = abs_sample;
1261 temp_lossless_check_data ^= (
sample & 0x00ffffff) <<
channel;
1262 *sample_buffer++ =
sample;
1270 *lossless_check_data++ = temp_lossless_check_data;
1289 unsigned int cur_index = (
ctx->starting_frame_index +
index) %
ctx->max_restart_interval;
1290 int32_t *input_buffer =
ctx->inout_buffer + cur_index *
ctx->one_sample_buffer_size;
1293 for (
i = 0;
i <
ctx->frame_size[cur_index];
i++) {
1295 *sample_buffer++ = *input_buffer++;
1334 memset(sample_mask, 0x00,
sizeof(sample_mask));
1336 for (
i = 0;
i <
ctx->number_of_samples;
i++) {
1338 sample_mask[
channel] |= *sample_buffer++;
1353 int min = INT_MAX,
max = INT_MIN;
1358 for (order = 0; order <
fp->order; order++) {
1359 int coeff = fcoeff[order];
1366 coeff_mask |=
coeff;
1398 int32_t *lpc_samples =
ctx->lpc_sample_buffer;
1404 for (
i = 0;
i <
ctx->number_of_samples;
i++) {
1405 *lpc_samples++ = *sample_buffer;
1406 sample_buffer +=
ctx->num_channels;
1418 for (
i = 0;
i < order;
i++)
1419 fcoeff[
i] = coefs[order-1][
i];
1449 uint64_t score[4], sum[4] = { 0, 0, 0, 0, };
1455 for(
i = 2;
i <
ctx->number_of_samples;
i++) {
1456 int32_t left = left_ch [
i *
ctx->num_channels] - 2 * left_ch [(
i - 1) *
ctx->num_channels] + left_ch [(
i - 2) *
ctx->num_channels];
1457 int32_t right = right_ch[
i *
ctx->num_channels] - 2 * right_ch[(
i - 1) *
ctx->num_channels] + right_ch[(
i - 2) *
ctx->num_channels];
1460 sum[1] +=
FFABS( right);
1470 for(
i = 1;
i < 3;
i++)
1471 if(score[
i] < score[best])
1490 coeff_mask |=
coeff;
1503 unsigned int shift = 0;
1509 if (
ctx->num_channels - 2 != 2) {
1525 mp->
coeff[0][0] = 1 << 14; mp->
coeff[0][1] = -(1 << 14);
1526 mp->
coeff[0][2] = 0 << 14; mp->
coeff[0][2] = 0 << 14;
1527 mp->
forco[0][0] = 1 << 14; mp->
forco[0][1] = -(1 << 14);
1528 mp->
forco[0][2] = 0 << 14; mp->
forco[0][2] = 0 << 14;
1533 mp->
coeff[0][0] = 1 << 14; mp->
coeff[0][1] = 1 << 14;
1534 mp->
coeff[0][2] = 0 << 14; mp->
coeff[0][2] = 0 << 14;
1535 mp->
forco[0][0] = 1 << 14; mp->
forco[0][1] = -(1 << 14);
1536 mp->
forco[0][2] = 0 << 14; mp->
forco[0][2] = 0 << 14;
1540 for (mat = 0; mat < mp->
count; mat++)
1553 {-9, 8}, {-8, 7}, {-15, 14},
1573 lsb_bits += !!lsb_bits;
1575 unsign = 1 << (lsb_bits - 1);
1610 unsign = 1 << (lsb_bits - 1);
1619 bo->
min =
max - unsign + 1;
1627 unsigned int channel,
int codebook,
1635 int codebook_offset = 7 + (2 - codebook);
1637 int lsb_bits = 0, bitcount = 0;
1638 int offset_min = INT_MAX, offset_max = INT_MAX;
1645 while (sample_min < codebook_min || sample_max > codebook_max) {
1651 unsign = 1 << lsb_bits;
1654 if (codebook == 2) {
1655 unsign_offset -= unsign;
1661 int temp_min, temp_max;
1666 if (temp_min < offset_min)
1667 offset_min = temp_min;
1669 temp_max = unsign - temp_min - 1;
1670 if (temp_max < offset_max)
1671 offset_max = temp_max;
1677 sample_buffer +=
ctx->num_channels;
1691 unsigned int channel,
int codebook,
1695 int previous_count = INT_MAX;
1696 int offset_min, offset_max;
1709 if (temp_bo.
bitcount < previous_count) {
1714 }
else if (++is_greater >=
ctx->max_codebook_search)
1757 sample_buffer +=
ctx->num_channels;
1763 if (no_filters_used) {
1771 BestOffset temp_bo = { 0, INT_MAX, 0, 0, 0, };
1778 if (no_filters_used) {
1779 offset_max = temp_bo.
max;
1796 #define SAMPLE_MAX(bitdepth) ((1 << (bitdepth - 1)) - 1)
1797 #define SAMPLE_MIN(bitdepth) (~SAMPLE_MAX(bitdepth))
1799 #define MSB_MASK(bits) (-1u << bits)
1813 unsigned int number_of_samples =
ctx->number_of_samples;
1814 unsigned int filter_shift =
fp[
FIR]->shift;
1819 unsigned int size =
ctx->number_of_samples;
1821 if (!filter_state_buffer[
i]) {
1823 "Not enough memory for applying filters.\n");
1828 for (
i = 0;
i < 8;
i++) {
1829 filter_state_buffer[
FIR][
i] = *sample_buffer;
1830 filter_state_buffer[
IIR][
i] = *sample_buffer;
1832 sample_buffer +=
ctx->num_channels;
1835 for (
i = 8;
i < number_of_samples;
i++) {
1843 for (order = 0; order <
fp[
filter]->order; order++)
1844 accum += (int64_t)filter_state_buffer[
filter][
i - 1 - order] *
1848 accum >>= filter_shift;
1857 sample_buffer +=
ctx->num_channels;
1860 sample_buffer =
ctx->sample_buffer +
channel;
1861 for (
i = 0;
i < number_of_samples;
i++) {
1862 *sample_buffer = filter_state_buffer[
IIR][
i];
1864 sample_buffer +=
ctx->num_channels;
1893 int32_t *sample_buffer =
ctx->sample_buffer +
ctx->num_channels - 2;
1898 for (
i = 0;
i <
ctx->number_of_samples;
i++) {
1899 uint16_t seed_shr7 =
seed >> 7;
1901 *sample_buffer++ = ((int8_t) seed_shr7) << rh->
noise_shift;
1903 seed = (
seed << 16) ^ seed_shr7 ^ (seed_shr7 << 5);
1905 sample_buffer +=
ctx->num_channels - 2;
1917 unsigned int mat,
i, maxchan;
1919 maxchan =
ctx->num_channels;
1921 for (mat = 0; mat < mp->
count; mat++) {
1924 unsigned int outch = mp->
outch[mat];
1926 sample_buffer =
ctx->sample_buffer;
1927 for (
i = 0;
i <
ctx->number_of_samples;
i++) {
1928 unsigned int src_ch;
1931 for (src_ch = 0; src_ch < maxchan; src_ch++) {
1933 accum += (int64_t)
sample * mp->
forco[mat][src_ch];
1935 sample_buffer[outch] = (accum >> 14) &
mask;
1937 sample_buffer +=
ctx->num_channels;
1953 #define ZERO_PATH '0'
1954 #define CODEBOOK_CHANGE_BITS 21
1962 path_counter[
i].
path[1] = 0x00;
1979 int bitcount =
src->bitcount;
1980 char *path =
src->path + 1;
1984 for (
i = 0; path[
i];
i++)
1991 bitcount += cur_bo[cur_codebook].
bitcount;
1993 if (prev_codebook != cur_codebook ||
2009 unsigned int best_codebook;
2016 unsigned int best_bitcount = INT_MAX;
2017 unsigned int codebook;
2022 int prev_best_bitcount = INT_MAX;
2025 for (last_best = 0; last_best < 2; last_best++) {
2038 src_path = &path_counter[codebook];
2043 if (temp_bitcount < best_bitcount) {
2044 best_bitcount = temp_bitcount;
2045 best_codebook = codebook;
2048 if (temp_bitcount < prev_best_bitcount) {
2049 prev_best_bitcount = temp_bitcount;
2050 if (src_path != dst_path)
2053 dst_path->
bitcount = temp_bitcount;
2069 best_codebook = *best_path++ -
ZERO_PATH;
2087 unsigned int substr;
2091 for (substr = 0; substr <
ctx->num_substreams; substr++) {
2093 (
ctx->restart_intervals - 1)*(
ctx->sequence_size)*(
ctx->avctx->channels) +
2094 (
ctx->seq_offset[
ctx->restart_intervals - 1])*(
ctx->avctx->channels);
2097 (
ctx->restart_intervals - 1)*(
ctx->sequence_size)*(
ctx->avctx->channels) +
2098 (
ctx->seq_offset[
ctx->restart_intervals - 1])*(
ctx->avctx->channels);
2104 if (max_huff_lsbs < huff_lsbs)
2105 max_huff_lsbs = huff_lsbs;
2116 if (max_output_bits < ctx->max_output_bits[
index])
2117 max_output_bits =
ctx->max_output_bits[
index];
2120 for (substr = 0; substr <
ctx->num_substreams; substr++) {
2122 ctx->cur_restart_header = &
ctx->restart_header[substr];
2128 ctx->cur_decoding_params = &
ctx->major_decoding_params[
index][substr];
2129 ctx->cur_channel_params =
ctx->major_channel_params[
index];
2133 ctx->prev_decoding_params =
ctx->cur_decoding_params;
2134 ctx->prev_channel_params =
ctx->cur_channel_params;
2138 ctx->major_number_of_subblocks =
ctx->number_of_subblocks;
2139 ctx->major_filter_state_subblock = 1;
2140 ctx->major_cur_subblock_index = 0;
2148 unsigned int substr;
2150 for (substr = 0; substr <
ctx->num_substreams; substr++) {
2152 ctx->cur_restart_header = &
ctx->restart_header[substr];
2153 ctx->cur_decoding_params = seq_dp + 1*(
ctx->num_substreams) + substr;
2154 ctx->cur_channel_params = seq_cp + 1*(
ctx->avctx->channels);
2176 (seq_dp + substr)->blocksize = 8;
2177 (seq_dp + 1*(
ctx->num_substreams) + substr)->blocksize -= 8;
2180 ctx->cur_decoding_params = seq_dp +
index*(
ctx->num_substreams) + substr;
2181 ctx->cur_channel_params = seq_cp +
index*(
ctx->avctx->channels);
2184 ctx->sample_buffer +=
ctx->cur_decoding_params->blocksize *
ctx->num_channels;
2193 unsigned int substr;
2195 ctx->sample_buffer =
ctx->major_inout_buffer;
2197 ctx->starting_frame_index = 0;
2198 ctx->number_of_frames =
ctx->major_number_of_frames;
2199 ctx->number_of_samples =
ctx->major_frame_size;
2201 for (substr = 0; substr <
ctx->num_substreams; substr++) {
2205 ctx->cur_restart_header = &
ctx->restart_header[substr];
2207 ctx->cur_decoding_params = &
ctx->major_decoding_params[1][substr];
2208 ctx->cur_channel_params =
ctx->major_channel_params[1];
2224 unsigned int bytes_written = 0;
2225 int restart_frame,
ret;
2242 ctx->inout_buffer =
ctx->major_inout_buffer
2243 +
ctx->frame_index *
ctx->one_sample_buffer_size;
2245 if (
ctx->last_frame ==
ctx->inout_buffer) {
2249 ctx->sample_buffer =
ctx->major_scratch_buffer
2250 +
ctx->frame_index *
ctx->one_sample_buffer_size;
2252 ctx->write_buffer =
ctx->inout_buffer;
2256 goto input_and_return;
2262 ctx->frame_index = 0;
2264 ctx->sample_buffer =
ctx->major_scratch_buffer;
2265 ctx->inout_buffer =
ctx->major_inout_buffer;
2275 restart_frame = !
ctx->frame_index;
2277 if (restart_frame) {
2279 if (
ctx->min_restart_interval !=
ctx->max_restart_interval)
2283 if (
ctx->min_restart_interval ==
ctx->max_restart_interval)
2284 ctx->write_buffer =
ctx->sample_buffer;
2288 ctx->timestamp +=
ctx->frame_size[
ctx->frame_index];
2289 ctx->dts +=
ctx->frame_size[
ctx->frame_index];
2296 ctx->next_major_number_of_frames++;
2298 }
else if (!
ctx->last_frame) {
2299 ctx->last_frame =
ctx->inout_buffer;
2302 restart_frame = (
ctx->frame_index + 1) %
ctx->min_restart_interval;
2304 if (!restart_frame) {
2308 seq_index <
ctx->restart_intervals && (seq_index *
ctx->min_restart_interval) <=
ctx->avctx->frame_number;
2310 unsigned int number_of_samples = 0;
2313 ctx->sample_buffer =
ctx->major_scratch_buffer;
2314 ctx->inout_buffer =
ctx->major_inout_buffer;
2315 ctx->seq_index = seq_index;
2317 ctx->starting_frame_index = (
ctx->avctx->frame_number - (
ctx->avctx->frame_number %
ctx->min_restart_interval)
2318 - (seq_index *
ctx->min_restart_interval)) %
ctx->max_restart_interval;
2319 ctx->number_of_frames =
ctx->next_major_number_of_frames;
2320 ctx->number_of_subblocks =
ctx->next_major_number_of_frames + 1;
2323 (
ctx->frame_index /
ctx->min_restart_interval)*(
ctx->sequence_size)*(
ctx->avctx->channels) +
2324 (
ctx->seq_offset[seq_index])*(
ctx->avctx->channels);
2327 (
ctx->frame_index /
ctx->min_restart_interval)*(
ctx->sequence_size)*(
ctx->num_substreams) +
2328 (
ctx->seq_offset[seq_index])*(
ctx->num_substreams);
2331 number_of_samples +=
ctx->frame_size[(
ctx->starting_frame_index +
index) %
ctx->max_restart_interval];
2333 ctx->number_of_samples = number_of_samples;
2345 if (
ctx->frame_index == (
ctx->max_restart_interval - 1)) {
2346 ctx->major_frame_size =
ctx->next_major_frame_size;
2347 ctx->next_major_frame_size = 0;
2348 ctx->major_number_of_frames =
ctx->next_major_number_of_frames;
2349 ctx->next_major_number_of_frames = 0;
2351 if (!
ctx->major_frame_size)
2360 avpkt->
size = bytes_written;
2383 #if CONFIG_MLP_ENCODER
2395 .supported_samplerates = (
const int[]) {44100, 48000, 88200, 96000, 176400, 192000, 0},
2399 #if CONFIG_TRUEHD_ENCODER
2411 .supported_samplerates = (
const int[]) {44100, 48000, 88200, 96000, 176400, 192000, 0},
uint8_t fbits[MAX_CHANNELS]
fraction bits
int frame_size
Number of samples per channel in an audio frame.
static void set_best_codebook(MLPEncodeContext *ctx)
#define AV_LOG_WARNING
Something somehow does not look correct.
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.
#define AV_CH_LAYOUT_5POINT0_BACK
static av_cold int init(AVCodecContext *avctx)
#define MLP_MIN_LPC_ORDER
unsigned int major_cur_subblock_index
uint8_t codebook
Which VLC codebook to use to read residuals.
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
uint8_t ch_modifier_thd1
channel modifier for TrueHD stream 1
static uint8_t xor_32_to_8(uint32_t value)
XOR four bytes into one.
uint64_t channel_layout
Audio channel layout.
static ChannelParams restart_channel_params[MAX_CHANNELS]
static void write_decoding_params(MLPEncodeContext *ctx, PutBitContext *pb, int params_changed)
Writes decoding parameters to the bitstream.
void ff_af_queue_remove(AudioFrameQueue *afq, int nb_samples, int64_t *pts, int64_t *duration)
Remove frame(s) from the queue.
int sample_rate
samples per second
static uint8_t * write_substrs(MLPEncodeContext *ctx, uint8_t *buf, int buf_size, int restart_frame, uint16_t substream_data_len[MAX_SUBSTREAMS])
Writes the substreams data to the bitstream.
static enum MLPChMode estimate_stereo_mode(MLPEncodeContext *ctx)
void ff_af_queue_close(AudioFrameQueue *afq)
Close AudioFrameQueue.
int32_t * major_scratch_buffer
Scratch buffer big enough to fit all data for one entire major frame interval.
static enum AVSampleFormat sample_fmts[]
static void write_major_sync(MLPEncodeContext *ctx, uint8_t *buf, int buf_size)
Writes a major sync header to the bitstream.
static av_cold int mlp_encode_close(AVCodecContext *avctx)
uint16_t blocksize
number of PCM samples in current audio block
#define SAMPLE_MAX(bitdepth)
int coded_peak_bitrate
peak bitrate for this major sync header
#define AV_CH_LAYOUT_MONO
int32_t * lpc_sample_buffer
DecodingParams * prev_decoding_params
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(const uint8_t *) pi - 0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(const uint8_t *) pi - 0x80) *(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(const int16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(const int16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16, *(const int16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(const int32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(const int32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32, *(const int32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(const int64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64, *(const int64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(const float *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(const float *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(const float *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(const float *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(const double *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(const double *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(const double *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(const double *) pi *(INT64_C(1)<< 63))) #define FMT_PAIR_FUNC(out, in) static conv_func_type *const fmt_pair_to_conv_functions[AV_SAMPLE_FMT_NB *AV_SAMPLE_FMT_NB]={ FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_U8), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S16), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S32), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_FLT), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_DBL), FMT_PAIR_FUNC(AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_S64), FMT_PAIR_FUNC(AV_SAMPLE_FMT_S64, AV_SAMPLE_FMT_S64), };static void cpy1(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, len);} static void cpy2(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 2 *len);} static void cpy4(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 4 *len);} static void cpy8(uint8_t **dst, const uint8_t **src, int len){ memcpy(*dst, *src, 8 *len);} AudioConvert *swri_audio_convert_alloc(enum AVSampleFormat out_fmt, enum AVSampleFormat in_fmt, int channels, const int *ch_map, int flags) { AudioConvert *ctx;conv_func_type *f=fmt_pair_to_conv_functions[av_get_packed_sample_fmt(out_fmt)+AV_SAMPLE_FMT_NB *av_get_packed_sample_fmt(in_fmt)];if(!f) return NULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) return NULL;if(channels==1){ in_fmt=av_get_planar_sample_fmt(in_fmt);out_fmt=av_get_planar_sample_fmt(out_fmt);} ctx->channels=channels;ctx->conv_f=f;ctx->ch_map=ch_map;if(in_fmt==AV_SAMPLE_FMT_U8||in_fmt==AV_SAMPLE_FMT_U8P) memset(ctx->silence, 0x80, sizeof(ctx->silence));if(out_fmt==in_fmt &&!ch_map) { switch(av_get_bytes_per_sample(in_fmt)){ case 1:ctx->simd_f=cpy1;break;case 2:ctx->simd_f=cpy2;break;case 4:ctx->simd_f=cpy4;break;case 8:ctx->simd_f=cpy8;break;} } if(HAVE_X86ASM &&1) swri_audio_convert_init_x86(ctx, out_fmt, in_fmt, channels);if(ARCH_ARM) swri_audio_convert_init_arm(ctx, out_fmt, in_fmt, channels);if(ARCH_AARCH64) swri_audio_convert_init_aarch64(ctx, out_fmt, in_fmt, channels);return ctx;} void swri_audio_convert_free(AudioConvert **ctx) { av_freep(ctx);} int swri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, int len) { int ch;int off=0;const int os=(out->planar ? 1 :out->ch_count) *out->bps;unsigned misaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask) { int planes=in->planar ? in->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) in->ch[ch];misaligned|=m &ctx->in_simd_align_mask;} if(ctx->out_simd_align_mask) { int planes=out->planar ? out->ch_count :1;unsigned m=0;for(ch=0;ch< planes;ch++) m|=(intptr_t) out->ch[ch];misaligned|=m &ctx->out_simd_align_mask;} if(ctx->simd_f &&!ctx->ch_map &&!misaligned){ off=len &~15;av_assert1(off >=0);av_assert1(off<=len);av_assert2(ctx->channels==SWR_CH_MAX||!in->ch[ctx->channels]);if(off >0){ if(out->planar==in->planar){ int planes=out->planar ? out->ch_count :1;for(ch=0;ch< planes;ch++){ ctx->simd_f(out-> ch ch
static void put_sbits(PutBitContext *pb, int n, int32_t value)
int32_t forco[MAX_MATRICES][MAX_CHANNELS+2]
forward coefficients
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
av_cold void ff_af_queue_init(AVCodecContext *avctx, AudioFrameQueue *afq)
Initialize AudioFrameQueue.
#define SUBSTREAM_INFO_HIGH_RATE
static av_cold int end(AVCodecContext *avctx)
int8_t shift[MAX_CHANNELS]
Left shift to apply to decoded PCM values to get final 24-bit output.
This structure describes decoded (raw) audio or video data.
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
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.
static void clear_path_counter(PathCounter *path_counter)
unsigned int number_of_subblocks
uint8_t ff_mlp_calculate_parity(const uint8_t *buf, unsigned int buf_size)
XOR together all the bytes of a buffer.
unsigned int number_of_frames
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
const ChannelInformation ff_mlp_ch_info[21]
Tables defining channel information.
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce then the filter should push the output frames on the output link immediately As an exception to the previous rule if the input frame is enough to produce several output frames then the filter needs output only at least one per link The additional frames can be left buffered in the filter
static void set_major_params(MLPEncodeContext *ctx)
Analyzes all collected bitcounts and selects the best parameters for each individual access unit.
unsigned int min_restart_interval
Min interval of access units in between two major frames.
unsigned int sequence_size
static void write_block_data(MLPEncodeContext *ctx, PutBitContext *pb)
Writes the residuals to the bitstream.
uint16_t ff_mlp_checksum16(const uint8_t *buf, unsigned int buf_size)
FilterParams filter_params[NUM_FILTERS]
uint8_t ff_mlp_checksum8(const uint8_t *buf, unsigned int buf_size)
MLP uses checksums that seem to be based on the standard CRC algorithm, but are not (in implementatio...
static void clear_decoding_params(MLPEncodeContext *ctx, DecodingParams decoding_params[MAX_SUBSTREAMS])
Clears a DecodingParams struct the way it should be after a restart header.
uint8_t huff_lsbs
Size of residual suffix not encoded using VLC.
static int mlp_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet)
unsigned int major_number_of_frames
#define MLP_MAX_LPC_ORDER
static int compare_matrix_params(MLPEncodeContext *ctx, const MatrixParams *prev, const MatrixParams *mp)
Compare two primitive matrices and returns 1 if anything has changed.
unsigned int next_major_frame_size
Counter of number of samples for next major frame.
int ff_af_queue_add(AudioFrameQueue *afq, const AVFrame *f)
Add a frame to the queue.
#define AV_CH_LAYOUT_STEREO
#define AV_CH_LAYOUT_QUAD
int32_t * sample_buffer
Pointer to current access unit samples.
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 ...
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define SUBSTREAM_INFO_MAX_2_CHAN
#define AV_CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
unsigned int major_filter_state_subblock
static const uint16_t mask[17]
ChannelParams * seq_channel_params
uint8_t ch_modifier_thd2
channel modifier for TrueHD stream 2
static void copy_matrix_params(MatrixParams *dst, MatrixParams *src)
int flags
Flags modifying the (de)muxer behaviour.
uint16_t dts
Decoding timestamp of current access unit.
int num_channels
Number of channels in major_scratch_buffer.
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
static int mlp_peak_bitrate(int peak_bitrate, int sample_rate)
static void default_decoding_params(MLPEncodeContext *ctx, DecodingParams decoding_params[MAX_SUBSTREAMS])
Sets default vales in our encoder for a DecodingParams struct.
static void code_matrix_coeffs(MLPEncodeContext *ctx, unsigned int mat)
Determines how many fractional bits are needed to encode matrix coefficients.
const uint64_t ff_mlp_channel_layouts[12]
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
static void determine_bits(MLPEncodeContext *ctx)
Determines the least amount of bits needed to encode the samples using any or no codebook.
int flags
major sync info flags
static void lossless_matrix_coeffs(MLPEncodeContext *ctx)
Determines best coefficients to use for the lossless matrix.
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.
uint16_t timestamp
Timestamp of current access unit.
RestartHeader * cur_restart_header
static const int codebook_extremes[3][2]
Min and max values that can be encoded with each codebook.
static void apply_filters(MLPEncodeContext *ctx)
unsigned int major_frame_size
Number of samples in current major frame being encoded.
int num_substreams
Number of substreams contained within this stream.
int32_t * lossless_check_data
Array with lossless_check_data for each access unit.
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.
unsigned int starting_frame_index
static void copy_filter_params(ChannelParams *dst_cp, ChannelParams *src_cp, int filter)
static void input_to_sample_buffer(MLPEncodeContext *ctx)
unsigned int * frame_size
Array with number of samples/channel in each access unit.
static void rematrix_channels(MLPEncodeContext *ctx)
Rematrixes all channels using chosen coefficients.
int32_t coeff[NUM_FILTERS][MAX_FIR_ORDER]
int ff_lpc_calc_coefs(LPCContext *s, const int32_t *samples, int blocksize, int min_order, int max_order, int precision, int32_t coefs[][MAX_LPC_ORDER], int *shift, enum FFLPCType lpc_type, int lpc_passes, int omethod, int min_shift, int max_shift, int zero_shift)
Calculate LPC coefficients for multiple orders.
unsigned int * max_output_bits
largest output bit-depth
static int number_sbits(int number)
Calculates the smallest number of bits it takes to encode a given signed value in two's complement.
unsigned int number_of_samples
AVCodec ff_truehd_encoder
unsigned int major_number_of_subblocks
uint8_t channel_arrangement
channel arrangement for MLP streams
uint8_t ff_mlp_restart_checksum(const uint8_t *buf, unsigned int bit_size)
Calculate an 8-bit checksum over a restart header – a non-multiple-of-8 number of bits,...
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...
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
int32_t * last_frame
Pointer to last frame with data to encode.
unsigned int max_restart_interval
Max interval of access units in between two major frames.
enum AVSampleFormat sample_fmt
audio sample format
#define MAX_SUBSTREAMS
Maximum number of substreams that can be decoded.
int32_t * write_buffer
Pointer to data currently being written to bitstream.
uint8_t ch_modifier_thd0
channel modifier for TrueHD stream 0
#define NUM_FILTERS
number of allowed filters
DecodingParams * cur_decoding_params
uint8_t order
number of taps in filter
static void generate_2_noise_channels(MLPEncodeContext *ctx)
Generates two noise channels worth of data.
uint8_t quant_step_size[MAX_CHANNELS]
left shift to apply to Huffman-decoded residuals
static unsigned int write_access_unit(MLPEncodeContext *ctx, uint8_t *buf, int buf_size, int restart_frame)
Writes an entire access unit to the bitstream.
#define AV_CH_LAYOUT_5POINT1_BACK
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf offset
int16_t huff_offset
Offset to apply to residual values.
static int number_trailing_zeroes(int32_t sample)
Counts the number of trailing zeroes in a value.
static void input_data(MLPEncodeContext *ctx, void *samples)
Wrapper function for inputting data in two different bit-depths.
#define AV_CH_LAYOUT_3POINT1
av_cold void ff_lpc_end(LPCContext *s)
Uninitialize LPCContext.
int channels
number of audio channels
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.
ChannelParams * prev_channel_params
DecodingParams * decoding_params
unsigned int restart_intervals
Number of possible major frame sizes.
uint8_t outch[MAX_MATRICES]
output channel for each matrix
char path[MAJOR_HEADER_INTERVAL+3]
#define i(width, name, range_min, range_max)
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
static int put_bits_count(PutBitContext *s)
int32_t * inout_buffer
Pointer to data currently being read from lavc or written to bitstream.
#define AV_CH_LAYOUT_2POINT1
#define SUBSTREAM_INFO_ALWAYS_SET
static DecodingParams restart_decoding_params[MAX_SUBSTREAMS]
#define av_malloc_array(a, b)
static int compare_best_offset(BestOffset *prev, BestOffset *cur)
AVSampleFormat
Audio sample formats.
static BestOffset restart_best_offset[NUM_CODEBOOKS]
#define AV_CH_LAYOUT_4POINT1
unsigned int max_codebook_search
@ AV_SAMPLE_FMT_S16
signed 16 bits
const char * name
Name of the codec implementation.
sample data coding information
av_cold void ff_mlp_init_crc(void)
#define MAJOR_SYNC_INFO_SIGNATURE
ChannelParams * cur_channel_params
#define NUM_CODEBOOKS
Number of possible codebooks (counting "no codebooks")
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
size_t av_strlcat(char *dst, const char *src, size_t size)
Append the string src to the string dst, but to a total length of no more than size - 1 bytes,...
#define AV_CH_LAYOUT_SURROUND
int32_t coeff[MAX_MATRICES][MAX_CHANNELS+2]
decoding coefficients
static volatile int checksum
Tag MUST be and< 10hcoeff half pel interpolation filter coefficients, hcoeff[0] are the 2 middle coefficients[1] are the next outer ones and so on, resulting in a filter like:...eff[2], hcoeff[1], hcoeff[0], hcoeff[0], hcoeff[1], hcoeff[2] ... the sign of the coefficients is not explicitly stored but alternates after each coeff and coeff[0] is positive, so ...,+,-,+,-,+,+,-,+,-,+,... hcoeff[0] is not explicitly stored but found by subtracting the sum of all stored coefficients with signs from 32 hcoeff[0]=32 - hcoeff[1] - hcoeff[2] - ... a good choice for hcoeff and htaps is htaps=6 hcoeff={40,-10, 2} an alternative which requires more computations at both encoder and decoder side and may or may not be better is htaps=8 hcoeff={42,-14, 6,-2}ref_frames minimum of the number of available reference frames and max_ref_frames for example the first frame after a key frame always has ref_frames=1spatial_decomposition_type wavelet type 0 is a 9/7 symmetric compact integer wavelet 1 is a 5/3 symmetric compact integer wavelet others are reserved stored as delta from last, last is reset to 0 if always_reset||keyframeqlog quality(logarithmic quantizer scale) stored as delta from last, last is reset to 0 if always_reset||keyframemv_scale stored as delta from last, last is reset to 0 if always_reset||keyframe FIXME check that everything works fine if this changes between framesqbias dequantization bias stored as delta from last, last is reset to 0 if always_reset||keyframeblock_max_depth maximum depth of the block tree stored as delta from last, last is reset to 0 if always_reset||keyframequant_table quantization tableHighlevel bitstream structure:==============================--------------------------------------------|Header|--------------------------------------------|------------------------------------|||Block0||||split?||||yes no||||......... intra?||||:Block01 :yes no||||:Block02 :....... ..........||||:Block03 ::y DC ::ref index:||||:Block04 ::cb DC ::motion x :||||......... :cr DC ::motion y :||||....... ..........|||------------------------------------||------------------------------------|||Block1|||...|--------------------------------------------|------------ ------------ ------------|||Y subbands||Cb subbands||Cr subbands||||--- ---||--- ---||--- ---|||||LL0||HL0||||LL0||HL0||||LL0||HL0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||LH0||HH0||||LH0||HH0||||LH0||HH0|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HL1||LH1||||HL1||LH1||||HL1||LH1|||||--- ---||--- ---||--- ---||||--- ---||--- ---||--- ---|||||HH1||HL2||||HH1||HL2||||HH1||HL2|||||...||...||...|||------------ ------------ ------------|--------------------------------------------Decoding process:=================------------|||Subbands|------------||||------------|Intra DC||||LL0 subband prediction ------------|\ Dequantization ------------------- \||Reference frames|\ IDWT|------- -------|Motion \|||Frame 0||Frame 1||Compensation . OBMC v -------|------- -------|--------------. \------> Frame n output Frame Frame<----------------------------------/|...|------------------- Range Coder:============Binary Range Coder:------------------- The implemented range coder is an adapted version based upon "Range encoding: an algorithm for removing redundancy from a digitised message." by G. N. N. Martin. The symbols encoded by the Snow range coder are bits(0|1). The associated probabilities are not fix but change depending on the symbol mix seen so far. bit seen|new state ---------+----------------------------------------------- 0|256 - state_transition_table[256 - old_state];1|state_transition_table[old_state];state_transition_table={ 0, 0, 0, 0, 0, 0, 0, 0, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 194, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 215, 215, 216, 217, 218, 219, 220, 220, 222, 223, 224, 225, 226, 227, 227, 229, 229, 230, 231, 232, 234, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 0, 0, 0, 0, 0, 0, 0};FIXME Range Coding of integers:------------------------- FIXME Neighboring Blocks:===================left and top are set to the respective blocks unless they are outside of the image in which case they are set to the Null block top-left is set to the top left block unless it is outside of the image in which case it is set to the left block if this block has no larger parent block or it is at the left side of its parent block and the top right block is not outside of the image then the top right block is used for top-right else the top-left block is used Null block y, cb, cr are 128 level, ref, mx and my are 0 Motion Vector Prediction:=========================1. the motion vectors of all the neighboring blocks are scaled to compensate for the difference of reference frames scaled_mv=(mv *(256 *(current_reference+1)/(mv.reference+1))+128)> the median of the scaled left
static int best_codebook_path_cost(MLPEncodeContext *ctx, unsigned int channel, PathCounter *src, int cur_codebook)
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.
static int compare_decoding_params(MLPEncodeContext *ctx)
Compares two DecodingParams and ChannelParams structures to decide if a new decoding params header ha...
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.
main external API structure.
static void write_filter_params(MLPEncodeContext *ctx, PutBitContext *pb, unsigned int channel, unsigned int filter)
Writes filter parameters for one filter to the bitstream.
int32_t * major_inout_buffer
Buffer with all in/out data for one entire major frame interval.
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 ...
ChannelParams * channel_params
unsigned int next_major_number_of_frames
MatrixParams matrix_params
static void analyze_sample_buffer(MLPEncodeContext *ctx)
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Filter the word “frame” indicates either a video frame or a group of audio samples
#define SAMPLE_MIN(bitdepth)
unsigned int one_sample_buffer_size
Number of samples*channel for one access unit.
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 o...
static int shift(int a, int b)
unsigned int seq_index
Sequence index for high compression levels.
unsigned int frame_index
Index of current frame being encoded.
static void process_major_frame(MLPEncodeContext *ctx)
int frame_number
Frame counter, set by libavcodec.
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
static av_always_inline int diff(const uint32_t a, const uint32_t b)
const uint8_t ff_mlp_huffman_tables[3][18][2]
Tables defining the Huffman codes.
static av_cold int mlp_encode_init(AVCodecContext *avctx)
This structure stores compressed data.
DecodingParams * seq_decoding_params
static void clear_channel_params(MLPEncodeContext *ctx, ChannelParams channel_params[MAX_CHANNELS])
Clears a ChannelParams struct the way it should be after a restart header.
#define AV_CH_LAYOUT_4POINT0
#define CODEBOOK_CHANGE_BITS
static const double coeff[2][5]
static void write_matrix_params(MLPEncodeContext *ctx, PutBitContext *pb)
Writes matrix params for all primitive matrices to the bitstream.
#define MLP_MIN_LPC_SHIFT
uint8_t count
number of matrices to apply
static const char * path_counter_codebook[]
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
static void determine_filters(MLPEncodeContext *ctx)
Tries to determine a good prediction filter, and applies it to the samples buffer if the filter is go...
uint8_t shift
Right shift to apply to output of filter.
@ AV_SAMPLE_FMT_S32
signed 32 bits
#define MLP_MAX_LPC_SHIFT
@ FF_LPC_TYPE_LEVINSON
Levinson-Durbin recursion.
uint8_t param_presence_flags
Bitmask of which parameter sets are conveyed in a decoding parameter block.
#define MAJOR_HEADER_INTERVAL
MLP encoder Copyright (c) 2008 Ramiro Polla.
av_cold int ff_lpc_init(LPCContext *s, int blocksize, int max_order, enum FFLPCType lpc_type)
Initialize LPCContext.
static void write_restart_header(MLPEncodeContext *ctx, PutBitContext *pb)
Writes a restart header to the bitstream.
static void copy_restart_frame_params(MLPEncodeContext *ctx, unsigned int substr)