00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00027
00028
00029
00030
00031 #include <stdio.h>
00032 #include <stdlib.h>
00033
00034 #include "avcodec.h"
00035 #include "libavutil/audioconvert.h"
00036
00037 #define ALT_BITSTREAM_READER_LE
00038 #include "get_bits.h"
00039 #include "bytestream.h"
00040
00041 #define SMKTREE_BITS 9
00042 #define SMK_NODE 0x80000000
00043
00044
00045
00046
00047 typedef struct SmackVContext {
00048 AVCodecContext *avctx;
00049 AVFrame pic;
00050
00051 int *mmap_tbl, *mclr_tbl, *full_tbl, *type_tbl;
00052 int mmap_last[3], mclr_last[3], full_last[3], type_last[3];
00053 } SmackVContext;
00054
00058 typedef struct HuffContext {
00059 int length;
00060 int maxlength;
00061 int current;
00062 uint32_t *bits;
00063 int *lengths;
00064 int *values;
00065 } HuffContext;
00066
00067
00068 typedef struct DBCtx {
00069 VLC *v1, *v2;
00070 int *recode1, *recode2;
00071 int escapes[3];
00072 int *last;
00073 int lcur;
00074 } DBCtx;
00075
00076
00077 static const int block_runs[64] = {
00078 1, 2, 3, 4, 5, 6, 7, 8,
00079 9, 10, 11, 12, 13, 14, 15, 16,
00080 17, 18, 19, 20, 21, 22, 23, 24,
00081 25, 26, 27, 28, 29, 30, 31, 32,
00082 33, 34, 35, 36, 37, 38, 39, 40,
00083 41, 42, 43, 44, 45, 46, 47, 48,
00084 49, 50, 51, 52, 53, 54, 55, 56,
00085 57, 58, 59, 128, 256, 512, 1024, 2048 };
00086
00087 enum SmkBlockTypes {
00088 SMK_BLK_MONO = 0,
00089 SMK_BLK_FULL = 1,
00090 SMK_BLK_SKIP = 2,
00091 SMK_BLK_FILL = 3 };
00092
00096 static int smacker_decode_tree(GetBitContext *gb, HuffContext *hc, uint32_t prefix, int length)
00097 {
00098 if(!get_bits1(gb)){
00099 if(hc->current >= 256){
00100 av_log(NULL, AV_LOG_ERROR, "Tree size exceeded!\n");
00101 return -1;
00102 }
00103 if(length){
00104 hc->bits[hc->current] = prefix;
00105 hc->lengths[hc->current] = length;
00106 } else {
00107 hc->bits[hc->current] = 0;
00108 hc->lengths[hc->current] = 0;
00109 }
00110 hc->values[hc->current] = get_bits(gb, 8);
00111 hc->current++;
00112 if(hc->maxlength < length)
00113 hc->maxlength = length;
00114 return 0;
00115 } else {
00116 int r;
00117 length++;
00118 r = smacker_decode_tree(gb, hc, prefix, length);
00119 if(r)
00120 return r;
00121 return smacker_decode_tree(gb, hc, prefix | (1 << (length - 1)), length);
00122 }
00123 }
00124
00128 static int smacker_decode_bigtree(GetBitContext *gb, HuffContext *hc, DBCtx *ctx)
00129 {
00130 if (hc->current + 1 >= hc->length) {
00131 av_log(NULL, AV_LOG_ERROR, "Tree size exceeded!\n");
00132 return -1;
00133 }
00134 if(!get_bits1(gb)){
00135 int val, i1, i2, b1, b2;
00136 b1 = get_bits_count(gb);
00137 i1 = ctx->v1->table ? get_vlc2(gb, ctx->v1->table, SMKTREE_BITS, 3) : 0;
00138 b1 = get_bits_count(gb) - b1;
00139 b2 = get_bits_count(gb);
00140 i2 = ctx->v2->table ? get_vlc2(gb, ctx->v2->table, SMKTREE_BITS, 3) : 0;
00141 b2 = get_bits_count(gb) - b2;
00142 if (i1 < 0 || i2 < 0)
00143 return -1;
00144 val = ctx->recode1[i1] | (ctx->recode2[i2] << 8);
00145 if(val == ctx->escapes[0]) {
00146 ctx->last[0] = hc->current;
00147 val = 0;
00148 } else if(val == ctx->escapes[1]) {
00149 ctx->last[1] = hc->current;
00150 val = 0;
00151 } else if(val == ctx->escapes[2]) {
00152 ctx->last[2] = hc->current;
00153 val = 0;
00154 }
00155
00156 hc->values[hc->current++] = val;
00157 return 1;
00158 } else {
00159 int r = 0, r_new, t;
00160
00161 t = hc->current++;
00162 r = smacker_decode_bigtree(gb, hc, ctx);
00163 if(r < 0)
00164 return r;
00165 hc->values[t] = SMK_NODE | r;
00166 r++;
00167 r_new = smacker_decode_bigtree(gb, hc, ctx);
00168 if (r_new < 0)
00169 return r_new;
00170 return r + r_new;
00171 }
00172 }
00173
00177 static int smacker_decode_header_tree(SmackVContext *smk, GetBitContext *gb, int **recodes, int *last, int size)
00178 {
00179 int res;
00180 HuffContext huff;
00181 HuffContext tmp1, tmp2;
00182 VLC vlc[2];
00183 int escapes[3];
00184 DBCtx ctx;
00185 int err = 0;
00186
00187 if(size >= UINT_MAX>>4){
00188 av_log(smk->avctx, AV_LOG_ERROR, "size too large\n");
00189 return -1;
00190 }
00191
00192 tmp1.length = 256;
00193 tmp1.maxlength = 0;
00194 tmp1.current = 0;
00195 tmp1.bits = av_mallocz(256 * 4);
00196 tmp1.lengths = av_mallocz(256 * sizeof(int));
00197 tmp1.values = av_mallocz(256 * sizeof(int));
00198
00199 tmp2.length = 256;
00200 tmp2.maxlength = 0;
00201 tmp2.current = 0;
00202 tmp2.bits = av_mallocz(256 * 4);
00203 tmp2.lengths = av_mallocz(256 * sizeof(int));
00204 tmp2.values = av_mallocz(256 * sizeof(int));
00205
00206 memset(&vlc[0], 0, sizeof(VLC));
00207 memset(&vlc[1], 0, sizeof(VLC));
00208
00209 if(get_bits1(gb)) {
00210 smacker_decode_tree(gb, &tmp1, 0, 0);
00211 skip_bits1(gb);
00212 res = init_vlc(&vlc[0], SMKTREE_BITS, tmp1.length,
00213 tmp1.lengths, sizeof(int), sizeof(int),
00214 tmp1.bits, sizeof(uint32_t), sizeof(uint32_t), INIT_VLC_LE);
00215 if(res < 0) {
00216 av_log(smk->avctx, AV_LOG_ERROR, "Cannot build VLC table\n");
00217 return -1;
00218 }
00219 } else {
00220 av_log(smk->avctx, AV_LOG_ERROR, "Skipping low bytes tree\n");
00221 }
00222 if(get_bits1(gb)){
00223 smacker_decode_tree(gb, &tmp2, 0, 0);
00224 skip_bits1(gb);
00225 res = init_vlc(&vlc[1], SMKTREE_BITS, tmp2.length,
00226 tmp2.lengths, sizeof(int), sizeof(int),
00227 tmp2.bits, sizeof(uint32_t), sizeof(uint32_t), INIT_VLC_LE);
00228 if(res < 0) {
00229 av_log(smk->avctx, AV_LOG_ERROR, "Cannot build VLC table\n");
00230 return -1;
00231 }
00232 } else {
00233 av_log(smk->avctx, AV_LOG_ERROR, "Skipping high bytes tree\n");
00234 }
00235
00236 escapes[0] = get_bits(gb, 8);
00237 escapes[0] |= get_bits(gb, 8) << 8;
00238 escapes[1] = get_bits(gb, 8);
00239 escapes[1] |= get_bits(gb, 8) << 8;
00240 escapes[2] = get_bits(gb, 8);
00241 escapes[2] |= get_bits(gb, 8) << 8;
00242
00243 last[0] = last[1] = last[2] = -1;
00244
00245 ctx.escapes[0] = escapes[0];
00246 ctx.escapes[1] = escapes[1];
00247 ctx.escapes[2] = escapes[2];
00248 ctx.v1 = &vlc[0];
00249 ctx.v2 = &vlc[1];
00250 ctx.recode1 = tmp1.values;
00251 ctx.recode2 = tmp2.values;
00252 ctx.last = last;
00253
00254 huff.length = ((size + 3) >> 2) + 3;
00255 huff.maxlength = 0;
00256 huff.current = 0;
00257 huff.values = av_mallocz(huff.length * sizeof(int));
00258
00259 if (smacker_decode_bigtree(gb, &huff, &ctx) < 0)
00260 err = -1;
00261 skip_bits1(gb);
00262 if(ctx.last[0] == -1) ctx.last[0] = huff.current++;
00263 if(ctx.last[1] == -1) ctx.last[1] = huff.current++;
00264 if(ctx.last[2] == -1) ctx.last[2] = huff.current++;
00265
00266 *recodes = huff.values;
00267
00268 if(vlc[0].table)
00269 free_vlc(&vlc[0]);
00270 if(vlc[1].table)
00271 free_vlc(&vlc[1]);
00272 av_free(tmp1.bits);
00273 av_free(tmp1.lengths);
00274 av_free(tmp1.values);
00275 av_free(tmp2.bits);
00276 av_free(tmp2.lengths);
00277 av_free(tmp2.values);
00278
00279 return err;
00280 }
00281
00282 static int decode_header_trees(SmackVContext *smk) {
00283 GetBitContext gb;
00284 int mmap_size, mclr_size, full_size, type_size;
00285
00286 mmap_size = AV_RL32(smk->avctx->extradata);
00287 mclr_size = AV_RL32(smk->avctx->extradata + 4);
00288 full_size = AV_RL32(smk->avctx->extradata + 8);
00289 type_size = AV_RL32(smk->avctx->extradata + 12);
00290
00291 init_get_bits(&gb, smk->avctx->extradata + 16, (smk->avctx->extradata_size - 16) * 8);
00292
00293 if(!get_bits1(&gb)) {
00294 av_log(smk->avctx, AV_LOG_INFO, "Skipping MMAP tree\n");
00295 smk->mmap_tbl = av_malloc(sizeof(int) * 2);
00296 smk->mmap_tbl[0] = 0;
00297 smk->mmap_last[0] = smk->mmap_last[1] = smk->mmap_last[2] = 1;
00298 } else {
00299 if (smacker_decode_header_tree(smk, &gb, &smk->mmap_tbl, smk->mmap_last, mmap_size))
00300 return -1;
00301 }
00302 if(!get_bits1(&gb)) {
00303 av_log(smk->avctx, AV_LOG_INFO, "Skipping MCLR tree\n");
00304 smk->mclr_tbl = av_malloc(sizeof(int) * 2);
00305 smk->mclr_tbl[0] = 0;
00306 smk->mclr_last[0] = smk->mclr_last[1] = smk->mclr_last[2] = 1;
00307 } else {
00308 if (smacker_decode_header_tree(smk, &gb, &smk->mclr_tbl, smk->mclr_last, mclr_size))
00309 return -1;
00310 }
00311 if(!get_bits1(&gb)) {
00312 av_log(smk->avctx, AV_LOG_INFO, "Skipping FULL tree\n");
00313 smk->full_tbl = av_malloc(sizeof(int) * 2);
00314 smk->full_tbl[0] = 0;
00315 smk->full_last[0] = smk->full_last[1] = smk->full_last[2] = 1;
00316 } else {
00317 if (smacker_decode_header_tree(smk, &gb, &smk->full_tbl, smk->full_last, full_size))
00318 return -1;
00319 }
00320 if(!get_bits1(&gb)) {
00321 av_log(smk->avctx, AV_LOG_INFO, "Skipping TYPE tree\n");
00322 smk->type_tbl = av_malloc(sizeof(int) * 2);
00323 smk->type_tbl[0] = 0;
00324 smk->type_last[0] = smk->type_last[1] = smk->type_last[2] = 1;
00325 } else {
00326 if (smacker_decode_header_tree(smk, &gb, &smk->type_tbl, smk->type_last, type_size))
00327 return -1;
00328 }
00329
00330 return 0;
00331 }
00332
00333 static av_always_inline void last_reset(int *recode, int *last) {
00334 recode[last[0]] = recode[last[1]] = recode[last[2]] = 0;
00335 }
00336
00337
00338 static av_always_inline int smk_get_code(GetBitContext *gb, int *recode, int *last) {
00339 register int *table = recode;
00340 int v, b;
00341
00342 b = get_bits_count(gb);
00343 while(*table & SMK_NODE) {
00344 if(get_bits1(gb))
00345 table += (*table) & (~SMK_NODE);
00346 table++;
00347 }
00348 v = *table;
00349 b = get_bits_count(gb) - b;
00350
00351 if(v != recode[last[0]]) {
00352 recode[last[2]] = recode[last[1]];
00353 recode[last[1]] = recode[last[0]];
00354 recode[last[0]] = v;
00355 }
00356 return v;
00357 }
00358
00359 static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
00360 {
00361 const uint8_t *buf = avpkt->data;
00362 int buf_size = avpkt->size;
00363 SmackVContext * const smk = avctx->priv_data;
00364 uint8_t *out;
00365 uint32_t *pal;
00366 GetBitContext gb;
00367 int blocks, blk, bw, bh;
00368 int i;
00369 int stride;
00370
00371 if(buf_size <= 769)
00372 return 0;
00373
00374 smk->pic.reference = 1;
00375 smk->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
00376 if(avctx->reget_buffer(avctx, &smk->pic) < 0){
00377 av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
00378 return -1;
00379 }
00380
00381
00382 pal = (uint32_t*)smk->pic.data[1];
00383 smk->pic.palette_has_changed = buf[0] & 1;
00384 smk->pic.key_frame = !!(buf[0] & 2);
00385 if(smk->pic.key_frame)
00386 smk->pic.pict_type = AV_PICTURE_TYPE_I;
00387 else
00388 smk->pic.pict_type = AV_PICTURE_TYPE_P;
00389
00390 buf++;
00391 for(i = 0; i < 256; i++)
00392 *pal++ = bytestream_get_be24(&buf);
00393 buf_size -= 769;
00394
00395 last_reset(smk->mmap_tbl, smk->mmap_last);
00396 last_reset(smk->mclr_tbl, smk->mclr_last);
00397 last_reset(smk->full_tbl, smk->full_last);
00398 last_reset(smk->type_tbl, smk->type_last);
00399 init_get_bits(&gb, buf, buf_size * 8);
00400
00401 blk = 0;
00402 bw = avctx->width >> 2;
00403 bh = avctx->height >> 2;
00404 blocks = bw * bh;
00405 out = smk->pic.data[0];
00406 stride = smk->pic.linesize[0];
00407 while(blk < blocks) {
00408 int type, run, mode;
00409 uint16_t pix;
00410
00411 type = smk_get_code(&gb, smk->type_tbl, smk->type_last);
00412 run = block_runs[(type >> 2) & 0x3F];
00413 switch(type & 3){
00414 case SMK_BLK_MONO:
00415 while(run-- && blk < blocks){
00416 int clr, map;
00417 int hi, lo;
00418 clr = smk_get_code(&gb, smk->mclr_tbl, smk->mclr_last);
00419 map = smk_get_code(&gb, smk->mmap_tbl, smk->mmap_last);
00420 out = smk->pic.data[0] + (blk / bw) * (stride * 4) + (blk % bw) * 4;
00421 hi = clr >> 8;
00422 lo = clr & 0xFF;
00423 for(i = 0; i < 4; i++) {
00424 if(map & 1) out[0] = hi; else out[0] = lo;
00425 if(map & 2) out[1] = hi; else out[1] = lo;
00426 if(map & 4) out[2] = hi; else out[2] = lo;
00427 if(map & 8) out[3] = hi; else out[3] = lo;
00428 map >>= 4;
00429 out += stride;
00430 }
00431 blk++;
00432 }
00433 break;
00434 case SMK_BLK_FULL:
00435 mode = 0;
00436 if(avctx->codec_tag == MKTAG('S', 'M', 'K', '4')) {
00437 if(get_bits1(&gb)) mode = 1;
00438 else if(get_bits1(&gb)) mode = 2;
00439 }
00440 while(run-- && blk < blocks){
00441 out = smk->pic.data[0] + (blk / bw) * (stride * 4) + (blk % bw) * 4;
00442 switch(mode){
00443 case 0:
00444 for(i = 0; i < 4; i++) {
00445 pix = smk_get_code(&gb, smk->full_tbl, smk->full_last);
00446 AV_WL16(out+2,pix);
00447 pix = smk_get_code(&gb, smk->full_tbl, smk->full_last);
00448 AV_WL16(out,pix);
00449 out += stride;
00450 }
00451 break;
00452 case 1:
00453 pix = smk_get_code(&gb, smk->full_tbl, smk->full_last);
00454 out[0] = out[1] = pix & 0xFF;
00455 out[2] = out[3] = pix >> 8;
00456 out += stride;
00457 out[0] = out[1] = pix & 0xFF;
00458 out[2] = out[3] = pix >> 8;
00459 out += stride;
00460 pix = smk_get_code(&gb, smk->full_tbl, smk->full_last);
00461 out[0] = out[1] = pix & 0xFF;
00462 out[2] = out[3] = pix >> 8;
00463 out += stride;
00464 out[0] = out[1] = pix & 0xFF;
00465 out[2] = out[3] = pix >> 8;
00466 out += stride;
00467 break;
00468 case 2:
00469 for(i = 0; i < 2; i++) {
00470 uint16_t pix1, pix2;
00471 pix2 = smk_get_code(&gb, smk->full_tbl, smk->full_last);
00472 pix1 = smk_get_code(&gb, smk->full_tbl, smk->full_last);
00473 AV_WL16(out,pix1);
00474 AV_WL16(out+2,pix2);
00475 out += stride;
00476 AV_WL16(out,pix1);
00477 AV_WL16(out+2,pix2);
00478 out += stride;
00479 }
00480 break;
00481 }
00482 blk++;
00483 }
00484 break;
00485 case SMK_BLK_SKIP:
00486 while(run-- && blk < blocks)
00487 blk++;
00488 break;
00489 case SMK_BLK_FILL:
00490 mode = type >> 8;
00491 while(run-- && blk < blocks){
00492 uint32_t col;
00493 out = smk->pic.data[0] + (blk / bw) * (stride * 4) + (blk % bw) * 4;
00494 col = mode * 0x01010101;
00495 for(i = 0; i < 4; i++) {
00496 *((uint32_t*)out) = col;
00497 out += stride;
00498 }
00499 blk++;
00500 }
00501 break;
00502 }
00503
00504 }
00505
00506 *data_size = sizeof(AVFrame);
00507 *(AVFrame*)data = smk->pic;
00508
00509
00510 return buf_size;
00511 }
00512
00513
00514
00515
00516
00517
00518
00519
00520 static av_cold int decode_init(AVCodecContext *avctx)
00521 {
00522 SmackVContext * const c = avctx->priv_data;
00523
00524 c->avctx = avctx;
00525
00526 avctx->pix_fmt = PIX_FMT_PAL8;
00527
00528 avcodec_get_frame_defaults(&c->pic);
00529
00530
00531 if(avctx->extradata_size < 16){
00532 av_log(avctx, AV_LOG_ERROR, "Extradata missing!\n");
00533 return -1;
00534 }
00535
00536 if (decode_header_trees(c))
00537 return -1;
00538
00539 return 0;
00540 }
00541
00542
00543
00544
00545
00546
00547
00548
00549 static av_cold int decode_end(AVCodecContext *avctx)
00550 {
00551 SmackVContext * const smk = avctx->priv_data;
00552
00553 av_freep(&smk->mmap_tbl);
00554 av_freep(&smk->mclr_tbl);
00555 av_freep(&smk->full_tbl);
00556 av_freep(&smk->type_tbl);
00557
00558 if (smk->pic.data[0])
00559 avctx->release_buffer(avctx, &smk->pic);
00560
00561 return 0;
00562 }
00563
00564
00565 static av_cold int smka_decode_init(AVCodecContext *avctx)
00566 {
00567 if (avctx->channels < 1 || avctx->channels > 2) {
00568 av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
00569 return AVERROR(EINVAL);
00570 }
00571 avctx->channel_layout = (avctx->channels==2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO;
00572 avctx->sample_fmt = avctx->bits_per_coded_sample == 8 ? AV_SAMPLE_FMT_U8 : AV_SAMPLE_FMT_S16;
00573 return 0;
00574 }
00575
00579 static int smka_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
00580 {
00581 const uint8_t *buf = avpkt->data;
00582 int buf_size = avpkt->size;
00583 GetBitContext gb;
00584 HuffContext h[4];
00585 VLC vlc[4];
00586 int16_t *samples = data;
00587 int8_t *samples8 = data;
00588 int val;
00589 int i, res;
00590 int unp_size;
00591 int bits, stereo;
00592 int pred[2] = {0, 0};
00593
00594 if (buf_size <= 4) {
00595 av_log(avctx, AV_LOG_ERROR, "packet is too small\n");
00596 return AVERROR(EINVAL);
00597 }
00598
00599 unp_size = AV_RL32(buf);
00600
00601 init_get_bits(&gb, buf + 4, (buf_size - 4) * 8);
00602
00603 if(!get_bits1(&gb)){
00604 av_log(avctx, AV_LOG_INFO, "Sound: no data\n");
00605 *data_size = 0;
00606 return 1;
00607 }
00608 stereo = get_bits1(&gb);
00609 bits = get_bits1(&gb);
00610 if (unp_size & 0xC0000000 || unp_size > *data_size) {
00611 av_log(avctx, AV_LOG_ERROR, "Frame is too large to fit in buffer\n");
00612 return -1;
00613 }
00614 if (stereo ^ (avctx->channels != 1)) {
00615 av_log(avctx, AV_LOG_ERROR, "channels mismatch\n");
00616 return AVERROR(EINVAL);
00617 }
00618 if (bits && avctx->sample_fmt == AV_SAMPLE_FMT_U8) {
00619 av_log(avctx, AV_LOG_ERROR, "sample format mismatch\n");
00620 return AVERROR(EINVAL);
00621 }
00622
00623 memset(vlc, 0, sizeof(VLC) * 4);
00624 memset(h, 0, sizeof(HuffContext) * 4);
00625
00626 for(i = 0; i < (1 << (bits + stereo)); i++) {
00627 h[i].length = 256;
00628 h[i].maxlength = 0;
00629 h[i].current = 0;
00630 h[i].bits = av_mallocz(256 * 4);
00631 h[i].lengths = av_mallocz(256 * sizeof(int));
00632 h[i].values = av_mallocz(256 * sizeof(int));
00633 skip_bits1(&gb);
00634 smacker_decode_tree(&gb, &h[i], 0, 0);
00635 skip_bits1(&gb);
00636 if(h[i].current > 1) {
00637 res = init_vlc(&vlc[i], SMKTREE_BITS, h[i].length,
00638 h[i].lengths, sizeof(int), sizeof(int),
00639 h[i].bits, sizeof(uint32_t), sizeof(uint32_t), INIT_VLC_LE);
00640 if(res < 0) {
00641 av_log(avctx, AV_LOG_ERROR, "Cannot build VLC table\n");
00642 return -1;
00643 }
00644 }
00645 }
00646 if(bits) {
00647 for(i = stereo; i >= 0; i--)
00648 pred[i] = av_bswap16(get_bits(&gb, 16));
00649 for(i = 0; i <= stereo; i++)
00650 *samples++ = pred[i];
00651 for(; i < unp_size / 2; i++) {
00652 if(i & stereo) {
00653 if(vlc[2].table)
00654 res = get_vlc2(&gb, vlc[2].table, SMKTREE_BITS, 3);
00655 else
00656 res = 0;
00657 val = h[2].values[res];
00658 if(vlc[3].table)
00659 res = get_vlc2(&gb, vlc[3].table, SMKTREE_BITS, 3);
00660 else
00661 res = 0;
00662 val |= h[3].values[res] << 8;
00663 pred[1] += (int16_t)val;
00664 *samples++ = pred[1];
00665 } else {
00666 if(vlc[0].table)
00667 res = get_vlc2(&gb, vlc[0].table, SMKTREE_BITS, 3);
00668 else
00669 res = 0;
00670 val = h[0].values[res];
00671 if(vlc[1].table)
00672 res = get_vlc2(&gb, vlc[1].table, SMKTREE_BITS, 3);
00673 else
00674 res = 0;
00675 val |= h[1].values[res] << 8;
00676 pred[0] += val;
00677 *samples++ = pred[0];
00678 }
00679 }
00680 } else {
00681 for(i = stereo; i >= 0; i--)
00682 pred[i] = get_bits(&gb, 8);
00683 for(i = 0; i <= stereo; i++)
00684 *samples8++ = pred[i];
00685 for(; i < unp_size; i++) {
00686 if(i & stereo){
00687 if(vlc[1].table)
00688 res = get_vlc2(&gb, vlc[1].table, SMKTREE_BITS, 3);
00689 else
00690 res = 0;
00691 pred[1] += (int8_t)h[1].values[res];
00692 *samples8++ = pred[1];
00693 } else {
00694 if(vlc[0].table)
00695 res = get_vlc2(&gb, vlc[0].table, SMKTREE_BITS, 3);
00696 else
00697 res = 0;
00698 pred[0] += (int8_t)h[0].values[res];
00699 *samples8++ = pred[0];
00700 }
00701 }
00702 }
00703
00704 for(i = 0; i < 4; i++) {
00705 if(vlc[i].table)
00706 free_vlc(&vlc[i]);
00707 av_free(h[i].bits);
00708 av_free(h[i].lengths);
00709 av_free(h[i].values);
00710 }
00711
00712 *data_size = unp_size;
00713 return buf_size;
00714 }
00715
00716 AVCodec ff_smacker_decoder = {
00717 "smackvid",
00718 AVMEDIA_TYPE_VIDEO,
00719 CODEC_ID_SMACKVIDEO,
00720 sizeof(SmackVContext),
00721 decode_init,
00722 NULL,
00723 decode_end,
00724 decode_frame,
00725 CODEC_CAP_DR1,
00726 .long_name = NULL_IF_CONFIG_SMALL("Smacker video"),
00727 };
00728
00729 AVCodec ff_smackaud_decoder = {
00730 "smackaud",
00731 AVMEDIA_TYPE_AUDIO,
00732 CODEC_ID_SMACKAUDIO,
00733 0,
00734 smka_decode_init,
00735 NULL,
00736 NULL,
00737 smka_decode_frame,
00738 .long_name = NULL_IF_CONFIG_SMALL("Smacker audio"),
00739 };
00740