From: Havard Graff Date: Tue, 7 Jun 2016 12:38:19 +0000 (+0200) Subject: rtpmux: cleanup ssrc-handling code a bit X-Git-Tag: 1.16.2~354 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6f37bd8f19ad5ef563d64d1c97ac3f6a61b38773;p=platform%2Fupstream%2Fgst-plugins-good.git rtpmux: cleanup ssrc-handling code a bit And add some better logging. https://bugzilla.gnome.org/show_bug.cgi?id=795162 --- diff --git a/gst/rtpmanager/gstrtpmux.c b/gst/rtpmanager/gstrtpmux.c index 1841b97e9..3ac5b420e 100644 --- a/gst/rtpmanager/gstrtpmux.c +++ b/gst/rtpmanager/gstrtpmux.c @@ -213,7 +213,7 @@ gst_rtp_mux_src_event_real (GstRTPMux * rtp_mux, GstEvent * event) if (!gst_structure_get_uint (s, "ssrc", &ssrc)) ssrc = -1; - GST_DEBUG_OBJECT (rtp_mux, "collided ssrc: %" G_GUINT32_FORMAT, ssrc); + GST_DEBUG_OBJECT (rtp_mux, "collided ssrc: %x", ssrc); /* choose another ssrc for our stream */ GST_OBJECT_LOCK (rtp_mux); @@ -229,6 +229,8 @@ gst_rtp_mux_src_event_real (GstRTPMux * rtp_mux, GstEvent * event) rtp_mux->current_ssrc = g_random_int (); new_ssrc = rtp_mux->current_ssrc; + GST_INFO_OBJECT (rtp_mux, "New ssrc after collision %x (was: %x)", + new_ssrc, ssrc); GST_OBJECT_UNLOCK (rtp_mux); caps = gst_pad_get_current_caps (rtp_mux->srcpad); @@ -371,9 +373,9 @@ process_buffer_locked (GstRTPMux * rtp_mux, GstRTPMuxPadPrivate * padpriv, gst_rtp_buffer_set_ssrc (rtpbuffer, rtp_mux->current_ssrc); gst_rtp_mux_readjust_rtp_timestamp_locked (rtp_mux, padpriv, rtpbuffer); GST_LOG_OBJECT (rtp_mux, - "Pushing packet size %" G_GSIZE_FORMAT ", seq=%d, ts=%u", + "Pushing packet size %" G_GSIZE_FORMAT ", seq=%d, ts=%u, ssrc=%x", rtpbuffer->map[0].size, rtp_mux->seqnum, - gst_rtp_buffer_get_timestamp (rtpbuffer)); + gst_rtp_buffer_get_timestamp (rtpbuffer), rtp_mux->current_ssrc); if (padpriv) { if (padpriv->segment.format == GST_FORMAT_TIME) { @@ -619,8 +621,7 @@ gst_rtp_mux_setcaps (GstPad * pad, GstRTPMux * rtp_mux, GstCaps * caps) structure = gst_caps_get_structure (othercaps, 0); GST_OBJECT_LOCK (rtp_mux); if (gst_structure_get_uint (structure, "ssrc", &rtp_mux->current_ssrc)) { - GST_DEBUG_OBJECT (pad, "Use downstream ssrc: %x", - rtp_mux->current_ssrc); + GST_INFO_OBJECT (pad, "Use downstream ssrc: %x", rtp_mux->current_ssrc); rtp_mux->have_ssrc = TRUE; } GST_OBJECT_UNLOCK (rtp_mux); @@ -651,11 +652,14 @@ gst_rtp_mux_setcaps (GstPad * pad, GstRTPMux * rtp_mux, GstCaps * caps) and if that fails, generate one */ if (rtp_mux->ssrc == DEFAULT_SSRC) { if (rtp_mux->current_ssrc == DEFAULT_SSRC) { - if (!gst_structure_get_uint (structure, "ssrc", &rtp_mux->current_ssrc)) + if (!gst_structure_get_uint (structure, "ssrc", &rtp_mux->current_ssrc)) { rtp_mux->current_ssrc = g_random_int (); + GST_INFO_OBJECT (rtp_mux, "Set random ssrc %x", rtp_mux->current_ssrc); + } } } else { rtp_mux->current_ssrc = rtp_mux->ssrc; + GST_INFO_OBJECT (rtp_mux, "Set ssrc %x", rtp_mux->current_ssrc); } gst_caps_set_simple (caps, @@ -766,7 +770,7 @@ gst_rtp_mux_getcaps (GstPad * pad, GstRTPMux * mux, GstCaps * filter) structure = gst_caps_get_structure (othercaps, 0); if (mux->ssrc == DEFAULT_SSRC) { if (gst_structure_get_uint (structure, "ssrc", &mux->current_ssrc)) - GST_DEBUG_OBJECT (pad, "Use downstream ssrc: %u", mux->current_ssrc); + GST_DEBUG_OBJECT (pad, "Use downstream ssrc: %x", mux->current_ssrc); } clear_caps (othercaps, TRUE); @@ -874,7 +878,7 @@ gst_rtp_mux_set_property (GObject * object, rtp_mux->ssrc = g_value_get_uint (value); rtp_mux->current_ssrc = rtp_mux->ssrc; rtp_mux->have_ssrc = TRUE; - rtp_mux->ssrc_random = FALSE; + GST_DEBUG_OBJECT (rtp_mux, "ssrc prop set to %x", rtp_mux->ssrc); GST_OBJECT_UNLOCK (rtp_mux); break; default: @@ -967,12 +971,8 @@ gst_rtp_mux_ready_to_paused (GstRTPMux * rtp_mux) rtp_mux->last_stop = GST_CLOCK_TIME_NONE; - if (rtp_mux->ssrc_random) { - rtp_mux->have_ssrc = FALSE; - } else { + if (rtp_mux->have_ssrc) rtp_mux->current_ssrc = rtp_mux->ssrc; - rtp_mux->have_ssrc = TRUE; - } GST_DEBUG_OBJECT (rtp_mux, "set timestamp-offset to %u", rtp_mux->ts_base); diff --git a/gst/rtpmanager/gstrtpmux.h b/gst/rtpmanager/gstrtpmux.h index 3de9f4186..b94d408ba 100644 --- a/gst/rtpmanager/gstrtpmux.h +++ b/gst/rtpmanager/gstrtpmux.h @@ -72,7 +72,6 @@ struct _GstRTPMux guint ssrc; guint current_ssrc; gboolean have_ssrc; - gboolean ssrc_random; GstPad *last_pad; /* protected by object lock */ diff --git a/tests/check/elements/rtpmux.c b/tests/check/elements/rtpmux.c index a1c4ada93..d9defed28 100644 --- a/tests/check/elements/rtpmux.c +++ b/tests/check/elements/rtpmux.c @@ -511,6 +511,51 @@ GST_START_TEST (test_rtpmux_ssrc_property_overrules_downstream) } GST_END_TEST; +GST_START_TEST (test_rtpmux_ssrc_property_survive_statechange) +{ + GstHarness * h = gst_harness_new_with_padnames ("rtpmux", NULL, "src"); + GstHarness * h0 = gst_harness_new_with_element ( + h->element, "sink_0", NULL); + GstHarness * h1 = gst_harness_new_with_element ( + h->element, "sink_1", NULL); + GstBuffer * buf0; + GstBuffer * buf1; + + gst_element_set_state (h->element, GST_STATE_NULL); + /* rtpmux ssrc is set to 111111 */ + g_object_set (h->element, "ssrc", 111111, NULL); + gst_element_set_state (h->element, GST_STATE_PLAYING); + + /* upstream ssrc is 222222 and 333333 */ + gst_harness_set_src_caps_str (h0, "application/x-rtp, ssrc=(uint)222222"); + gst_harness_set_src_caps_str (h1, "application/x-rtp, ssrc=(uint)333333"); + + /* downstream is specifying 444444 as ssrc */ + gst_harness_set_sink_caps_str (h, "application/x-rtp, ssrc=(uint)444444"); + gst_harness_set_sink_caps_str (h, "application/x-rtp"); + + /* push*/ + fail_unless_equals_int (GST_FLOW_OK, + gst_harness_push (h0, generate_test_buffer (0, 222222))); + fail_unless_equals_int (GST_FLOW_OK, + gst_harness_push (h1, generate_test_buffer (0, 333333))); + + buf0 = gst_harness_pull (h); + buf1 = gst_harness_pull (h); + + /* we expect the ssrc to be property ssrc */ + fail_unless_equals_int (111111, _rtp_buffer_get_ssrc (buf0)); + fail_unless_equals_int (111111, _rtp_buffer_get_ssrc (buf1)); + + gst_buffer_unref (buf0); + gst_buffer_unref (buf1); + + gst_harness_teardown (h0); + gst_harness_teardown (h1); + gst_harness_teardown (h); +} +GST_END_TEST; + GST_START_TEST (test_rtpmux_ssrc_downstream_dynamic) { GstHarness *h = gst_harness_new_parse ("rtpmux ! capsfilter"); @@ -586,6 +631,7 @@ rtpmux_suite (void) tcase_add_test (tc_chain, test_rtpmux_ssrc_downstream_overrules_upstream); tcase_add_test (tc_chain, test_rtpmux_ssrc_property_overrules_downstream); + tcase_add_test (tc_chain, test_rtpmux_ssrc_property_survive_statechange); tcase_add_test (tc_chain, test_rtpmux_ssrc_downstream_dynamic);