d3d11: Don't assume response of context query has valid d3d11 device context
authorSeungha Yang <seungha@centricular.com>
Tue, 16 Jun 2020 10:26:13 +0000 (19:26 +0900)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 16 Jun 2020 11:23:34 +0000 (11:23 +0000)
Peer elements should return FALSE if d3d11 device context is unavailable
but it might happen for some reason (e.g., wrong implementation or so)

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1347>

sys/d3d11/gstd3d11utils.c

index 7d33048..d306403 100644 (file)
@@ -210,7 +210,7 @@ static void
 run_d3d11_context_query (GstElement * element, GstD3D11Device ** device)
 {
   GstQuery *query;
-  GstContext *ctxt;
+  GstContext *ctxt = NULL;
 
   /* 1) Query downstream with GST_QUERY_CONTEXT for the context and
    *    check if downstream already has a context of the specific type
@@ -218,18 +218,22 @@ run_d3d11_context_query (GstElement * element, GstD3D11Device ** device)
   query = gst_query_new_context (GST_D3D11_DEVICE_HANDLE_CONTEXT_TYPE);
   if (run_query (element, query, GST_PAD_SRC)) {
     gst_query_parse_context (query, &ctxt);
-    GST_CAT_INFO_OBJECT (GST_CAT_CONTEXT, element,
-        "found context (%" GST_PTR_FORMAT ") in downstream query", ctxt);
-    gst_element_set_context (element, ctxt);
+    if (ctxt) {
+      GST_CAT_INFO_OBJECT (GST_CAT_CONTEXT, element,
+          "found context (%" GST_PTR_FORMAT ") in downstream query", ctxt);
+      gst_element_set_context (element, ctxt);
+    }
   }
 
   /* 2) although we found d3d11 device context above, the element does not want
    *    to use the context. Then try to find from the other direction */
   if (*device == NULL && run_query (element, query, GST_PAD_SINK)) {
     gst_query_parse_context (query, &ctxt);
-    GST_CAT_INFO_OBJECT (GST_CAT_CONTEXT, element,
-        "found context (%" GST_PTR_FORMAT ") in upstream query", ctxt);
-    gst_element_set_context (element, ctxt);
+    if (ctxt) {
+      GST_CAT_INFO_OBJECT (GST_CAT_CONTEXT, element,
+          "found context (%" GST_PTR_FORMAT ") in upstream query", ctxt);
+      gst_element_set_context (element, ctxt);
+    }
   }
 
   if (*device == NULL) {