summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Waters <ystreet00@gmail.com>2014-03-15 14:06:40 +0100
committerMatthew Waters <ystreet00@gmail.com>2014-03-15 14:06:40 +0100
commit76eef8a6aed12c6f5a209339a9e8468a02441205 (patch)
tree9c133be3c172e01cc676bad557ca738f2d2afc4a
parent5e835c272374b8f176c9a082e75d97d881528467 (diff)
Add GL context sharing support for non-gstgl elements
-rw-r--r--gst-libs/gst/gl/gstglfilter.c43
-rw-r--r--gst-libs/gst/gl/gstglmixer.c39
-rw-r--r--gst/gl/gstglimagesink.c16
-rw-r--r--gst/gl/gstgltestsrc.c25
4 files changed, 117 insertions, 6 deletions
diff --git a/gst-libs/gst/gl/gstglfilter.c b/gst-libs/gst/gl/gstglfilter.c
index 5260bcc..2ce0ca3 100644
--- a/gst-libs/gst/gl/gstglfilter.c
+++ b/gst-libs/gst/gl/gstglfilter.c
@@ -735,6 +735,8 @@ gst_gl_filter_propose_allocation (GstBaseTransform * trans,
gboolean need_pool;
GError *error = NULL;
GstStructure *gl_context;
+ gchar *platform, *gl_apis;
+ gpointer handle;
gst_query_parse_allocation (query, &caps, &need_pool);
@@ -794,11 +796,22 @@ gst_gl_filter_propose_allocation (GstBaseTransform * trans,
/* we also support various metadata */
gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, 0);
+ gl_apis = gst_gl_api_to_string (gst_gl_context_get_gl_api (filter->context));
+ platform =
+ gst_gl_platform_to_string (gst_gl_context_get_gl_platform
+ (filter->context));
+ handle = (gpointer) gst_gl_context_get_gl_context (filter->context);
+
gl_context =
gst_structure_new ("GstVideoGLTextureUploadMeta", "gst.gl.GstGLContext",
- GST_GL_TYPE_CONTEXT, filter->context, NULL);
+ GST_GL_TYPE_CONTEXT, filter->context, "gst.gl.context.handle",
+ G_TYPE_POINTER, handle, "gst.gl.context.type", G_TYPE_STRING, platform,
+ "gst.gl.context.apis", G_TYPE_STRING, gl_apis, NULL);
gst_query_add_allocation_meta (query,
GST_VIDEO_GL_TEXTURE_UPLOAD_META_API_TYPE, gl_context);
+
+ g_free (gl_apis);
+ g_free (platform);
gst_structure_free (gl_context);
return TRUE;
@@ -840,6 +853,7 @@ gst_gl_filter_decide_allocation (GstBaseTransform * trans, GstQuery * query)
guint idx;
GError *error = NULL;
guint in_width, in_height, out_width, out_height;
+ GstGLContext *other_context = NULL;
gst_query_parse_allocation (query, &caps, NULL);
@@ -864,6 +878,9 @@ gst_gl_filter_decide_allocation (GstBaseTransform * trans, GstQuery * query)
GST_VIDEO_GL_TEXTURE_UPLOAD_META_API_TYPE, &idx)) {
GstGLContext *context;
const GstStructure *upload_meta_params;
+ gpointer handle;
+ gchar *type;
+ gchar *apis;
gst_query_parse_nth_allocation_meta (query, idx, &upload_meta_params);
if (gst_structure_get (upload_meta_params, "gst.gl.GstGLContext",
@@ -873,12 +890,34 @@ gst_gl_filter_decide_allocation (GstBaseTransform * trans, GstQuery * query)
filter->context = context;
if (old)
gst_object_unref (old);
+ } else if (gst_structure_get (upload_meta_params, "gst.gl.context.handle",
+ G_TYPE_POINTER, &handle, "gst.gl.context.type", G_TYPE_STRING,
+ &type, "gst.gl.context.apis", G_TYPE_STRING, &apis, NULL)
+ && handle) {
+ GstGLPlatform platform = GST_GL_PLATFORM_NONE;
+ GstGLAPI gl_apis;
+
+ GST_DEBUG ("got GL context handle 0x%p with type %s and apis %s", handle,
+ type, apis);
+
+ if (g_strcmp0 (type, "glx") == 0)
+ platform = GST_GL_PLATFORM_GLX;
+
+ gl_apis = gst_gl_api_from_string (apis);
+
+ if (gl_apis && platform)
+ other_context =
+ gst_gl_context_new_wrapped (filter->display, (guintptr) handle,
+ platform, gl_apis);
}
}
+ if (!other_context)
+ other_context = filter->other_context;
+
if (!filter->context) {
filter->context = gst_gl_context_new (filter->display);
- if (!gst_gl_context_create (filter->context, filter->other_context, &error))
+ if (!gst_gl_context_create (filter->context, other_context, &error))
goto context_error;
}
diff --git a/gst-libs/gst/gl/gstglmixer.c b/gst-libs/gst/gl/gstglmixer.c
index fe08208..f656087 100644
--- a/gst-libs/gst/gl/gstglmixer.c
+++ b/gst-libs/gst/gl/gstglmixer.c
@@ -328,6 +328,8 @@ gst_gl_mixer_propose_allocation (GstGLMixer * mix,
gboolean need_pool;
GError *error = NULL;
GstStructure *gl_context;
+ gchar *platform, *gl_apis;
+ gpointer handle;
gst_query_parse_allocation (query, &caps, &need_pool);
@@ -386,11 +388,21 @@ gst_gl_mixer_propose_allocation (GstGLMixer * mix,
/* we also support various metadata */
gst_query_add_allocation_meta (query, GST_VIDEO_META_API_TYPE, 0);
+ gl_apis = gst_gl_api_to_string (gst_gl_context_get_gl_api (mix->context));
+ platform =
+ gst_gl_platform_to_string (gst_gl_context_get_gl_platform (mix->context));
+ handle = (gpointer) gst_gl_context_get_gl_context (mix->context);
+
gl_context =
gst_structure_new ("GstVideoGLTextureUploadMeta", "gst.gl.GstGLContext",
- GST_GL_TYPE_CONTEXT, mix->context, NULL);
+ GST_GL_TYPE_CONTEXT, mix->context, "gst.gl.context.handle",
+ G_TYPE_POINTER, handle, "gst.gl.context.type", G_TYPE_STRING, platform,
+ "gst.gl.context.apis", G_TYPE_STRING, gl_apis, NULL);
gst_query_add_allocation_meta (query,
GST_VIDEO_GL_TEXTURE_UPLOAD_META_API_TYPE, gl_context);
+
+ g_free (gl_apis);
+ g_free (platform);
gst_structure_free (gl_context);
return TRUE;
@@ -1080,6 +1092,7 @@ gst_gl_mixer_decide_allocation (GstGLMixer * mix, GstQuery * query)
GError *error = NULL;
guint idx;
guint out_width, out_height;
+ GstGLContext *other_context = NULL;
gst_query_parse_allocation (query, &caps, NULL);
@@ -1104,6 +1117,9 @@ gst_gl_mixer_decide_allocation (GstGLMixer * mix, GstQuery * query)
GST_VIDEO_GL_TEXTURE_UPLOAD_META_API_TYPE, &idx)) {
GstGLContext *context;
const GstStructure *upload_meta_params;
+ gpointer handle;
+ gchar *type;
+ gchar *apis;
gst_query_parse_nth_allocation_meta (query, idx, &upload_meta_params);
if (gst_structure_get (upload_meta_params, "gst.gl.GstGLContext",
@@ -1113,12 +1129,31 @@ gst_gl_mixer_decide_allocation (GstGLMixer * mix, GstQuery * query)
mix->context = context;
if (old)
gst_object_unref (old);
+ } else if (gst_structure_get (upload_meta_params, "gst.gl.context.handle",
+ G_TYPE_POINTER, &handle, "gst.gl.context.type", G_TYPE_STRING,
+ &type, "gst.gl.context.apis", G_TYPE_STRING, &apis, NULL)
+ && handle) {
+ GstGLPlatform platform = GST_GL_PLATFORM_NONE;
+ GstGLAPI gl_apis;
+
+ GST_DEBUG ("got GL context handle 0x%p with type %s and apis %s", handle,
+ type, apis);
+
+ if (g_strcmp0 (type, "glx") == 0)
+ platform = GST_GL_PLATFORM_GLX;
+
+ gl_apis = gst_gl_api_from_string (apis);
+
+ if (gl_apis && platform)
+ other_context =
+ gst_gl_context_new_wrapped (mix->display, (guintptr) handle,
+ platform, gl_apis);
}
}
if (!mix->context) {
mix->context = gst_gl_context_new (mix->display);
- if (!gst_gl_context_create (mix->context, NULL, &error))
+ if (!gst_gl_context_create (mix->context, other_context, &error))
goto context_error;
}
diff --git a/gst/gl/gstglimagesink.c b/gst/gl/gstglimagesink.c
index 269234a..f49422c 100644
--- a/gst/gl/gstglimagesink.c
+++ b/gst/gl/gstglimagesink.c
@@ -861,6 +861,8 @@ gst_glimage_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
guint size;
gboolean need_pool;
GstStructure *gl_context;
+ gchar *platform, *gl_apis;
+ gpointer handle;
if (!_ensure_gl_setup (glimage_sink))
return FALSE;
@@ -915,11 +917,23 @@ gst_glimage_sink_propose_allocation (GstBaseSink * bsink, GstQuery * query)
gst_object_unref (pool);
+ gl_apis =
+ gst_gl_api_to_string (gst_gl_context_get_gl_api (glimage_sink->context));
+ platform =
+ gst_gl_platform_to_string (gst_gl_context_get_gl_platform
+ (glimage_sink->context));
+ handle = (gpointer) gst_gl_context_get_gl_context (glimage_sink->context);
+
gl_context =
gst_structure_new ("GstVideoGLTextureUploadMeta", "gst.gl.GstGLContext",
- GST_GL_TYPE_CONTEXT, glimage_sink->context, NULL);
+ GST_GL_TYPE_CONTEXT, glimage_sink->context, "gst.gl.context.handle",
+ G_TYPE_POINTER, handle, "gst.gl.context.type", G_TYPE_STRING, platform,
+ "gst.gl.context.apis", G_TYPE_STRING, gl_apis, NULL);
gst_query_add_allocation_meta (query,
GST_VIDEO_GL_TEXTURE_UPLOAD_META_API_TYPE, gl_context);
+
+ g_free (gl_apis);
+ g_free (platform);
gst_structure_free (gl_context);
return TRUE;
diff --git a/gst/gl/gstgltestsrc.c b/gst/gl/gstgltestsrc.c
index 1d9d343..b788dcd 100644
--- a/gst/gl/gstgltestsrc.c
+++ b/gst/gl/gstgltestsrc.c
@@ -597,6 +597,7 @@ gst_gl_test_src_decide_allocation (GstBaseSrc * basesrc, GstQuery * query)
GError *error = NULL;
guint idx;
guint out_width, out_height;
+ GstGLContext *other_context = NULL;
gst_query_parse_allocation (query, &caps, NULL);
@@ -621,6 +622,9 @@ gst_gl_test_src_decide_allocation (GstBaseSrc * basesrc, GstQuery * query)
GST_VIDEO_GL_TEXTURE_UPLOAD_META_API_TYPE, &idx)) {
GstGLContext *context;
const GstStructure *upload_meta_params;
+ gpointer handle;
+ gchar *type;
+ gchar *apis;
gst_query_parse_nth_allocation_meta (query, idx, &upload_meta_params);
if (gst_structure_get (upload_meta_params, "gst.gl.GstGLContext",
@@ -630,12 +634,31 @@ gst_gl_test_src_decide_allocation (GstBaseSrc * basesrc, GstQuery * query)
src->context = context;
if (old)
gst_object_unref (old);
+ } else if (gst_structure_get (upload_meta_params, "gst.gl.context.handle",
+ G_TYPE_POINTER, &handle, "gst.gl.context.type", G_TYPE_STRING,
+ &type, "gst.gl.context.apis", G_TYPE_STRING, &apis, NULL)
+ && handle) {
+ GstGLPlatform platform = GST_GL_PLATFORM_NONE;
+ GstGLAPI gl_apis;
+
+ GST_DEBUG ("got GL context handle 0x%p with type %s and apis %s", handle,
+ type, apis);
+
+ if (g_strcmp0 (type, "glx") == 0)
+ platform = GST_GL_PLATFORM_GLX;
+
+ gl_apis = gst_gl_api_from_string (apis);
+
+ if (gl_apis && platform)
+ other_context =
+ gst_gl_context_new_wrapped (src->display, (guintptr) handle,
+ platform, gl_apis);
}
}
if (!src->context) {
src->context = gst_gl_context_new (src->display);
- if (!gst_gl_context_create (src->context, NULL, &error))
+ if (!gst_gl_context_create (src->context, other_context, &error))
goto context_error;
}