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_%u",
88 GST_STATIC_CAPS ("application/x-rtp")
91 static GstPad *gst_rtp_mux_request_new_pad (GstElement * element,
92 GstPadTemplate * templ, const gchar * name, const GstCaps * caps);
93 static void gst_rtp_mux_release_pad (GstElement * element, GstPad * pad);
94 static GstFlowReturn gst_rtp_mux_chain (GstPad * pad, GstObject * parent,
96 static GstFlowReturn gst_rtp_mux_chain_list (GstPad * pad, GstObject * parent,
97 GstBufferList * bufferlist);
98 static gboolean gst_rtp_mux_setcaps (GstPad * pad, GstRTPMux * rtp_mux,
100 static gboolean gst_rtp_mux_sink_event (GstPad * pad, GstObject * parent,
102 static gboolean gst_rtp_mux_sink_query (GstPad * pad, GstObject * parent,
105 static GstStateChangeReturn gst_rtp_mux_change_state (GstElement *
106 element, GstStateChange transition);
108 static void gst_rtp_mux_set_property (GObject * object, guint prop_id,
109 const GValue * value, GParamSpec * pspec);
110 static void gst_rtp_mux_get_property (GObject * object, guint prop_id,
111 GValue * value, GParamSpec * pspec);
112 static void gst_rtp_mux_dispose (GObject * object);
114 static gboolean gst_rtp_mux_src_event_real (GstRTPMux * rtp_mux,
117 G_DEFINE_TYPE (GstRTPMux, gst_rtp_mux, GST_TYPE_ELEMENT);
121 gst_rtp_mux_class_init (GstRTPMuxClass * klass)
123 GObjectClass *gobject_class;
124 GstElementClass *gstelement_class;
126 gobject_class = (GObjectClass *) klass;
127 gstelement_class = (GstElementClass *) klass;
130 gst_element_class_add_pad_template (gstelement_class,
131 gst_static_pad_template_get (&src_factory));
132 gst_element_class_add_pad_template (gstelement_class,
133 gst_static_pad_template_get (&sink_factory));
135 gst_element_class_set_metadata (gstelement_class, "RTP muxer",
137 "multiplex N rtp streams into one", "Zeeshan Ali <first.last@nokia.com>");
139 gobject_class->get_property = gst_rtp_mux_get_property;
140 gobject_class->set_property = gst_rtp_mux_set_property;
141 gobject_class->dispose = gst_rtp_mux_dispose;
143 klass->src_event = gst_rtp_mux_src_event_real;
145 g_object_class_install_property (G_OBJECT_CLASS (klass),
146 PROP_TIMESTAMP_OFFSET, g_param_spec_int ("timestamp-offset",
148 "Offset to add to all outgoing timestamps (-1 = random)", -1,
149 G_MAXINT, DEFAULT_TIMESTAMP_OFFSET,
150 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
151 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SEQNUM_OFFSET,
152 g_param_spec_int ("seqnum-offset", "Sequence number Offset",
153 "Offset to add to all outgoing seqnum (-1 = random)", -1, G_MAXINT,
154 DEFAULT_SEQNUM_OFFSET, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
155 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SEQNUM,
156 g_param_spec_uint ("seqnum", "Sequence number",
157 "The RTP sequence number of the last processed packet",
158 0, G_MAXUINT, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
159 g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_SSRC,
160 g_param_spec_uint ("ssrc", "SSRC",
161 "The SSRC of the packets (-1 == random)",
162 0, G_MAXUINT, DEFAULT_SSRC,
163 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
165 gstelement_class->request_new_pad =
166 GST_DEBUG_FUNCPTR (gst_rtp_mux_request_new_pad);
167 gstelement_class->release_pad = GST_DEBUG_FUNCPTR (gst_rtp_mux_release_pad);
168 gstelement_class->change_state = GST_DEBUG_FUNCPTR (gst_rtp_mux_change_state);
172 gst_rtp_mux_dispose (GObject * object)
174 GstRTPMux *rtp_mux = GST_RTP_MUX (object);
177 g_clear_object (&rtp_mux->last_pad);
180 for (item = GST_ELEMENT_PADS (object); item; item = g_list_next (item)) {
181 GstPad *pad = GST_PAD (item->data);
182 if (GST_PAD_IS_SINK (pad)) {
183 gst_element_release_request_pad (GST_ELEMENT (object), pad);
188 G_OBJECT_CLASS (gst_rtp_mux_parent_class)->dispose (object);
192 gst_rtp_mux_src_event (GstPad * pad, GstObject * parent, GstEvent * event)
194 GstRTPMux *rtp_mux = GST_RTP_MUX (parent);
195 GstRTPMuxClass *klass;
196 gboolean ret = FALSE;
198 klass = GST_RTP_MUX_GET_CLASS (rtp_mux);
200 ret = klass->src_event (rtp_mux, event);
206 gst_rtp_mux_src_event_real (GstRTPMux * rtp_mux, GstEvent * event)
209 gboolean result = FALSE;
210 gboolean done = FALSE;
212 iter = gst_element_iterate_sink_pads (GST_ELEMENT (rtp_mux));
215 GValue item = { 0, };
217 switch (gst_iterator_next (iter, &item)) {
218 case GST_ITERATOR_OK:
219 gst_event_ref (event);
220 result |= gst_pad_push_event (g_value_get_object (&item), event);
221 g_value_reset (&item);
223 case GST_ITERATOR_RESYNC:
224 gst_iterator_resync (iter);
227 case GST_ITERATOR_ERROR:
228 GST_WARNING_OBJECT (rtp_mux, "Error iterating sinkpads");
229 case GST_ITERATOR_DONE:
234 gst_iterator_free (iter);
235 gst_event_unref (event);
241 gst_rtp_mux_init (GstRTPMux * rtp_mux)
243 GstElementClass *klass = GST_ELEMENT_GET_CLASS (rtp_mux);
246 gst_pad_new_from_template (gst_element_class_get_pad_template (klass,
248 gst_pad_set_event_function (rtp_mux->srcpad,
249 GST_DEBUG_FUNCPTR (gst_rtp_mux_src_event));
250 gst_element_add_pad (GST_ELEMENT (rtp_mux), rtp_mux->srcpad);
252 rtp_mux->ssrc = DEFAULT_SSRC;
253 rtp_mux->ts_offset = DEFAULT_TIMESTAMP_OFFSET;
254 rtp_mux->seqnum_offset = DEFAULT_SEQNUM_OFFSET;
256 rtp_mux->last_stop = GST_CLOCK_TIME_NONE;
260 gst_rtp_mux_setup_sinkpad (GstRTPMux * rtp_mux, GstPad * sinkpad)
262 GstRTPMuxPadPrivate *padpriv = g_slice_new0 (GstRTPMuxPadPrivate);
264 /* setup some pad functions */
265 gst_pad_set_chain_function (sinkpad, GST_DEBUG_FUNCPTR (gst_rtp_mux_chain));
266 gst_pad_set_chain_list_function (sinkpad,
267 GST_DEBUG_FUNCPTR (gst_rtp_mux_chain_list));
268 gst_pad_set_event_function (sinkpad,
269 GST_DEBUG_FUNCPTR (gst_rtp_mux_sink_event));
270 gst_pad_set_query_function (sinkpad,
271 GST_DEBUG_FUNCPTR (gst_rtp_mux_sink_query));
274 gst_segment_init (&padpriv->segment, GST_FORMAT_UNDEFINED);
276 gst_pad_set_element_private (sinkpad, padpriv);
278 gst_pad_set_active (sinkpad, TRUE);
279 gst_element_add_pad (GST_ELEMENT (rtp_mux), sinkpad);
283 gst_rtp_mux_request_new_pad (GstElement * element,
284 GstPadTemplate * templ, const gchar * req_name, const GstCaps * caps)
289 g_return_val_if_fail (templ != NULL, NULL);
290 g_return_val_if_fail (GST_IS_RTP_MUX (element), NULL);
292 rtp_mux = GST_RTP_MUX (element);
294 if (templ->direction != GST_PAD_SINK) {
295 GST_WARNING_OBJECT (rtp_mux, "request pad that is not a SINK pad");
299 newpad = gst_pad_new_from_template (templ, req_name);
301 gst_rtp_mux_setup_sinkpad (rtp_mux, newpad);
303 GST_WARNING_OBJECT (rtp_mux, "failed to create request pad");
309 gst_rtp_mux_release_pad (GstElement * element, GstPad * pad)
311 GstRTPMuxPadPrivate *padpriv;
313 GST_OBJECT_LOCK (element);
314 padpriv = gst_pad_get_element_private (pad);
315 gst_pad_set_element_private (pad, NULL);
316 GST_OBJECT_UNLOCK (element);
318 gst_element_remove_pad (element, pad);
321 g_slice_free (GstRTPMuxPadPrivate, padpriv);
325 /* Put our own clock-base on the buffer */
327 gst_rtp_mux_readjust_rtp_timestamp_locked (GstRTPMux * rtp_mux,
328 GstRTPMuxPadPrivate * padpriv, GstRTPBuffer * rtpbuffer)
331 guint32 sink_ts_base = 0;
333 if (padpriv && padpriv->have_clock_base)
334 sink_ts_base = padpriv->clock_base;
336 ts = gst_rtp_buffer_get_timestamp (rtpbuffer) - sink_ts_base +
338 GST_LOG_OBJECT (rtp_mux, "Re-adjusting RTP ts %u to %u",
339 gst_rtp_buffer_get_timestamp (rtpbuffer), ts);
340 gst_rtp_buffer_set_timestamp (rtpbuffer, ts);
344 process_buffer_locked (GstRTPMux * rtp_mux, GstRTPMuxPadPrivate * padpriv,
345 GstRTPBuffer * rtpbuffer)
347 GstRTPMuxClass *klass = GST_RTP_MUX_GET_CLASS (rtp_mux);
349 if (klass->accept_buffer_locked)
350 if (!klass->accept_buffer_locked (rtp_mux, padpriv, rtpbuffer))
354 gst_rtp_buffer_set_seq (rtpbuffer, rtp_mux->seqnum);
356 gst_rtp_buffer_set_ssrc (rtpbuffer, rtp_mux->current_ssrc);
357 gst_rtp_mux_readjust_rtp_timestamp_locked (rtp_mux, padpriv, rtpbuffer);
358 GST_LOG_OBJECT (rtp_mux, "Pushing packet size %d, seq=%d, ts=%u",
359 rtpbuffer->map.size, rtp_mux->seqnum,
360 gst_rtp_buffer_get_timestamp (rtpbuffer));
363 if (padpriv->segment.format == GST_FORMAT_TIME)
364 GST_BUFFER_PTS (rtpbuffer->buffer) =
365 gst_segment_to_running_time (&padpriv->segment, GST_FORMAT_TIME,
366 GST_BUFFER_PTS (rtpbuffer->buffer));
372 struct BufferListData
375 GstRTPMuxPadPrivate *padpriv;
380 process_list_item (GstBuffer ** buffer, guint idx, gpointer user_data)
382 struct BufferListData *bd = user_data;
383 GstRTPBuffer rtpbuffer = GST_RTP_BUFFER_INIT;
385 *buffer = gst_buffer_make_writable (*buffer);
387 gst_rtp_buffer_map (*buffer, GST_MAP_READWRITE, &rtpbuffer);
389 bd->drop = !process_buffer_locked (bd->rtp_mux, bd->padpriv, &rtpbuffer);
391 gst_rtp_buffer_unmap (&rtpbuffer);
396 if (GST_BUFFER_DURATION_IS_VALID (*buffer) &&
397 GST_BUFFER_TIMESTAMP_IS_VALID (*buffer))
398 bd->rtp_mux->last_stop = GST_BUFFER_TIMESTAMP (*buffer) +
399 GST_BUFFER_DURATION (*buffer);
401 bd->rtp_mux->last_stop = GST_CLOCK_TIME_NONE;
407 gst_rtp_mux_chain_list (GstPad * pad, GstObject * parent,
408 GstBufferList * bufferlist)
412 GstRTPMuxPadPrivate *padpriv;
413 gboolean drop = TRUE;
414 struct BufferListData bd;
416 rtp_mux = GST_RTP_MUX (parent);
418 GST_OBJECT_LOCK (rtp_mux);
420 padpriv = gst_pad_get_element_private (pad);
422 GST_OBJECT_UNLOCK (rtp_mux);
423 ret = GST_FLOW_NOT_LINKED;
424 gst_buffer_list_unref (bufferlist);
428 bd.rtp_mux = rtp_mux;
429 bd.padpriv = padpriv;
432 bufferlist = gst_buffer_list_make_writable (bufferlist);
433 gst_buffer_list_foreach (bufferlist, process_list_item, &bd);
435 GST_OBJECT_UNLOCK (rtp_mux);
438 gst_buffer_list_unref (bufferlist);
441 ret = gst_pad_push_list (rtp_mux->srcpad, bufferlist);
450 resend_events (GstPad * pad, GstEvent ** event, gpointer user_data)
452 GstRTPMux *rtp_mux = user_data;
454 gst_pad_push_event (rtp_mux->srcpad, gst_event_ref (*event));
460 gst_rtp_mux_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
464 GstRTPMuxPadPrivate *padpriv;
466 gboolean changed = FALSE;
467 GstRTPBuffer rtpbuffer = GST_RTP_BUFFER_INIT;
469 rtp_mux = GST_RTP_MUX (GST_OBJECT_PARENT (pad));
471 if (!gst_rtp_buffer_validate (buffer)) {
472 gst_buffer_unref (buffer);
473 GST_ERROR_OBJECT (rtp_mux, "Invalid RTP buffer");
474 return GST_FLOW_ERROR;
477 GST_OBJECT_LOCK (rtp_mux);
478 padpriv = gst_pad_get_element_private (pad);
481 GST_OBJECT_UNLOCK (rtp_mux);
482 gst_buffer_unref (buffer);
483 return GST_FLOW_NOT_LINKED;
486 buffer = gst_buffer_make_writable (buffer);
488 gst_rtp_buffer_map (buffer, GST_MAP_READWRITE, &rtpbuffer);
490 drop = !process_buffer_locked (rtp_mux, padpriv, &rtpbuffer);
492 gst_rtp_buffer_unmap (&rtpbuffer);
495 if (pad != rtp_mux->last_pad) {
497 g_clear_object (&rtp_mux->last_pad);
498 rtp_mux->last_pad = g_object_ref (pad);
501 if (GST_BUFFER_DURATION_IS_VALID (buffer) &&
502 GST_BUFFER_TIMESTAMP_IS_VALID (buffer))
503 rtp_mux->last_stop = GST_BUFFER_TIMESTAMP (buffer) +
504 GST_BUFFER_DURATION (buffer);
506 rtp_mux->last_stop = GST_CLOCK_TIME_NONE;
509 GST_OBJECT_UNLOCK (rtp_mux);
512 gst_pad_sticky_events_foreach (pad, resend_events, rtp_mux);
515 gst_buffer_unref (buffer);
518 ret = gst_pad_push (rtp_mux->srcpad, buffer);
525 gst_rtp_mux_setcaps (GstPad * pad, GstRTPMux * rtp_mux, GstCaps * caps)
527 GstStructure *structure;
528 gboolean ret = FALSE;
529 GstRTPMuxPadPrivate *padpriv;
531 structure = gst_caps_get_structure (caps, 0);
536 GST_OBJECT_LOCK (rtp_mux);
537 padpriv = gst_pad_get_element_private (pad);
539 gst_structure_get_uint (structure, "clock-base", &padpriv->clock_base)) {
540 padpriv->have_clock_base = TRUE;
542 GST_OBJECT_UNLOCK (rtp_mux);
544 caps = gst_caps_copy (caps);
546 gst_caps_set_simple (caps,
547 "clock-base", G_TYPE_UINT, rtp_mux->ts_base,
548 "seqnum-base", G_TYPE_UINT, rtp_mux->seqnum_base, NULL);
550 GST_DEBUG_OBJECT (rtp_mux,
551 "setting caps %" GST_PTR_FORMAT " on src pad..", caps);
552 ret = gst_pad_set_caps (rtp_mux->srcpad, caps);
554 if (rtp_mux->ssrc == -1) {
555 if (gst_structure_has_field_typed (structure, "ssrc", G_TYPE_UINT)) {
556 rtp_mux->current_ssrc = g_value_get_uint
557 (gst_structure_get_value (structure, "ssrc"));
561 gst_caps_unref (caps);
567 clear_caps (GstCaps * caps, gboolean only_clock_rate)
571 /* Lets only match on the clock-rate */
572 for (i = 0; i < gst_caps_get_size (caps); i++) {
573 GstStructure *s = gst_caps_get_structure (caps, i);
575 for (j = 0; j < gst_structure_n_fields (s); j++) {
576 const gchar *name = gst_structure_nth_field_name (s, j);
578 if (strcmp (name, "clock-rate") && (only_clock_rate ||
579 (strcmp (name, "ssrc")))) {
580 gst_structure_remove_field (s, name);
588 same_clock_rate_fold (const GValue * item, GValue * ret, gpointer user_data)
590 GstPad *mypad = user_data;
591 GstPad *pad = g_value_get_object (item);
593 const GstCaps *accumcaps;
600 accumcaps = gst_value_get_caps (ret);
601 peercaps = gst_pad_peer_query_caps (pad, (GstCaps *) accumcaps);
603 g_warning ("no peercaps");
606 peercaps = gst_caps_make_writable (peercaps);
607 clear_caps (peercaps, TRUE);
609 intersect = gst_caps_intersect (accumcaps, peercaps);
611 g_value_take_boxed (ret, intersect);
612 gst_caps_unref (peercaps);
614 return !gst_caps_is_empty (intersect);
618 gst_rtp_mux_getcaps (GstPad * pad, GstRTPMux * mux, GstCaps * filter)
620 GstCaps *caps = NULL;
621 GstIterator *iter = NULL;
623 GstIteratorResult res;
625 GstCaps *othercaps = NULL;
626 GstCaps *filtered_caps;
628 peercaps = gst_pad_peer_query_caps (mux->srcpad, filter);
631 othercaps = gst_caps_intersect (peercaps,
632 gst_pad_get_pad_template_caps (pad));
633 gst_caps_unref (peercaps);
635 othercaps = gst_caps_copy (gst_pad_get_pad_template_caps (mux->srcpad));
639 filtered_caps = gst_caps_intersect (othercaps, filter);
640 gst_caps_unref (othercaps);
642 filtered_caps = othercaps;
645 filtered_caps = gst_caps_make_writable (filtered_caps);
646 clear_caps (filtered_caps, FALSE);
648 g_value_init (&v, GST_TYPE_CAPS);
650 iter = gst_element_iterate_sink_pads (GST_ELEMENT (mux));
652 gst_value_set_caps (&v, filtered_caps);
653 res = gst_iterator_fold (iter, same_clock_rate_fold, &v, pad);
654 gst_iterator_resync (iter);
655 } while (res == GST_ITERATOR_RESYNC);
656 gst_iterator_free (iter);
658 caps = (GstCaps *) gst_value_get_caps (&v);
660 if (res == GST_ITERATOR_ERROR) {
661 gst_caps_unref (caps);
662 caps = gst_caps_new_empty ();
665 gst_caps_unref (filtered_caps);
671 gst_rtp_mux_sink_query (GstPad * pad, GstObject * parent, GstQuery * query)
673 GstRTPMux *mux = GST_RTP_MUX (parent);
674 gboolean res = FALSE;
676 switch (GST_QUERY_TYPE (query)) {
679 GstCaps *filter, *caps;
681 gst_query_parse_caps (query, &filter);
682 caps = gst_rtp_mux_getcaps (pad, mux, filter);
683 gst_query_set_caps_result (query, caps);
684 gst_caps_unref (caps);
689 res = gst_pad_query_default (pad, parent, query);
700 gst_rtp_mux_get_property (GObject * object,
701 guint prop_id, GValue * value, GParamSpec * pspec)
705 rtp_mux = GST_RTP_MUX (object);
708 case PROP_TIMESTAMP_OFFSET:
709 g_value_set_int (value, rtp_mux->ts_offset);
711 case PROP_SEQNUM_OFFSET:
712 g_value_set_int (value, rtp_mux->seqnum_offset);
715 GST_OBJECT_LOCK (rtp_mux);
716 g_value_set_uint (value, rtp_mux->seqnum);
717 GST_OBJECT_UNLOCK (rtp_mux);
720 g_value_set_uint (value, rtp_mux->ssrc);
723 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
729 gst_rtp_mux_set_property (GObject * object,
730 guint prop_id, const GValue * value, GParamSpec * pspec)
734 rtp_mux = GST_RTP_MUX (object);
737 case PROP_TIMESTAMP_OFFSET:
738 rtp_mux->ts_offset = g_value_get_int (value);
740 case PROP_SEQNUM_OFFSET:
741 rtp_mux->seqnum_offset = g_value_get_int (value);
744 rtp_mux->ssrc = g_value_get_uint (value);
747 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
753 gst_rtp_mux_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
755 GstRTPMux *mux = GST_RTP_MUX (parent);
758 switch (GST_EVENT_TYPE (event)) {
763 gst_event_parse_caps (event, &caps);
764 return gst_rtp_mux_setcaps (pad, mux, caps);
766 case GST_EVENT_FLUSH_STOP:
768 GST_OBJECT_LOCK (mux);
769 mux->last_stop = GST_CLOCK_TIME_NONE;
770 GST_OBJECT_UNLOCK (mux);
773 case GST_EVENT_SEGMENT:
775 GstRTPMuxPadPrivate *padpriv;
777 GST_OBJECT_LOCK (mux);
778 padpriv = gst_pad_get_element_private (pad);
781 gst_event_copy_segment (event, &padpriv->segment);
783 GST_OBJECT_UNLOCK (mux);
784 gst_event_unref (event);
791 GST_OBJECT_LOCK (mux);
792 is_pad = (pad == mux->last_pad);
793 GST_OBJECT_UNLOCK (mux);
796 return gst_pad_push_event (mux->srcpad, event);
802 gst_rtp_mux_ready_to_paused (GstRTPMux * rtp_mux)
805 GST_OBJECT_LOCK (rtp_mux);
807 g_clear_object (&rtp_mux->last_pad);
809 if (rtp_mux->ssrc == -1)
810 rtp_mux->current_ssrc = g_random_int ();
812 rtp_mux->current_ssrc = rtp_mux->ssrc;
814 if (rtp_mux->seqnum_offset == -1)
815 rtp_mux->seqnum_base = g_random_int_range (0, G_MAXUINT16);
817 rtp_mux->seqnum_base = rtp_mux->seqnum_offset;
818 rtp_mux->seqnum = rtp_mux->seqnum_base;
820 if (rtp_mux->ts_offset == -1)
821 rtp_mux->ts_base = g_random_int ();
823 rtp_mux->ts_base = rtp_mux->ts_offset;
825 rtp_mux->last_stop = GST_CLOCK_TIME_NONE;
827 GST_DEBUG_OBJECT (rtp_mux, "set clock-base to %u", rtp_mux->ts_base);
829 GST_OBJECT_UNLOCK (rtp_mux);
832 static GstStateChangeReturn
833 gst_rtp_mux_change_state (GstElement * element, GstStateChange transition)
837 rtp_mux = GST_RTP_MUX (element);
839 switch (transition) {
840 case GST_STATE_CHANGE_NULL_TO_READY:
842 case GST_STATE_CHANGE_READY_TO_PAUSED:
843 gst_rtp_mux_ready_to_paused (rtp_mux);
845 case GST_STATE_CHANGE_PAUSED_TO_READY:
851 return GST_ELEMENT_CLASS (gst_rtp_mux_parent_class)->change_state (element,
856 gst_rtp_mux_plugin_init (GstPlugin * plugin)
858 GST_DEBUG_CATEGORY_INIT (gst_rtp_mux_debug, "rtpmux", 0, "rtp muxer");
860 return gst_element_register (plugin, "rtpmux", GST_RANK_NONE,