]> git.sesse.net Git - vlc/commitdiff
avcodec: pass data pointer to hwaccel release callbacks and simplify
authorRémi Denis-Courmont <remi@remlab.net>
Thu, 25 Jul 2013 15:45:24 +0000 (18:45 +0300)
committerRémi Denis-Courmont <remi@remlab.net>
Thu, 25 Jul 2013 15:45:24 +0000 (18:45 +0300)
modules/codec/avcodec/dxva2.c
modules/codec/avcodec/hwdummy.c
modules/codec/avcodec/va.h
modules/codec/avcodec/vaapi.c
modules/codec/avcodec/vda.c
modules/codec/avcodec/video.c
modules/hw/vdpau/avcodec.c

index d33b5713ecc6549afa9bf5258097a638515227c4..5d8cd19f18d4872e65388280697aa4af1a510c99 100644 (file)
@@ -471,12 +471,15 @@ static int Get(vlc_va_t *external, AVFrame *ff)
     ff->opaque = surface;
     return VLC_SUCCESS;
 }
-static void Release(void *opaque)
+
+static void Release(void *opaque, uint8_t *data)
 {
     vlc_va_surface_t *surface = opaque;
 
     surface->refcount--;
+    (void) data;
 }
+
 static void Close(vlc_va_t *external)
 {
     vlc_va_dxva2_t *va = vlc_va_dxva2_Get(external);
index ead7ccdaec0588a71acbb45f271c9f21caa098fc..83b56e0149590a34a94e6774d3322dea6ad1a853 100644 (file)
@@ -47,8 +47,9 @@ vlc_module_begin()
     add_shortcut("dummy")
 vlc_module_end()
 
-#define DECODER_MAGIC 0x12345678
-#define SURFACE_MAGIC 0x87654321
+#define DECODER_MAGIC 0xdec0dea0
+#define DATA_MAGIC    0xda1a0000
+#define OPAQUE_MAGIC  0x0da00e00
 
 struct vlc_va_sys_t
 {
@@ -63,15 +64,16 @@ static int Lock(vlc_va_t *va, AVFrame *ff)
         ff->linesize[i] = 0;
     }
 
-    ff->data[0] = (void *)(uintptr_t)SURFACE_MAGIC; /* must be non-NULL */
-    ff->data[3] = (void *)(uintptr_t)SURFACE_MAGIC;
-    ff->opaque = (void *)(uintptr_t)SURFACE_MAGIC;
+    ff->data[0] = (void *)(uintptr_t)DATA_MAGIC; /* must be non-NULL */
+    ff->data[3] = (void *)(uintptr_t)DATA_MAGIC;
+    ff->opaque = (void *)(uintptr_t)OPAQUE_MAGIC;
     return VLC_SUCCESS;
 }
 
-static void Unlock(void *opaque)
+static void Unlock(void *opaque, uint8_t *data)
 {
-    assert((uintptr_t)opaque == SURFACE_MAGIC);
+    assert((uintptr_t)opaque == OPAQUE_MAGIC);
+    assert((uintptr_t)data == DATA_MAGIC);
 }
 
 static VdpStatus Render(VdpDecoder decoder, VdpVideoSurface target,
@@ -82,7 +84,7 @@ static VdpStatus Render(VdpDecoder decoder, VdpVideoSurface target,
     (void) decoder; (void) target; (void) picture_info;
     (void) bitstream_buffer_count; (void) bitstream_buffers;
     assert(decoder == DECODER_MAGIC);
-    assert(target == SURFACE_MAGIC);
+    assert(target == DATA_MAGIC);
     return VDP_STATUS_OK;
 }
 
@@ -90,8 +92,8 @@ static int Copy(vlc_va_t *va, picture_t *pic, AVFrame *ff)
 {
     (void) va; (void) ff;
 
-    assert((uintptr_t)ff->data[3] == SURFACE_MAGIC);
-    assert((uintptr_t)ff->opaque == SURFACE_MAGIC);
+    assert((uintptr_t)ff->data[3] == DATA_MAGIC);
+    assert((uintptr_t)ff->opaque == OPAQUE_MAGIC);
 
     /* Put some dummy picture content */
     memset(pic->p[0].p_pixels, 0xF0,
index 128942c45769213beb1216a7c951e6e9f893370d..ddbf9ce1616672a7098cbc3f539153ad59137fc6 100644 (file)
@@ -38,7 +38,7 @@ struct vlc_va_t {
     int  (*setup)(vlc_va_t *, void **hw, vlc_fourcc_t *output,
                   int width, int height);
     int  (*get)(vlc_va_t *, AVFrame *frame);
-    void (*release)(void *opaque);
+    void (*release)(void *opaque, uint8_t *surface);
     int  (*extract)(vlc_va_t *, picture_t *dst, AVFrame *src);
 };
 
@@ -86,7 +86,8 @@ static inline int vlc_va_Get(vlc_va_t *va, AVFrame *frame)
  * Releases a hardware surface from a libavcodec frame.
  * The surface has been previously allocated with vlc_va_Get().
  *
- * @param opaque opaque data pointer of the AVFrame passed to vlc_va_Get().
+ * @param opaque opaque data pointer of the AVFrame set by vlc_va_Get()
+ * @param data data[0] pointer of the AVFrame set by vlc_va_Get()
  *
  * @note This function needs not be reentrant. However it may be called
  * concurrently with vlc_va_Get() and/or vlc_va_Extract() from other threads
@@ -94,9 +95,9 @@ static inline int vlc_va_Get(vlc_va_t *va, AVFrame *frame)
  *
  * @param frame libavcodec frame previously allocated by vlc_va_Get()
  */
-static inline void vlc_va_Release(vlc_va_t *va, void *opaque)
+static inline void vlc_va_Release(vlc_va_t *va, void *opaque, uint8_t *data)
 {
-    va->release(opaque);
+    va->release(opaque, data);
 }
 
 /**
index df3fc4a894aee838b3be5477aee4844cfdb4deef..7b40c3e000d1f6b345cd0192b9a4b496ae0fcada 100644 (file)
@@ -518,13 +518,14 @@ static int Get( vlc_va_t *va, AVFrame *p_ff )
     return VLC_SUCCESS;
 }
 
-static void Release( void *opaque )
+static void Release( void *opaque, uint8_t *data )
 {
     vlc_va_surface_t *p_surface = opaque;
 
     vlc_mutex_lock( p_surface->p_lock );
     p_surface->i_refcount--;
     vlc_mutex_unlock( p_surface->p_lock );
+    (void) data;
 }
 
 static void Close( vlc_va_sys_t *sys )
index faddbe7ebe1be47a6f08c4cb3bfd02c90e7e9eec..695d08c3c4712205c584927f9644b3bab27a2815 100644 (file)
@@ -255,7 +255,7 @@ static int Extract( vlc_va_t *external, picture_t *p_picture, AVFrame *p_ff )
     return VLC_SUCCESS;
 }
 
-static void Release( void *opaque )
+static void Release( void *opaque, uint8_t *data )
 {
     assert( opaque == NULL );
 #if 0
@@ -264,6 +264,7 @@ static void Release( void *opaque )
     if ( cv_buffer )
         CVPixelBufferRelease( cv_buffer );
 #endif
+    (void) data;
 }
 
 static void Close( vlc_va_t *external )
index d6a966f65d6aeb3765e1585ae56ec31cd5fadee7..b25a8d459edd5470980260ff1d1d3b6e04015ec3 100644 (file)
@@ -894,21 +894,6 @@ static void ffmpeg_CopyPicture( decoder_t *p_dec,
 }
 
 #if LIBAVCODEC_VERSION_MAJOR >= 55
-typedef struct
-{
-    vlc_va_t *va;
-    void *opaque;
-} lavc_hw_ref_t;
-
-static void lavc_va_ReleaseFrame(void *opaque, uint8_t *data)
-{
-    lavc_hw_ref_t *ref = opaque;
-
-    vlc_va_Release(ref->va, ref->opaque);
-    free(ref);
-    (void) data;
-}
-
 static int lavc_va_GetFrame(struct AVCodecContext *ctx, AVFrame *frame,
                             int flags)
 {
@@ -928,20 +913,11 @@ static int lavc_va_GetFrame(struct AVCodecContext *ctx, AVFrame *frame,
         return -1;
     }
 
-    lavc_hw_ref_t *ref = malloc(sizeof (*ref));
-    if (unlikely(ref == NULL))
-    {
-        vlc_va_Release(va, frame->opaque);
-        return -1;
-    }
-    ref->va = va;
-    ref->opaque = frame->opaque;
-
-    frame->buf[0] = av_buffer_create(frame->data[0], 0, lavc_va_ReleaseFrame,
-                                     ref, 0);
+    frame->buf[0] = av_buffer_create(frame->data[0], 0, va->release,
+                                     frame->opaque, 0);
     if (unlikely(frame->buf[0] == NULL))
     {
-        lavc_va_ReleaseFrame(ref, frame->data[0]);
+        vlc_va_Release(va, frame->opaque, frame->data[0]);
         return -1;
     }
     assert(frame->data[0] != NULL);
@@ -1262,7 +1238,7 @@ static void ffmpeg_ReleaseFrameBuf( struct AVCodecContext *p_context,
     decoder_sys_t *p_sys = p_dec->p_sys;
 
     if( p_sys->p_va )
-        vlc_va_Release( p_sys->p_va, p_ff_pic->opaque );
+        vlc_va_Release( p_sys->p_va, p_ff_pic->opaque, p_ff_pic->data[0] );
     else if( p_ff_pic->opaque )
         decoder_UnlinkPicture( p_dec, (picture_t*)p_ff_pic->opaque);
     else if( p_ff_pic->type == FF_BUFFER_TYPE_INTERNAL )
index 8c027d37b8314d48c8a1de29113de1220abfb115..07028b63261fc29984ee2663601ff00890b13baa 100644 (file)
@@ -91,12 +91,13 @@ static int Lock(vlc_va_t *va, AVFrame *ff)
     return VLC_SUCCESS;
 }
 
-static void Unlock(void *opaque)
+static void Unlock(void *opaque, uint8_t *data)
 {
     vlc_vdp_video_field_t *field = opaque;
 
     assert(field != NULL);
     field->destroy(field);
+    (void) data;
 }
 
 static int Copy(vlc_va_t *va, picture_t *pic, AVFrame *ff)