45 #define VLC_STATIC_SIZE 64
48 #define VLC_STATIC_SIZE 512
86 #define PARAM_BLOCKSIZE (1 << 7)
87 #define PARAM_MATRIX (1 << 6)
88 #define PARAM_OUTSHIFT (1 << 5)
89 #define PARAM_QUANTSTEP (1 << 4)
90 #define PARAM_FIR (1 << 3)
91 #define PARAM_IIR (1 << 2)
92 #define PARAM_HUFFOFFSET (1 << 1)
93 #define PARAM_PRESENCE (1 << 0)
203 if (!huff_vlc[0].
bits) {
219 unsigned int substr,
unsigned int ch)
228 sign_huff_offset -= 7 << lsb_bits;
231 sign_huff_offset -= 1 << sign_shift;
233 return sign_huff_offset;
240 unsigned int substr,
unsigned int pos)
253 int lsb_bits = cp->
huff_lsbs - quant_step_size;
264 result = (result << lsb_bits) +
get_bits(gbp, lsb_bits);
267 result *= 1 << quant_step_size;
308 "Channel group 2 cannot have more bits per sample than group 1.\n");
314 "Channel groups with differing sample rates are not currently supported.\n");
324 "Sampling rate %d is greater than the supported maximum (%d).\n",
330 "Block size %d is greater than the supported maximum (%d).\n",
336 "Block size pow2 %d is greater than the supported maximum (%d).\n",
349 "%d substreams (more than the "
350 "maximum supported by the decoder)",
388 "unexpected stream_type %X in MLP",
398 "unexpected stream_type %X in !MLP",
477 int min_channel, max_channel, max_matrix_channel;
484 if (sync_word != 0x31ea >> 1) {
486 "restart header sync incorrect (got 0x%04x)\n", sync_word);
501 max_matrix_channel =
get_bits(gbp, 4);
503 if (max_matrix_channel > std_max_matrix_channel) {
505 "Max matrix channel cannot be greater than %d.\n",
506 std_max_matrix_channel);
510 if (max_channel != max_matrix_channel) {
512 "Max channel must be equal max matrix channel.\n");
520 "%d channels (more than the "
521 "maximum supported by the decoder)",
526 if (min_channel > max_channel) {
528 "Substream min channel cannot be greater than max channel.\n");
539 "Extracting %d-channel downmix (0x%"PRIx64
") from substream %d. "
540 "Further substreams will be skipped.\n",
555 if (tmp != lossless_check)
557 "Lossless check failed - expected %02x, calculated %02x.\n",
558 lossless_check, tmp);
575 "Assignment of matrix channel %d to invalid output channel %d",
596 for (ch = s->
min_channel; ch <= s->max_channel; ch++) {
639 unsigned int substr,
unsigned int channel,
645 const char fchar = filter ?
'I' :
'F';
657 if (order > max_order) {
659 "%cIR filter order %d is greater than maximum %d.\n",
660 fchar, order, max_order);
667 int coeff_bits, coeff_shift;
673 if (coeff_bits < 1 || coeff_bits > 16) {
675 "%cIR filter coeff_bits must be between 1 and 16.\n",
679 if (coeff_bits + coeff_shift > 16) {
681 "Sum of coeff_bits and coeff_shift for %cIR filter must be 16 or less.\n",
686 for (i = 0; i < order; i++)
687 fcoeff[i] =
get_sbits(gbp, coeff_bits) * (1 << coeff_shift);
690 int state_bits, state_shift;
694 "FIR filter has state data specified.\n");
703 for (i = 0; i < order; i++)
704 fp->
state[i] = state_bits ?
get_sbits(gbp, state_bits) * (1 << state_shift) : 0;
716 unsigned int mat,
ch;
730 "Number of primitive matrices cannot be greater than %d.\n",
731 max_primitive_matrices);
736 int frac_bits, max_chan;
743 "Invalid channel %d specified as output from matrix.\n",
747 if (frac_bits > 14) {
749 "Too many fractional bits specified.\n");
757 for (ch = 0; ch <= max_chan; ch++) {
760 coeff_val =
get_sbits(gbp, frac_bits + 2);
808 "FIR and IIR filters must use the same precision.\n");
844 unsigned recompute_sho = 0;
886 recompute_sho |= 1<<
ch;
889 for (ch = s->
min_channel; ch <= s->max_channel; ch++)
891 recompute_sho |= 1<<
ch;
899 if (recompute_sho & (1<<ch)) {
916 #define MSB_MASK(bits) (-1u << (bits))
931 unsigned int filter_shift = fir->
shift;
952 unsigned int i,
ch, expected_stream_pos = 0;
957 expected_stream_pos +=
get_bits(gbp, 16);
959 "Substreams with VLC block size check info");
974 for (ch = s->
min_channel; ch <= s->max_channel; ch++)
991 30, 51, 22, 54, 3, 7, -4, 38, 14, 55, 46, 81, 22, 58, -3, 2,
992 52, 31, -7, 51, 15, 44, 74, 30, 85, -17, 10, 33, 18, 80, 28, 62,
993 10, 32, 23, 69, 72, 26, 35, 17, 73, 60, 8, 56, 2, 6, -2, -5,
994 51, 4, 11, 50, 66, 76, 21, 44, 33, 47, 1, 26, 64, 48, 57, 40,
995 38, 16, -10, -28, 92, 22, -18, 29, -10, 5, -13, 49, 19, 24, 70, 34,
996 61, 48, 30, 14, -6, 25, 58, 33, 42, 60, 67, 17, 54, 17, 22, 30,
997 67, 44, -9, 50, -11, 43, 40, 32, 59, 82, 13, 49, -14, 55, 60, 36,
998 48, 49, 31, 47, 15, 12, 4, 65, 1, 23, 29, 39, 45, -2, 84, 69,
999 0, 72, 37, 57, 27, 41, -15, -16, 35, 31, 14, 61, 24, 0, 27, 24,
1000 16, 41, 55, 34, 53, 9, 56, 12, 25, 29, 53, 5, 20, -20, -8, 20,
1001 13, 28, -3, 78, 38, 16, 11, 62, 46, 29, 21, 24, 46, 65, 43, -23,
1002 89, 18, 74, 21, 38, -12, 19, 12, -19, 8, 15, 33, 4, 57, 9, -8,
1003 36, 35, 26, 28, 7, 83, 63, 79, 75, 11, 3, 87, 37, 47, 34, 40,
1004 39, 19, 20, 42, 27, 34, 39, 77, 13, 42, 59, 64, 45, -1, 32, 37,
1005 45, -5, 53, -6, 7, 36, 50, 23, 6, 32, 9, -21, 18, 71, 27, 52,
1006 -25, 31, 35, 42, -1, 68, 63, 52, 26, 43, 66, 37, 41, 25, 40, 70,
1026 for (i = 0; i < s->
blockpos; i++) {
1027 uint16_t seed_shr7 = seed >> 7;
1031 seed = (seed << 16) ^ seed_shr7 ^ (seed_shr7 << 5);
1046 uint8_t seed_shr15 = seed >> 15;
1048 seed = (seed << 8) ^ seed_shr15 ^ (seed_shr15 << 5);
1062 unsigned int maxchan;
1128 int *got_frame_ptr,
AVPacket *avpkt)
1131 int buf_size = avpkt->
size;
1134 unsigned int length, substr;
1135 unsigned int substream_start;
1136 unsigned int header_size = 4;
1137 unsigned int substr_header_size = 0;
1146 length = (
AV_RB16(buf) & 0xfff) * 2;
1163 "Stream parameters not seen; skipping frame.\n");
1168 substream_start = 0;
1171 int extraword_present, checkdata_present,
end, nonrestart_substr;
1180 substr_header_size += 2;
1182 if (extraword_present) {
1188 substr_header_size += 2;
1191 if (length < header_size + substr_header_size) {
1201 if (end + header_size + substr_header_size > length) {
1203 "Indicated length of substream %d data goes off end of "
1204 "packet.\n", substr);
1205 end = length - header_size - substr_header_size;
1208 if (end < substream_start) {
1210 "Indicated end offset of substream %d data "
1211 "is smaller than calculated start offset.\n",
1219 substream_parity_present[substr] = checkdata_present;
1220 substream_data_len[substr] = end - substream_start;
1221 substream_start =
end;
1227 if ((((parity_bits >> 4) ^ parity_bits) & 0xF) != 0xF) {
1232 buf += header_size + substr_header_size;
1264 goto substream_length_mismatch;
1270 if (substream_data_len[substr] * 8 -
get_bits_count(&gb) >= 32) {
1286 if (substream_parity_present[substr]) {
1290 goto substream_length_mismatch;
1295 if ((
get_bits(&gb, 8) ^ parity) != 0xa9 )
1302 goto substream_length_mismatch;
1307 "No restart header present in substream %d.\n", substr);
1309 buf += substream_data_len[substr];
1317 substream_length_mismatch:
1326 #if CONFIG_MLP_DECODER
1338 #if CONFIG_TRUEHD_DECODER
uint8_t shift
Right shift to apply to output of filter.
static unsigned int show_bits_long(GetBitContext *s, int n)
Show 0-32 bits.
static uint64_t thd_channel_layout_extract_channel(uint64_t channel_layout, int index)
int major_sync_header_size
Size of the major sync unit, in bytes.
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
FilterParams filter_params[NUM_FILTERS]
This structure describes decoded (raw) audio or video data.
static av_cold int mlp_decode_init(AVCodecContext *avctx)
#define AV_CH_TOP_FRONT_RIGHT
void(* mlp_rematrix_channel)(int32_t *samples, const int32_t *coeffs, const uint8_t *bypassed_lsbs, const int8_t *noise_buffer, int index, unsigned int dest_ch, uint16_t blockpos, unsigned int maxchan, int matrix_noise_shift, int access_unit_size_pow2, int32_t mask)
int8_t noise_buffer[MAX_BLOCKSIZE_POW2]
ptrdiff_t const GLvoid * data
uint8_t param_presence_flags
Bitmask of which parameter sets are conveyed in a decoding parameter block.
uint8_t params_valid
Set if a valid major sync block has been read. Otherwise no decoding is possible. ...
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_LOG_WARNING
Something somehow does not look correct.
static av_cold int init(AVCodecContext *avctx)
#define INIT_VLC_STATIC(vlc, bits, a, b, c, d, e, f, g, static_size)
#define AV_CH_TOP_FRONT_LEFT
#define AV_CH_TOP_FRONT_CENTER
#define AV_CH_LOW_FREQUENCY_2
const uint8_t ff_mlp_huffman_tables[3][18][2]
Tables defining the Huffman codes.
#define MAX_BLOCKSIZE_POW2
next power of two greater than MAX_BLOCKSIZE
enum AVMatrixEncoding matrix_encoding
The matrix encoding mode for this substream.
static int read_restart_header(MLPDecodeContext *m, GetBitContext *gbp, const uint8_t *buf, unsigned int substr)
Read a restart header from a block in a substream.
#define MAX_SAMPLERATE
maximum sample frequency seen in files
int8_t output_shift[MAX_CHANNELS]
Left shift to apply to decoded PCM values to get final 24-bit output.
#define AV_CH_SURROUND_DIRECT_RIGHT
#define AV_CH_LAYOUT_STEREO
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_WL32 unsigned int_TMPL AV_WL24 unsigned int_TMPL AV_WL16 uint64_t_TMPL AV_WB64 unsigned int_TMPL AV_WB32 unsigned int_TMPL AV_WB24 unsigned int_TMPL AV_RB16
static int get_sbits(GetBitContext *s, int n)
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
int32_t matrix_coeff[MAX_MATRICES][MAX_CHANNELS]
Matrix coefficients, stored as 2.14 fixed point.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
void void avpriv_request_sample(void *avc, const char *msg,...) av_printf_format(2
Log a generic warning message about a missing feature.
enum AVSampleFormat sample_fmt
audio sample format
static uint8_t xor_32_to_8(uint32_t value)
XOR four bytes into one.
static av_cold int end(AVCodecContext *avctx)
#define MAX_FIR_ORDER
The maximum number of taps in IIR and FIR filters.
uint8_t pi<< 24) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_U8,(uint64_t)((*(constuint8_t *) pi-0x80U))<< 56) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0f/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_U8,(*(constuint8_t *) pi-0x80)*(1.0/(1<< 7))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S16,(*(constint16_t *) pi >>8)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S16,(uint64_t)(*(constint16_t *) pi)<< 48) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0f/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S16,*(constint16_t *) pi *(1.0/(1<< 15))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S32,(*(constint32_t *) pi >>24)+0x80) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_S32,(uint64_t)(*(constint32_t *) pi)<< 32) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0f/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S32,*(constint32_t *) pi *(1.0/(1U<< 31))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_S64,(*(constint64_t *) pi >>56)+0x80) CONV_FUNC(AV_SAMPLE_FMT_FLT, float, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0f/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_DBL, double, AV_SAMPLE_FMT_S64,*(constint64_t *) pi *(1.0/(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_FLT, av_clip_uint8(lrintf(*(constfloat *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_FLT, av_clip_int16(lrintf(*(constfloat *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_FLT, av_clipl_int32(llrintf(*(constfloat *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_FLT, llrintf(*(constfloat *) pi *(INT64_C(1)<< 63))) CONV_FUNC(AV_SAMPLE_FMT_U8, uint8_t, AV_SAMPLE_FMT_DBL, av_clip_uint8(lrint(*(constdouble *) pi *(1<< 7))+0x80)) CONV_FUNC(AV_SAMPLE_FMT_S16, int16_t, AV_SAMPLE_FMT_DBL, av_clip_int16(lrint(*(constdouble *) pi *(1<< 15)))) CONV_FUNC(AV_SAMPLE_FMT_S32, int32_t, AV_SAMPLE_FMT_DBL, av_clipl_int32(llrint(*(constdouble *) pi *(1U<< 31)))) CONV_FUNC(AV_SAMPLE_FMT_S64, int64_t, AV_SAMPLE_FMT_DBL, llrint(*(constdouble *) pi *(INT64_C(1)<< 63)))#defineFMT_PAIR_FUNC(out, in) staticconv_func_type *constfmt_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),};staticvoidcpy1(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, len);}staticvoidcpy2(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 2 *len);}staticvoidcpy4(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 4 *len);}staticvoidcpy8(uint8_t **dst, constuint8_t **src, intlen){memcpy(*dst,*src, 8 *len);}AudioConvert *swri_audio_convert_alloc(enumAVSampleFormatout_fmt, enumAVSampleFormatin_fmt, intchannels, constint *ch_map, intflags){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) returnNULL;ctx=av_mallocz(sizeof(*ctx));if(!ctx) returnNULL;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)){case1:ctx->simd_f=cpy1;break;case2:ctx->simd_f=cpy2;break;case4:ctx->simd_f=cpy4;break;case8: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);returnctx;}voidswri_audio_convert_free(AudioConvert **ctx){av_freep(ctx);}intswri_audio_convert(AudioConvert *ctx, AudioData *out, AudioData *in, intlen){intch;intoff=0;constintos=(out->planar?1:out->ch_count)*out->bps;unsignedmisaligned=0;av_assert0(ctx->channels==out->ch_count);if(ctx->in_simd_align_mask){intplanes=in->planar?in->ch_count:1;unsignedm=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){intplanes=out->planar?out->ch_count:1;unsignedm=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){intplanes=out->planar?out->ch_count:1;for(ch=0;ch< planes;ch++){ctx->simd_f(out-> ch ch
uint8_t ch_assign[MAX_CHANNELS]
For each channel output by the matrix, the output channel to map it to.
static void filter(int16_t *output, ptrdiff_t out_stride, int16_t *low, ptrdiff_t low_stride, int16_t *high, ptrdiff_t high_stride, int len, uint8_t clip)
#define AV_CH_LOW_FREQUENCY
Public header for CRC hash function implementation.
static void fill_noise_buffer(MLPDecodeContext *m, unsigned int substr)
Generate a block of noise, used when restart sync word == 0x31eb.
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
static int get_bits_count(const GetBitContext *s)
uint8_t restart_seen
Set if a valid restart header has been read. Otherwise the substream cannot be decoded.
bitstream reader API header.
static void generate_2_noise_channels(MLPDecodeContext *m, unsigned int substr)
Noise generation functions.
uint8_t min_channel
The index of the first channel coded in this substream.
static int read_filter_params(MLPDecodeContext *m, GetBitContext *gbp, unsigned int substr, unsigned int channel, unsigned int filter)
Read parameters for one of the prediction filters.
int16_t huff_offset
Offset to apply to residual values.
static int read_channel_params(MLPDecodeContext *m, unsigned int substr, GetBitContext *gbp, unsigned int ch)
Read channel parameters.
#define VLC_BITS
number of bits used for VLC lookup - longest Huffman code is 9
#define NUM_FILTERS
number of allowed filters
uint8_t max_channel
The index of the last channel coded in this substream.
uint8_t ff_mlp_calculate_parity(const uint8_t *buf, unsigned int buf_size)
XOR together all the bytes of a buffer.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
ChannelParams channel_params[MAX_CHANNELS]
Channel coding parameters for channels in the substream.
#define MAX_MATRIX_CHANNEL_TRUEHD
static const uint16_t mask[17]
uint8_t needs_reordering
Stream needs channel reordering to comply with FFmpeg's channel order.
int8_t bypassed_lsbs[MAX_BLOCKSIZE][MAX_CHANNELS]
static const struct endianess table[]
uint8_t quant_step_size[MAX_CHANNELS]
Left shift to apply to Huffman-decoded residuals.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static const uint64_t thd_channel_order[]
#define AV_CH_LAYOUT_QUAD
static int read_huff_channels(MLPDecodeContext *m, GetBitContext *gbp, unsigned int substr, unsigned int pos)
Read a sample, consisting of either, both or neither of entropy-coded MSBs and plain LSBs...
const char * name
Name of the codec implementation.
uint8_t num_substreams
Number of substreams contained within this stream.
static int read_access_unit(AVCodecContext *avctx, void *data, int *got_frame_ptr, AVPacket *avpkt)
Read an access unit from the stream.
uint8_t max_matrix_channel
The number of channels input into the rematrix stage.
uint64_t channel_layout
Audio channel layout.
common internal API header
static int read_matrix_params(MLPDecodeContext *m, unsigned int substr, GetBitContext *gbp)
Read parameters for primitive matrices.
static void filter_channel(MLPDecodeContext *m, unsigned int substr, unsigned int channel)
Generate PCM samples using the prediction filters and residual values read from the data stream...
audio channel layout utility functions
#define MAX_MATRIX_CHANNEL_MLP
Last possible matrix channel for each codec.
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 int output_data(MLPDecodeContext *m, unsigned int substr, AVFrame *frame, int *got_frame_ptr)
Write the audio data into the output buffer.
uint16_t noise_type
restart header data
static int read_major_sync(MLPDecodeContext *m, GetBitContext *gb)
Read a major sync info header - contains high level information about the stream - sample rate...
int32_t(*(* mlp_select_pack_output)(uint8_t *ch_assign, int8_t *output_shift, uint8_t max_matrix_channel, int is32))(int32_t
int32_t lossless_check_data
Running XOR of all output samples.
static int read_block_data(MLPDecodeContext *m, GetBitContext *gbp, unsigned int substr)
Read a block of PCM residual data (or actual if no filtering active).
static av_always_inline int get_vlc2(GetBitContext *s, VLC_TYPE(*table)[2], int bits, int max_depth)
Parse a vlc code.
#define AV_CH_FRONT_LEFT_OF_CENTER
static const int8_t noise_table[256]
Data table used for TrueHD noise generation function.
#define AV_CH_FRONT_CENTER
int filter_changed[MAX_CHANNELS][NUM_FILTERS]
uint8_t lsb_bypass[MAX_MATRICES]
Whether the LSBs of the matrix output are encoded in the bitstream.
int32_t coeff[NUM_FILTERS][MAX_FIR_ORDER]
static volatile int checksum
#define AV_CH_LAYOUT_5POINT1_BACK
static void error(const char *err)
int access_unit_size
number of PCM samples contained in each frame
#define FF_ARRAY_ELEMS(a)
#define AV_CH_FRONT_RIGHT_OF_CENTER
int ff_side_data_update_matrix_encoding(AVFrame *frame, enum AVMatrixEncoding matrix_encoding)
Add or update AV_FRAME_DATA_MATRIXENCODING side data.
#define AVERROR_PATCHWELCOME
Not yet implemented in FFmpeg, patches welcome.
int frame_size
Number of samples per channel in an audio frame.
#define AV_LOG_INFO
Standard information.
uint16_t blocksize
number of PCM samples in current audio block
uint8_t codebook
Which VLC codebook to use to read residuals.
#define MAX_MATRICES_TRUEHD
Libavcodec external API header.
uint8_t data_check_present
Set if the substream contains extra info to check the size of VLC blocks.
int32_t state[MAX_FIR_ORDER]
int sample_rate
samples per second
av_cold void ff_mlpdsp_init(MLPDSPContext *c)
SubStream substream[MAX_SUBSTREAMS]
uint8_t order
number of taps in filter
static int read_decoding_params(MLPDecodeContext *m, GetBitContext *gbp, unsigned int substr)
Read decoding parameters that change more often than those in the restart header. ...
main external API structure.
int is_major_sync_unit
Current access unit being read has a major sync.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int32_t sample_buffer[MAX_BLOCKSIZE][MAX_CHANNELS]
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits1(GetBitContext *s)
static void skip_bits(GetBitContext *s, int n)
uint64_t ch_layout
The channel layout for this substream.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
uint8_t num_primitive_matrices
matrix data
#define AV_CH_LAYOUT_5POINT0_BACK
uint8_t max_decoded_substream
Index of the last substream to decode - further substreams are skipped.
int av_get_channel_layout_channel_index(uint64_t channel_layout, uint64_t channel)
Get the index of a channel in channel_layout.
uint8_t huff_lsbs
Size of residual suffix not encoded using VLC.
static av_cold void init_static(void)
Initialize static data, constant between all invocations of the codec.
uint16_t blockpos
Number of PCM samples decoded so far in this frame.
#define AV_CH_BACK_CENTER
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
uint32_t noisegen_seed
The current seed value for the pseudorandom noise generator(s).
common internal api header.
uint8_t matrix_out_ch[MAX_MATRICES]
matrix output channel
int access_unit_size_pow2
next power of two above the number of samples in each frame
channel
Use these values when setting the channel map with ebur128_set_channel().
#define MAX_SUBSTREAMS
Maximum number of substreams that can be decoded.
static int32_t calculate_sign_huff(MLPDecodeContext *m, unsigned int substr, unsigned int ch)
int ff_mlp_read_major_sync(void *log, MLPHeaderInfo *mh, GetBitContext *gb)
Read a major sync info header - contains high level information about the stream - sample rate...
uint8_t matrix_noise_shift[MAX_MATRICES]
Left shift to apply to noise values in 0x31eb substreams.
uint8_t noise_shift
The left shift applied to random noise in 0x31ea substreams.
sample data coding information
int channels
number of audio channels
av_cold void ff_mlp_init_crc(void)
#define AV_CH_SURROUND_DIRECT_LEFT
void(* mlp_filter_channel)(int32_t *state, const int32_t *coeff, int firorder, int iirorder, unsigned int filter_shift, int32_t mask, int blocksize, int32_t *sample_buffer)
#define AV_CH_FRONT_RIGHT
#define MAX_MATRICES_MLP
Maximum number of matrices used in decoding; most streams have one matrix per output channel...
#define FFSWAP(type, a, b)
#define AV_CH_LAYOUT_MONO
uint64_t request_channel_layout
Request decoder to use this channel layout if it can (0 for default)
int32_t(* mlp_pack_output)(int32_t lossless_check_data, uint16_t blockpos, int32_t(*sample_buffer)[MAX_CHANNELS], void *data, uint8_t *ch_assign, int8_t *output_shift, uint8_t max_matrix_channel, int is32)
This structure stores compressed data.
int nb_samples
number of audio samples (per channel) described by this frame
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
int32_t sign_huff_offset
sign/rounding-corrected version of huff_offset
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...