rtpssrcdemux: Hold on internal stream lock while pushing sticky

This reverts "6f3734c305 rtpssrcdemux: Only forward stick events while
holding the sinkpad stream lock" and actually hold on the internal
stream lock. This prevents in some needed case having a second
streaming thread poping in and messing up event ordering.
This commit is contained in:
Nicolas Dufresne 2018-11-28 17:14:11 -05:00
parent c596bdda38
commit 40daf6322d

View file

@ -142,9 +142,6 @@ struct _GstRtpSsrcDemuxPad
GstPad *rtp_pad; GstPad *rtp_pad;
GstCaps *caps; GstCaps *caps;
GstPad *rtcp_pad; GstPad *rtcp_pad;
gboolean pushed_initial_rtp_events;
gboolean pushed_initial_rtcp_events;
}; };
/* find a src pad for a given SSRC, returns NULL if the SSRC was not found /* find a src pad for a given SSRC, returns NULL if the SSRC was not found
@ -197,6 +194,7 @@ struct ForwardStickyEventData
guint32 ssrc; guint32 ssrc;
}; };
/* With internal stream lock held */
static gboolean static gboolean
forward_sticky_events (GstPad * pad, GstEvent ** event, gpointer user_data) forward_sticky_events (GstPad * pad, GstEvent ** event, gpointer user_data)
{ {
@ -210,6 +208,7 @@ forward_sticky_events (GstPad * pad, GstEvent ** event, gpointer user_data)
return TRUE; return TRUE;
} }
/* With internal stream lock held */
static void static void
forward_initial_events (GstRtpSsrcDemux * demux, guint32 ssrc, GstPad * pad, forward_initial_events (GstRtpSsrcDemux * demux, guint32 ssrc, GstPad * pad,
PadType padtype) PadType padtype)
@ -240,28 +239,17 @@ find_or_create_demux_pad_for_ssrc (GstRtpSsrcDemux * demux, guint32 ssrc,
gchar *padname; gchar *padname;
GstRtpSsrcDemuxPad *demuxpad; GstRtpSsrcDemuxPad *demuxpad;
GstPad *retpad; GstPad *retpad;
gulong rtp_block, rtcp_block;
GST_PAD_LOCK (demux); GST_PAD_LOCK (demux);
demuxpad = find_demux_pad_for_ssrc (demux, ssrc); demuxpad = find_demux_pad_for_ssrc (demux, ssrc);
if (demuxpad != NULL) { if (demuxpad != NULL) {
gboolean forward = FALSE;
switch (padtype) { switch (padtype) {
case RTP_PAD: case RTP_PAD:
retpad = gst_object_ref (demuxpad->rtp_pad); retpad = gst_object_ref (demuxpad->rtp_pad);
if (!demuxpad->pushed_initial_rtp_events) {
forward = TRUE;
demuxpad->pushed_initial_rtp_events = TRUE;
}
break; break;
case RTCP_PAD: case RTCP_PAD:
retpad = gst_object_ref (demuxpad->rtcp_pad); retpad = gst_object_ref (demuxpad->rtcp_pad);
if (!demuxpad->pushed_initial_rtcp_events) {
forward = TRUE;
demuxpad->pushed_initial_rtcp_events = TRUE;
}
break; break;
default: default:
retpad = NULL; retpad = NULL;
@ -270,8 +258,6 @@ find_or_create_demux_pad_for_ssrc (GstRtpSsrcDemux * demux, guint32 ssrc,
GST_PAD_UNLOCK (demux); GST_PAD_UNLOCK (demux);
if (forward)
forward_initial_events (demux, ssrc, retpad, padtype);
return retpad; return retpad;
} }
@ -312,15 +298,8 @@ find_or_create_demux_pad_for_ssrc (GstRtpSsrcDemux * demux, guint32 ssrc,
gst_pad_use_fixed_caps (rtcp_pad); gst_pad_use_fixed_caps (rtcp_pad);
gst_pad_set_active (rtcp_pad, TRUE); gst_pad_set_active (rtcp_pad, TRUE);
if (padtype == RTP_PAD) { forward_initial_events (demux, ssrc, rtp_pad, RTP_PAD);
demuxpad->pushed_initial_rtp_events = TRUE; forward_initial_events (demux, ssrc, rtcp_pad, RTCP_PAD);
forward_initial_events (demux, ssrc, rtp_pad, padtype);
} else if (padtype == RTCP_PAD) {
demuxpad->pushed_initial_rtcp_events = TRUE;
forward_initial_events (demux, ssrc, rtcp_pad, padtype);
} else {
g_assert_not_reached ();
}
gst_element_add_pad (GST_ELEMENT_CAST (demux), rtp_pad); gst_element_add_pad (GST_ELEMENT_CAST (demux), rtp_pad);
gst_element_add_pad (GST_ELEMENT_CAST (demux), rtcp_pad); gst_element_add_pad (GST_ELEMENT_CAST (demux), rtcp_pad);
@ -340,18 +319,10 @@ find_or_create_demux_pad_for_ssrc (GstRtpSsrcDemux * demux, guint32 ssrc,
gst_object_ref (rtp_pad); gst_object_ref (rtp_pad);
gst_object_ref (rtcp_pad); gst_object_ref (rtcp_pad);
rtp_block = gst_pad_add_probe (rtp_pad, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM,
NULL, NULL, NULL);
rtcp_block = gst_pad_add_probe (rtcp_pad, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM,
NULL, NULL, NULL);
GST_PAD_UNLOCK (demux);
g_signal_emit (G_OBJECT (demux), g_signal_emit (G_OBJECT (demux),
gst_rtp_ssrc_demux_signals[SIGNAL_NEW_SSRC_PAD], 0, ssrc, rtp_pad); gst_rtp_ssrc_demux_signals[SIGNAL_NEW_SSRC_PAD], 0, ssrc, rtp_pad);
gst_pad_remove_probe (rtp_pad, rtp_block); GST_PAD_UNLOCK (demux);
gst_pad_remove_probe (rtcp_pad, rtcp_block);
gst_object_unref (rtp_pad); gst_object_unref (rtp_pad);
gst_object_unref (rtcp_pad); gst_object_unref (rtcp_pad);
@ -565,11 +536,7 @@ forward_event (GstPad * pad, gpointer user_data)
for (walk = fdata->demux->srcpads; walk; walk = walk->next) { for (walk = fdata->demux->srcpads; walk; walk = walk->next) {
GstRtpSsrcDemuxPad *dpad = (GstRtpSsrcDemuxPad *) walk->data; GstRtpSsrcDemuxPad *dpad = (GstRtpSsrcDemuxPad *) walk->data;
/* Only forward the event if the initial events have been through first, if (pad == dpad->rtp_pad || pad == dpad->rtcp_pad) {
* the initial events should be forwarded before any other event
* or buffer is pushed */
if ((pad == dpad->rtp_pad && dpad->pushed_initial_rtp_events) ||
(pad == dpad->rtcp_pad && dpad->pushed_initial_rtcp_events)) {
newevent = add_ssrc_and_ref (fdata->event, dpad->ssrc); newevent = add_ssrc_and_ref (fdata->event, dpad->ssrc);
break; break;
} }