diff options
author | FlyingRat <flyingrat@outlook.com> | 2013-04-07 16:36:04 +0200 |
---|---|---|
committer | FlyingRat <flyingrat@outlook.com> | 2013-04-07 16:36:04 +0200 |
commit | 0e63a815aa6af63a21848e04b683d3f506dd41b1 (patch) | |
tree | 002f61d8a5b1d294d99fd4ba5b6982d76a612f0c /lib/ffmpeg/libavcodec/dxa.c | |
parent | 71862137c5337fc678681a23bfbc65f4db7a7b2f (diff) |
[FFmpeg] version bump to n1.2 (rev e820e3a) - lib/ffmpeg
This commit now contains the original patches sub directory:
patches - Org dir that contains applied xbmc custom patches.
patches/README-patches - New README file with info about xbmc patches.
patches/obsolete-patches - New dir with obsolete xbmc patches.
Diffstat (limited to 'lib/ffmpeg/libavcodec/dxa.c')
-rw-r--r-- | lib/ffmpeg/libavcodec/dxa.c | 73 |
1 files changed, 38 insertions, 35 deletions
diff --git a/lib/ffmpeg/libavcodec/dxa.c b/lib/ffmpeg/libavcodec/dxa.c index f32fdd33e5..a2fe5578df 100644 --- a/lib/ffmpeg/libavcodec/dxa.c +++ b/lib/ffmpeg/libavcodec/dxa.c @@ -27,8 +27,11 @@ #include <stdio.h> #include <stdlib.h> +#include "libavutil/common.h" #include "libavutil/intreadwrite.h" +#include "bytestream.h" #include "avcodec.h" +#include "internal.h" #include <zlib.h> @@ -36,7 +39,6 @@ * Decoder context */ typedef struct DxaDecContext { - AVCodecContext *avctx; AVFrame pic, prev; int dsize; @@ -179,7 +181,7 @@ static int decode_13(AVCodecContext *avctx, DxaDecContext *c, uint8_t* dst, uint break; default: av_log(avctx, AV_LOG_ERROR, "Unknown opcode %d\n", type); - return -1; + return AVERROR_INVALIDDATA; } } dst += stride * 4; @@ -188,36 +190,30 @@ static int decode_13(AVCodecContext *avctx, DxaDecContext *c, uint8_t* dst, uint return 0; } -static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPacket *avpkt) +static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt) { - const uint8_t *buf = avpkt->data; - int buf_size = avpkt->size; DxaDecContext * const c = avctx->priv_data; uint8_t *outptr, *srcptr, *tmpptr; unsigned long dsize; - int i, j, compr; + int i, j, compr, ret; int stride; - int orig_buf_size = buf_size; int pc = 0; + GetByteContext gb; - /* make the palette available on the way out */ - if(buf[0]=='C' && buf[1]=='M' && buf[2]=='A' && buf[3]=='P'){ - int r, g, b; + bytestream2_init(&gb, avpkt->data, avpkt->size); - buf += 4; + /* make the palette available on the way out */ + if (bytestream2_peek_le32(&gb) == MKTAG('C','M','A','P')) { + bytestream2_skip(&gb, 4); for(i = 0; i < 256; i++){ - r = *buf++; - g = *buf++; - b = *buf++; - c->pal[i] = 0xFF << 24 | r << 16 | g << 8 | b; + c->pal[i] = 0xFFU << 24 | bytestream2_get_be24(&gb); } pc = 1; - buf_size -= 768+4; } - if(avctx->get_buffer(avctx, &c->pic) < 0){ + if ((ret = ff_get_buffer(avctx, &c->pic)) < 0) { av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); - return -1; + return ret; } memcpy(c->pic.data[1], c->pal, AVPALETTE_SIZE); c->pic.palette_has_changed = pc; @@ -227,15 +223,19 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac tmpptr = c->prev.data[0]; stride = c->pic.linesize[0]; - if(buf[0]=='N' && buf[1]=='U' && buf[2]=='L' && buf[3]=='L') + if (bytestream2_get_le32(&gb) == MKTAG('N','U','L','L')) compr = -1; else - compr = buf[4]; + compr = bytestream2_get_byte(&gb); dsize = c->dsize; - if((compr != 4 && compr != -1) && uncompress(c->decomp_buf, &dsize, buf + 9, buf_size - 9) != Z_OK){ - av_log(avctx, AV_LOG_ERROR, "Uncompress failed!\n"); - return -1; + if (compr != 4 && compr != -1) { + bytestream2_skip(&gb, 4); + if (uncompress(c->decomp_buf, &dsize, avpkt->data + bytestream2_tell(&gb), + bytestream2_get_bytes_left(&gb)) != Z_OK) { + av_log(avctx, AV_LOG_ERROR, "Uncompress failed!\n"); + return AVERROR_UNKNOWN; + } } switch(compr){ case -1: @@ -256,7 +256,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac c->pic.key_frame = !(compr & 1); c->pic.pict_type = (compr & 1) ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I; for(j = 0; j < avctx->height; j++){ - if(compr & 1){ + if((compr & 1) && tmpptr){ for(i = 0; i < avctx->width; i++) outptr[i] = srcptr[i] ^ tmpptr[i]; tmpptr += stride; @@ -270,38 +270,42 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac case 13: c->pic.key_frame = 0; c->pic.pict_type = AV_PICTURE_TYPE_P; + if (!c->prev.data[0]) { + av_log(avctx, AV_LOG_ERROR, "Missing reference frame\n"); + return AVERROR_INVALIDDATA; + } decode_13(avctx, c, c->pic.data[0], srcptr, c->prev.data[0]); break; default: - av_log(avctx, AV_LOG_ERROR, "Unknown/unsupported compression type %d\n", buf[4]); - return -1; + av_log(avctx, AV_LOG_ERROR, "Unknown/unsupported compression type %d\n", compr); + return AVERROR_INVALIDDATA; } FFSWAP(AVFrame, c->pic, c->prev); if(c->pic.data[0]) avctx->release_buffer(avctx, &c->pic); - *data_size = sizeof(AVFrame); + *got_frame = 1; *(AVFrame*)data = c->prev; /* always report that the buffer was completely consumed */ - return orig_buf_size; + return avpkt->size; } static av_cold int decode_init(AVCodecContext *avctx) { DxaDecContext * const c = avctx->priv_data; - c->avctx = avctx; - avctx->pix_fmt = PIX_FMT_PAL8; + avctx->pix_fmt = AV_PIX_FMT_PAL8; avcodec_get_frame_defaults(&c->pic); avcodec_get_frame_defaults(&c->prev); c->dsize = avctx->width * avctx->height * 2; - if((c->decomp_buf = av_malloc(c->dsize)) == NULL) { + c->decomp_buf = av_malloc(c->dsize); + if (!c->decomp_buf) { av_log(avctx, AV_LOG_ERROR, "Can't allocate decompression buffer.\n"); - return -1; + return AVERROR(ENOMEM); } return 0; @@ -323,12 +327,11 @@ static av_cold int decode_end(AVCodecContext *avctx) AVCodec ff_dxa_decoder = { .name = "dxa", .type = AVMEDIA_TYPE_VIDEO, - .id = CODEC_ID_DXA, + .id = AV_CODEC_ID_DXA, .priv_data_size = sizeof(DxaDecContext), .init = decode_init, .close = decode_end, .decode = decode_frame, .capabilities = CODEC_CAP_DR1, - .long_name = NULL_IF_CONFIG_SMALL("Feeble Files/ScummVM DXA"), + .long_name = NULL_IF_CONFIG_SMALL("Feeble Files/ScummVM DXA"), }; - |