33 #define MAJOR_HEADER_INTERVAL 16
35 #define MLP_MIN_LPC_ORDER 1
36 #define MLP_MAX_LPC_ORDER 8
37 #define MLP_MIN_LPC_SHIFT 8
38 #define MLP_MAX_LPC_SHIFT 15
97 #define HUFF_OFFSET_MIN (-16384)
98 #define HUFF_OFFSET_MAX ( 16383)
101 #define NUM_CODEBOOKS 4
111 int coded_sample_fmt [2];
112 int coded_sample_rate[2];
208 #define SYNC_MAJOR 0xf8726f
209 #define MAJOR_SYNC_INFO_SIGNATURE 0xB752
211 #define SYNC_MLP 0xbb
212 #define SYNC_TRUEHD 0xba
215 #define FLAGS_DVDA 0x4000
217 #define FLAGS_CONST 0x8000
219 #define SUBSTREAM_INFO_MAX_2_CHAN 0x01
220 #define SUBSTREAM_INFO_HIGH_RATE 0x02
221 #define SUBSTREAM_INFO_ALWAYS_SET 0x04
222 #define SUBSTREAM_INFO_2_SUBSTREAMS 0x08
246 for (
i = 0;
i <
fp->order;
i++)
271 for (mat = 0; mat < mp->
count; mat++) {
317 for (ch = rh->
min_channel; ch <= rh->max_channel; ch++) {
355 for (order = 0; order < dst->
order; order++)
376 dst->
outch[count] =
src->outch[count];
410 for (substr = 0; substr <
ctx->num_substreams; substr++) {
446 for (substr = 0; substr <
ctx->num_substreams; substr++) {
448 uint8_t param_presence_flags = 0;
490 unsigned int substr,
index;
491 unsigned int sum = 0;
500 ctx->coded_sample_rate[0] = 0x08 + 0;
505 ctx->coded_sample_rate[0] = 0x08 + 1;
511 ctx->coded_sample_rate[0] = 0x08 + 2;
516 ctx->coded_sample_rate[0] = 0x00 + 0;
521 ctx->coded_sample_rate[0] = 0x00 + 1;
527 ctx->coded_sample_rate[0] = 0x00 + 2;
532 "sample rates are 44100, 88200, 176400, 48000, "
536 ctx->coded_sample_rate[1] = -1 & 0xf;
544 "Only mono and stereo are supported at the moment.\n");
555 ctx->wordlength = 16;
561 ctx->wordlength = 24;
566 "Only 16- and 24-bit samples are supported.\n");
569 ctx->coded_sample_fmt[1] = -1 & 0xf;
579 ctx->max_codebook_search = 3;
581 ctx->restart_intervals =
ctx->max_restart_interval /
ctx->min_restart_interval;
588 if (!
ctx->lpc_sample_buffer) {
590 "Not enough memory for buffering samples.\n");
594 size =
ctx->one_sample_buffer_size *
ctx->max_restart_interval;
597 if (!
ctx->major_scratch_buffer) {
599 "Not enough memory for buffering samples.\n");
604 if (!
ctx->major_inout_buffer) {
606 "Not enough memory for buffering samples.\n");
612 ctx->num_substreams = 1;
618 ctx->channel_arrangement = 0;
break;
620 ctx->channel_arrangement = 1;
break;
622 ctx->channel_arrangement = 2;
break;
624 ctx->channel_arrangement = 3;
break;
626 ctx->channel_arrangement = 4;
break;
628 ctx->channel_arrangement = 7;
break;
630 ctx->channel_arrangement = 8;
break;
632 ctx->channel_arrangement = 9;
break;
634 ctx->channel_arrangement = 10;
break;
636 ctx->channel_arrangement = 11;
break;
638 ctx->channel_arrangement = 12;
break;
650 ctx->ch_modifier_thd0 = 0;
651 ctx->ch_modifier_thd1 = 0;
652 ctx->ch_modifier_thd2 = 0;
653 ctx->channel_arrangement = 1;
656 ctx->ch_modifier_thd0 = 1;
657 ctx->ch_modifier_thd1 = 1;
658 ctx->ch_modifier_thd2 = 1;
659 ctx->channel_arrangement = 11;
662 ctx->ch_modifier_thd0 = 2;
663 ctx->ch_modifier_thd1 = 1;
664 ctx->ch_modifier_thd2 = 2;
665 ctx->channel_arrangement = 15;
672 ctx->channel_occupancy = 0;
673 ctx->summary_info = 0;
676 size =
sizeof(
unsigned int) *
ctx->max_restart_interval;
679 if (!
ctx->frame_size)
683 if (!
ctx->max_output_bits)
687 *
ctx->num_substreams *
ctx->max_restart_interval;
690 if (!
ctx->lossless_check_data)
698 ctx->sequence_size = sum;
700 *
ctx->restart_intervals *
ctx->sequence_size *
ctx->avctx->channels;
702 if (!
ctx->channel_params) {
704 "Not enough memory for analysis context.\n");
709 *
ctx->restart_intervals *
ctx->sequence_size *
ctx->num_substreams;
711 if (!
ctx->decoding_params) {
713 "Not enough memory for analysis context.\n");
717 for (substr = 0; substr <
ctx->num_substreams; substr++) {
735 "Not enough memory for LPC context.\n");
853 for (mat = 0; mat < mp->
count; mat++) {
892 for (
i = 0;
i <
fp->order;
i++) {
958 for (ch = rh->
min_channel; ch <= rh->max_channel; ch++) {
1015 for (ch = rh->
min_channel; ch <= rh->max_channel; ch++) {
1020 codebook_index [ch] = cp->
codebook - 1;
1026 sign_huff_offset[ch] -= 7 << lsb_bits[ch];
1029 if (sign_shift >= 0)
1030 sign_huff_offset[ch] -= 1 << sign_shift;
1034 for (ch = rh->
min_channel; ch <= rh->max_channel; ch++) {
1036 sample -= sign_huff_offset[ch];
1038 if (codebook_index[ch] >= 0) {
1039 int vlc =
sample >> lsb_bits[ch];
1049 ctx->write_buffer = sample_buffer;
1057 int32_t *lossless_check_data =
ctx->lossless_check_data;
1058 unsigned int substr;
1061 lossless_check_data +=
ctx->frame_index *
ctx->num_substreams;
1063 for (substr = 0; substr <
ctx->num_substreams; substr++) {
1064 unsigned int cur_subblock_index =
ctx->major_cur_subblock_index;
1065 unsigned int num_subblocks =
ctx->major_filter_state_subblock;
1066 unsigned int subblock;
1068 int substr_restart_frame = restart_frame;
1073 ctx->cur_restart_header = rh;
1077 for (subblock = 0; subblock <= num_subblocks; subblock++) {
1078 unsigned int subblock_index;
1080 subblock_index = cur_subblock_index++;
1082 ctx->cur_decoding_params = &
ctx->major_decoding_params[subblock_index][substr];
1083 ctx->cur_channel_params =
ctx->major_channel_params[subblock_index];
1085 params_changed =
ctx->major_params_changed[subblock_index][substr];
1087 if (substr_restart_frame || params_changed) {
1090 if (substr_restart_frame) {
1106 put_bits(&pb, 1, !substr_restart_frame);
1108 substr_restart_frame = 0;
1115 if (
ctx->last_frame ==
ctx->inout_buffer) {
1133 substream_data_len[substr] = end;
1138 ctx->major_cur_subblock_index +=
ctx->major_filter_state_subblock + 1;
1139 ctx->major_filter_state_subblock = 0;
1146 uint8_t *substream_headers,
unsigned int length,
1150 uint16_t access_unit_header = 0;
1151 uint16_t parity_nibble = 0;
1152 unsigned int substr;
1154 parity_nibble =
ctx->dts;
1155 parity_nibble ^= length;
1157 for (substr = 0; substr <
ctx->num_substreams; substr++) {
1158 uint16_t substr_hdr = 0;
1160 substr_hdr |= (0 << 15);
1161 substr_hdr |= (!restart_frame << 14);
1162 substr_hdr |= (1 << 13);
1163 substr_hdr |= (0 << 12);
1164 substr_hdr |= (substream_data_len[substr] / 2) & 0x0FFF;
1166 AV_WB16(substream_headers, substr_hdr);
1168 parity_nibble ^= *substream_headers++;
1169 parity_nibble ^= *substream_headers++;
1172 parity_nibble ^= parity_nibble >> 8;
1173 parity_nibble ^= parity_nibble >> 4;
1174 parity_nibble &= 0xF;
1176 access_unit_header |= (parity_nibble ^ 0xF) << 12;
1177 access_unit_header |= length & 0xFFF;
1185 int buf_size,
int restart_frame)
1189 unsigned int substr;
1199 if (restart_frame) {
1210 for (substr = 0; substr <
ctx->num_substreams; substr++) {
1215 buf =
write_substrs(
ctx, buf, buf_size, restart_frame, substream_data_len);
1217 total_length = buf - buf0;
1221 return total_length;
1235 int32_t *lossless_check_data =
ctx->lossless_check_data;
1237 const int16_t *samples_16 = (
const int16_t *) samples;
1238 unsigned int substr;
1240 lossless_check_data +=
ctx->frame_index *
ctx->num_substreams;
1242 for (substr = 0; substr <
ctx->num_substreams; substr++) {
1245 int32_t temp_lossless_check_data = 0;
1246 uint32_t greatest = 0;
1250 for (
i = 0;
i <
ctx->frame_size[
ctx->frame_index];
i++) {
1252 uint32_t abs_sample;
1255 sample = is24 ? *samples_32++ >> 8 : *samples_16++ * 256;
1259 if (greatest < abs_sample)
1260 greatest = abs_sample;
1262 temp_lossless_check_data ^= (
sample & 0x00ffffff) <<
channel;
1263 *sample_buffer++ =
sample;
1271 *lossless_check_data++ = temp_lossless_check_data;
1290 unsigned int cur_index = (
ctx->starting_frame_index +
index) %
ctx->max_restart_interval;
1291 int32_t *input_buffer =
ctx->inout_buffer + cur_index *
ctx->one_sample_buffer_size;
1294 for (
i = 0;
i <
ctx->frame_size[cur_index];
i++) {
1296 *sample_buffer++ = *input_buffer++;
1335 memset(sample_mask, 0x00,
sizeof(sample_mask));
1337 for (
i = 0;
i <
ctx->number_of_samples;
i++) {
1339 sample_mask[
channel] |= *sample_buffer++;
1354 int min = INT_MAX,
max = INT_MIN;
1359 for (order = 0; order <
fp->order; order++) {
1360 int coeff = fcoeff[order];
1367 coeff_mask |=
coeff;
1399 int32_t *lpc_samples =
ctx->lpc_sample_buffer;
1405 for (
i = 0;
i <
ctx->number_of_samples;
i++) {
1406 *lpc_samples++ = *sample_buffer;
1407 sample_buffer +=
ctx->num_channels;
1419 for (
i = 0;
i < order;
i++)
1420 fcoeff[
i] = coefs[order-1][
i];
1450 uint64_t score[4], sum[4] = { 0, 0, 0, 0, };
1456 for(
i = 2;
i <
ctx->number_of_samples;
i++) {
1457 int32_t left = left_ch [
i *
ctx->num_channels] - 2 * left_ch [(
i - 1) *
ctx->num_channels] + left_ch [(
i - 2) *
ctx->num_channels];
1458 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[0] +=
FFABS( left );
1461 sum[1] +=
FFABS( right);
1462 sum[2] +=
FFABS((left + right) >> 1);
1463 sum[3] +=
FFABS( left - right);
1471 for(
i = 1;
i < 3;
i++)
1472 if(score[
i] < score[best])
1491 coeff_mask |=
coeff;
1504 unsigned int shift = 0;
1510 if (
ctx->num_channels - 2 != 2) {
1526 mp->
coeff[0][0] = 1 << 14; mp->
coeff[0][1] = -(1 << 14);
1527 mp->
coeff[0][2] = 0 << 14; mp->
coeff[0][2] = 0 << 14;
1528 mp->
forco[0][0] = 1 << 14; mp->
forco[0][1] = -(1 << 14);
1529 mp->
forco[0][2] = 0 << 14; mp->
forco[0][2] = 0 << 14;
1534 mp->
coeff[0][0] = 1 << 14; mp->
coeff[0][1] = 1 << 14;
1535 mp->
coeff[0][2] = 0 << 14; mp->
coeff[0][2] = 0 << 14;
1536 mp->
forco[0][0] = 1 << 14; mp->
forco[0][1] = -(1 << 14);
1537 mp->
forco[0][2] = 0 << 14; mp->
forco[0][2] = 0 << 14;
1541 for (mat = 0; mat < mp->
count; mat++)
1554 {-9, 8}, {-8, 7}, {-15, 14},
1574 lsb_bits += !!lsb_bits;
1577 unsign = 1 << (lsb_bits - 1);
1613 unsign = 1 << (lsb_bits - 1);
1622 bo->
min =
max - unsign + 1;
1638 int codebook_offset = 7 + (2 -
codebook);
1640 int lsb_bits = 0, bitcount = 0;
1641 int offset_min = INT_MAX, offset_max = INT_MAX;
1648 while (sample_min < codebook_min || sample_max > codebook_max) {
1654 unsign = 1 << lsb_bits;
1658 unsign_offset -= unsign;
1664 int temp_min, temp_max;
1669 if (temp_min < offset_min)
1670 offset_min = temp_min;
1672 temp_max = unsign - temp_min - 1;
1673 if (temp_max < offset_max)
1674 offset_max = temp_max;
1680 sample_buffer +=
ctx->num_channels;
1698 int previous_count = INT_MAX;
1699 int offset_min, offset_max;
1705 while (offset <= offset_max && offset >= offset_min) {
1712 if (temp_bo.
bitcount < previous_count) {
1717 }
else if (++is_greater >=
ctx->max_codebook_search)
1756 sample_buffer +=
ctx->num_channels;
1762 if (no_filters_used) {
1770 BestOffset temp_bo = { 0, INT_MAX, 0, 0, 0, };
1777 if (no_filters_used) {
1778 offset_max = temp_bo.
max;
1795 #define SAMPLE_MAX(bitdepth) ((1 << (bitdepth - 1)) - 1)
1796 #define SAMPLE_MIN(bitdepth) (~SAMPLE_MAX(bitdepth))
1798 #define MSB_MASK(bits) (-(int)(1u << (bits)))
1812 unsigned int number_of_samples =
ctx->number_of_samples;
1813 unsigned int filter_shift =
fp[
FIR]->shift;
1818 unsigned int size =
ctx->number_of_samples;
1820 if (!filter_state_buffer[
i]) {
1822 "Not enough memory for applying filters.\n");
1824 goto free_and_return;
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;
1853 goto free_and_return;
1859 sample_buffer +=
ctx->num_channels;
1862 sample_buffer =
ctx->sample_buffer +
channel;
1863 for (
i = 0;
i < number_of_samples;
i++) {
1864 *sample_buffer = filter_state_buffer[
IIR][
i];
1866 sample_buffer +=
ctx->num_channels;
1896 int32_t *sample_buffer =
ctx->sample_buffer +
ctx->num_channels - 2;
1901 for (
i = 0;
i <
ctx->number_of_samples;
i++) {
1902 uint16_t seed_shr7 =
seed >> 7;
1904 *sample_buffer++ = ((int8_t) seed_shr7) * (1 << rh->
noise_shift);
1906 seed = (
seed << 16) ^ seed_shr7 ^ (seed_shr7 << 5);
1908 sample_buffer +=
ctx->num_channels - 2;
1920 unsigned int mat,
i, maxchan;
1922 maxchan =
ctx->num_channels;
1924 for (mat = 0; mat < mp->
count; mat++) {
1927 unsigned int outch = mp->
outch[mat];
1929 sample_buffer =
ctx->sample_buffer;
1930 for (
i = 0;
i <
ctx->number_of_samples;
i++) {
1931 unsigned int src_ch;
1934 for (src_ch = 0; src_ch < maxchan; src_ch++) {
1936 accum += (int64_t)
sample * mp->
forco[mat][src_ch];
1938 sample_buffer[outch] = (accum >> 14) &
mask;
1940 sample_buffer +=
ctx->num_channels;
1955 #define CODEBOOK_CHANGE_BITS 21
1959 memset(path_counter, 0, (
NUM_CODEBOOKS + 1) *
sizeof(*path_counter));
1973 int idx =
src->cur_idx;
1976 int bitcount =
src->bitcount;
1977 int prev_codebook =
src->path[idx];
1979 bitcount += cur_bo[cur_codebook].
bitcount;
1981 if (prev_codebook != cur_codebook ||
1997 unsigned int best_codebook;
2004 unsigned int best_bitcount = INT_MAX;
2010 int prev_best_bitcount = INT_MAX;
2013 for (last_best = 0; last_best < 2; last_best++) {
2026 src_path = &path_counter[
codebook];
2031 if (temp_bitcount < best_bitcount) {
2032 best_bitcount = temp_bitcount;
2036 if (temp_bitcount < prev_best_bitcount) {
2037 prev_best_bitcount = temp_bitcount;
2038 if (src_path != dst_path)
2042 dst_path->
bitcount = temp_bitcount;
2058 best_codebook = *best_path++;
2076 unsigned int substr;
2080 for (substr = 0; substr <
ctx->num_substreams; substr++) {
2082 (
ctx->restart_intervals - 1)*(
ctx->sequence_size)*(
ctx->avctx->channels) +
2083 (
ctx->seq_offset[
ctx->restart_intervals - 1])*(
ctx->avctx->channels);
2086 (
ctx->restart_intervals - 1)*(
ctx->sequence_size)*(
ctx->avctx->channels) +
2087 (
ctx->seq_offset[
ctx->restart_intervals - 1])*(
ctx->avctx->channels);
2093 if (max_huff_lsbs < huff_lsbs)
2094 max_huff_lsbs = huff_lsbs;
2105 if (max_output_bits < ctx->max_output_bits[
index])
2106 max_output_bits =
ctx->max_output_bits[
index];
2109 for (substr = 0; substr <
ctx->num_substreams; substr++) {
2111 ctx->cur_restart_header = &
ctx->restart_header[substr];
2117 ctx->cur_decoding_params = &
ctx->major_decoding_params[
index][substr];
2118 ctx->cur_channel_params =
ctx->major_channel_params[
index];
2122 ctx->prev_decoding_params =
ctx->cur_decoding_params;
2123 ctx->prev_channel_params =
ctx->cur_channel_params;
2127 ctx->major_number_of_subblocks =
ctx->number_of_subblocks;
2128 ctx->major_filter_state_subblock = 1;
2129 ctx->major_cur_subblock_index = 0;
2137 unsigned int substr;
2139 for (substr = 0; substr <
ctx->num_substreams; substr++) {
2141 ctx->cur_restart_header = &
ctx->restart_header[substr];
2142 ctx->cur_decoding_params = seq_dp + 1*(
ctx->num_substreams) + substr;
2143 ctx->cur_channel_params = seq_cp + 1*(
ctx->avctx->channels);
2165 (seq_dp + substr)->blocksize = 8;
2166 (seq_dp + 1*(
ctx->num_substreams) + substr)->blocksize -= 8;
2169 ctx->cur_decoding_params = seq_dp +
index*(
ctx->num_substreams) + substr;
2170 ctx->cur_channel_params = seq_cp +
index*(
ctx->avctx->channels);
2173 ctx->sample_buffer +=
ctx->cur_decoding_params->blocksize *
ctx->num_channels;
2182 unsigned int substr;
2184 ctx->sample_buffer =
ctx->major_inout_buffer;
2186 ctx->starting_frame_index = 0;
2187 ctx->number_of_frames =
ctx->major_number_of_frames;
2188 ctx->number_of_samples =
ctx->major_frame_size;
2190 for (substr = 0; substr <
ctx->num_substreams; substr++) {
2191 ctx->cur_restart_header = &
ctx->restart_header[substr];
2193 ctx->cur_decoding_params = &
ctx->major_decoding_params[1][substr];
2194 ctx->cur_channel_params =
ctx->major_channel_params[1];
2209 unsigned int bytes_written = 0;
2210 int restart_frame, ret;
2224 ctx->inout_buffer =
ctx->major_inout_buffer
2225 +
ctx->frame_index *
ctx->one_sample_buffer_size;
2227 if (
ctx->last_frame ==
ctx->inout_buffer) {
2231 ctx->sample_buffer =
ctx->major_scratch_buffer
2232 +
ctx->frame_index *
ctx->one_sample_buffer_size;
2234 ctx->write_buffer =
ctx->inout_buffer;
2238 goto input_and_return;
2244 ctx->frame_index = 0;
2246 ctx->sample_buffer =
ctx->major_scratch_buffer;
2247 ctx->inout_buffer =
ctx->major_inout_buffer;
2257 restart_frame = !
ctx->frame_index;
2259 if (restart_frame) {
2261 if (
ctx->min_restart_interval !=
ctx->max_restart_interval)
2265 if (
ctx->min_restart_interval ==
ctx->max_restart_interval)
2266 ctx->write_buffer =
ctx->sample_buffer;
2270 ctx->timestamp +=
ctx->frame_size[
ctx->frame_index];
2271 ctx->dts +=
ctx->frame_size[
ctx->frame_index];
2278 ctx->next_major_number_of_frames++;
2280 }
else if (!
ctx->last_frame) {
2281 ctx->last_frame =
ctx->inout_buffer;
2284 restart_frame = (
ctx->frame_index + 1) %
ctx->min_restart_interval;
2286 if (!restart_frame) {
2290 seq_index <
ctx->restart_intervals && (seq_index *
ctx->min_restart_interval) <=
ctx->avctx->frame_number;
2292 unsigned int number_of_samples = 0;
2295 ctx->sample_buffer =
ctx->major_scratch_buffer;
2296 ctx->inout_buffer =
ctx->major_inout_buffer;
2297 ctx->seq_index = seq_index;
2299 ctx->starting_frame_index = (
ctx->avctx->frame_number - (
ctx->avctx->frame_number %
ctx->min_restart_interval)
2300 - (seq_index *
ctx->min_restart_interval)) %
ctx->max_restart_interval;
2301 ctx->number_of_frames =
ctx->next_major_number_of_frames;
2302 ctx->number_of_subblocks =
ctx->next_major_number_of_frames + 1;
2305 (
ctx->frame_index /
ctx->min_restart_interval)*(
ctx->sequence_size)*(
ctx->avctx->channels) +
2306 (
ctx->seq_offset[seq_index])*(
ctx->avctx->channels);
2309 (
ctx->frame_index /
ctx->min_restart_interval)*(
ctx->sequence_size)*(
ctx->num_substreams) +
2310 (
ctx->seq_offset[seq_index])*(
ctx->num_substreams);
2313 number_of_samples +=
ctx->frame_size[(
ctx->starting_frame_index +
index) %
ctx->max_restart_interval];
2315 ctx->number_of_samples = number_of_samples;
2327 if (
ctx->frame_index == (
ctx->max_restart_interval - 1)) {
2328 ctx->major_frame_size =
ctx->next_major_frame_size;
2329 ctx->next_major_frame_size = 0;
2330 ctx->major_number_of_frames =
ctx->next_major_number_of_frames;
2331 ctx->next_major_number_of_frames = 0;
2333 if (!
ctx->major_frame_size)
2342 avpkt->
size = bytes_written;
2366 #if CONFIG_MLP_ENCODER
2378 .supported_samplerates = (
const int[]) {44100, 48000, 88200, 96000, 176400, 192000, 0},
2383 #if CONFIG_TRUEHD_ENCODER
2395 .supported_samplerates = (
const int[]) {44100, 48000, 88200, 96000, 176400, 192000, 0},
static enum AVSampleFormat sample_fmts[]
AVCodec ff_truehd_encoder
av_cold void ff_af_queue_init(AVCodecContext *avctx, AudioFrameQueue *afq)
Initialize AudioFrameQueue.
void ff_af_queue_close(AudioFrameQueue *afq)
Close AudioFrameQueue.
void ff_af_queue_remove(AudioFrameQueue *afq, int nb_samples, int64_t *pts, int64_t *duration)
Remove frame(s) from the queue.
int ff_af_queue_add(AudioFrameQueue *afq, const AVFrame *f)
Add a frame to the queue.
Libavcodec external API header.
static av_cold int init(AVCodecContext *avctx)
static av_always_inline void filter(int16_t *output, ptrdiff_t out_stride, const int16_t *low, ptrdiff_t low_stride, const int16_t *high, ptrdiff_t high_stride, int len, int clip)
static const unsigned codebook[256][2]
#define FFABS(a)
Absolute value, Note, INT_MIN / INT64_MIN result in undefined behavior as they are not representable ...
Public header for CRC hash function implementation.
mode
Use these values in ebur128_init (or'ed).
channel
Use these values when setting the channel map with ebur128_set_channel().
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
#define AV_CH_LAYOUT_2POINT1
#define AV_CH_LAYOUT_QUAD
#define AV_CH_LAYOUT_4POINT0
#define AV_CH_LAYOUT_MONO
#define AV_CH_LAYOUT_SURROUND
#define AV_CH_LAYOUT_5POINT0_BACK
#define AV_CH_LAYOUT_STEREO
#define AV_CH_LAYOUT_4POINT1
#define AV_CH_LAYOUT_3POINT1
#define AV_CH_LAYOUT_5POINT1_BACK
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
#define AV_CODEC_CAP_EXPERIMENTAL
Codec is experimental and is thus avoided in favor of non experimental encoders.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define AV_LOG_WARNING
Something somehow does not look correct.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
AVSampleFormat
Audio sample formats.
@ AV_SAMPLE_FMT_S32
signed 32 bits
@ AV_SAMPLE_FMT_S16
signed 16 bits
static const float quant_step_size[]
static void put_bits(Jpeg2000EncoderContext *s, int val, int n)
put n times val bit
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
av_cold void ff_lpc_end(LPCContext *s)
Uninitialize LPCContext.
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.
av_cold int ff_lpc_init(LPCContext *s, int blocksize, int max_order, enum FFLPCType lpc_type)
Initialize LPCContext.
@ FF_LPC_TYPE_LEVINSON
Levinson-Durbin recursion.
static const uint16_t mask[17]
const uint8_t ff_mlp_huffman_tables[3][18][2]
Tables defining the Huffman codes.
uint16_t ff_mlp_checksum16(const uint8_t *buf, unsigned int buf_size)
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,...
const uint64_t ff_mlp_channel_layouts[12]
const ChannelInformation ff_mlp_ch_info[21]
Tables defining channel information.
av_cold void ff_mlp_init_crc(void)
uint8_t ff_mlp_calculate_parity(const uint8_t *buf, unsigned int buf_size)
XOR together all the bytes of a buffer.
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...
#define NUM_FILTERS
number of allowed filters
#define MAX_SUBSTREAMS
Maximum number of substreams that can be decoded.
static uint8_t xor_32_to_8(uint32_t value)
XOR four bytes into one.
#define SUBSTREAM_INFO_ALWAYS_SET
static void write_matrix_params(MLPEncodeContext *ctx, PutBitContext *pb)
Writes matrix params for all primitive matrices to the bitstream.
static int mlp_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet)
static const int codebook_extremes[3][2]
Min and max values that can be encoded with each codebook.
static void analyze_sample_buffer(MLPEncodeContext *ctx)
#define MAJOR_SYNC_INFO_SIGNATURE
static void rematrix_channels(MLPEncodeContext *ctx)
Rematrixes all channels using chosen coefficients.
static void write_major_sync(MLPEncodeContext *ctx, uint8_t *buf, int buf_size)
Writes a major sync header to the bitstream.
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 ...
static void write_block_data(MLPEncodeContext *ctx, PutBitContext *pb)
Writes the residuals to the bitstream.
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.
#define SUBSTREAM_INFO_MAX_2_CHAN
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...
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)
static void copy_filter_params(ChannelParams *dst_cp, ChannelParams *src_cp, int filter)
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 ...
static av_cold int mlp_encode_close(AVCodecContext *avctx)
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.
static void process_major_frame(MLPEncodeContext *ctx)
static void default_decoding_params(MLPEncodeContext *ctx, DecodingParams decoding_params[MAX_SUBSTREAMS])
Sets default vales in our encoder for a DecodingParams struct.
static void generate_2_noise_channels(MLPEncodeContext *ctx)
Generates two noise channels worth of data.
static int best_codebook_path_cost(MLPEncodeContext *ctx, unsigned int channel, PathCounter *src, int cur_codebook)
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.
static void apply_filters(MLPEncodeContext *ctx)
static void write_filter_params(MLPEncodeContext *ctx, PutBitContext *pb, unsigned int channel, unsigned int filter)
Writes filter parameters for one filter to the bitstream.
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)
#define SAMPLE_MAX(bitdepth)
static void determine_bits(MLPEncodeContext *ctx)
Determines the least amount of bits needed to encode the samples using any or no codebook.
static BestOffset restart_best_offset[NUM_CODEBOOKS]
static int compare_decoding_params(MLPEncodeContext *ctx)
Compares two DecodingParams and ChannelParams structures to decide if a new decoding params header ha...
#define MLP_MAX_LPC_ORDER
static int number_trailing_zeroes(int32_t sample)
Counts the number of trailing zeroes in a value.
static DecodingParams restart_decoding_params[MAX_SUBSTREAMS]
static int mlp_peak_bitrate(int peak_bitrate, int sample_rate)
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...
#define CODEBOOK_CHANGE_BITS
static void lossless_matrix_coeffs(MLPEncodeContext *ctx)
Determines best coefficients to use for the lossless matrix.
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.
static void input_data(MLPEncodeContext *ctx, void *samples)
Wrapper function for inputting data in two different bit-depths.
static av_cold int mlp_encode_init(AVCodecContext *avctx)
#define MLP_MIN_LPC_ORDER
#define SAMPLE_MIN(bitdepth)
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...
static int number_sbits(int number)
Calculates the smallest number of bits it takes to encode a given signed value in two's complement.
static int compare_best_offset(BestOffset *prev, BestOffset *cur)
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 ChannelParams restart_channel_params[MAX_CHANNELS]
#define NUM_CODEBOOKS
Number of possible codebooks (counting "no codebooks")
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.
static void write_decoding_params(MLPEncodeContext *ctx, PutBitContext *pb, int params_changed)
Writes decoding parameters to the bitstream.
static void copy_restart_frame_params(MLPEncodeContext *ctx, unsigned int substr)
static int compare_matrix_params(MLPEncodeContext *ctx, const MatrixParams *prev, const MatrixParams *mp)
Compare two primitive matrices and returns 1 if anything has changed.
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.
static void write_restart_header(MLPEncodeContext *ctx, PutBitContext *pb)
Writes a restart header to the bitstream.
#define MLP_MAX_LPC_SHIFT
#define MAJOR_HEADER_INTERVAL
MLP encoder Copyright (c) 2008 Ramiro Polla Copyright (c) 2016-2019 Jai Luthra.
#define MLP_MIN_LPC_SHIFT
static void code_matrix_coeffs(MLPEncodeContext *ctx, unsigned int mat)
Determines how many fractional bits are needed to encode matrix coefficients.
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.
static void copy_matrix_params(MatrixParams *dst, MatrixParams *src)
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.
static void set_best_codebook(MLPEncodeContext *ctx)
#define SUBSTREAM_INFO_HIGH_RATE
static void set_major_params(MLPEncodeContext *ctx)
Analyzes all collected bitcounts and selects the best parameters for each individual access unit.
static void input_to_sample_buffer(MLPEncodeContext *ctx)
static void put_sbits(PutBitContext *pb, int n, int32_t value)
static void init_put_bits(PutBitContext *s, uint8_t *buffer, int buffer_size)
Initialize the PutBitContext s.
static int put_bits_count(PutBitContext *s)
static void flush_put_bits(PutBitContext *s)
Pad the end of the output stream with zeros.
#define FF_ARRAY_ELEMS(a)
static int shift(int a, int b)
main external API structure.
enum AVSampleFormat sample_fmt
audio sample format
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
int sample_rate
samples per second
int frame_number
Frame counter, set by libavcodec.
int channels
number of audio channels
uint64_t channel_layout
Audio channel layout.
int frame_size
Number of samples per channel in an audio frame.
const char * name
Name of the codec implementation.
int flags
Flags modifying the (de)muxer behaviour.
This structure describes decoded (raw) audio or video data.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
This structure stores compressed data.
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
sample data coding information
FilterParams filter_params[NUM_FILTERS]
uint8_t huff_lsbs
Size of residual suffix not encoded using VLC.
int32_t coeff[NUM_FILTERS][MAX_FIR_ORDER]
int16_t huff_offset
Offset to apply to residual values.
uint8_t codebook
Which VLC codebook to use to read residuals.
uint8_t quant_step_size[MAX_CHANNELS]
left shift to apply to Huffman-decoded residuals
uint16_t blocksize
number of PCM samples in current audio block
MatrixParams matrix_params
uint8_t param_presence_flags
Bitmask of which parameter sets are conveyed in a decoding parameter block.
uint8_t shift
Right shift to apply to output of filter.
uint8_t order
number of taps in filter
uint16_t dts
Decoding timestamp of current access unit.
uint8_t ch_modifier_thd1
channel modifier for TrueHD stream 1
ChannelParams * seq_channel_params
ChannelParams * prev_channel_params
int num_substreams
Number of substreams contained within this stream.
int32_t * lpc_sample_buffer
unsigned int number_of_frames
int32_t * inout_buffer
Pointer to data currently being read from lavc or written to bitstream.
unsigned int frame_index
Index of current frame being encoded.
DecodingParams * cur_decoding_params
uint8_t ch_modifier_thd2
channel modifier for TrueHD stream 2
ChannelParams * channel_params
int32_t * major_inout_buffer
Buffer with all in/out data for one entire major frame interval.
unsigned int major_frame_size
Number of samples in current major frame being encoded.
unsigned int major_number_of_subblocks
unsigned int major_cur_subblock_index
unsigned int * frame_size
Array with number of samples/channel in each access unit.
unsigned int * max_output_bits
largest output bit-depth
unsigned int next_major_frame_size
Counter of number of samples for next major frame.
unsigned int major_filter_state_subblock
unsigned int max_codebook_search
unsigned int one_sample_buffer_size
Number of samples*channel for one access unit.
uint16_t timestamp
Timestamp of current access unit.
int coded_peak_bitrate
peak bitrate for this major sync header
unsigned int number_of_samples
DecodingParams * prev_decoding_params
uint8_t ch_modifier_thd0
channel modifier for TrueHD stream 0
unsigned int number_of_subblocks
unsigned int max_restart_interval
Max interval of access units in between two major frames.
DecodingParams * decoding_params
uint8_t channel_arrangement
channel arrangement for MLP streams
unsigned int starting_frame_index
unsigned int next_major_number_of_frames
DecodingParams * seq_decoding_params
int32_t * major_scratch_buffer
Scratch buffer big enough to fit all data for one entire major frame interval.
ChannelParams * cur_channel_params
unsigned int major_number_of_frames
int flags
major sync info flags
int32_t * last_frame
Pointer to last frame with data to encode.
unsigned int sequence_size
unsigned int min_restart_interval
Min interval of access units in between two major frames.
int32_t * lossless_check_data
Array with lossless_check_data for each access unit.
unsigned int seq_index
Sequence index for high compression levels.
unsigned int restart_intervals
Number of possible major frame sizes.
int32_t * write_buffer
Pointer to data currently being written to bitstream.
int num_channels
Number of channels in major_scratch_buffer.
int32_t * sample_buffer
Pointer to current access unit samples.
RestartHeader * cur_restart_header
int32_t coeff[MAX_MATRICES][MAX_CHANNELS+2]
decoding coefficients
uint8_t outch[MAX_MATRICES]
output channel for each matrix
int32_t forco[MAX_MATRICES][MAX_CHANNELS+2]
forward coefficients
uint8_t fbits[MAX_CHANNELS]
fraction bits
uint8_t count
number of matrices to apply
int8_t shift[MAX_CHANNELS]
Left shift to apply to decoded PCM values to get final 24-bit output.
char path[MAJOR_HEADER_INTERVAL+2]
#define av_malloc_array(a, b)
static volatile int checksum
static const double coeff[2][5]
static av_always_inline int diff(const uint32_t a, const uint32_t b)
static const uint8_t offset[127][2]