From 01a3fc44c01628ff854f10b3ee8e1f64cc9bf660 Mon Sep 17 00:00:00 2001 From: Gwenole Beauchesne Date: Fri, 13 Dec 2013 16:03:08 +0100 Subject: [PATCH] plugins: factor out video context sharing code. --- gst/vaapi/gstvaapidecode.c | 46 +---------------------------- gst/vaapi/gstvaapidownload.c | 21 +------------- gst/vaapi/gstvaapiencode.c | 48 +----------------------------- gst/vaapi/gstvaapipluginbase.c | 44 ++++++++++++++++++++++++++++ gst/vaapi/gstvaapipostproc.c | 53 +--------------------------------- gst/vaapi/gstvaapisink.c | 41 -------------------------- gst/vaapi/gstvaapiupload.c | 26 +---------------- 7 files changed, 49 insertions(+), 230 deletions(-) diff --git a/gst/vaapi/gstvaapidecode.c b/gst/vaapi/gstvaapidecode.c index 851659b3c1..9cc5f78f20 100644 --- a/gst/vaapi/gstvaapidecode.c +++ b/gst/vaapi/gstvaapidecode.c @@ -35,7 +35,6 @@ #include "gstvaapidecode.h" #include "gstvaapipluginutil.h" -#include "gstvaapivideocontext.h" #include "gstvaapivideobuffer.h" #if GST_CHECK_VERSION(1,1,0) && USE_GLX #include "gstvaapivideometa_texture.h" @@ -95,35 +94,11 @@ static GstStaticPadTemplate gst_vaapidecode_src_factory = GST_PAD_ALWAYS, GST_STATIC_CAPS(gst_vaapidecode_src_caps_str)); -/* GstVideoContext interface */ -#if !GST_CHECK_VERSION(1,1,0) -static void -gst_vaapidecode_set_video_context(GstVideoContext *context, const gchar *type, - const GValue *value) -{ - GstVaapiDecode *decode = GST_VAAPIDECODE (context); - gst_vaapi_set_display (type, value, &GST_VAAPI_PLUGIN_BASE_DISPLAY(decode)); -} - -static void -gst_video_context_interface_init(GstVideoContextInterface *iface) -{ - iface->set_context = gst_vaapidecode_set_video_context; -} - -#define GstVideoContextClass GstVideoContextInterface -#endif - G_DEFINE_TYPE_WITH_CODE( GstVaapiDecode, gst_vaapidecode, GST_TYPE_VIDEO_DECODER, - GST_VAAPI_PLUGIN_BASE_INIT_INTERFACES -#if !GST_CHECK_VERSION(1,1,0) - G_IMPLEMENT_INTERFACE(GST_TYPE_VIDEO_CONTEXT, - gst_video_context_interface_init) -#endif - ) + GST_VAAPI_PLUGIN_BASE_INIT_INTERFACES) static gboolean gst_vaapidecode_update_src_caps(GstVaapiDecode *decode, @@ -564,21 +539,6 @@ error_create_pool: } #endif -#if GST_CHECK_VERSION(1,1,0) -static void -gst_vaapidecode_set_context(GstElement *element, GstContext *context) -{ - GstVaapiDecode * const decode = GST_VAAPIDECODE(element); - GstVaapiDisplay *display = NULL; - - if (gst_vaapi_video_context_get_display(context, &display)) { - GST_INFO_OBJECT(element, "set display %p", display); - GST_VAAPI_PLUGIN_BASE_DISPLAY_REPLACE(decode, display); - gst_vaapi_display_unref(display); - } -} -#endif - static inline gboolean gst_vaapidecode_ensure_display(GstVaapiDecode *decode) { @@ -833,10 +793,6 @@ gst_vaapidecode_class_init(GstVaapiDecodeClass *klass) GST_DEBUG_FUNCPTR(gst_vaapidecode_decide_allocation); #endif -#if GST_CHECK_VERSION(1,1,0) - element_class->set_context = GST_DEBUG_FUNCPTR(gst_vaapidecode_set_context); -#endif - gst_element_class_set_static_metadata(element_class, "VA-API decoder", "Codec/Decoder/Video", diff --git a/gst/vaapi/gstvaapidownload.c b/gst/vaapi/gstvaapidownload.c index a7bb9f2310..ff2a25a79e 100644 --- a/gst/vaapi/gstvaapidownload.c +++ b/gst/vaapi/gstvaapidownload.c @@ -32,7 +32,6 @@ #include "gst/vaapi/sysdeps.h" #include #include -#include #include "gstvaapidownload.h" #include "gstvaapipluginutil.h" @@ -91,29 +90,11 @@ struct _GstVaapiDownloadClass { GstVaapiPluginBaseClass parent_class; }; -/* GstVideoContext interface */ -static void -gst_vaapidownload_set_video_context(GstVideoContext *context, const gchar *type, - const GValue *value) -{ - GstVaapiDownload *download = GST_VAAPIDOWNLOAD (context); - gst_vaapi_set_display (type, value, &GST_VAAPI_PLUGIN_BASE_DISPLAY(download)); -} - -static void -gst_video_context_interface_init(GstVideoContextInterface *iface) -{ - iface->set_context = gst_vaapidownload_set_video_context; -} - -#define GstVideoContextClass GstVideoContextInterface G_DEFINE_TYPE_WITH_CODE( GstVaapiDownload, gst_vaapidownload, GST_TYPE_BASE_TRANSFORM, - GST_VAAPI_PLUGIN_BASE_INIT_INTERFACES - G_IMPLEMENT_INTERFACE(GST_TYPE_VIDEO_CONTEXT, - gst_video_context_interface_init)) + GST_VAAPI_PLUGIN_BASE_INIT_INTERFACES) static gboolean gst_vaapidownload_start(GstBaseTransform *trans); diff --git a/gst/vaapi/gstvaapiencode.c b/gst/vaapi/gstvaapiencode.c index b4d49ef8e6..87fadc09f5 100644 --- a/gst/vaapi/gstvaapiencode.c +++ b/gst/vaapi/gstvaapiencode.c @@ -23,7 +23,6 @@ #include #include #include "gstvaapiencode.h" -#include "gstvaapivideocontext.h" #include "gstvaapipluginutil.h" #include "gstvaapivideometa.h" #if GST_CHECK_VERSION(1,0,0) @@ -42,47 +41,9 @@ GST_DEBUG_CATEGORY_STATIC (gst_vaapiencode_debug); #define GST_CAT_DEFAULT gst_vaapiencode_debug -/* GstContext interface */ -#if GST_CHECK_VERSION(1,1,0) -static void -gst_vaapiencode_set_context (GstElement * element, GstContext * context) -{ - GstVaapiEncode *const encode = GST_VAAPIENCODE_CAST (element); - GstVaapiDisplay *display = NULL; - - if (gst_vaapi_video_context_get_display (context, &display)) { - GST_INFO_OBJECT (element, "set display %p", display); - GST_VAAPI_PLUGIN_BASE_DISPLAY_REPLACE (encode, display); - gst_vaapi_display_unref (display); - } -} -#else -static void -gst_vaapiencode_set_video_context (GstVideoContext * context, - const gchar * type, const GValue * value) -{ - GstVaapiEncode *const encode = GST_VAAPIENCODE_CAST (context); - - gst_vaapi_set_display (type, value, &GST_VAAPI_PLUGIN_BASE_DISPLAY (encode)); -} - -static void -gst_video_context_interface_init (GstVideoContextInterface * iface) -{ - iface->set_context = gst_vaapiencode_set_video_context; -} - -#define GstVideoContextClass GstVideoContextInterface -#endif - G_DEFINE_TYPE_WITH_CODE (GstVaapiEncode, gst_vaapiencode, GST_TYPE_VIDEO_ENCODER, - GST_VAAPI_PLUGIN_BASE_INIT_INTERFACES -#if !GST_CHECK_VERSION(1,1,0) - G_IMPLEMENT_INTERFACE (GST_TYPE_VIDEO_CONTEXT, - gst_video_context_interface_init) -#endif - ) + GST_VAAPI_PLUGIN_BASE_INIT_INTERFACES) enum { @@ -917,9 +878,6 @@ static void gst_vaapiencode_class_init (GstVaapiEncodeClass * klass) { GObjectClass *const object_class = G_OBJECT_CLASS (klass); -#if GST_CHECK_VERSION(1,1,0) - GstElementClass *const element_class = GST_ELEMENT_CLASS (klass); -#endif GstVideoEncoderClass *const venc_class = GST_VIDEO_ENCODER_CLASS (klass); GST_DEBUG_CATEGORY_INIT (gst_vaapiencode_debug, @@ -931,10 +889,6 @@ gst_vaapiencode_class_init (GstVaapiEncodeClass * klass) object_class->set_property = gst_vaapiencode_set_property; object_class->get_property = gst_vaapiencode_get_property; -#if GST_CHECK_VERSION(1,1,0) - element_class->set_context = GST_DEBUG_FUNCPTR (gst_vaapiencode_set_context); -#endif - venc_class->open = GST_DEBUG_FUNCPTR (gst_vaapiencode_open); venc_class->close = GST_DEBUG_FUNCPTR (gst_vaapiencode_close); venc_class->set_format = GST_DEBUG_FUNCPTR (gst_vaapiencode_set_format); diff --git a/gst/vaapi/gstvaapipluginbase.c b/gst/vaapi/gstvaapipluginbase.c index 35fadf5376..09e6b4b42a 100644 --- a/gst/vaapi/gstvaapipluginbase.c +++ b/gst/vaapi/gstvaapipluginbase.c @@ -25,6 +25,7 @@ #include "gst/vaapi/sysdeps.h" #include "gstvaapipluginbase.h" #include "gstvaapipluginutil.h" +#include "gstvaapivideocontext.h" /* Default debug category is from the subclass */ #define GST_CAT_DEFAULT (plugin->debug_category) @@ -36,6 +37,8 @@ implements_interface_supported (GstImplementsInterface * iface, GType type) { GstVaapiPluginBase *const plugin = GST_VAAPI_PLUGIN_BASE (iface); + if (type == GST_TYPE_VIDEO_CONTEXT) + return TRUE; return GST_VAAPI_PLUGIN_BASE_GET_CLASS (plugin)->has_interface (plugin, type); } @@ -46,6 +49,39 @@ implements_interface_init (GstImplementsInterfaceClass * iface) } #endif +/* GstVideoContext interface */ +#if GST_CHECK_VERSION(1,1,0) +static void +plugin_set_context (GstElement * element, GstContext * context) +{ + GstVaapiPluginBase *const plugin = GST_VAAPI_PLUGIN_BASE (element); + GstVaapiDisplay *display = NULL; + + if (gst_vaapi_video_context_get_display (context, &display)) { + GST_INFO_OBJECT (element, "set display %p", display); + gst_vaapi_display_replace (&plugin->display, display); + gst_vaapi_display_unref (display); + } +} +#else +static void +plugin_set_context (GstVideoContext * context, const gchar * type, + const GValue * value) +{ + GstVaapiPluginBase *const plugin = GST_VAAPI_PLUGIN_BASE (context); + + gst_vaapi_set_display (type, value, &plugin->display); +} + +static void +video_context_interface_init (GstVideoContextInterface * iface) +{ + iface->set_context = plugin_set_context; +} + +#define GstVideoContextClass GstVideoContextInterface +#endif + void gst_vaapi_plugin_base_init_interfaces (GType g_define_type_id) { @@ -53,6 +89,9 @@ gst_vaapi_plugin_base_init_interfaces (GType g_define_type_id) G_IMPLEMENT_INTERFACE (GST_TYPE_IMPLEMENTS_INTERFACE, implements_interface_init); #endif +#if !GST_CHECK_VERSION(1,1,0) + G_IMPLEMENT_INTERFACE (GST_TYPE_VIDEO_CONTEXT, video_context_interface_init); +#endif } static gboolean @@ -71,6 +110,11 @@ gst_vaapi_plugin_base_class_init (GstVaapiPluginBaseClass * klass) { klass->has_interface = default_has_interface; klass->display_changed = default_display_changed; + +#if GST_CHECK_VERSION(1,1,0) + GstElementClass *const element_class = GST_ELEMENT_CLASS (klass); + element_class->set_context = GST_DEBUG_FUNCPTR (plugin_set_context); +#endif } void diff --git a/gst/vaapi/gstvaapipostproc.c b/gst/vaapi/gstvaapipostproc.c index 36afd2d641..700c55e54e 100755 --- a/gst/vaapi/gstvaapipostproc.c +++ b/gst/vaapi/gstvaapipostproc.c @@ -34,7 +34,6 @@ #include "gstvaapipostproc.h" #include "gstvaapipluginutil.h" -#include "gstvaapivideocontext.h" #include "gstvaapivideobuffer.h" #if GST_CHECK_VERSION(1,0,0) #include "gstvaapivideobufferpool.h" @@ -89,42 +88,11 @@ static GstStaticPadTemplate gst_vaapipostproc_src_factory = GST_PAD_ALWAYS, GST_STATIC_CAPS(gst_vaapipostproc_src_caps_str)); -/* GstVideoContext interface */ -#if !GST_CHECK_VERSION(1,1,0) -static void -gst_vaapipostproc_set_video_context( - GstVideoContext *context, - const gchar *type, - const GValue *value -) -{ - GstVaapiPostproc * const postproc = GST_VAAPIPOSTPROC(context); - - gst_vaapi_set_display(type, value, &GST_VAAPI_PLUGIN_BASE_DISPLAY(postproc)); - - if (postproc->uploader) - gst_vaapi_uploader_ensure_display(postproc->uploader, GST_VAAPI_PLUGIN_BASE_DISPLAY(postproc)); -} - -static void -gst_video_context_interface_init(GstVideoContextInterface *iface) -{ - iface->set_context = gst_vaapipostproc_set_video_context; -} - -#define GstVideoContextClass GstVideoContextInterface -#endif - G_DEFINE_TYPE_WITH_CODE( GstVaapiPostproc, gst_vaapipostproc, GST_TYPE_BASE_TRANSFORM, - GST_VAAPI_PLUGIN_BASE_INIT_INTERFACES -#if !GST_CHECK_VERSION(1,1,0) - G_IMPLEMENT_INTERFACE(GST_TYPE_VIDEO_CONTEXT, - gst_video_context_interface_init) -#endif - ) + GST_VAAPI_PLUGIN_BASE_INIT_INTERFACES) enum { PROP_0, @@ -233,21 +201,6 @@ find_filter_op(GPtrArray *filter_ops, GstVaapiFilterOp op) return NULL; } -#if GST_CHECK_VERSION(1,1,0) -static void -gst_vaapipostproc_set_context(GstElement *element, GstContext *context) -{ - GstVaapiPostproc * const postproc = GST_VAAPIPOSTPROC(element); - GstVaapiDisplay *display = NULL; - - if (gst_vaapi_video_context_get_display(context, &display)) { - GST_INFO_OBJECT(element, "set display %p", display); - GST_VAAPI_PLUGIN_BASE_DISPLAY_REPLACE(postproc, display); - gst_vaapi_display_unref(display); - } -} -#endif - static inline gboolean gst_vaapipostproc_ensure_display(GstVaapiPostproc *postproc) { @@ -1627,10 +1580,6 @@ gst_vaapipostproc_class_init(GstVaapiPostprocClass *klass) trans_class->prepare_output_buffer = gst_vaapipostproc_prepare_output_buffer; -#if GST_CHECK_VERSION(1,1,0) - element_class->set_context = gst_vaapipostproc_set_context; -#endif - gst_element_class_set_static_metadata(element_class, "VA-API video postprocessing", "Filter/Converter/Video", diff --git a/gst/vaapi/gstvaapisink.c b/gst/vaapi/gstvaapisink.c index 86fd91bbdc..2f081dff2c 100644 --- a/gst/vaapi/gstvaapisink.c +++ b/gst/vaapi/gstvaapisink.c @@ -71,7 +71,6 @@ #include "gstvaapisink.h" #include "gstvaapipluginutil.h" -#include "gstvaapivideocontext.h" #include "gstvaapivideometa.h" #if GST_CHECK_VERSION(1,0,0) #include "gstvaapivideobufferpool.h" @@ -107,23 +106,6 @@ static GstStaticPadTemplate gst_vaapisink_sink_factory = GST_PAD_ALWAYS, GST_STATIC_CAPS(gst_vaapisink_sink_caps_str)); -/* GstVideoContext interface */ -#if !GST_CHECK_VERSION(1,1,0) -static void -gst_vaapisink_set_video_context(GstVideoContext *context, const gchar *type, - const GValue *value) -{ - GstVaapiSink *sink = GST_VAAPISINK (context); - gst_vaapi_set_display (type, value, &GST_VAAPI_PLUGIN_BASE_DISPLAY(sink)); -} - -static void -gst_vaapisink_video_context_iface_init(GstVideoContextInterface *iface) -{ - iface->set_context = gst_vaapisink_set_video_context; -} -#endif - static gboolean gst_vaapisink_has_interface(GstVaapiPluginBase *plugin, GType type) { @@ -138,10 +120,6 @@ G_DEFINE_TYPE_WITH_CODE( gst_vaapisink, GST_TYPE_VIDEO_SINK, GST_VAAPI_PLUGIN_BASE_INIT_INTERFACES -#if !GST_CHECK_VERSION(1,1,0) - G_IMPLEMENT_INTERFACE(GST_TYPE_VIDEO_CONTEXT, - gst_vaapisink_video_context_iface_init); -#endif G_IMPLEMENT_INTERFACE(GST_TYPE_VIDEO_OVERLAY, gst_vaapisink_video_overlay_iface_init)) @@ -1342,21 +1320,6 @@ gst_vaapisink_buffer_alloc( } #endif -#if GST_CHECK_VERSION(1,1,0) -static void -gst_vaapisink_set_context(GstElement *element, GstContext *context) -{ - GstVaapiSink * const sink = GST_VAAPISINK(element); - GstVaapiDisplay *display = NULL; - - if (gst_vaapi_video_context_get_display(context, &display)) { - GST_INFO_OBJECT(element, "set display %p", display); - GST_VAAPI_PLUGIN_BASE_DISPLAY_REPLACE(sink, display); - gst_vaapi_display_unref(display); - } -} -#endif - static gboolean gst_vaapisink_query(GstBaseSink *base_sink, GstQuery *query) { @@ -1493,10 +1456,6 @@ gst_vaapisink_class_init(GstVaapiSinkClass *klass) basesink_class->buffer_alloc = gst_vaapisink_buffer_alloc; #endif -#if GST_CHECK_VERSION(1,1,0) - element_class->set_context = gst_vaapisink_set_context; -#endif - gst_element_class_set_static_metadata(element_class, "VA-API sink", "Sink/Video", diff --git a/gst/vaapi/gstvaapiupload.c b/gst/vaapi/gstvaapiupload.c index e74b0ca8d0..d4b52b7f25 100644 --- a/gst/vaapi/gstvaapiupload.c +++ b/gst/vaapi/gstvaapiupload.c @@ -33,7 +33,6 @@ #include "gst/vaapi/sysdeps.h" #include #include -#include #include "gstvaapiupload.h" #include "gstvaapipluginutil.h" @@ -68,34 +67,11 @@ static GstStaticPadTemplate gst_vaapiupload_src_factory = GST_PAD_ALWAYS, GST_STATIC_CAPS(gst_vaapiupload_vaapi_caps_str)); -/* GstVideoContext interface */ -static void -gst_vaapiupload_set_video_context(GstVideoContext *context, const gchar *type, - const GValue *value) -{ - GstVaapiUpload * const upload = GST_VAAPIUPLOAD(context); - - gst_vaapi_set_display(type, value, &GST_VAAPI_PLUGIN_BASE_DISPLAY(upload)); - - if (upload->uploader) - gst_vaapi_uploader_ensure_display(upload->uploader, - GST_VAAPI_PLUGIN_BASE_DISPLAY(upload)); -} - -static void -gst_video_context_interface_init(GstVideoContextInterface *iface) -{ - iface->set_context = gst_vaapiupload_set_video_context; -} - -#define GstVideoContextClass GstVideoContextInterface G_DEFINE_TYPE_WITH_CODE( GstVaapiUpload, gst_vaapiupload, GST_TYPE_BASE_TRANSFORM, - GST_VAAPI_PLUGIN_BASE_INIT_INTERFACES - G_IMPLEMENT_INTERFACE(GST_TYPE_VIDEO_CONTEXT, - gst_video_context_interface_init)) + GST_VAAPI_PLUGIN_BASE_INIT_INTERFACES) static gboolean gst_vaapiupload_start(GstBaseTransform *trans);