FFmpeg
Loading...
Searching...
No Matches
hcadec.c
Go to the documentation of this file.
1/*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19#include "libavutil/crc.h"
20#include "libavutil/float_dsp.h"
21#include "libavutil/mem.h"
23#include "libavutil/tx.h"
24
25#include "avcodec.h"
26#include "bytestream.h"
27#include "codec_internal.h"
28#include "decode.h"
29#include "get_bits.h"
30#include "hca_data.h"
31
32#define HCA_MASK 0x7f7f7f7f
33#define MAX_CHANNELS 16
34
35typedef struct ChannelContext {
36 DECLARE_ALIGNED(32, float, base)[128];
37 DECLARE_ALIGNED(32, float, factors)[128];
38 DECLARE_ALIGNED(32, float, imdct_in)[128];
39 DECLARE_ALIGNED(32, float, imdct_out)[128];
40 DECLARE_ALIGNED(32, float, imdct_prev)[128];
41 int8_t scale_factors[128];
42 uint8_t scale[128];
43 int8_t intensity[8];
44 int8_t *hfr_scale;
45 unsigned count;
48
49typedef struct HCAContext {
51
53
54 uint8_t ath[128];
55 uint8_t cipher[256];
56 uint64_t key;
57 uint16_t subkey;
58
62 uint8_t track_count;
68
69 // Set during init() and freed on close(). Untouched on init_flush()
74
75static void cipher_init56_create_table(uint8_t *r, uint8_t key)
76{
77 const int mul = ((key & 1) << 3) | 5;
78 const int add = (key & 0xE) | 1;
79
80 key >>= 4;
81 for (int i = 0; i < 16; i++) {
82 key = (key * mul + add) & 0xF;
83 r[i] = key;
84 }
85}
86
87static void cipher_init56(uint8_t *cipher, uint64_t keycode)
88{
89 uint8_t base[256], base_r[16], base_c[16], kc[8], seed[16];
90
91 /* 56bit keycode encryption (given as a uint64_t number, but upper 8b aren't used) */
92 /* keycode = keycode - 1 */
93 if (keycode != 0)
94 keycode--;
95
96 /* init keycode table */
97 for (int r = 0; r < (8-1); r++) {
98 kc[r] = keycode & 0xFF;
99 keycode = keycode >> 8;
100 }
101
102 /* init seed table */
103 seed[ 0] = kc[1];
104 seed[ 1] = kc[1] ^ kc[6];
105 seed[ 2] = kc[2] ^ kc[3];
106 seed[ 3] = kc[2];
107 seed[ 4] = kc[2] ^ kc[1];
108 seed[ 5] = kc[3] ^ kc[4];
109 seed[ 6] = kc[3];
110 seed[ 7] = kc[3] ^ kc[2];
111 seed[ 8] = kc[4] ^ kc[5];
112 seed[ 9] = kc[4];
113 seed[10] = kc[4] ^ kc[3];
114 seed[11] = kc[5] ^ kc[6];
115 seed[12] = kc[5];
116 seed[13] = kc[5] ^ kc[4];
117 seed[14] = kc[6] ^ kc[1];
118 seed[15] = kc[6];
119
120 /* init base table */
121 cipher_init56_create_table(base_r, kc[0]);
122 for (int r = 0; r < 16; r++) {
123 uint8_t nb;
125 nb = base_r[r] << 4;
126 for (int c = 0; c < 16; c++)
127 base[r*16 + c] = nb | base_c[c]; /* combine nibbles */
128 }
129
130 /* final shuffle table */
131 {
132 unsigned x = 0;
133 unsigned pos = 1;
134
135 for (int i = 0; i < 256; i++) {
136 x = (x + 17) & 0xFF;
137 if (base[x] != 0 && base[x] != 0xFF)
138 cipher[pos++] = base[x];
139 }
140 cipher[0] = 0;
141 cipher[0xFF] = 0xFF;
142 }
143}
144
145static void cipher_init(uint8_t *cipher, int type, uint64_t keycode, uint16_t subkey)
146{
147 switch (type) {
148 case 56:
149 if (keycode) {
150 if (subkey)
151 keycode = keycode * (((uint64_t)subkey<<16u)|((uint16_t)~subkey+2u));
152 cipher_init56(cipher, keycode);
153 }
154 break;
155 case 0:
156 for (int i = 0; i < 256; i++)
157 cipher[i] = i;
158 break;
159 }
160}
161
162static void ath_init1(uint8_t *ath, int sample_rate)
163{
164 unsigned int index;
165 unsigned int acc = 0;
166
167 for (int i = 0; i < 128; i++) {
168 acc += sample_rate;
169 index = acc >> 13;
170
171 if (index >= 654) {
172 memset(ath+i, 0xFF, (128 - i));
173 break;
174 }
175
177 }
178}
179
180static int ath_init(uint8_t *ath, int type, int sample_rate)
181{
182 switch (type) {
183 case 0:
184 /* nothing to do */
185 break;
186 case 1:
187 ath_init1(ath, sample_rate);
188 break;
189 default:
190 return AVERROR_INVALIDDATA;
191 }
192
193 return 0;
194}
195
196static inline unsigned ceil2(unsigned a, unsigned b)
197{
198 return (b > 0) ? (a / b + ((a % b) ? 1 : 0)) : 0;
199}
200
202{
203 HCAContext *c = avctx->priv_data;
204
205 memset(c, 0, offsetof(HCAContext, tx_fn));
206}
207
208static int init_hca(AVCodecContext *avctx, const uint8_t *extradata,
209 const int extradata_size)
210{
211 HCAContext *c = avctx->priv_data;
212 GetByteContext gb0, *const gb = &gb0;
213 int8_t r[16] = { 0 };
214 unsigned b, chunk;
215 int version, ret;
216 unsigned hfr_group_count;
217
218 init_flush(avctx);
219
220 if (extradata_size < 36)
221 return AVERROR_INVALIDDATA;
222
223 bytestream2_init(gb, extradata, extradata_size);
224
225 bytestream2_skipu(gb, 4);
226 version = bytestream2_get_be16(gb);
227 bytestream2_skipu(gb, 2);
228
229 c->ath_type = version >= 0x200 ? 0 : 1;
230
231 if ((bytestream2_get_be32u(gb) & HCA_MASK) != MKBETAG('f', 'm', 't', 0))
232 return AVERROR_INVALIDDATA;
233 bytestream2_skipu(gb, 4);
234 bytestream2_skipu(gb, 4);
235 bytestream2_skipu(gb, 4);
236
237 chunk = bytestream2_get_be32u(gb) & HCA_MASK;
238 if (chunk == MKBETAG('c', 'o', 'm', 'p')) {
239 bytestream2_skipu(gb, 2);
240 bytestream2_skipu(gb, 1);
241 bytestream2_skipu(gb, 1);
242 c->track_count = bytestream2_get_byteu(gb);
243 c->channel_config = bytestream2_get_byteu(gb);
244 c->total_band_count = bytestream2_get_byteu(gb);
245 c->base_band_count = bytestream2_get_byteu(gb);
246 c->stereo_band_count = bytestream2_get_byte (gb);
247 c->bands_per_hfr_group = bytestream2_get_byte (gb);
248 bytestream2_skipu(gb, 2);
249 } else if (chunk == MKBETAG('d', 'e', 'c', 0)) {
250 bytestream2_skipu(gb, 2);
251 bytestream2_skipu(gb, 1);
252 bytestream2_skipu(gb, 1);
253 c->total_band_count = bytestream2_get_byteu(gb) + 1;
254 c->base_band_count = bytestream2_get_byteu(gb) + 1;
255 c->track_count = bytestream2_peek_byteu(gb) >> 4;
256 c->channel_config = bytestream2_get_byteu(gb) & 0xF;
257 if (!bytestream2_get_byteu(gb))
258 c->base_band_count = c->total_band_count;
259 c->stereo_band_count = c->total_band_count - c->base_band_count;
260 c->bands_per_hfr_group = 0;
261 } else
262 return AVERROR_INVALIDDATA;
263
264 if (c->total_band_count > FF_ARRAY_ELEMS(c->ch->imdct_in))
265 return AVERROR_INVALIDDATA;
266
267 while (bytestream2_get_bytes_left(gb) >= 4) {
268 chunk = bytestream2_get_be32u(gb) & HCA_MASK;
269 if (chunk == MKBETAG('v', 'b', 'r', 0)) {
270 bytestream2_skip(gb, 2 + 2);
271 } else if (chunk == MKBETAG('a', 't', 'h', 0)) {
272 c->ath_type = bytestream2_get_be16(gb);
273 } else if (chunk == MKBETAG('r', 'v', 'a', 0)) {
274 bytestream2_skip(gb, 4);
275 } else if (chunk == MKBETAG('c', 'o', 'm', 'm')) {
276 bytestream2_skip(gb, bytestream2_get_byte(gb) * 8);
277 } else if (chunk == MKBETAG('c', 'i', 'p', 'h')) {
278 c->ciph_type = bytestream2_get_be16(gb);
279 } else if (chunk == MKBETAG('l', 'o', 'o', 'p')) {
280 bytestream2_skip(gb, 4 + 4 + 2 + 2);
281 } else if (chunk == MKBETAG('p', 'a', 'd', 0)) {
282 break;
283 } else {
284 break;
285 }
286 }
287
288 if (bytestream2_get_bytes_left(gb) >= 10) {
290 c->key = bytestream2_get_be64u(gb);
291 c->subkey = bytestream2_get_be16u(gb);
292 }
293
294 cipher_init(c->cipher, c->ciph_type, c->key, c->subkey);
295
296 ret = ath_init(c->ath, c->ath_type, avctx->sample_rate);
297 if (ret < 0)
298 return ret;
299
300 if (!c->track_count)
301 c->track_count = 1;
302
303 b = avctx->ch_layout.nb_channels / c->track_count;
304 if (c->stereo_band_count && b > 1) {
305 int8_t *x = r;
306
307 for (int i = 0; i < c->track_count; i++, x+=b) {
308 switch (b) {
309 case 2:
310 case 3:
311 x[0] = 1;
312 x[1] = 2;
313 break;
314 case 4:
315 x[0]=1; x[1] = 2;
316 if (c->channel_config == 0) {
317 x[2]=1;
318 x[3]=2;
319 }
320 break;
321 case 5:
322 x[0]=1; x[1] = 2;
323 if (c->channel_config <= 2) {
324 x[3]=1;
325 x[4]=2;
326 }
327 break;
328 case 6:
329 case 7:
330 x[0] = 1; x[1] = 2; x[4] = 1; x[5] = 2;
331 break;
332 case 8:
333 x[0] = 1; x[1] = 2; x[4] = 1; x[5] = 2; x[6] = 1; x[7] = 2;
334 break;
335 }
336 }
337 }
338
339 if (c->total_band_count < c->base_band_count)
340 return AVERROR_INVALIDDATA;
341
342 hfr_group_count = ceil2(c->total_band_count - (c->base_band_count + c->stereo_band_count),
343 c->bands_per_hfr_group);
344
345 if (c->base_band_count + c->stereo_band_count + (uint64_t)hfr_group_count > 128ULL)
346 return AVERROR_INVALIDDATA;
347 c->hfr_group_count = hfr_group_count;
348
349 for (int i = 0; i < avctx->ch_layout.nb_channels; i++) {
350 c->ch[i].chan_type = r[i];
351 c->ch[i].count = c->base_band_count + ((r[i] != 2) ? c->stereo_band_count : 0);
352 c->ch[i].hfr_scale = &c->ch[i].scale_factors[c->base_band_count + c->stereo_band_count];
353 if (c->ch[i].count > 128)
354 return AVERROR_INVALIDDATA;
355 }
356
357 // Done last to signal init() finished
358 c->crc_table = av_crc_get_table(AV_CRC_16_ANSI);
359
360 return 0;
361}
362
364{
365 HCAContext *c = avctx->priv_data;
366 float scale = 1.f / 8.f;
367 int ret;
368
370
371 if (avctx->ch_layout.nb_channels <= 0 || avctx->ch_layout.nb_channels > FF_ARRAY_ELEMS(c->ch))
372 return AVERROR(EINVAL);
373
375 if (!c->fdsp)
376 return AVERROR(ENOMEM);
377
378 ret = av_tx_init(&c->tx_ctx, &c->tx_fn, AV_TX_FLOAT_MDCT, 1, 128, &scale, 0);
379 if (ret < 0)
380 return ret;
381
382 if (avctx->extradata_size != 0 && avctx->extradata_size < 36)
383 return AVERROR_INVALIDDATA;
384
385 if (!avctx->extradata_size)
386 return 0;
387
388 return init_hca(avctx, avctx->extradata, avctx->extradata_size);
389}
390
391static void run_imdct(HCAContext *c, ChannelContext *ch, int index, float *out)
392{
393 c->tx_fn(c->tx_ctx, ch->imdct_out, ch->imdct_in, sizeof(float));
394
395 c->fdsp->vector_fmul_window(out, ch->imdct_prev + (128 >> 1),
396 ch->imdct_out, window, 128 >> 1);
397
398 memcpy(ch->imdct_prev, ch->imdct_out, 128 * sizeof(float));
399}
400
402 int index, unsigned band_count, unsigned base_band_count,
403 unsigned stereo_band_count)
404{
405 float ratio_l = intensity_ratio_table[ch2->intensity[index]];
406 float ratio_r = ratio_l - 2.0f;
407 float *c1 = &ch1->imdct_in[base_band_count];
408 float *c2 = &ch2->imdct_in[base_band_count];
409
410 if (ch1->chan_type != 1 || !stereo_band_count)
411 return;
412
413 for (int i = 0; i < band_count; i++) {
414 c2[i] = c1[i] * ratio_r;
415 c1[i] *= ratio_l;
416 }
417}
418
420 unsigned hfr_group_count,
421 unsigned bands_per_hfr_group,
422 unsigned start_band, unsigned total_band_count)
423{
424 if (ch->chan_type == 2 || !bands_per_hfr_group)
425 return;
426
427 for (int i = 0, k = start_band, l = start_band - 1; i < hfr_group_count; i++){
428 for (int j = 0; j < bands_per_hfr_group && k < total_band_count && l >= 0; j++, k++, l--){
430 av_clip_intp2(ch->hfr_scale[i] - ch->scale_factors[l], 6) ] * ch->imdct_in[l];
431 }
432 }
433
434 ch->imdct_in[127] = 0;
435}
436
438 GetBitContext *gb)
439{
440 const float *base = ch->base;
441 float *factors = ch->factors;
442 float *out = ch->imdct_in;
443
444 for (int i = 0; i < ch->count; i++) {
445 unsigned scale = ch->scale[i];
446 int nb_bits = max_bits_table[scale];
447 int value = get_bitsz(gb, nb_bits);
448 float factor;
449
450 if (scale > 7) {
451 value = (1 - ((value & 1) << 1)) * (value >> 1);
452 if (!value)
453 skip_bits_long(gb, -1);
454 factor = value;
455 } else {
456 value += scale << 4;
459 }
460 factors[i] = factor;
461 }
462
463 memset(factors + ch->count, 0, 512 - ch->count * sizeof(*factors));
464 c->fdsp->vector_fmul(out, factors, base, 128);
465}
466
468 GetBitContext *gb,
469 unsigned hfr_group_count,
470 int packed_noise_level,
471 const uint8_t *ath)
472{
473 int delta_bits = get_bits(gb, 3);
474
475 if (delta_bits > 5) {
476 for (int i = 0; i < ch->count; i++)
477 ch->scale_factors[i] = get_bits(gb, 6);
478 } else if (delta_bits) {
479 int factor = get_bits(gb, 6);
480 int max_value = (1 << delta_bits) - 1;
481 int half_max = max_value >> 1;
482
483 ch->scale_factors[0] = factor;
484 for (int i = 1; i < ch->count; i++){
485 int delta = get_bits(gb, delta_bits);
486
487 if (delta == max_value) {
488 factor = get_bits(gb, 6);
489 } else {
490 factor += delta - half_max;
491 }
493
494 ch->scale_factors[i] = factor;
495 }
496 } else {
497 memset(ch->scale_factors, 0, 128);
498 }
499
500 if (ch->chan_type == 2){
501 ch->intensity[0] = get_bits(gb, 4);
502 if (ch->intensity[0] < 15) {
503 for (int i = 1; i < 8; i++)
504 ch->intensity[i] = get_bits(gb, 4);
505 }
506 } else {
507 for (int i = 0; i < hfr_group_count; i++)
508 ch->hfr_scale[i] = get_bits(gb, 6);
509 }
510
511 for (int i = 0; i < ch->count; i++) {
512 int scale = ch->scale_factors[i];
513
514 if (scale) {
515 scale = c->ath[i] + ((packed_noise_level + i) >> 8) - ((scale * 5) >> 1) + 2;
516 scale = scale_table[av_clip(scale, 0, 58)];
517 }
518 ch->scale[i] = scale;
519 }
520
521 memset(ch->scale + ch->count, 0, sizeof(ch->scale) - ch->count);
522
523 for (int i = 0; i < ch->count; i++)
525}
526
528 int *got_frame_ptr, AVPacket *avpkt)
529{
530 HCAContext *c = avctx->priv_data;
531 int ch, offset = 0, ret, packed_noise_level;
532 GetBitContext gb0, *const gb = &gb0;
533 float **samples;
534
535 if (avpkt->size <= 8)
536 return AVERROR_INVALIDDATA;
537
538 if (AV_RN16(avpkt->data) != 0xFFFF) {
539 if ((AV_RL32(avpkt->data)) != MKTAG('H','C','A',0)) {
540 return AVERROR_INVALIDDATA;
541 } else if (AV_RB16(avpkt->data + 6) <= avpkt->size) {
542 ret = init_hca(avctx, avpkt->data, AV_RB16(avpkt->data + 6));
543 if (ret < 0) {
544 c->crc_table = NULL; // signal that init has not finished
545 return ret;
546 }
547 offset = AV_RB16(avpkt->data + 6);
548 if (offset == avpkt->size)
549 return avpkt->size;
550 } else {
551 return AVERROR_INVALIDDATA;
552 }
553 }
554
555 if (!c->crc_table)
556 return AVERROR_INVALIDDATA;
557
558 if (c->key || c->subkey) {
559 uint8_t *data, *cipher = c->cipher;
560
561 if ((ret = av_packet_make_writable(avpkt)) < 0)
562 return ret;
563 data = avpkt->data;
564 for (int n = 0; n < avpkt->size; n++)
565 data[n] = cipher[data[n]];
566 }
567
568 if (avctx->err_recognition & AV_EF_CRCCHECK) {
569 if (av_crc(c->crc_table, 0, avpkt->data + offset, avpkt->size - offset))
570 return AVERROR_INVALIDDATA;
571 }
572
573 if ((ret = init_get_bits8(gb, avpkt->data + offset, avpkt->size - offset)) < 0)
574 return ret;
575
576 if (get_bits(gb, 16) != 0xFFFF)
577 return AVERROR_INVALIDDATA;
578
579 frame->nb_samples = 1024;
580 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
581 return ret;
582 samples = (float **)frame->extended_data;
583
584 packed_noise_level = (get_bits(gb, 9) << 8) - get_bits(gb, 7);
585
586 for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++)
587 unpack(c, &c->ch[ch], gb, c->hfr_group_count, packed_noise_level, c->ath);
588
589 for (int i = 0; i < 8; i++) {
590 for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++)
591 dequantize_coefficients(c, &c->ch[ch], gb);
592 for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++)
593 reconstruct_hfr(c, &c->ch[ch], c->hfr_group_count, c->bands_per_hfr_group,
594 c->stereo_band_count + c->base_band_count, c->total_band_count);
595 for (ch = 0; ch < avctx->ch_layout.nb_channels - 1; ch++)
596 apply_intensity_stereo(c, &c->ch[ch], &c->ch[ch+1], i,
597 c->total_band_count - c->base_band_count,
598 c->base_band_count, c->stereo_band_count);
599 for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++)
600 run_imdct(c, &c->ch[ch], i, samples[ch] + i * 128);
601 }
602
603 *got_frame_ptr = 1;
604
605 return avpkt->size;
606}
607
609{
610 HCAContext *c = avctx->priv_data;
611
612 av_freep(&c->fdsp);
613 av_tx_uninit(&c->tx_ctx);
614
615 return 0;
616}
617
619{
620 HCAContext *c = avctx->priv_data;
621
622 for (int ch = 0; ch < MAX_CHANNELS; ch++)
623 memset(c->ch[ch].imdct_prev, 0, sizeof(c->ch[ch].imdct_prev));
624}
625
627 .p.name = "hca",
628 CODEC_LONG_NAME("CRI HCA"),
629 .p.type = AVMEDIA_TYPE_AUDIO,
630 .p.id = AV_CODEC_ID_HCA,
631 .priv_data_size = sizeof(HCAContext),
632 .init = decode_init,
634 .flush = decode_flush,
635 .close = decode_close,
636 .p.capabilities = AV_CODEC_CAP_DR1,
637 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
638};
#define MAX_CHANNELS
Definition aac.h:33
static av_cold float ath(float f, float add)
Calculate ATH value for given frequency.
Definition aacpsy.c:320
static av_cold void decode_flush(AVCodecContext *avctx)
Definition agm.c:1253
const FFCodec ff_hca_decoder
Definition hcadec.c:626
Libavcodec external API header.
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
Definition bytestream.h:174
static av_always_inline int bytestream2_get_bytes_left(const GetByteContext *g)
Definition bytestream.h:158
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition bytestream.h:137
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition bytestream.h:168
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define s(width, name)
Definition cbs_vp9.c:198
#define FF_CODEC_DECODE_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define av_clip_intp2
Definition common.h:121
#define av_clip
Definition common.h:100
#define av_clip_uintp2
Definition common.h:124
#define NULL
Definition coverity.c:32
Public header for CRC hash function implementation.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition decode.c:1777
#define AV_EF_CRCCHECK
Verify checksums embedded in the bitstream (could be of either encoded or decoded data,...
Definition defs.h:48
static AVFrame * frame
int(* init)(AVBSFContext *ctx)
Definition dts2pts.c:608
double value
Definition eval.c:102
const char * key
static SDL_Window * window
Definition ffplay.c:365
bitstream reader API header.
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition get_bits.h:280
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition get_bits.h:544
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition get_bits.h:337
static av_always_inline int get_bitsz(GetBitContext *s, int n)
Read 0-25 bits.
Definition get_bits.h:353
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition avcodec.h:322
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
@ AV_CODEC_ID_HCA
Definition codec_id.h:546
int av_packet_make_writable(AVPacket *pkt)
Create a writable reference for the data described by a given packet, avoiding data copy if possible.
Definition packet.c:516
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
Definition crc.c:389
uint32_t AVCRC
Definition crc.h:46
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
Definition crc.c:421
@ AV_CRC_16_ANSI
Definition crc.h:50
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR(e)
Definition error.h:45
@ AVMEDIA_TYPE_AUDIO
Definition avutil.h:201
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition samplefmt.h:66
int index
Definition gxfenc.c:90
int a
static const int8_t quant_spectrum_value[]
Definition hca_data.h:41
static const float quant_step_size[]
Definition hca_data.h:125
static const uint8_t max_bits_table[]
Definition hca_data.h:25
static const int scale_conv_bias
Definition hca_data.h:111
static const uint8_t quant_spectrum_bits[]
Definition hca_data.h:29
static const float scale_conversion_table[]
Definition hca_data.h:91
static const uint8_t scale_table[]
Definition hca_data.h:53
static const uint8_t ath_base_curve[656]
Definition hca_data.h:131
static const float intensity_ratio_table[]
Definition hca_data.h:85
static const float dequantizer_scaling_table[]
Definition hca_data.h:113
static av_cold void decode_flush(AVCodecContext *avctx)
Definition hcadec.c:618
static void dequantize_coefficients(HCAContext *c, ChannelContext *ch, GetBitContext *gb)
Definition hcadec.c:437
static void unpack(HCAContext *c, ChannelContext *ch, GetBitContext *gb, unsigned hfr_group_count, int packed_noise_level, const uint8_t *ath)
Definition hcadec.c:467
static void ath_init1(uint8_t *ath, int sample_rate)
Definition hcadec.c:162
static int decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Definition hcadec.c:527
static void cipher_init56(uint8_t *cipher, uint64_t keycode)
Definition hcadec.c:87
static void cipher_init(uint8_t *cipher, int type, uint64_t keycode, uint16_t subkey)
Definition hcadec.c:145
static void run_imdct(HCAContext *c, ChannelContext *ch, int index, float *out)
Definition hcadec.c:391
static av_cold int decode_close(AVCodecContext *avctx)
Definition hcadec.c:608
static av_cold int decode_init(AVCodecContext *avctx)
Definition hcadec.c:363
static av_cold void init_flush(AVCodecContext *avctx)
Definition hcadec.c:201
static unsigned ceil2(unsigned a, unsigned b)
Definition hcadec.c:196
static void cipher_init56_create_table(uint8_t *r, uint8_t key)
Definition hcadec.c:75
#define HCA_MASK
Definition hcadec.c:32
#define MAX_CHANNELS
Definition hcadec.c:33
static void apply_intensity_stereo(HCAContext *s, ChannelContext *ch1, ChannelContext *ch2, int index, unsigned band_count, unsigned base_band_count, unsigned stereo_band_count)
Definition hcadec.c:401
static int ath_init(uint8_t *ath, int type, int sample_rate)
Definition hcadec.c:180
static int init_hca(AVCodecContext *avctx, const uint8_t *extradata, const int extradata_size)
Definition hcadec.c:208
static void reconstruct_hfr(HCAContext *s, ChannelContext *ch, unsigned hfr_group_count, unsigned bands_per_hfr_group, unsigned start_band, unsigned total_band_count)
Definition hcadec.c:419
cl_device_type type
#define r
Definition input.c:42
#define b
Definition input.c:43
static void scale(int *out, const int *in, const int w, const int h, const int shift)
Definition intra.c:278
#define AV_RL32(p)
#define AV_RN16(p)
#define AV_RB16(p)
unsigned offset
Definition libaomenc.c:763
static av_cold int decode_init(AVCodecContext *avctx)
Definition 4xm.c:998
static int decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_frame, AVPacket *avpkt)
Definition 4xm.c:837
static av_cold int decode_close(AVCodecContext *avctx)
Definition aacdec.c:1220
static const int factor[16]
Definition vf_pp7.c:98
#define av_cold
Definition attributes.h:117
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
Definition float_dsp.c:135
version
Definition libkvazaar.c:313
#define MKTAG(a, b, c, d)
Definition macros.h:55
#define MKBETAG(a, b, c, d)
Definition macros.h:56
Memory handling functions.
#define DECLARE_ALIGNED(n, t, v)
Declare a variable that is aligned in memory.
static const uint64_t c2
Definition murmur3.c:53
static const uint64_t c1
Definition murmur3.c:52
const char data[16]
Definition mxf.c:149
#define FF_ARRAY_ELEMS(a)
unsigned int pos
Definition spdifenc.c:431
int nb_channels
Number of channels in this layout.
main external API structure.
Definition avcodec.h:443
AVChannelLayout ch_layout
Audio channel layout.
Definition avcodec.h:1055
enum AVSampleFormat sample_fmt
audio sample format
Definition avcodec.h:1047
int sample_rate
samples per second
Definition avcodec.h:1040
int flags
AV_CODEC_FLAG_*.
Definition avcodec.h:500
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
Definition avcodec.h:526
int extradata_size
Definition avcodec.h:527
void * priv_data
Definition avcodec.h:470
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition avcodec.h:1416
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
This structure stores compressed data.
Definition packet.h:580
int size
Definition packet.h:604
uint8_t * data
Definition packet.h:603
int chan_type
Definition hcadec.c:46
float factors[128]
Definition hcadec.c:37
int8_t scale_factors[128]
Definition hcadec.c:41
int8_t intensity[8]
Definition hcadec.c:43
float base[128]
Definition hcadec.c:36
uint8_t scale[128]
Definition hcadec.c:42
int8_t * hfr_scale
Definition hcadec.c:44
float imdct_prev[128]
Definition hcadec.c:40
float imdct_out[128]
Definition hcadec.c:39
unsigned count
Definition hcadec.c:45
float imdct_in[128]
Definition hcadec.c:38
AVTXContext * tx_ctx
Definition hcadec.c:71
int ciph_type
Definition hcadec.c:60
uint8_t total_band_count
Definition hcadec.c:64
uint8_t channel_config
Definition hcadec.c:63
unsigned hfr_group_count
Definition hcadec.c:61
uint8_t base_band_count
Definition hcadec.c:65
AVFloatDSPContext * fdsp
Definition hcadec.c:72
ChannelContext ch[MAX_CHANNELS]
Definition hcadec.c:52
uint8_t ath[128]
Definition hcadec.c:54
uint8_t bands_per_hfr_group
Definition hcadec.c:67
uint8_t stereo_band_count
Definition hcadec.c:66
uint8_t track_count
Definition hcadec.c:62
uint8_t cipher[256]
Definition hcadec.c:55
const AVCRC * crc_table
Definition hcadec.c:50
int ath_type
Definition hcadec.c:59
uint64_t key
Definition hcadec.c:56
uint16_t subkey
Definition hcadec.c:57
av_tx_fn tx_fn
Definition hcadec.c:70
#define av_freep(p)
static FILE * out
Definition movenc.c:55
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
Definition tx.c:295
av_cold int av_tx_init(AVTXContext **ctx, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags)
Initialize a transform context with the given configuration (i)MDCTs with an odd length are currently...
Definition tx.c:903
@ AV_TX_FLOAT_MDCT
Standard MDCT with a sample data type of float, double or int32_t, respectively.
Definition tx.h:68
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
Definition tx.h:151
static unsigned int seed
Definition videogen.c:78
float delta
uint8_t base
Definition vp3data.h:128
static double c[64]