2006-03-21 18:27:47 +01:00
|
|
|
/*
|
|
|
|
* Smacker decoder
|
|
|
|
* Copyright (c) 2006 Konstantin Shishkov
|
|
|
|
*
|
2006-10-07 17:30:46 +02:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2006-03-21 18:27:47 +01:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 17:30:46 +02:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2006-03-21 18:27:47 +01:00
|
|
|
*
|
2006-10-07 17:30:46 +02:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2006-03-21 18:27:47 +01:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2006-10-07 17:30:46 +02:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2006-03-21 18:27:47 +01:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2010-04-20 16:45:34 +02:00
|
|
|
* @file
|
2006-03-21 18:27:47 +01:00
|
|
|
* Smacker decoder
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Based on http://wiki.multimedia.cx/index.php?title=Smacker
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2012-11-10 16:00:00 +01:00
|
|
|
#include "libavutil/channel_layout.h"
|
2006-03-21 18:27:47 +01:00
|
|
|
#include "avcodec.h"
|
2012-11-10 13:22:56 +01:00
|
|
|
#include "internal.h"
|
2011-11-09 22:19:52 +01:00
|
|
|
#include "mathops.h"
|
2006-03-21 18:27:47 +01:00
|
|
|
|
2011-12-22 16:33:31 +01:00
|
|
|
#define BITSTREAM_READER_LE
|
2009-04-13 18:20:26 +02:00
|
|
|
#include "get_bits.h"
|
2008-02-02 23:31:11 +01:00
|
|
|
#include "bytestream.h"
|
2006-03-21 18:27:47 +01:00
|
|
|
|
|
|
|
#define SMKTREE_BITS 9
|
|
|
|
#define SMK_NODE 0x80000000
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Decoder context
|
|
|
|
*/
|
|
|
|
typedef struct SmackVContext {
|
|
|
|
AVCodecContext *avctx;
|
|
|
|
AVFrame pic;
|
|
|
|
|
|
|
|
int *mmap_tbl, *mclr_tbl, *full_tbl, *type_tbl;
|
|
|
|
int mmap_last[3], mclr_last[3], full_last[3], type_last[3];
|
|
|
|
} SmackVContext;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Context used for code reconstructing
|
|
|
|
*/
|
|
|
|
typedef struct HuffContext {
|
|
|
|
int length;
|
|
|
|
int maxlength;
|
|
|
|
int current;
|
|
|
|
uint32_t *bits;
|
|
|
|
int *lengths;
|
|
|
|
int *values;
|
|
|
|
} HuffContext;
|
|
|
|
|
|
|
|
/* common parameters used for decode_bigtree */
|
|
|
|
typedef struct DBCtx {
|
|
|
|
VLC *v1, *v2;
|
|
|
|
int *recode1, *recode2;
|
|
|
|
int escapes[3];
|
|
|
|
int *last;
|
|
|
|
int lcur;
|
|
|
|
} DBCtx;
|
|
|
|
|
|
|
|
/* possible runs of blocks */
|
|
|
|
static const int block_runs[64] = {
|
|
|
|
1, 2, 3, 4, 5, 6, 7, 8,
|
|
|
|
9, 10, 11, 12, 13, 14, 15, 16,
|
|
|
|
17, 18, 19, 20, 21, 22, 23, 24,
|
|
|
|
25, 26, 27, 28, 29, 30, 31, 32,
|
|
|
|
33, 34, 35, 36, 37, 38, 39, 40,
|
|
|
|
41, 42, 43, 44, 45, 46, 47, 48,
|
|
|
|
49, 50, 51, 52, 53, 54, 55, 56,
|
|
|
|
57, 58, 59, 128, 256, 512, 1024, 2048 };
|
|
|
|
|
|
|
|
enum SmkBlockTypes {
|
|
|
|
SMK_BLK_MONO = 0,
|
|
|
|
SMK_BLK_FULL = 1,
|
|
|
|
SMK_BLK_SKIP = 2,
|
|
|
|
SMK_BLK_FILL = 3 };
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decode local frame tree
|
|
|
|
*/
|
|
|
|
static int smacker_decode_tree(GetBitContext *gb, HuffContext *hc, uint32_t prefix, int length)
|
|
|
|
{
|
2012-11-30 16:00:07 +01:00
|
|
|
if(length > 32 || length > 3*SMKTREE_BITS) {
|
2012-06-21 16:01:52 +02:00
|
|
|
av_log(NULL, AV_LOG_ERROR, "length too long\n");
|
2012-11-11 11:04:04 +01:00
|
|
|
return AVERROR_INVALIDDATA;
|
2012-06-21 16:01:52 +02:00
|
|
|
}
|
2006-03-21 18:27:47 +01:00
|
|
|
if(!get_bits1(gb)){ //Leaf
|
|
|
|
if(hc->current >= 256){
|
|
|
|
av_log(NULL, AV_LOG_ERROR, "Tree size exceeded!\n");
|
2012-11-11 11:04:04 +01:00
|
|
|
return AVERROR_INVALIDDATA;
|
2006-03-21 18:27:47 +01:00
|
|
|
}
|
|
|
|
if(length){
|
|
|
|
hc->bits[hc->current] = prefix;
|
|
|
|
hc->lengths[hc->current] = length;
|
|
|
|
} else {
|
|
|
|
hc->bits[hc->current] = 0;
|
|
|
|
hc->lengths[hc->current] = 0;
|
|
|
|
}
|
|
|
|
hc->values[hc->current] = get_bits(gb, 8);
|
|
|
|
hc->current++;
|
|
|
|
if(hc->maxlength < length)
|
|
|
|
hc->maxlength = length;
|
|
|
|
return 0;
|
|
|
|
} else { //Node
|
|
|
|
int r;
|
|
|
|
length++;
|
|
|
|
r = smacker_decode_tree(gb, hc, prefix, length);
|
|
|
|
if(r)
|
|
|
|
return r;
|
|
|
|
return smacker_decode_tree(gb, hc, prefix | (1 << (length - 1)), length);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decode header tree
|
|
|
|
*/
|
|
|
|
static int smacker_decode_bigtree(GetBitContext *gb, HuffContext *hc, DBCtx *ctx)
|
|
|
|
{
|
2012-01-26 01:12:42 +01:00
|
|
|
if (hc->current + 1 >= hc->length) {
|
|
|
|
av_log(NULL, AV_LOG_ERROR, "Tree size exceeded!\n");
|
2012-11-11 11:04:04 +01:00
|
|
|
return AVERROR_INVALIDDATA;
|
2012-01-26 01:12:42 +01:00
|
|
|
}
|
2006-03-21 18:27:47 +01:00
|
|
|
if(!get_bits1(gb)){ //Leaf
|
2012-07-01 15:56:16 +02:00
|
|
|
int val, i1, i2;
|
2011-09-11 18:54:01 +02:00
|
|
|
i1 = ctx->v1->table ? get_vlc2(gb, ctx->v1->table, SMKTREE_BITS, 3) : 0;
|
|
|
|
i2 = ctx->v2->table ? get_vlc2(gb, ctx->v2->table, SMKTREE_BITS, 3) : 0;
|
|
|
|
if (i1 < 0 || i2 < 0)
|
2012-11-11 11:04:04 +01:00
|
|
|
return AVERROR_INVALIDDATA;
|
2006-03-21 18:27:47 +01:00
|
|
|
val = ctx->recode1[i1] | (ctx->recode2[i2] << 8);
|
|
|
|
if(val == ctx->escapes[0]) {
|
|
|
|
ctx->last[0] = hc->current;
|
|
|
|
val = 0;
|
|
|
|
} else if(val == ctx->escapes[1]) {
|
|
|
|
ctx->last[1] = hc->current;
|
|
|
|
val = 0;
|
|
|
|
} else if(val == ctx->escapes[2]) {
|
|
|
|
ctx->last[2] = hc->current;
|
|
|
|
val = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
hc->values[hc->current++] = val;
|
|
|
|
return 1;
|
|
|
|
} else { //Node
|
2012-01-26 01:12:42 +01:00
|
|
|
int r = 0, r_new, t;
|
2006-03-21 18:27:47 +01:00
|
|
|
|
|
|
|
t = hc->current++;
|
|
|
|
r = smacker_decode_bigtree(gb, hc, ctx);
|
|
|
|
if(r < 0)
|
|
|
|
return r;
|
|
|
|
hc->values[t] = SMK_NODE | r;
|
|
|
|
r++;
|
2012-01-26 01:12:42 +01:00
|
|
|
r_new = smacker_decode_bigtree(gb, hc, ctx);
|
|
|
|
if (r_new < 0)
|
|
|
|
return r_new;
|
|
|
|
return r + r_new;
|
2006-03-21 18:27:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store large tree as FFmpeg's vlc codes
|
|
|
|
*/
|
|
|
|
static int smacker_decode_header_tree(SmackVContext *smk, GetBitContext *gb, int **recodes, int *last, int size)
|
|
|
|
{
|
|
|
|
int res;
|
|
|
|
HuffContext huff;
|
|
|
|
HuffContext tmp1, tmp2;
|
2011-06-06 14:13:02 +02:00
|
|
|
VLC vlc[2] = { { 0 } };
|
2006-03-21 18:27:47 +01:00
|
|
|
int escapes[3];
|
|
|
|
DBCtx ctx;
|
2012-01-26 01:12:42 +01:00
|
|
|
int err = 0;
|
2006-03-21 18:27:47 +01:00
|
|
|
|
2006-05-13 12:45:26 +02:00
|
|
|
if(size >= UINT_MAX>>4){ // (((size + 3) >> 2) + 3) << 2 must not overflow
|
|
|
|
av_log(smk->avctx, AV_LOG_ERROR, "size too large\n");
|
2012-11-11 11:04:04 +01:00
|
|
|
return AVERROR_INVALIDDATA;
|
2006-05-13 12:45:26 +02:00
|
|
|
}
|
|
|
|
|
2006-03-21 18:27:47 +01:00
|
|
|
tmp1.length = 256;
|
|
|
|
tmp1.maxlength = 0;
|
|
|
|
tmp1.current = 0;
|
|
|
|
tmp1.bits = av_mallocz(256 * 4);
|
|
|
|
tmp1.lengths = av_mallocz(256 * sizeof(int));
|
|
|
|
tmp1.values = av_mallocz(256 * sizeof(int));
|
|
|
|
|
|
|
|
tmp2.length = 256;
|
|
|
|
tmp2.maxlength = 0;
|
|
|
|
tmp2.current = 0;
|
|
|
|
tmp2.bits = av_mallocz(256 * 4);
|
|
|
|
tmp2.lengths = av_mallocz(256 * sizeof(int));
|
|
|
|
tmp2.values = av_mallocz(256 * sizeof(int));
|
|
|
|
|
|
|
|
if(get_bits1(gb)) {
|
2012-11-30 15:58:19 +01:00
|
|
|
res = smacker_decode_tree(gb, &tmp1, 0, 0);
|
|
|
|
if (res < 0)
|
|
|
|
return res;
|
2007-08-09 02:57:36 +02:00
|
|
|
skip_bits1(gb);
|
2012-11-25 02:36:34 +01:00
|
|
|
if(tmp1.current > 1) {
|
|
|
|
res = init_vlc(&vlc[0], SMKTREE_BITS, tmp1.length,
|
|
|
|
tmp1.lengths, sizeof(int), sizeof(int),
|
|
|
|
tmp1.bits, sizeof(uint32_t), sizeof(uint32_t), INIT_VLC_LE);
|
|
|
|
if(res < 0) {
|
|
|
|
av_log(smk->avctx, AV_LOG_ERROR, "Cannot build VLC table\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
2006-03-21 18:27:47 +01:00
|
|
|
}
|
2012-11-25 02:36:34 +01:00
|
|
|
}
|
|
|
|
if (!vlc[0].table) {
|
2006-03-21 18:27:47 +01:00
|
|
|
av_log(smk->avctx, AV_LOG_ERROR, "Skipping low bytes tree\n");
|
|
|
|
}
|
|
|
|
if(get_bits1(gb)){
|
2012-11-30 15:58:19 +01:00
|
|
|
res = smacker_decode_tree(gb, &tmp2, 0, 0);
|
|
|
|
if (res < 0)
|
|
|
|
return res;
|
2007-08-09 02:57:36 +02:00
|
|
|
skip_bits1(gb);
|
2012-11-25 02:36:34 +01:00
|
|
|
if(tmp2.current > 1) {
|
|
|
|
res = init_vlc(&vlc[1], SMKTREE_BITS, tmp2.length,
|
|
|
|
tmp2.lengths, sizeof(int), sizeof(int),
|
|
|
|
tmp2.bits, sizeof(uint32_t), sizeof(uint32_t), INIT_VLC_LE);
|
|
|
|
if(res < 0) {
|
|
|
|
av_log(smk->avctx, AV_LOG_ERROR, "Cannot build VLC table\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
2006-03-21 18:27:47 +01:00
|
|
|
}
|
2012-11-25 02:36:34 +01:00
|
|
|
}
|
|
|
|
if (!vlc[1].table) {
|
2006-03-21 18:27:47 +01:00
|
|
|
av_log(smk->avctx, AV_LOG_ERROR, "Skipping high bytes tree\n");
|
|
|
|
}
|
|
|
|
|
2012-09-30 16:49:08 +02:00
|
|
|
escapes[0] = get_bits(gb, 16);
|
|
|
|
escapes[1] = get_bits(gb, 16);
|
|
|
|
escapes[2] = get_bits(gb, 16);
|
2006-03-21 18:27:47 +01:00
|
|
|
|
|
|
|
last[0] = last[1] = last[2] = -1;
|
|
|
|
|
|
|
|
ctx.escapes[0] = escapes[0];
|
|
|
|
ctx.escapes[1] = escapes[1];
|
|
|
|
ctx.escapes[2] = escapes[2];
|
|
|
|
ctx.v1 = &vlc[0];
|
|
|
|
ctx.v2 = &vlc[1];
|
|
|
|
ctx.recode1 = tmp1.values;
|
|
|
|
ctx.recode2 = tmp2.values;
|
|
|
|
ctx.last = last;
|
|
|
|
|
2013-06-12 14:22:24 +02:00
|
|
|
huff.length = ((size + 3) >> 2) + 4;
|
2006-03-21 18:27:47 +01:00
|
|
|
huff.maxlength = 0;
|
|
|
|
huff.current = 0;
|
|
|
|
huff.values = av_mallocz(huff.length * sizeof(int));
|
2013-06-29 16:04:07 +02:00
|
|
|
if (!huff.values)
|
|
|
|
return AVERROR(ENOMEM);
|
2006-03-21 18:27:47 +01:00
|
|
|
|
2012-01-26 01:12:42 +01:00
|
|
|
if (smacker_decode_bigtree(gb, &huff, &ctx) < 0)
|
|
|
|
err = -1;
|
2007-08-09 02:57:36 +02:00
|
|
|
skip_bits1(gb);
|
2006-03-21 18:27:47 +01:00
|
|
|
if(ctx.last[0] == -1) ctx.last[0] = huff.current++;
|
|
|
|
if(ctx.last[1] == -1) ctx.last[1] = huff.current++;
|
|
|
|
if(ctx.last[2] == -1) ctx.last[2] = huff.current++;
|
2012-01-25 22:28:57 +01:00
|
|
|
if(huff.current > huff.length){
|
|
|
|
ctx.last[0] = ctx.last[1] = ctx.last[2] = 1;
|
|
|
|
av_log(smk->avctx, AV_LOG_ERROR, "bigtree damaged\n");
|
2012-11-11 11:04:04 +01:00
|
|
|
return AVERROR_INVALIDDATA;
|
2012-01-25 22:28:57 +01:00
|
|
|
}
|
2006-03-21 18:27:47 +01:00
|
|
|
|
|
|
|
*recodes = huff.values;
|
|
|
|
|
|
|
|
if(vlc[0].table)
|
2012-02-09 10:37:58 +01:00
|
|
|
ff_free_vlc(&vlc[0]);
|
2006-03-21 18:27:47 +01:00
|
|
|
if(vlc[1].table)
|
2012-02-09 10:37:58 +01:00
|
|
|
ff_free_vlc(&vlc[1]);
|
2006-03-21 18:27:47 +01:00
|
|
|
av_free(tmp1.bits);
|
|
|
|
av_free(tmp1.lengths);
|
|
|
|
av_free(tmp1.values);
|
|
|
|
av_free(tmp2.bits);
|
|
|
|
av_free(tmp2.lengths);
|
|
|
|
av_free(tmp2.values);
|
|
|
|
|
2012-01-26 01:12:42 +01:00
|
|
|
return err;
|
2006-03-21 18:27:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static int decode_header_trees(SmackVContext *smk) {
|
|
|
|
GetBitContext gb;
|
2013-06-29 16:02:43 +02:00
|
|
|
int mmap_size, mclr_size, full_size, type_size, ret;
|
2006-03-21 18:27:47 +01:00
|
|
|
|
2007-01-19 23:12:59 +01:00
|
|
|
mmap_size = AV_RL32(smk->avctx->extradata);
|
|
|
|
mclr_size = AV_RL32(smk->avctx->extradata + 4);
|
|
|
|
full_size = AV_RL32(smk->avctx->extradata + 8);
|
|
|
|
type_size = AV_RL32(smk->avctx->extradata + 12);
|
2006-03-21 18:27:47 +01:00
|
|
|
|
|
|
|
init_get_bits(&gb, smk->avctx->extradata + 16, (smk->avctx->extradata_size - 16) * 8);
|
|
|
|
|
|
|
|
if(!get_bits1(&gb)) {
|
|
|
|
av_log(smk->avctx, AV_LOG_INFO, "Skipping MMAP tree\n");
|
|
|
|
smk->mmap_tbl = av_malloc(sizeof(int) * 2);
|
|
|
|
smk->mmap_tbl[0] = 0;
|
|
|
|
smk->mmap_last[0] = smk->mmap_last[1] = smk->mmap_last[2] = 1;
|
|
|
|
} else {
|
2013-06-29 16:02:43 +02:00
|
|
|
ret = smacker_decode_header_tree(smk, &gb, &smk->mmap_tbl, smk->mmap_last, mmap_size);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2006-03-21 18:27:47 +01:00
|
|
|
}
|
2007-08-09 02:13:31 +02:00
|
|
|
if(!get_bits1(&gb)) {
|
2006-03-21 18:27:47 +01:00
|
|
|
av_log(smk->avctx, AV_LOG_INFO, "Skipping MCLR tree\n");
|
|
|
|
smk->mclr_tbl = av_malloc(sizeof(int) * 2);
|
|
|
|
smk->mclr_tbl[0] = 0;
|
|
|
|
smk->mclr_last[0] = smk->mclr_last[1] = smk->mclr_last[2] = 1;
|
|
|
|
} else {
|
2013-06-29 16:02:43 +02:00
|
|
|
ret = smacker_decode_header_tree(smk, &gb, &smk->mclr_tbl, smk->mclr_last, mclr_size);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2006-03-21 18:27:47 +01:00
|
|
|
}
|
2007-08-09 02:13:31 +02:00
|
|
|
if(!get_bits1(&gb)) {
|
2006-03-21 18:27:47 +01:00
|
|
|
av_log(smk->avctx, AV_LOG_INFO, "Skipping FULL tree\n");
|
|
|
|
smk->full_tbl = av_malloc(sizeof(int) * 2);
|
|
|
|
smk->full_tbl[0] = 0;
|
|
|
|
smk->full_last[0] = smk->full_last[1] = smk->full_last[2] = 1;
|
|
|
|
} else {
|
2013-06-29 16:02:43 +02:00
|
|
|
ret = smacker_decode_header_tree(smk, &gb, &smk->full_tbl, smk->full_last, full_size);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2006-03-21 18:27:47 +01:00
|
|
|
}
|
2007-08-09 02:13:31 +02:00
|
|
|
if(!get_bits1(&gb)) {
|
2006-03-21 18:27:47 +01:00
|
|
|
av_log(smk->avctx, AV_LOG_INFO, "Skipping TYPE tree\n");
|
|
|
|
smk->type_tbl = av_malloc(sizeof(int) * 2);
|
|
|
|
smk->type_tbl[0] = 0;
|
|
|
|
smk->type_last[0] = smk->type_last[1] = smk->type_last[2] = 1;
|
|
|
|
} else {
|
2013-06-29 16:02:43 +02:00
|
|
|
ret = smacker_decode_header_tree(smk, &gb, &smk->type_tbl, smk->type_last, type_size);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2006-03-21 18:27:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-12-08 01:35:08 +01:00
|
|
|
static av_always_inline void last_reset(int *recode, int *last) {
|
2006-03-21 18:27:47 +01:00
|
|
|
recode[last[0]] = recode[last[1]] = recode[last[2]] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get code and update history */
|
2006-12-08 01:35:08 +01:00
|
|
|
static av_always_inline int smk_get_code(GetBitContext *gb, int *recode, int *last) {
|
2006-03-21 18:27:47 +01:00
|
|
|
register int *table = recode;
|
2012-01-26 01:22:05 +01:00
|
|
|
int v;
|
2006-03-21 18:27:47 +01:00
|
|
|
|
|
|
|
while(*table & SMK_NODE) {
|
|
|
|
if(get_bits1(gb))
|
|
|
|
table += (*table) & (~SMK_NODE);
|
|
|
|
table++;
|
|
|
|
}
|
|
|
|
v = *table;
|
|
|
|
|
|
|
|
if(v != recode[last[0]]) {
|
|
|
|
recode[last[2]] = recode[last[1]];
|
|
|
|
recode[last[1]] = recode[last[0]];
|
|
|
|
recode[last[0]] = v;
|
|
|
|
}
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2012-11-13 19:35:22 +01:00
|
|
|
static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
|
|
|
|
AVPacket *avpkt)
|
2006-03-21 18:27:47 +01:00
|
|
|
{
|
2007-04-08 22:24:16 +02:00
|
|
|
SmackVContext * const smk = avctx->priv_data;
|
2006-03-21 18:27:47 +01:00
|
|
|
uint8_t *out;
|
|
|
|
uint32_t *pal;
|
2012-03-25 01:37:43 +01:00
|
|
|
GetByteContext gb2;
|
2006-03-21 18:27:47 +01:00
|
|
|
GetBitContext gb;
|
|
|
|
int blocks, blk, bw, bh;
|
2012-10-15 14:08:24 +02:00
|
|
|
int i, ret;
|
2006-03-21 18:27:47 +01:00
|
|
|
int stride;
|
2012-03-25 01:37:43 +01:00
|
|
|
int flags;
|
2006-03-21 18:27:47 +01:00
|
|
|
|
2012-03-25 01:37:43 +01:00
|
|
|
if (avpkt->size <= 769)
|
2012-10-15 14:08:24 +02:00
|
|
|
return AVERROR_INVALIDDATA;
|
2006-03-21 18:27:47 +01:00
|
|
|
|
lavc: factorize ff_{thread_,re,}get_buffer error messages.
Coccinelle profile used:
@@
expression r, ctx, f, loglevel, str, flags;
@@
-if ((r = ff_get_buffer(ctx, f, flags)) < 0) {
- av_log(ctx, loglevel, str);
- return r;
-}
+if ((r = ff_get_buffer(ctx, f, flags)) < 0)
+ return r;
@@
expression r, ctx, f, loglevel, str;
@@
-if ((r = ff_reget_buffer(ctx, f)) < 0) {
- av_log(ctx, loglevel, str);
- return r;
-}
+if ((r = ff_reget_buffer(ctx, f)) < 0)
+ return r;
@@
expression r, ctx, f, loglevel, str, flags;
@@
-if ((r = ff_thread_get_buffer(ctx, f, flags)) < 0) {
- av_log(ctx, loglevel, str);
- return r;
-}
+if ((r = ff_thread_get_buffer(ctx, f, flags)) < 0)
+ return r;
...along with some manual patches for the remaining ones.
2013-03-12 08:41:53 +01:00
|
|
|
if ((ret = ff_reget_buffer(avctx, &smk->pic)) < 0)
|
2012-10-15 14:08:24 +02:00
|
|
|
return ret;
|
2006-03-21 18:27:47 +01:00
|
|
|
|
|
|
|
/* make the palette available on the way out */
|
|
|
|
pal = (uint32_t*)smk->pic.data[1];
|
2012-03-25 01:37:43 +01:00
|
|
|
bytestream2_init(&gb2, avpkt->data, avpkt->size);
|
|
|
|
flags = bytestream2_get_byteu(&gb2);
|
|
|
|
smk->pic.palette_has_changed = flags & 1;
|
|
|
|
smk->pic.key_frame = !!(flags & 2);
|
2006-03-21 18:27:47 +01:00
|
|
|
if(smk->pic.key_frame)
|
2011-04-28 01:40:44 +02:00
|
|
|
smk->pic.pict_type = AV_PICTURE_TYPE_I;
|
2006-03-21 18:27:47 +01:00
|
|
|
else
|
2011-04-28 01:40:44 +02:00
|
|
|
smk->pic.pict_type = AV_PICTURE_TYPE_P;
|
2006-03-21 18:27:47 +01:00
|
|
|
|
2008-02-02 23:31:11 +01:00
|
|
|
for(i = 0; i < 256; i++)
|
2012-10-14 03:17:13 +02:00
|
|
|
*pal++ = 0xFFU << 24 | bytestream2_get_be24u(&gb2);
|
2006-03-21 18:27:47 +01:00
|
|
|
|
|
|
|
last_reset(smk->mmap_tbl, smk->mmap_last);
|
|
|
|
last_reset(smk->mclr_tbl, smk->mclr_last);
|
|
|
|
last_reset(smk->full_tbl, smk->full_last);
|
|
|
|
last_reset(smk->type_tbl, smk->type_last);
|
2012-03-25 01:37:43 +01:00
|
|
|
init_get_bits(&gb, avpkt->data + 769, (avpkt->size - 769) * 8);
|
2006-03-21 18:27:47 +01:00
|
|
|
|
|
|
|
blk = 0;
|
|
|
|
bw = avctx->width >> 2;
|
|
|
|
bh = avctx->height >> 2;
|
|
|
|
blocks = bw * bh;
|
|
|
|
out = smk->pic.data[0];
|
|
|
|
stride = smk->pic.linesize[0];
|
|
|
|
while(blk < blocks) {
|
|
|
|
int type, run, mode;
|
|
|
|
uint16_t pix;
|
|
|
|
|
|
|
|
type = smk_get_code(&gb, smk->type_tbl, smk->type_last);
|
|
|
|
run = block_runs[(type >> 2) & 0x3F];
|
|
|
|
switch(type & 3){
|
|
|
|
case SMK_BLK_MONO:
|
|
|
|
while(run-- && blk < blocks){
|
|
|
|
int clr, map;
|
|
|
|
int hi, lo;
|
|
|
|
clr = smk_get_code(&gb, smk->mclr_tbl, smk->mclr_last);
|
|
|
|
map = smk_get_code(&gb, smk->mmap_tbl, smk->mmap_last);
|
|
|
|
out = smk->pic.data[0] + (blk / bw) * (stride * 4) + (blk % bw) * 4;
|
|
|
|
hi = clr >> 8;
|
|
|
|
lo = clr & 0xFF;
|
|
|
|
for(i = 0; i < 4; i++) {
|
|
|
|
if(map & 1) out[0] = hi; else out[0] = lo;
|
|
|
|
if(map & 2) out[1] = hi; else out[1] = lo;
|
|
|
|
if(map & 4) out[2] = hi; else out[2] = lo;
|
|
|
|
if(map & 8) out[3] = hi; else out[3] = lo;
|
|
|
|
map >>= 4;
|
|
|
|
out += stride;
|
|
|
|
}
|
|
|
|
blk++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SMK_BLK_FULL:
|
|
|
|
mode = 0;
|
2006-05-17 05:03:53 +02:00
|
|
|
if(avctx->codec_tag == MKTAG('S', 'M', 'K', '4')) { // In case of Smacker v4 we have three modes
|
2006-03-21 18:27:47 +01:00
|
|
|
if(get_bits1(&gb)) mode = 1;
|
|
|
|
else if(get_bits1(&gb)) mode = 2;
|
|
|
|
}
|
|
|
|
while(run-- && blk < blocks){
|
|
|
|
out = smk->pic.data[0] + (blk / bw) * (stride * 4) + (blk % bw) * 4;
|
|
|
|
switch(mode){
|
|
|
|
case 0:
|
|
|
|
for(i = 0; i < 4; i++) {
|
|
|
|
pix = smk_get_code(&gb, smk->full_tbl, smk->full_last);
|
2007-06-02 03:41:07 +02:00
|
|
|
AV_WL16(out+2,pix);
|
2006-03-21 18:27:47 +01:00
|
|
|
pix = smk_get_code(&gb, smk->full_tbl, smk->full_last);
|
2007-06-02 03:41:07 +02:00
|
|
|
AV_WL16(out,pix);
|
2006-03-21 18:27:47 +01:00
|
|
|
out += stride;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
pix = smk_get_code(&gb, smk->full_tbl, smk->full_last);
|
|
|
|
out[0] = out[1] = pix & 0xFF;
|
|
|
|
out[2] = out[3] = pix >> 8;
|
|
|
|
out += stride;
|
|
|
|
out[0] = out[1] = pix & 0xFF;
|
|
|
|
out[2] = out[3] = pix >> 8;
|
|
|
|
out += stride;
|
|
|
|
pix = smk_get_code(&gb, smk->full_tbl, smk->full_last);
|
|
|
|
out[0] = out[1] = pix & 0xFF;
|
|
|
|
out[2] = out[3] = pix >> 8;
|
|
|
|
out += stride;
|
|
|
|
out[0] = out[1] = pix & 0xFF;
|
|
|
|
out[2] = out[3] = pix >> 8;
|
|
|
|
out += stride;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
for(i = 0; i < 2; i++) {
|
|
|
|
uint16_t pix1, pix2;
|
|
|
|
pix2 = smk_get_code(&gb, smk->full_tbl, smk->full_last);
|
2008-12-15 18:51:10 +01:00
|
|
|
pix1 = smk_get_code(&gb, smk->full_tbl, smk->full_last);
|
2007-06-02 03:41:07 +02:00
|
|
|
AV_WL16(out,pix1);
|
|
|
|
AV_WL16(out+2,pix2);
|
2006-03-21 18:27:47 +01:00
|
|
|
out += stride;
|
2007-06-02 03:41:07 +02:00
|
|
|
AV_WL16(out,pix1);
|
|
|
|
AV_WL16(out+2,pix2);
|
2006-03-21 18:27:47 +01:00
|
|
|
out += stride;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
blk++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SMK_BLK_SKIP:
|
|
|
|
while(run-- && blk < blocks)
|
|
|
|
blk++;
|
|
|
|
break;
|
|
|
|
case SMK_BLK_FILL:
|
|
|
|
mode = type >> 8;
|
|
|
|
while(run-- && blk < blocks){
|
|
|
|
uint32_t col;
|
|
|
|
out = smk->pic.data[0] + (blk / bw) * (stride * 4) + (blk % bw) * 4;
|
|
|
|
col = mode * 0x01010101;
|
|
|
|
for(i = 0; i < 4; i++) {
|
|
|
|
*((uint32_t*)out) = col;
|
|
|
|
out += stride;
|
|
|
|
}
|
|
|
|
blk++;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-11-21 21:34:46 +01:00
|
|
|
if ((ret = av_frame_ref(data, &smk->pic)) < 0)
|
|
|
|
return ret;
|
|
|
|
|
2012-11-13 19:35:22 +01:00
|
|
|
*got_frame = 1;
|
2006-03-21 18:27:47 +01:00
|
|
|
|
|
|
|
/* always report that the buffer was completely consumed */
|
2012-03-25 01:37:43 +01:00
|
|
|
return avpkt->size;
|
2006-03-21 18:27:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Init smacker decoder
|
|
|
|
*
|
|
|
|
*/
|
2008-03-21 04:11:20 +01:00
|
|
|
static av_cold int decode_init(AVCodecContext *avctx)
|
2006-03-21 18:27:47 +01:00
|
|
|
{
|
2007-04-08 22:24:16 +02:00
|
|
|
SmackVContext * const c = avctx->priv_data;
|
2013-06-29 16:02:43 +02:00
|
|
|
int ret;
|
2006-03-21 18:27:47 +01:00
|
|
|
|
|
|
|
c->avctx = avctx;
|
|
|
|
|
2012-10-06 12:10:34 +02:00
|
|
|
avctx->pix_fmt = AV_PIX_FMT_PAL8;
|
2011-05-02 02:15:15 +02:00
|
|
|
avcodec_get_frame_defaults(&c->pic);
|
2006-03-21 18:27:47 +01:00
|
|
|
|
|
|
|
/* decode huffman trees from extradata */
|
|
|
|
if(avctx->extradata_size < 16){
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Extradata missing!\n");
|
2012-10-15 14:08:24 +02:00
|
|
|
return AVERROR(EINVAL);
|
2006-03-21 18:27:47 +01:00
|
|
|
}
|
|
|
|
|
2013-06-29 16:02:43 +02:00
|
|
|
ret = decode_header_trees(c);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2006-03-21 18:27:47 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Uninit smacker decoder
|
|
|
|
*
|
|
|
|
*/
|
2008-03-21 04:11:20 +01:00
|
|
|
static av_cold int decode_end(AVCodecContext *avctx)
|
2006-03-21 18:27:47 +01:00
|
|
|
{
|
2007-04-08 22:24:16 +02:00
|
|
|
SmackVContext * const smk = avctx->priv_data;
|
2006-03-21 18:27:47 +01:00
|
|
|
|
2006-09-09 13:40:41 +02:00
|
|
|
av_freep(&smk->mmap_tbl);
|
|
|
|
av_freep(&smk->mclr_tbl);
|
|
|
|
av_freep(&smk->full_tbl);
|
|
|
|
av_freep(&smk->type_tbl);
|
2006-03-21 18:27:47 +01:00
|
|
|
|
2012-11-21 21:34:46 +01:00
|
|
|
av_frame_unref(&smk->pic);
|
2006-03-21 18:27:47 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-03-21 04:11:20 +01:00
|
|
|
static av_cold int smka_decode_init(AVCodecContext *avctx)
|
2006-03-21 18:27:47 +01:00
|
|
|
{
|
2011-09-21 17:37:51 +02:00
|
|
|
if (avctx->channels < 1 || avctx->channels > 2) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "invalid number of channels\n");
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
2011-02-03 14:26:09 +01:00
|
|
|
avctx->channel_layout = (avctx->channels==2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO;
|
2010-11-12 12:04:40 +01:00
|
|
|
avctx->sample_fmt = avctx->bits_per_coded_sample == 8 ? AV_SAMPLE_FMT_U8 : AV_SAMPLE_FMT_S16;
|
2011-09-06 18:17:45 +02:00
|
|
|
|
2006-03-21 18:27:47 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Decode Smacker audio data
|
|
|
|
*/
|
2011-09-06 18:17:45 +02:00
|
|
|
static int smka_decode_frame(AVCodecContext *avctx, void *data,
|
|
|
|
int *got_frame_ptr, AVPacket *avpkt)
|
2006-03-21 18:27:47 +01:00
|
|
|
{
|
2012-12-24 02:00:41 +01:00
|
|
|
AVFrame *frame = data;
|
2009-04-07 17:59:50 +02:00
|
|
|
const uint8_t *buf = avpkt->data;
|
|
|
|
int buf_size = avpkt->size;
|
2006-03-21 18:27:47 +01:00
|
|
|
GetBitContext gb;
|
2011-06-06 14:13:02 +02:00
|
|
|
HuffContext h[4] = { { 0 } };
|
|
|
|
VLC vlc[4] = { { 0 } };
|
2011-09-06 18:17:45 +02:00
|
|
|
int16_t *samples;
|
|
|
|
uint8_t *samples8;
|
2006-03-21 18:27:47 +01:00
|
|
|
int val;
|
2011-09-06 18:17:45 +02:00
|
|
|
int i, res, ret;
|
2006-03-21 18:27:47 +01:00
|
|
|
int unp_size;
|
|
|
|
int bits, stereo;
|
|
|
|
int pred[2] = {0, 0};
|
|
|
|
|
2011-09-21 17:42:55 +02:00
|
|
|
if (buf_size <= 4) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "packet is too small\n");
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
|
|
|
|
2007-01-19 23:12:59 +01:00
|
|
|
unp_size = AV_RL32(buf);
|
2006-03-21 18:27:47 +01:00
|
|
|
|
2012-11-24 18:02:08 +01:00
|
|
|
if (unp_size > (1U<<24)) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "packet is too big\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
|
|
|
|
2006-03-21 18:27:47 +01:00
|
|
|
init_get_bits(&gb, buf + 4, (buf_size - 4) * 8);
|
|
|
|
|
|
|
|
if(!get_bits1(&gb)){
|
|
|
|
av_log(avctx, AV_LOG_INFO, "Sound: no data\n");
|
2011-09-06 18:17:45 +02:00
|
|
|
*got_frame_ptr = 0;
|
2006-03-21 18:27:47 +01:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
stereo = get_bits1(&gb);
|
|
|
|
bits = get_bits1(&gb);
|
2011-09-21 17:49:33 +02:00
|
|
|
if (stereo ^ (avctx->channels != 1)) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "channels mismatch\n");
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
|
|
|
if (bits && avctx->sample_fmt == AV_SAMPLE_FMT_U8) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "sample format mismatch\n");
|
|
|
|
return AVERROR(EINVAL);
|
|
|
|
}
|
2006-03-21 18:27:47 +01:00
|
|
|
|
2011-09-06 18:17:45 +02:00
|
|
|
/* get output buffer */
|
2012-12-24 02:00:41 +01:00
|
|
|
frame->nb_samples = unp_size / (avctx->channels * (bits + 1));
|
lavc: factorize ff_{thread_,re,}get_buffer error messages.
Coccinelle profile used:
@@
expression r, ctx, f, loglevel, str, flags;
@@
-if ((r = ff_get_buffer(ctx, f, flags)) < 0) {
- av_log(ctx, loglevel, str);
- return r;
-}
+if ((r = ff_get_buffer(ctx, f, flags)) < 0)
+ return r;
@@
expression r, ctx, f, loglevel, str;
@@
-if ((r = ff_reget_buffer(ctx, f)) < 0) {
- av_log(ctx, loglevel, str);
- return r;
-}
+if ((r = ff_reget_buffer(ctx, f)) < 0)
+ return r;
@@
expression r, ctx, f, loglevel, str, flags;
@@
-if ((r = ff_thread_get_buffer(ctx, f, flags)) < 0) {
- av_log(ctx, loglevel, str);
- return r;
-}
+if ((r = ff_thread_get_buffer(ctx, f, flags)) < 0)
+ return r;
...along with some manual patches for the remaining ones.
2013-03-12 08:41:53 +01:00
|
|
|
if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
|
2011-09-06 18:17:45 +02:00
|
|
|
return ret;
|
2012-12-24 02:00:41 +01:00
|
|
|
samples = (int16_t *)frame->data[0];
|
|
|
|
samples8 = frame->data[0];
|
2011-09-06 18:17:45 +02:00
|
|
|
|
2006-03-21 18:27:47 +01:00
|
|
|
// Initialize
|
|
|
|
for(i = 0; i < (1 << (bits + stereo)); i++) {
|
|
|
|
h[i].length = 256;
|
|
|
|
h[i].maxlength = 0;
|
|
|
|
h[i].current = 0;
|
|
|
|
h[i].bits = av_mallocz(256 * 4);
|
|
|
|
h[i].lengths = av_mallocz(256 * sizeof(int));
|
|
|
|
h[i].values = av_mallocz(256 * sizeof(int));
|
2007-08-09 02:57:36 +02:00
|
|
|
skip_bits1(&gb);
|
2013-06-12 14:27:00 +02:00
|
|
|
if (smacker_decode_tree(&gb, &h[i], 0, 0) < 0) {
|
|
|
|
for (; i >= 0; i--) {
|
|
|
|
if (vlc[i].table)
|
|
|
|
ff_free_vlc(&vlc[i]);
|
|
|
|
av_free(h[i].bits);
|
|
|
|
av_free(h[i].lengths);
|
|
|
|
av_free(h[i].values);
|
|
|
|
}
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
2007-08-09 02:57:36 +02:00
|
|
|
skip_bits1(&gb);
|
2006-03-25 16:37:08 +01:00
|
|
|
if(h[i].current > 1) {
|
|
|
|
res = init_vlc(&vlc[i], SMKTREE_BITS, h[i].length,
|
2006-03-21 18:27:47 +01:00
|
|
|
h[i].lengths, sizeof(int), sizeof(int),
|
|
|
|
h[i].bits, sizeof(uint32_t), sizeof(uint32_t), INIT_VLC_LE);
|
2006-03-25 16:37:08 +01:00
|
|
|
if(res < 0) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "Cannot build VLC table\n");
|
2012-11-11 11:04:04 +01:00
|
|
|
return AVERROR_INVALIDDATA;
|
2006-03-25 16:37:08 +01:00
|
|
|
}
|
2006-03-21 18:27:47 +01:00
|
|
|
}
|
|
|
|
}
|
2013-05-27 18:21:04 +02:00
|
|
|
/* this codec relies on wraparound instead of clipping audio */
|
2006-03-21 18:27:47 +01:00
|
|
|
if(bits) { //decode 16-bit data
|
2007-03-21 06:56:29 +01:00
|
|
|
for(i = stereo; i >= 0; i--)
|
2012-03-30 20:40:14 +02:00
|
|
|
pred[i] = sign_extend(av_bswap16(get_bits(&gb, 16)), 16);
|
2011-09-13 01:14:44 +02:00
|
|
|
for(i = 0; i <= stereo; i++)
|
2007-03-21 06:56:29 +01:00
|
|
|
*samples++ = pred[i];
|
2011-09-13 01:14:44 +02:00
|
|
|
for(; i < unp_size / 2; i++) {
|
2011-12-15 22:45:57 +01:00
|
|
|
if(get_bits_left(&gb)<0)
|
2012-11-11 11:04:04 +01:00
|
|
|
return AVERROR_INVALIDDATA;
|
2006-03-21 18:27:47 +01:00
|
|
|
if(i & stereo) {
|
2006-03-25 16:37:08 +01:00
|
|
|
if(vlc[2].table)
|
|
|
|
res = get_vlc2(&gb, vlc[2].table, SMKTREE_BITS, 3);
|
|
|
|
else
|
|
|
|
res = 0;
|
2012-04-16 16:39:02 +02:00
|
|
|
if (res < 0) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "invalid vlc\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
2006-03-25 16:37:08 +01:00
|
|
|
val = h[2].values[res];
|
|
|
|
if(vlc[3].table)
|
|
|
|
res = get_vlc2(&gb, vlc[3].table, SMKTREE_BITS, 3);
|
|
|
|
else
|
|
|
|
res = 0;
|
2012-04-16 16:39:02 +02:00
|
|
|
if (res < 0) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "invalid vlc\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
2006-03-25 16:37:08 +01:00
|
|
|
val |= h[3].values[res] << 8;
|
2011-11-09 22:19:52 +01:00
|
|
|
pred[1] += sign_extend(val, 16);
|
2013-05-20 21:42:06 +02:00
|
|
|
*samples++ = pred[1];
|
2006-03-21 18:27:47 +01:00
|
|
|
} else {
|
2006-03-25 16:37:08 +01:00
|
|
|
if(vlc[0].table)
|
|
|
|
res = get_vlc2(&gb, vlc[0].table, SMKTREE_BITS, 3);
|
|
|
|
else
|
|
|
|
res = 0;
|
2012-04-16 16:39:02 +02:00
|
|
|
if (res < 0) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "invalid vlc\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
2006-03-25 16:37:08 +01:00
|
|
|
val = h[0].values[res];
|
|
|
|
if(vlc[1].table)
|
|
|
|
res = get_vlc2(&gb, vlc[1].table, SMKTREE_BITS, 3);
|
|
|
|
else
|
|
|
|
res = 0;
|
2012-04-16 16:39:02 +02:00
|
|
|
if (res < 0) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "invalid vlc\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
2006-03-25 16:37:08 +01:00
|
|
|
val |= h[1].values[res] << 8;
|
2011-11-09 22:19:52 +01:00
|
|
|
pred[0] += sign_extend(val, 16);
|
2013-05-20 21:42:06 +02:00
|
|
|
*samples++ = pred[0];
|
2006-03-21 18:27:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else { //8-bit data
|
2007-03-21 06:56:29 +01:00
|
|
|
for(i = stereo; i >= 0; i--)
|
|
|
|
pred[i] = get_bits(&gb, 8);
|
2011-09-13 01:14:44 +02:00
|
|
|
for(i = 0; i <= stereo; i++)
|
2009-03-21 16:52:14 +01:00
|
|
|
*samples8++ = pred[i];
|
2011-09-13 01:14:44 +02:00
|
|
|
for(; i < unp_size; i++) {
|
2011-12-15 22:45:57 +01:00
|
|
|
if(get_bits_left(&gb)<0)
|
2012-11-11 11:04:04 +01:00
|
|
|
return AVERROR_INVALIDDATA;
|
2006-03-21 18:27:47 +01:00
|
|
|
if(i & stereo){
|
2006-03-25 16:37:08 +01:00
|
|
|
if(vlc[1].table)
|
|
|
|
res = get_vlc2(&gb, vlc[1].table, SMKTREE_BITS, 3);
|
|
|
|
else
|
|
|
|
res = 0;
|
2012-04-16 16:39:02 +02:00
|
|
|
if (res < 0) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "invalid vlc\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
2011-11-09 22:19:52 +01:00
|
|
|
pred[1] += sign_extend(h[1].values[res], 8);
|
2013-05-27 05:40:44 +02:00
|
|
|
*samples8++ = pred[1];
|
2006-03-21 18:27:47 +01:00
|
|
|
} else {
|
2006-03-25 16:37:08 +01:00
|
|
|
if(vlc[0].table)
|
|
|
|
res = get_vlc2(&gb, vlc[0].table, SMKTREE_BITS, 3);
|
|
|
|
else
|
|
|
|
res = 0;
|
2012-04-16 16:39:02 +02:00
|
|
|
if (res < 0) {
|
|
|
|
av_log(avctx, AV_LOG_ERROR, "invalid vlc\n");
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
}
|
2011-11-09 22:19:52 +01:00
|
|
|
pred[0] += sign_extend(h[0].values[res], 8);
|
2013-05-27 05:40:44 +02:00
|
|
|
*samples8++ = pred[0];
|
2006-03-21 18:27:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(i = 0; i < 4; i++) {
|
|
|
|
if(vlc[i].table)
|
2012-02-09 10:37:58 +01:00
|
|
|
ff_free_vlc(&vlc[i]);
|
2011-02-03 02:09:36 +01:00
|
|
|
av_free(h[i].bits);
|
|
|
|
av_free(h[i].lengths);
|
|
|
|
av_free(h[i].values);
|
2006-03-21 18:27:47 +01:00
|
|
|
}
|
|
|
|
|
2012-12-24 02:00:41 +01:00
|
|
|
*got_frame_ptr = 1;
|
2011-09-06 18:17:45 +02:00
|
|
|
|
2006-03-21 18:27:47 +01:00
|
|
|
return buf_size;
|
|
|
|
}
|
|
|
|
|
2011-01-25 22:40:11 +01:00
|
|
|
AVCodec ff_smacker_decoder = {
|
2011-07-17 12:54:31 +02:00
|
|
|
.name = "smackvid",
|
|
|
|
.type = AVMEDIA_TYPE_VIDEO,
|
2012-08-05 11:11:04 +02:00
|
|
|
.id = AV_CODEC_ID_SMACKVIDEO,
|
2011-07-17 12:54:31 +02:00
|
|
|
.priv_data_size = sizeof(SmackVContext),
|
|
|
|
.init = decode_init,
|
|
|
|
.close = decode_end,
|
|
|
|
.decode = decode_frame,
|
|
|
|
.capabilities = CODEC_CAP_DR1,
|
2012-04-06 18:19:39 +02:00
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("Smacker video"),
|
2006-03-21 18:27:47 +01:00
|
|
|
};
|
|
|
|
|
2011-01-25 22:40:11 +01:00
|
|
|
AVCodec ff_smackaud_decoder = {
|
2011-07-17 12:54:31 +02:00
|
|
|
.name = "smackaud",
|
|
|
|
.type = AVMEDIA_TYPE_AUDIO,
|
2012-08-05 11:11:04 +02:00
|
|
|
.id = AV_CODEC_ID_SMACKAUDIO,
|
2011-07-17 12:54:31 +02:00
|
|
|
.init = smka_decode_init,
|
|
|
|
.decode = smka_decode_frame,
|
2011-09-06 18:17:45 +02:00
|
|
|
.capabilities = CODEC_CAP_DR1,
|
2012-04-06 18:19:39 +02:00
|
|
|
.long_name = NULL_IF_CONFIG_SMALL("Smacker audio"),
|
2006-03-21 18:27:47 +01:00
|
|
|
};
|