bluetooth/aptx: Simplify lifetime of `caps`
authorMarijn Suijten <marijns95@gmail.com>
Sat, 23 Jan 2021 19:20:45 +0000 (20:20 +0100)
committerPulseAudio Marge Bot <pulseaudio-maintainers@lists.freedesktop.org>
Mon, 1 Feb 2021 17:23:46 +0000 (17:23 +0000)
Fixes: 73c80ffba ("bluetooth/aptx: Deduplicate caps setup for encoding and decoding")
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/487>

src/modules/bluetooth/a2dp-codec-aptx-gst.c

index e94eee6..8b5129b 100644 (file)
@@ -270,7 +270,7 @@ static uint8_t fill_preferred_configuration_hd(const pa_sample_spec *default_sam
 
 bool gst_init_aptx(struct gst_info *info, pa_sample_spec *ss, bool for_encoding) {
     GstElement *enc, *dec, *capsf;
-    GstCaps *caps = NULL;
+    GstCaps *caps;
     GstPad *pad;
     const char *aptx_codec_media_type;
 
@@ -334,17 +334,18 @@ bool gst_init_aptx(struct gst_info *info, pa_sample_spec *ss, bool for_encoding)
 
     aptx_codec_media_type = info->codec_type == APTX_HD ? "audio/aptx-hd" : "audio/aptx";
 
-    caps = gst_caps_new_simple(aptx_codec_media_type,
-            "rate", G_TYPE_INT, (int) ss->rate,
-            "channels", G_TYPE_INT, (int) ss->channels,
-            NULL);
-
     capsf = gst_element_factory_make("capsfilter", "aptx_capsfilter");
     if (!capsf) {
         pa_log_error("Could not create aptX capsfilter element");
         goto fail;
     }
+
+    caps = gst_caps_new_simple(aptx_codec_media_type,
+            "rate", G_TYPE_INT, (int) ss->rate,
+            "channels", G_TYPE_INT, (int) ss->channels,
+            NULL);
     g_object_set(capsf, "caps", caps, NULL);
+    gst_caps_unref(caps);
 
     if (for_encoding) {
         enc = gst_element_factory_make("openaptxenc", "aptx_encoder");
@@ -390,7 +391,6 @@ bool gst_init_aptx(struct gst_info *info, pa_sample_spec *ss, bool for_encoding)
         gst_object_unref(GST_OBJECT(pad));
     }
 
-    gst_caps_unref(caps);
 
     return true;
 
@@ -398,9 +398,6 @@ fail_enc_dec:
     gst_object_unref(GST_OBJECT(capsf));
 
 fail:
-    if (caps)
-        gst_caps_unref(caps);
-
     pa_log_error("aptX initialisation failed");
     return false;
 }