* commit '541427ab4d5b4b6f5a90a687a06decdb78e7bc3c': eamad: use the bytestream2 API instead of AV_RL Conflicts: libavcodec/eamad.c
Unified · Split
| @@ -29,6 +29,7 @@ · 28 unmodified lines | ||
| 29 | 29 | */ |
| 30 | 30 | |
| 31 | 31 | #include "avcodec.h" |
| 32 | +#include "bytestream.h" | |
| 32 | 33 | #include "bswapdsp.h" |
| 33 | 34 | #include "get_bits.h" |
| 34 | 35 | #include "aandcttab.h" |
| @@ -243,30 +244,32 @@ static int decode_frame(AVCodecContext *avctx, · 208 unmodified lines | ||
| 243 | 244 | { |
| 244 | 245 | const uint8_t *buf = avpkt->data; |
| 245 | 246 | int buf_size = avpkt->size; |
| 246 | − const uint8_t *buf_end = buf+buf_size; | |
| 247 | 247 | MadContext *s = avctx->priv_data; |
| 248 | 248 | AVFrame *frame = data; |
| 249 | + GetByteContext gb; | |
| 249 | 250 | int width, height; |
| 250 | 251 | int chunk_type; |
| 251 | 252 | int inter, ret; |
| 252 | 253 | |
| 253 | − if (buf_size < 26) { | |
| 254 | − av_log(avctx, AV_LOG_ERROR, "Input buffer too small\n"); | |
| 255 | − *got_frame = 0; | |
| 256 | − return AVERROR_INVALIDDATA; | |
| 257 | − } | |
| 254 | + bytestream2_init(&gb, buf, buf_size); | |
| 258 | 255 | |
| 259 | − chunk_type = AV_RL32(&buf[0]); | |
| 256 | + chunk_type = bytestream2_get_le32(&gb); | |
| 260 | 257 | inter = (chunk_type == MADm_TAG || chunk_type == MADe_TAG); |
| 261 | − buf += 8; | |
| 258 | + bytestream2_skip(&gb, 10); | |
| 262 | 259 | |
| 263 | 260 | av_reduce(&avctx->time_base.num, &avctx->time_base.den, |
| 264 | − AV_RL16(&buf[6]), 1000, 1<<30); | |
| 261 | + bytestream2_get_le16(&gb), 1000, 1<<30); | |
| 262 | + | |
| 263 | + width = bytestream2_get_le16(&gb); | |
| 264 | + height = bytestream2_get_le16(&gb); | |
| 265 | + bytestream2_skip(&gb, 1); | |
| 266 | + calc_quant_matrix(s, bytestream2_get_byte(&gb)); | |
| 267 | + bytestream2_skip(&gb, 2); | |
| 265 | 268 | |
| 266 | − width = AV_RL16(&buf[8]); | |
| 267 | − height = AV_RL16(&buf[10]); | |
| 268 | − calc_quant_matrix(s, buf[13]); | |
| 269 | − buf += 16; | |
| 269 | + if (bytestream2_get_bytes_left(&gb) < 2) { | |
| 270 | + av_log(avctx, AV_LOG_ERROR, "Input data too small\n"); | |
| 271 | + return AVERROR_INVALIDDATA; | |
| 272 | + } | |
| 270 | 273 | |
| 271 | 274 | if (width < 16 || height < 16) { |
| 272 | 275 | av_log(avctx, AV_LOG_ERROR, "Dimensions too small\n"); |
| @@ -275,7 +278,7 @@ static int decode_frame(AVCodecContext *avctx, · 2 unmodified lines | ||
| 275 | 278 | |
| 276 | 279 | if (avctx->width != width || avctx->height != height) { |
| 277 | 280 | av_frame_unref(s->last_frame); |
| 278 | − if((width * height)/2048*7 > buf_end-buf) | |
| 281 | + if((width * height)/2048*7 > bytestream2_get_bytes_left(&gb)) | |
| 279 | 282 | return AVERROR_INVALIDDATA; |
| 280 | 283 | if ((ret = ff_set_dimensions(avctx, width, height)) < 0) |
| 281 | 284 | return ret; |
| @@ -298,13 +301,13 @@ static int decode_frame(AVCodecContext *avctx, · 16 unmodified lines | ||
| 298 | 301 | } |
| 299 | 302 | |
| 300 | 303 | av_fast_padded_malloc(&s->bitstream_buf, &s->bitstream_buf_size, |
| 301 | − buf_end - buf); | |
| 304 | + bytestream2_get_bytes_left(&gb)); | |
| 302 | 305 | if (!s->bitstream_buf) |
| 303 | 306 | return AVERROR(ENOMEM); |
| 304 | − s->bbdsp.bswap16_buf(s->bitstream_buf, (const uint16_t *) buf, | |
| 305 | − (buf_end - buf) / 2); | |
| 306 | − memset((uint8_t*)s->bitstream_buf + (buf_end-buf), 0, FF_INPUT_BUFFER_PADDING_SIZE); | |
| 307 | − init_get_bits(&s->gb, s->bitstream_buf, 8*(buf_end-buf)); | |
| 307 | + s->bbdsp.bswap16_buf(s->bitstream_buf, (const uint16_t *)(buf + bytestream2_tell(&gb)), | |
| 308 | + bytestream2_get_bytes_left(&gb) / 2); | |
| 309 | + memset((uint8_t*)s->bitstream_buf + bytestream2_get_bytes_left(&gb), 0, FF_INPUT_BUFFER_PADDING_SIZE); | |
| 310 | + init_get_bits(&s->gb, s->bitstream_buf, 8*(bytestream2_get_bytes_left(&gb))); | |
| 308 | 311 | |
| 309 | 312 | for (s->mb_y=0; s->mb_y < (avctx->height+15)/16; s->mb_y++) |
| 310 | 313 | for (s->mb_x=0; s->mb_x < (avctx->width +15)/16; s->mb_x++) |