X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fescape124.c;h=4ca4ff3951a92c2a9e21851a2fef29e98e9da4b0;hb=bc9c70e5a33b988a2cb2e42777dc976dafd6e849;hp=bf843351801ae2b1630a9317c5e111c19cb53692;hpb=1354fa6442d4cb9ad1d96ee03010b3cd46068f41;p=ffmpeg diff --git a/libavcodec/escape124.c b/libavcodec/escape124.c index bf843351801..4ca4ff3951a 100644 --- a/libavcodec/escape124.c +++ b/libavcodec/escape124.c @@ -2,27 +2,27 @@ * Escape 124 Video Decoder * Copyright (C) 2008 Eli Friedman (eli.friedman@gmail.com) * - * 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 */ #include "avcodec.h" -#define ALT_BITSTREAM_READER_LE -#include "bitstream.h" +#define BITSTREAM_READER_LE +#include "get_bits.h" typedef union MacroBlock { uint16_t pixels[4]; @@ -37,7 +37,7 @@ typedef union SuperBlock { typedef struct CodeBook { unsigned depth; unsigned size; - MacroBlock blocks[0]; + MacroBlock* blocks; } CodeBook; typedef struct Escape124Context { @@ -45,7 +45,7 @@ typedef struct Escape124Context { unsigned num_superblocks; - CodeBook* codebooks[3]; + CodeBook codebooks[3]; } Escape124Context; static int can_safely_read(GetBitContext* gb, int bits) { @@ -75,7 +75,7 @@ static av_cold int escape124_decode_close(AVCodecContext *avctx) Escape124Context *s = avctx->priv_data; for (i = 0; i < 3; i++) - av_free(s->codebooks[i]); + av_free(s->codebooks[i].blocks); if (s->frame.data[0]) avctx->release_buffer(avctx, &s->frame); @@ -83,23 +83,23 @@ static av_cold int escape124_decode_close(AVCodecContext *avctx) return 0; } -static CodeBook* unpack_codebook(GetBitContext* gb, unsigned depth, +static CodeBook unpack_codebook(GetBitContext* gb, unsigned depth, unsigned size) { unsigned i, j; - CodeBook* cb; + CodeBook cb = { 0 }; if (!can_safely_read(gb, size * 34)) - return NULL; + return cb; - if (size >= (INT_MAX - sizeof(CodeBook)) / sizeof(MacroBlock)) - return NULL; - cb = av_malloc(size * sizeof(MacroBlock) + sizeof(CodeBook)); - if (!cb) - return NULL; + if (size >= INT_MAX / sizeof(MacroBlock)) + return cb; + cb.blocks = av_malloc(size ? size * sizeof(MacroBlock) : 1); + if (!cb.blocks) + return cb; - cb->depth = depth; - cb->size = size; + cb.depth = depth; + cb.size = size; for (i = 0; i < size; i++) { unsigned mask_bits = get_bits(gb, 4); unsigned color0 = get_bits(gb, 15); @@ -107,9 +107,9 @@ static CodeBook* unpack_codebook(GetBitContext* gb, unsigned depth, for (j = 0; j < 4; j++) { if (mask_bits & (1 << j)) - cb->blocks[i].pixels[j] = color1; + cb.blocks[i].pixels[j] = color1; else - cb->blocks[i].pixels[j] = color0; + cb.blocks[i].pixels[j] = color0; } } return cb; @@ -149,7 +149,7 @@ static MacroBlock decode_macroblock(Escape124Context* s, GetBitContext* gb, *codebook_index = transitions[*codebook_index][get_bits1(gb)]; } - depth = s->codebooks[*codebook_index]->depth; + depth = s->codebooks[*codebook_index].depth; // depth = 0 means that this shouldn't read any bits; // in theory, this is the same as get_bits(gb, 0), but @@ -157,15 +157,15 @@ static MacroBlock decode_macroblock(Escape124Context* s, GetBitContext* gb, block_index = depth ? get_bits(gb, depth) : 0; if (*codebook_index == 1) { - block_index += superblock_index << s->codebooks[1]->depth; + block_index += superblock_index << s->codebooks[1].depth; } // This condition can occur with invalid bitstreams and // *codebook_index == 2 - if (block_index >= s->codebooks[*codebook_index]->size) + if (block_index >= s->codebooks[*codebook_index].size) return (MacroBlock) { { 0 } }; - return s->codebooks[*codebook_index]->blocks[block_index]; + return s->codebooks[*codebook_index].blocks[block_index]; } static void insert_mb_into_sb(SuperBlock* sb, MacroBlock mb, unsigned index) { @@ -195,19 +195,12 @@ static const uint16_t mask_matrix[] = {0x1, 0x2, 0x10, 0x20, 0x100, 0x200, 0x1000, 0x2000, 0x400, 0x800, 0x4000, 0x8000}; -/** - * Decode a single frame - * @param avctx decoder context - * @param data decoded frame - * @param data_size size of the decoded frame - * @param buf input buffer - * @param buf_size input buffer size - * @return 0 success, -1 on error - */ static int escape124_decode_frame(AVCodecContext *avctx, void *data, int *data_size, - const uint8_t *buf, int buf_size) + AVPacket *avpkt) { + const uint8_t *buf = avpkt->data; + int buf_size = avpkt->size; Escape124Context *s = avctx->priv_data; GetBitContext gb; @@ -265,9 +258,9 @@ static int escape124_decode_frame(AVCodecContext *avctx, cb_size = s->num_superblocks << cb_depth; } } - av_free(s->codebooks[i]); + av_free(s->codebooks[i].blocks); s->codebooks[i] = unpack_codebook(&gb, cb_depth, cb_size); - if (!s->codebooks[i]) + if (!s->codebooks[i].blocks) return -1; } } @@ -370,15 +363,14 @@ static int escape124_decode_frame(AVCodecContext *avctx, } -AVCodec escape124_decoder = { - "escape124", - CODEC_TYPE_VIDEO, - CODEC_ID_ESCAPE124, - sizeof(Escape124Context), - escape124_decode_init, - NULL, - escape124_decode_close, - escape124_decode_frame, - CODEC_CAP_DR1, +AVCodec ff_escape124_decoder = { + .name = "escape124", + .type = AVMEDIA_TYPE_VIDEO, + .id = CODEC_ID_ESCAPE124, + .priv_data_size = sizeof(Escape124Context), + .init = escape124_decode_init, + .close = escape124_decode_close, + .decode = escape124_decode_frame, + .capabilities = CODEC_CAP_DR1, + .long_name = NULL_IF_CONFIG_SMALL("Escape 124"), }; -