[vlc-commits] avcodec: simplify hwaccel picture release

Rémi Denis-Courmont git at videolan.org
Tue Apr 21 23:43:07 CEST 2015


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed Apr 22 00:34:53 2015 +0300| [1b927cdd1b0887586fc866ce4a042290540b2b15] | committer: Rémi Denis-Courmont

avcodec: simplify hwaccel picture release

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=1b927cdd1b0887586fc866ce4a042290540b2b15
---

 modules/codec/avcodec/dxva2.c |    1 +
 modules/codec/avcodec/vaapi.c |    1 +
 modules/codec/avcodec/vda.c   |    6 ++++--
 modules/codec/avcodec/video.c |   42 +++++++----------------------------------
 modules/hw/vdpau/avcodec.c    |    3 ++-
 5 files changed, 15 insertions(+), 38 deletions(-)

diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
index d8ea4a8..2fb2c4d 100644
--- a/modules/codec/avcodec/dxva2.c
+++ b/modules/codec/avcodec/dxva2.c
@@ -488,6 +488,7 @@ static void Release(void *opaque, uint8_t *data)
 
     surface->refcount--;
     pic->context = NULL;
+    picture_Release(pic);
     (void) data;
 }
 
diff --git a/modules/codec/avcodec/vaapi.c b/modules/codec/avcodec/vaapi.c
index 0ebc63f..ab23ec8 100644
--- a/modules/codec/avcodec/vaapi.c
+++ b/modules/codec/avcodec/vaapi.c
@@ -391,6 +391,7 @@ static void Release( void *opaque, uint8_t *data )
     vlc_mutex_unlock( p_surface->p_lock );
 
     pic->context = NULL;
+    picture_Release(pic);
     (void) data;
 }
 
diff --git a/modules/codec/avcodec/vda.c b/modules/codec/avcodec/vda.c
index 9c6357f..d842038 100644
--- a/modules/codec/avcodec/vda.c
+++ b/modules/codec/avcodec/vda.c
@@ -307,7 +307,8 @@ static void Release( void *opaque, uint8_t *data )
     if ( cv_buffer )
         CVPixelBufferRelease( cv_buffer );
 #endif
-    (void) opaque; (void) data;
+    picture_Release(opaque);
+    (void) data;
 }
 
 #else
@@ -385,7 +386,8 @@ static int Extract( vlc_va_t *va, picture_t *p_picture, uint8_t *data )
 
 static void Release( void *opaque, uint8_t *data )
 {
-    (void) opaque; (void) data;
+    picture_Release(opaque);
+    (void) data;
 }
 
 #endif
diff --git a/modules/codec/avcodec/video.c b/modules/codec/avcodec/video.c
index 48236e1..a015e31 100644
--- a/modules/codec/avcodec/video.c
+++ b/modules/codec/avcodec/video.c
@@ -84,12 +84,6 @@ struct decoder_sys_t
     vlc_sem_t sem_mt;
 };
 
-typedef struct
-{
-    vlc_va_t *va;
-    picture_t *pic;
-} lavc_va_picture_t;
-
 #ifdef HAVE_AVCODEC_MT
 #   define wait_mt(s) vlc_sem_wait( &s->sem_mt )
 #   define post_mt(s) vlc_sem_post( &s->sem_mt )
@@ -654,7 +648,6 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
     while( !p_block || p_block->i_buffer > 0 || p_sys->b_flush )
     {
         int i_used, b_gotpicture;
-        picture_t *p_pic;
         AVPacket pkt;
 
         post_mt( p_sys );
@@ -791,7 +784,8 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
         if( !b_drawpicture || ( !p_sys->p_va && !p_sys->p_ff_pic->linesize[0] ) )
             continue;
 
-        if( p_sys->p_ff_pic->opaque == NULL )
+        picture_t *p_pic = p_sys->p_ff_pic->opaque;
+        if( p_pic == NULL )
         {
             /* Get a new picture */
             if( p_sys->p_va == NULL )
@@ -807,17 +801,9 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
             lavc_CopyPicture(p_dec, p_pic, p_sys->p_ff_pic);
         }
         else
-        if( p_sys->p_va != NULL )
-        {
-            lavc_va_picture_t *vapic = p_sys->p_ff_pic->opaque;
-
-            p_pic = vapic->pic;
-            vlc_va_Extract( p_sys->p_va, p_pic, p_sys->p_ff_pic->data[3] );
-            picture_Hold( p_pic );
-        }
-        else
         {
-            p_pic = (picture_t *)p_sys->p_ff_pic->opaque;
+            if( p_sys->p_va != NULL )
+                vlc_va_Extract( p_sys->p_va, p_pic, p_sys->p_ff_pic->data[3] );
             picture_Hold( p_pic );
         }
 
@@ -959,15 +945,6 @@ static void ffmpeg_InitCodec( decoder_t *p_dec )
     }
 }
 
-static void lavc_va_ReleaseFrame(void *opaque, uint8_t *data)
-{
-    lavc_va_picture_t *vapic = opaque;
-
-    vlc_va_Release(vapic->va, vapic->pic, data);
-    picture_Release(vapic->pic);
-    free(vapic);
-}
-
 static int lavc_va_GetFrame(struct AVCodecContext *ctx, AVFrame *frame,
                             int flags)
 {
@@ -984,10 +961,6 @@ static int lavc_va_GetFrame(struct AVCodecContext *ctx, AVFrame *frame,
     if (pic == NULL)
         return -1;
 
-    lavc_va_picture_t *vapic = xmalloc(sizeof (*vapic));
-
-    vapic->va = va;
-    vapic->pic = pic;
     if (vlc_va_Get(va, pic, &frame->data[0]))
     {
         msg_Err(dec, "hardware acceleration picture allocation failed");
@@ -998,15 +971,14 @@ static int lavc_va_GetFrame(struct AVCodecContext *ctx, AVFrame *frame,
      * data[3] actually contains the format-specific surface handle. */
     frame->data[3] = frame->data[0];
 
-    frame->buf[0] = av_buffer_create(frame->data[0], 0, lavc_va_ReleaseFrame,
-                                     vapic, 0);
+    frame->buf[0] = av_buffer_create(frame->data[0], 0, va->release, pic, 0);
     if (unlikely(frame->buf[0] == NULL))
     {
-        lavc_va_ReleaseFrame(vapic, frame->data[0]);
+        vlc_va_Release(va, pic, frame->data[0]);
         return -1;
     }
 
-    frame->opaque = vapic;
+    frame->opaque = pic;
     assert(frame->data[0] != NULL);
     (void) flags;
     return 0;
diff --git a/modules/hw/vdpau/avcodec.c b/modules/hw/vdpau/avcodec.c
index 8df0c00..b8b31c2 100644
--- a/modules/hw/vdpau/avcodec.c
+++ b/modules/hw/vdpau/avcodec.c
@@ -148,7 +148,8 @@ static int Lock(vlc_va_t *va, picture_t *pic, uint8_t **data)
 
 static void Unlock(void *opaque, uint8_t *data)
 {
-    (void) opaque; (void) data;
+    picture_Release(opaque);
+    (void) data;
 }
 
 static int Copy(vlc_va_t *va, picture_t *pic, uint8_t *data)



More information about the vlc-commits mailing list