X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fdsicinav.c;h=4c6c41c2feb650526c6575cb31e1ba17c4031de9;hb=bd36ec55bef7c446079e192655d065fd86483876;hp=245b569433690d062b4ebbf4973c20afc9624ad6;hpb=859bdc33e4c7b0bbb7a549df484b99e341dec074;p=ffmpeg diff --git a/libavcodec/dsicinav.c b/libavcodec/dsicinav.c index 245b5694336..4c6c41c2feb 100644 --- a/libavcodec/dsicinav.c +++ b/libavcodec/dsicinav.c @@ -2,20 +2,20 @@ * Delphine Software International CIN Audio/Video Decoders * Copyright (c) 2006 Gregory Montoir (cyx@users.sourceforge.net) * - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg 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. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg 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 Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -26,6 +26,7 @@ #include "avcodec.h" #include "bytestream.h" +#include "mathops.h" typedef enum CinVideoBitmapIndex { @@ -43,6 +44,7 @@ typedef struct CinVideoContext { } CinVideoContext; typedef struct CinAudioContext { + AVFrame frame; int initial_decode_frame; int delta; } CinAudioContext; @@ -93,6 +95,7 @@ static av_cold int cinvideo_decode_init(AVCodecContext *avctx) cin->avctx = avctx; avctx->pix_fmt = PIX_FMT_PAL8; + avcodec_get_frame_defaults(&cin->frame); cin->frame.data[0] = NULL; cin->bitmap_size = avctx->width * avctx->height; @@ -221,12 +224,12 @@ static int cinvideo_decode_frame(AVCodecContext *avctx, if (palette_colors_count > 256) return AVERROR_INVALIDDATA; for (i = 0; i < palette_colors_count; ++i) { - cin->palette[i] = bytestream_get_le24(&buf); + cin->palette[i] = 0xFF << 24 | bytestream_get_le24(&buf); bitmap_frame_size -= 3; } } else { for (i = 0; i < palette_colors_count; ++i) { - cin->palette[buf[0]] = AV_RL24(buf+1); + cin->palette[buf[0]] = 0xFF << 24 | AV_RL24(buf+1); buf += 4; bitmap_frame_size -= 4; } @@ -316,40 +319,47 @@ static av_cold int cinaudio_decode_init(AVCodecContext *avctx) cin->delta = 0; avctx->sample_fmt = AV_SAMPLE_FMT_S16; + avcodec_get_frame_defaults(&cin->frame); + avctx->coded_frame = &cin->frame; + return 0; } -static int cinaudio_decode_frame(AVCodecContext *avctx, - void *data, int *data_size, - AVPacket *avpkt) +static int cinaudio_decode_frame(AVCodecContext *avctx, void *data, + int *got_frame_ptr, AVPacket *avpkt) { const uint8_t *buf = avpkt->data; - int buf_size = avpkt->size; CinAudioContext *cin = avctx->priv_data; - const uint8_t *src = buf; - int16_t *samples = data; - int delta; - - buf_size = FFMIN(buf_size, *data_size/2); + const uint8_t *buf_end = buf + avpkt->size; + int16_t *samples; + int delta, ret; + + /* get output buffer */ + cin->frame.nb_samples = avpkt->size - cin->initial_decode_frame; + if ((ret = avctx->get_buffer(avctx, &cin->frame)) < 0) { + av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); + return ret; + } + samples = (int16_t *)cin->frame.data[0]; delta = cin->delta; if (cin->initial_decode_frame) { cin->initial_decode_frame = 0; - delta = (int16_t)AV_RL16(src); src += 2; + delta = sign_extend(AV_RL16(buf), 16); + buf += 2; *samples++ = delta; - buf_size -= 2; } - while (buf_size > 0) { - delta += cinaudio_delta16_table[*src++]; + while (buf < buf_end) { + delta += cinaudio_delta16_table[*buf++]; delta = av_clip_int16(delta); *samples++ = delta; - --buf_size; } cin->delta = delta; - *data_size = (uint8_t *)samples - (uint8_t *)data; + *got_frame_ptr = 1; + *(AVFrame *)data = cin->frame; - return src - buf; + return avpkt->size; } @@ -372,5 +382,6 @@ AVCodec ff_dsicinaudio_decoder = { .priv_data_size = sizeof(CinAudioContext), .init = cinaudio_decode_init, .decode = cinaudio_decode_frame, + .capabilities = CODEC_CAP_DR1, .long_name = NULL_IF_CONFIG_SMALL("Delphine Software International CIN audio"), };