From 05ccc2f6eaacff0a67e7614b8f6c4e80f2ceda15 Mon Sep 17 00:00:00 2001 From: Alessandro Decina Date: Tue, 12 Jan 2016 14:36:02 +1100 Subject: [PATCH] applemedia: avfvideosrc: optionally get the GL context from gst_element_set_context Allow setting the GL context with gst_element_set_context. When available, the local context obtained via the context query still has the precedence. --- sys/applemedia/avfvideosrc.m | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/sys/applemedia/avfvideosrc.m b/sys/applemedia/avfvideosrc.m index 401547afda..c55ba55bdf 100644 --- a/sys/applemedia/avfvideosrc.m +++ b/sys/applemedia/avfvideosrc.m @@ -753,7 +753,7 @@ didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer GstCapsFeatures *features = gst_caps_get_features (caps, 0); if (gst_caps_features_contains (features, GST_CAPS_FEATURE_MEMORY_GL_MEMORY)) { - GstGLContext *context = query_gl_context (GST_BASE_SRC_PAD (baseSrc)); + GstGLContext *context = find_gl_context (element); textureCache = gst_video_texture_cache_new (context); gst_video_texture_cache_set_format (textureCache, format, caps); gst_object_unref (context); @@ -964,7 +964,7 @@ didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer } static GstGLContext * -query_gl_context (GstPad *srcpad) +query_gl_local_context (GstPad *srcpad) { GstGLContext *gl_context = NULL; GstContext *context = NULL; @@ -983,6 +983,32 @@ query_gl_context (GstPad *srcpad) return gl_context; } +static GstGLContext * +find_gl_app_context (GstElement *element) +{ + GstGLContext *gl_context = NULL; + GstContext *context = gst_element_get_context (element, "gst.gl.app_context"); + if (context) { + const GstStructure *s = gst_context_get_structure (context); + gst_structure_get (s, "context", GST_GL_TYPE_CONTEXT, &gl_context, NULL); + gst_context_unref (context); + } + + return gl_context; +} + +static GstGLContext * +find_gl_context (GstElement *element) +{ + GstGLContext *gl_context = NULL; + + gl_context = query_gl_local_context (GST_BASE_SRC_PAD (element)); + if (!gl_context) + gl_context = find_gl_app_context (element); + + return gl_context; +} + static gboolean caps_filter_out_gl_memory (GstCapsFeatures * features, GstStructure * structure, gpointer user_data) @@ -999,7 +1025,7 @@ caps_filter_out_gl_memory (GstCapsFeatures * features, GstStructure * structure, new_caps = gst_caps_make_writable (new_caps); - context = query_gl_context (GST_BASE_SRC_PAD (baseSrc)); + context = find_gl_context (element); if (!context) gst_caps_filter_and_map_in_place (new_caps, caps_filter_out_gl_memory, NULL); else