rtpsession: use proper locking for pads and caps

Use the sesion lock and shotdown variable to protect and ref the pads we are
going to push on.

fixes #561825
This commit is contained in:
Wim Taymans 2009-08-31 16:34:14 +02:00
parent a522a2d4d2
commit a74c385b7b

View file

@ -949,13 +949,20 @@ gst_rtp_session_process_rtp (RTPSession * sess, RTPSource * src,
GstFlowReturn result;
GstRtpSession *rtpsession;
GstRtpSessionPrivate *priv;
GstPad *rtp_src;
rtpsession = GST_RTP_SESSION (user_data);
priv = rtpsession->priv;
if (rtpsession->recv_rtp_src) {
GST_RTP_SESSION_LOCK (rtpsession);
if ((rtp_src = rtpsession->recv_rtp_src))
gst_object_ref (rtp_src);
GST_RTP_SESSION_UNLOCK (rtpsession);
if (rtp_src) {
GST_LOG_OBJECT (rtpsession, "pushing received RTP packet");
result = gst_pad_push (rtpsession->recv_rtp_src, buffer);
result = gst_pad_push (rtp_src, buffer);
gst_object_unref (rtp_src);
} else {
GST_DEBUG_OBJECT (rtpsession, "dropping received RTP packet");
gst_buffer_unref (buffer);
@ -973,19 +980,25 @@ gst_rtp_session_send_rtp (RTPSession * sess, RTPSource * src,
GstFlowReturn result;
GstRtpSession *rtpsession;
GstRtpSessionPrivate *priv;
GstPad *rtp_src;
rtpsession = GST_RTP_SESSION (user_data);
priv = rtpsession->priv;
if (rtpsession->send_rtp_src) {
GST_RTP_SESSION_LOCK (rtpsession);
if ((rtp_src = rtpsession->send_rtp_src))
gst_object_ref (rtp_src);
GST_RTP_SESSION_UNLOCK (rtpsession);
if (rtp_src) {
if (GST_IS_BUFFER (data)) {
GST_LOG_OBJECT (rtpsession, "sending RTP packet");
result = gst_pad_push (rtpsession->send_rtp_src, GST_BUFFER_CAST (data));
result = gst_pad_push (rtp_src, GST_BUFFER_CAST (data));
} else {
GST_LOG_OBJECT (rtpsession, "sending RTP list");
result = gst_pad_push_list (rtpsession->send_rtp_src,
GST_BUFFER_LIST_CAST (data));
result = gst_pad_push_list (rtp_src, GST_BUFFER_LIST_CAST (data));
}
gst_object_unref (rtp_src);
} else {
gst_mini_object_unref (GST_MINI_OBJECT_CAST (data));
result = GST_FLOW_OK;
@ -1003,37 +1016,55 @@ gst_rtp_session_send_rtcp (RTPSession * sess, RTPSource * src,
GstFlowReturn result;
GstRtpSession *rtpsession;
GstRtpSessionPrivate *priv;
GstPad *rtcp_src;
rtpsession = GST_RTP_SESSION (user_data);
priv = rtpsession->priv;
if (rtpsession->send_rtcp_src) {
GST_RTP_SESSION_LOCK (rtpsession);
if (rtpsession->priv->stop_thread)
goto stopping;
if ((rtcp_src = rtpsession->send_rtcp_src)) {
GstCaps *caps;
/* set rtcp caps on output pad */
caps = GST_PAD_CAPS (rtpsession->send_rtcp_src);
if (!caps) {
if ((caps = GST_PAD_CAPS (rtcp_src))) {
caps = gst_caps_new_simple ("application/x-rtcp", NULL);
gst_pad_set_caps (rtpsession->send_rtcp_src, caps);
} else {
gst_caps_ref (caps);
gst_pad_set_caps (rtcp_src, caps);
gst_caps_unref (caps);
}
gst_buffer_set_caps (buffer, caps);
gst_caps_unref (caps);
GST_LOG_OBJECT (rtpsession, "sending RTCP");
result = gst_pad_push (rtpsession->send_rtcp_src, buffer);
gst_object_ref (rtcp_src);
GST_RTP_SESSION_UNLOCK (rtpsession);
result = gst_pad_push (rtcp_src, buffer);
/* we have to send EOS after this packet */
if (eos) {
GST_LOG_OBJECT (rtpsession, "sending EOS");
gst_pad_push_event (rtpsession->send_rtcp_src, gst_event_new_eos ());
gst_pad_push_event (rtcp_src, gst_event_new_eos ());
}
gst_object_unref (rtcp_src);
} else {
GST_RTP_SESSION_UNLOCK (rtpsession);
GST_DEBUG_OBJECT (rtpsession, "not sending RTCP, no output pad");
gst_buffer_unref (buffer);
result = GST_FLOW_OK;
}
return result;
/* ERRORS */
stopping:
{
GST_DEBUG_OBJECT (rtpsession, "we are stopping");
gst_buffer_unref (buffer);
GST_RTP_SESSION_UNLOCK (rtpsession);
return GST_FLOW_OK;
}
}
/* called when the session manager has an SR RTCP packet ready for handling
@ -1045,28 +1076,48 @@ gst_rtp_session_sync_rtcp (RTPSession * sess,
GstFlowReturn result;
GstRtpSession *rtpsession;
GstRtpSessionPrivate *priv;
GstPad *sync_src;
rtpsession = GST_RTP_SESSION (user_data);
priv = rtpsession->priv;
if (rtpsession->sync_src) {
GST_RTP_SESSION_LOCK (rtpsession);
if (rtpsession->priv->stop_thread)
goto stopping;
if ((sync_src = rtpsession->sync_src)) {
GstCaps *caps;
/* set rtcp caps on output pad */
if (!(caps = GST_PAD_CAPS (rtpsession->sync_src))) {
if (!(caps = GST_PAD_CAPS (sync_src))) {
caps = gst_caps_new_simple ("application/x-rtcp", NULL);
gst_pad_set_caps (rtpsession->sync_src, caps);
gst_pad_set_caps (sync_src, caps);
gst_caps_unref (caps);
}
gst_buffer_set_caps (buffer, caps);
gst_object_ref (sync_src);
GST_RTP_SESSION_UNLOCK (rtpsession);
GST_LOG_OBJECT (rtpsession, "sending Sync RTCP");
result = gst_pad_push (rtpsession->sync_src, buffer);
result = gst_pad_push (sync_src, buffer);
gst_object_unref (sync_src);
} else {
GST_RTP_SESSION_UNLOCK (rtpsession);
GST_DEBUG_OBJECT (rtpsession, "not sending Sync RTCP, no output pad");
gst_buffer_unref (buffer);
result = GST_FLOW_OK;
}
return result;
/* ERRORS */
stopping:
{
GST_DEBUG_OBJECT (rtpsession, "we are stopping");
gst_buffer_unref (buffer);
GST_RTP_SESSION_UNLOCK (rtpsession);
return GST_FLOW_OK;
}
}
static void