FFmpeg: libavcodec/hcadec.c Source File
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
23
30
31 #define HCA_MASK 0x7f7f7f7f
32 #define MAX_CHANNELS 16
33
47
50
52
57
67
68 // Set during init() and freed on close(). Untouched on init_flush()
73
75 {
76 const int mul = ((
key & 1) << 3) | 5;
77 const int add = (
key & 0xE) | 1;
78
80 for (
int i = 0;
i < 16;
i++) {
81 key = (
key * mul + add) & 0xF;
83 }
84 }
85
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 */
103 seed[ 1] = kc[1] ^ kc[6];
104 seed[ 2] = kc[2] ^ kc[3];
106 seed[ 4] = kc[2] ^ kc[1];
107 seed[ 5] = kc[3] ^ kc[4];
109 seed[ 7] = kc[3] ^ kc[2];
110 seed[ 8] = kc[4] ^ kc[5];
112 seed[10] = kc[4] ^ kc[3];
113 seed[11] = kc[5] ^ kc[6];
115 seed[13] = kc[5] ^ kc[4];
116 seed[14] = kc[6] ^ kc[1];
118
119 /* init base table */
121 for (
int r = 0;
r < 16;
r++) {
122 uint8_t nb;
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;
133
134 for (
int i = 0;
i < 256;
i++) {
135 x = (x + 17) & 0xFF;
136 if (
base[x] != 0 &&
base[x] != 0xFF)
138 }
139 cipher[0] = 0;
140 cipher[0xFF] = 0xFF;
141 }
142 }
143
145 {
147 case 56:
148 if (keycode) {
149 if (subkey)
150 keycode = keycode * (((uint64_t)subkey<<16
u)|((uint16_t)~subkey+2
u));
152 }
153 break;
154 case 0:
155 for (
int i = 0;
i < 256;
i++)
157 break;
158 }
159 }
160
162 {
164 unsigned int acc = 0;
165
166 for (
int i = 0;
i < 128;
i++) {
169
171 memset(
ath+
i, 0xFF, (128 -
i));
172 break;
173 }
174
176 }
177 }
178
180 {
182 case 0:
183 /* nothing to do */
184 break;
185 case 1:
187 break;
188 default:
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
201 {
203
205 }
206
208 const int extradata_size)
209 {
212 int8_t
r[16] = { 0 };
215 unsigned hfr_group_count;
216
218
219 if (extradata_size < 36)
221
223
225 version = bytestream2_get_be16(gb);
227
228 c->ath_type =
version >= 0x200 ? 0 : 1;
229
230 if ((bytestream2_get_be32u(gb) &
HCA_MASK) !=
MKBETAG(
'f',
'm',
't', 0))
235
236 chunk = bytestream2_get_be32u(gb) &
HCA_MASK;
237 if (chunk ==
MKBETAG(
'c',
'o',
'm',
'p')) {
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)) {
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
261
264
266 chunk = bytestream2_get_be32u(gb) &
HCA_MASK;
267 if (chunk ==
MKBETAG(
'v',
'b',
'r', 0)) {
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)) {
273 }
else if (chunk ==
MKBETAG(
'c',
'o',
'm',
'm')) {
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')) {
279 }
else if (chunk ==
MKBETAG(
'p',
'a',
'd', 0)) {
280 break;
281 } else {
282 break;
283 }
284 }
285
288 c->key = bytestream2_get_be64u(gb);
289 c->subkey = bytestream2_get_be16u(gb);
290 }
291
293
297
300
302 if (
c->stereo_band_count &&
b > 1) {
304
305 for (
int i = 0;
i <
c->track_count;
i++, x+=
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)
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)
345 c->hfr_group_count = hfr_group_count;
346
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)
353 }
354
355 // Done last to signal init() finished
357
358 return 0;
359 }
360
362 {
364 float scale = 1.f / 8.f;
366
368
371
375
379
382
384 return 0;
385
387 }
388
390 {
392
395
397 }
398
400 int index,
unsigned band_count,
unsigned base_band_count,
401 unsigned stereo_band_count)
402 {
404 float ratio_r = ratio_l - 2.0f;
407
408 if (ch1->
chan_type != 1 || !stereo_band_count)
409 return;
410
411 for (
int i = 0;
i < band_count;
i++) {
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--){
429 }
430 }
431
433 }
434
437 {
441
442 for (
int i = 0;
i < ch->
count;
i++) {
447
453 } else {
457 }
459 }
460
461 memset(factors + ch->
count, 0, 512 - ch->
count *
sizeof(*factors));
462 c->fdsp->vector_fmul(
out, factors,
base, 128);
463 }
464
467 unsigned hfr_group_count,
468 int packed_noise_level,
470 {
472
473 if (delta_bits > 5) {
476 } else if (delta_bits) {
478 int max_value = (1 << delta_bits) - 1;
479 int half_max = max_value >> 1;
480
482 for (
int i = 1;
i < ch->
count;
i++){
484
485 if (
delta == max_value) {
487 } else {
489 }
491
493 }
494 } else {
496 }
497
501 for (
int i = 1;
i < 8;
i++)
503 }
504 } else {
505 for (
int i = 0;
i < hfr_group_count;
i++)
507 }
508
509 for (
int i = 0;
i < ch->
count;
i++) {
511
513 scale =
c->ath[
i] + ((packed_noise_level +
i) >> 8) - ((
scale * 5) >> 1) + 2;
515 }
517 }
518
520
523 }
524
526 int *got_frame_ptr,
AVPacket *avpkt)
527 {
529 int ch,
offset = 0,
ret, packed_noise_level;
532
533 if (avpkt->
size <= 8)
535
542 c->crc_table =
NULL;
// signal that init has not finished
544 }
548 } else {
550 }
551 }
552
555
556 if (
c->key ||
c->subkey) {
557 uint8_t *
data, *cipher =
c->cipher;
558
562 for (
int n = 0; n < avpkt->
size; n++)
564 }
565
569 }
570
573
576
581
583
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++) {
592 c->stereo_band_count +
c->base_band_count,
c->total_band_count);
595 c->total_band_count -
c->base_band_count,
596 c->base_band_count,
c->stereo_band_count);
599 }
600
601 *got_frame_ptr = 1;
602
604 }
605
607 {
609
612
613 return 0;
614 }
615
617 {
619
621 memset(
c->ch[ch].imdct_prev, 0,
sizeof(
c->ch[ch].imdct_prev));
622 }
623
638 };
@ AV_SAMPLE_FMT_FLTP
float, planar
static void skip_bits_long(GetBitContext *s, int n)
Skips the specified number of bits.
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
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
int sample_rate
samples per second
#define u(width, name, range_min, range_max)
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
static av_always_inline void bytestream2_skipu(GetByteContext *g, unsigned int size)
This structure describes decoded (raw) audio or video data.
static int init_hca(AVCodecContext *avctx, const uint8_t *extradata, const int extradata_size)
ChannelContext ch[MAX_CHANNELS]
int nb_channels
Number of channels in this layout.
static void apply_intensity_stereo(HCAContext *s, ChannelContext *ch1, ChannelContext *ch2, int index, unsigned band_count, unsigned base_band_count, unsigned stereo_band_count)
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...
static void cipher_init56(uint8_t *cipher, uint64_t keycode)
static av_always_inline void bytestream2_skip(GetByteContext *g, unsigned int size)
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
static SDL_Window * window
AVCodec p
The public AVCodec.
AVChannelLayout ch_layout
Audio channel layout.
int flags
AV_CODEC_FLAG_*.
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
uint8_t bands_per_hfr_group
#define FF_ARRAY_ELEMS(a)
static int init_get_bits8(GetBitContext *s, const uint8_t *buffer, int byte_size)
Initialize GetBitContext.
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
static void unpack(HCAContext *c, ChannelContext *ch, GetBitContext *gb, unsigned hfr_group_count, int packed_noise_level, const uint8_t *ath)
static void ath_init1(uint8_t *ath, int sample_rate)
@ AV_TX_FLOAT_MDCT
Standard MDCT with a sample data type of float, double or int32_t, respecively.
#define FF_CODEC_DECODE_CB(func)
static const float scale_conversion_table[]
static const uint8_t quant_spectrum_bits[]
static int decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt)
static av_cold float ath(float f, float add)
Calculate ATH value for given frequency.
static const int8_t quant_spectrum_value[]
#define CODEC_LONG_NAME(str)
static void dequantize_coefficients(HCAContext *c, ChannelContext *ch, GetBitContext *gb)
static av_cold int decode_init(AVCodecContext *avctx)
static const float quant_step_size[]
#define AV_EF_CRCCHECK
Verify checksums embedded in the bitstream (could be of either encoded or decoded data,...
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
static av_always_inline int bytestream2_get_bytes_left(GetByteContext *g)
static int ath_init(uint8_t *ath, int type, int sample_rate)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int(* init)(AVBSFContext *ctx)
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
static void scale(int *out, const int *in, const int w, const int h, const int shift)
static const float dequantizer_scaling_table[]
#define DECLARE_ALIGNED(n, t, v)
uint8_t stereo_band_count
static const uint8_t scale_table[]
enum AVSampleFormat sample_fmt
audio sample format
const FFCodec ff_hca_decoder
#define MKBETAG(a, b, c, d)
static void reconstruct_hfr(HCAContext *s, ChannelContext *ch, unsigned hfr_group_count, unsigned bands_per_hfr_group, unsigned start_band, unsigned total_band_count)
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
const AVCRC * av_crc_get_table(AVCRCId crc_id)
Get an initialized standard CRC table.
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
av_cold void av_tx_uninit(AVTXContext **ctx)
Frees a context and sets *ctx to NULL, does nothing when *ctx == NULL.
static av_cold int decode_close(AVCodecContext *avctx)
int nb_samples
number of audio samples (per channel) described by this frame
#define i(width, name, range_min, range_max)
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
uint8_t ** extended_data
pointers to the data planes/channels.
AVSampleFormat
Audio sample formats.
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
static const uint8_t ath_base_curve[656]
const char * name
Name of the codec implementation.
static const uint8_t max_bits_table[]
static unsigned ceil2(unsigned a, unsigned b)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
main external API structure.
static void cipher_init(uint8_t *cipher, int type, uint64_t keycode, uint16_t subkey)
uint32_t av_crc(const AVCRC *ctx, uint32_t crc, const uint8_t *buffer, size_t length)
Calculate the CRC of a block.
int av_packet_make_writable(AVPacket *pkt)
Create a writable reference for the data described by a given packet, avoiding data copy if possible.
static av_cold void decode_flush(AVCodecContext *avctx)
Filter the word "frame" indicates either a video frame or a group of audio samples
int8_t scale_factors[128]
static const int factor[16]
static void cipher_init56_create_table(uint8_t *r, uint8_t key)
static av_always_inline int get_bitsz(GetBitContext *s, int n)
Read 0-25 bits.
#define AV_CODEC_FLAG_BITEXACT
Use only bitexact stuff (except (I)DCT).
static const float intensity_ratio_table[]
This structure stores compressed data.
av_cold AVFloatDSPContext * avpriv_float_dsp_alloc(int bit_exact)
Allocate a float DSP context.
static av_always_inline void bytestream2_init(GetByteContext *g, const uint8_t *buf, int buf_size)
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
#define MKTAG(a, b, c, d)
static av_cold void init_flush(AVCodecContext *avctx)
static const int scale_conv_bias
static void run_imdct(HCAContext *c, ChannelContext *ch, int index, float *out)
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
Generated on Thu Sep 26 2024 23:14:59 for FFmpeg by
doxygen
1.8.17