Browse code

Merge commit '4a4841d4e0f0dc50998511bf6c48b518012024db'

* commit '4a4841d4e0f0dc50998511bf6c48b518012024db':
fraps: use the AVFrame API properly.
rpza: use the AVFrame API properly.
motionpixels: use the AVFrame API properly.
vmdvideo: use the AVFrame API properly.

Conflicts:
libavcodec/fraps.c
libavcodec/motionpixels.c
libavcodec/rpza.c
libavcodec/vmdav.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>

Michael Niedermayer authored on 2013/11/17 10:24:27
Showing 3 changed files
... ...
@@ -36,7 +36,7 @@ typedef struct HuffCode {
36 36
 
37 37
 typedef struct MotionPixelsContext {
38 38
     AVCodecContext *avctx;
39
-    AVFrame frame;
39
+    AVFrame *frame;
40 40
     DSPContext dsp;
41 41
     uint8_t *changes_map;
42 42
     int offset_bits_len;
... ...
@@ -50,6 +50,19 @@ typedef struct MotionPixelsContext {
50 50
     int bswapbuf_size;
51 51
 } MotionPixelsContext;
52 52
 
53
+static av_cold int mp_decode_end(AVCodecContext *avctx)
54
+{
55
+    MotionPixelsContext *mp = avctx->priv_data;
56
+
57
+    av_freep(&mp->changes_map);
58
+    av_freep(&mp->vpt);
59
+    av_freep(&mp->hpt);
60
+    av_freep(&mp->bswapbuf);
61
+    av_frame_free(&mp->frame);
62
+
63
+    return 0;
64
+}
65
+
53 66
 static av_cold int mp_decode_init(AVCodecContext *avctx)
54 67
 {
55 68
     MotionPixelsContext *mp = avctx->priv_data;
... ...
@@ -75,7 +88,13 @@ static av_cold int mp_decode_init(AVCodecContext *avctx)
75 75
         return AVERROR(ENOMEM);
76 76
     }
77 77
     avctx->pix_fmt = AV_PIX_FMT_RGB555;
78
-    avcodec_get_frame_defaults(&mp->frame);
78
+
79
+    mp->frame = av_frame_alloc();
80
+    if (!mp->frame) {
81
+        mp_decode_end(avctx);
82
+        return AVERROR(ENOMEM);
83
+    }
84
+
79 85
     return 0;
80 86
 }
81 87
 
... ...
@@ -96,14 +115,14 @@ static void mp_read_changes_map(MotionPixelsContext *mp, GetBitContext *gb, int
96 96
             continue;
97 97
         w = FFMIN(w, mp->avctx->width  - x);
98 98
         h = FFMIN(h, mp->avctx->height - y);
99
-        pixels = (uint16_t *)&mp->frame.data[0][y * mp->frame.linesize[0] + x * 2];
99
+        pixels = (uint16_t *)&mp->frame->data[0][y * mp->frame->linesize[0] + x * 2];
100 100
         while (h--) {
101 101
             mp->changes_map[offset] = w;
102 102
             if (read_color)
103 103
                 for (i = 0; i < w; ++i)
104 104
                     pixels[i] = color;
105 105
             offset += mp->avctx->width;
106
-            pixels += mp->frame.linesize[0] / 2;
106
+            pixels += mp->frame->linesize[0] / 2;
107 107
         }
108 108
     }
109 109
 }
... ...
@@ -165,7 +184,7 @@ static YuvPixel mp_get_yuv_from_rgb(MotionPixelsContext *mp, int x, int y)
165 165
 {
166 166
     int color;
167 167
 
168
-    color = *(uint16_t *)&mp->frame.data[0][y * mp->frame.linesize[0] + x * 2];
168
+    color = *(uint16_t *)&mp->frame->data[0][y * mp->frame->linesize[0] + x * 2];
169 169
     return mp_rgb_yuv_table[color];
170 170
 }
171 171
 
... ...
@@ -174,7 +193,7 @@ static void mp_set_rgb_from_yuv(MotionPixelsContext *mp, int x, int y, const Yuv
174 174
     int color;
175 175
 
176 176
     color = mp_yuv_to_rgb(p->y, p->v, p->u, 1);
177
-    *(uint16_t *)&mp->frame.data[0][y * mp->frame.linesize[0] + x * 2] = color;
177
+    *(uint16_t *)&mp->frame->data[0][y * mp->frame->linesize[0] + x * 2] = color;
178 178
 }
179 179
 
180 180
 static int mp_get_vlc(MotionPixelsContext *mp, GetBitContext *gb)
... ...
@@ -271,7 +290,7 @@ static int mp_decode_frame(AVCodecContext *avctx,
271 271
     GetBitContext gb;
272 272
     int i, count1, count2, sz, ret;
273 273
 
274
-    if ((ret = ff_reget_buffer(avctx, &mp->frame)) < 0)
274
+    if ((ret = ff_reget_buffer(avctx, mp->frame)) < 0)
275 275
         return ret;
276 276
 
277 277
     /* le32 bitstream msb first */
... ...
@@ -296,7 +315,7 @@ static int mp_decode_frame(AVCodecContext *avctx,
296 296
         goto end;
297 297
 
298 298
     if (mp->changes_map[0] == 0) {
299
-        *(uint16_t *)mp->frame.data[0] = get_bits(&gb, 15);
299
+        *(uint16_t *)mp->frame->data[0] = get_bits(&gb, 15);
300 300
         mp->changes_map[0] = 1;
301 301
     }
302 302
     if (mp_read_codes_table(mp, &gb) < 0)
... ...
@@ -316,25 +335,12 @@ static int mp_decode_frame(AVCodecContext *avctx,
316 316
     ff_free_vlc(&mp->vlc);
317 317
 
318 318
 end:
319
-    if ((ret = av_frame_ref(data, &mp->frame)) < 0)
319
+    if ((ret = av_frame_ref(data, mp->frame)) < 0)
320 320
         return ret;
321 321
     *got_frame       = 1;
322 322
     return buf_size;
323 323
 }
324 324
 
325
-static av_cold int mp_decode_end(AVCodecContext *avctx)
326
-{
327
-    MotionPixelsContext *mp = avctx->priv_data;
328
-
329
-    av_freep(&mp->changes_map);
330
-    av_freep(&mp->vpt);
331
-    av_freep(&mp->hpt);
332
-    av_freep(&mp->bswapbuf);
333
-    av_frame_unref(&mp->frame);
334
-
335
-    return 0;
336
-}
337
-
338 325
 AVCodec ff_motionpixels_decoder = {
339 326
     .name           = "motionpixels",
340 327
     .long_name      = NULL_IF_CONFIG_SMALL("Motion Pixels video"),
... ...
@@ -46,7 +46,7 @@
46 46
 typedef struct RpzaContext {
47 47
 
48 48
     AVCodecContext *avctx;
49
-    AVFrame frame;
49
+    AVFrame *frame;
50 50
 
51 51
     const unsigned char *buf;
52 52
     int size;
... ...
@@ -72,7 +72,7 @@ typedef struct RpzaContext {
72 72
 static void rpza_decode_stream(RpzaContext *s)
73 73
 {
74 74
     int width = s->avctx->width;
75
-    int stride = s->frame.linesize[0] / 2;
75
+    int stride = s->frame->linesize[0] / 2;
76 76
     int row_inc = stride - 4;
77 77
     int stream_ptr = 0;
78 78
     int chunk_size;
... ...
@@ -82,7 +82,7 @@ static void rpza_decode_stream(RpzaContext *s)
82 82
     unsigned short color4[4];
83 83
     unsigned char index, idx;
84 84
     unsigned short ta, tb;
85
-    unsigned short *pixels = (unsigned short *)s->frame.data[0];
85
+    unsigned short *pixels = (unsigned short *)s->frame->data[0];
86 86
 
87 87
     int row_ptr = 0;
88 88
     int pixel_ptr = -4;
... ...
@@ -239,7 +239,9 @@ static av_cold int rpza_decode_init(AVCodecContext *avctx)
239 239
     s->avctx = avctx;
240 240
     avctx->pix_fmt = AV_PIX_FMT_RGB555;
241 241
 
242
-    avcodec_get_frame_defaults(&s->frame);
242
+    s->frame = av_frame_alloc();
243
+    if (!s->frame)
244
+        return AVERROR(ENOMEM);
243 245
 
244 246
     return 0;
245 247
 }
... ...
@@ -256,12 +258,12 @@ static int rpza_decode_frame(AVCodecContext *avctx,
256 256
     s->buf = buf;
257 257
     s->size = buf_size;
258 258
 
259
-    if ((ret = ff_reget_buffer(avctx, &s->frame)) < 0)
259
+    if ((ret = ff_reget_buffer(avctx, s->frame)) < 0)
260 260
         return ret;
261 261
 
262 262
     rpza_decode_stream(s);
263 263
 
264
-    if ((ret = av_frame_ref(data, &s->frame)) < 0)
264
+    if ((ret = av_frame_ref(data, s->frame)) < 0)
265 265
         return ret;
266 266
 
267 267
     *got_frame      = 1;
... ...
@@ -274,7 +276,7 @@ static av_cold int rpza_decode_end(AVCodecContext *avctx)
274 274
 {
275 275
     RpzaContext *s = avctx->priv_data;
276 276
 
277
-    av_frame_unref(&s->frame);
277
+    av_frame_free(&s->frame);
278 278
 
279 279
     return 0;
280 280
 }
... ...
@@ -61,7 +61,7 @@
61 61
 typedef struct VmdVideoContext {
62 62
 
63 63
     AVCodecContext *avctx;
64
-    AVFrame prev_frame;
64
+    AVFrame *prev_frame;
65 65
 
66 66
     const unsigned char *buf;
67 67
     int size;
... ...
@@ -244,11 +244,11 @@ static int vmd_decode(VmdVideoContext *s, AVFrame *frame)
244 244
 
245 245
     /* if only a certain region will be updated, copy the entire previous
246 246
      * frame before the decode */
247
-    if (s->prev_frame.data[0] &&
247
+    if (s->prev_frame->data[0] &&
248 248
         (frame_x || frame_y || (frame_width != s->avctx->width) ||
249 249
         (frame_height != s->avctx->height))) {
250 250
 
251
-        memcpy(frame->data[0], s->prev_frame.data[0],
251
+        memcpy(frame->data[0], s->prev_frame->data[0],
252 252
             s->avctx->height * frame->linesize[0]);
253 253
     }
254 254
 
... ...
@@ -291,7 +291,7 @@ static int vmd_decode(VmdVideoContext *s, AVFrame *frame)
291 291
     }
292 292
 
293 293
     dp = &frame->data[0][frame_y * frame->linesize[0] + frame_x];
294
-    pp = &s->prev_frame.data[0][frame_y * s->prev_frame.linesize[0] + frame_x];
294
+    pp = &s->prev_frame->data[0][frame_y * s->prev_frame->linesize[0] + frame_x];
295 295
     switch (meth) {
296 296
     case 1:
297 297
         for (i = 0; i < frame_height; i++) {
... ...
@@ -307,7 +307,7 @@ static int vmd_decode(VmdVideoContext *s, AVFrame *frame)
307 307
                     ofs += len;
308 308
                 } else {
309 309
                     /* interframe pixel copy */
310
-                    if (ofs + len + 1 > frame_width || !s->prev_frame.data[0])
310
+                    if (ofs + len + 1 > frame_width || !s->prev_frame->data[0])
311 311
                         return AVERROR_INVALIDDATA;
312 312
                     memcpy(&dp[ofs], &pp[ofs], len + 1);
313 313
                     ofs += len + 1;
... ...
@@ -320,7 +320,7 @@ static int vmd_decode(VmdVideoContext *s, AVFrame *frame)
320 320
                 return AVERROR_INVALIDDATA;
321 321
             }
322 322
             dp += frame->linesize[0];
323
-            pp += s->prev_frame.linesize[0];
323
+            pp += s->prev_frame->linesize[0];
324 324
         }
325 325
         break;
326 326
 
... ...
@@ -328,7 +328,7 @@ static int vmd_decode(VmdVideoContext *s, AVFrame *frame)
328 328
         for (i = 0; i < frame_height; i++) {
329 329
             bytestream2_get_buffer(&gb, dp, frame_width);
330 330
             dp += frame->linesize[0];
331
-            pp += s->prev_frame.linesize[0];
331
+            pp += s->prev_frame->linesize[0];
332 332
         }
333 333
         break;
334 334
 
... ...
@@ -353,7 +353,7 @@ static int vmd_decode(VmdVideoContext *s, AVFrame *frame)
353 353
                     }
354 354
                 } else {
355 355
                     /* interframe pixel copy */
356
-                    if (ofs + len + 1 > frame_width || !s->prev_frame.data[0])
356
+                    if (ofs + len + 1 > frame_width || !s->prev_frame->data[0])
357 357
                         return AVERROR_INVALIDDATA;
358 358
                     memcpy(&dp[ofs], &pp[ofs], len + 1);
359 359
                     ofs += len + 1;
... ...
@@ -366,13 +366,24 @@ static int vmd_decode(VmdVideoContext *s, AVFrame *frame)
366 366
                 return AVERROR_INVALIDDATA;
367 367
             }
368 368
             dp += frame->linesize[0];
369
-            pp += s->prev_frame.linesize[0];
369
+            pp += s->prev_frame->linesize[0];
370 370
         }
371 371
         break;
372 372
     }
373 373
     return 0;
374 374
 }
375 375
 
376
+static av_cold int vmdvideo_decode_end(AVCodecContext *avctx)
377
+{
378
+    VmdVideoContext *s = avctx->priv_data;
379
+
380
+    av_frame_free(&s->prev_frame);
381
+    av_freep(&s->unpack_buffer);
382
+    s->unpack_buffer_size = 0;
383
+
384
+    return 0;
385
+}
386
+
376 387
 static av_cold int vmdvideo_decode_init(AVCodecContext *avctx)
377 388
 {
378 389
     VmdVideoContext *s = avctx->priv_data;
... ...
@@ -412,7 +423,11 @@ static av_cold int vmdvideo_decode_init(AVCodecContext *avctx)
412 412
         palette32[i] |= palette32[i] >> 6 & 0x30303;
413 413
     }
414 414
 
415
-    avcodec_get_frame_defaults(&s->prev_frame);
415
+    s->prev_frame = av_frame_alloc();
416
+    if (!s->prev_frame) {
417
+        vmdvideo_decode_end(avctx);
418
+        return AVERROR(ENOMEM);
419
+    }
416 420
 
417 421
     return 0;
418 422
 }
... ...
@@ -443,8 +458,8 @@ static int vmdvideo_decode_frame(AVCodecContext *avctx,
443 443
     memcpy(frame->data[1], s->palette, PALETTE_COUNT * 4);
444 444
 
445 445
     /* shuffle frames */
446
-    av_frame_unref(&s->prev_frame);
447
-    if ((ret = av_frame_ref(&s->prev_frame, frame)) < 0)
446
+    av_frame_unref(s->prev_frame);
447
+    if ((ret = av_frame_ref(s->prev_frame, frame)) < 0)
448 448
         return ret;
449 449
 
450 450
     *got_frame      = 1;
... ...
@@ -453,18 +468,6 @@ static int vmdvideo_decode_frame(AVCodecContext *avctx,
453 453
     return buf_size;
454 454
 }
455 455
 
456
-static av_cold int vmdvideo_decode_end(AVCodecContext *avctx)
457
-{
458
-    VmdVideoContext *s = avctx->priv_data;
459
-
460
-    av_frame_unref(&s->prev_frame);
461
-    av_freep(&s->unpack_buffer);
462
-    s->unpack_buffer_size = 0;
463
-
464
-    return 0;
465
-}
466
-
467
-
468 456
 /*
469 457
  * Audio Decoder
470 458
  */