From 140fa66be339f9574dd8ae6193e4d9b89099cb9a Mon Sep 17 00:00:00 2001 From: Gwenole Beauchesne Date: Tue, 26 Mar 2013 10:31:10 +0100 Subject: [PATCH] plugins: integrate GstVaapiVideoMeta from libgstvaapi. Move GstVaapiVideoMeta from core libgstvaapi decoding library to the actual plugin elements. That's only useful there. Also inline reference counting code from GstVaapiMiniObject. --- docs/reference/libs/libs-sections.txt | 28 ------- gst-libs/gst/vaapi/Makefile.am | 2 - gst/vaapi/Makefile.am | 2 + gst/vaapi/gstvaapidecode.c | 1 - gst/vaapi/gstvaapidownload.c | 1 - gst/vaapi/gstvaapipostproc.c | 1 - gst/vaapi/gstvaapisink.c | 2 +- gst/vaapi/gstvaapiupload.c | 1 - gst/vaapi/gstvaapiuploader.c | 1 - gst/vaapi/gstvaapivideobuffer.h | 2 +- gst/vaapi/gstvaapivideoconverter_glx.c | 2 +- .../gst => gst}/vaapi/gstvaapivideometa.c | 81 ++++++++++++------- .../gst => gst}/vaapi/gstvaapivideometa.h | 29 +++++-- 13 files changed, 80 insertions(+), 73 deletions(-) rename {gst-libs/gst => gst}/vaapi/gstvaapivideometa.c (91%) rename {gst-libs/gst => gst}/vaapi/gstvaapivideometa.h (89%) diff --git a/docs/reference/libs/libs-sections.txt b/docs/reference/libs/libs-sections.txt index 71e1ab9f67..140232363c 100644 --- a/docs/reference/libs/libs-sections.txt +++ b/docs/reference/libs/libs-sections.txt @@ -171,34 +171,6 @@ GST_VAAPI_IS_IMAGE_POOL_CLASS GST_VAAPI_IMAGE_POOL_GET_CLASS -
-gstvaapivideometa -GstVaapiVideoMeta -gst_vaapi_video_meta_new -gst_vaapi_video_meta_new_from_pool -gst_vaapi_video_meta_new_with_image -gst_vaapi_video_meta_new_with_surface -gst_vaapi_video_meta_new_with_surface_proxy -gst_vaapi_video_meta_ref -gst_vaapi_video_meta_unref -gst_vaapi_video_meta_replace -gst_vaapi_video_meta_get_display -gst_vaapi_video_meta_get_image -gst_vaapi_video_meta_set_image -gst_vaapi_video_meta_set_image_from_pool -gst_vaapi_video_meta_get_surface -gst_vaapi_video_meta_set_surface -gst_vaapi_video_meta_set_surface_from_pool -gst_vaapi_video_meta_set_surface_converter -gst_vaapi_video_meta_get_surface_converter -gst_vaapi_video_meta_get_surface_proxy -gst_vaapi_video_meta_set_surface_proxy -gst_vaapi_video_meta_get_render_flags -gst_vaapi_video_meta_set_render_flags - -gst_vaapi_video_meta_get_type -
-
gstvaapitypes Basic data structures diff --git a/gst-libs/gst/vaapi/Makefile.am b/gst-libs/gst/vaapi/Makefile.am index 90ec07b839..16a27a60ff 100644 --- a/gst-libs/gst/vaapi/Makefile.am +++ b/gst-libs/gst/vaapi/Makefile.am @@ -68,7 +68,6 @@ libgstvaapi_source_c = \ gstvaapisurfaceproxy.c \ gstvaapiutils.c \ gstvaapivalue.c \ - gstvaapivideometa.c \ gstvaapivideopool.c \ gstvaapiwindow.c \ $(NULL) @@ -94,7 +93,6 @@ libgstvaapi_source_h = \ gstvaapisurfaceproxy.h \ gstvaapitypes.h \ gstvaapivalue.h \ - gstvaapivideometa.h \ gstvaapivideopool.h \ gstvaapiwindow.h \ $(NULL) diff --git a/gst/vaapi/Makefile.am b/gst/vaapi/Makefile.am index b2e442c4ff..c5955cb4c2 100644 --- a/gst/vaapi/Makefile.am +++ b/gst/vaapi/Makefile.am @@ -39,6 +39,7 @@ libgstvaapi_source_c = \ gstvaapiupload.c \ gstvaapiuploader.c \ gstvaapivideobuffer.c \ + gstvaapivideometa.c \ $(NULL) libgstvaapi_source_h = \ @@ -50,6 +51,7 @@ libgstvaapi_source_h = \ gstvaapiupload.h \ gstvaapiuploader.h \ gstvaapivideobuffer.h \ + gstvaapivideometa.h \ $(NULL) if USE_GLX diff --git a/gst/vaapi/gstvaapidecode.c b/gst/vaapi/gstvaapidecode.c index 8d19182aef..18377fe88e 100644 --- a/gst/vaapi/gstvaapidecode.c +++ b/gst/vaapi/gstvaapidecode.c @@ -30,7 +30,6 @@ #include "gst/vaapi/sysdeps.h" #include -#include #include #include "gstvaapidecode.h" diff --git a/gst/vaapi/gstvaapidownload.c b/gst/vaapi/gstvaapidownload.c index 9bb032f8e3..f90cfa2af9 100644 --- a/gst/vaapi/gstvaapidownload.c +++ b/gst/vaapi/gstvaapidownload.c @@ -31,7 +31,6 @@ #include #include #include -#include #include "gstvaapidownload.h" #include "gstvaapipluginutil.h" diff --git a/gst/vaapi/gstvaapipostproc.c b/gst/vaapi/gstvaapipostproc.c index e2f0e5cad7..bb0d76c12d 100644 --- a/gst/vaapi/gstvaapipostproc.c +++ b/gst/vaapi/gstvaapipostproc.c @@ -31,7 +31,6 @@ #include "gst/vaapi/sysdeps.h" #include #include -#include #include "gstvaapipostproc.h" #include "gstvaapipluginutil.h" diff --git a/gst/vaapi/gstvaapisink.c b/gst/vaapi/gstvaapisink.c index ff062ba006..0669d22906 100644 --- a/gst/vaapi/gstvaapisink.c +++ b/gst/vaapi/gstvaapisink.c @@ -34,7 +34,6 @@ #include #include #include -#include #if USE_DRM # include #endif @@ -56,6 +55,7 @@ #include "gstvaapisink.h" #include "gstvaapipluginutil.h" +#include "gstvaapivideometa.h" #define GST_PLUGIN_NAME "vaapisink" #define GST_PLUGIN_DESC "A VA-API based videosink" diff --git a/gst/vaapi/gstvaapiupload.c b/gst/vaapi/gstvaapiupload.c index 9ac8d7a589..ecb0743e65 100644 --- a/gst/vaapi/gstvaapiupload.c +++ b/gst/vaapi/gstvaapiupload.c @@ -32,7 +32,6 @@ #include #include #include -#include #include "gstvaapiupload.h" #include "gstvaapipluginutil.h" diff --git a/gst/vaapi/gstvaapiuploader.c b/gst/vaapi/gstvaapiuploader.c index 1c898d37f9..a0d5ef1357 100644 --- a/gst/vaapi/gstvaapiuploader.c +++ b/gst/vaapi/gstvaapiuploader.c @@ -26,7 +26,6 @@ #include #include #include -#include #include "gstvaapiuploader.h" #include "gstvaapivideobuffer.h" diff --git a/gst/vaapi/gstvaapivideobuffer.h b/gst/vaapi/gstvaapivideobuffer.h index e658172fe7..36bbd28abf 100644 --- a/gst/vaapi/gstvaapivideobuffer.h +++ b/gst/vaapi/gstvaapivideobuffer.h @@ -23,7 +23,7 @@ #ifndef GST_VAAPI_VIDEO_BUFFER_H #define GST_VAAPI_VIDEO_BUFFER_H -#include +#include "gstvaapivideometa.h" G_BEGIN_DECLS diff --git a/gst/vaapi/gstvaapivideoconverter_glx.c b/gst/vaapi/gstvaapivideoconverter_glx.c index 7cbd65479d..323013f39b 100644 --- a/gst/vaapi/gstvaapivideoconverter_glx.c +++ b/gst/vaapi/gstvaapivideoconverter_glx.c @@ -22,10 +22,10 @@ */ #include "gst/vaapi/sysdeps.h" -#include #include #include "gstvaapivideoconverter_glx.h" #include "gstvaapipluginutil.h" +#include "gstvaapivideometa.h" typedef gboolean (*GstSurfaceUploadFunction)(GstSurfaceConverter *, GstSurfaceBuffer *); diff --git a/gst-libs/gst/vaapi/gstvaapivideometa.c b/gst/vaapi/gstvaapivideometa.c similarity index 91% rename from gst-libs/gst/vaapi/gstvaapivideometa.c rename to gst/vaapi/gstvaapivideometa.c index 95f016848a..2b4370093d 100644 --- a/gst-libs/gst/vaapi/gstvaapivideometa.c +++ b/gst/vaapi/gstvaapivideometa.c @@ -25,15 +25,13 @@ * @short_description: VA video meta for GStreamer */ -#include "sysdeps.h" +#include "gst/vaapi/sysdeps.h" +#include +#include #include "gstvaapivideometa.h" -#include "gstvaapiminiobject.h" -#include "gstvaapiimagepool.h" -#include "gstvaapisurfacepool.h" -#include "gstvaapiobject_priv.h" -#define DEBUG 1 -#include "gstvaapidebug.h" +#define GST_VAAPI_TYPE_VIDEO_META \ + (gst_vaapi_video_meta_get_type()) #define GST_VAAPI_VIDEO_META(obj) \ ((GstVaapiVideoMeta *)(obj)) @@ -42,6 +40,7 @@ (GST_VAAPI_VIDEO_META(obj) != NULL) struct _GstVaapiVideoMeta { + gint ref_count; GstVaapiDisplay *display; GstVaapiVideoPool *image_pool; GstVaapiImage *image; @@ -65,14 +64,14 @@ static inline void set_image(GstVaapiVideoMeta *meta, GstVaapiImage *image) { meta->image = g_object_ref(image); - set_display(meta, GST_VAAPI_OBJECT_DISPLAY(image)); + set_display(meta, gst_vaapi_object_get_display(GST_VAAPI_OBJECT(image))); } static inline void set_surface(GstVaapiVideoMeta *meta, GstVaapiSurface *surface) { meta->surface = g_object_ref(surface); - set_display(meta, GST_VAAPI_OBJECT_DISPLAY(surface)); + set_display(meta, gst_vaapi_object_get_display(GST_VAAPI_OBJECT(surface))); } static void @@ -101,7 +100,7 @@ gst_vaapi_video_meta_destroy_surface(GstVaapiVideoMeta *meta) g_clear_object(&meta->surface_pool); } -GType +static GType gst_vaapi_video_meta_get_type(void) { static gsize g_type; @@ -127,6 +126,7 @@ gst_vaapi_video_meta_finalize(GstVaapiVideoMeta *meta) static void gst_vaapi_video_meta_init(GstVaapiVideoMeta *meta) { + meta->ref_count = 1; meta->display = NULL; meta->image_pool = NULL; meta->image = NULL; @@ -137,28 +137,29 @@ gst_vaapi_video_meta_init(GstVaapiVideoMeta *meta) meta->render_flags = 0; } -static inline const GstVaapiMiniObjectClass * -gst_vaapi_video_meta_class(void) -{ - static const GstVaapiMiniObjectClass GstVaapiVideoMetaClass = { - sizeof(GstVaapiVideoMeta), - (GDestroyNotify)gst_vaapi_video_meta_finalize - }; - return &GstVaapiVideoMetaClass; -} - static inline GstVaapiVideoMeta * _gst_vaapi_video_meta_new(void) { GstVaapiVideoMeta *meta; - meta = (GstVaapiVideoMeta *) - gst_vaapi_mini_object_new(gst_vaapi_video_meta_class()); - if (meta) - gst_vaapi_video_meta_init(meta); + meta = g_slice_alloc(sizeof(*meta)); + if (!meta) + return NULL; + gst_vaapi_video_meta_init(meta); return meta; } +static inline void +_gst_vaapi_video_meta_free(GstVaapiVideoMeta *meta) +{ + g_atomic_int_inc(&meta->ref_count); + + gst_vaapi_video_meta_finalize(meta); + + if (G_LIKELY(g_atomic_int_dec_and_test(&meta->ref_count))) + g_slice_free1(sizeof(*meta), meta); +} + /** * gst_vaapi_video_meta_new: * @display: a #GstVaapiDisplay @@ -317,8 +318,10 @@ gst_vaapi_video_meta_new_with_surface_proxy(GstVaapiSurfaceProxy *proxy) GstVaapiVideoMeta * gst_vaapi_video_meta_ref(GstVaapiVideoMeta *meta) { - return (GstVaapiVideoMeta *) - gst_vaapi_mini_object_ref(GST_VAAPI_MINI_OBJECT(meta)); + g_return_val_if_fail(meta != NULL, NULL); + + g_atomic_int_inc(&meta->ref_count); + return meta; } /** @@ -331,7 +334,11 @@ gst_vaapi_video_meta_ref(GstVaapiVideoMeta *meta) void gst_vaapi_video_meta_unref(GstVaapiVideoMeta *meta) { - gst_vaapi_mini_object_unref(GST_VAAPI_MINI_OBJECT(meta)); + g_return_if_fail(meta != NULL); + g_return_if_fail(meta->ref_count > 0); + + if (g_atomic_int_dec_and_test(&meta->ref_count)) + _gst_vaapi_video_meta_free(meta); } /** @@ -347,8 +354,24 @@ void gst_vaapi_video_meta_replace(GstVaapiVideoMeta **old_meta_ptr, GstVaapiVideoMeta *new_meta) { - gst_vaapi_mini_object_replace((GstVaapiMiniObject **)(old_meta_ptr), - (GstVaapiMiniObject *)(new_meta)); + GstVaapiVideoMeta *old_meta; + + g_return_if_fail(old_meta_ptr != NULL); + + old_meta = g_atomic_pointer_get((gpointer *)old_meta_ptr); + + if (old_meta == new_meta) + return; + + if (new_meta) + gst_vaapi_video_meta_ref(new_meta); + + while (!g_atomic_pointer_compare_and_exchange((gpointer *)old_meta_ptr, + old_meta, new_meta)) + old_meta = g_atomic_pointer_get((gpointer *)old_meta_ptr); + + if (old_meta) + gst_vaapi_video_meta_unref(old_meta); } /** diff --git a/gst-libs/gst/vaapi/gstvaapivideometa.h b/gst/vaapi/gstvaapivideometa.h similarity index 89% rename from gst-libs/gst/vaapi/gstvaapivideometa.h rename to gst/vaapi/gstvaapivideometa.h index 42bda676c4..47d07e345d 100644 --- a/gst-libs/gst/vaapi/gstvaapivideometa.h +++ b/gst/vaapi/gstvaapivideometa.h @@ -31,85 +31,102 @@ G_BEGIN_DECLS -#define GST_VAAPI_TYPE_VIDEO_META \ - (gst_vaapi_video_meta_get_type()) - typedef struct _GstVaapiVideoMeta GstVaapiVideoMeta; -GType -gst_vaapi_video_meta_get_type(void) G_GNUC_CONST; - +G_GNUC_INTERNAL GstVaapiVideoMeta * gst_vaapi_video_meta_new(GstVaapiDisplay *display); +G_GNUC_INTERNAL GstVaapiVideoMeta * gst_vaapi_video_meta_new_from_pool(GstVaapiVideoPool *pool); +G_GNUC_INTERNAL GstVaapiVideoMeta * gst_vaapi_video_meta_new_with_image(GstVaapiImage *image); +G_GNUC_INTERNAL GstVaapiVideoMeta * gst_vaapi_video_meta_new_with_surface(GstVaapiSurface *surface); +G_GNUC_INTERNAL GstVaapiVideoMeta * gst_vaapi_video_meta_new_with_surface_proxy(GstVaapiSurfaceProxy *proxy); +G_GNUC_INTERNAL GstVaapiVideoMeta * gst_vaapi_video_meta_ref(GstVaapiVideoMeta *meta); +G_GNUC_INTERNAL void gst_vaapi_video_meta_unref(GstVaapiVideoMeta *meta); +G_GNUC_INTERNAL void gst_vaapi_video_meta_replace(GstVaapiVideoMeta **old_meta_ptr, GstVaapiVideoMeta *new_meta); +G_GNUC_INTERNAL GstVaapiDisplay * gst_vaapi_video_meta_get_display(GstVaapiVideoMeta *meta); +G_GNUC_INTERNAL GstVaapiImage * gst_vaapi_video_meta_get_image(GstVaapiVideoMeta *meta); +G_GNUC_INTERNAL void gst_vaapi_video_meta_set_image(GstVaapiVideoMeta *meta, GstVaapiImage *image); +G_GNUC_INTERNAL gboolean gst_vaapi_video_meta_set_image_from_pool(GstVaapiVideoMeta *meta, GstVaapiVideoPool *pool); +G_GNUC_INTERNAL GstVaapiSurface * gst_vaapi_video_meta_get_surface(GstVaapiVideoMeta *meta); +G_GNUC_INTERNAL void gst_vaapi_video_meta_set_surface(GstVaapiVideoMeta *meta, GstVaapiSurface *surface); +G_GNUC_INTERNAL gboolean gst_vaapi_video_meta_set_surface_from_pool(GstVaapiVideoMeta *meta, GstVaapiVideoPool *pool); +G_GNUC_INTERNAL GstVaapiSurfaceProxy * gst_vaapi_video_meta_get_surface_proxy(GstVaapiVideoMeta *meta); +G_GNUC_INTERNAL void gst_vaapi_video_meta_set_surface_proxy(GstVaapiVideoMeta *meta, GstVaapiSurfaceProxy *proxy); +G_GNUC_INTERNAL GFunc gst_vaapi_video_meta_get_surface_converter(GstVaapiVideoMeta *meta); +G_GNUC_INTERNAL void gst_vaapi_video_meta_set_surface_converter(GstVaapiVideoMeta *meta, GFunc func); +G_GNUC_INTERNAL guint gst_vaapi_video_meta_get_render_flags(GstVaapiVideoMeta *meta); +G_GNUC_INTERNAL void gst_vaapi_video_meta_set_render_flags(GstVaapiVideoMeta *meta, guint flags); +G_GNUC_INTERNAL GstVaapiVideoMeta * gst_buffer_get_vaapi_video_meta(GstBuffer *buffer); +G_GNUC_INTERNAL void gst_buffer_set_vaapi_video_meta(GstBuffer *buffer, GstVaapiVideoMeta *meta);