mpegvideo_enc: do not unreference frames before the code is done with them
authorMichael Niedermayer <michaelni@gmx.at>
Sat, 25 May 2013 18:29:17 +0000 (20:29 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Sat, 25 May 2013 18:30:50 +0000 (20:30 +0200)
Fixes Ticket2592

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavcodec/mpegvideo.c
libavcodec/mpegvideo_enc.c

index a713099..e76fc34 100644 (file)
@@ -1714,7 +1714,6 @@ int ff_MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx)
  * frame has been coded/decoded. */
 void ff_MPV_frame_end(MpegEncContext *s)
 {
-    int i;
     /* redraw edges for the frame if decoding didn't complete */
     // just to make sure that all data is rendered.
     if (CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration) {
@@ -1763,13 +1762,6 @@ void ff_MPV_frame_end(MpegEncContext *s)
     assert(i < MAX_PICTURE_COUNT);
 #endif
 
-    if (s->encoding) {
-        /* release non-reference frames */
-        for (i = 0; i < MAX_PICTURE_COUNT; i++) {
-            if (!s->picture[i].reference)
-                ff_mpeg_unref_picture(s, &s->picture[i]);
-        }
-    }
     // clear copies, to avoid confusion
 #if 0
     memset(&s->last_picture,    0, sizeof(Picture));
index 0db2f83..6a0f3b5 100644 (file)
@@ -1632,6 +1632,13 @@ vbv_retry:
     } else {
         s->frame_bits = 0;
     }
+
+    /* release non-reference frames */
+    for (i = 0; i < MAX_PICTURE_COUNT; i++) {
+        if (!s->picture[i].reference)
+            ff_mpeg_unref_picture(s, &s->picture[i]);
+    }
+
     assert((s->frame_bits & 7) == 0);
 
     pkt->size = s->frame_bits / 8;