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