X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fsmacker.c;h=3a97b720a5aac8b7ec3cc2df264be96da507b3ef;hb=20d33ee8b1d2cf5ba4b4d4a81db0ff7b4a125dd3;hp=1690518b6b17483bec27e5442768a423c415664e;hpb=fd76c37fd9f564b4e979fbe20ecfcfad13f8b4f4;p=ffmpeg diff --git a/libavcodec/smacker.c b/libavcodec/smacker.c index 1690518b6b1..3a97b720a5a 100644 --- a/libavcodec/smacker.c +++ b/libavcodec/smacker.c @@ -2,25 +2,25 @@ * 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 */ @@ -32,9 +32,10 @@ #include #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 @@ -167,7 +168,7 @@ static int smacker_decode_bigtree(GetBitContext *gb, HuffContext *hc, DBCtx *ctx } /** - * 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) { @@ -345,8 +346,10 @@ static av_always_inline int smk_get_code(GetBitContext *gb, int *recode, int *la 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; @@ -457,8 +460,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, const 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; @@ -512,12 +515,6 @@ static av_cold int decode_init(AVCodecContext *avctx) 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; @@ -558,19 +555,23 @@ static av_cold int decode_end(AVCodecContext *avctx) 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; @@ -588,7 +589,7 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data, int *data_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; } @@ -618,7 +619,7 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data, int *data_size, } 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++) { @@ -654,7 +655,7 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data, int *data_size, 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) @@ -662,49 +663,46 @@ static int smka_decode_frame(AVCodecContext *avctx, void *data, int *data_size, 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,