aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2014-07-30 19:59:38 +0200
committerMichael Niedermayer <michaelni@gmx.at>2014-07-30 19:59:38 +0200
commit357325603719a1283a7375b6df9ddb7fafe203fe (patch)
tree2cb811d8debf9e510ce1fd346f813f3f6786dfcc
parent4ddac7199b247e4ed04296db944f29f5148e9860 (diff)
parentf9204ec56a4cf73843d1e5b8563d3584c2c05b47 (diff)
downloadffmpeg-357325603719a1283a7375b6df9ddb7fafe203fe.tar.gz
Merge commit 'f9204ec56a4cf73843d1e5b8563d3584c2c05b47' into release/2.2
* commit 'f9204ec56a4cf73843d1e5b8563d3584c2c05b47': eamad: use the bytestream2 API instead of AV_RL Conflicts: libavcodec/eamad.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
-rw-r--r--libavcodec/eamad.c40
1 files changed, 22 insertions, 18 deletions
diff --git a/libavcodec/eamad.c b/libavcodec/eamad.c
index 2d34d35a54..950d8f3732 100644
--- a/libavcodec/eamad.c
+++ b/libavcodec/eamad.c
@@ -29,6 +29,7 @@
*/
#include "avcodec.h"
+#include "bytestream.h"
#include "get_bits.h"
#include "aandcttab.h"
#include "eaidct.h"
@@ -237,30 +238,32 @@ static int decode_frame(AVCodecContext *avctx,
{
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
- const uint8_t *buf_end = buf+buf_size;
MadContext *s = avctx->priv_data;
AVFrame *frame = data;
+ GetByteContext gb;
int width, height;
int chunk_type;
int inter, ret;
- if (buf_size < 26) {
- av_log(avctx, AV_LOG_ERROR, "Input buffer too small\n");
- *got_frame = 0;
- return AVERROR_INVALIDDATA;
- }
+ bytestream2_init(&gb, buf, buf_size);
- chunk_type = AV_RL32(&buf[0]);
+ chunk_type = bytestream2_get_le32(&gb);
inter = (chunk_type == MADm_TAG || chunk_type == MADe_TAG);
- buf += 8;
+ bytestream2_skip(&gb, 10);
av_reduce(&avctx->time_base.num, &avctx->time_base.den,
- AV_RL16(&buf[6]), 1000, 1<<30);
+ bytestream2_get_le16(&gb), 1000, 1<<30);
+
+ width = bytestream2_get_le16(&gb);
+ height = bytestream2_get_le16(&gb);
+ bytestream2_skip(&gb, 1);
+ calc_quant_matrix(s, bytestream2_get_byte(&gb));
+ bytestream2_skip(&gb, 2);
- width = AV_RL16(&buf[8]);
- height = AV_RL16(&buf[10]);
- calc_quant_matrix(s, buf[13]);
- buf += 16;
+ if (bytestream2_get_bytes_left(&gb) < 2) {
+ av_log(avctx, AV_LOG_ERROR, "Input data too small\n");
+ return AVERROR_INVALIDDATA;
+ }
if (width < 16 || height < 16) {
av_log(avctx, AV_LOG_ERROR, "Dimensions too small\n");
@@ -269,7 +272,7 @@ static int decode_frame(AVCodecContext *avctx,
if (avctx->width != width || avctx->height != height) {
av_frame_unref(s->last_frame);
- if((width * height)/2048*7 > buf_end-buf)
+ if((width * height)/2048*7 > bytestream2_get_bytes_left(&gb))
return AVERROR_INVALIDDATA;
if ((ret = ff_set_dimensions(avctx, width, height)) < 0)
return ret;
@@ -292,12 +295,13 @@ static int decode_frame(AVCodecContext *avctx,
}
av_fast_padded_malloc(&s->bitstream_buf, &s->bitstream_buf_size,
- buf_end - buf);
+ bytestream2_get_bytes_left(&gb));
if (!s->bitstream_buf)
return AVERROR(ENOMEM);
- s->dsp.bswap16_buf(s->bitstream_buf, (const uint16_t*)buf, (buf_end-buf)/2);
- memset((uint8_t*)s->bitstream_buf + (buf_end-buf), 0, FF_INPUT_BUFFER_PADDING_SIZE);
- init_get_bits(&s->gb, s->bitstream_buf, 8*(buf_end-buf));
+ s->dsp.bswap16_buf(s->bitstream_buf, (const uint16_t *)(buf + bytestream2_tell(&gb)),
+ bytestream2_get_bytes_left(&gb) / 2);
+ memset((uint8_t*)s->bitstream_buf + bytestream2_get_bytes_left(&gb), 0, FF_INPUT_BUFFER_PADDING_SIZE);
+ init_get_bits(&s->gb, s->bitstream_buf, 8*(bytestream2_get_bytes_left(&gb)));
for (s->mb_y=0; s->mb_y < (avctx->height+15)/16; s->mb_y++)
for (s->mb_x=0; s->mb_x < (avctx->width +15)/16; s->mb_x++)