]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/utvideo.c
ivi_common: Initialize a variable at declaration in ff_ivi_decode_blocks().
[ffmpeg] / libavcodec / utvideo.c
index d105d2914825465dbdf8b3119ab1bcb6390fe7c8..378a1f7c1635cd59137c6e7df6097232cfc9951d 100644 (file)
@@ -31,6 +31,7 @@
 #include "bytestream.h"
 #include "get_bits.h"
 #include "dsputil.h"
+#include "thread.h"
 
 enum {
     PRED_NONE = 0,
@@ -102,16 +103,16 @@ static int build_huff(const uint8_t *src, VLC *vlc, int *fsym)
         code += 0x80000000u >> (he[i].len - 1);
     }
 
-    return init_vlc_sparse(vlc, FFMIN(he[last].len, 9), last + 1,
-                           bits,  sizeof(*bits),  sizeof(*bits),
-                           codes, sizeof(*codes), sizeof(*codes),
-                           syms,  sizeof(*syms),  sizeof(*syms), 0);
+    return ff_init_vlc_sparse(vlc, FFMIN(he[last].len, 9), last + 1,
+                              bits,  sizeof(*bits),  sizeof(*bits),
+                              codes, sizeof(*codes), sizeof(*codes),
+                              syms,  sizeof(*syms),  sizeof(*syms), 0);
 }
 
 static int decode_plane(UtvideoContext *c, int plane_no,
                         uint8_t *dst, int step, int stride,
                         int width, int height,
-                        const uint8_t *src, int src_size, int use_pred)
+                        const uint8_t *src, int use_pred)
 {
     int i, j, slice, pix;
     int sstart, send;
@@ -150,7 +151,6 @@ static int decode_plane(UtvideoContext *c, int plane_no,
     }
 
     src      += 256;
-    src_size -= 256;
 
     send = 0;
     for (slice = 0; slice < c->slices; slice++) {
@@ -206,11 +206,11 @@ static int decode_plane(UtvideoContext *c, int plane_no,
                    get_bits_left(&gb));
     }
 
-    free_vlc(&vlc);
+    ff_free_vlc(&vlc);
 
     return 0;
 fail:
-    free_vlc(&vlc);
+    ff_free_vlc(&vlc);
     return AVERROR_INVALIDDATA;
 }
 
@@ -357,39 +357,41 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac
 {
     const uint8_t *buf = avpkt->data;
     int buf_size = avpkt->size;
-    const uint8_t *buf_end = buf + buf_size;
     UtvideoContext *c = avctx->priv_data;
-    const uint8_t *ptr;
     int i, j;
     const uint8_t *plane_start[5];
     int plane_size, max_slice_size = 0, slice_start, slice_end, slice_size;
     int ret;
+    GetByteContext gb;
 
     if (c->pic.data[0])
-        avctx->release_buffer(avctx, &c->pic);
+        ff_thread_release_buffer(avctx, &c->pic);
 
     c->pic.reference = 1;
     c->pic.buffer_hints = FF_BUFFER_HINTS_VALID;
-    if ((ret = avctx->get_buffer(avctx, &c->pic)) < 0) {
+    if ((ret = ff_thread_get_buffer(avctx, &c->pic)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
         return ret;
     }
 
+    ff_thread_finish_setup(avctx);
+
     /* parse plane structure to retrieve frame flags and validate slice offsets */
-    ptr = buf;
+    bytestream2_init(&gb, buf, buf_size);
     for (i = 0; i < c->planes; i++) {
-        plane_start[i] = ptr;
-        if (buf_end - ptr < 256 + 4 * c->slices) {
+        plane_start[i] = gb.buffer;
+        if (bytestream2_get_bytes_left(&gb) < 256 + 4 * c->slices) {
             av_log(avctx, AV_LOG_ERROR, "Insufficient data for a plane\n");
             return AVERROR_INVALIDDATA;
         }
-        ptr += 256;
+        bytestream2_skipu(&gb, 256);
         slice_start = 0;
         slice_end   = 0;
         for (j = 0; j < c->slices; j++) {
-            slice_end   = bytestream_get_le32(&ptr);
+            slice_end   = bytestream2_get_le32u(&gb);
             slice_size  = slice_end - slice_start;
-            if (slice_size < 0) {
+            if (slice_end <= 0 || slice_size <= 0 ||
+                bytestream2_get_bytes_left(&gb) < slice_end) {
                 av_log(avctx, AV_LOG_ERROR, "Incorrect slice size\n");
                 return AVERROR_INVALIDDATA;
             }
@@ -397,18 +399,14 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac
             max_slice_size = FFMAX(max_slice_size, slice_size);
         }
         plane_size = slice_end;
-        if (buf_end - ptr < plane_size) {
-            av_log(avctx, AV_LOG_ERROR, "Plane size is bigger than available data\n");
-            return AVERROR_INVALIDDATA;
-        }
-        ptr += plane_size;
+        bytestream2_skipu(&gb, plane_size);
     }
-    plane_start[c->planes] = ptr;
-    if (buf_end - ptr < c->frame_info_size) {
+    plane_start[c->planes] = gb.buffer;
+    if (bytestream2_get_bytes_left(&gb) < c->frame_info_size) {
         av_log(avctx, AV_LOG_ERROR, "Not enough data for frame information\n");
         return AVERROR_INVALIDDATA;
     }
-    c->frame_info = AV_RL32(ptr);
+    c->frame_info = bytestream2_get_le32u(&gb);
     av_log(avctx, AV_LOG_DEBUG, "frame information flags %X\n", c->frame_info);
 
     c->frame_pred = (c->frame_info >> 8) & 3;
@@ -432,8 +430,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac
         for (i = 0; i < c->planes; i++) {
             ret = decode_plane(c, i, c->pic.data[0] + rgb_order[i], c->planes,
                                c->pic.linesize[0], avctx->width, avctx->height,
-                               plane_start[i], plane_start[i + 1] - plane_start[i],
-                               c->frame_pred == PRED_LEFT);
+                               plane_start[i], c->frame_pred == PRED_LEFT);
             if (ret)
                 return ret;
             if (c->frame_pred == PRED_MEDIAN)
@@ -448,8 +445,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac
         for (i = 0; i < 3; i++) {
             ret = decode_plane(c, i, c->pic.data[i], 1,
                                c->pic.linesize[i], avctx->width >> !!i, avctx->height >> !!i,
-                               plane_start[i], plane_start[i + 1] - plane_start[i],
-                               c->frame_pred == PRED_LEFT);
+                               plane_start[i], c->frame_pred == PRED_LEFT);
             if (ret)
                 return ret;
             if (c->frame_pred == PRED_MEDIAN) {
@@ -470,8 +466,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac
         for (i = 0; i < 3; i++) {
             ret = decode_plane(c, i, c->pic.data[i], 1,
                                c->pic.linesize[i], avctx->width >> !!i, avctx->height,
-                               plane_start[i], plane_start[i + 1] - plane_start[i],
-                               c->frame_pred == PRED_LEFT);
+                               plane_start[i], c->frame_pred == PRED_LEFT);
             if (ret)
                 return ret;
             if (c->frame_pred == PRED_MEDIAN) {
@@ -489,6 +484,8 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *data_size, AVPac
         break;
     }
 
+    c->pic.key_frame = 1;
+    c->pic.pict_type = AV_PICTURE_TYPE_I;
     *data_size = sizeof(AVFrame);
     *(AVFrame*)data = c->pic;
 
@@ -502,7 +499,7 @@ static av_cold int decode_init(AVCodecContext *avctx)
 
     c->avctx = avctx;
 
-    dsputil_init(&c->dsp, avctx);
+    ff_dsputil_init(&c->dsp, avctx);
 
     if (avctx->extradata_size < 16) {
         av_log(avctx, AV_LOG_ERROR, "Insufficient extradata size %d, should be at least 16\n",
@@ -557,7 +554,7 @@ static av_cold int decode_end(AVCodecContext *avctx)
     UtvideoContext * const c = avctx->priv_data;
 
     if (c->pic.data[0])
-        avctx->release_buffer(avctx, &c->pic);
+        ff_thread_release_buffer(avctx, &c->pic);
 
     av_freep(&c->slice_bits);
 
@@ -572,7 +569,6 @@ AVCodec ff_utvideo_decoder = {
     .init           = decode_init,
     .close          = decode_end,
     .decode         = decode_frame,
-    .capabilities   = CODEC_CAP_DR1,
+    .capabilities   = CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS,
     .long_name      = NULL_IF_CONFIG_SMALL("Ut Video"),
 };
-