Merge branch 'master' into 0.11
[platform/upstream/gstreamer.git] / gst-libs / gst / rtp / gstbasertpdepayload.c
index 9c33413..c8be565 100644 (file)
 
 #include "gstbasertpdepayload.h"
 
-#ifdef GST_DISABLE_DEPRECATED
-#define QUEUE_LOCK_INIT(base)   (g_static_rec_mutex_init(&base->queuelock))
-#define QUEUE_LOCK_FREE(base)   (g_static_rec_mutex_free(&base->queuelock))
-#define QUEUE_LOCK(base)        (g_static_rec_mutex_lock(&base->queuelock))
-#define QUEUE_UNLOCK(base)      (g_static_rec_mutex_unlock(&base->queuelock))
-#else
-/* otherwise it's already been defined in the header (FIXME 0.11)*/
-#endif
-
 GST_DEBUG_CATEGORY_STATIC (basertpdepayload_debug);
 #define GST_CAT_DEFAULT (basertpdepayload_debug)
 
@@ -65,12 +56,9 @@ enum
   LAST_SIGNAL
 };
 
-#define DEFAULT_QUEUE_DELAY    0
-
 enum
 {
   PROP_0,
-  PROP_QUEUE_DELAY,
   PROP_LAST
 };
 
@@ -96,13 +84,35 @@ static gboolean gst_base_rtp_depayload_packet_lost (GstBaseRTPDepayload *
 static gboolean gst_base_rtp_depayload_handle_event (GstBaseRTPDepayload *
     filter, GstEvent * event);
 
-GST_BOILERPLATE (GstBaseRTPDepayload, gst_base_rtp_depayload, GstElement,
-    GST_TYPE_ELEMENT);
+static GstElementClass *parent_class = NULL;
+static void gst_base_rtp_depayload_class_init (GstBaseRTPDepayloadClass *
+    klass);
+static void gst_base_rtp_depayload_init (GstBaseRTPDepayload * basertppayload,
+    GstBaseRTPDepayloadClass * klass);
 
-static void
-gst_base_rtp_depayload_base_init (gpointer klass)
+GType
+gst_base_rtp_depayload_get_type (void)
 {
-  /*GstElementClass *element_class = GST_ELEMENT_CLASS (klass); */
+  static GType base_rtp_depayload_type = 0;
+
+  if (g_once_init_enter ((gsize *) & base_rtp_depayload_type)) {
+    static const GTypeInfo base_rtp_depayload_info = {
+      sizeof (GstBaseRTPDepayloadClass),
+      NULL,
+      NULL,
+      (GClassInitFunc) gst_base_rtp_depayload_class_init,
+      NULL,
+      NULL,
+      sizeof (GstBaseRTPDepayload),
+      0,
+      (GInstanceInitFunc) gst_base_rtp_depayload_init,
+    };
+
+    g_once_init_leave ((gsize *) & base_rtp_depayload_type,
+        g_type_register_static (GST_TYPE_ELEMENT, "GstBaseRTPDepayload",
+            &base_rtp_depayload_info, G_TYPE_FLAG_ABSTRACT));
+  }
+  return base_rtp_depayload_type;
 }
 
 static void
@@ -121,21 +131,6 @@ gst_base_rtp_depayload_class_init (GstBaseRTPDepayloadClass * klass)
   gobject_class->set_property = gst_base_rtp_depayload_set_property;
   gobject_class->get_property = gst_base_rtp_depayload_get_property;
 
-  /**
-   * GstBaseRTPDepayload::queue-delay
-   *
-   * Control the amount of packets to buffer.
-   *
-   * Deprecated: Use a jitterbuffer or RTP session manager to delay packet
-   * playback. This property has no effect anymore since 0.10.15.
-   */
-#ifndef GST_REMOVE_DEPRECATED
-  g_object_class_install_property (gobject_class, PROP_QUEUE_DELAY,
-      g_param_spec_uint ("queue-delay", "Queue Delay",
-          "Amount of ms to queue/buffer, deprecated", 0, G_MAXUINT,
-          DEFAULT_QUEUE_DELAY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
-#endif
-
   gstelement_class->change_state = gst_base_rtp_depayload_change_state;
 
   klass->set_gst_timestamp = gst_base_rtp_depayload_set_gst_timestamp;
@@ -176,19 +171,12 @@ gst_base_rtp_depayload_init (GstBaseRTPDepayload * filter,
   gst_pad_use_fixed_caps (filter->srcpad);
   gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad);
 
-  filter->queue = g_queue_new ();
-  filter->queue_delay = DEFAULT_QUEUE_DELAY;
-
   gst_segment_init (&filter->segment, GST_FORMAT_UNDEFINED);
 }
 
 static void
 gst_base_rtp_depayload_finalize (GObject * object)
 {
-  GstBaseRTPDepayload *filter = GST_BASE_RTP_DEPAYLOAD (object);
-
-  g_queue_free (filter->queue);
-
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
@@ -269,6 +257,7 @@ gst_base_rtp_depayload_chain (GstPad * pad, GstBuffer * in)
   guint32 rtptime;
   gboolean discont;
   gint gap;
+  GstRTPBuffer rtp;
 
   filter = GST_BASE_RTP_DEPAYLOAD (GST_OBJECT_PARENT (pad));
   priv = filter->priv;
@@ -293,8 +282,11 @@ gst_base_rtp_depayload_chain (GstPad * pad, GstBuffer * in)
   priv->timestamp = timestamp;
   priv->duration = GST_BUFFER_DURATION (in);
 
-  seqnum = gst_rtp_buffer_get_seq (in);
-  rtptime = gst_rtp_buffer_get_timestamp (in);
+  gst_rtp_buffer_map (in, GST_MAP_READ, &rtp);
+  seqnum = gst_rtp_buffer_get_seq (&rtp);
+  rtptime = gst_rtp_buffer_get_timestamp (&rtp);
+  gst_rtp_buffer_unmap (&rtp);
+
   discont = FALSE;
 
   GST_LOG_OBJECT (filter, "discont %d, seqnum %u, rtptime %u, timestamp %"
@@ -337,7 +329,7 @@ gst_base_rtp_depayload_chain (GstPad * pad, GstBuffer * in)
     /* we detected a seqnum discont but the buffer was not flagged with a discont,
      * set the discont flag so that the subclass can throw away old data. */
     priv->discont = TRUE;
-    in = gst_buffer_make_metadata_writable (in);
+    in = gst_buffer_make_writable (in);
     GST_BUFFER_FLAG_SET (in, GST_BUFFER_FLAG_DISCONT);
   }
 
@@ -361,22 +353,14 @@ gst_base_rtp_depayload_chain (GstPad * pad, GstBuffer * in)
 not_negotiated:
   {
     /* this is not fatal but should be filtered earlier */
-    if (GST_BUFFER_CAPS (in) == NULL) {
-      GST_ELEMENT_ERROR (filter, CORE, NEGOTIATION,
-          ("No RTP format was negotiated."),
-          ("Input buffers need to have RTP caps set on them. This is usually "
-              "achieved by setting the 'caps' property of the upstream source "
-              "element (often udpsrc or appsrc), or by putting a capsfilter "
-              "element before the depayloader and setting the 'caps' property "
-              "on that. Also see http://cgit.freedesktop.org/gstreamer/"
-              "gst-plugins-good/tree/gst/rtp/README"));
-    } else {
-      GST_ELEMENT_ERROR (filter, CORE, NEGOTIATION,
-          ("No RTP format was negotiated."),
-          ("RTP caps on input buffer were rejected, most likely because they "
-              "were incomplete or contained wrong values. Check the debug log "
-              "for more information."));
-    }
+    GST_ELEMENT_ERROR (filter, CORE, NEGOTIATION,
+        ("No RTP format was negotiated."),
+        ("Input buffers need to have RTP caps set on them. This is usually "
+            "achieved by setting the 'caps' property of the upstream source "
+            "element (often udpsrc or appsrc), or by putting a capsfilter "
+            "element before the depayloader and setting the 'caps' property "
+            "on that. Also see http://cgit.freedesktop.org/gstreamer/"
+            "gst-plugins-good/tree/gst/rtp/README"));
     gst_buffer_unref (in);
     return GST_FLOW_NOT_NEGOTIATED;
   }
@@ -417,19 +401,9 @@ gst_base_rtp_depayload_handle_event (GstBaseRTPDepayload * filter,
       filter->need_newsegment = TRUE;
       filter->priv->next_seqnum = -1;
       break;
-    case GST_EVENT_NEWSEGMENT:
+    case GST_EVENT_SEGMENT:
     {
-      gboolean update;
-      gdouble rate;
-      GstFormat fmt;
-      gint64 start, stop, position;
-
-      gst_event_parse_new_segment (event, &update, &rate, &fmt, &start, &stop,
-          &position);
-
-      gst_segment_set_newsegment (&filter->segment, update, rate, fmt,
-          start, stop, position);
-
+      gst_event_copy_segment (event, &filter->segment);
       /* don't pass the event downstream, we generate our own segment including
        * the NTP time and other things we receive in caps */
       forward = FALSE;
@@ -500,6 +474,7 @@ create_segment_event (GstBaseRTPDepayload * filter, gboolean update,
   GstEvent *event;
   GstClockTime stop;
   GstBaseRTPDepayloadPrivate *priv;
+  GstSegment segment;
 
   priv = filter->priv;
 
@@ -508,9 +483,15 @@ create_segment_event (GstBaseRTPDepayload * filter, gboolean update,
   else
     stop = -1;
 
-  event = gst_event_new_new_segment_full (update, priv->play_speed,
-      priv->play_scale, GST_FORMAT_TIME, position, stop,
-      position + priv->npt_start);
+  gst_segment_init (&segment, GST_FORMAT_TIME);
+  segment.rate = priv->play_speed;
+  segment.applied_rate = priv->play_scale;
+  segment.start = 0;
+  segment.stop = stop;
+  segment.time = priv->npt_start;
+  segment.position = position;
+
+  event = gst_event_new_segment (&segment);
 
   return event;
 }
@@ -519,18 +500,16 @@ typedef struct
 {
   GstBaseRTPDepayload *depayload;
   GstBaseRTPDepayloadClass *bclass;
-  GstCaps *caps;
   gboolean do_ts;
   gboolean rtptime;
 } HeaderData;
 
-static GstBufferListItem
-set_headers (GstBuffer ** buffer, guint group, guint idx, HeaderData * data)
+static gboolean
+set_headers (GstBuffer ** buffer, guint idx, HeaderData * data)
 {
   GstBaseRTPDepayload *depayload = data->depayload;
 
-  *buffer = gst_buffer_make_metadata_writable (*buffer);
-  gst_buffer_set_caps (*buffer, data->caps);
+  *buffer = gst_buffer_make_writable (*buffer);
 
   /* set the timestamp if we must and can */
   if (data->bclass->set_gst_timestamp && data->do_ts)
@@ -542,7 +521,7 @@ set_headers (GstBuffer ** buffer, guint group, guint idx, HeaderData * data)
     depayload->priv->discont = FALSE;
   }
 
-  return GST_BUFFER_LIST_SKIP_GROUP;
+  return TRUE;
 }
 
 static GstFlowReturn
@@ -552,7 +531,6 @@ gst_base_rtp_depayload_prepare_push (GstBaseRTPDepayload * filter,
   HeaderData data;
 
   data.depayload = filter;
-  data.caps = GST_PAD_CAPS (filter->srcpad);
   data.rtptime = rtptime;
   data.do_ts = do_ts;
   data.bclass = GST_BASE_RTP_DEPAYLOAD_GET_CLASS (filter);
@@ -562,7 +540,7 @@ gst_base_rtp_depayload_prepare_push (GstBaseRTPDepayload * filter,
     gst_buffer_list_foreach (*blist, (GstBufferListFunc) set_headers, &data);
   } else {
     GstBuffer **buf = obj;
-    set_headers (buf, 0, 0, &data);
+    set_headers (buf, 0, &data);
   }
 
   /* if this is the first buffer send a NEWSEGMENT */
@@ -774,9 +752,6 @@ gst_base_rtp_depayload_set_property (GObject * object, guint prop_id,
   filter = GST_BASE_RTP_DEPAYLOAD (object);
 
   switch (prop_id) {
-    case PROP_QUEUE_DELAY:
-      filter->queue_delay = g_value_get_uint (value);
-      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -792,9 +767,6 @@ gst_base_rtp_depayload_get_property (GObject * object, guint prop_id,
   filter = GST_BASE_RTP_DEPAYLOAD (object);
 
   switch (prop_id) {
-    case PROP_QUEUE_DELAY:
-      g_value_set_uint (value, filter->queue_delay);
-      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;