Merge branch 'master' into 0.11
[platform/upstream/gst-plugins-good.git] / gst / rtpmanager / rtpsource.c
index 2912708..611cca7 100644 (file)
@@ -230,7 +230,7 @@ rtp_source_init (RTPSource * src)
   src->probation = RTP_DEFAULT_PROBATION;
   src->closing = FALSE;
 
-  src->sdes = gst_structure_new ("application/x-rtp-source-sdes", NULL);
+  src->sdes = gst_structure_new_empty ("application/x-rtp-source-sdes");
 
   src->payload = -1;
   src->clock_rate = -1;
@@ -244,6 +244,13 @@ rtp_source_init (RTPSource * src)
 }
 
 static void
+rtp_conflicting_address_free (RTPConflictingAddress * addr)
+{
+  g_object_unref (addr->address);
+  g_free (addr);
+}
+
+static void
 rtp_source_finalize (GObject * object)
 {
   RTPSource *src;
@@ -261,13 +268,19 @@ rtp_source_finalize (GObject * object)
 
   gst_caps_replace (&src->caps, NULL);
 
-  g_list_foreach (src->conflicting_addresses, (GFunc) g_free, NULL);
+  g_list_foreach (src->conflicting_addresses,
+      (GFunc) rtp_conflicting_address_free, NULL);
   g_list_free (src->conflicting_addresses);
 
   while ((buffer = g_queue_pop_head (src->retained_feedback)))
     gst_buffer_unref (buffer);
   g_queue_free (src->retained_feedback);
 
+  if (src->rtp_from)
+    g_object_unref (src->rtp_from);
+  if (src->rtcp_from)
+    g_object_unref (src->rtcp_from);
+
   G_OBJECT_CLASS (rtp_source_parent_class)->finalize (object);
 }
 
@@ -277,7 +290,7 @@ rtp_source_create_stats (RTPSource * src)
   GstStructure *s;
   gboolean is_sender = src->is_sender;
   gboolean internal = src->internal;
-  gchar address_str[GST_NETADDRESS_MAX_LEN];
+  gchar *address_str;
   gboolean have_rb;
   guint8 fractionlost = 0;
   gint32 packetslost = 0;
@@ -306,15 +319,15 @@ rtp_source_create_stats (RTPSource * src)
       "clock-rate", G_TYPE_INT, src->clock_rate, NULL);
 
   /* add address and port */
-  if (src->have_rtp_from) {
-    gst_netaddress_to_string (&src->rtp_from, address_str,
-        sizeof (address_str));
+  if (src->rtp_from) {
+    address_str = __g_socket_address_to_string (src->rtp_from);
     gst_structure_set (s, "rtp-from", G_TYPE_STRING, address_str, NULL);
+    g_free (address_str);
   }
-  if (src->have_rtcp_from) {
-    gst_netaddress_to_string (&src->rtcp_from, address_str,
-        sizeof (address_str));
+  if (src->rtcp_from) {
+    address_str = __g_socket_address_to_string (src->rtcp_from);
     gst_structure_set (s, "rtcp-from", G_TYPE_STRING, address_str, NULL);
+    g_free (address_str);
   }
 
   gst_structure_set (s,
@@ -805,12 +818,13 @@ rtp_source_get_sdes_string (RTPSource * src, GstRTCPSDESType type)
  * collistion checking.
  */
 void
-rtp_source_set_rtp_from (RTPSource * src, GstNetAddress * address)
+rtp_source_set_rtp_from (RTPSource * src, GSocketAddress * address)
 {
   g_return_if_fail (RTP_IS_SOURCE (src));
 
-  src->have_rtp_from = TRUE;
-  memcpy (&src->rtp_from, address, sizeof (GstNetAddress));
+  if (src->rtp_from)
+    g_object_unref (src->rtp_from);
+  src->rtp_from = G_SOCKET_ADDRESS (g_object_ref (address));
 }
 
 /**
@@ -822,12 +836,13 @@ rtp_source_set_rtp_from (RTPSource * src, GstNetAddress * address)
  * collistion checking.
  */
 void
-rtp_source_set_rtcp_from (RTPSource * src, GstNetAddress * address)
+rtp_source_set_rtcp_from (RTPSource * src, GSocketAddress * address)
 {
   g_return_if_fail (RTP_IS_SOURCE (src));
 
-  src->have_rtcp_from = TRUE;
-  memcpy (&src->rtcp_from, address, sizeof (GstNetAddress));
+  if (src->rtcp_from)
+    g_object_unref (src->rtcp_from);
+  src->rtcp_from = G_SOCKET_ADDRESS (g_object_ref (address));
 }
 
 static GstFlowReturn
@@ -897,7 +912,7 @@ calculate_jitter (RTPSource * src, GstBuffer * buffer,
   gint32 diff;
   gint clock_rate;
   guint8 pt;
-  GstRTPBuffer rtp;
+  GstRTPBuffer rtp = { NULL };
 
   /* get arrival time */
   if ((running_time = arrival->running_time) == GST_CLOCK_TIME_NONE)
@@ -1026,7 +1041,7 @@ rtp_source_process_rtp (RTPSource * src, GstBuffer * buffer,
   guint16 seqnr, udelta;
   RTPSourceStats *stats;
   guint16 expected;
-  GstRTPBuffer rtp;
+  GstRTPBuffer rtp = { NULL };
 
   g_return_val_if_fail (RTP_IS_SOURCE (src), GST_FLOW_ERROR);
   g_return_val_if_fail (GST_IS_BUFFER (buffer), GST_FLOW_ERROR);
@@ -1037,11 +1052,6 @@ rtp_source_process_rtp (RTPSource * src, GstBuffer * buffer,
   seqnr = gst_rtp_buffer_get_seq (&rtp);
   gst_rtp_buffer_unmap (&rtp);
 
-  /* FIXME-0.11
-   * would be nice to be able to pass along with buffer */
-  g_assert_not_reached ();
-  /* rtp_source_update_caps (src, GST_BUFFER_CAPS (buffer)); */
-
   if (stats->cycles == -1) {
     GST_DEBUG ("received first buffer");
     /* first time we heard of this source */
@@ -1171,7 +1181,7 @@ rtp_source_process_bye (RTPSource * src, const gchar * reason)
 static gboolean
 set_ssrc (GstBuffer ** buffer, guint idx, RTPSource * src)
 {
-  GstRTPBuffer rtp;
+  GstRTPBuffer rtp = { NULL };
 
   *buffer = gst_buffer_make_writable (*buffer);
   gst_rtp_buffer_map (*buffer, GST_MAP_WRITE, &rtp);
@@ -1206,7 +1216,7 @@ rtp_source_send_rtp (RTPSource * src, gpointer data, gboolean is_list,
   GstBuffer *buffer = NULL;
   guint packets;
   guint32 ssrc;
-  GstRTPBuffer rtp;
+  GstRTPBuffer rtp = { NULL };
 
   g_return_val_if_fail (RTP_IS_SOURCE (src), GST_FLOW_ERROR);
   g_return_val_if_fail (is_list || GST_IS_BUFFER (data), GST_FLOW_ERROR);
@@ -1223,10 +1233,6 @@ rtp_source_send_rtp (RTPSource * src, gpointer data, gboolean is_list,
     buffer = GST_BUFFER_CAST (data);
   }
 
-  /* FIXME-0.11 */
-  g_assert_not_reached ();
-  /* rtp_source_update_caps (src, GST_BUFFER_CAPS (buffer)); */
-
   /* we are a sender now */
   src->is_sender = TRUE;
 
@@ -1234,7 +1240,7 @@ rtp_source_send_rtp (RTPSource * src, gpointer data, gboolean is_list,
     gint i;
 
     /* Each group makes up a network packet. */
-    packets = gst_buffer_list_len (list);
+    packets = gst_buffer_list_length (list);
     for (i = 0, len = 0; i < packets; i++) {
       gst_rtp_buffer_map (gst_buffer_list_get (list, i), GST_MAP_READ, &rtp);
       len += gst_rtp_buffer_get_payload_len (&rtp);
@@ -1368,6 +1374,9 @@ rtp_source_process_sr (RTPSource * src, GstClockTime time, guint64 ntptime,
 
   /* make current */
   src->stats.curr_sr = curridx;
+
+  src->stats.prev_rtcptime = src->stats.last_rtcptime;
+  src->stats.last_rtcptime = time;
 }
 
 /**
@@ -1706,7 +1715,7 @@ rtp_source_get_last_rb (RTPSource * src, guint8 * fractionlost,
  * Returns: TRUE if it was a known conflict, FALSE otherwise
  */
 gboolean
-rtp_source_find_conflicting_address (RTPSource * src, GstNetAddress * address,
+rtp_source_find_conflicting_address (RTPSource * src, GSocketAddress * address,
     GstClockTime time)
 {
   GList *item;
@@ -1715,7 +1724,7 @@ rtp_source_find_conflicting_address (RTPSource * src, GstNetAddress * address,
       item; item = g_list_next (item)) {
     RTPConflictingAddress *known_conflict = item->data;
 
-    if (gst_netaddress_equal (address, &known_conflict->address)) {
+    if (__g_socket_address_equal (address, known_conflict->address)) {
       known_conflict->time = time;
       return TRUE;
     }
@@ -1734,13 +1743,13 @@ rtp_source_find_conflicting_address (RTPSource * src, GstNetAddress * address,
  */
 void
 rtp_source_add_conflicting_address (RTPSource * src,
-    GstNetAddress * address, GstClockTime time)
+    GSocketAddress * address, GstClockTime time)
 {
   RTPConflictingAddress *new_conflict;
 
   new_conflict = g_new0 (RTPConflictingAddress, 1);
 
-  memcpy (&new_conflict->address, address, sizeof (GstNetAddress));
+  new_conflict->address = G_SOCKET_ADDRESS (g_object_ref (address));
   new_conflict->time = time;
 
   src->conflicting_addresses = g_list_prepend (src->conflicting_addresses,
@@ -1771,12 +1780,14 @@ rtp_source_timeout (RTPSource * src, GstClockTime current_time,
     GList *next_item = g_list_next (item);
 
     if (known_conflict->time < current_time - collision_timeout) {
-      gchar buf[40];
+      gchar *buf;
 
       src->conflicting_addresses =
           g_list_delete_link (src->conflicting_addresses, item);
-      gst_netaddress_to_string (&known_conflict->address, buf, 40);
+      buf = __g_socket_address_to_string (known_conflict->address);
       GST_DEBUG ("collision %p timed out: %s", known_conflict, buf);
+      g_free (buf);
+      g_object_unref (known_conflict->address);
       g_free (known_conflict);
     }
     item = next_item;