]> git.sesse.net Git - vlc/commitdiff
Workaround a potential segfault when using VAAPI/DXVA2 (close #3606).
authorLaurent Aimar <fenrir@videolan.org>
Sat, 12 Jun 2010 23:41:11 +0000 (01:41 +0200)
committerLaurent Aimar <fenrir@videolan.org>
Sat, 12 Jun 2010 23:42:22 +0000 (01:42 +0200)
It seems that some avcodec decoders release frames even after being flushed.

modules/codec/avcodec/video.c

index d88fc26261c6552134535f5ea0d0c997126fc1ec..246189b9a53a050aa1e23d65318e4f55507585c8 100644 (file)
@@ -795,7 +795,10 @@ void EndVideoDec( decoder_t *p_dec )
     if( p_sys->p_ff_pic ) av_free( p_sys->p_ff_pic );
 
     if( p_sys->p_va )
+    {
         vlc_va_Delete( p_sys->p_va );
+        p_sys->p_va = NULL;
+    }
     vlc_sem_destroy( &p_sys->sem_mt );
 }
 
@@ -1120,25 +1123,24 @@ static void ffmpeg_ReleaseFrameBuf( struct AVCodecContext *p_context,
     if( p_sys->p_va )
     {
         vlc_va_Release( p_sys->p_va, p_ff_pic );
-
-        /* */
-        for( int i = 0; i < 4; i++ )
-            p_ff_pic->data[i] = NULL;
     }
     else if( !p_ff_pic->opaque )
     {
-        avcodec_default_release_buffer( p_context, p_ff_pic );
+        /* We can end up here without the AVFrame being allocated by
+         * avcodec_default_get_buffer() if VA is used and the frame is
+         * released when the decoder is closed
+         */
+        if( p_ff_pic->type == FF_BUFFER_TYPE_INTERNAL )
+            avcodec_default_release_buffer( p_context, p_ff_pic );
     }
     else
     {
         picture_t *p_pic = (picture_t*)p_ff_pic->opaque;
 
         decoder_UnlinkPicture( p_dec, p_pic );
-
-        /* */
-        for( int i = 0; i < 4; i++ )
-            p_ff_pic->data[i] = NULL;
     }
+    for( int i = 0; i < 4; i++ )
+        p_ff_pic->data[i] = NULL;
 }
 
 #ifdef HAVE_AVCODEC_VA