* Smacker decoder
* Copyright (c) 2006 Konstantin Shishkov
*
- * This file is part of FFmpeg.
+ * This file is part of Libav.
*
- * FFmpeg is free software; you can redistribute it and/or
+ * Libav is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
- * FFmpeg is distributed in the hope that it will be useful,
+ * Libav is distributed in the hope that it will be useful,
* 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
- * License along with FFmpeg; if not, write to the Free Software
+ * License along with Libav; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
- * @file smacker.c
+ * @file
* Smacker decoder
*/
#include <stdlib.h>
#include "avcodec.h"
+#include "libavutil/audioconvert.h"
#define ALT_BITSTREAM_READER_LE
-#include "bitstream.h"
+#include "get_bits.h"
#include "bytestream.h"
#define SMKTREE_BITS 9
}
/**
- * Store large tree as FFmpeg's vlc codes
+ * Store large tree as Libav's vlc codes
*/
static int smacker_decode_header_tree(SmackVContext *smk, GetBitContext *gb, int **recodes, int *last, int size)
{
return v;
}
-static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, const uint8_t *buf, int buf_size)
+static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
{
+ const uint8_t *buf = avpkt->data;
+ int buf_size = avpkt->size;
SmackVContext * const smk = avctx->priv_data;
uint8_t *out;
uint32_t *pal;
if(buf_size <= 769)
return 0;
- if(smk->pic.data[0])
- avctx->release_buffer(avctx, &smk->pic);
smk->pic.reference = 1;
smk->pic.buffer_hints = FF_BUFFER_HINTS_VALID | FF_BUFFER_HINTS_PRESERVE | FF_BUFFER_HINTS_REUSABLE;
smk->pic.palette_has_changed = buf[0] & 1;
smk->pic.key_frame = !!(buf[0] & 2);
if(smk->pic.key_frame)
- smk->pic.pict_type = FF_I_TYPE;
+ smk->pic.pict_type = AV_PICTURE_TYPE_I;
else
- smk->pic.pict_type = FF_P_TYPE;
+ smk->pic.pict_type = AV_PICTURE_TYPE_P;
buf++;
for(i = 0; i < 256; i++)
case 2:
for(i = 0; i < 2; i++) {
uint16_t pix1, pix2;
- pix1 = smk_get_code(&gb, smk->full_tbl, smk->full_last);
pix2 = smk_get_code(&gb, smk->full_tbl, smk->full_last);
+ pix1 = smk_get_code(&gb, smk->full_tbl, smk->full_last);
AV_WL16(out,pix1);
AV_WL16(out+2,pix2);
out += stride;
c->avctx = avctx;
- c->pic.data[0] = NULL;
-
- if (avcodec_check_dimensions(avctx, avctx->width, avctx->height) < 0) {
- return 1;
- }
-
avctx->pix_fmt = PIX_FMT_PAL8;
static av_cold int smka_decode_init(AVCodecContext *avctx)
{
- avctx->sample_fmt = SAMPLE_FMT_S16;
+ avctx->channel_layout = (avctx->channels==2) ? AV_CH_LAYOUT_STEREO : AV_CH_LAYOUT_MONO;
+ avctx->sample_fmt = avctx->bits_per_coded_sample == 8 ? AV_SAMPLE_FMT_U8 : AV_SAMPLE_FMT_S16;
return 0;
}
/**
* Decode Smacker audio data
*/
-static int smka_decode_frame(AVCodecContext *avctx, void *data, int *data_size, const uint8_t *buf, int buf_size)
+static int smka_decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt)
{
+ const uint8_t *buf = avpkt->data;
+ int buf_size = avpkt->size;
GetBitContext gb;
HuffContext h[4];
VLC vlc[4];
int16_t *samples = data;
+ int8_t *samples8 = data;
int val;
int i, res;
int unp_size;
}
stereo = get_bits1(&gb);
bits = get_bits1(&gb);
- if (unp_size & 0xC0000000 || (unp_size << !bits) > *data_size) {
+ if (unp_size & 0xC0000000 || unp_size > *data_size) {
av_log(avctx, AV_LOG_ERROR, "Frame is too large to fit in buffer\n");
return -1;
}
}
if(bits) { //decode 16-bit data
for(i = stereo; i >= 0; i--)
- pred[i] = bswap_16(get_bits(&gb, 16));
+ pred[i] = av_bswap16(get_bits(&gb, 16));
for(i = 0; i < stereo; i++)
*samples++ = pred[i];
for(i = 0; i < unp_size / 2; i++) {
for(i = stereo; i >= 0; i--)
pred[i] = get_bits(&gb, 8);
for(i = 0; i < stereo; i++)
- *samples++ = (pred[i] - 0x80) << 8;
+ *samples8++ = pred[i];
for(i = 0; i < unp_size; i++) {
if(i & stereo){
if(vlc[1].table)
else
res = 0;
pred[1] += (int8_t)h[1].values[res];
- *samples++ = (pred[1] - 0x80) << 8;
+ *samples8++ = pred[1];
} else {
if(vlc[0].table)
res = get_vlc2(&gb, vlc[0].table, SMKTREE_BITS, 3);
else
res = 0;
pred[0] += (int8_t)h[0].values[res];
- *samples++ = (pred[0] - 0x80) << 8;
+ *samples8++ = pred[0];
}
}
- unp_size *= 2;
}
for(i = 0; i < 4; i++) {
if(vlc[i].table)
free_vlc(&vlc[i]);
- if(h[i].bits)
- av_free(h[i].bits);
- if(h[i].lengths)
- av_free(h[i].lengths);
- if(h[i].values)
- av_free(h[i].values);
+ av_free(h[i].bits);
+ av_free(h[i].lengths);
+ av_free(h[i].values);
}
*data_size = unp_size;
return buf_size;
}
-AVCodec smacker_decoder = {
+AVCodec ff_smacker_decoder = {
"smackvid",
- CODEC_TYPE_VIDEO,
+ AVMEDIA_TYPE_VIDEO,
CODEC_ID_SMACKVIDEO,
sizeof(SmackVContext),
decode_init,
NULL,
decode_end,
decode_frame,
+ CODEC_CAP_DR1,
.long_name = NULL_IF_CONFIG_SMALL("Smacker video"),
};
-AVCodec smackaud_decoder = {
+AVCodec ff_smackaud_decoder = {
"smackaud",
- CODEC_TYPE_AUDIO,
+ AVMEDIA_TYPE_AUDIO,
CODEC_ID_SMACKAUDIO,
0,
smka_decode_init,