From c427860a20866045bef130b9a3e576c9f6367c47 Mon Sep 17 00:00:00 2001 From: Nirbheek Chauhan Date: Mon, 9 Apr 2018 17:16:38 +0530 Subject: [PATCH] wasapi: Don't open the device in get_caps() 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 | 15 +++++++++------ sys/wasapi/gstwasapisrc.c | 15 +++++++++------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/sys/wasapi/gstwasapisink.c b/sys/wasapi/gstwasapisink.c index 5d4a0a6..6ea72e1 100644 --- a/sys/wasapi/gstwasapisink.c +++ b/sys/wasapi/gstwasapisink.c @@ -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; } diff --git a/sys/wasapi/gstwasapisrc.c b/sys/wasapi/gstwasapisrc.c index b17485b..389d49a 100644 --- a/sys/wasapi/gstwasapisrc.c +++ b/sys/wasapi/gstwasapisrc.c @@ -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; } -- 2.7.4