1 /* RTP muxer element for GStreamer
5 * Copyright (C) <2007-2010> Nokia Corporation.
6 * Contact: Zeeshan Ali <zeeshan.ali@nokia.com>
7 * Copyright (C) <2007-2010> Collabora Ltd
8 * Contact: Olivier Crete <olivier.crete@collabora.co.uk>
9 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
10 * 2000,2005 Wim Taymans <wim@fluendo.com>
12 * This library is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU Library General Public
14 * License as published by the Free Software Foundation; either
15 * version 2 of the License, or (at your option) any later version.
17 * This library is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with this library; if not, write to the
24 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
25 * Boston, MA 02111-1307, USA.
29 * SECTION:element-rtpmux
30 * @see_also: rtpdtmfmux
32 * The rtp muxer takes multiple RTP streams having the same clock-rate and
33 * muxes into a single stream with a single SSRC.
36 * <title>Example pipelines</title>
38 * gst-launch rtpmux name=mux ! udpsink host=127.0.0.1 port=8888 \
39 * alsasrc ! alawenc ! rtppcmapay ! \
40 * application/x-rtp, payload=8, rate=8000 ! mux.sink_0 \
41 * audiotestsrc is-live=1 ! \
42 * mulawenc ! rtppcmupay ! \
43 * application/x-rtp, payload=0, rate=8000 ! mux.sink_1
45 * In this example, an audio stream is captured from ALSA and another is
46 * generated, both are encoded into different payload types and muxed together
47 * so they can be sent on the same port.
50 * Last reviewed on 2010-09-30 (0.10.21)
58 #include <gst/rtp/gstrtpbuffer.h>
61 #include "gstrtpmux.h"
63 GST_DEBUG_CATEGORY_STATIC (gst_rtp_mux_debug);
64 #define GST_CAT_DEFAULT gst_rtp_mux_debug
69 PROP_TIMESTAMP_OFFSET,
75 #define DEFAULT_TIMESTAMP_OFFSET -1
76 #define DEFAULT_SEQNUM_OFFSET -1
77 #define DEFAULT_SSRC -1
79 static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE ("src",
82 GST_STATIC_CAPS ("application/x-rtp")
85 static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE ("sink_%d",
88 GST_STATIC_CAPS ("application/x-rtp")
91 static GstPad *gst_rtp_mux_request_new_pad (GstElement * element,
92 GstPadTemplate * templ, const gchar * name);
93 static void gst_rtp_mux_release_pad (GstElement * element, GstPad * pad);
94 static GstFlowReturn gst_rtp_mux_chain (GstPad * pad, GstBuffer * buffer);
95 static GstFlowReturn gst_rtp_mux_chain_list (GstPad * pad,
96 GstBufferList * bufferlist);
97 static gboolean gst_rtp_mux_setcaps (GstPad * pad, GstCaps * caps);
98 static GstCaps *gst_rtp_mux_getcaps (GstPad * pad);
99 static gboolean gst_rtp_mux_sink_event (GstPad * pad, GstEvent * event);
101 static GstStateChangeReturn gst_rtp_mux_change_state (GstElement *
102 element, GstStateChange transition);
104 static void gst_rtp_mux_set_property (GObject * object, guint prop_id,
105 const GValue * value, GParamSpec * pspec);
106 static void gst_rtp_mux_get_property (GObject * object, guint prop_id,
107 GValue * value, GParamSpec * pspec);
108 static void gst_rtp_mux_dispose (GObject * object);
110 GST_BOILERPLATE (GstRTPMux, gst_rtp_mux, GstElement, GST_TYPE_ELEMENT);
113 gst_rtp_mux_base_init (gpointer g_class)
115 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
117 gst_element_class_add_pad_template (element_class,
118 gst_static_pad_template_get (&src_factory));
119 gst_element_class_add_pad_template (element_class,
120 gst_static_pad_template_get (&sink_factory));
122 gst_element_class_set_details_simple (element_class, "RTP muxer",
124 "multiplex N rtp streams into one", "Zeeshan Ali <first.last@nokia.com>");
128 gst_rtp_mux_class_init (GstRTPMuxClass * klass)
130 GObjectClass *gobject_class;
131 GstElementClass *gstelement_class;
133 gobject_class = (GObjectClass *) klass;
134 gstelement_class = (GstElementClass *) klass;
136 gobject_class->get_property = gst_rtp_mux_get_property;
137 gobject_class->set_property = gst_rtp_mux_set_property;
138 gobject_class->dispose = gst_rtp_mux_dispose;
140 g_object_class_install_property (G_OBJECT_CLASS (klass),
141 PROP_TIMESTAMP_OFFSET, g_param_spec_int ("timestamp-offset",
143 "Offset to add to all outgoing timestamps (-1 = random)", -1,
144 G_MAXINT, DEFAULT_TIMESTAMP_OFFSET,
145 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
146 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SEQNUM_OFFSET,
147 g_param_spec_int ("seqnum-offset", "Sequence number Offset",
148 "Offset to add to all outgoing seqnum (-1 = random)", -1, G_MAXINT,
149 DEFAULT_SEQNUM_OFFSET, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
150 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SEQNUM,
151 g_param_spec_uint ("seqnum", "Sequence number",
152 "The RTP sequence number of the last processed packet",
153 0, G_MAXUINT, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
154 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SSRC,
155 g_param_spec_uint ("ssrc", "SSRC",
156 "The SSRC of the packets (-1 == random)",
157 0, G_MAXUINT, DEFAULT_SSRC,
158 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
160 gstelement_class->request_new_pad =
161 GST_DEBUG_FUNCPTR (gst_rtp_mux_request_new_pad);
162 gstelement_class->release_pad = GST_DEBUG_FUNCPTR (gst_rtp_mux_release_pad);
163 gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_rtp_mux_change_state);
167 gst_rtp_mux_dispose (GObject * object)
172 for (item = GST_ELEMENT_PADS (object); item; item = g_list_next (item)) {
173 GstPad *pad = GST_PAD (item->data);
174 if (GST_PAD_IS_SINK (pad)) {
175 gst_element_release_request_pad (GST_ELEMENT (object), pad);
180 G_OBJECT_CLASS (parent_class)->dispose (object);
184 gst_rtp_mux_src_event (GstPad * pad, GstEvent * event)
189 gboolean result = FALSE;
190 gboolean done = FALSE;
192 rtp_mux = gst_pad_get_parent_element (pad);
193 g_return_val_if_fail (rtp_mux != NULL, FALSE);
195 iter = gst_element_iterate_sink_pads (rtp_mux);
198 switch (gst_iterator_next (iter, (gpointer) & sinkpad)) {
199 case GST_ITERATOR_OK:
200 gst_event_ref (event);
201 result |= gst_pad_push_event (sinkpad, event);
202 gst_object_unref (sinkpad);
204 case GST_ITERATOR_RESYNC:
205 gst_iterator_resync (iter);
208 case GST_ITERATOR_ERROR:
209 GST_WARNING_OBJECT (rtp_mux, "Error iterating sinkpads");
210 case GST_ITERATOR_DONE:
215 gst_iterator_free (iter);
216 gst_object_unref (rtp_mux);
217 gst_event_unref (event);
223 gst_rtp_mux_init (GstRTPMux * object, GstRTPMuxClass * g_class)
225 GstElementClass *klass = GST_ELEMENT_GET_CLASS (object);
228 gst_pad_new_from_template (gst_element_class_get_pad_template (klass,
230 gst_pad_set_event_function (object->srcpad,
231 GST_DEBUG_FUNCPTR (gst_rtp_mux_src_event));
232 gst_element_add_pad (GST_ELEMENT (object), object->srcpad);
234 object->ssrc = DEFAULT_SSRC;
235 object->ts_offset = DEFAULT_TIMESTAMP_OFFSET;
236 object->seqnum_offset = DEFAULT_SEQNUM_OFFSET;
238 object->segment_pending = TRUE;
242 gst_rtp_mux_setup_sinkpad (GstRTPMux * rtp_mux, GstPad * sinkpad)
244 GstRTPMuxPadPrivate *padpriv = g_slice_new0 (GstRTPMuxPadPrivate);
246 /* setup some pad functions */
247 gst_pad_set_setcaps_function (sinkpad, gst_rtp_mux_setcaps);
248 gst_pad_set_getcaps_function (sinkpad, gst_rtp_mux_getcaps);
249 gst_pad_set_chain_function (sinkpad, GST_DEBUG_FUNCPTR (gst_rtp_mux_chain));
250 gst_pad_set_chain_list_function (sinkpad,
251 GST_DEBUG_FUNCPTR (gst_rtp_mux_chain_list));
252 gst_pad_set_event_function (sinkpad,
253 GST_DEBUG_FUNCPTR (gst_rtp_mux_sink_event));
256 gst_segment_init (&padpriv->segment, GST_FORMAT_UNDEFINED);
258 gst_pad_set_element_private (sinkpad, padpriv);
260 gst_pad_set_active (sinkpad, TRUE);
261 gst_element_add_pad (GST_ELEMENT (rtp_mux), sinkpad);
265 gst_rtp_mux_request_new_pad (GstElement * element,
266 GstPadTemplate * templ, const gchar * req_name)
271 g_return_val_if_fail (templ != NULL, NULL);
272 g_return_val_if_fail (GST_IS_RTP_MUX (element), NULL);
274 rtp_mux = GST_RTP_MUX (element);
276 if (templ->direction != GST_PAD_SINK) {
277 GST_WARNING_OBJECT (rtp_mux, "request pad that is not a SINK pad");
281 newpad = gst_pad_new_from_template (templ, req_name);
283 gst_rtp_mux_setup_sinkpad (rtp_mux, newpad);
285 GST_WARNING_OBJECT (rtp_mux, "failed to create request pad");
291 gst_rtp_mux_release_pad (GstElement * element, GstPad * pad)
293 GstRTPMuxPadPrivate *padpriv;
295 GST_OBJECT_LOCK (element);
296 padpriv = gst_pad_get_element_private (pad);
297 gst_pad_set_element_private (pad, NULL);
298 GST_OBJECT_UNLOCK (element);
300 gst_element_remove_pad (element, pad);
303 gst_caps_replace (&padpriv->out_caps, NULL);
304 g_slice_free (GstRTPMuxPadPrivate, padpriv);
308 /* Put our own clock-base on the buffer */
310 gst_rtp_mux_readjust_rtp_timestamp_locked (GstRTPMux * rtp_mux,
311 GstRTPMuxPadPrivate * padpriv, GstBuffer * buffer)
314 guint32 sink_ts_base = 0;
316 if (padpriv && padpriv->have_clock_base)
317 sink_ts_base = padpriv->clock_base;
319 ts = gst_rtp_buffer_get_timestamp (buffer) - sink_ts_base + rtp_mux->ts_base;
320 GST_LOG_OBJECT (rtp_mux, "Re-adjusting RTP ts %u to %u",
321 gst_rtp_buffer_get_timestamp (buffer), ts);
322 gst_rtp_buffer_set_timestamp (buffer, ts);
326 process_buffer_locked (GstRTPMux * rtp_mux, GstRTPMuxPadPrivate * padpriv,
329 GstRTPMuxClass *klass = GST_RTP_MUX_GET_CLASS (rtp_mux);
331 if (klass->accept_buffer_locked)
332 if (!klass->accept_buffer_locked (rtp_mux, padpriv, buffer))
336 gst_rtp_buffer_set_seq (buffer, rtp_mux->seqnum);
338 gst_rtp_buffer_set_ssrc (buffer, rtp_mux->current_ssrc);
339 gst_rtp_mux_readjust_rtp_timestamp_locked (rtp_mux, padpriv, buffer);
340 GST_LOG_OBJECT (rtp_mux, "Pushing packet size %d, seq=%d, ts=%u",
341 GST_BUFFER_SIZE (buffer), rtp_mux->seqnum,
342 gst_rtp_buffer_get_timestamp (buffer));
345 gst_buffer_set_caps (buffer, padpriv->out_caps);
346 if (padpriv->segment.format == GST_FORMAT_TIME)
347 GST_BUFFER_TIMESTAMP (buffer) =
348 gst_segment_to_running_time (&padpriv->segment, GST_FORMAT_TIME,
349 GST_BUFFER_TIMESTAMP (buffer));
356 gst_rtp_mux_chain_list (GstPad * pad, GstBufferList * bufferlist)
360 GstBufferListIterator *it;
361 GstRTPMuxPadPrivate *padpriv;
362 GstEvent *newseg_event = NULL;
363 gboolean drop = TRUE;
365 rtp_mux = GST_RTP_MUX (gst_pad_get_parent (pad));
367 if (!gst_rtp_buffer_list_validate (bufferlist)) {
368 GST_ERROR_OBJECT (rtp_mux, "Invalid RTP buffer");
369 gst_object_unref (rtp_mux);
370 return GST_FLOW_ERROR;
373 GST_OBJECT_LOCK (rtp_mux);
375 padpriv = gst_pad_get_element_private (pad);
377 GST_OBJECT_UNLOCK (rtp_mux);
378 ret = GST_FLOW_NOT_LINKED;
379 gst_buffer_list_unref (bufferlist);
383 bufferlist = gst_buffer_list_make_writable (bufferlist);
384 it = gst_buffer_list_iterate (bufferlist);
385 while (gst_buffer_list_iterator_next_group (it)) {
388 rtpbuf = gst_buffer_list_iterator_next (it);
389 rtpbuf = gst_buffer_make_writable (rtpbuf);
391 drop = !process_buffer_locked (rtp_mux, padpriv, rtpbuf);
396 gst_buffer_list_iterator_take (it, rtpbuf);
398 gst_buffer_list_iterator_free (it);
400 if (!drop && rtp_mux->segment_pending) {
402 * We set the start at 0, because we re-timestamps to the running time
404 newseg_event = gst_event_new_new_segment_full (FALSE, 1.0, 1.0,
405 GST_FORMAT_TIME, 0, -1, 0);
407 rtp_mux->segment_pending = FALSE;
410 GST_OBJECT_UNLOCK (rtp_mux);
413 gst_pad_push_event (rtp_mux->srcpad, newseg_event);
416 gst_buffer_list_unref (bufferlist);
419 ret = gst_pad_push_list (rtp_mux->srcpad, bufferlist);
424 gst_object_unref (rtp_mux);
430 gst_rtp_mux_chain (GstPad * pad, GstBuffer * buffer)
434 GstRTPMuxPadPrivate *padpriv;
435 GstEvent *newseg_event = NULL;
438 rtp_mux = GST_RTP_MUX (GST_OBJECT_PARENT (pad));
440 if (!gst_rtp_buffer_validate (buffer)) {
441 gst_buffer_unref (buffer);
442 GST_ERROR_OBJECT (rtp_mux, "Invalid RTP buffer");
443 return GST_FLOW_ERROR;
446 GST_OBJECT_LOCK (rtp_mux);
447 padpriv = gst_pad_get_element_private (pad);
450 GST_OBJECT_UNLOCK (rtp_mux);
451 gst_buffer_unref (buffer);
452 return GST_FLOW_NOT_LINKED;
455 buffer = gst_buffer_make_writable (buffer);
457 drop = !process_buffer_locked (rtp_mux, padpriv, buffer);
459 if (!drop && rtp_mux->segment_pending) {
461 * We set the start at 0, because we re-timestamps to the running time
463 newseg_event = gst_event_new_new_segment_full (FALSE, 1.0, 1.0,
464 GST_FORMAT_TIME, 0, -1, 0);
466 rtp_mux->segment_pending = FALSE;
468 GST_OBJECT_UNLOCK (rtp_mux);
471 gst_pad_push_event (rtp_mux->srcpad, newseg_event);
474 gst_buffer_unref (buffer);
477 ret = gst_pad_push (rtp_mux->srcpad, buffer);
484 gst_rtp_mux_setcaps (GstPad * pad, GstCaps * caps)
487 GstStructure *structure;
488 gboolean ret = FALSE;
489 GstRTPMuxPadPrivate *padpriv;
491 rtp_mux = GST_RTP_MUX (gst_pad_get_parent (pad));
493 structure = gst_caps_get_structure (caps, 0);
498 GST_OBJECT_LOCK (rtp_mux);
499 padpriv = gst_pad_get_element_private (pad);
501 gst_structure_get_uint (structure, "clock-base", &padpriv->clock_base)) {
502 padpriv->have_clock_base = TRUE;
504 GST_OBJECT_UNLOCK (rtp_mux);
506 caps = gst_caps_copy (caps);
508 gst_caps_set_simple (caps,
509 "clock-base", G_TYPE_UINT, rtp_mux->ts_base,
510 "seqnum-base", G_TYPE_UINT, rtp_mux->seqnum_base, NULL);
512 GST_DEBUG_OBJECT (rtp_mux,
513 "setting caps %" GST_PTR_FORMAT " on src pad..", caps);
514 ret = gst_pad_set_caps (rtp_mux->srcpad, caps);
516 if (rtp_mux->ssrc == -1) {
517 if (gst_structure_has_field_typed (structure, "ssrc", G_TYPE_UINT)) {
518 rtp_mux->current_ssrc = g_value_get_uint
519 (gst_structure_get_value (structure, "ssrc"));
524 GST_OBJECT_LOCK (rtp_mux);
525 padpriv = gst_pad_get_element_private (pad);
527 gst_caps_replace (&padpriv->out_caps, caps);
528 GST_OBJECT_UNLOCK (rtp_mux);
530 gst_caps_unref (caps);
533 gst_object_unref (rtp_mux);
539 clear_caps (GstCaps * caps, gboolean only_clock_rate)
543 /* Lets only match on the clock-rate */
544 for (i = 0; i < gst_caps_get_size (caps); i++) {
545 GstStructure *s = gst_caps_get_structure (caps, i);
547 for (j = 0; j < gst_structure_n_fields (s); j++) {
548 const gchar *name = gst_structure_nth_field_name (s, j);
550 if (strcmp (name, "clock-rate") && (only_clock_rate ||
551 (strcmp (name, "ssrc")))) {
552 gst_structure_remove_field (s, name);
560 same_clock_rate_fold (gpointer item, GValue * ret, gpointer user_data)
562 GstPad *mypad = user_data;
566 const GstCaps *accumcaps;
570 gst_object_unref (pad);
574 peercaps = gst_pad_peer_get_caps (pad);
576 gst_object_unref (pad);
580 othercaps = gst_caps_intersect (peercaps,
581 gst_pad_get_pad_template_caps (pad));
582 gst_caps_unref (peercaps);
584 accumcaps = gst_value_get_caps (ret);
586 clear_caps (othercaps, TRUE);
588 intersect = gst_caps_intersect (accumcaps, othercaps);
590 g_value_take_boxed (ret, intersect);
592 gst_caps_unref (othercaps);
593 gst_object_unref (pad);
595 return !gst_caps_is_empty (intersect);
599 gst_rtp_mux_getcaps (GstPad * pad)
601 GstRTPMux *mux = GST_RTP_MUX (gst_pad_get_parent (pad));
602 GstCaps *caps = NULL;
603 GstIterator *iter = NULL;
605 GstIteratorResult res;
606 GstCaps *peercaps = gst_pad_peer_get_caps (mux->srcpad);
607 GstCaps *othercaps = NULL;
610 othercaps = gst_caps_intersect (peercaps,
611 gst_pad_get_pad_template_caps (pad));
612 gst_caps_unref (peercaps);
614 othercaps = gst_caps_copy (gst_pad_get_pad_template_caps (mux->srcpad));
617 clear_caps (othercaps, FALSE);
619 g_value_init (&v, GST_TYPE_CAPS);
621 iter = gst_element_iterate_sink_pads (GST_ELEMENT (mux));
623 gst_value_set_caps (&v, othercaps);
624 res = gst_iterator_fold (iter, same_clock_rate_fold, &v, pad);
625 } while (res == GST_ITERATOR_RESYNC);
626 gst_iterator_free (iter);
628 caps = (GstCaps *) gst_value_get_caps (&v);
630 if (res == GST_ITERATOR_ERROR) {
631 gst_caps_unref (caps);
632 caps = gst_caps_new_empty ();
636 gst_caps_unref (othercaps);
637 gst_object_unref (mux);
644 gst_rtp_mux_get_property (GObject * object,
645 guint prop_id, GValue * value, GParamSpec * pspec)
649 rtp_mux = GST_RTP_MUX (object);
652 case PROP_TIMESTAMP_OFFSET:
653 g_value_set_int (value, rtp_mux->ts_offset);
655 case PROP_SEQNUM_OFFSET:
656 g_value_set_int (value, rtp_mux->seqnum_offset);
659 GST_OBJECT_LOCK (rtp_mux);
660 g_value_set_uint (value, rtp_mux->seqnum);
661 GST_OBJECT_UNLOCK (rtp_mux);
664 g_value_set_uint (value, rtp_mux->ssrc);
667 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
673 gst_rtp_mux_set_property (GObject * object,
674 guint prop_id, const GValue * value, GParamSpec * pspec)
678 rtp_mux = GST_RTP_MUX (object);
681 case PROP_TIMESTAMP_OFFSET:
682 rtp_mux->ts_offset = g_value_get_int (value);
684 case PROP_SEQNUM_OFFSET:
685 rtp_mux->seqnum_offset = g_value_get_int (value);
688 rtp_mux->ssrc = g_value_get_uint (value);
691 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
697 gst_rtp_mux_sink_event (GstPad * pad, GstEvent * event)
701 gboolean ret = FALSE;
702 gboolean forward = TRUE;
704 mux = GST_RTP_MUX (gst_pad_get_parent (pad));
706 switch (GST_EVENT_TYPE (event)) {
707 case GST_EVENT_FLUSH_STOP:
709 GstRTPMuxPadPrivate *padpriv;
711 GST_OBJECT_LOCK (mux);
712 mux->segment_pending = TRUE;
713 padpriv = gst_pad_get_element_private (pad);
715 gst_segment_init (&padpriv->segment, GST_FORMAT_UNDEFINED);
716 GST_OBJECT_UNLOCK (mux);
719 case GST_EVENT_NEWSEGMENT:
722 gdouble rate, applied_rate;
724 gint64 start, stop, position;
725 GstRTPMuxPadPrivate *padpriv;
727 gst_event_parse_new_segment_full (event, &update, &rate, &applied_rate,
728 &format, &start, &stop, &position);
730 GST_OBJECT_LOCK (mux);
731 padpriv = gst_pad_get_element_private (pad);
734 if (format == GST_FORMAT_TIME)
735 gst_segment_set_newsegment_full (&padpriv->segment, update,
736 rate, applied_rate, format, start, stop, position);
738 gst_segment_init (&padpriv->segment, GST_FORMAT_UNDEFINED);
740 GST_OBJECT_UNLOCK (mux);
741 gst_event_unref (event);
751 ret = gst_pad_push_event (mux->srcpad, event);
753 gst_object_unref (mux);
759 clear_segment (gpointer data, gpointer user_data)
762 GstRTPMux *mux = user_data;
763 GstRTPMuxPadPrivate *padpriv;
765 GST_OBJECT_LOCK (mux);
766 padpriv = gst_pad_get_element_private (pad);
768 gst_segment_init (&padpriv->segment, GST_FORMAT_UNDEFINED);
769 GST_OBJECT_UNLOCK (mux);
771 gst_object_unref (pad);
776 gst_rtp_mux_ready_to_paused (GstRTPMux * rtp_mux)
780 iter = gst_element_iterate_sink_pads (GST_ELEMENT (rtp_mux));
781 while (gst_iterator_foreach (iter, clear_segment, rtp_mux) ==
782 GST_ITERATOR_RESYNC);
783 gst_iterator_free (iter);
785 GST_OBJECT_LOCK (rtp_mux);
786 rtp_mux->segment_pending = TRUE;
788 if (rtp_mux->ssrc == -1)
789 rtp_mux->current_ssrc = g_random_int ();
791 rtp_mux->current_ssrc = rtp_mux->ssrc;
793 if (rtp_mux->seqnum_offset == -1)
794 rtp_mux->seqnum_base = g_random_int_range (0, G_MAXUINT16);
796 rtp_mux->seqnum_base = rtp_mux->seqnum_offset;
797 rtp_mux->seqnum = rtp_mux->seqnum_base;
799 if (rtp_mux->ts_offset == -1)
800 rtp_mux->ts_base = g_random_int ();
802 rtp_mux->ts_base = rtp_mux->ts_offset;
804 GST_DEBUG_OBJECT (rtp_mux, "set clock-base to %u", rtp_mux->ts_base);
806 GST_OBJECT_UNLOCK (rtp_mux);
809 static GstStateChangeReturn
810 gst_rtp_mux_change_state (GstElement * element, GstStateChange transition)
814 rtp_mux = GST_RTP_MUX (element);
816 switch (transition) {
817 case GST_STATE_CHANGE_NULL_TO_READY:
819 case GST_STATE_CHANGE_READY_TO_PAUSED:
820 gst_rtp_mux_ready_to_paused (rtp_mux);
822 case GST_STATE_CHANGE_PAUSED_TO_READY:
828 return GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
832 gst_rtp_mux_plugin_init (GstPlugin * plugin)
834 GST_DEBUG_CATEGORY_INIT (gst_rtp_mux_debug, "rtpmux", 0, "rtp muxer");
836 return gst_element_register (plugin, "rtpmux", GST_RANK_NONE,