Mercurial > libavcodec.hg
comparison ra144.c @ 6805:8faad14a40a5 libavcodec
Read the bitstream where the data is actually needed instead of doing it in unpack_input()
author | vitor |
---|---|
date | Thu, 15 May 2008 18:31:55 +0000 |
parents | 24a8b213ba4d |
children | e4be053e7d9b |
comparison
equal
deleted
inserted
replaced
6804:24a8b213ba4d | 6805:8faad14a40a5 |
---|---|
30 | 30 |
31 | 31 |
32 /* internal globals */ | 32 /* internal globals */ |
33 typedef struct { | 33 typedef struct { |
34 unsigned int resetflag, val, oldval; | 34 unsigned int resetflag, val, oldval; |
35 unsigned int unpacked[28]; /* buffer for unpacked input */ | |
36 unsigned int *iptr; /* pointer to current input (from unpacked) */ | |
37 unsigned int gval; | 35 unsigned int gval; |
38 unsigned short *gsp; | 36 unsigned short *gsp; |
39 unsigned int gbuf1[8]; | 37 unsigned int gbuf1[8]; |
40 unsigned short gbuf2[120]; | 38 unsigned short gbuf2[120]; |
41 signed short output_buffer[40]; | 39 signed short output_buffer[40]; |
123 a2[x] >>= 4; | 121 a2[x] >>= 4; |
124 } | 122 } |
125 | 123 |
126 | 124 |
127 /* do quarter-block output */ | 125 /* do quarter-block output */ |
128 static void do_output_subblock(Real144_internal *glob, unsigned int x) | 126 static void do_output_subblock(Real144_internal *glob, unsigned int x, GetBitContext *gb) |
129 { | 127 { |
130 int a, b, c, d, e, f, g; | 128 int e, f, g; |
129 int a = get_bits(gb, 7); | |
130 int d = get_bits(gb, 8); | |
131 int b = get_bits(gb, 7); | |
132 int c = get_bits(gb, 7); | |
131 | 133 |
132 if (x == 1) | 134 if (x == 1) |
133 memset(glob->buffer, 0, 20); | 135 memset(glob->buffer, 0, 20); |
134 | 136 |
135 if ((*glob->iptr) == 0) | 137 if (a) { |
136 a = 0; | 138 a += HALFBLOCK - 1; |
137 else | |
138 a = (*glob->iptr) + HALFBLOCK - 1; | |
139 | |
140 glob->iptr++; | |
141 b = *(glob->iptr++); | |
142 c = *(glob->iptr++); | |
143 d = *(glob->iptr++); | |
144 | |
145 if (a) | |
146 rotate_block(glob->buffer_2, glob->buffer_a, a); | 139 rotate_block(glob->buffer_2, glob->buffer_a, a); |
140 } | |
147 | 141 |
148 memcpy(glob->buffer_b, etable1 + b * BLOCKSIZE, BLOCKSIZE * 2); | 142 memcpy(glob->buffer_b, etable1 + b * BLOCKSIZE, BLOCKSIZE * 2); |
149 e = ((ftable1[b] >> 4) *glob->gval) >> 8; | 143 e = ((ftable1[b] >> 4) *glob->gval) >> 8; |
150 memcpy(glob->buffer_c, etable2 + c * BLOCKSIZE, BLOCKSIZE * 2); | 144 memcpy(glob->buffer_c, etable2 + c * BLOCKSIZE, BLOCKSIZE * 2); |
151 f=((ftable2[c] >> 4) *glob->gval) >> 8; | 145 f=((ftable2[c] >> 4) *glob->gval) >> 8; |
264 ptr[10] = x; | 258 ptr[10] = x; |
265 ptr++; | 259 ptr++; |
266 } | 260 } |
267 memcpy(out, ptr+10 - len, len * 2); | 261 memcpy(out, ptr+10 - len, len * 2); |
268 memcpy(statbuf, ptr, 20); | 262 memcpy(statbuf, ptr, 20); |
269 } | |
270 | |
271 /* Decode 20-byte input */ | |
272 static void unpack_input(const unsigned char *input, unsigned int *output) | |
273 { | |
274 int i; | |
275 static const uint8_t sizes[10] = {6, 5, 5, 4, 4, 3, 3, 3, 3, 2}; | |
276 | |
277 GetBitContext gb; | |
278 | |
279 init_get_bits(&gb, input, 20 * 8); | |
280 | |
281 for (i=0; i<10; i++) | |
282 output[i+1] = get_bits(&gb, sizes[i]); | |
283 | |
284 output[0] = get_bits(&gb, 5); | |
285 | |
286 output += 11; | |
287 for (i=0; i<4; i++) { | |
288 output[0] = get_bits(&gb, 7); | |
289 output[3] = get_bits(&gb, 8); | |
290 output[1] = get_bits(&gb, 7); | |
291 output[2] = get_bits(&gb, 7); | |
292 output += 4; | |
293 } | |
294 } | 263 } |
295 | 264 |
296 static unsigned int rms(int *data, int f) | 265 static unsigned int rms(int *data, int f) |
297 { | 266 { |
298 int *c; | 267 int *c; |
439 /* Uncompress one block (20 bytes -> 160*2 bytes) */ | 408 /* Uncompress one block (20 bytes -> 160*2 bytes) */ |
440 static int ra144_decode_frame(AVCodecContext * avctx, | 409 static int ra144_decode_frame(AVCodecContext * avctx, |
441 void *vdata, int *data_size, | 410 void *vdata, int *data_size, |
442 const uint8_t * buf, int buf_size) | 411 const uint8_t * buf, int buf_size) |
443 { | 412 { |
413 static const uint8_t sizes[10] = {6, 5, 5, 4, 4, 3, 3, 3, 3, 2}; | |
444 unsigned int a, b, c; | 414 unsigned int a, b, c; |
415 int i; | |
445 signed short *shptr; | 416 signed short *shptr; |
446 unsigned int *lptr; | |
447 const short **dptr; | |
448 int16_t *datao; | 417 int16_t *datao; |
449 int16_t *data = vdata; | 418 int16_t *data = vdata; |
450 Real144_internal *glob = avctx->priv_data; | 419 Real144_internal *glob = avctx->priv_data; |
420 GetBitContext gb; | |
451 | 421 |
452 if(buf_size == 0) | 422 if(buf_size == 0) |
453 return 0; | 423 return 0; |
454 | 424 |
455 datao = data; | 425 datao = data; |
456 unpack_input(buf, glob->unpacked); | 426 |
457 | 427 init_get_bits(&gb, buf, 20 * 8); |
458 glob->iptr = glob->unpacked; | 428 |
459 glob->val = decodeval[(*(glob->iptr++)) << 1]; | 429 for (i=0; i<10; i++) |
460 | 430 // "<< 1"? Doesn't this make one value out of two of the table useless? |
461 dptr = decodetable; | 431 glob->swapbuf1[i] = decodetable[i][get_bits(&gb, sizes[i]) << 1]; |
462 lptr = glob->swapbuf1; | |
463 | |
464 while (lptr<glob->swapbuf1 + 10) | |
465 *(lptr++) = (*(dptr++))[(*(glob->iptr++)) << 1]; | |
466 | 432 |
467 do_voice(glob->swapbuf1, glob->swapbuf2); | 433 do_voice(glob->swapbuf1, glob->swapbuf2); |
468 | 434 |
435 glob->val = decodeval[get_bits(&gb, 5) << 1]; // Useless table entries? | |
469 a = t_sqrt(glob->val*glob->oldval) >> 12; | 436 a = t_sqrt(glob->val*glob->oldval) >> 12; |
470 | 437 |
471 for (c=0; c < NBLOCKS; c++) { | 438 for (c=0; c < NBLOCKS; c++) { |
472 if (c == (NBLOCKS - 1)) { | 439 if (c == (NBLOCKS - 1)) { |
473 dec1(glob, glob->swapbuf1, glob->swapbuf2, 3, glob->val); | 440 dec1(glob, glob->swapbuf1, glob->swapbuf2, 3, glob->val); |
490 | 457 |
491 /* do output */ | 458 /* do output */ |
492 for (b=0, c=0; c<4; c++) { | 459 for (b=0, c=0; c<4; c++) { |
493 glob->gval = glob->gbuf1[c * 2]; | 460 glob->gval = glob->gbuf1[c * 2]; |
494 glob->gsp = glob->gbuf2 + b; | 461 glob->gsp = glob->gbuf2 + b; |
495 do_output_subblock(glob, glob->resetflag); | 462 do_output_subblock(glob, glob->resetflag, &gb); |
496 glob->resetflag = 0; | 463 glob->resetflag = 0; |
497 | 464 |
498 shptr = glob->output_buffer; | 465 shptr = glob->output_buffer; |
499 while (shptr < glob->output_buffer + BLOCKSIZE) | 466 while (shptr < glob->output_buffer + BLOCKSIZE) |
500 *data++ = av_clip_int16(*(shptr++) << 2); | 467 *data++ = av_clip_int16(*(shptr++) << 2); |