summaryrefslogtreecommitdiff
path: root/libavcodec/eatgq.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavcodec/eatgq.c')
-rw-r--r--libavcodec/eatgq.c59
1 files changed, 32 insertions, 27 deletions
diff --git a/libavcodec/eatgq.c b/libavcodec/eatgq.c
index 190f4c8955..1308c07cff 100644
--- a/libavcodec/eatgq.c
+++ b/libavcodec/eatgq.c
@@ -2,20 +2,20 @@
* Electronic Arts TGQ Video Decoder
* Copyright (c) 2007-2008 Peter Ross <pross@xvid.org>
*
- * 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 St, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -31,9 +31,9 @@
#define BITSTREAM_READER_LE
#include "aandcttab.h"
#include "avcodec.h"
-#include "bitstream.h"
#include "bytestream.h"
#include "eaidct.h"
+#include "get_bits.h"
#include "idctdsp.h"
#include "internal.h"
@@ -58,44 +58,44 @@ static av_cold int tgq_decode_init(AVCodecContext *avctx)
return 0;
}
-static void tgq_decode_block(TgqContext *s, int16_t block[64], BitstreamContext *bc)
+static void tgq_decode_block(TgqContext *s, int16_t block[64], GetBitContext *gb)
{
uint8_t *perm = s->scantable.permutated;
int i, j, value;
- block[0] = bitstream_read_signed(bc, 8) * s->qtable[0];
+ block[0] = get_sbits(gb, 8) * s->qtable[0];
for (i = 1; i < 64;) {
- switch (bitstream_peek(bc, 3)) {
+ switch (show_bits(gb, 3)) {
case 4:
block[perm[i++]] = 0;
case 0:
block[perm[i++]] = 0;
- bitstream_skip(bc, 3);
+ skip_bits(gb, 3);
break;
case 5:
case 1:
- bitstream_skip(bc, 2);
- value = bitstream_read(bc, 6);
+ skip_bits(gb, 2);
+ value = get_bits(gb, 6);
for (j = 0; j < value; j++)
block[perm[i++]] = 0;
break;
case 6:
- bitstream_skip(bc, 3);
+ skip_bits(gb, 3);
block[perm[i]] = -s->qtable[perm[i]];
i++;
break;
case 2:
- bitstream_skip(bc, 3);
+ skip_bits(gb, 3);
block[perm[i]] = s->qtable[perm[i]];
i++;
break;
case 7: // 111b
case 3: // 011b
- bitstream_skip(bc, 2);
- if (bitstream_peek(bc, 6) == 0x3F) {
- bitstream_skip(bc, 6);
- block[perm[i]] = bitstream_read_signed(bc, 8) * s->qtable[perm[i]];
+ skip_bits(gb, 2);
+ if (show_bits(gb, 6) == 0x3F) {
+ skip_bits(gb, 6);
+ block[perm[i]] = get_sbits(gb, 8) * s->qtable[perm[i]];
} else {
- block[perm[i]] = bitstream_read_signed(bc, 6) * s->qtable[perm[i]];
+ block[perm[i]] = get_sbits(gb, 6) * s->qtable[perm[i]];
}
i++;
break;
@@ -148,7 +148,7 @@ static void tgq_idct_put_mb_dconly(TgqContext *s, AVFrame *frame,
}
}
-static void tgq_decode_mb(TgqContext *s, AVFrame *frame, int mb_y, int mb_x)
+static int tgq_decode_mb(TgqContext *s, AVFrame *frame, int mb_y, int mb_x)
{
int mode;
int i;
@@ -156,10 +156,13 @@ static void tgq_decode_mb(TgqContext *s, AVFrame *frame, int mb_y, int mb_x)
mode = bytestream2_get_byte(&s->gb);
if (mode > 12) {
- BitstreamContext bc;
- bitstream_init8(&bc, s->gb.buffer, FFMIN(s->gb.buffer_end - s->gb.buffer, mode));
+ GetBitContext gb;
+ int ret = init_get_bits8(&gb, s->gb.buffer, FFMIN(bytestream2_get_bytes_left(&s->gb), mode));
+ if (ret < 0)
+ return ret;
+
for (i = 0; i < 6; i++)
- tgq_decode_block(s, s->block[i], &bc);
+ tgq_decode_block(s, s->block[i], &gb);
tgq_idct_put_mb(s, s->block, frame, mb_x, mb_y);
bytestream2_skip(&s->gb, mode);
} else {
@@ -176,9 +179,11 @@ static void tgq_decode_mb(TgqContext *s, AVFrame *frame, int mb_y, int mb_x)
}
} else {
av_log(s->avctx, AV_LOG_ERROR, "unsupported mb mode %i\n", mode);
+ return -1;
}
tgq_idct_put_mb_dconly(s, frame, mb_x, mb_y, dc);
}
+ return 0;
}
static void tgq_calculate_qtable(TgqContext *s, int quant)
@@ -201,12 +206,13 @@ static int tgq_decode_frame(AVCodecContext *avctx,
TgqContext *s = avctx->priv_data;
AVFrame *frame = data;
int x, y, ret;
- int big_endian = AV_RL32(&buf[4]) > 0x000FFFFF;
+ int big_endian;
if (buf_size < 16) {
av_log(avctx, AV_LOG_WARNING, "truncated header\n");
return AVERROR_INVALIDDATA;
}
+ big_endian = AV_RL32(&buf[4]) > 0x000FFFFF;
bytestream2_init(&s->gb, buf + 8, buf_size - 8);
if (big_endian) {
s->width = bytestream2_get_be16u(&s->gb);
@@ -223,16 +229,15 @@ static int tgq_decode_frame(AVCodecContext *avctx,
tgq_calculate_qtable(s, bytestream2_get_byteu(&s->gb));
bytestream2_skip(&s->gb, 3);
- if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
- av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+ if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)
return ret;
- }
frame->key_frame = 1;
frame->pict_type = AV_PICTURE_TYPE_I;
for (y = 0; y < FFALIGN(avctx->height, 16) >> 4; y++)
for (x = 0; x < FFALIGN(avctx->width, 16) >> 4; x++)
- tgq_decode_mb(s, frame, y, x);
+ if (tgq_decode_mb(s, frame, y, x) < 0)
+ return AVERROR_INVALIDDATA;
*got_frame = 1;