Merge branch 'master' into 0.11
[platform/upstream/gstreamer.git] / gst-libs / gst / rtp / gstbasertppayload.c
index e27d97a..33e6a90 100644 (file)
@@ -95,7 +95,8 @@ static void gst_basertppayload_init (GstBaseRTPPayload * basertppayload,
 static void gst_basertppayload_finalize (GObject * object);
 
 static gboolean gst_basertppayload_sink_setcaps (GstPad * pad, GstCaps * caps);
-static GstCaps *gst_basertppayload_sink_getcaps (GstPad * pad);
+static GstCaps *gst_basertppayload_sink_getcaps (GstPad * pad,
+    GstCaps * filter);
 static gboolean gst_basertppayload_event (GstPad * pad, GstEvent * event);
 static GstFlowReturn gst_basertppayload_chain (GstPad * pad,
     GstBuffer * buffer);
@@ -117,7 +118,7 @@ gst_basertppayload_get_type (void)
 {
   static GType basertppayload_type = 0;
 
-  if (!basertppayload_type) {
+  if (g_once_init_enter ((gsize *) & basertppayload_type)) {
     static const GTypeInfo basertppayload_info = {
       sizeof (GstBaseRTPPayloadClass),
       (GBaseInitFunc) gst_basertppayload_base_init,
@@ -130,9 +131,9 @@ gst_basertppayload_get_type (void)
       (GInstanceInitFunc) gst_basertppayload_init,
     };
 
-    basertppayload_type =
+    g_once_init_leave ((gsize *) & basertppayload_type,
         g_type_register_static (GST_TYPE_ELEMENT, "GstBaseRTPPayload",
-        &basertppayload_info, G_TYPE_FLAG_ABSTRACT);
+            &basertppayload_info, G_TYPE_FLAG_ABSTRACT));
   }
   return basertppayload_type;
 }
@@ -343,7 +344,7 @@ gst_basertppayload_sink_setcaps (GstPad * pad, GstCaps * caps)
 }
 
 static GstCaps *
-gst_basertppayload_sink_getcaps (GstPad * pad)
+gst_basertppayload_sink_getcaps (GstPad * pad, GstCaps * filter)
 {
   GstBaseRTPPayload *basertppayload;
   GstBaseRTPPayloadClass *basertppayload_class;
@@ -355,7 +356,7 @@ gst_basertppayload_sink_getcaps (GstPad * pad)
   basertppayload_class = GST_BASE_RTP_PAYLOAD_GET_CLASS (basertppayload);
 
   if (basertppayload_class->get_caps)
-    caps = basertppayload_class->get_caps (basertppayload, pad);
+    caps = basertppayload_class->get_caps (basertppayload, pad, filter);
 
   if (!caps) {
     caps = GST_PAD_TEMPLATE_CAPS (GST_PAD_PAD_TEMPLATE (pad));
@@ -363,7 +364,10 @@ gst_basertppayload_sink_getcaps (GstPad * pad)
         "using pad template %p with caps %p %" GST_PTR_FORMAT,
         GST_PAD_PAD_TEMPLATE (pad), caps, caps);
 
-    caps = gst_caps_ref (caps);
+    if (filter)
+      caps = gst_caps_intersect_full (filter, caps, GST_CAPS_INTERSECT_FIRST);
+    else
+      caps = gst_caps_ref (caps);
   }
 
   gst_object_unref (basertppayload);
@@ -399,28 +403,15 @@ gst_basertppayload_event (GstPad * pad, GstEvent * event)
       res = gst_pad_event_default (pad, event);
       gst_segment_init (&basertppayload->segment, GST_FORMAT_UNDEFINED);
       break;
-    case GST_EVENT_NEWSEGMENT:
+    case GST_EVENT_SEGMENT:
     {
-      gboolean update;
-      gdouble rate, arate;
-      GstFormat fmt;
-      gint64 start, stop, position;
       GstSegment *segment;
 
       segment = &basertppayload->segment;
-
-      gst_event_parse_new_segment_full (event, &update, &rate, &arate, &fmt,
-          &start, &stop, &position);
-      gst_segment_set_newsegment_full (segment, update, rate, arate, fmt, start,
-          stop, position);
+      gst_event_copy_segment (event, segment);
 
       GST_DEBUG_OBJECT (basertppayload,
-          "configured NEWSEGMENT update %d, rate %lf, applied rate %lf, "
-          "format %d, "
-          "%" G_GINT64_FORMAT " -- %" G_GINT64_FORMAT ", time %"
-          G_GINT64_FORMAT ", accum %" G_GINT64_FORMAT, update, rate, arate,
-          segment->format, segment->start, segment->stop, segment->time,
-          segment->accum);
+          "configured SEGMENT %" GST_SEGMENT_FORMAT, segment);
       /* fallthrough */
     }
     default:
@@ -560,7 +551,7 @@ gst_basertppayload_set_outcaps (GstBaseRTPPayload * payload,
   payload->abidata.ABI.ptime = 0;
 
   /* the peer caps can override some of the defaults */
-  peercaps = gst_pad_peer_get_caps (payload->srcpad);
+  peercaps = gst_pad_peer_get_caps (payload->srcpad, srccaps);
   if (peercaps == NULL) {
     /* no peer caps, just add the other properties */
     gst_caps_set_simple (srccaps,
@@ -577,11 +568,10 @@ gst_basertppayload_set_outcaps (GstBaseRTPPayload * payload,
     gint pt;
     guint max_ptime, ptime;
 
-    /* peer provides caps we can use to fixate, intersect. This always returns a
-     * writable caps. */
-    temp = gst_caps_intersect (srccaps, peercaps);
+    /* peer provides caps we can use to fixate. They are already intersected
+     * with our srccaps, just make them writable */
+    temp = gst_caps_make_writable (peercaps);
     gst_caps_unref (srccaps);
-    gst_caps_unref (peercaps);
 
     if (gst_caps_is_empty (temp)) {
       gst_caps_unref (temp);
@@ -704,14 +694,13 @@ typedef struct
   guint32 ssrc;
   guint16 seqnum;
   guint8 pt;
-  GstCaps *caps;
   GstClockTime timestamp;
   guint64 offset;
   guint32 rtptime;
 } HeaderData;
 
-static GstBufferListItem
-find_timestamp (GstBuffer ** buffer, guint group, guint idx, HeaderData * data)
+static gboolean
+find_timestamp (GstBuffer ** buffer, guint idx, HeaderData * data)
 {
   data->timestamp = GST_BUFFER_TIMESTAMP (*buffer);
   data->offset = GST_BUFFER_OFFSET (*buffer);
@@ -719,23 +708,27 @@ find_timestamp (GstBuffer ** buffer, guint group, guint idx, HeaderData * data)
   /* stop when we find a timestamp. We take whatever offset is associated with
    * the timestamp (if any) to do perfect timestamps when we need to. */
   if (data->timestamp != -1)
-    return GST_BUFFER_LIST_END;
+    return FALSE;
   else
-    return GST_BUFFER_LIST_CONTINUE;
+    return TRUE;
 }
 
-static GstBufferListItem
+static gboolean
 set_headers (GstBuffer ** buffer, guint group, guint idx, HeaderData * data)
 {
-  gst_rtp_buffer_set_ssrc (*buffer, data->ssrc);
-  gst_rtp_buffer_set_payload_type (*buffer, data->pt);
-  gst_rtp_buffer_set_seq (*buffer, data->seqnum);
-  gst_rtp_buffer_set_timestamp (*buffer, data->rtptime);
-  gst_buffer_set_caps (*buffer, data->caps);
+  GstRTPBuffer rtp;
+
+  gst_rtp_buffer_map (*buffer, GST_MAP_WRITE, &rtp);
+  gst_rtp_buffer_set_ssrc (&rtp, data->ssrc);
+  gst_rtp_buffer_set_payload_type (&rtp, data->pt);
+  gst_rtp_buffer_set_seq (&rtp, data->seqnum);
+  gst_rtp_buffer_set_timestamp (&rtp, data->rtptime);
+  gst_rtp_buffer_unmap (&rtp);
+
   /* increment the seqnum for each buffer */
   data->seqnum++;
 
-  return GST_BUFFER_LIST_SKIP_GROUP;
+  return TRUE;
 }
 
 /* Updates the SSRC, payload type, seqnum and timestamp of the RTP buffer
@@ -761,7 +754,6 @@ gst_basertppayload_prepare_push (GstBaseRTPPayload * payload,
   data.seqnum = payload->seqnum;
   data.ssrc = payload->current_ssrc;
   data.pt = payload->pt;
-  data.caps = GST_PAD_CAPS (payload->srcpad);
 
   /* find the first buffer with a timestamp */
   if (is_list) {
@@ -821,7 +813,7 @@ gst_basertppayload_prepare_push (GstBaseRTPPayload * payload,
   GST_LOG_OBJECT (payload,
       "Preparing to push packet with size %d, seq=%d, rtptime=%u, timestamp %"
       GST_TIME_FORMAT, (is_list) ? -1 :
-      GST_BUFFER_SIZE (GST_BUFFER (obj)), payload->seqnum, data.rtptime,
+      gst_buffer_get_size (GST_BUFFER (obj)), payload->seqnum, data.rtptime,
       GST_TIME_ARGS (data.timestamp));
 
   if (g_atomic_int_compare_and_exchange (&payload->