From 73c80ffba03f3abd92a38593446c6119ba305921 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Thu, 21 Jan 2021 23:59:57 +0100 Subject: [PATCH] bluetooth/aptx: Deduplicate caps setup for encoding and decoding Part-of: --- src/modules/bluetooth/a2dp-codec-aptx-gst.c | 22 ++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/modules/bluetooth/a2dp-codec-aptx-gst.c b/src/modules/bluetooth/a2dp-codec-aptx-gst.c index 82cbc2c9f..0ce844667 100644 --- a/src/modules/bluetooth/a2dp-codec-aptx-gst.c +++ b/src/modules/bluetooth/a2dp-codec-aptx-gst.c @@ -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; - GstCaps *caps; + GstCaps *caps = NULL; GstPad *pad; const char *aptx_codec_media_type; @@ -334,6 +334,11 @@ 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); + if (for_encoding) { enc = gst_element_factory_make("openaptxenc", "aptx_encoder"); @@ -342,12 +347,7 @@ bool gst_init_aptx(struct gst_info *info, pa_sample_spec *ss, bool for_encoding) 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(info->enc_sink, "caps", caps, NULL); - gst_caps_unref(caps); info->enc_bin = gst_bin_new("aptx_enc_bin"); pa_assert(info->enc_bin); @@ -369,12 +369,7 @@ bool gst_init_aptx(struct gst_info *info, pa_sample_spec *ss, bool for_encoding) 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(info->dec_src, "caps", caps, NULL); - gst_caps_unref(caps); info->dec_bin = gst_bin_new("aptx_dec_bin"); pa_assert(info->dec_bin); @@ -390,9 +385,14 @@ 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; fail: + if (caps) + gst_caps_unref(caps); + pa_log_error("aptX initialisation failed"); return false; }