Browse code

avcodec/rpza: Move frame allocation to a later point

This will allow performing some fast checks before the slow allocation

Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit 8a708aa99cb0e8d76e52117b1fd89d221f0055e9)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>

Michael Niedermayer authored on 2018/12/17 03:04:56
Showing 1 changed files
... ...
@@ -73,13 +73,12 @@ typedef struct RpzaContext {
73 73
 static int rpza_decode_stream(RpzaContext *s)
74 74
 {
75 75
     int width = s->avctx->width;
76
-    int stride = s->frame->linesize[0] / 2;
77
-    int row_inc = stride - 4;
76
+    int stride, row_inc, ret;
78 77
     int chunk_size;
79 78
     uint16_t colorA = 0, colorB;
80 79
     uint16_t color4[4];
81 80
     uint16_t ta, tb;
82
-    uint16_t *pixels = (uint16_t *)s->frame->data[0];
81
+    uint16_t *pixels;
83 82
 
84 83
     int row_ptr = 0;
85 84
     int pixel_ptr = 0;
... ...
@@ -106,6 +105,12 @@ static int rpza_decode_stream(RpzaContext *s)
106 106
     /* Number of 4x4 blocks in frame. */
107 107
     total_blocks = ((s->avctx->width + 3) / 4) * ((s->avctx->height + 3) / 4);
108 108
 
109
+    if ((ret = ff_reget_buffer(s->avctx, s->frame)) < 0)
110
+        return ret;
111
+    pixels = (uint16_t *)s->frame->data[0];
112
+    stride = s->frame->linesize[0] / 2;
113
+    row_inc = stride - 4;
114
+
109 115
     /* Process chunk data */
110 116
     while (bytestream2_get_bytes_left(&s->gb)) {
111 117
         uint8_t opcode = bytestream2_get_byte(&s->gb); /* Get opcode */
... ...
@@ -256,9 +261,6 @@ static int rpza_decode_frame(AVCodecContext *avctx,
256 256
 
257 257
     bytestream2_init(&s->gb, avpkt->data, avpkt->size);
258 258
 
259
-    if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)
260
-        return ret;
261
-
262 259
     ret = rpza_decode_stream(s);
263 260
     if (ret < 0)
264 261
         return ret;