avfvideosrc: fix GL texture negotiation
authorIlya Konstantinov <ilya.konstantinov@gmail.com>
Sat, 11 Apr 2015 04:38:57 +0000 (07:38 +0300)
committerAlessandro Decina <alessandro.d@gmail.com>
Tue, 14 Apr 2015 08:05:57 +0000 (18:05 +1000)
GST_VIDEO_GL_TEXTURE_UPLOAD_META_API_TYPE should no longer be used.
Instead, just get the GL context.

https://bugzilla.gnome.org/show_bug.cgi?id=747352

sys/applemedia/avfvideosrc.m

index 19b6e55e90f04c5e5614b757d3484419fd57c641..7c863b23a17941035e7d15f76e45fd08eb7ac219 100644 (file)
@@ -769,28 +769,34 @@ didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer
   useVideoMeta = gst_query_find_allocation_meta (query,
       GST_VIDEO_META_API_TYPE, NULL);
 
-  guint idx;
-  if (gst_query_find_allocation_meta (query,
-        GST_VIDEO_GL_TEXTURE_UPLOAD_META_API_TYPE, &idx)) {
-    GstGLContext *context;
-    const GstStructure *upload_meta_params;
-
-    gst_query_parse_nth_allocation_meta (query, idx, &upload_meta_params);
-    if (gst_structure_get (upload_meta_params, "gst.gl.GstGLContext",
-          GST_GL_TYPE_CONTEXT, &context, NULL) && context) {
-      GstCaps *query_caps;
-      GstCapsFeatures *features;
-
-      gst_query_parse_allocation (query, &query_caps, NULL);
-      features = gst_caps_get_features (query_caps, 0);
-      if (gst_caps_features_contains (features, GST_CAPS_FEATURE_MEMORY_GL_MEMORY)) {
-        textureCache = gst_core_video_texture_cache_new (context);
-        gst_core_video_texture_cache_set_format (textureCache,
-            "NV12", query_caps);
+  /* determine whether we can pass GL textures to downstream element */
+  GstCapsFeatures *features = gst_caps_get_features (caps, 0);
+  if (gst_caps_features_contains (features, GST_CAPS_FEATURE_MEMORY_GL_MEMORY)) {
+    GstGLContext *glContext = NULL;
+
+    /* get GL context from downstream element */
+    GstQuery *query = gst_query_new_context ("gst.gl.local_context");
+    if (gst_pad_peer_query (GST_BASE_SRC_PAD (element), query)) {
+      GstContext *context;
+      gst_query_parse_context (query, &context);
+      if (context) {
+        const GstStructure *s = gst_context_get_structure (context);
+        gst_structure_get (s, "context", GST_GL_TYPE_CONTEXT, &glContext,
+            NULL);
       }
-      gst_object_unref (context);
     }
-  }
+    gst_query_unref (query);
+
+    if (glContext) {
+      GST_INFO_OBJECT (element, "pushing textures. GL context %p", glContext);
+      textureCache = gst_core_video_texture_cache_new (glContext);
+      gst_core_video_texture_cache_set_format (textureCache,
+          "NV12", caps);
+      gst_object_unref (glContext);
+    } else {
+      GST_WARNING_OBJECT (element, "got memory:GLMemory caps but not GL context from downstream element");
+    }
+  } 
 
   return YES;
 }