]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/4xm.c
h264_mvpred: constify all uses of H264Context
[ffmpeg] / libavcodec / 4xm.c
index b958e841ca9f329aaed3cbffa0ec77e1133493b0..b248d87569ea370dae1e7b6f6a97ba9263d6b01f 100644 (file)
@@ -31,8 +31,8 @@
 #include "libavutil/intreadwrite.h"
 #include "avcodec.h"
 #include "blockdsp.h"
+#include "bswapdsp.h"
 #include "bytestream.h"
-#include "dsputil.h"
 #include "get_bits.h"
 #include "internal.h"
 
@@ -132,8 +132,8 @@ typedef struct CFrameBuffer {
 
 typedef struct FourXContext {
     AVCodecContext *avctx;
-    DSPContext dsp;
     BlockDSPContext bdsp;
+    BswapDSPContext bbdsp;
     uint16_t *frame_buffer;
     uint16_t *last_frame_buffer;
     GetBitContext pre_gb;          ///< ac/dc prefix
@@ -340,22 +340,29 @@ static inline void mcdc(uint16_t *dst, uint16_t *src, int log2w,
 static int decode_p_block(FourXContext *f, uint16_t *dst, uint16_t *src,
                           int log2w, int log2h, int stride)
 {
-    const int index = size2index[log2h][log2w];
-    const int h     = 1 << log2h;
-    int code        = get_vlc2(&f->gb,
-                               block_type_vlc[1 - (f->version > 1)][index].table,
-                               BLOCK_TYPE_VLC_BITS, 1);
-    uint16_t *start = f->last_frame_buffer;
-    uint16_t *end   = start + stride * (f->avctx->height - h + 1) - (1 << log2w);
-    int ret;
-    int scale   = 1;
+    int index, h, code, ret, scale = 1;
+    uint16_t *start, *end;
     unsigned dc = 0;
 
-    if (code < 0 || code > 6 || log2w < 0)
+    if (log2h < 0 || log2w < 0)
+        return AVERROR_INVALIDDATA;
+
+    index = size2index[log2h][log2w];
+    if (index < 0)
+        return AVERROR_INVALIDDATA;
+
+    h     = 1 << log2h;
+    code  = get_vlc2(&f->gb, block_type_vlc[1 - (f->version > 1)][index].table,
+                     BLOCK_TYPE_VLC_BITS, 1);
+    if (code < 0 || code > 6)
         return AVERROR_INVALIDDATA;
 
+    start = f->last_frame_buffer;
+    end   = start + stride * (f->avctx->height - h + 1) - (1 << log2w);
+
     if (code == 1) {
-        log2h--;
+        if (--log2h < 0)
+            return AVERROR_INVALIDDATA;
         if ((ret = decode_p_block(f, dst, src, log2w, log2h, stride)) < 0)
             return ret;
         return decode_p_block(f, dst + (stride << log2h),
@@ -442,8 +449,8 @@ static int decode_p_frame(FourXContext *f, const uint8_t *buf, int length)
                    bitstream_size + FF_INPUT_BUFFER_PADDING_SIZE);
     if (!f->bitstream_buffer)
         return AVERROR(ENOMEM);
-    f->dsp.bswap_buf(f->bitstream_buffer, (const uint32_t*)(buf + extra),
-                     bitstream_size / 4);
+    f->bbdsp.bswap_buf(f->bitstream_buffer, (const uint32_t *) (buf + extra),
+                       bitstream_size / 4);
     memset((uint8_t*)f->bitstream_buffer + bitstream_size,
            0, FF_INPUT_BUFFER_PADDING_SIZE);
     init_get_bits(&f->gb, f->bitstream_buffer, 8 * bitstream_size);
@@ -765,8 +772,8 @@ static int decode_i_frame(FourXContext *f, const uint8_t *buf, int length)
                    prestream_size + FF_INPUT_BUFFER_PADDING_SIZE);
     if (!f->bitstream_buffer)
         return AVERROR(ENOMEM);
-    f->dsp.bswap_buf(f->bitstream_buffer, (const uint32_t*)prestream,
-                     prestream_size / 4);
+    f->bbdsp.bswap_buf(f->bitstream_buffer, (const uint32_t *) prestream,
+                       prestream_size / 4);
     memset((uint8_t*)f->bitstream_buffer + prestream_size,
            0, FF_INPUT_BUFFER_PADDING_SIZE);
     init_get_bits(&f->pre_gb, f->bitstream_buffer, 8 * prestream_size);
@@ -820,9 +827,6 @@ static int decode_frame(AVCodecContext *avctx, void *data,
         const int data_size  = buf_size - 20;
         CFrameBuffer *cfrm;
 
-        if (data_size < 0)
-            return AVERROR_INVALIDDATA;
-
         id         = AV_RL32(buf + 12);
         whole_size = AV_RL32(buf + 16);
 
@@ -956,7 +960,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
 
     f->version = AV_RL32(avctx->extradata) >> 16;
     ff_blockdsp_init(&f->bdsp, avctx);
-    ff_dsputil_init(&f->dsp, avctx);
+    ff_bswapdsp_init(&f->bbdsp);
     f->avctx = avctx;
     init_vlcs(f);