From c902a6f52537c515c75a9950863acc9b4582c03b Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Tue, 28 Apr 2015 20:11:07 +1000 Subject: [PATCH] glupload: provide the sink template caps that could be used https://bugzilla.gnome.org/show_bug.cgi?id=746399 --- ext/gl/gstglfilterbin.c | 12 +++++------- ext/gl/gstglmixerbin.c | 13 ++++++------- ext/gl/gstglsinkbin.c | 11 ++++------- ext/gl/gstgluploadelement.c | 12 +++++------- gst-libs/gst/gl/gstglmemory.h | 4 ++++ gst-libs/gst/gl/gstglupload.c | 34 ++++++++++++++++++++++++++++++++++ gst-libs/gst/gl/gstglupload.h | 2 ++ 7 files changed, 60 insertions(+), 28 deletions(-) diff --git a/ext/gl/gstglfilterbin.c b/ext/gl/gstglfilterbin.c index ecaa051357..a8e703e5d7 100644 --- a/ext/gl/gstglfilterbin.c +++ b/ext/gl/gstglfilterbin.c @@ -61,17 +61,12 @@ static GstStaticPadTemplate _src_pad_template = GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_ALWAYS, GST_STATIC_CAPS ("video/x-raw(ANY)")); -static GstStaticPadTemplate _sink_pad_template = -GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("video/x-raw(ANY)")); - static void gst_gl_filter_bin_class_init (GstGLFilterBinClass * klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); GstElementClass *element_class = GST_ELEMENT_CLASS (klass); + GstCaps *upload_caps; element_class->change_state = gst_gl_filter_bin_change_state; @@ -80,8 +75,11 @@ gst_gl_filter_bin_class_init (GstGLFilterBinClass * klass) gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&_src_pad_template)); + + upload_caps = gst_gl_upload_get_input_template_caps (); gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&_sink_pad_template)); + gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, upload_caps)); + gst_caps_unref (upload_caps); g_object_class_install_property (gobject_class, PROP_FILTER, g_param_spec_object ("filter", diff --git a/ext/gl/gstglmixerbin.c b/ext/gl/gstglmixerbin.c index 2dada971d7..47fff2a542 100644 --- a/ext/gl/gstglmixerbin.c +++ b/ext/gl/gstglmixerbin.c @@ -110,12 +110,6 @@ static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src", GST_STATIC_CAPS ("video/x-raw(ANY)") ); -static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink_%u", - GST_PAD_SINK, - GST_PAD_REQUEST, - GST_STATIC_CAPS ("video/x-raw(ANY)") - ); - static void gst_gl_mixer_bin_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec); static void gst_gl_mixer_bin_get_property (GObject * object, guint prop_id, @@ -133,6 +127,7 @@ gst_gl_mixer_bin_class_init (GstGLMixerBinClass * klass) { GObjectClass *gobject_class = (GObjectClass *) klass; GstElementClass *element_class = GST_ELEMENT_CLASS (klass); + GstCaps *upload_caps; g_type_class_add_private (klass, sizeof (GstGLMixerBinPrivate)); @@ -178,8 +173,12 @@ gst_gl_mixer_bin_class_init (GstGLMixerBinClass * klass) gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&src_factory)); + + upload_caps = gst_gl_upload_get_input_template_caps (); gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&sink_factory)); + gst_pad_template_new ("sink_%u", GST_PAD_SINK, GST_PAD_REQUEST, + upload_caps)); + gst_caps_unref (upload_caps); } static void diff --git a/ext/gl/gstglsinkbin.c b/ext/gl/gstglsinkbin.c index 320a9470be..1f4bd531c3 100644 --- a/ext/gl/gstglsinkbin.c +++ b/ext/gl/gstglsinkbin.c @@ -43,12 +43,6 @@ static void gst_gl_sink_bin_video_overlay_init (gpointer g_iface, static void gst_gl_sink_bin_navigation_interface_init (gpointer g_iface, gpointer g_iface_data); -static GstStaticPadTemplate gst_gl_sink_bin_template = -GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("video/x-raw(ANY)")); - enum { PROP_0, @@ -79,6 +73,7 @@ gst_gl_sink_bin_class_init (GstGLSinkBinClass * klass) { GObjectClass *gobject_class; GstElementClass *element_class; + GstCaps *upload_caps; gobject_class = (GObjectClass *) klass; element_class = GST_ELEMENT_CLASS (klass); @@ -119,8 +114,10 @@ gst_gl_sink_bin_class_init (GstGLSinkBinClass * klass) "Infrastructure to process GL textures", "Matthew Waters "); + upload_caps = gst_gl_upload_get_input_template_caps (); gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&gst_gl_sink_bin_template)); + gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, upload_caps)); + gst_caps_unref (upload_caps); } static void diff --git a/ext/gl/gstgluploadelement.c b/ext/gl/gstgluploadelement.c index fc8883ddaf..42f5fa4095 100644 --- a/ext/gl/gstgluploadelement.c +++ b/ext/gl/gstgluploadelement.c @@ -72,17 +72,12 @@ GST_STATIC_PAD_TEMPLATE ("src", GST_PAD_ALWAYS, GST_STATIC_CAPS ("video/x-raw(ANY)")); -static GstStaticPadTemplate gst_gl_upload_element_sink_pad_template = -GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS ("video/x-raw(ANY)")); - static void gst_gl_upload_element_class_init (GstGLUploadElementClass * klass) { GstBaseTransformClass *bt_class = GST_BASE_TRANSFORM_CLASS (klass); GstElementClass *element_class = GST_ELEMENT_CLASS (klass); + GstCaps *upload_caps; bt_class->query = gst_gl_upload_element_query; bt_class->transform_caps = _gst_gl_upload_element_transform_caps; @@ -98,8 +93,11 @@ gst_gl_upload_element_class_init (GstGLUploadElementClass * klass) gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&gst_gl_upload_element_src_pad_template)); + + upload_caps = gst_gl_upload_get_input_template_caps (); gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&gst_gl_upload_element_sink_pad_template)); + gst_pad_template_new ("sink", GST_PAD_SINK, GST_PAD_ALWAYS, upload_caps)); + gst_caps_unref (upload_caps); gst_element_class_set_metadata (element_class, "OpenGL uploader", "Filter/Video", diff --git a/gst-libs/gst/gl/gstglmemory.h b/gst-libs/gst/gl/gstglmemory.h index 87033c0f56..28db0a45e0 100644 --- a/gst-libs/gst/gl/gstglmemory.h +++ b/gst-libs/gst/gl/gstglmemory.h @@ -109,6 +109,10 @@ struct _GstGLMemory }; #define GST_CAPS_FEATURE_MEMORY_GL_MEMORY "memory:GLMemory" +#define GST_GL_MEMORY_VIDEO_FORMATS_STR \ + "{ RGBA, BGRA, RGBx, BGRx, ARGB, ABGR, xRGB, xBGR, RGB, BGR, RGB16, BGR16, " \ + "AYUV, I420, YV12, NV12, NV21, YUY2, UYVY, Y41B, Y42B, Y444, " \ + "GRAY8, GRAY16_LE, GRAY16_BE }" /** * GST_GL_MEMORY_ALLOCATOR: diff --git a/gst-libs/gst/gl/gstglupload.c b/gst-libs/gst/gl/gstglupload.c index 9309b4648c..f93936de15 100644 --- a/gst-libs/gst/gl/gstglupload.c +++ b/gst-libs/gst/gl/gstglupload.c @@ -97,6 +97,8 @@ struct _UploadMethod const gchar *name; GstGLUploadMethodFlags flags; + GstStaticCaps input_template_caps; + gpointer (*new) (GstGLUpload * upload); GstCaps *(*transform_caps) (GstGLContext * context, GstPadDirection direction, GstCaps * caps); @@ -277,6 +279,8 @@ _gl_memory_upload_free (gpointer impl) static const UploadMethod _gl_memory_upload = { "GLMemory", METHOD_FLAG_CAN_SHARE_CONTEXT, + GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE_WITH_FEATURES + (GST_CAPS_FEATURE_MEMORY_GL_MEMORY, GST_GL_MEMORY_VIDEO_FORMATS_STR)), &_gl_memory_upload_new, &_gl_memory_upload_transform_caps, &_gl_memory_upload_accept, @@ -445,6 +449,8 @@ _egl_image_upload_free (gpointer impl) static const UploadMethod _egl_image_upload = { "EGLImage", 0, + GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE_WITH_FEATURES + (GST_CAPS_FEATURE_MEMORY_EGL_IMAGE, "RGBA")), &_egl_image_upload_new, &_egl_image_upload_transform_caps, &_egl_image_upload_accept, @@ -651,6 +657,8 @@ _upload_meta_upload_free (gpointer impl) static const UploadMethod _upload_meta_upload = { "UploadMeta", METHOD_FLAG_CAN_SHARE_CONTEXT, + GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE_WITH_FEATURES + (GST_CAPS_FEATURE_META_GST_VIDEO_GL_TEXTURE_UPLOAD_META, "RGBA")), &_upload_meta_upload_new, &_upload_meta_upload_transform_caps, &_upload_meta_upload_accept, @@ -780,6 +788,7 @@ _raw_data_upload_free (gpointer impl) static const UploadMethod _raw_data_upload = { "Raw Data", 0, + GST_STATIC_CAPS (GST_VIDEO_CAPS_MAKE (GST_GL_MEMORY_VIDEO_FORMATS_STR)), &_raw_data_upload_new, &_raw_data_upload_transform_caps, &_raw_data_upload_accept, @@ -796,6 +805,31 @@ static const UploadMethod *upload_methods[] = { &_gl_memory_upload, &_upload_meta_upload, &_raw_data_upload }; +static GMutex upload_global_lock; + +GstCaps * +gst_gl_upload_get_input_template_caps (void) +{ + GstCaps *ret = NULL; + gint i; + + g_mutex_lock (&upload_global_lock); + + /* FIXME: cache this and invalidate on changes to upload_methods */ + for (i = 0; i < G_N_ELEMENTS (upload_methods); i++) { + GstCaps *template = + gst_static_caps_get ((GstStaticCaps *) & + upload_methods[i]->input_template_caps); + ret = ret == NULL ? template : gst_caps_merge (ret, template); + } + + ret = gst_caps_simplify (ret); + + g_mutex_unlock (&upload_global_lock); + + return ret; +} + #define DEBUG_INIT \ GST_DEBUG_CATEGORY_INIT (gst_gl_upload_debug, "glupload", 0, "upload"); diff --git a/gst-libs/gst/gl/gstglupload.h b/gst-libs/gst/gl/gstglupload.h index 865289143d..5bc4346822 100644 --- a/gst-libs/gst/gl/gstglupload.h +++ b/gst-libs/gst/gl/gstglupload.h @@ -78,6 +78,8 @@ struct _GstGLUploadClass GstObjectClass object_class; }; +GstCaps * gst_gl_upload_get_input_template_caps (void); + GstGLUpload * gst_gl_upload_new (GstGLContext * context); GstCaps * gst_gl_upload_transform_caps (GstGLContext * context,