From 0e2d128bec3f4341febbc361d617b5553277e52a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Olivier=20Cr=C3=AAte?= Date: Fri, 26 Mar 2021 15:02:50 -0400 Subject: [PATCH] webrtcbin: Make request-pad validation an early return This reduces the indendation. Part-of: --- ext/webrtc/gstwebrtcbin.c | 96 +++++++++++++++++++++++------------------------ 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/ext/webrtc/gstwebrtcbin.c b/ext/webrtc/gstwebrtcbin.c index 02c9c49..8c12d67 100644 --- a/ext/webrtc/gstwebrtcbin.c +++ b/ext/webrtc/gstwebrtcbin.c @@ -6194,65 +6194,65 @@ gst_webrtc_bin_request_new_pad (GstElement * element, GstPadTemplate * templ, const gchar * name, const GstCaps * caps) { GstWebRTCBin *webrtc = GST_WEBRTC_BIN (element); + GstWebRTCRTPTransceiver *trans; GstWebRTCBinPad *pad = NULL; + GstWebRTCBinPad *pad2; guint serial; if (!_have_nice_elements (webrtc) || !_have_dtls_elements (webrtc)) return NULL; - if (templ->direction == GST_PAD_SINK || - g_strcmp0 (templ->name_template, "sink_%u") == 0) { - GstWebRTCRTPTransceiver *trans; - GstWebRTCBinPad *pad2; - - GST_OBJECT_LOCK (webrtc); - if (name == NULL || strlen (name) < 6 || !g_str_has_prefix (name, "sink_")) { - /* no name given when requesting the pad, use next available int */ - serial = webrtc->priv->max_sink_pad_serial++; - } else { - /* parse serial number from requested padname */ - serial = g_ascii_strtoull (&name[5], NULL, 10); - if (serial > webrtc->priv->max_sink_pad_serial) - webrtc->priv->max_sink_pad_serial = serial; - } - GST_OBJECT_UNLOCK (webrtc); + if (templ->direction != GST_PAD_SINK || + g_strcmp0 (templ->name_template, "sink_%u") != 0) { + GST_ERROR_OBJECT (element, "Requested pad that shouldn't be requestable"); + return NULL; + } - trans = _find_transceiver_for_mline (webrtc, serial); + GST_OBJECT_LOCK (webrtc); + if (name == NULL || strlen (name) < 6 || !g_str_has_prefix (name, "sink_")) { + /* no name given when requesting the pad, use next available int */ + serial = webrtc->priv->max_sink_pad_serial++; + } else { + /* parse serial number from requested padname */ + serial = g_ascii_strtoull (&name[5], NULL, 10); + if (serial > webrtc->priv->max_sink_pad_serial) + webrtc->priv->max_sink_pad_serial = serial; + } + GST_OBJECT_UNLOCK (webrtc); - /* Ignore transceivers that already have a pad allocated */ - pad2 = _find_pad_for_transceiver (webrtc, GST_PAD_SINK, trans); - if (pad2) { - serial = -1; - trans = NULL; - gst_object_unref (pad2); - } + trans = _find_transceiver_for_mline (webrtc, serial); - if (!trans) { - trans = - GST_WEBRTC_RTP_TRANSCEIVER (_create_webrtc_transceiver (webrtc, - GST_WEBRTC_RTP_TRANSCEIVER_DIRECTION_SENDRECV, -1)); - GST_LOG_OBJECT (webrtc, "Created new transceiver %" GST_PTR_FORMAT, - trans); - } else { - GST_LOG_OBJECT (webrtc, "Using existing transceiver %" GST_PTR_FORMAT - " for mline %u", trans, serial); - } - pad = _create_pad_for_sdp_media (webrtc, GST_PAD_SINK, trans, serial); + /* Ignore transceivers that already have a pad allocated */ + pad2 = _find_pad_for_transceiver (webrtc, GST_PAD_SINK, trans); + if (pad2) { + serial = -1; + trans = NULL; + gst_object_unref (pad2); + } - if (caps && name && !_update_transceiver_kind_from_caps (trans, caps)) - GST_WARNING_OBJECT (webrtc, - "Trying to create pad %s with caps %" GST_PTR_FORMAT - " but transceiver %d already exists with a different" - " media type", name, caps, serial); - - pad->block_id = gst_pad_add_probe (GST_PAD (pad), GST_PAD_PROBE_TYPE_BLOCK | - GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_BUFFER_LIST, - (GstPadProbeCallback) sink_pad_block, NULL, NULL); - webrtc->priv->pending_sink_transceivers = - g_list_append (webrtc->priv->pending_sink_transceivers, - gst_object_ref (pad)); - _add_pad (webrtc, pad); + if (!trans) { + trans = GST_WEBRTC_RTP_TRANSCEIVER (_create_webrtc_transceiver (webrtc, + GST_WEBRTC_RTP_TRANSCEIVER_DIRECTION_SENDRECV, -1)); + GST_LOG_OBJECT (webrtc, "Created new transceiver %" GST_PTR_FORMAT, trans); + } else { + GST_LOG_OBJECT (webrtc, "Using existing transceiver %" GST_PTR_FORMAT + " for mline %u", trans, serial); } + pad = _create_pad_for_sdp_media (webrtc, GST_PAD_SINK, trans, serial); + + if (caps && name && !_update_transceiver_kind_from_caps (trans, caps)) + GST_WARNING_OBJECT (webrtc, + "Trying to create pad %s with caps %" GST_PTR_FORMAT + " but transceiver %d already exists with a different" + " media type", name, caps, serial); + + pad->block_id = gst_pad_add_probe (GST_PAD (pad), GST_PAD_PROBE_TYPE_BLOCK | + GST_PAD_PROBE_TYPE_BUFFER | GST_PAD_PROBE_TYPE_BUFFER_LIST, + (GstPadProbeCallback) sink_pad_block, NULL, NULL); + webrtc->priv->pending_sink_transceivers = + g_list_append (webrtc->priv->pending_sink_transceivers, + gst_object_ref (pad)); + _add_pad (webrtc, pad); return GST_PAD (pad); } -- 2.7.4