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, G_PARAM_READWRITE));
145 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SEQNUM_OFFSET,
146 g_param_spec_int ("seqnum-offset", "Sequence number Offset",
147 "Offset to add to all outgoing seqnum (-1 = random)", -1, G_MAXINT,
148 DEFAULT_SEQNUM_OFFSET, G_PARAM_READWRITE));
149 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SEQNUM,
150 g_param_spec_uint ("seqnum", "Sequence number",
151 "The RTP sequence number of the last processed packet",
152 0, G_MAXUINT, 0, G_PARAM_READABLE));
153 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SSRC,
154 g_param_spec_uint ("ssrc", "SSRC",
155 "The SSRC of the packets (-1 == random)",
156 0, G_MAXUINT, DEFAULT_SSRC, G_PARAM_READWRITE));
158 gstelement_class->request_new_pad =
159 GST_DEBUG_FUNCPTR (gst_rtp_mux_request_new_pad);
160 gstelement_class->release_pad = GST_DEBUG_FUNCPTR (gst_rtp_mux_release_pad);
161 gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_rtp_mux_change_state);
165 gst_rtp_mux_dispose (GObject * object)
170 for (item = GST_ELEMENT_PADS (object); item; item = g_list_next (item)) {
171 GstPad *pad = GST_PAD (item->data);
172 if (GST_PAD_IS_SINK (pad)) {
173 gst_element_release_request_pad (GST_ELEMENT (object), pad);
178 G_OBJECT_CLASS (parent_class)->dispose (object);
182 gst_rtp_mux_src_event (GstPad * pad, GstEvent * event)
187 gboolean result = FALSE;
188 gboolean done = FALSE;
190 rtp_mux = gst_pad_get_parent_element (pad);
191 g_return_val_if_fail (rtp_mux != NULL, FALSE);
193 iter = gst_element_iterate_sink_pads (rtp_mux);
196 switch (gst_iterator_next (iter, (gpointer) & sinkpad)) {
197 case GST_ITERATOR_OK:
198 gst_event_ref (event);
199 result |= gst_pad_push_event (sinkpad, event);
200 gst_object_unref (sinkpad);
202 case GST_ITERATOR_RESYNC:
203 gst_iterator_resync (iter);
206 case GST_ITERATOR_ERROR:
207 GST_WARNING_OBJECT (rtp_mux, "Error iterating sinkpads");
208 case GST_ITERATOR_DONE:
213 gst_iterator_free (iter);
214 gst_object_unref (rtp_mux);
215 gst_event_unref (event);
221 gst_rtp_mux_init (GstRTPMux * object, GstRTPMuxClass * g_class)
223 GstElementClass *klass = GST_ELEMENT_GET_CLASS (object);
226 gst_pad_new_from_template (gst_element_class_get_pad_template (klass,
228 gst_pad_set_event_function (object->srcpad,
229 GST_DEBUG_FUNCPTR (gst_rtp_mux_src_event));
230 gst_element_add_pad (GST_ELEMENT (object), object->srcpad);
232 object->ssrc = DEFAULT_SSRC;
233 object->ts_offset = DEFAULT_TIMESTAMP_OFFSET;
234 object->seqnum_offset = DEFAULT_SEQNUM_OFFSET;
236 object->segment_pending = TRUE;
240 gst_rtp_mux_setup_sinkpad (GstRTPMux * rtp_mux, GstPad * sinkpad)
242 GstRTPMuxClass *klass;
243 GstRTPMuxPadPrivate *padpriv = g_slice_new0 (GstRTPMuxPadPrivate);
245 klass = GST_RTP_MUX_GET_CLASS (rtp_mux);
247 /* setup some pad functions */
248 gst_pad_set_setcaps_function (sinkpad, gst_rtp_mux_setcaps);
249 gst_pad_set_getcaps_function (sinkpad, gst_rtp_mux_getcaps);
250 gst_pad_set_chain_function (sinkpad, GST_DEBUG_FUNCPTR (gst_rtp_mux_chain));
251 gst_pad_set_chain_list_function (sinkpad,
252 GST_DEBUG_FUNCPTR (gst_rtp_mux_chain_list));
253 gst_pad_set_event_function (sinkpad,
254 GST_DEBUG_FUNCPTR (gst_rtp_mux_sink_event));
257 gst_segment_init (&padpriv->segment, GST_FORMAT_UNDEFINED);
259 gst_pad_set_element_private (sinkpad, padpriv);
261 gst_pad_set_active (sinkpad, TRUE);
262 gst_element_add_pad (GST_ELEMENT (rtp_mux), sinkpad);
266 gst_rtp_mux_request_new_pad (GstElement * element,
267 GstPadTemplate * templ, const gchar * req_name)
272 g_return_val_if_fail (templ != NULL, NULL);
273 g_return_val_if_fail (GST_IS_RTP_MUX (element), NULL);
275 rtp_mux = GST_RTP_MUX (element);
277 if (templ->direction != GST_PAD_SINK) {
278 GST_WARNING_OBJECT (rtp_mux, "request pad that is not a SINK pad");
282 newpad = gst_pad_new_from_template (templ, req_name);
284 gst_rtp_mux_setup_sinkpad (rtp_mux, newpad);
286 GST_WARNING_OBJECT (rtp_mux, "failed to create request pad");
292 gst_rtp_mux_release_pad (GstElement * element, GstPad * pad)
294 GstRTPMuxPadPrivate *padpriv;
296 GST_OBJECT_LOCK (element);
297 padpriv = gst_pad_get_element_private (pad);
298 gst_pad_set_element_private (pad, NULL);
299 GST_OBJECT_UNLOCK (element);
301 gst_element_remove_pad (element, pad);
304 gst_caps_replace (&padpriv->out_caps, NULL);
305 g_slice_free (GstRTPMuxPadPrivate, padpriv);
309 /* Put our own clock-base on the buffer */
311 gst_rtp_mux_readjust_rtp_timestamp_locked (GstRTPMux * rtp_mux,
312 GstRTPMuxPadPrivate * padpriv, GstBuffer * buffer)
315 guint32 sink_ts_base = 0;
317 if (padpriv && padpriv->have_clock_base)
318 sink_ts_base = padpriv->clock_base;
320 ts = gst_rtp_buffer_get_timestamp (buffer) - sink_ts_base + rtp_mux->ts_base;
321 GST_LOG_OBJECT (rtp_mux, "Re-adjusting RTP ts %u to %u",
322 gst_rtp_buffer_get_timestamp (buffer), ts);
323 gst_rtp_buffer_set_timestamp (buffer, ts);
327 process_buffer_locked (GstRTPMux * rtp_mux, GstRTPMuxPadPrivate * padpriv,
330 GstRTPMuxClass *klass = GST_RTP_MUX_GET_CLASS (rtp_mux);
332 if (klass->accept_buffer_locked)
333 if (!klass->accept_buffer_locked (rtp_mux, padpriv, buffer))
337 gst_rtp_buffer_set_seq (buffer, rtp_mux->seqnum);
339 gst_rtp_buffer_set_ssrc (buffer, rtp_mux->current_ssrc);
340 gst_rtp_mux_readjust_rtp_timestamp_locked (rtp_mux, padpriv, buffer);
341 GST_LOG_OBJECT (rtp_mux, "Pushing packet size %d, seq=%d, ts=%u",
342 GST_BUFFER_SIZE (buffer), rtp_mux->seqnum,
343 gst_rtp_buffer_get_timestamp (buffer));
346 gst_buffer_set_caps (buffer, padpriv->out_caps);
347 if (padpriv->segment.format == GST_FORMAT_TIME)
348 GST_BUFFER_TIMESTAMP (buffer) =
349 gst_segment_to_running_time (&padpriv->segment, GST_FORMAT_TIME,
350 GST_BUFFER_TIMESTAMP (buffer));
357 gst_rtp_mux_chain_list (GstPad * pad, GstBufferList * bufferlist)
361 GstBufferListIterator *it;
362 GstRTPMuxPadPrivate *padpriv;
363 GstEvent *newseg_event = NULL;
364 gboolean drop = TRUE;
366 rtp_mux = GST_RTP_MUX (gst_pad_get_parent (pad));
368 if (!gst_rtp_buffer_list_validate (bufferlist)) {
369 GST_ERROR_OBJECT (rtp_mux, "Invalid RTP buffer");
370 gst_object_unref (rtp_mux);
371 return GST_FLOW_ERROR;
374 GST_OBJECT_LOCK (rtp_mux);
376 padpriv = gst_pad_get_element_private (pad);
378 GST_OBJECT_UNLOCK (rtp_mux);
379 ret = GST_FLOW_NOT_LINKED;
380 gst_buffer_list_unref (bufferlist);
384 bufferlist = gst_buffer_list_make_writable (bufferlist);
385 it = gst_buffer_list_iterate (bufferlist);
386 while (gst_buffer_list_iterator_next_group (it)) {
389 rtpbuf = gst_buffer_list_iterator_next (it);
390 rtpbuf = gst_buffer_make_writable (rtpbuf);
392 drop = !process_buffer_locked (rtp_mux, padpriv, rtpbuf);
397 gst_buffer_list_iterator_take (it, rtpbuf);
399 gst_buffer_list_iterator_free (it);
401 if (!drop && rtp_mux->segment_pending) {
403 * We set the start at 0, because we re-timestamps to the running time
405 newseg_event = gst_event_new_new_segment_full (FALSE, 1.0, 1.0,
406 GST_FORMAT_TIME, 0, -1, 0);
408 rtp_mux->segment_pending = FALSE;
411 GST_OBJECT_UNLOCK (rtp_mux);
414 gst_pad_push_event (rtp_mux->srcpad, newseg_event);
417 gst_buffer_list_unref (bufferlist);
420 ret = gst_pad_push_list (rtp_mux->srcpad, bufferlist);
425 gst_object_unref (rtp_mux);
431 gst_rtp_mux_chain (GstPad * pad, GstBuffer * buffer)
435 GstRTPMuxPadPrivate *padpriv;
436 GstEvent *newseg_event = NULL;
439 rtp_mux = GST_RTP_MUX (GST_OBJECT_PARENT (pad));
441 if (!gst_rtp_buffer_validate (buffer)) {
442 gst_buffer_unref (buffer);
443 GST_ERROR_OBJECT (rtp_mux, "Invalid RTP buffer");
444 return GST_FLOW_ERROR;
447 GST_OBJECT_LOCK (rtp_mux);
448 padpriv = gst_pad_get_element_private (pad);
451 GST_OBJECT_UNLOCK (rtp_mux);
452 gst_buffer_unref (buffer);
453 return GST_FLOW_NOT_LINKED;
456 buffer = gst_buffer_make_writable (buffer);
458 drop = !process_buffer_locked (rtp_mux, padpriv, buffer);
460 if (!drop && rtp_mux->segment_pending) {
462 * We set the start at 0, because we re-timestamps to the running time
464 newseg_event = gst_event_new_new_segment_full (FALSE, 1.0, 1.0,
465 GST_FORMAT_TIME, 0, -1, 0);
467 rtp_mux->segment_pending = FALSE;
469 GST_OBJECT_UNLOCK (rtp_mux);
472 gst_pad_push_event (rtp_mux->srcpad, newseg_event);
475 gst_buffer_unref (buffer);
478 ret = gst_pad_push (rtp_mux->srcpad, buffer);
485 gst_rtp_mux_setcaps (GstPad * pad, GstCaps * caps)
488 GstStructure *structure;
489 gboolean ret = FALSE;
490 GstRTPMuxPadPrivate *padpriv;
492 rtp_mux = GST_RTP_MUX (gst_pad_get_parent (pad));
494 structure = gst_caps_get_structure (caps, 0);
499 GST_OBJECT_LOCK (rtp_mux);
500 padpriv = gst_pad_get_element_private (pad);
502 gst_structure_get_uint (structure, "clock-base", &padpriv->clock_base)) {
503 padpriv->have_clock_base = TRUE;
505 GST_OBJECT_UNLOCK (rtp_mux);
507 caps = gst_caps_copy (caps);
509 gst_caps_set_simple (caps,
510 "clock-base", G_TYPE_UINT, rtp_mux->ts_base,
511 "seqnum-base", G_TYPE_UINT, rtp_mux->seqnum_base, NULL);
513 GST_DEBUG_OBJECT (rtp_mux,
514 "setting caps %" GST_PTR_FORMAT " on src pad..", caps);
515 ret = gst_pad_set_caps (rtp_mux->srcpad, caps);
517 if (rtp_mux->ssrc == -1) {
518 if (gst_structure_has_field_typed (structure, "ssrc", G_TYPE_UINT)) {
519 rtp_mux->current_ssrc = g_value_get_uint
520 (gst_structure_get_value (structure, "ssrc"));
525 GST_OBJECT_LOCK (rtp_mux);
526 padpriv = gst_pad_get_element_private (pad);
528 gst_caps_replace (&padpriv->out_caps, caps);
529 GST_OBJECT_UNLOCK (rtp_mux);
531 gst_caps_unref (caps);
534 gst_object_unref (rtp_mux);
540 clear_caps (GstCaps * caps, gboolean only_clock_rate)
544 /* Lets only match on the clock-rate */
545 for (i = 0; i < gst_caps_get_size (caps); i++) {
546 GstStructure *s = gst_caps_get_structure (caps, i);
548 for (j = 0; j < gst_structure_n_fields (s); j++) {
549 const gchar *name = gst_structure_nth_field_name (s, j);
551 if (strcmp (name, "clock-rate") && (only_clock_rate ||
552 (strcmp (name, "ssrc")))) {
553 gst_structure_remove_field (s, name);
561 same_clock_rate_fold (gpointer item, GValue * ret, gpointer user_data)
563 GstPad *mypad = user_data;
567 const GstCaps *accumcaps;
571 gst_object_unref (pad);
575 peercaps = gst_pad_peer_get_caps (pad);
577 gst_object_unref (pad);
581 othercaps = gst_caps_intersect (peercaps,
582 gst_pad_get_pad_template_caps (pad));
583 gst_caps_unref (peercaps);
585 accumcaps = gst_value_get_caps (ret);
587 clear_caps (othercaps, TRUE);
589 intersect = gst_caps_intersect (accumcaps, othercaps);
591 g_value_take_boxed (ret, intersect);
593 gst_caps_unref (othercaps);
594 gst_object_unref (pad);
596 return !gst_caps_is_empty (intersect);
600 gst_rtp_mux_getcaps (GstPad * pad)
602 GstRTPMux *mux = GST_RTP_MUX (gst_pad_get_parent (pad));
603 GstCaps *caps = NULL;
604 GstIterator *iter = NULL;
606 GstIteratorResult res;
607 GstCaps *peercaps = gst_pad_peer_get_caps (mux->srcpad);
608 GstCaps *othercaps = NULL;
611 othercaps = gst_caps_intersect (peercaps,
612 gst_pad_get_pad_template_caps (pad));
613 gst_caps_unref (peercaps);
615 othercaps = gst_caps_copy (gst_pad_get_pad_template_caps (mux->srcpad));
618 clear_caps (othercaps, FALSE);
620 g_value_init (&v, GST_TYPE_CAPS);
622 iter = gst_element_iterate_sink_pads (GST_ELEMENT (mux));
624 gst_value_set_caps (&v, othercaps);
625 res = gst_iterator_fold (iter, same_clock_rate_fold, &v, pad);
626 } while (res == GST_ITERATOR_RESYNC);
627 gst_iterator_free (iter);
629 caps = (GstCaps *) gst_value_get_caps (&v);
631 if (res == GST_ITERATOR_ERROR) {
632 gst_caps_unref (caps);
633 caps = gst_caps_new_empty ();
637 gst_caps_unref (othercaps);
638 gst_object_unref (mux);
645 gst_rtp_mux_get_property (GObject * object,
646 guint prop_id, GValue * value, GParamSpec * pspec)
650 rtp_mux = GST_RTP_MUX (object);
653 case PROP_TIMESTAMP_OFFSET:
654 g_value_set_int (value, rtp_mux->ts_offset);
656 case PROP_SEQNUM_OFFSET:
657 g_value_set_int (value, rtp_mux->seqnum_offset);
660 GST_OBJECT_LOCK (rtp_mux);
661 g_value_set_uint (value, rtp_mux->seqnum);
662 GST_OBJECT_UNLOCK (rtp_mux);
665 g_value_set_uint (value, rtp_mux->ssrc);
668 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
674 gst_rtp_mux_set_property (GObject * object,
675 guint prop_id, const GValue * value, GParamSpec * pspec)
679 rtp_mux = GST_RTP_MUX (object);
682 case PROP_TIMESTAMP_OFFSET:
683 rtp_mux->ts_offset = g_value_get_int (value);
685 case PROP_SEQNUM_OFFSET:
686 rtp_mux->seqnum_offset = g_value_get_int (value);
689 rtp_mux->ssrc = g_value_get_uint (value);
692 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
698 gst_rtp_mux_sink_event (GstPad * pad, GstEvent * event)
702 gboolean ret = FALSE;
703 gboolean forward = TRUE;
705 mux = GST_RTP_MUX (gst_pad_get_parent (pad));
707 switch (GST_EVENT_TYPE (event)) {
708 case GST_EVENT_FLUSH_STOP:
710 GstRTPMuxPadPrivate *padpriv;
712 GST_OBJECT_LOCK (mux);
713 mux->segment_pending = TRUE;
714 padpriv = gst_pad_get_element_private (pad);
716 gst_segment_init (&padpriv->segment, GST_FORMAT_UNDEFINED);
717 GST_OBJECT_UNLOCK (mux);
720 case GST_EVENT_NEWSEGMENT:
723 gdouble rate, applied_rate;
725 gint64 start, stop, position;
726 GstRTPMuxPadPrivate *padpriv;
728 gst_event_parse_new_segment_full (event, &update, &rate, &applied_rate,
729 &format, &start, &stop, &position);
731 GST_OBJECT_LOCK (mux);
732 padpriv = gst_pad_get_element_private (pad);
735 if (format == GST_FORMAT_TIME)
736 gst_segment_set_newsegment_full (&padpriv->segment, update,
737 rate, applied_rate, format, start, stop, position);
739 gst_segment_init (&padpriv->segment, GST_FORMAT_UNDEFINED);
741 GST_OBJECT_UNLOCK (mux);
742 gst_event_unref (event);
752 ret = gst_pad_push_event (mux->srcpad, event);
754 gst_object_unref (mux);
760 clear_segment (gpointer data, gpointer user_data)
763 GstRTPMux *mux = user_data;
764 GstRTPMuxPadPrivate *padpriv;
766 GST_OBJECT_LOCK (mux);
767 padpriv = gst_pad_get_element_private (pad);
769 gst_segment_init (&padpriv->segment, GST_FORMAT_UNDEFINED);
770 GST_OBJECT_UNLOCK (mux);
772 gst_object_unref (pad);
777 gst_rtp_mux_ready_to_paused (GstRTPMux * rtp_mux)
781 iter = gst_element_iterate_sink_pads (GST_ELEMENT (rtp_mux));
782 while (gst_iterator_foreach (iter, clear_segment, rtp_mux) ==
783 GST_ITERATOR_RESYNC);
784 gst_iterator_free (iter);
786 GST_OBJECT_LOCK (rtp_mux);
787 rtp_mux->segment_pending = TRUE;
789 if (rtp_mux->ssrc == -1)
790 rtp_mux->current_ssrc = g_random_int ();
792 rtp_mux->current_ssrc = rtp_mux->ssrc;
794 if (rtp_mux->seqnum_offset == -1)
795 rtp_mux->seqnum_base = g_random_int_range (0, G_MAXUINT16);
797 rtp_mux->seqnum_base = rtp_mux->seqnum_offset;
798 rtp_mux->seqnum = rtp_mux->seqnum_base;
800 if (rtp_mux->ts_offset == -1)
801 rtp_mux->ts_base = g_random_int ();
803 rtp_mux->ts_base = rtp_mux->ts_offset;
805 GST_DEBUG_OBJECT (rtp_mux, "set clock-base to %u", rtp_mux->ts_base);
807 GST_OBJECT_UNLOCK (rtp_mux);
810 static GstStateChangeReturn
811 gst_rtp_mux_change_state (GstElement * element, GstStateChange transition)
815 rtp_mux = GST_RTP_MUX (element);
817 switch (transition) {
818 case GST_STATE_CHANGE_NULL_TO_READY:
820 case GST_STATE_CHANGE_READY_TO_PAUSED:
821 gst_rtp_mux_ready_to_paused (rtp_mux);
823 case GST_STATE_CHANGE_PAUSED_TO_READY:
829 return GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
833 gst_rtp_mux_plugin_init (GstPlugin * plugin)
835 GST_DEBUG_CATEGORY_INIT (gst_rtp_mux_debug, "rtpmux", 0, "rtp muxer");
837 return gst_element_register (plugin, "rtpmux", GST_RANK_NONE,