From: Olivier CrĂȘte Date: Wed, 19 May 2021 00:26:38 +0000 (-0400) Subject: webrtc: Remove reundundant context object in transportsendbin X-Git-Tag: 1.19.3~507^2~393 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3bdf1e691e585ce3279a7be239a3402cb5f418af;p=platform%2Fupstream%2Fgstreamer.git webrtc: Remove reundundant context object in transportsendbin Part-of: --- diff --git a/ext/webrtc/transportsendbin.c b/ext/webrtc/transportsendbin.c index d5de83e..794a94b 100644 --- a/ext/webrtc/transportsendbin.c +++ b/ext/webrtc/transportsendbin.c @@ -171,9 +171,9 @@ transport_send_bin_change_state (GstElement * element, * arguably the element should be able to deal with this itself or * we should only add it once/if we get the encoding keys */ TSB_LOCK (send); - gst_element_set_locked_state (send->rtp_ctx.dtlssrtpenc, TRUE); + gst_element_set_locked_state (send->dtlssrtpenc, TRUE); send->active = TRUE; - send->rtp_ctx.has_clientness = FALSE; + send->has_clientness = FALSE; TSB_UNLOCK (send); break; } @@ -184,9 +184,9 @@ transport_send_bin_change_state (GstElement * element, /* RTP */ /* unblock the encoder once the key is set, this should also be automatic */ elem = send->stream->transport->dtlssrtpenc; - send->rtp_ctx.rtp_block = block_peer_pad (elem, "rtp_sink_0"); + send->rtp_block = block_peer_pad (elem, "rtp_sink_0"); /* Also block the RTCP pad on the RTP encoder, in case we mux RTCP */ - send->rtp_ctx.rtcp_block = block_peer_pad (elem, "rtcp_sink_0"); + send->rtcp_block = block_peer_pad (elem, "rtcp_sink_0"); /* unblock ice sink once a connection is made, this should also be automatic */ elem = send->stream->transport->transport->sink; @@ -219,7 +219,7 @@ transport_send_bin_change_state (GstElement * element, send->active = FALSE; cleanup_blocks (send); - gst_element_set_locked_state (send->rtp_ctx.dtlssrtpenc, FALSE); + gst_element_set_locked_state (send->dtlssrtpenc, FALSE); TSB_UNLOCK (send); break; @@ -234,11 +234,7 @@ transport_send_bin_change_state (GstElement * element, static void _on_dtls_enc_key_set (GstElement * dtlssrtpenc, TransportSendBin * send) { - TransportSendBinDTLSContext *ctx; - - if (dtlssrtpenc == send->rtp_ctx.dtlssrtpenc) - ctx = &send->rtp_ctx; - else { + if (dtlssrtpenc != send->dtlssrtpenc) { GST_WARNING_OBJECT (send, "Received dtls-enc key info for unknown element %" GST_PTR_FORMAT, dtlssrtpenc); @@ -253,9 +249,9 @@ _on_dtls_enc_key_set (GstElement * dtlssrtpenc, TransportSendBin * send) } GST_LOG_OBJECT (send, "Unblocking %" GST_PTR_FORMAT " pads", dtlssrtpenc); - _free_pad_block (ctx->rtp_block); - _free_pad_block (ctx->rtcp_block); - ctx->rtp_block = ctx->rtcp_block = NULL; + _free_pad_block (send->rtp_block); + _free_pad_block (send->rtcp_block); + send->rtp_block = send->rtcp_block = NULL; done: TSB_UNLOCK (send); @@ -266,7 +262,7 @@ maybe_start_enc (TransportSendBin * send) { GstWebRTCICEConnectionState state; - if (!send->rtp_ctx.has_clientness) { + if (!send->has_clientness) { GST_LOG_OBJECT (send, "Can't start DTLS because doesn't know client-ness"); return; } @@ -278,15 +274,15 @@ maybe_start_enc (TransportSendBin * send) return; } - gst_element_set_locked_state (send->rtp_ctx.dtlssrtpenc, FALSE); - gst_element_sync_state_with_parent (send->rtp_ctx.dtlssrtpenc); + gst_element_set_locked_state (send->dtlssrtpenc, FALSE); + gst_element_sync_state_with_parent (send->dtlssrtpenc); } static void _on_notify_dtls_client_status (GstElement * dtlssrtpenc, GParamSpec * pspec, TransportSendBin * send) { - if (dtlssrtpenc != send->rtp_ctx.dtlssrtpenc) { + if (dtlssrtpenc != send->dtlssrtpenc) { GST_WARNING_OBJECT (send, "Received dtls-enc client mode for unknown element %" GST_PTR_FORMAT, dtlssrtpenc); @@ -300,7 +296,7 @@ _on_notify_dtls_client_status (GstElement * dtlssrtpenc, goto done; } - send->rtp_ctx.has_clientness = TRUE; + send->has_clientness = TRUE; GST_DEBUG_OBJECT (send, "DTLS-SRTP encoder configured. Unlocking it and maybe changing state %" GST_PTR_FORMAT, dtlssrtpenc); @@ -319,63 +315,47 @@ _on_notify_ice_connection_state (GstWebRTCICETransport * transport, TSB_UNLOCK (send); } - static void -tsb_setup_ctx (TransportSendBin * send, TransportSendBinDTLSContext * ctx, - GstWebRTCDTLSTransport * transport) +transport_send_bin_constructed (GObject * object) { - GstElement *dtlssrtpenc, *nicesink; + TransportSendBin *send = TRANSPORT_SEND_BIN (object); + GstPadTemplate *templ; + GstPad *ghost, *pad; + + g_return_if_fail (send->stream); - dtlssrtpenc = ctx->dtlssrtpenc = transport->dtlssrtpenc; - nicesink = ctx->nicesink = transport->transport->sink; + send->dtlssrtpenc = send->stream->transport->dtlssrtpenc; + send->nicesink = send->stream->transport->transport->sink; /* unblock the encoder once the key is set */ - g_signal_connect (dtlssrtpenc, "on-key-set", + g_signal_connect (send->dtlssrtpenc, "on-key-set", G_CALLBACK (_on_dtls_enc_key_set), send); /* Bring the encoder up to current state only once the is-client prop is set */ - g_signal_connect (dtlssrtpenc, "notify::is-client", + g_signal_connect (send->dtlssrtpenc, "notify::is-client", G_CALLBACK (_on_notify_dtls_client_status), send); /* unblock ice sink once it signals a connection */ - g_signal_connect (transport->transport, "notify::state", + g_signal_connect (send->stream->transport->transport, "notify::state", G_CALLBACK (_on_notify_ice_connection_state), send); - gst_bin_add (GST_BIN (send), GST_ELEMENT (dtlssrtpenc)); - gst_bin_add (GST_BIN (send), GST_ELEMENT (nicesink)); + gst_bin_add (GST_BIN (send), GST_ELEMENT (send->dtlssrtpenc)); + gst_bin_add (GST_BIN (send), GST_ELEMENT (send->nicesink)); - if (!gst_element_link_pads (GST_ELEMENT (dtlssrtpenc), "src", nicesink, - "sink")) + if (!gst_element_link_pads (GST_ELEMENT (send->dtlssrtpenc), "src", + send->nicesink, "sink")) g_warn_if_reached (); -} -static void -transport_send_bin_constructed (GObject * object) -{ - TransportSendBin *send = TRANSPORT_SEND_BIN (object); - GstWebRTCDTLSTransport *transport; - GstPadTemplate *templ; - GstPad *ghost, *pad; - - g_return_if_fail (send->stream); - - /* RTP */ - transport = send->stream->transport; - /* Do the common init for the context struct */ - tsb_setup_ctx (send, &send->rtp_ctx, transport); - - templ = _find_pad_template (transport->dtlssrtpenc, - GST_PAD_SINK, GST_PAD_REQUEST, "rtp_sink_%d"); - pad = gst_element_request_pad (transport->dtlssrtpenc, templ, "rtp_sink_0", - NULL); + templ = _find_pad_template (send->dtlssrtpenc, GST_PAD_SINK, GST_PAD_REQUEST, + "rtp_sink_%d"); + pad = gst_element_request_pad (send->dtlssrtpenc, templ, "rtp_sink_0", NULL); ghost = gst_ghost_pad_new ("rtp_sink", pad); gst_element_add_pad (GST_ELEMENT (send), ghost); gst_object_unref (pad); /* push the data stream onto the RTP dtls element */ - templ = _find_pad_template (transport->dtlssrtpenc, - GST_PAD_SINK, GST_PAD_REQUEST, "data_sink"); - pad = gst_element_request_pad (transport->dtlssrtpenc, templ, "data_sink", - NULL); + templ = _find_pad_template (send->dtlssrtpenc, GST_PAD_SINK, GST_PAD_REQUEST, + "data_sink"); + pad = gst_element_request_pad (send->dtlssrtpenc, templ, "data_sink", NULL); ghost = gst_ghost_pad_new ("data_sink", pad); gst_element_add_pad (GST_ELEMENT (send), ghost); @@ -383,10 +363,9 @@ transport_send_bin_constructed (GObject * object) /* RTCP */ /* Do the common init for the context struct */ - templ = _find_pad_template (transport->dtlssrtpenc, - GST_PAD_SINK, GST_PAD_REQUEST, "rtcp_sink_%d"); - pad = gst_element_request_pad (transport->dtlssrtpenc, templ, "rtcp_sink_0", - NULL); + templ = _find_pad_template (send->dtlssrtpenc, GST_PAD_SINK, GST_PAD_REQUEST, + "rtcp_sink_%d"); + pad = gst_element_request_pad (send->dtlssrtpenc, templ, "rtcp_sink_0", NULL); ghost = gst_ghost_pad_new ("rtcp_sink", pad); gst_element_add_pad (GST_ELEMENT (send), ghost); @@ -396,35 +375,30 @@ transport_send_bin_constructed (GObject * object) } static void -cleanup_ctx_blocks (TransportSendBinDTLSContext * ctx) +cleanup_blocks (TransportSendBin * send) { - if (ctx->rtp_block) { - _free_pad_block (ctx->rtp_block); - ctx->rtp_block = NULL; + if (send->rtp_block) { + _free_pad_block (send->rtp_block); + send->rtp_block = NULL; } - if (ctx->rtcp_block) { - _free_pad_block (ctx->rtcp_block); - ctx->rtcp_block = NULL; + if (send->rtcp_block) { + _free_pad_block (send->rtcp_block); + send->rtcp_block = NULL; } } static void -cleanup_blocks (TransportSendBin * send) -{ - cleanup_ctx_blocks (&send->rtp_ctx); -} - -static void transport_send_bin_dispose (GObject * object) { TransportSendBin *send = TRANSPORT_SEND_BIN (object); TSB_LOCK (send); - if (send->rtp_ctx.nicesink) { - g_signal_handlers_disconnect_by_data (send->rtp_ctx.nicesink, send); - send->rtp_ctx.nicesink = NULL; + if (send->nicesink) { + g_signal_handlers_disconnect_by_data (send->nicesink, send); + send->nicesink = NULL; } + cleanup_blocks (send); TSB_UNLOCK (send); diff --git a/ext/webrtc/transportsendbin.h b/ext/webrtc/transportsendbin.h index 6821e05..5266c8c 100644 --- a/ext/webrtc/transportsendbin.h +++ b/ext/webrtc/transportsendbin.h @@ -34,18 +34,6 @@ GType transport_send_bin_get_type(void); typedef struct _TransportSendBinDTLSContext TransportSendBinDTLSContext; -struct _TransportSendBinDTLSContext { - GstElement *dtlssrtpenc; - GstElement *nicesink; - - gboolean has_clientness; - - /* Block on the dtlssrtpenc RTP sink pad, if any */ - struct pad_block *rtp_block; - /* Block on the dtlssrtpenc RTCP sink pad, if any */ - struct pad_block *rtcp_block; -}; - struct _TransportSendBin { GstBin parent; @@ -55,15 +43,15 @@ struct _TransportSendBin TransportStream *stream; /* parent transport stream */ - TransportSendBinDTLSContext rtp_ctx; + GstElement *dtlssrtpenc; + GstElement *nicesink; - /* - struct pad_block *rtp_block; - struct pad_block *rtp_nice_block; + gboolean has_clientness; + /* Block on the dtlssrtpenc RTP sink pad, if any */ + struct pad_block *rtp_block; + /* Block on the dtlssrtpenc RTCP sink pad, if any */ struct pad_block *rtcp_block; - struct pad_block *rtcp_nice_block; - */ }; struct _TransportSendBinClass