FFmpeg
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_internal.h"
22 #include "libavutil/tx.h"
23 
24 #include "avcodec.h"
25 #include "bytestream.h"
26 #include "codec_internal.h"
27 #include "decode.h"
28 #include "get_bits.h"
29 #include "hca_data.h"
30 
31 #define HCA_MASK 0x7f7f7f7f
32 #define MAX_CHANNELS 16
33 
34 typedef struct ChannelContext {
35  DECLARE_ALIGNED(32, float, base)[128];
36  DECLARE_ALIGNED(32, float, factors)[128];
37  DECLARE_ALIGNED(32, float, imdct_in)[128];
38  DECLARE_ALIGNED(32, float, imdct_out)[128];
39  DECLARE_ALIGNED(32, float, imdct_prev)[128];
40  int8_t scale_factors[128];
41  uint8_t scale[128];
42  int8_t intensity[8];
43  int8_t *hfr_scale;
44  unsigned count;
45  int chan_type;
47 
48 typedef struct HCAContext {
49  const AVCRC *crc_table;
50 
52 
53  uint8_t ath[128];
54  uint8_t cipher[256];
55  uint64_t key;
56  uint16_t subkey;
57 
58  int ath_type;
59  int ciph_type;
60  unsigned hfr_group_count;
61  uint8_t track_count;
62  uint8_t channel_config;
64  uint8_t base_band_count;
67 
68  // Set during init() and freed on close(). Untouched on init_flush()
72 } HCAContext;
73 
74 static void cipher_init56_create_table(uint8_t *r, uint8_t key)
75 {
76  const int mul = ((key & 1) << 3) | 5;
77  const int add = (key & 0xE) | 1;
78 
79  key >>= 4;
80  for (int i = 0; i < 16; i++) {
81  key = (key * mul + add) & 0xF;
82  r[i] = key;
83  }
84 }
85 
86 static void cipher_init56(uint8_t *cipher, uint64_t keycode)
87 {
88  uint8_t base[256], base_r[16], base_c[16], kc[8], seed[16];
89 
90  /* 56bit keycode encryption (given as a uint64_t number, but upper 8b aren't used) */
91  /* keycode = keycode - 1 */
92  if (keycode != 0)
93  keycode--;
94 
95  /* init keycode table */
96  for (int r = 0; r < (8-1); r++) {
97  kc[r] = keycode & 0xFF;
98  keycode = keycode >> 8;
99  }
100 
101  /* init seed table */
102  seed[ 0] = kc[1];
103  seed[ 1] = kc[1] ^ kc[6];
104  seed[ 2] = kc[2] ^ kc[3];
105  seed[ 3] = kc[2];
106  seed[ 4] = kc[2] ^ kc[1];
107  seed[ 5] = kc[3] ^ kc[4];
108  seed[ 6] = kc[3];
109  seed[ 7] = kc[3] ^ kc[2];
110  seed[ 8] = kc[4] ^ kc[5];
111  seed[ 9] = kc[4];
112  seed[10] = kc[4] ^ kc[3];
113  seed[11] = kc[5] ^ kc[6];
114  seed[12] = kc[5];
115  seed[13] = kc[5] ^ kc[4];
116  seed[14] = kc[6] ^ kc[1];
117  seed[15] = kc[6];
118 
119  /* init base table */
120  cipher_init56_create_table(base_r, kc[0]);
121  for (int r = 0; r < 16; r++) {
122  uint8_t nb;
124  nb = base_r[r] << 4;
125  for (int c = 0; c < 16; c++)
126  base[r*16 + c] = nb | base_c[c]; /* combine nibbles */
127  }
128 
129  /* final shuffle table */
130  {
131  unsigned x = 0;
132  unsigned pos = 1;
133 
134  for (int i = 0; i < 256; i++) {
135  x = (x + 17) & 0xFF;
136  if (base[x] != 0 && base[x] != 0xFF)
137  cipher[pos++] = base[x];
138  }
139  cipher[0] = 0;
140  cipher[0xFF] = 0xFF;
141  }
142 }
143 
144 static void cipher_init(uint8_t *cipher, int type, uint64_t keycode, uint16_t subkey)
145 {
146  switch (type) {
147  case 56:
148  if (keycode) {
149  if (subkey)
150  keycode = keycode * (((uint64_t)subkey<<16u)|((uint16_t)~subkey+2u));
151  cipher_init56(cipher, keycode);
152  }
153  break;
154  case 0:
155  for (int i = 0; i < 256; i++)
156  cipher[i] = i;
157  break;
158  }
159 }
160 
161 static void ath_init1(uint8_t *ath, int sample_rate)
162 {
163  unsigned int index;
164  unsigned int acc = 0;
165 
166  for (int i = 0; i < 128; i++) {
167  acc += sample_rate;
168  index = acc >> 13;
169 
170  if (index >= 654) {
171  memset(ath+i, 0xFF, (128 - i));
172  break;
173  }
174 
176  }
177 }
178 
179 static int ath_init(uint8_t *ath, int type, int sample_rate)
180 {
181  switch (type) {
182  case 0:
183  /* nothing to do */
184  break;
185  case 1:
187  break;
188  default:
189  return AVERROR_INVALIDDATA;
190  }
191 
192  return 0;
193 }
194 
195 static inline unsigned ceil2(unsigned a, unsigned b)
196 {
197  return (b > 0) ? (a / b + ((a % b) ? 1 : 0)) : 0;
198 }
199 
200 static av_cold void init_flush(AVCodecContext *avctx)
201 {
202  HCAContext *c = avctx->priv_data;
203 
204  memset(c, 0, offsetof(HCAContext, tx_fn));
205 }
206 
207 static int init_hca(AVCodecContext *avctx, const uint8_t *extradata,
208  const int extradata_size)
209 {
210  HCAContext *c = avctx->priv_data;
211  GetByteContext gb0, *const gb = &gb0;
212  int8_t r[16] = { 0 };
213  unsigned b, chunk;
214  int version, ret;
215  unsigned hfr_group_count;
216 
217  init_flush(avctx);
218 
219  if (extradata_size < 36)
220  return AVERROR_INVALIDDATA;
221 
222  bytestream2_init(gb, extradata, extradata_size);
223 
224  bytestream2_skipu(gb, 4);
225  version = bytestream2_get_be16(gb);
226  bytestream2_skipu(gb, 2);
227 
228  c->ath_type = version >= 0x200 ? 0 : 1;
229 
230  if ((bytestream2_get_be32u(gb) & HCA_MASK) != MKBETAG('f', 'm', 't', 0))
231  return AVERROR_INVALIDDATA;
232  bytestream2_skipu(gb, 4);
233  bytestream2_skipu(gb, 4);
234  bytestream2_skipu(gb, 4);
235 
236  chunk = bytestream2_get_be32u(gb) & HCA_MASK;
237  if (chunk == MKBETAG('c', 'o', 'm', 'p')) {
238  bytestream2_skipu(gb, 2);
239  bytestream2_skipu(gb, 1);
240  bytestream2_skipu(gb, 1);
241  c->track_count = bytestream2_get_byteu(gb);
242  c->channel_config = bytestream2_get_byteu(gb);
243  c->total_band_count = bytestream2_get_byteu(gb);
244  c->base_band_count = bytestream2_get_byteu(gb);
245  c->stereo_band_count = bytestream2_get_byte (gb);
246  c->bands_per_hfr_group = bytestream2_get_byte (gb);
247  } else if (chunk == MKBETAG('d', 'e', 'c', 0)) {
248  bytestream2_skipu(gb, 2);
249  bytestream2_skipu(gb, 1);
250  bytestream2_skipu(gb, 1);
251  c->total_band_count = bytestream2_get_byteu(gb) + 1;
252  c->base_band_count = bytestream2_get_byteu(gb) + 1;
253  c->track_count = bytestream2_peek_byteu(gb) >> 4;
254  c->channel_config = bytestream2_get_byteu(gb) & 0xF;
255  if (!bytestream2_get_byteu(gb))
256  c->base_band_count = c->total_band_count;
257  c->stereo_band_count = c->total_band_count - c->base_band_count;
258  c->bands_per_hfr_group = 0;
259  } else
260  return AVERROR_INVALIDDATA;
261 
262  if (c->total_band_count > FF_ARRAY_ELEMS(c->ch->imdct_in))
263  return AVERROR_INVALIDDATA;
264 
265  while (bytestream2_get_bytes_left(gb) >= 4) {
266  chunk = bytestream2_get_be32u(gb) & HCA_MASK;
267  if (chunk == MKBETAG('v', 'b', 'r', 0)) {
268  bytestream2_skip(gb, 2 + 2);
269  } else if (chunk == MKBETAG('a', 't', 'h', 0)) {
270  c->ath_type = bytestream2_get_be16(gb);
271  } else if (chunk == MKBETAG('r', 'v', 'a', 0)) {
272  bytestream2_skip(gb, 4);
273  } else if (chunk == MKBETAG('c', 'o', 'm', 'm')) {
274  bytestream2_skip(gb, bytestream2_get_byte(gb) * 8);
275  } else if (chunk == MKBETAG('c', 'i', 'p', 'h')) {
276  c->ciph_type = bytestream2_get_be16(gb);
277  } else if (chunk == MKBETAG('l', 'o', 'o', 'p')) {
278  bytestream2_skip(gb, 4 + 4 + 2 + 2);
279  } else if (chunk == MKBETAG('p', 'a', 'd', 0)) {
280  break;
281  } else {
282  break;
283  }
284  }
285 
286  if (bytestream2_get_bytes_left(gb) >= 10) {
288  c->key = bytestream2_get_be64u(gb);
289  c->subkey = bytestream2_get_be16u(gb);
290  }
291 
292  cipher_init(c->cipher, c->ciph_type, c->key, c->subkey);
293 
294  ret = ath_init(c->ath, c->ath_type, avctx->sample_rate);
295  if (ret < 0)
296  return ret;
297 
298  if (!c->track_count)
299  c->track_count = 1;
300 
301  b = avctx->ch_layout.nb_channels / c->track_count;
302  if (c->stereo_band_count && b > 1) {
303  int8_t *x = r;
304 
305  for (int i = 0; i < c->track_count; i++, x+=b) {
306  switch (b) {
307  case 2:
308  case 3:
309  x[0] = 1;
310  x[1] = 2;
311  break;
312  case 4:
313  x[0]=1; x[1] = 2;
314  if (c->channel_config == 0) {
315  x[2]=1;
316  x[3]=2;
317  }
318  break;
319  case 5:
320  x[0]=1; x[1] = 2;
321  if (c->channel_config <= 2) {
322  x[3]=1;
323  x[4]=2;
324  }
325  break;
326  case 6:
327  case 7:
328  x[0] = 1; x[1] = 2; x[4] = 1; x[5] = 2;
329  break;
330  case 8:
331  x[0] = 1; x[1] = 2; x[4] = 1; x[5] = 2; x[6] = 1; x[7] = 2;
332  break;
333  }
334  }
335  }
336 
337  if (c->total_band_count < c->base_band_count)
338  return AVERROR_INVALIDDATA;
339 
340  hfr_group_count = ceil2(c->total_band_count - (c->base_band_count + c->stereo_band_count),
341  c->bands_per_hfr_group);
342 
343  if (c->base_band_count + c->stereo_band_count + (uint64_t)hfr_group_count > 128ULL)
344  return AVERROR_INVALIDDATA;
345  c->hfr_group_count = hfr_group_count;
346 
347  for (int i = 0; i < avctx->ch_layout.nb_channels; i++) {
348  c->ch[i].chan_type = r[i];
349  c->ch[i].count = c->base_band_count + ((r[i] != 2) ? c->stereo_band_count : 0);
350  c->ch[i].hfr_scale = &c->ch[i].scale_factors[c->base_band_count + c->stereo_band_count];
351  if (c->ch[i].count > 128)
352  return AVERROR_INVALIDDATA;
353  }
354 
355  // Done last to signal init() finished
356  c->crc_table = av_crc_get_table(AV_CRC_16_ANSI);
357 
358  return 0;
359 }
360 
362 {
363  HCAContext *c = avctx->priv_data;
364  float scale = 1.f / 8.f;
365  int ret;
366 
368 
369  if (avctx->ch_layout.nb_channels <= 0 || avctx->ch_layout.nb_channels > FF_ARRAY_ELEMS(c->ch))
370  return AVERROR(EINVAL);
371 
373  if (!c->fdsp)
374  return AVERROR(ENOMEM);
375 
376  ret = av_tx_init(&c->tx_ctx, &c->tx_fn, AV_TX_FLOAT_MDCT, 1, 128, &scale, 0);
377  if (ret < 0)
378  return ret;
379 
380  if (avctx->extradata_size != 0 && avctx->extradata_size < 36)
381  return AVERROR_INVALIDDATA;
382 
383  if (!avctx->extradata_size)
384  return 0;
385 
386  return init_hca(avctx, avctx->extradata, avctx->extradata_size);
387 }
388 
389 static void run_imdct(HCAContext *c, ChannelContext *ch, int index, float *out)
390 {
391  c->tx_fn(c->tx_ctx, ch->imdct_out, ch->imdct_in, sizeof(float));
392 
393  c->fdsp->vector_fmul_window(out, ch->imdct_prev + (128 >> 1),
394  ch->imdct_out, window, 128 >> 1);
395 
396  memcpy(ch->imdct_prev, ch->imdct_out, 128 * sizeof(float));
397 }
398 
400  int index, unsigned band_count, unsigned base_band_count,
401  unsigned stereo_band_count)
402 {
403  float ratio_l = intensity_ratio_table[ch2->intensity[index]];
404  float ratio_r = ratio_l - 2.0f;
405  float *c1 = &ch1->imdct_in[base_band_count];
406  float *c2 = &ch2->imdct_in[base_band_count];
407 
408  if (ch1->chan_type != 1 || !stereo_band_count)
409  return;
410 
411  for (int i = 0; i < band_count; i++) {
412  c2[i] = c1[i] * ratio_r;
413  c1[i] *= ratio_l;
414  }
415 }
416 
418  unsigned hfr_group_count,
419  unsigned bands_per_hfr_group,
420  unsigned start_band, unsigned total_band_count)
421 {
422  if (ch->chan_type == 2 || !bands_per_hfr_group)
423  return;
424 
425  for (int i = 0, k = start_band, l = start_band - 1; i < hfr_group_count; i++){
426  for (int j = 0; j < bands_per_hfr_group && k < total_band_count && l >= 0; j++, k++, l--){
428  av_clip_intp2(ch->hfr_scale[i] - ch->scale_factors[l], 6) ] * ch->imdct_in[l];
429  }
430  }
431 
432  ch->imdct_in[127] = 0;
433 }
434 
436  GetBitContext *gb)
437 {
438  const float *base = ch->base;
439  float *factors = ch->factors;
440  float *out = ch->imdct_in;
441 
442  for (int i = 0; i < ch->count; i++) {
443  unsigned scale = ch->scale[i];
444  int nb_bits = max_bits_table[scale];
445  int value = get_bitsz(gb, nb_bits);
446  float factor;
447 
448  if (scale > 7) {
449  value = (1 - ((value & 1) << 1)) * (value >> 1);
450  if (!value)
451  skip_bits_long(gb, -1);
452  factor = value;
453  } else {
454  value += scale << 4;
455  skip_bits_long(gb, quant_spectrum_bits[value] - nb_bits);
457  }
458  factors[i] = factor;
459  }
460 
461  memset(factors + ch->count, 0, 512 - ch->count * sizeof(*factors));
462  c->fdsp->vector_fmul(out, factors, base, 128);
463 }
464 
465 static void unpack(HCAContext *c, ChannelContext *ch,
466  GetBitContext *gb,
467  unsigned hfr_group_count,
468  int packed_noise_level,
469  const uint8_t *ath)
470 {
471  int delta_bits = get_bits(gb, 3);
472 
473  if (delta_bits > 5) {
474  for (int i = 0; i < ch->count; i++)
475  ch->scale_factors[i] = get_bits(gb, 6);
476  } else if (delta_bits) {
477  int factor = get_bits(gb, 6);
478  int max_value = (1 << delta_bits) - 1;
479  int half_max = max_value >> 1;
480 
481  ch->scale_factors[0] = factor;
482  for (int i = 1; i < ch->count; i++){
483  int delta = get_bits(gb, delta_bits);
484 
485  if (delta == max_value) {
486  factor = get_bits(gb, 6);
487  } else {
488  factor += delta - half_max;
489  }
491 
492  ch->scale_factors[i] = factor;
493  }
494  } else {
495  memset(ch->scale_factors, 0, 128);
496  }
497 
498  if (ch->chan_type == 2){
499  ch->intensity[0] = get_bits(gb, 4);
500  if (ch->intensity[0] < 15) {
501  for (int i = 1; i < 8; i++)
502  ch->intensity[i] = get_bits(gb, 4);
503  }
504  } else {
505  for (int i = 0; i < hfr_group_count; i++)
506  ch->hfr_scale[i] = get_bits(gb, 6);
507  }
508 
509  for (int i = 0; i < ch->count; i++) {
510  int scale = ch->scale_factors[i];
511 
512  if (scale) {
513  scale = c->ath[i] + ((packed_noise_level + i) >> 8) - ((scale * 5) >> 1) + 2;
514  scale = scale_table[av_clip(scale, 0, 58)];
515  }
516  ch->scale[i] = scale;
517  }
518 
519  memset(ch->scale + ch->count, 0, sizeof(ch->scale) - ch->count);
520 
521  for (int i = 0; i < ch->count; i++)
523 }
524 
526  int *got_frame_ptr, AVPacket *avpkt)
527 {
528  HCAContext *c = avctx->priv_data;
529  int ch, offset = 0, ret, packed_noise_level;
530  GetBitContext gb0, *const gb = &gb0;
531  float **samples;
532 
533  if (avpkt->size <= 8)
534  return AVERROR_INVALIDDATA;
535 
536  if (AV_RN16(avpkt->data) != 0xFFFF) {
537  if ((AV_RL32(avpkt->data)) != MKTAG('H','C','A',0)) {
538  return AVERROR_INVALIDDATA;
539  } else if (AV_RB16(avpkt->data + 6) <= avpkt->size) {
540  ret = init_hca(avctx, avpkt->data, AV_RB16(avpkt->data + 6));
541  if (ret < 0) {
542  c->crc_table = NULL; // signal that init has not finished
543  return ret;
544  }
545  offset = AV_RB16(avpkt->data + 6);
546  if (offset == avpkt->size)
547  return avpkt->size;
548  } else {
549  return AVERROR_INVALIDDATA;
550  }
551  }
552 
553  if (!c->crc_table)
554  return AVERROR_INVALIDDATA;
555 
556  if (c->key || c->subkey) {
557  uint8_t *data, *cipher = c->cipher;
558 
559  if ((ret = av_packet_make_writable(avpkt)) < 0)
560  return ret;
561  data = avpkt->data;
562  for (int n = 0; n < avpkt->size; n++)
563  data[n] = cipher[data[n]];
564  }
565 
566  if (avctx->err_recognition & AV_EF_CRCCHECK) {
567  if (av_crc(c->crc_table, 0, avpkt->data + offset, avpkt->size - offset))
568  return AVERROR_INVALIDDATA;
569  }
570 
571  if ((ret = init_get_bits8(gb, avpkt->data + offset, avpkt->size - offset)) < 0)
572  return ret;
573 
574  if (get_bits(gb, 16) != 0xFFFF)
575  return AVERROR_INVALIDDATA;
576 
577  frame->nb_samples = 1024;
578  if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
579  return ret;
580  samples = (float **)frame->extended_data;
581 
582  packed_noise_level = (get_bits(gb, 9) << 8) - get_bits(gb, 7);
583 
584  for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++)
585  unpack(c, &c->ch[ch], gb, c->hfr_group_count, packed_noise_level, c->ath);
586 
587  for (int i = 0; i < 8; i++) {
588  for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++)
589  dequantize_coefficients(c, &c->ch[ch], gb);
590  for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++)
591  reconstruct_hfr(c, &c->ch[ch], c->hfr_group_count, c->bands_per_hfr_group,
592  c->stereo_band_count + c->base_band_count, c->total_band_count);
593  for (ch = 0; ch < avctx->ch_layout.nb_channels - 1; ch++)
594  apply_intensity_stereo(c, &c->ch[ch], &c->ch[ch+1], i,
595  c->total_band_count - c->base_band_count,
596  c->base_band_count, c->stereo_band_count);
597  for (ch = 0; ch < avctx->ch_layout.nb_channels; ch++)
598  run_imdct(c, &c->ch[ch], i, samples[ch] + i * 128);
599  }
600 
601  *got_frame_ptr = 1;
602 
603  return avpkt->size;
604 }
605 
607 {
608  HCAContext *c = avctx->priv_data;
609 
610  av_freep(&c->fdsp);
611  av_tx_uninit(&c->tx_ctx);
612 
613  return 0;
614 }
615 
617 {
618  HCAContext *c = avctx->priv_data;
619 
620  for (int ch = 0; ch < MAX_CHANNELS; ch++)
621  memset(c->ch[ch].imdct_prev, 0, sizeof(c->ch[ch].imdct_prev));
622 }
623 
625  .p.name = "hca",
626  CODEC_LONG_NAME("CRI HCA"),
627  .p.type = AVMEDIA_TYPE_AUDIO,
628  .p.id = AV_CODEC_ID_HCA,
629  .priv_data_size = sizeof(HCAContext),
630  .init = decode_init,
632  .flush = decode_flush,
633  .close = decode_close,
634  .p.capabilities = AV_CODEC_CAP_DR1,
635  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
636  .p.sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP,
638 };
AV_SAMPLE_FMT_FLTP
@ AV_SAMPLE_FMT_FLTP
float, planar
Definition: samplefmt.h:66
skip_bits_long
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
Definition: get_bits.h:278
ChannelContext::hfr_scale
int8_t * hfr_scale
Definition: hcadec.c:43
MAX_CHANNELS
#define MAX_CHANNELS
Definition: hcadec.c:32
av_clip
#define av_clip
Definition: common.h:96
FF_CODEC_CAP_INIT_CLEANUP
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: codec_internal.h:42
r
const char * r
Definition: vf_curves.c:126
acc
int acc
Definition: yuv2rgb.c:554
AVERROR
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
mem_internal.h
out
FILE * out
Definition: movenc.c:54
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1064
GetByteContext
Definition: bytestream.h:33
u
#define u(width, name, range_min, range_max)
Definition: cbs_h2645.c:250
AVCRC
uint32_t AVCRC
Definition: crc.h:46
av_clip_uintp2
#define av_clip_uintp2
Definition: common.h:120
AVTXContext
Definition: tx_priv.h:235
AVCodecContext::err_recognition
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:1412
bytestream2_skipu
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
Definition: bytestream.h:174
AV_RN16
#define AV_RN16(p)
Definition: intreadwrite.h:358
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
AVPacket::data
uint8_t * data
Definition: packet.h:491
b
#define b
Definition: input.c:41
data
const char data[16]
Definition: mxf.c:148
init_hca
static int init_hca(AVCodecContext *avctx, const uint8_t *extradata, const int extradata_size)
Definition: hcadec.c:207
HCAContext::ch
ChannelContext ch[MAX_CHANNELS]
Definition: hcadec.c:51
FFCodec
Definition: codec_internal.h:127
base
uint8_t base
Definition: vp3data.h:128
ChannelContext::imdct_prev
float imdct_prev[128]
Definition: hcadec.c:39
c1
static const uint64_t c1
Definition: murmur3.c:52
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:317
apply_intensity_stereo
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:399
sample_rate
sample_rate
Definition: ffmpeg_filter.c:368
HCAContext::key
uint64_t key
Definition: hcadec.c:55
av_tx_init
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:901
crc.h
cipher_init56
static void cipher_init56(uint8_t *cipher, uint64_t keycode)
Definition: hcadec.c:86
bytestream2_skip
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
Definition: bytestream.h:168
get_bits
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
Definition: get_bits.h:335
window
static SDL_Window * window
Definition: ffplay.c:360
FFCodec::p
AVCodec p
The public AVCodec.
Definition: codec_internal.h:131
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:2107
GetBitContext
Definition: get_bits.h:108
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:521
type
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 type
Definition: writing_filters.txt:86
scale
static av_always_inline float scale(float x, float s)
Definition: vf_v360.c:1389
HCA_MASK
#define HCA_MASK
Definition: hcadec.c:31
ChannelContext::base
float base[128]
Definition: hcadec.c:35
HCAContext::bands_per_hfr_group
uint8_t bands_per_hfr_group
Definition: hcadec.c:66
HCAContext::hfr_group_count
unsigned hfr_group_count
Definition: hcadec.c:60
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
av_cold
#define av_cold
Definition: attributes.h:90
init_get_bits8
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
Definition: get_bits.h:545
av_tx_fn
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
unpack
static void unpack(HCAContext *c, ChannelContext *ch, GetBitContext *gb, unsigned hfr_group_count, int packed_noise_level, const uint8_t *ath)
Definition: hcadec.c:465
ath_init1
static void ath_init1(uint8_t *ath, int sample_rate)
Definition: hcadec.c:161
AVCodecContext::extradata_size
int extradata_size
Definition: avcodec.h:543
AV_TX_FLOAT_MDCT
@ AV_TX_FLOAT_MDCT
Standard MDCT with a sample data type of float, double or int32_t, respecively.
Definition: tx.h:68
HCAContext::total_band_count
uint8_t total_band_count
Definition: hcadec.c:63
FF_CODEC_DECODE_CB
#define FF_CODEC_DECODE_CB(func)
Definition: codec_internal.h:306
HCAContext::tx_fn
av_tx_fn tx_fn
Definition: hcadec.c:69
s
#define s(width, name)
Definition: cbs_vp9.c:198
scale_conversion_table
static const float scale_conversion_table[]
Definition: hca_data.h:91
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
init
int(* init)(AVBSFContext *ctx)
Definition: dts2pts_bsf.c:365
quant_spectrum_bits
static const uint8_t quant_spectrum_bits[]
Definition: hca_data.h:29
decode.h
get_bits.h
decode_frame
static int decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
Definition: hcadec.c:525
HCAContext::ath_type
int ath_type
Definition: hcadec.c:58
key
const char * key
Definition: hwcontext_opencl.c:174
ath
static av_cold float ath(float f, float add)
Calculate ATH value for given frequency.
Definition: aacpsy.c:292
quant_spectrum_value
static const int8_t quant_spectrum_value[]
Definition: hca_data.h:41
CODEC_LONG_NAME
#define CODEC_LONG_NAME(str)
Definition: codec_internal.h:272
dequantize_coefficients
static void dequantize_coefficients(HCAContext *c, ChannelContext *ch, GetBitContext *gb)
Definition: hcadec.c:435
frame
static AVFrame * frame
Definition: demux_decode.c:54
AV_CRC_16_ANSI
@ AV_CRC_16_ANSI
Definition: crc.h:50
ChannelContext::chan_type
int chan_type
Definition: hcadec.c:45
HCAContext::ath
uint8_t ath[128]
Definition: hcadec.c:53
NULL
#define NULL
Definition: coverity.c:32
av_clip_intp2
#define av_clip_intp2
Definition: common.h:117
decode_init
static av_cold int decode_init(AVCodecContext *avctx)
Definition: hcadec.c:361
ChannelContext::imdct_out
float imdct_out[128]
Definition: hcadec.c:38
quant_step_size
static const float quant_step_size[]
Definition: hca_data.h:125
HCAContext::fdsp
AVFloatDSPContext * fdsp
Definition: hcadec.c:71
AV_EF_CRCCHECK
#define AV_EF_CRCCHECK
Verify checksums embedded in the bitstream (could be of either encoded or decoded data,...
Definition: defs.h:48
seed
static unsigned int seed
Definition: videogen.c:78
index
int index
Definition: gxfenc.c:89
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
bytestream2_get_bytes_left
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
Definition: bytestream.h:158
float_dsp.h
ath_init
static int ath_init(uint8_t *ath, int type, int sample_rate)
Definition: hcadec.c:179
ff_get_buffer
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
Definition: decode.c:1617
AV_CODEC_CAP_DR1
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition: codec.h:52
AVPacket::size
int size
Definition: packet.h:492
dequantizer_scaling_table
static const float dequantizer_scaling_table[]
Definition: hca_data.h:113
codec_internal.h
DECLARE_ALIGNED
#define DECLARE_ALIGNED(n, t, v)
Definition: mem_internal.h:87
HCAContext::stereo_band_count
uint8_t stereo_band_count
Definition: hcadec.c:65
scale_table
static const uint8_t scale_table[]
Definition: hca_data.h:53
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1080
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
ff_hca_decoder
const FFCodec ff_hca_decoder
Definition: hcadec.c:624
MKBETAG
#define MKBETAG(a, b, c, d)
Definition: macros.h:56
reconstruct_hfr
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:417
AVFloatDSPContext
Definition: float_dsp.h:24
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
av_crc_get_table
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
Definition: crc.c:374
offset
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
Definition: writing_filters.txt:86
version
version
Definition: libkvazaar.c:321
HCAContext::base_band_count
uint8_t base_band_count
Definition: hcadec.c:64
av_tx_uninit
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
Definition: tx.c:294
HCAContext::crc_table
const AVCRC * crc_table
Definition: hcadec.c:49
decode_close
static av_cold int decode_close(AVCodecContext *avctx)
Definition: hcadec.c:606
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:420
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
ChannelContext::scale
uint8_t scale[128]
Definition: hcadec.c:41
AVCodecContext::extradata
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:542
AVFrame::extended_data
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:401
hca_data.h
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
delta
float delta
Definition: vorbis_enc_data.h:430
value
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 default value
Definition: writing_filters.txt:86
ChannelContext::factors
float factors[128]
Definition: hcadec.c:36
ath_base_curve
static const uint8_t ath_base_curve[656]
Definition: hca_data.h:131
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
max_bits_table
static const uint8_t max_bits_table[]
Definition: hca_data.h:25
avcodec.h
ChannelContext::count
unsigned count
Definition: hcadec.c:44
HCAContext::track_count
uint8_t track_count
Definition: hcadec.c:61
ret
ret
Definition: filter_design.txt:187
HCAContext::subkey
uint16_t subkey
Definition: hcadec.c:56
ceil2
static unsigned ceil2(unsigned a, unsigned b)
Definition: hcadec.c:195
pos
unsigned int pos
Definition: spdifenc.c:413
HCAContext
Definition: hcadec.c:48
AV_RL32
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
Definition: bytestream.h:92
ChannelContext::intensity
int8_t intensity[8]
Definition: hcadec.c:42
AVCodecContext
main external API structure.
Definition: avcodec.h:441
c2
static const uint64_t c2
Definition: murmur3.c:53
cipher_init
static void cipher_init(uint8_t *cipher, int type, uint64_t keycode, uint16_t subkey)
Definition: hcadec.c:144
av_crc
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:392
av_packet_make_writable
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: avpacket.c:505
decode_flush
static av_cold void decode_flush(AVCodecContext *avctx)
Definition: hcadec.c:616
samples
Filter the word “frame” indicates either a video frame or a group of audio samples
Definition: filter_design.txt:8
ChannelContext::imdct_in
float imdct_in[128]
Definition: hcadec.c:37
ChannelContext
Definition: hcadec.c:34
ChannelContext::scale_factors
int8_t scale_factors[128]
Definition: hcadec.c:40
factor
static const int factor[16]
Definition: vf_pp7.c:78
cipher_init56_create_table
static void cipher_init56_create_table(uint8_t *r, uint8_t key)
Definition: hcadec.c:74
HCAContext::channel_config
uint8_t channel_config
Definition: hcadec.c:62
get_bitsz
static av_always_inline int get_bitsz(GetBitContext *s, int n)
Read 0-25 bits.
Definition: get_bits.h:351
AV_CODEC_FLAG_BITEXACT
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
Definition: avcodec.h:338
intensity_ratio_table
static const float intensity_ratio_table[]
Definition: hca_data.h:85
HCAContext::tx_ctx
AVTXContext * tx_ctx
Definition: hcadec.c:70
AVPacket
This structure stores compressed data.
Definition: packet.h:468
AVCodecContext::priv_data
void * priv_data
Definition: avcodec.h:468
HCAContext::cipher
uint8_t cipher[256]
Definition: hcadec.c:54
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
avpriv_float_dsp_alloc
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
Definition: float_dsp.c:135
bytestream.h
bytestream2_init
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
Definition: bytestream.h:137
AVERROR_INVALIDDATA
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:61
MKTAG
#define MKTAG(a, b, c, d)
Definition: macros.h:55
init_flush
static av_cold void init_flush(AVCodecContext *avctx)
Definition: hcadec.c:200
scale_conv_bias
static const int scale_conv_bias
Definition: hca_data.h:111
AV_CODEC_ID_HCA
@ AV_CODEC_ID_HCA
Definition: codec_id.h:535
run_imdct
static void run_imdct(HCAContext *c, ChannelContext *ch, int index, float *out)
Definition: hcadec.c:389
AV_RB16
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
Definition: bytestream.h:98
tx.h
HCAContext::ciph_type
int ciph_type
Definition: hcadec.c:59