[vlc-commits] hw: vaapi: add filter instance holder

Thomas Guillem git at videolan.org
Tue Jul 4 19:54:25 CEST 2017


vlc | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Jul  4 19:14:38 2017 +0200| [50b8264a93dd85f248a52d1e52899fe5dc38fcd9] | committer: Thomas Guillem

hw: vaapi: add filter instance holder

See XXX comments.

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

 modules/hw/vaapi/chroma.c    |  9 +++---
 modules/hw/vaapi/filters.c   | 76 ++++++++++++++++++++++++++++++++++++++++----
 modules/hw/vaapi/filters.h   |  8 +++++
 modules/hw/vaapi/vlc_vaapi.c | 15 ---------
 modules/hw/vaapi/vlc_vaapi.h |  4 ---
 5 files changed, 83 insertions(+), 29 deletions(-)

diff --git a/modules/hw/vaapi/chroma.c b/modules/hw/vaapi/chroma.c
index 028b2e2ede..0991ff16f4 100644
--- a/modules/hw/vaapi/chroma.c
+++ b/modules/hw/vaapi/chroma.c
@@ -309,7 +309,7 @@ vlc_vaapi_OpenChroma(vlc_object_t *obj)
                               VA_FOURCC_NV12);
         if (!filter_sys->dest_pics)
         {
-            vlc_vaapi_ReleaseInstance(filter_sys->va_inst);
+            vlc_vaapi_FilterReleaseInstance(filter, filter_sys->va_inst);
             free(filter_sys);
             return VLC_EGENERIC;
         }
@@ -326,7 +326,7 @@ vlc_vaapi_OpenChroma(vlc_object_t *obj)
         if (is_upload)
         {
             picture_pool_Release(filter_sys->dest_pics);
-            vlc_vaapi_ReleaseInstance(filter_sys->va_inst);
+            vlc_vaapi_FilterReleaseInstance(filter, filter_sys->va_inst);
         }
         free(filter_sys);
         return VLC_EGENERIC;
@@ -340,7 +340,8 @@ vlc_vaapi_OpenChroma(vlc_object_t *obj)
 void
 vlc_vaapi_CloseChroma(vlc_object_t *obj)
 {
-    filter_sys_t *const filter_sys = ((filter_t *)obj)->p_sys;
+    filter_t *filter = (filter_t *)obj;
+    filter_sys_t *const filter_sys = filter->p_sys;
 
     if (filter_sys->image_fallback.image_id != VA_INVALID_ID)
         vlc_vaapi_DestroyImage(obj, filter_sys->dpy,
@@ -348,7 +349,7 @@ vlc_vaapi_CloseChroma(vlc_object_t *obj)
     if (filter_sys->dest_pics)
         picture_pool_Release(filter_sys->dest_pics);
     if (filter_sys->va_inst != NULL)
-        vlc_vaapi_ReleaseInstance(filter_sys->va_inst);
+        vlc_vaapi_FilterReleaseInstance(filter, filter_sys->va_inst);
     CopyCleanCache(&filter_sys->cache);
 
     free(filter_sys);
diff --git a/modules/hw/vaapi/filters.c b/modules/hw/vaapi/filters.c
index 4e5a37d833..db3b3a84cb 100644
--- a/modules/hw/vaapi/filters.c
+++ b/modules/hw/vaapi/filters.c
@@ -32,6 +32,69 @@
 #include <vlc_plugin.h>
 #include "filters.h"
 
+/*******************
+ * Instance holder *
+ *******************/
+
+/* XXX: Static filters (like deinterlace) may not have access to a picture
+ * allocated by the vout if it's not the first filter in the chain. That vout
+ * picture is needed to get the VADisplay instance. Therefore, we store the
+ * fist vaapi instance set by a filter so that it can be re-usable by others
+ * filters. The instance is ref-counted, so there is no problem if the main
+ * filter is destroyed before the other ones. */
+static struct {
+    vlc_mutex_t lock;
+    struct vlc_vaapi_instance *inst;
+    filter_t *owner;
+} holder = { VLC_STATIC_MUTEX, NULL, NULL };
+
+struct vlc_vaapi_instance *
+vlc_vaapi_FilterHoldInstance(filter_t *filter, VADisplay *dpy)
+{
+
+    picture_t *pic = filter_NewPicture(filter);
+    if (!pic)
+        return NULL;
+
+    if (pic->format.i_chroma != VLC_CODEC_VAAPI_420)
+    {
+        picture_Release(pic);
+        return NULL;
+    }
+
+    struct vlc_vaapi_instance *va_inst = NULL;
+
+    vlc_mutex_lock(&holder.lock);
+    if (holder.inst != NULL)
+    {
+        va_inst = holder.inst;
+        *dpy = vlc_vaapi_HoldInstance(holder.inst);
+    }
+    else
+    {
+        holder.owner = filter;
+        holder.inst = va_inst = pic->p_sys ?
+            vlc_vaapi_PicSysHoldInstance(pic->p_sys, dpy) : NULL;
+    }
+    vlc_mutex_unlock(&holder.lock);
+    picture_Release(pic);
+
+    return va_inst;
+}
+
+void
+vlc_vaapi_FilterReleaseInstance(filter_t *filter,
+                                struct vlc_vaapi_instance *va_inst)
+{
+    vlc_vaapi_ReleaseInstance(va_inst);
+    vlc_mutex_lock(&holder.lock);
+    if (filter == holder.owner)
+    {
+        holder.inst = NULL;
+        holder.owner = NULL;
+    }
+    vlc_mutex_unlock(&holder.lock);
+}
 /********************************
  * Common structures and macros *
  ********************************/
@@ -379,19 +442,20 @@ error:
         vlc_vaapi_DestroyConfig(VLC_OBJECT(filter),
                                 filter_sys->va.dpy, filter_sys->va.conf);
     if (filter_sys->va.inst)
-        vlc_vaapi_ReleaseInstance(filter_sys->va.inst);
+        vlc_vaapi_FilterReleaseInstance(filter, filter_sys->va.inst);
     free(filter_sys);
     return VLC_EGENERIC;
 }
 
 static void
-Close(vlc_object_t * obj, filter_sys_t * filter_sys)
+Close(filter_t *filter, filter_sys_t * filter_sys)
 {
+    vlc_object_t * obj = VLC_OBJECT(filter);
     picture_pool_Release(filter_sys->dest_pics);
     vlc_vaapi_DestroyBuffer(obj, filter_sys->va.dpy, filter_sys->va.buf);
     vlc_vaapi_DestroyContext(obj, filter_sys->va.dpy, filter_sys->va.ctx);
     vlc_vaapi_DestroyConfig(obj, filter_sys->va.dpy, filter_sys->va.conf);
-    vlc_vaapi_ReleaseInstance(filter_sys->va.inst);
+    vlc_vaapi_FilterReleaseInstance(filter, filter_sys->va.inst);
     free(filter_sys);
 }
 
@@ -593,7 +657,7 @@ CloseAdjust(vlc_object_t * obj)
         var_Destroy(obj, adjust_params_names[i]);
     }
     free(filter_sys->p_data);
-    Close(obj, filter_sys);
+    Close(filter, filter_sys);
 }
 
 /***************************
@@ -727,7 +791,7 @@ CloseBasicFilter(vlc_object_t * obj)
     var_Destroy(obj, p_data->sigma.psz_name);
     free(p_data->sigma.psz_name);
     free(p_data);
-    Close(obj, filter_sys);
+    Close(filter, filter_sys);
 }
 
 /*************************
@@ -992,7 +1056,7 @@ CloseDeinterlace(vlc_object_t * obj)
         free(p_data->history.pp_pics);
     }
     free(p_data);
-    Close(obj, filter_sys);
+    Close(filter, filter_sys);
 }
 
 /*********************
diff --git a/modules/hw/vaapi/filters.h b/modules/hw/vaapi/filters.h
index aafb1383f4..2e739feb37 100644
--- a/modules/hw/vaapi/filters.h
+++ b/modules/hw/vaapi/filters.h
@@ -31,4 +31,12 @@
 int  vlc_vaapi_OpenChroma(vlc_object_t *obj);
 void vlc_vaapi_CloseChroma(vlc_object_t *obj);
 
+/* Get and hold the VADisplay instance from a filter */
+struct vlc_vaapi_instance *
+vlc_vaapi_FilterHoldInstance(filter_t *filter, VADisplay *dpy);
+
+void
+vlc_vaapi_FilterReleaseInstance(filter_t *filter,
+                                struct vlc_vaapi_instance *va_inst);
+
 #endif /* VLC_VAAPI_FILTERS_H */
diff --git a/modules/hw/vaapi/vlc_vaapi.c b/modules/hw/vaapi/vlc_vaapi.c
index 7b9d9c0da2..f376ddd713 100644
--- a/modules/hw/vaapi/vlc_vaapi.c
+++ b/modules/hw/vaapi/vlc_vaapi.c
@@ -602,21 +602,6 @@ vlc_vaapi_PicSysHoldInstance(picture_sys_t *sys, VADisplay *dpy)
     return sys->instance->va_inst;
 }
 
-struct vlc_vaapi_instance *
-vlc_vaapi_FilterHoldInstance(filter_t *filter, VADisplay *dpy)
-{
-    picture_t *pic = filter_NewPicture(filter);
-    if (!pic)
-        return NULL;
-
-    struct vlc_vaapi_instance *va_inst =
-        pic->format.i_chroma == VLC_CODEC_VAAPI_420 && pic->p_sys ?
-        vlc_vaapi_PicSysHoldInstance(pic->p_sys, dpy) : NULL;
-    picture_Release(pic);
-
-    return va_inst;
-}
-
 #define ASSERT_VAAPI_CHROMA(pic) do { \
     assert(pic->format.i_chroma == VLC_CODEC_VAAPI_420); \
 } while(0)
diff --git a/modules/hw/vaapi/vlc_vaapi.h b/modules/hw/vaapi/vlc_vaapi.h
index fc2cfff6a8..0efd3370b5 100644
--- a/modules/hw/vaapi/vlc_vaapi.h
+++ b/modules/hw/vaapi/vlc_vaapi.h
@@ -187,10 +187,6 @@ vlc_vaapi_PicSysGetRenderTargets(picture_sys_t *sys,
 struct vlc_vaapi_instance *
 vlc_vaapi_PicSysHoldInstance(picture_sys_t *sys, VADisplay *dpy);
 
-/* Get and hold the VADisplay instance from a filter */
-struct vlc_vaapi_instance *
-vlc_vaapi_FilterHoldInstance(filter_t *filter, VADisplay *dpy);
-
 /* Attachs the VASurface to the picture context, the picture must be allocated
  * by a vaapi pool (see vlc_vaapi_PoolNew()) */
 void



More information about the vlc-commits mailing list