summaryrefslogtreecommitdiffstats
path: root/libavcodec/escape130.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavcodec/escape130.c')
-rw-r--r--libavcodec/escape130.c60
1 files changed, 32 insertions, 28 deletions
diff --git a/libavcodec/escape130.c b/libavcodec/escape130.c
index 0f2fcae..1dd7eed 100644
--- a/libavcodec/escape130.c
+++ b/libavcodec/escape130.c
@@ -2,20 +2,20 @@
* Escape 130 video decoder
* Copyright (C) 2008 Eli Friedman (eli.friedman <at> gmail.com)
*
- * 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
*/
@@ -24,7 +24,7 @@
#define BITSTREAM_READER_LE
#include "avcodec.h"
-#include "bitstream.h"
+#include "get_bits.h"
#include "internal.h"
typedef struct Escape130Context {
@@ -163,23 +163,26 @@ static av_cold int escape130_decode_close(AVCodecContext *avctx)
return 0;
}
-static int decode_skip_count(BitstreamContext *bc)
+static int decode_skip_count(GetBitContext* gb)
{
int value;
- value = bitstream_read_bit(bc);
+ if (get_bits_left(gb) < 1+3)
+ return -1;
+
+ value = get_bits1(gb);
if (value)
return 0;
- value = bitstream_read(bc, 3);
+ value = get_bits(gb, 3);
if (value)
return value;
- value = bitstream_read(bc, 8);
+ value = get_bits(gb, 8);
if (value)
return value + 7;
- value = bitstream_read(bc, 15);
+ value = get_bits(gb, 15);
if (value)
return value + 262;
@@ -189,11 +192,10 @@ static int decode_skip_count(BitstreamContext *bc)
static int escape130_decode_frame(AVCodecContext *avctx, void *data,
int *got_frame, AVPacket *avpkt)
{
- const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
Escape130Context *s = avctx->priv_data;
AVFrame *pic = data;
- BitstreamContext bc;
+ GetBitContext gb;
int ret;
uint8_t *old_y, *old_cb, *old_cr,
@@ -216,7 +218,9 @@ static int escape130_decode_frame(AVCodecContext *avctx, void *data,
if ((ret = ff_get_buffer(avctx, pic, 0)) < 0)
return ret;
- bitstream_init8(&bc, buf + 16, buf_size - 16);
+ if ((ret = init_get_bits8(&gb, avpkt->data, avpkt->size)) < 0)
+ return ret;
+ skip_bits_long(&gb, 16 * 8);
new_y = s->new_y;
new_cb = s->new_u;
@@ -235,7 +239,7 @@ static int escape130_decode_frame(AVCodecContext *avctx, void *data,
// Note that this call will make us skip the rest of the blocks
// if the frame ends prematurely.
if (skip == -1)
- skip = decode_skip_count(&bc);
+ skip = decode_skip_count(&gb);
if (skip == -1) {
av_log(avctx, AV_LOG_ERROR, "Error decoding skip value\n");
return AVERROR_INVALIDDATA;
@@ -250,31 +254,31 @@ static int escape130_decode_frame(AVCodecContext *avctx, void *data,
cb = old_cb[0];
cr = old_cr[0];
} else {
- if (bitstream_read_bit(&bc)) {
- unsigned sign_selector = bitstream_read(&bc, 6);
- unsigned difference_selector = bitstream_read(&bc, 2);
- y_avg = 2 * bitstream_read(&bc, 5);
+ if (get_bits1(&gb)) {
+ unsigned sign_selector = get_bits(&gb, 6);
+ unsigned difference_selector = get_bits(&gb, 2);
+ y_avg = 2 * get_bits(&gb, 5);
for (i = 0; i < 4; i++) {
y[i] = av_clip(y_avg + offset_table[difference_selector] *
sign_table[sign_selector][i], 0, 63);
}
- } else if (bitstream_read_bit(&bc)) {
- if (bitstream_read_bit(&bc)) {
- y_avg = bitstream_read(&bc, 6);
+ } else if (get_bits1(&gb)) {
+ if (get_bits1(&gb)) {
+ y_avg = get_bits(&gb, 6);
} else {
- unsigned adjust_index = bitstream_read(&bc, 3);
+ unsigned adjust_index = get_bits(&gb, 3);
y_avg = (y_avg + luma_adjust[adjust_index]) & 63;
}
for (i = 0; i < 4; i++)
y[i] = y_avg;
}
- if (bitstream_read_bit(&bc)) {
- if (bitstream_read_bit(&bc)) {
- cb = bitstream_read(&bc, 5);
- cr = bitstream_read(&bc, 5);
+ if (get_bits1(&gb)) {
+ if (get_bits1(&gb)) {
+ cb = get_bits(&gb, 5);
+ cr = get_bits(&gb, 5);
} else {
- unsigned adjust_index = bitstream_read(&bc, 3);
+ unsigned adjust_index = get_bits(&gb, 3);
cb = (cb + chroma_adjust[0][adjust_index]) & 31;
cr = (cr + chroma_adjust[1][adjust_index]) & 31;
}
@@ -333,7 +337,7 @@ static int escape130_decode_frame(AVCodecContext *avctx, void *data,
}
ff_dlog(avctx, "Frame data: provided %d bytes, used %d bytes\n",
- buf_size, bitstream_tell(&bc) >> 3);
+ buf_size, get_bits_count(&gb) >> 3);
FFSWAP(uint8_t*, s->old_y, s->new_y);
FFSWAP(uint8_t*, s->old_u, s->new_u);
OpenPOWER on IntegriCloud