wasapi: Don't open the device in get_caps()
authorNirbheek Chauhan <nirbheek@centricular.com>
Mon, 9 Apr 2018 11:46:38 +0000 (17:16 +0530)
committerNirbheek Chauhan <nirbheek@centricular.com>
Mon, 9 Apr 2018 11:58:11 +0000 (17:28 +0530)
We can just return the template caps till the device is opened when
going from READY -> PAUSED. This fixes a CRITICAL when calling
ELEMENT_ERROR before the ringbuffer is allocated.

Also fixes a couple of leaks in error conditions.

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

sys/wasapi/gstwasapisink.c
sys/wasapi/gstwasapisrc.c

index 5d4a0a6..6ea72e1 100644 (file)
@@ -339,22 +339,26 @@ gst_wasapi_sink_get_caps (GstBaseSink * bsink, GstCaps * filter)
 
     template_caps = gst_pad_get_pad_template_caps (bsink->sinkpad);
 
-    if (!self->client)
-      gst_wasapi_sink_open (GST_AUDIO_SINK (bsink));
+    if (!self->client) {
+      caps = template_caps;
+      goto out;
+    }
 
     ret = gst_wasapi_util_get_device_format (GST_ELEMENT (self),
         self->sharemode, self->device, self->client, &format);
     if (!ret) {
       GST_ELEMENT_ERROR (self, STREAM, FORMAT, (NULL),
           ("failed to detect format"));
-      goto out;
+      gst_caps_unref (template_caps);
+      return NULL;
     }
 
     gst_wasapi_util_parse_waveformatex ((WAVEFORMATEXTENSIBLE *) format,
         template_caps, &caps, &self->positions);
     if (caps == NULL) {
       GST_ELEMENT_ERROR (self, STREAM, FORMAT, (NULL), ("unknown format"));
-      goto out;
+      gst_caps_unref (template_caps);
+      return NULL;
     }
 
     {
@@ -376,9 +380,8 @@ gst_wasapi_sink_get_caps (GstBaseSink * bsink, GstCaps * filter)
     caps = filtered;
   }
 
-  GST_DEBUG_OBJECT (self, "returning caps %" GST_PTR_FORMAT, caps);
-
 out:
+  GST_DEBUG_OBJECT (self, "returning caps %" GST_PTR_FORMAT, caps);
   return caps;
 }
 
index b17485b..389d49a 100644 (file)
@@ -326,22 +326,26 @@ gst_wasapi_src_get_caps (GstBaseSrc * bsrc, GstCaps * filter)
 
     template_caps = gst_pad_get_pad_template_caps (bsrc->srcpad);
 
-    if (!self->client)
-      gst_wasapi_src_open (GST_AUDIO_SRC (bsrc));
+    if (!self->client) {
+      caps = template_caps;
+      goto out;
+    }
 
     ret = gst_wasapi_util_get_device_format (GST_ELEMENT (self),
         self->sharemode, self->device, self->client, &format);
     if (!ret) {
       GST_ELEMENT_ERROR (self, STREAM, FORMAT, (NULL),
           ("failed to detect format"));
-      goto out;
+      gst_caps_unref (template_caps);
+      return NULL;
     }
 
     gst_wasapi_util_parse_waveformatex ((WAVEFORMATEXTENSIBLE *) format,
         template_caps, &caps, &self->positions);
     if (caps == NULL) {
       GST_ELEMENT_ERROR (self, STREAM, FORMAT, (NULL), ("unknown format"));
-      goto out;
+      gst_caps_unref (template_caps);
+      return NULL;
     }
 
     {
@@ -363,9 +367,8 @@ gst_wasapi_src_get_caps (GstBaseSrc * bsrc, GstCaps * filter)
     caps = filtered;
   }
 
-  GST_DEBUG_OBJECT (self, "returning caps %" GST_PTR_FORMAT, caps);
-
 out:
+  GST_DEBUG_OBJECT (self, "returning caps %" GST_PTR_FORMAT, caps);
   return caps;
 }