2 * Copyright (C) <2007> Wim Taymans <wim.taymans@gmail.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
22 #include <gst/rtp/gstrtpbuffer.h>
23 #include <gst/rtp/gstrtcpbuffer.h>
24 #include <gst/netbuffer/gstnetbuffer.h>
27 #include "rtpsession.h"
29 GST_DEBUG_CATEGORY_STATIC (rtp_session_debug);
30 #define GST_CAT_DEFAULT rtp_session_debug
32 /* signals and args */
36 SIGNAL_ON_SSRC_COLLISION,
37 SIGNAL_ON_SSRC_VALIDATED,
38 SIGNAL_ON_SSRC_ACTIVE,
41 SIGNAL_ON_BYE_TIMEOUT,
43 SIGNAL_ON_SENDER_TIMEOUT,
47 #define DEFAULT_INTERNAL_SOURCE NULL
48 #define DEFAULT_BANDWIDTH RTP_STATS_BANDWIDTH
49 #define DEFAULT_RTCP_FRACTION RTP_STATS_RTCP_BANDWIDTH
50 #define DEFAULT_SDES_CNAME NULL
51 #define DEFAULT_SDES_NAME NULL
52 #define DEFAULT_SDES_EMAIL NULL
53 #define DEFAULT_SDES_PHONE NULL
54 #define DEFAULT_SDES_LOCATION NULL
55 #define DEFAULT_SDES_TOOL NULL
56 #define DEFAULT_SDES_NOTE NULL
57 #define DEFAULT_NUM_SOURCES 0
58 #define DEFAULT_NUM_ACTIVE_SOURCES 0
74 PROP_NUM_ACTIVE_SOURCES,
78 /* update average packet size, we keep this scaled by 16 to keep enough
80 #define UPDATE_AVG(avg, val) \
84 (avg) = ((val) + (15 * (avg))) >> 4;
86 /* The number RTCP intervals after which to timeout entries in the
89 #define RTCP_INTERVAL_COLLISION_TIMEOUT 10
91 /* GObject vmethods */
92 static void rtp_session_finalize (GObject * object);
93 static void rtp_session_set_property (GObject * object, guint prop_id,
94 const GValue * value, GParamSpec * pspec);
95 static void rtp_session_get_property (GObject * object, guint prop_id,
96 GValue * value, GParamSpec * pspec);
98 static guint rtp_session_signals[LAST_SIGNAL] = { 0 };
100 G_DEFINE_TYPE (RTPSession, rtp_session, G_TYPE_OBJECT);
102 static RTPSource *obtain_source (RTPSession * sess, guint32 ssrc,
103 gboolean * created, RTPArrivalStats * arrival, gboolean rtp);
104 static GstFlowReturn rtp_session_send_bye_locked (RTPSession * sess,
105 const gchar * reason, GstClockTime current_time);
106 static GstClockTime calculate_rtcp_interval (RTPSession * sess,
107 gboolean deterministic, gboolean first);
110 rtp_session_class_init (RTPSessionClass * klass)
112 GObjectClass *gobject_class;
114 gobject_class = (GObjectClass *) klass;
116 gobject_class->finalize = rtp_session_finalize;
117 gobject_class->set_property = rtp_session_set_property;
118 gobject_class->get_property = rtp_session_get_property;
121 * RTPSession::on-new-ssrc:
122 * @session: the object which received the signal
123 * @src: the new RTPSource
125 * Notify of a new SSRC that entered @session.
127 rtp_session_signals[SIGNAL_ON_NEW_SSRC] =
128 g_signal_new ("on-new-ssrc", G_TYPE_FROM_CLASS (klass),
129 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (RTPSessionClass, on_new_ssrc),
130 NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
133 * RTPSession::on-ssrc-collision:
134 * @session: the object which received the signal
135 * @src: the #RTPSource that caused a collision
137 * Notify when we have an SSRC collision
139 rtp_session_signals[SIGNAL_ON_SSRC_COLLISION] =
140 g_signal_new ("on-ssrc-collision", G_TYPE_FROM_CLASS (klass),
141 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (RTPSessionClass, on_ssrc_collision),
142 NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
145 * RTPSession::on-ssrc-validated:
146 * @session: the object which received the signal
147 * @src: the new validated RTPSource
149 * Notify of a new SSRC that became validated.
151 rtp_session_signals[SIGNAL_ON_SSRC_VALIDATED] =
152 g_signal_new ("on-ssrc-validated", G_TYPE_FROM_CLASS (klass),
153 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (RTPSessionClass, on_ssrc_validated),
154 NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
157 * RTPSession::on-ssrc-active:
158 * @session: the object which received the signal
159 * @src: the active RTPSource
161 * Notify of a SSRC that is active, i.e., sending RTCP.
163 rtp_session_signals[SIGNAL_ON_SSRC_ACTIVE] =
164 g_signal_new ("on-ssrc-active", G_TYPE_FROM_CLASS (klass),
165 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (RTPSessionClass, on_ssrc_active),
166 NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
169 * RTPSession::on-ssrc-sdes:
170 * @session: the object which received the signal
171 * @src: the RTPSource
173 * Notify that a new SDES was received for SSRC.
175 rtp_session_signals[SIGNAL_ON_SSRC_SDES] =
176 g_signal_new ("on-ssrc-sdes", G_TYPE_FROM_CLASS (klass),
177 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (RTPSessionClass, on_ssrc_sdes),
178 NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
181 * RTPSession::on-bye-ssrc:
182 * @session: the object which received the signal
183 * @src: the RTPSource that went away
185 * Notify of an SSRC that became inactive because of a BYE packet.
187 rtp_session_signals[SIGNAL_ON_BYE_SSRC] =
188 g_signal_new ("on-bye-ssrc", G_TYPE_FROM_CLASS (klass),
189 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (RTPSessionClass, on_bye_ssrc),
190 NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
193 * RTPSession::on-bye-timeout:
194 * @session: the object which received the signal
195 * @src: the RTPSource that timed out
197 * Notify of an SSRC that has timed out because of BYE
199 rtp_session_signals[SIGNAL_ON_BYE_TIMEOUT] =
200 g_signal_new ("on-bye-timeout", G_TYPE_FROM_CLASS (klass),
201 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (RTPSessionClass, on_bye_timeout),
202 NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
205 * RTPSession::on-timeout:
206 * @session: the object which received the signal
207 * @src: the RTPSource that timed out
209 * Notify of an SSRC that has timed out
211 rtp_session_signals[SIGNAL_ON_TIMEOUT] =
212 g_signal_new ("on-timeout", G_TYPE_FROM_CLASS (klass),
213 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (RTPSessionClass, on_timeout),
214 NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
217 * RTPSession::on-sender-timeout:
218 * @session: the object which received the signal
219 * @src: the RTPSource that timed out
221 * Notify of an SSRC that was a sender but timed out and became a receiver.
223 rtp_session_signals[SIGNAL_ON_SENDER_TIMEOUT] =
224 g_signal_new ("on-sender-timeout", G_TYPE_FROM_CLASS (klass),
225 G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (RTPSessionClass, on_sender_timeout),
226 NULL, NULL, g_cclosure_marshal_VOID__OBJECT, G_TYPE_NONE, 1,
229 g_object_class_install_property (gobject_class, PROP_INTERNAL_SOURCE,
230 g_param_spec_object ("internal-source", "Internal Source",
231 "The internal source element of the session",
232 RTP_TYPE_SOURCE, G_PARAM_READABLE));
234 g_object_class_install_property (gobject_class, PROP_BANDWIDTH,
235 g_param_spec_double ("bandwidth", "Bandwidth",
236 "The bandwidth of the session",
237 0.0, G_MAXDOUBLE, DEFAULT_BANDWIDTH, G_PARAM_READWRITE));
239 g_object_class_install_property (gobject_class, PROP_RTCP_FRACTION,
240 g_param_spec_double ("rtcp-fraction", "RTCP Fraction",
241 "The fraction of the bandwidth used for RTCP",
242 0.0, G_MAXDOUBLE, DEFAULT_RTCP_FRACTION, G_PARAM_READWRITE));
244 g_object_class_install_property (gobject_class, PROP_SDES_CNAME,
245 g_param_spec_string ("sdes-cname", "SDES CNAME",
246 "The CNAME to put in SDES messages of this session",
247 DEFAULT_SDES_CNAME, G_PARAM_READWRITE));
249 g_object_class_install_property (gobject_class, PROP_SDES_NAME,
250 g_param_spec_string ("sdes-name", "SDES NAME",
251 "The NAME to put in SDES messages of this session",
252 DEFAULT_SDES_NAME, G_PARAM_READWRITE));
254 g_object_class_install_property (gobject_class, PROP_SDES_EMAIL,
255 g_param_spec_string ("sdes-email", "SDES EMAIL",
256 "The EMAIL to put in SDES messages of this session",
257 DEFAULT_SDES_EMAIL, G_PARAM_READWRITE));
259 g_object_class_install_property (gobject_class, PROP_SDES_PHONE,
260 g_param_spec_string ("sdes-phone", "SDES PHONE",
261 "The PHONE to put in SDES messages of this session",
262 DEFAULT_SDES_PHONE, G_PARAM_READWRITE));
264 g_object_class_install_property (gobject_class, PROP_SDES_LOCATION,
265 g_param_spec_string ("sdes-location", "SDES LOCATION",
266 "The LOCATION to put in SDES messages of this session",
267 DEFAULT_SDES_LOCATION, G_PARAM_READWRITE));
269 g_object_class_install_property (gobject_class, PROP_SDES_TOOL,
270 g_param_spec_string ("sdes-tool", "SDES TOOL",
271 "The TOOL to put in SDES messages of this session",
272 DEFAULT_SDES_TOOL, G_PARAM_READWRITE));
274 g_object_class_install_property (gobject_class, PROP_SDES_NOTE,
275 g_param_spec_string ("sdes-note", "SDES NOTE",
276 "The NOTE to put in SDES messages of this session",
277 DEFAULT_SDES_NOTE, G_PARAM_READWRITE));
279 g_object_class_install_property (gobject_class, PROP_NUM_SOURCES,
280 g_param_spec_uint ("num-sources", "Num Sources",
281 "The number of sources in the session", 0, G_MAXUINT,
282 DEFAULT_NUM_SOURCES, G_PARAM_READABLE));
284 g_object_class_install_property (gobject_class, PROP_NUM_ACTIVE_SOURCES,
285 g_param_spec_uint ("num-active-sources", "Num Active Sources",
286 "The number of active sources in the session", 0, G_MAXUINT,
287 DEFAULT_NUM_ACTIVE_SOURCES, G_PARAM_READABLE));
289 GST_DEBUG_CATEGORY_INIT (rtp_session_debug, "rtpsession", 0, "RTP Session");
293 rtp_session_init (RTPSession * sess)
298 sess->lock = g_mutex_new ();
299 sess->key = g_random_int ();
303 for (i = 0; i < 32; i++) {
305 g_hash_table_new_full (NULL, NULL, NULL,
306 (GDestroyNotify) g_object_unref);
308 sess->cnames = g_hash_table_new_full (NULL, NULL, g_free, NULL);
310 rtp_stats_init_defaults (&sess->stats);
312 /* create an active SSRC for this session manager */
313 sess->source = rtp_session_create_source (sess);
314 sess->source->validated = TRUE;
315 sess->stats.active_sources++;
317 /* default UDP header length */
318 sess->header_len = 28;
321 /* some default SDES entries */
322 str = g_strdup_printf ("%s@%s", g_get_user_name (), g_get_host_name ());
323 rtp_source_set_sdes_string (sess->source, GST_RTCP_SDES_CNAME, str);
326 rtp_source_set_sdes_string (sess->source, GST_RTCP_SDES_NAME,
328 rtp_source_set_sdes_string (sess->source, GST_RTCP_SDES_TOOL, "GStreamer");
330 sess->first_rtcp = TRUE;
332 GST_DEBUG ("%p: session using SSRC: %08x", sess, sess->source->ssrc);
336 rtp_session_finalize (GObject * object)
341 sess = RTP_SESSION_CAST (object);
343 g_mutex_free (sess->lock);
344 for (i = 0; i < 32; i++)
345 g_hash_table_destroy (sess->ssrcs[i]);
347 g_free (sess->bye_reason);
349 g_hash_table_destroy (sess->cnames);
350 g_object_unref (sess->source);
352 G_OBJECT_CLASS (rtp_session_parent_class)->finalize (object);
356 rtp_session_set_property (GObject * object, guint prop_id,
357 const GValue * value, GParamSpec * pspec)
361 sess = RTP_SESSION (object);
365 rtp_session_set_bandwidth (sess, g_value_get_double (value));
367 case PROP_RTCP_FRACTION:
368 rtp_session_set_rtcp_fraction (sess, g_value_get_double (value));
370 case PROP_SDES_CNAME:
371 rtp_session_set_sdes_string (sess, GST_RTCP_SDES_CNAME,
372 g_value_get_string (value));
375 rtp_session_set_sdes_string (sess, GST_RTCP_SDES_NAME,
376 g_value_get_string (value));
378 case PROP_SDES_EMAIL:
379 rtp_session_set_sdes_string (sess, GST_RTCP_SDES_EMAIL,
380 g_value_get_string (value));
382 case PROP_SDES_PHONE:
383 rtp_session_set_sdes_string (sess, GST_RTCP_SDES_PHONE,
384 g_value_get_string (value));
386 case PROP_SDES_LOCATION:
387 rtp_session_set_sdes_string (sess, GST_RTCP_SDES_LOC,
388 g_value_get_string (value));
391 rtp_session_set_sdes_string (sess, GST_RTCP_SDES_TOOL,
392 g_value_get_string (value));
395 rtp_session_set_sdes_string (sess, GST_RTCP_SDES_NOTE,
396 g_value_get_string (value));
399 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
405 rtp_session_get_property (GObject * object, guint prop_id,
406 GValue * value, GParamSpec * pspec)
410 sess = RTP_SESSION (object);
413 case PROP_INTERNAL_SOURCE:
414 g_value_take_object (value, rtp_session_get_internal_source (sess));
417 g_value_set_double (value, rtp_session_get_bandwidth (sess));
419 case PROP_RTCP_FRACTION:
420 g_value_set_double (value, rtp_session_get_rtcp_fraction (sess));
422 case PROP_SDES_CNAME:
423 g_value_take_string (value, rtp_session_get_sdes_string (sess,
424 GST_RTCP_SDES_CNAME));
427 g_value_take_string (value, rtp_session_get_sdes_string (sess,
428 GST_RTCP_SDES_NAME));
430 case PROP_SDES_EMAIL:
431 g_value_take_string (value, rtp_session_get_sdes_string (sess,
432 GST_RTCP_SDES_EMAIL));
434 case PROP_SDES_PHONE:
435 g_value_take_string (value, rtp_session_get_sdes_string (sess,
436 GST_RTCP_SDES_PHONE));
438 case PROP_SDES_LOCATION:
439 g_value_take_string (value, rtp_session_get_sdes_string (sess,
443 g_value_take_string (value, rtp_session_get_sdes_string (sess,
444 GST_RTCP_SDES_TOOL));
447 g_value_take_string (value, rtp_session_get_sdes_string (sess,
448 GST_RTCP_SDES_NOTE));
450 case PROP_NUM_SOURCES:
451 g_value_set_uint (value, rtp_session_get_num_sources (sess));
453 case PROP_NUM_ACTIVE_SOURCES:
454 g_value_set_uint (value, rtp_session_get_num_active_sources (sess));
457 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
463 on_new_ssrc (RTPSession * sess, RTPSource * source)
465 RTP_SESSION_UNLOCK (sess);
466 g_signal_emit (sess, rtp_session_signals[SIGNAL_ON_NEW_SSRC], 0, source);
467 RTP_SESSION_LOCK (sess);
471 on_ssrc_collision (RTPSession * sess, RTPSource * source)
473 RTP_SESSION_UNLOCK (sess);
474 g_signal_emit (sess, rtp_session_signals[SIGNAL_ON_SSRC_COLLISION], 0,
476 RTP_SESSION_LOCK (sess);
480 on_ssrc_validated (RTPSession * sess, RTPSource * source)
482 RTP_SESSION_UNLOCK (sess);
483 g_signal_emit (sess, rtp_session_signals[SIGNAL_ON_SSRC_VALIDATED], 0,
485 RTP_SESSION_LOCK (sess);
489 on_ssrc_active (RTPSession * sess, RTPSource * source)
491 RTP_SESSION_UNLOCK (sess);
492 g_signal_emit (sess, rtp_session_signals[SIGNAL_ON_SSRC_ACTIVE], 0, source);
493 RTP_SESSION_LOCK (sess);
497 on_ssrc_sdes (RTPSession * sess, RTPSource * source)
499 GST_DEBUG ("SDES changed for SSRC %08x", source->ssrc);
500 RTP_SESSION_UNLOCK (sess);
501 g_signal_emit (sess, rtp_session_signals[SIGNAL_ON_SSRC_SDES], 0, source);
502 RTP_SESSION_LOCK (sess);
506 on_bye_ssrc (RTPSession * sess, RTPSource * source)
508 RTP_SESSION_UNLOCK (sess);
509 g_signal_emit (sess, rtp_session_signals[SIGNAL_ON_BYE_SSRC], 0, source);
510 RTP_SESSION_LOCK (sess);
514 on_bye_timeout (RTPSession * sess, RTPSource * source)
516 RTP_SESSION_UNLOCK (sess);
517 g_signal_emit (sess, rtp_session_signals[SIGNAL_ON_BYE_TIMEOUT], 0, source);
518 RTP_SESSION_LOCK (sess);
522 on_timeout (RTPSession * sess, RTPSource * source)
524 RTP_SESSION_UNLOCK (sess);
525 g_signal_emit (sess, rtp_session_signals[SIGNAL_ON_TIMEOUT], 0, source);
526 RTP_SESSION_LOCK (sess);
530 on_sender_timeout (RTPSession * sess, RTPSource * source)
532 RTP_SESSION_UNLOCK (sess);
533 g_signal_emit (sess, rtp_session_signals[SIGNAL_ON_SENDER_TIMEOUT], 0,
535 RTP_SESSION_LOCK (sess);
541 * Create a new session object.
543 * Returns: a new #RTPSession. g_object_unref() after usage.
546 rtp_session_new (void)
550 sess = g_object_new (RTP_TYPE_SESSION, NULL);
556 * rtp_session_set_callbacks:
557 * @sess: an #RTPSession
558 * @callbacks: callbacks to configure
559 * @user_data: user data passed in the callbacks
561 * Configure a set of callbacks to be notified of actions.
564 rtp_session_set_callbacks (RTPSession * sess, RTPSessionCallbacks * callbacks,
567 g_return_if_fail (RTP_IS_SESSION (sess));
569 if (callbacks->process_rtp) {
570 sess->callbacks.process_rtp = callbacks->process_rtp;
571 sess->process_rtp_user_data = user_data;
573 if (callbacks->send_rtp) {
574 sess->callbacks.send_rtp = callbacks->send_rtp;
575 sess->send_rtp_user_data = user_data;
577 if (callbacks->send_rtcp) {
578 sess->callbacks.send_rtcp = callbacks->send_rtcp;
579 sess->send_rtcp_user_data = user_data;
581 if (callbacks->sync_rtcp) {
582 sess->callbacks.sync_rtcp = callbacks->sync_rtcp;
583 sess->sync_rtcp_user_data = user_data;
585 if (callbacks->clock_rate) {
586 sess->callbacks.clock_rate = callbacks->clock_rate;
587 sess->clock_rate_user_data = user_data;
589 if (callbacks->reconsider) {
590 sess->callbacks.reconsider = callbacks->reconsider;
591 sess->reconsider_user_data = user_data;
596 * rtp_session_set_process_rtp_callback:
597 * @sess: an #RTPSession
598 * @callback: callback to set
599 * @user_data: user data passed in the callback
601 * Configure only the process_rtp callback to be notified of the process_rtp action.
604 rtp_session_set_process_rtp_callback (RTPSession * sess,
605 RTPSessionProcessRTP callback, gpointer user_data)
607 g_return_if_fail (RTP_IS_SESSION (sess));
609 sess->callbacks.process_rtp = callback;
610 sess->process_rtp_user_data = user_data;
614 * rtp_session_set_send_rtp_callback:
615 * @sess: an #RTPSession
616 * @callback: callback to set
617 * @user_data: user data passed in the callback
619 * Configure only the send_rtp callback to be notified of the send_rtp action.
622 rtp_session_set_send_rtp_callback (RTPSession * sess,
623 RTPSessionSendRTP callback, gpointer user_data)
625 g_return_if_fail (RTP_IS_SESSION (sess));
627 sess->callbacks.send_rtp = callback;
628 sess->send_rtp_user_data = user_data;
632 * rtp_session_set_send_rtcp_callback:
633 * @sess: an #RTPSession
634 * @callback: callback to set
635 * @user_data: user data passed in the callback
637 * Configure only the send_rtcp callback to be notified of the send_rtcp action.
640 rtp_session_set_send_rtcp_callback (RTPSession * sess,
641 RTPSessionSendRTCP callback, gpointer user_data)
643 g_return_if_fail (RTP_IS_SESSION (sess));
645 sess->callbacks.send_rtcp = callback;
646 sess->send_rtcp_user_data = user_data;
650 * rtp_session_set_sync_rtcp_callback:
651 * @sess: an #RTPSession
652 * @callback: callback to set
653 * @user_data: user data passed in the callback
655 * Configure only the sync_rtcp callback to be notified of the sync_rtcp action.
658 rtp_session_set_sync_rtcp_callback (RTPSession * sess,
659 RTPSessionSyncRTCP callback, gpointer user_data)
661 g_return_if_fail (RTP_IS_SESSION (sess));
663 sess->callbacks.sync_rtcp = callback;
664 sess->sync_rtcp_user_data = user_data;
668 * rtp_session_set_clock_rate_callback:
669 * @sess: an #RTPSession
670 * @callback: callback to set
671 * @user_data: user data passed in the callback
673 * Configure only the clock_rate callback to be notified of the clock_rate action.
676 rtp_session_set_clock_rate_callback (RTPSession * sess,
677 RTPSessionClockRate callback, gpointer user_data)
679 g_return_if_fail (RTP_IS_SESSION (sess));
681 sess->callbacks.clock_rate = callback;
682 sess->clock_rate_user_data = user_data;
686 * rtp_session_set_reconsider_callback:
687 * @sess: an #RTPSession
688 * @callback: callback to set
689 * @user_data: user data passed in the callback
691 * Configure only the reconsider callback to be notified of the reconsider action.
694 rtp_session_set_reconsider_callback (RTPSession * sess,
695 RTPSessionReconsider callback, gpointer user_data)
697 g_return_if_fail (RTP_IS_SESSION (sess));
699 sess->callbacks.reconsider = callback;
700 sess->reconsider_user_data = user_data;
704 * rtp_session_set_bandwidth:
705 * @sess: an #RTPSession
706 * @bandwidth: the bandwidth allocated
708 * Set the session bandwidth in bytes per second.
711 rtp_session_set_bandwidth (RTPSession * sess, gdouble bandwidth)
713 g_return_if_fail (RTP_IS_SESSION (sess));
715 RTP_SESSION_LOCK (sess);
716 sess->stats.bandwidth = bandwidth;
717 RTP_SESSION_UNLOCK (sess);
721 * rtp_session_get_bandwidth:
722 * @sess: an #RTPSession
724 * Get the session bandwidth.
726 * Returns: the session bandwidth.
729 rtp_session_get_bandwidth (RTPSession * sess)
733 g_return_val_if_fail (RTP_IS_SESSION (sess), 0);
735 RTP_SESSION_LOCK (sess);
736 result = sess->stats.bandwidth;
737 RTP_SESSION_UNLOCK (sess);
743 * rtp_session_set_rtcp_fraction:
744 * @sess: an #RTPSession
745 * @bandwidth: the RTCP bandwidth
747 * Set the bandwidth that should be used for RTCP
751 rtp_session_set_rtcp_fraction (RTPSession * sess, gdouble bandwidth)
753 g_return_if_fail (RTP_IS_SESSION (sess));
755 RTP_SESSION_LOCK (sess);
756 sess->stats.rtcp_bandwidth = bandwidth;
757 RTP_SESSION_UNLOCK (sess);
761 * rtp_session_get_rtcp_fraction:
762 * @sess: an #RTPSession
764 * Get the session bandwidth used for RTCP.
766 * Returns: The bandwidth used for RTCP messages.
769 rtp_session_get_rtcp_fraction (RTPSession * sess)
773 g_return_val_if_fail (RTP_IS_SESSION (sess), 0.0);
775 RTP_SESSION_LOCK (sess);
776 result = sess->stats.rtcp_bandwidth;
777 RTP_SESSION_UNLOCK (sess);
783 * rtp_session_set_sdes_string:
784 * @sess: an #RTPSession
785 * @type: the type of the SDES item
786 * @item: a null-terminated string to set.
788 * Store an SDES item of @type in @sess.
790 * Returns: %FALSE if the data was unchanged @type is invalid.
793 rtp_session_set_sdes_string (RTPSession * sess, GstRTCPSDESType type,
798 g_return_val_if_fail (RTP_IS_SESSION (sess), FALSE);
800 RTP_SESSION_LOCK (sess);
801 result = rtp_source_set_sdes_string (sess->source, type, item);
802 RTP_SESSION_UNLOCK (sess);
808 * rtp_session_get_sdes_string:
809 * @sess: an #RTPSession
810 * @type: the type of the SDES item
812 * Get the SDES item of @type from @sess.
814 * Returns: a null-terminated copy of the SDES item or NULL when @type was not
815 * valid. g_free() after usage.
818 rtp_session_get_sdes_string (RTPSession * sess, GstRTCPSDESType type)
822 g_return_val_if_fail (RTP_IS_SESSION (sess), NULL);
824 RTP_SESSION_LOCK (sess);
825 result = rtp_source_get_sdes_string (sess->source, type);
826 RTP_SESSION_UNLOCK (sess);
832 source_push_rtp (RTPSource * source, GstBuffer * buffer, RTPSession * session)
834 GstFlowReturn result = GST_FLOW_OK;
836 if (source == session->source) {
837 GST_LOG ("source %08x pushed sender RTP packet", source->ssrc);
839 RTP_SESSION_UNLOCK (session);
841 if (session->callbacks.send_rtp)
843 session->callbacks.send_rtp (session, source, buffer,
844 session->send_rtp_user_data);
846 gst_buffer_unref (buffer);
849 GST_LOG ("source %08x pushed receiver RTP packet", source->ssrc);
850 RTP_SESSION_UNLOCK (session);
852 if (session->callbacks.process_rtp)
854 session->callbacks.process_rtp (session, source, buffer,
855 session->process_rtp_user_data);
857 gst_buffer_unref (buffer);
859 RTP_SESSION_LOCK (session);
865 source_clock_rate (RTPSource * source, guint8 pt, RTPSession * session)
869 RTP_SESSION_UNLOCK (session);
871 if (session->callbacks.clock_rate)
873 session->callbacks.clock_rate (session, pt,
874 session->clock_rate_user_data);
878 RTP_SESSION_LOCK (session);
880 GST_DEBUG ("got clock-rate %d for pt %d", result, pt);
885 static RTPSourceCallbacks callbacks = {
886 (RTPSourcePushRTP) source_push_rtp,
887 (RTPSourceClockRate) source_clock_rate,
891 * find_add_conflicting_addresses:
892 * @sess: The session to check in
893 * @arrival: The arrival stats for the buffer
895 * Checks if an address which has a conflict is already known,
896 * otherwise remembers it to prevent loops.
898 * Returns: TRUE if it was a known conflict, FALSE otherwise
902 find_add_conflicting_addresses (RTPSession * sess, RTPArrivalStats * arrival)
905 RTPConflictingAddress *new_conflict;
907 for (item = g_list_first (sess->conflicting_addresses);
908 item; item = g_list_next (item)) {
909 RTPConflictingAddress *known_conflict = item->data;
911 if (gst_netaddress_equal (&arrival->address, &known_conflict->address)) {
912 known_conflict->time = arrival->time;
917 new_conflict = g_new0 (RTPConflictingAddress, 1);
919 memcpy (&new_conflict->address, &arrival->address, sizeof (GstNetAddress));
920 new_conflict->time = arrival->time;
922 sess->conflicting_addresses = g_list_prepend (sess->conflicting_addresses,
929 check_collision (RTPSession * sess, RTPSource * source,
930 RTPArrivalStats * arrival, gboolean rtp)
932 /* If we have not arrival address, we can't do collision checking */
933 if (!arrival->have_address)
936 if (sess->source != source) {
937 /* This is not our local source, but lets check if two remote
941 if (source->have_rtp_from) {
942 if (gst_netaddress_equal (&source->rtp_from, &arrival->address))
943 /* Address is the same */
946 /* We don't already have a from address for RTP, just set it */
947 rtp_source_set_rtp_from (source, &arrival->address);
951 if (source->have_rtcp_from) {
952 if (gst_netaddress_equal (&source->rtcp_from, &arrival->address))
953 /* Address is the same */
956 /* We don't already have a from address for RTCP, just set it */
957 rtp_source_set_rtcp_from (source, &arrival->address);
961 /* We received RTP or RTCP from this source before but the network address
962 * changed. In this case, we have third-party collision or loop */
963 GST_DEBUG ("we have a third-party collision or loop");
965 /* FIXME: Log 3rd party collision somehow
966 * Maybe should be done in upper layer, only the SDES can tell us
967 * if its a collision or a loop
970 /* This is sending with our ssrc, is it an address we already know */
972 if (find_add_conflicting_addresses (sess, arrival)) {
973 /* Its a known conflict, its probably a loop, not a collision
974 * lets just drop the incoming packet
976 GST_DEBUG ("Our packets are being looped back to us, dropping");
978 /* Its a new collision, lets change our SSRC */
980 GST_DEBUG ("Collision for SSRC %x", rtp_source_get_ssrc (source));
981 on_ssrc_collision (sess, source);
983 rtp_session_send_bye_locked (sess, "SSRC Collision", arrival->time);
985 sess->change_ssrc = TRUE;
993 /* must be called with the session lock */
995 obtain_source (RTPSession * sess, guint32 ssrc, gboolean * created,
996 RTPArrivalStats * arrival, gboolean rtp)
1001 g_hash_table_lookup (sess->ssrcs[sess->mask_idx], GINT_TO_POINTER (ssrc));
1002 if (source == NULL) {
1003 /* make new Source in probation and insert */
1004 source = rtp_source_new (ssrc);
1006 /* for RTP packets we need to set the source in probation. Receiving RTCP
1007 * packets of an SSRC, on the other hand, is a strong indication that we
1008 * are dealing with a valid source. */
1010 source->probation = RTP_DEFAULT_PROBATION;
1012 source->probation = 0;
1014 /* store from address, if any */
1015 if (arrival->have_address) {
1017 rtp_source_set_rtp_from (source, &arrival->address);
1019 rtp_source_set_rtcp_from (source, &arrival->address);
1022 /* configure a callback on the source */
1023 rtp_source_set_callbacks (source, &callbacks, sess);
1025 g_hash_table_insert (sess->ssrcs[sess->mask_idx], GINT_TO_POINTER (ssrc),
1028 /* we have one more source now */
1029 sess->total_sources++;
1033 /* check for collision, this updates the address when not previously set */
1034 if (check_collision (sess, source, arrival, rtp)) {
1038 /* update last activity */
1039 source->last_activity = arrival->time;
1041 source->last_rtp_activity = arrival->time;
1047 * rtp_session_get_internal_source:
1048 * @sess: a #RTPSession
1050 * Get the internal #RTPSource of @sess.
1052 * Returns: The internal #RTPSource. g_object_unref() after usage.
1055 rtp_session_get_internal_source (RTPSession * sess)
1059 g_return_val_if_fail (RTP_IS_SESSION (sess), NULL);
1061 result = g_object_ref (sess->source);
1067 * rtp_session_set_internal_ssrc:
1068 * @sess: a #RTPSession
1071 * Set the SSRC of @sess to @ssrc.
1074 rtp_session_set_internal_ssrc (RTPSession * sess, guint32 ssrc)
1076 RTP_SESSION_LOCK (sess);
1077 g_hash_table_steal (sess->ssrcs[sess->mask_idx],
1078 GINT_TO_POINTER (sess->source->ssrc));
1080 sess->source->ssrc = ssrc;
1081 rtp_source_reset (sess->source);
1083 g_hash_table_insert (sess->ssrcs[sess->mask_idx],
1084 GINT_TO_POINTER (sess->source->ssrc), sess->source);
1085 RTP_SESSION_UNLOCK (sess);
1089 * rtp_session_get_internal_ssrc:
1090 * @sess: a #RTPSession
1092 * Get the internal SSRC of @sess.
1094 * Returns: The SSRC of the session.
1097 rtp_session_get_internal_ssrc (RTPSession * sess)
1101 RTP_SESSION_LOCK (sess);
1102 ssrc = sess->source->ssrc;
1103 RTP_SESSION_UNLOCK (sess);
1109 * rtp_session_add_source:
1110 * @sess: a #RTPSession
1111 * @src: #RTPSource to add
1113 * Add @src to @session.
1115 * Returns: %TRUE on success, %FALSE if a source with the same SSRC already
1116 * existed in the session.
1119 rtp_session_add_source (RTPSession * sess, RTPSource * src)
1121 gboolean result = FALSE;
1124 g_return_val_if_fail (RTP_IS_SESSION (sess), FALSE);
1125 g_return_val_if_fail (src != NULL, FALSE);
1127 RTP_SESSION_LOCK (sess);
1129 g_hash_table_lookup (sess->ssrcs[sess->mask_idx],
1130 GINT_TO_POINTER (src->ssrc));
1132 g_hash_table_insert (sess->ssrcs[sess->mask_idx],
1133 GINT_TO_POINTER (src->ssrc), src);
1134 /* we have one more source now */
1135 sess->total_sources++;
1138 RTP_SESSION_UNLOCK (sess);
1144 * rtp_session_get_num_sources:
1145 * @sess: an #RTPSession
1147 * Get the number of sources in @sess.
1149 * Returns: The number of sources in @sess.
1152 rtp_session_get_num_sources (RTPSession * sess)
1156 g_return_val_if_fail (RTP_IS_SESSION (sess), FALSE);
1158 RTP_SESSION_LOCK (sess);
1159 result = sess->total_sources;
1160 RTP_SESSION_UNLOCK (sess);
1166 * rtp_session_get_num_active_sources:
1167 * @sess: an #RTPSession
1169 * Get the number of active sources in @sess. A source is considered active when
1170 * it has been validated and has not yet received a BYE RTCP message.
1172 * Returns: The number of active sources in @sess.
1175 rtp_session_get_num_active_sources (RTPSession * sess)
1179 g_return_val_if_fail (RTP_IS_SESSION (sess), 0);
1181 RTP_SESSION_LOCK (sess);
1182 result = sess->stats.active_sources;
1183 RTP_SESSION_UNLOCK (sess);
1189 * rtp_session_get_source_by_ssrc:
1190 * @sess: an #RTPSession
1193 * Find the source with @ssrc in @sess.
1195 * Returns: a #RTPSource with SSRC @ssrc or NULL if the source was not found.
1196 * g_object_unref() after usage.
1199 rtp_session_get_source_by_ssrc (RTPSession * sess, guint32 ssrc)
1203 g_return_val_if_fail (RTP_IS_SESSION (sess), NULL);
1205 RTP_SESSION_LOCK (sess);
1207 g_hash_table_lookup (sess->ssrcs[sess->mask_idx], GINT_TO_POINTER (ssrc));
1209 g_object_ref (result);
1210 RTP_SESSION_UNLOCK (sess);
1216 * rtp_session_get_source_by_cname:
1217 * @sess: a #RTPSession
1220 * Find the source with @cname in @sess.
1222 * Returns: a #RTPSource with CNAME @cname or NULL if the source was not found.
1223 * g_object_unref() after usage.
1226 rtp_session_get_source_by_cname (RTPSession * sess, const gchar * cname)
1230 g_return_val_if_fail (RTP_IS_SESSION (sess), NULL);
1231 g_return_val_if_fail (cname != NULL, NULL);
1233 RTP_SESSION_LOCK (sess);
1234 result = g_hash_table_lookup (sess->cnames, cname);
1236 g_object_ref (result);
1237 RTP_SESSION_UNLOCK (sess);
1243 rtp_session_create_new_ssrc (RTPSession * sess)
1248 ssrc = g_random_int ();
1250 /* see if it exists in the session, we're done if it doesn't */
1251 if (g_hash_table_lookup (sess->ssrcs[sess->mask_idx],
1252 GINT_TO_POINTER (ssrc)) == NULL)
1261 * rtp_session_create_source:
1262 * @sess: an #RTPSession
1264 * Create an #RTPSource for use in @sess. This function will create a source
1265 * with an ssrc that is currently not used by any participants in the session.
1267 * Returns: an #RTPSource.
1270 rtp_session_create_source (RTPSession * sess)
1275 RTP_SESSION_LOCK (sess);
1276 ssrc = rtp_session_create_new_ssrc (sess);
1277 source = rtp_source_new (ssrc);
1278 g_object_ref (source);
1279 rtp_source_set_callbacks (source, &callbacks, sess);
1280 g_hash_table_insert (sess->ssrcs[sess->mask_idx], GINT_TO_POINTER (ssrc),
1282 /* we have one more source now */
1283 sess->total_sources++;
1284 RTP_SESSION_UNLOCK (sess);
1289 /* update the RTPArrivalStats structure with the current time and other bits
1290 * about the current buffer we are handling.
1291 * This function is typically called when a validated packet is received.
1292 * This function should be called with the SESSION_LOCK
1295 update_arrival_stats (RTPSession * sess, RTPArrivalStats * arrival,
1296 gboolean rtp, GstBuffer * buffer, GstClockTime current_time,
1299 /* get time of arrival */
1300 arrival->time = current_time;
1301 arrival->timestamp = GST_BUFFER_TIMESTAMP (buffer);
1302 arrival->ntpnstime = ntpnstime;
1304 /* get packet size including header overhead */
1305 arrival->bytes = GST_BUFFER_SIZE (buffer) + sess->header_len;
1308 arrival->payload_len = gst_rtp_buffer_get_payload_len (buffer);
1310 arrival->payload_len = 0;
1313 /* for netbuffer we can store the IP address to check for collisions */
1314 arrival->have_address = GST_IS_NETBUFFER (buffer);
1315 if (arrival->have_address) {
1316 GstNetBuffer *netbuf = (GstNetBuffer *) buffer;
1318 memcpy (&arrival->address, &netbuf->from, sizeof (GstNetAddress));
1323 * rtp_session_process_rtp:
1324 * @sess: and #RTPSession
1325 * @buffer: an RTP buffer
1326 * @current_time: the current system time
1327 * @ntpnstime: the NTP arrival time in nanoseconds
1329 * Process an RTP buffer in the session manager. This function takes ownership
1332 * Returns: a #GstFlowReturn.
1335 rtp_session_process_rtp (RTPSession * sess, GstBuffer * buffer,
1336 GstClockTime current_time, guint64 ntpnstime)
1338 GstFlowReturn result;
1342 gboolean prevsender, prevactive;
1343 RTPArrivalStats arrival;
1345 g_return_val_if_fail (RTP_IS_SESSION (sess), GST_FLOW_ERROR);
1346 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
1348 if (!gst_rtp_buffer_validate (buffer))
1349 goto invalid_packet;
1351 RTP_SESSION_LOCK (sess);
1352 /* update arrival stats */
1353 update_arrival_stats (sess, &arrival, TRUE, buffer, current_time, ntpnstime);
1355 /* ignore more RTP packets when we left the session */
1356 if (sess->source->received_bye)
1359 /* get SSRC and look up in session database */
1360 ssrc = gst_rtp_buffer_get_ssrc (buffer);
1361 source = obtain_source (sess, ssrc, &created, &arrival, TRUE);
1366 prevsender = RTP_SOURCE_IS_SENDER (source);
1367 prevactive = RTP_SOURCE_IS_ACTIVE (source);
1369 /* we need to ref so that we can process the CSRCs later */
1370 gst_buffer_ref (buffer);
1372 /* let source process the packet */
1373 result = rtp_source_process_rtp (source, buffer, &arrival);
1375 /* source became active */
1376 if (prevactive != RTP_SOURCE_IS_ACTIVE (source)) {
1377 sess->stats.active_sources++;
1378 GST_DEBUG ("source: %08x became active, %d active sources", ssrc,
1379 sess->stats.active_sources);
1380 on_ssrc_validated (sess, source);
1382 if (prevsender != RTP_SOURCE_IS_SENDER (source)) {
1383 sess->stats.sender_sources++;
1384 GST_DEBUG ("source: %08x became sender, %d sender sources", ssrc,
1385 sess->stats.sender_sources);
1389 on_new_ssrc (sess, source);
1391 if (source->validated) {
1395 /* for validated sources, we add the CSRCs as well */
1396 count = gst_rtp_buffer_get_csrc_count (buffer);
1398 for (i = 0; i < count; i++) {
1400 RTPSource *csrc_src;
1402 csrc = gst_rtp_buffer_get_csrc (buffer, i);
1405 csrc_src = obtain_source (sess, csrc, &created, &arrival, TRUE);
1408 GST_DEBUG ("created new CSRC: %08x", csrc);
1409 rtp_source_set_as_csrc (csrc_src);
1410 if (RTP_SOURCE_IS_ACTIVE (csrc_src))
1411 sess->stats.active_sources++;
1412 on_new_ssrc (sess, source);
1416 gst_buffer_unref (buffer);
1418 RTP_SESSION_UNLOCK (sess);
1425 gst_buffer_unref (buffer);
1426 GST_DEBUG ("invalid RTP packet received");
1431 gst_buffer_unref (buffer);
1432 RTP_SESSION_UNLOCK (sess);
1433 GST_DEBUG ("ignoring RTP packet because we are leaving");
1438 gst_buffer_unref (buffer);
1439 RTP_SESSION_UNLOCK (sess);
1440 GST_DEBUG ("ignoring packet because its collisioning");
1446 rtp_session_process_rb (RTPSession * sess, RTPSource * source,
1447 GstRTCPPacket * packet, RTPArrivalStats * arrival)
1451 count = gst_rtcp_packet_get_rb_count (packet);
1452 for (i = 0; i < count; i++) {
1453 guint32 ssrc, exthighestseq, jitter, lsr, dlsr;
1454 guint8 fractionlost;
1457 gst_rtcp_packet_get_rb (packet, i, &ssrc, &fractionlost,
1458 &packetslost, &exthighestseq, &jitter, &lsr, &dlsr);
1460 GST_DEBUG ("RB %d: SSRC %08x, jitter %" G_GUINT32_FORMAT, i, ssrc, jitter);
1462 if (ssrc == sess->source->ssrc) {
1463 /* only deal with report blocks for our session, we update the stats of
1464 * the sender of the RTCP message. We could also compare our stats against
1465 * the other sender to see if we are better or worse. */
1466 rtp_source_process_rb (source, arrival->time, fractionlost, packetslost,
1467 exthighestseq, jitter, lsr, dlsr);
1469 on_ssrc_active (sess, source);
1474 /* A Sender report contains statistics about how the sender is doing. This
1475 * includes timing informataion such as the relation between RTP and NTP
1476 * timestamps and the number of packets/bytes it sent to us.
1478 * In this report is also included a set of report blocks related to how this
1479 * sender is receiving data (in case we (or somebody else) is also sending stuff
1480 * to it). This info includes the packet loss, jitter and seqnum. It also
1481 * contains information to calculate the round trip time (LSR/DLSR).
1484 rtp_session_process_sr (RTPSession * sess, GstRTCPPacket * packet,
1485 RTPArrivalStats * arrival)
1487 guint32 senderssrc, rtptime, packet_count, octet_count;
1490 gboolean created, prevsender;
1492 gst_rtcp_packet_sr_get_sender_info (packet, &senderssrc, &ntptime, &rtptime,
1493 &packet_count, &octet_count);
1495 GST_DEBUG ("got SR packet: SSRC %08x, time %" GST_TIME_FORMAT,
1496 senderssrc, GST_TIME_ARGS (arrival->time));
1498 source = obtain_source (sess, senderssrc, &created, arrival, FALSE);
1503 prevsender = RTP_SOURCE_IS_SENDER (source);
1505 /* first update the source */
1506 rtp_source_process_sr (source, arrival->time, ntptime, rtptime, packet_count,
1509 if (prevsender != RTP_SOURCE_IS_SENDER (source)) {
1510 sess->stats.sender_sources++;
1511 GST_DEBUG ("source: %08x became sender, %d sender sources", senderssrc,
1512 sess->stats.sender_sources);
1516 on_new_ssrc (sess, source);
1518 rtp_session_process_rb (sess, source, packet, arrival);
1521 /* A receiver report contains statistics about how a receiver is doing. It
1522 * includes stuff like packet loss, jitter and the seqnum it received last. It
1523 * also contains info to calculate the round trip time.
1525 * We are only interested in how the sender of this report is doing wrt to us.
1528 rtp_session_process_rr (RTPSession * sess, GstRTCPPacket * packet,
1529 RTPArrivalStats * arrival)
1535 senderssrc = gst_rtcp_packet_rr_get_ssrc (packet);
1537 GST_DEBUG ("got RR packet: SSRC %08x", senderssrc);
1539 source = obtain_source (sess, senderssrc, &created, arrival, FALSE);
1545 on_new_ssrc (sess, source);
1547 rtp_session_process_rb (sess, source, packet, arrival);
1550 /* Get SDES items and store them in the SSRC */
1552 rtp_session_process_sdes (RTPSession * sess, GstRTCPPacket * packet,
1553 RTPArrivalStats * arrival)
1556 gboolean more_items, more_entries;
1558 items = gst_rtcp_packet_sdes_get_item_count (packet);
1559 GST_DEBUG ("got SDES packet with %d items", items);
1561 more_items = gst_rtcp_packet_sdes_first_item (packet);
1563 while (more_items) {
1565 gboolean changed, created;
1568 ssrc = gst_rtcp_packet_sdes_get_ssrc (packet);
1570 GST_DEBUG ("item %d, SSRC %08x", i, ssrc);
1572 /* find src, no probation when dealing with RTCP */
1573 source = obtain_source (sess, ssrc, &created, arrival, FALSE);
1579 more_entries = gst_rtcp_packet_sdes_first_entry (packet);
1581 while (more_entries) {
1582 GstRTCPSDESType type;
1586 gst_rtcp_packet_sdes_get_entry (packet, &type, &len, &data);
1588 GST_DEBUG ("entry %d, type %d, len %d, data %.*s", j, type, len, len,
1591 changed |= rtp_source_set_sdes (source, type, data, len);
1593 more_entries = gst_rtcp_packet_sdes_next_entry (packet);
1598 on_new_ssrc (sess, source);
1600 on_ssrc_sdes (sess, source);
1602 more_items = gst_rtcp_packet_sdes_next_item (packet);
1607 /* BYE is sent when a client leaves the session
1610 rtp_session_process_bye (RTPSession * sess, GstRTCPPacket * packet,
1611 RTPArrivalStats * arrival)
1616 reason = gst_rtcp_packet_bye_get_reason (packet);
1617 GST_DEBUG ("got BYE packet (reason: %s)", GST_STR_NULL (reason));
1619 count = gst_rtcp_packet_bye_get_ssrc_count (packet);
1620 for (i = 0; i < count; i++) {
1623 gboolean created, prevactive, prevsender;
1624 guint pmembers, members;
1626 ssrc = gst_rtcp_packet_bye_get_nth_ssrc (packet, i);
1627 GST_DEBUG ("SSRC: %08x", ssrc);
1629 /* find src and mark bye, no probation when dealing with RTCP */
1630 source = obtain_source (sess, ssrc, &created, arrival, FALSE);
1635 /* store time for when we need to time out this source */
1636 source->bye_time = arrival->time;
1638 prevactive = RTP_SOURCE_IS_ACTIVE (source);
1639 prevsender = RTP_SOURCE_IS_SENDER (source);
1641 /* let the source handle the rest */
1642 rtp_source_process_bye (source, reason);
1644 pmembers = sess->stats.active_sources;
1646 if (prevactive && !RTP_SOURCE_IS_ACTIVE (source)) {
1647 sess->stats.active_sources--;
1648 GST_DEBUG ("source: %08x became inactive, %d active sources", ssrc,
1649 sess->stats.active_sources);
1651 if (prevsender && !RTP_SOURCE_IS_SENDER (source)) {
1652 sess->stats.sender_sources--;
1653 GST_DEBUG ("source: %08x became non sender, %d sender sources", ssrc,
1654 sess->stats.sender_sources);
1656 members = sess->stats.active_sources;
1658 if (!sess->source->received_bye && members < pmembers) {
1659 /* some members went away since the previous timeout estimate.
1660 * Perform reverse reconsideration but only when we are not scheduling a
1662 if (arrival->time < sess->next_rtcp_check_time) {
1663 GstClockTime time_remaining;
1665 time_remaining = sess->next_rtcp_check_time - arrival->time;
1666 sess->next_rtcp_check_time =
1667 gst_util_uint64_scale (time_remaining, members, pmembers);
1669 GST_DEBUG ("reverse reconsideration %" GST_TIME_FORMAT,
1670 GST_TIME_ARGS (sess->next_rtcp_check_time));
1672 sess->next_rtcp_check_time += arrival->time;
1674 RTP_SESSION_UNLOCK (sess);
1675 /* notify app of reconsideration */
1676 if (sess->callbacks.reconsider)
1677 sess->callbacks.reconsider (sess, sess->reconsider_user_data);
1678 RTP_SESSION_LOCK (sess);
1683 on_new_ssrc (sess, source);
1685 on_bye_ssrc (sess, source);
1691 rtp_session_process_app (RTPSession * sess, GstRTCPPacket * packet,
1692 RTPArrivalStats * arrival)
1694 GST_DEBUG ("received APP");
1698 * rtp_session_process_rtcp:
1699 * @sess: and #RTPSession
1700 * @buffer: an RTCP buffer
1701 * @current_time: the current system time
1703 * Process an RTCP buffer in the session manager. This function takes ownership
1706 * Returns: a #GstFlowReturn.
1709 rtp_session_process_rtcp (RTPSession * sess, GstBuffer * buffer,
1710 GstClockTime current_time)
1712 GstRTCPPacket packet;
1713 gboolean more, is_bye = FALSE, is_sr = FALSE;
1714 RTPArrivalStats arrival;
1715 GstFlowReturn result = GST_FLOW_OK;
1717 g_return_val_if_fail (RTP_IS_SESSION (sess), GST_FLOW_ERROR);
1718 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
1720 if (!gst_rtcp_buffer_validate (buffer))
1721 goto invalid_packet;
1723 GST_DEBUG ("received RTCP packet");
1725 RTP_SESSION_LOCK (sess);
1726 /* update arrival stats */
1727 update_arrival_stats (sess, &arrival, FALSE, buffer, current_time, -1);
1732 /* make writable, we might want to change the buffer */
1733 buffer = gst_buffer_make_metadata_writable (buffer);
1735 /* start processing the compound packet */
1736 more = gst_rtcp_buffer_get_first_packet (buffer, &packet);
1740 type = gst_rtcp_packet_get_type (&packet);
1742 /* when we are leaving the session, we should ignore all non-BYE messages */
1743 if (sess->source->received_bye && type != GST_RTCP_TYPE_BYE) {
1744 GST_DEBUG ("ignoring non-BYE RTCP packet because we are leaving");
1749 case GST_RTCP_TYPE_SR:
1750 rtp_session_process_sr (sess, &packet, &arrival);
1753 case GST_RTCP_TYPE_RR:
1754 rtp_session_process_rr (sess, &packet, &arrival);
1756 case GST_RTCP_TYPE_SDES:
1757 rtp_session_process_sdes (sess, &packet, &arrival);
1759 case GST_RTCP_TYPE_BYE:
1761 rtp_session_process_bye (sess, &packet, &arrival);
1763 case GST_RTCP_TYPE_APP:
1764 rtp_session_process_app (sess, &packet, &arrival);
1767 GST_WARNING ("got unknown RTCP packet");
1771 more = gst_rtcp_packet_move_to_next (&packet);
1774 /* if we are scheduling a BYE, we only want to count bye packets, else we
1775 * count everything */
1776 if (sess->source->received_bye) {
1778 sess->stats.bye_members++;
1779 UPDATE_AVG (sess->stats.avg_rtcp_packet_size, arrival.bytes);
1782 /* keep track of average packet size */
1783 UPDATE_AVG (sess->stats.avg_rtcp_packet_size, arrival.bytes);
1785 RTP_SESSION_UNLOCK (sess);
1787 /* notify caller of sr packets in the callback */
1788 if (is_sr && sess->callbacks.sync_rtcp)
1789 result = sess->callbacks.sync_rtcp (sess, sess->source, buffer,
1790 sess->sync_rtcp_user_data);
1792 gst_buffer_unref (buffer);
1799 GST_DEBUG ("invalid RTCP packet received");
1800 gst_buffer_unref (buffer);
1805 gst_buffer_unref (buffer);
1806 RTP_SESSION_UNLOCK (sess);
1807 GST_DEBUG ("ignoring RTP packet because we left");
1813 * rtp_session_send_rtp:
1814 * @sess: an #RTPSession
1815 * @buffer: an RTP buffer
1816 * @current_time: the current system time
1817 * @ntpnstime: the NTP time in nanoseconds of when this buffer was captured.
1818 * This is the buffer timestamp converted to NTP time.
1820 * Send the RTP buffer in the session manager. This function takes ownership of
1823 * Returns: a #GstFlowReturn.
1826 rtp_session_send_rtp (RTPSession * sess, GstBuffer * buffer,
1827 GstClockTime current_time, guint64 ntpnstime)
1829 GstFlowReturn result;
1831 gboolean prevsender;
1833 g_return_val_if_fail (RTP_IS_SESSION (sess), GST_FLOW_ERROR);
1834 g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
1836 if (!gst_rtp_buffer_validate (buffer))
1837 goto invalid_packet;
1839 GST_LOG ("received RTP packet for sending");
1841 RTP_SESSION_LOCK (sess);
1842 source = sess->source;
1844 /* update last activity */
1845 source->last_rtp_activity = current_time;
1847 prevsender = RTP_SOURCE_IS_SENDER (source);
1849 /* we use our own source to send */
1850 result = rtp_source_send_rtp (source, buffer, ntpnstime);
1852 if (RTP_SOURCE_IS_SENDER (source) && !prevsender)
1853 sess->stats.sender_sources++;
1854 RTP_SESSION_UNLOCK (sess);
1861 gst_buffer_unref (buffer);
1862 GST_DEBUG ("invalid RTP packet received");
1868 calculate_rtcp_interval (RTPSession * sess, gboolean deterministic,
1871 GstClockTime result;
1873 if (sess->source->received_bye) {
1874 result = rtp_stats_calculate_bye_interval (&sess->stats);
1876 result = rtp_stats_calculate_rtcp_interval (&sess->stats,
1877 RTP_SOURCE_IS_SENDER (sess->source), first);
1880 GST_DEBUG ("next deterministic interval: %" GST_TIME_FORMAT ", first %d",
1881 GST_TIME_ARGS (result), first);
1884 result = rtp_stats_add_rtcp_jitter (&sess->stats, result);
1886 GST_DEBUG ("next interval: %" GST_TIME_FORMAT, GST_TIME_ARGS (result));
1892 * rtp_session_send_bye_locked:
1893 * @sess: an #RTPSession
1894 * @reason: a reason or NULL
1896 * Stop the current @sess and schedule a BYE message for the other members.
1898 * One must have the session lock to call this function
1900 * Returns: a #GstFlowReturn.
1902 static GstFlowReturn
1903 rtp_session_send_bye_locked (RTPSession * sess, const gchar * reason,
1904 GstClockTime current_time)
1906 GstFlowReturn result = GST_FLOW_OK;
1908 GstClockTime interval;
1910 g_return_val_if_fail (RTP_IS_SESSION (sess), GST_FLOW_ERROR);
1912 source = sess->source;
1914 /* ignore more BYEs */
1915 if (source->received_bye)
1918 /* we have BYE now */
1919 source->received_bye = TRUE;
1920 /* at least one member wants to send a BYE */
1921 g_free (sess->bye_reason);
1922 sess->bye_reason = g_strdup (reason);
1923 sess->stats.avg_rtcp_packet_size = 100;
1924 sess->stats.bye_members = 1;
1925 sess->first_rtcp = TRUE;
1926 sess->sent_bye = FALSE;
1928 /* reschedule transmission */
1929 sess->last_rtcp_send_time = current_time;
1930 interval = calculate_rtcp_interval (sess, FALSE, TRUE);
1931 sess->next_rtcp_check_time = current_time + interval;
1933 GST_DEBUG ("Schedule BYE for %" GST_TIME_FORMAT ", %" GST_TIME_FORMAT,
1934 GST_TIME_ARGS (interval), GST_TIME_ARGS (sess->next_rtcp_check_time));
1936 RTP_SESSION_UNLOCK (sess);
1937 /* notify app of reconsideration */
1938 if (sess->callbacks.reconsider)
1939 sess->callbacks.reconsider (sess, sess->reconsider_user_data);
1940 RTP_SESSION_LOCK (sess);
1947 * rtp_session_send_bye:
1948 * @sess: an #RTPSession
1949 * @reason: a reason or NULL
1950 * @current_time: the current system time
1952 * Stop the current @sess and schedule a BYE message for the other members.
1954 * One must have the session lock to call this function
1956 * Returns: a #GstFlowReturn.
1959 rtp_session_send_bye (RTPSession * sess, const gchar * reason,
1960 GstClockTime current_time)
1962 GstFlowReturn result = GST_FLOW_OK;
1964 g_return_val_if_fail (RTP_IS_SESSION (sess), GST_FLOW_ERROR);
1966 RTP_SESSION_LOCK (sess);
1967 result = rtp_session_send_bye_locked (sess, reason, current_time);
1968 RTP_SESSION_UNLOCK (sess);
1974 * rtp_session_next_timeout:
1975 * @sess: an #RTPSession
1976 * @current_time: the current system time
1978 * Get the next time we should perform session maintenance tasks.
1980 * Returns: a time when rtp_session_on_timeout() should be called with the
1981 * current system time.
1984 rtp_session_next_timeout (RTPSession * sess, GstClockTime current_time)
1986 GstClockTime result;
1988 g_return_val_if_fail (RTP_IS_SESSION (sess), GST_FLOW_ERROR);
1990 RTP_SESSION_LOCK (sess);
1992 result = sess->next_rtcp_check_time;
1994 GST_DEBUG ("current time: %" GST_TIME_FORMAT ", next :%" GST_TIME_FORMAT,
1995 GST_TIME_ARGS (current_time), GST_TIME_ARGS (result));
1997 if (result < current_time) {
1998 GST_DEBUG ("take current time as base");
1999 /* our previous check time expired, start counting from the current time
2001 result = current_time;
2004 if (sess->source->received_bye) {
2005 if (sess->sent_bye) {
2006 GST_DEBUG ("we sent BYE already");
2007 result = GST_CLOCK_TIME_NONE;
2008 } else if (sess->stats.active_sources >= 50) {
2009 GST_DEBUG ("reconsider BYE, more than 50 sources");
2010 /* reconsider BYE if members >= 50 */
2011 result += calculate_rtcp_interval (sess, FALSE, TRUE);
2014 if (sess->first_rtcp) {
2015 GST_DEBUG ("first RTCP packet");
2016 /* we are called for the first time */
2017 result += calculate_rtcp_interval (sess, FALSE, TRUE);
2018 } else if (sess->next_rtcp_check_time < current_time) {
2019 GST_DEBUG ("old check time expired, getting new timeout");
2020 /* get a new timeout when we need to */
2021 result += calculate_rtcp_interval (sess, FALSE, FALSE);
2024 sess->next_rtcp_check_time = result;
2026 GST_DEBUG ("next timeout: %" GST_TIME_FORMAT, GST_TIME_ARGS (result));
2027 RTP_SESSION_UNLOCK (sess);
2036 GstClockTime current_time;
2038 GstClockTime interval;
2039 GstRTCPPacket packet;
2045 session_start_rtcp (RTPSession * sess, ReportData * data)
2047 GstRTCPPacket *packet = &data->packet;
2048 RTPSource *own = sess->source;
2050 data->rtcp = gst_rtcp_buffer_new (sess->mtu);
2052 if (RTP_SOURCE_IS_SENDER (own)) {
2055 guint32 packet_count, octet_count;
2057 /* we are a sender, create SR */
2058 GST_DEBUG ("create SR for SSRC %08x", own->ssrc);
2059 gst_rtcp_buffer_add_packet (data->rtcp, GST_RTCP_TYPE_SR, packet);
2061 /* get latest stats */
2062 rtp_source_get_new_sr (own, data->ntpnstime, &ntptime, &rtptime,
2063 &packet_count, &octet_count);
2065 rtp_source_process_sr (own, data->ntpnstime, ntptime, rtptime, packet_count,
2068 /* fill in sender report info */
2069 gst_rtcp_packet_sr_set_sender_info (packet, own->ssrc,
2070 ntptime, rtptime, packet_count, octet_count);
2072 /* we are only receiver, create RR */
2073 GST_DEBUG ("create RR for SSRC %08x", own->ssrc);
2074 gst_rtcp_buffer_add_packet (data->rtcp, GST_RTCP_TYPE_RR, packet);
2075 gst_rtcp_packet_rr_set_ssrc (packet, own->ssrc);
2079 /* construct a Sender or Receiver Report */
2081 session_report_blocks (const gchar * key, RTPSource * source, ReportData * data)
2083 RTPSession *sess = data->sess;
2084 GstRTCPPacket *packet = &data->packet;
2086 /* create a new buffer if needed */
2087 if (data->rtcp == NULL) {
2088 session_start_rtcp (sess, data);
2090 if (gst_rtcp_packet_get_rb_count (packet) < GST_RTCP_MAX_RB_COUNT) {
2091 /* only report about other sender sources */
2092 if (source != sess->source && RTP_SOURCE_IS_SENDER (source)) {
2093 guint8 fractionlost;
2095 guint32 exthighestseq, jitter;
2099 rtp_source_get_new_rb (source, data->current_time, &fractionlost,
2100 &packetslost, &exthighestseq, &jitter, &lsr, &dlsr);
2102 /* packet is not yet filled, add report block for this source. */
2103 gst_rtcp_packet_add_rb (packet, source->ssrc, fractionlost, packetslost,
2104 exthighestseq, jitter, lsr, dlsr);
2109 /* perform cleanup of sources that timed out */
2111 session_cleanup (const gchar * key, RTPSource * source, ReportData * data)
2113 gboolean remove = FALSE;
2114 gboolean byetimeout = FALSE;
2115 gboolean sendertimeout = FALSE;
2116 gboolean is_sender, is_active;
2117 RTPSession *sess = data->sess;
2118 GstClockTime interval;
2120 is_sender = RTP_SOURCE_IS_SENDER (source);
2121 is_active = RTP_SOURCE_IS_ACTIVE (source);
2123 /* check for our own source, we don't want to delete our own source. */
2124 if (!(source == sess->source)) {
2125 if (source->received_bye) {
2126 /* if we received a BYE from the source, remove the source after some
2128 if (data->current_time > source->bye_time &&
2129 data->current_time - source->bye_time > sess->stats.bye_timeout) {
2130 GST_DEBUG ("removing BYE source %08x", source->ssrc);
2135 /* sources that were inactive for more than 5 times the deterministic reporting
2136 * interval get timed out. the min timeout is 5 seconds. */
2137 if (data->current_time > source->last_activity) {
2138 interval = MAX (data->interval * 5, 5 * GST_SECOND);
2139 if (data->current_time - source->last_activity > interval) {
2140 GST_DEBUG ("removing timeout source %08x, last %" GST_TIME_FORMAT,
2141 source->ssrc, GST_TIME_ARGS (source->last_activity));
2147 /* senders that did not send for a long time become a receiver, this also
2148 * holds for our own source. */
2150 if (data->current_time > source->last_rtp_activity) {
2151 interval = MAX (data->interval * 2, 5 * GST_SECOND);
2152 if (data->current_time - source->last_rtp_activity > interval) {
2153 GST_DEBUG ("sender source %08x timed out and became receiver, last %"
2154 GST_TIME_FORMAT, source->ssrc,
2155 GST_TIME_ARGS (source->last_rtp_activity));
2156 source->is_sender = FALSE;
2157 sess->stats.sender_sources--;
2158 sendertimeout = TRUE;
2164 sess->total_sources--;
2166 sess->stats.sender_sources--;
2168 sess->stats.active_sources--;
2171 on_bye_timeout (sess, source);
2173 on_timeout (sess, source);
2176 on_sender_timeout (sess, source);
2182 session_sdes (RTPSession * sess, ReportData * data)
2184 GstRTCPPacket *packet = &data->packet;
2188 /* add SDES packet */
2189 gst_rtcp_buffer_add_packet (data->rtcp, GST_RTCP_TYPE_SDES, packet);
2191 gst_rtcp_packet_sdes_add_item (packet, sess->source->ssrc);
2193 rtp_source_get_sdes (sess->source, GST_RTCP_SDES_CNAME, &sdes_data,
2195 gst_rtcp_packet_sdes_add_entry (packet, GST_RTCP_SDES_CNAME, sdes_len,
2198 /* other SDES items must only be added at regular intervals and only when the
2199 * user requests to since it might be a privacy problem */
2201 gst_rtcp_packet_sdes_add_entry (&packet, GST_RTCP_SDES_NAME,
2202 strlen (sess->name), (guint8 *) sess->name);
2203 gst_rtcp_packet_sdes_add_entry (&packet, GST_RTCP_SDES_TOOL,
2204 strlen (sess->tool), (guint8 *) sess->tool);
2207 data->has_sdes = TRUE;
2210 /* schedule a BYE packet */
2212 session_bye (RTPSession * sess, ReportData * data)
2214 GstRTCPPacket *packet = &data->packet;
2217 session_start_rtcp (sess, data);
2220 session_sdes (sess, data);
2222 /* add a BYE packet */
2223 gst_rtcp_buffer_add_packet (data->rtcp, GST_RTCP_TYPE_BYE, packet);
2224 gst_rtcp_packet_bye_add_ssrc (packet, sess->source->ssrc);
2225 if (sess->bye_reason)
2226 gst_rtcp_packet_bye_set_reason (packet, sess->bye_reason);
2228 /* we have a BYE packet now */
2229 data->is_bye = TRUE;
2233 is_rtcp_time (RTPSession * sess, GstClockTime current_time, ReportData * data)
2235 GstClockTime new_send_time, elapsed;
2238 /* no need to check yet */
2239 if (sess->next_rtcp_check_time > current_time) {
2240 GST_DEBUG ("no check time yet, next %" GST_TIME_FORMAT " > now %"
2241 GST_TIME_FORMAT, GST_TIME_ARGS (sess->next_rtcp_check_time),
2242 GST_TIME_ARGS (current_time));
2246 /* get elapsed time since we last reported */
2247 elapsed = current_time - sess->last_rtcp_send_time;
2249 /* perform forward reconsideration */
2250 new_send_time = rtp_stats_add_rtcp_jitter (&sess->stats, data->interval);
2252 GST_DEBUG ("forward reconsideration %" GST_TIME_FORMAT ", elapsed %"
2253 GST_TIME_FORMAT, GST_TIME_ARGS (new_send_time), GST_TIME_ARGS (elapsed));
2255 new_send_time += sess->last_rtcp_send_time;
2257 /* check if reconsideration */
2258 if (current_time < new_send_time) {
2259 GST_DEBUG ("reconsider RTCP for %" GST_TIME_FORMAT,
2260 GST_TIME_ARGS (new_send_time));
2262 /* store new check time */
2263 sess->next_rtcp_check_time = new_send_time;
2266 new_send_time = calculate_rtcp_interval (sess, FALSE, FALSE);
2268 GST_DEBUG ("can send RTCP now, next interval %" GST_TIME_FORMAT,
2269 GST_TIME_ARGS (new_send_time));
2270 sess->next_rtcp_check_time = current_time + new_send_time;
2276 * rtp_session_on_timeout:
2277 * @sess: an #RTPSession
2278 * @current_time: the current system time
2279 * @ntpnstime: the current NTP time in nanoseconds
2281 * Perform maintenance actions after the timeout obtained with
2282 * rtp_session_next_timeout() expired.
2284 * This function will perform timeouts of receivers and senders, send a BYE
2285 * packet or generate RTCP packets with current session stats.
2287 * This function can call the #RTPSessionSendRTCP callback, possibly multiple
2288 * times, for each packet that should be processed.
2290 * Returns: a #GstFlowReturn.
2293 rtp_session_on_timeout (RTPSession * sess, GstClockTime current_time,
2296 GstFlowReturn result = GST_FLOW_OK;
2300 g_return_val_if_fail (RTP_IS_SESSION (sess), GST_FLOW_ERROR);
2302 GST_DEBUG ("reporting at %" GST_TIME_FORMAT ", NTP time %" GST_TIME_FORMAT,
2303 GST_TIME_ARGS (current_time), GST_TIME_ARGS (ntpnstime));
2307 data.current_time = current_time;
2308 data.ntpnstime = ntpnstime;
2309 data.is_bye = FALSE;
2310 data.has_sdes = FALSE;
2312 RTP_SESSION_LOCK (sess);
2313 /* get a new interval, we need this for various cleanups etc */
2314 data.interval = calculate_rtcp_interval (sess, TRUE, sess->first_rtcp);
2316 /* first perform cleanups */
2317 g_hash_table_foreach_remove (sess->ssrcs[sess->mask_idx],
2318 (GHRFunc) session_cleanup, &data);
2320 /* see if we need to generate SR or RR packets */
2321 if (is_rtcp_time (sess, current_time, &data)) {
2322 if (sess->source->received_bye) {
2323 /* generate BYE instead */
2324 GST_DEBUG ("generating BYE message");
2325 session_bye (sess, &data);
2326 sess->sent_bye = TRUE;
2328 /* loop over all known sources and do something */
2329 g_hash_table_foreach (sess->ssrcs[sess->mask_idx],
2330 (GHFunc) session_report_blocks, &data);
2337 /* we keep track of the last report time in order to timeout inactive
2338 * receivers or senders */
2339 sess->last_rtcp_send_time = data.current_time;
2340 sess->first_rtcp = FALSE;
2342 /* add SDES for this source when not already added */
2344 session_sdes (sess, &data);
2346 /* update average RTCP size before sending */
2347 size = GST_BUFFER_SIZE (data.rtcp) + sess->header_len;
2348 UPDATE_AVG (sess->stats.avg_rtcp_packet_size, size);
2351 /* check for outdated collisions */
2352 GST_DEBUG ("checking collision list");
2353 item = g_list_first (sess->conflicting_addresses);
2355 RTPConflictingAddress *known_conflict = item->data;
2356 GList *next_item = g_list_next (item);
2358 if (known_conflict->time < current_time - (data.interval *
2359 RTCP_INTERVAL_COLLISION_TIMEOUT)) {
2360 sess->conflicting_addresses =
2361 g_list_delete_link (sess->conflicting_addresses, item);
2362 GST_DEBUG ("collision %p timed out", known_conflict);
2363 g_free (known_conflict);
2368 if (sess->change_ssrc) {
2369 GST_DEBUG ("need to change our SSRC (%08x)", sess->source->ssrc);
2370 g_hash_table_steal (sess->ssrcs[sess->mask_idx],
2371 GINT_TO_POINTER (sess->source->ssrc));
2373 sess->source->ssrc = rtp_session_create_new_ssrc (sess);
2374 rtp_source_reset (sess->source);
2376 g_hash_table_insert (sess->ssrcs[sess->mask_idx],
2377 GINT_TO_POINTER (sess->source->ssrc), sess->source);
2379 g_free (sess->bye_reason);
2380 sess->bye_reason = NULL;
2381 sess->sent_bye = FALSE;
2382 sess->change_ssrc = FALSE;
2383 GST_DEBUG ("changed our SSRC to %08x", sess->source->ssrc);
2385 RTP_SESSION_UNLOCK (sess);
2387 /* push out the RTCP packet */
2389 /* close the RTCP packet */
2390 gst_rtcp_buffer_end (data.rtcp);
2392 GST_DEBUG ("sending packet");
2393 if (sess->callbacks.send_rtcp)
2394 result = sess->callbacks.send_rtcp (sess, sess->source, data.rtcp,
2395 sess->sent_bye, sess->send_rtcp_user_data);
2397 GST_DEBUG ("freeing packet");
2398 gst_buffer_unref (data.rtcp);