rtp: Update codes based on 1.18.4
[platform/upstream/gst-plugins-good.git] / gst / rtp / gstrtpdvpay.c
index bd87d70..ac8579b 100644 (file)
@@ -14,8 +14,8 @@
  *
  * You should have received a copy of the GNU Library General Public
  * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
  */
 
 #ifdef HAVE_CONFIG_H
@@ -27,6 +27,7 @@
 #include <gst/rtp/gstrtpbuffer.h>
 
 #include "gstrtpdvpay.h"
+#include "gstrtputils.h"
 
 GST_DEBUG_CATEGORY (rtpdvpay_debug);
 #define GST_CAT_DEFAULT (rtpdvpay_debug)
@@ -65,9 +66,9 @@ GST_STATIC_PAD_TEMPLATE ("src",
     )
     );
 
-static gboolean gst_rtp_dv_pay_setcaps (GstBaseRTPPayload * payload,
+static gboolean gst_rtp_dv_pay_setcaps (GstRTPBasePayload * payload,
     GstCaps * caps);
-static GstFlowReturn gst_rtp_dv_pay_handle_buffer (GstBaseRTPPayload * payload,
+static GstFlowReturn gst_rtp_dv_pay_handle_buffer (GstRTPBasePayload * payload,
     GstBuffer * buffer);
 
 #define GST_TYPE_DV_PAY_MODE (gst_dv_pay_mode_get_type())
@@ -94,49 +95,51 @@ static void gst_dv_pay_set_property (GObject * object,
 static void gst_dv_pay_get_property (GObject * object,
     guint prop_id, GValue * value, GParamSpec * pspec);
 
-GST_BOILERPLATE (GstRTPDVPay, gst_rtp_dv_pay, GstBaseRTPPayload,
-    GST_TYPE_BASE_RTP_PAYLOAD)
-
-     static void gst_rtp_dv_pay_base_init (gpointer g_class)
-{
-  GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
-
-  gst_element_class_add_pad_template (element_class,
-      gst_static_pad_template_get (&gst_rtp_dv_pay_sink_template));
-  gst_element_class_add_pad_template (element_class,
-      gst_static_pad_template_get (&gst_rtp_dv_pay_src_template));
-  gst_element_class_set_details_simple (element_class, "RTP DV Payloader",
-      "Codec/Payloader/Network/RTP",
-      "Payloads DV into RTP packets (RFC 3189)",
-      "Marcel Moreaux <marcelm@spacelabs.nl>, Wim Taymans <wim.taymans@gmail.com>");
-}
+#define gst_rtp_dv_pay_parent_class parent_class
+G_DEFINE_TYPE (GstRTPDVPay, gst_rtp_dv_pay, GST_TYPE_RTP_BASE_PAYLOAD);
 
 static void
 gst_rtp_dv_pay_class_init (GstRTPDVPayClass * klass)
 {
   GObjectClass *gobject_class;
-  GstBaseRTPPayloadClass *gstbasertppayload_class;
+  GstElementClass *gstelement_class;
+  GstRTPBasePayloadClass *gstrtpbasepayload_class;
+
+  GST_DEBUG_CATEGORY_INIT (rtpdvpay_debug, "rtpdvpay", 0, "DV RTP Payloader");
 
   gobject_class = (GObjectClass *) klass;
-  gstbasertppayload_class = (GstBaseRTPPayloadClass *) klass;
+  gstelement_class = (GstElementClass *) klass;
+  gstrtpbasepayload_class = (GstRTPBasePayloadClass *) klass;
 
   gobject_class->set_property = gst_dv_pay_set_property;
   gobject_class->get_property = gst_dv_pay_get_property;
 
-  gstbasertppayload_class->set_caps = gst_rtp_dv_pay_setcaps;
-  gstbasertppayload_class->handle_buffer = gst_rtp_dv_pay_handle_buffer;
-
   g_object_class_install_property (gobject_class, PROP_MODE,
       g_param_spec_enum ("mode", "Mode",
           "The payload mode of payloading",
           GST_TYPE_DV_PAY_MODE, DEFAULT_MODE,
           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
-  GST_DEBUG_CATEGORY_INIT (rtpdvpay_debug, "rtpdvpay", 0, "DV RTP Payloader");
+  gst_element_class_add_static_pad_template (gstelement_class,
+      &gst_rtp_dv_pay_sink_template);
+  gst_element_class_add_static_pad_template (gstelement_class,
+      &gst_rtp_dv_pay_src_template);
+
+  gst_element_class_set_static_metadata (gstelement_class, "RTP DV Payloader",
+      "Codec/Payloader/Network/RTP",
+      "Payloads DV into RTP packets (RFC 3189)",
+      "Marcel Moreaux <marcelm@spacelabs.nl>, Wim Taymans <wim.taymans@gmail.com>");
+
+  gstrtpbasepayload_class->set_caps = gst_rtp_dv_pay_setcaps;
+  gstrtpbasepayload_class->handle_buffer = gst_rtp_dv_pay_handle_buffer;
+
+#ifndef TIZEN_FEATURE_GST_UPSTREAM_AVOID_BUILD_BREAK
+  gst_type_mark_as_plugin_api (GST_TYPE_DV_PAY_MODE, 0);
+#endif
 }
 
 static void
-gst_rtp_dv_pay_init (GstRTPDVPay * rtpdvpay, GstRTPDVPayClass * klass)
+gst_rtp_dv_pay_init (GstRTPDVPay * rtpdvpay)
 {
 }
 
@@ -173,7 +176,7 @@ gst_dv_pay_get_property (GObject * object,
 }
 
 static gboolean
-gst_rtp_dv_pay_setcaps (GstBaseRTPPayload * payload, GstCaps * caps)
+gst_rtp_dv_pay_setcaps (GstRTPBasePayload * payload, GstCaps * caps)
 {
   /* We don't do anything here, but we could check if it's a system stream and if
    * it's not, default to sending the video only. We will negotiate downstream
@@ -223,15 +226,15 @@ gst_dv_pay_negotiate (GstRTPDVPay * rtpdvpay, guint8 * data, gsize size)
     default:
       break;
   }
-  gst_basertppayload_set_options (GST_BASE_RTP_PAYLOAD (rtpdvpay), media, TRUE,
-      "DV", 90000);
+  gst_rtp_base_payload_set_options (GST_RTP_BASE_PAYLOAD (rtpdvpay), media,
+      TRUE, "DV", 90000);
 
   if (audio_bundled) {
-    res = gst_basertppayload_set_outcaps (GST_BASE_RTP_PAYLOAD (rtpdvpay),
+    res = gst_rtp_base_payload_set_outcaps (GST_RTP_BASE_PAYLOAD (rtpdvpay),
         "encode", G_TYPE_STRING, encode,
         "audio", G_TYPE_STRING, "bundled", NULL);
   } else {
-    res = gst_basertppayload_set_outcaps (GST_BASE_RTP_PAYLOAD (rtpdvpay),
+    res = gst_rtp_base_payload_set_outcaps (GST_RTP_BASE_PAYLOAD (rtpdvpay),
         "encode", G_TYPE_STRING, encode, NULL);
   }
   return res;
@@ -276,7 +279,7 @@ include_dif (GstRTPDVPay * rtpdvpay, guint8 * data)
 /* Get a DV frame, chop it up in pieces, and push the pieces to the RTP layer.
  */
 static GstFlowReturn
-gst_rtp_dv_pay_handle_buffer (GstBaseRTPPayload * basepayload,
+gst_rtp_dv_pay_handle_buffer (GstRTPBasePayload * basepayload,
     GstBuffer * buffer)
 {
   GstRTPDVPay *rtpdvpay;
@@ -284,8 +287,9 @@ gst_rtp_dv_pay_handle_buffer (GstBaseRTPPayload * basepayload,
   GstBuffer *outbuf;
   GstFlowReturn ret = GST_FLOW_OK;
   gint hdrlen;
-  gsize size, osize;
-  guint8 *data, *odata;
+  gsize size;
+  GstMapInfo map;
+  guint8 *data;
   guint8 *dest;
   guint filled;
   GstRTPBuffer rtp = { NULL, };
@@ -298,18 +302,23 @@ gst_rtp_dv_pay_handle_buffer (GstBaseRTPPayload * basepayload,
    * Therefore, we round the available room down to the nearest multiple of 80.
    *
    * The available room is just the packet MTU, minus the RTP header length. */
-  max_payload_size = ((GST_BASE_RTP_PAYLOAD_MTU (rtpdvpay) - hdrlen) / 80) * 80;
+  max_payload_size = ((GST_RTP_BASE_PAYLOAD_MTU (rtpdvpay) - hdrlen) / 80) * 80;
 
   /* The length of the buffer to transmit. */
-  data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
-
-  odata = data;
-  osize = size;
+  if (!gst_buffer_map (buffer, &map, GST_MAP_READ)) {
+    GST_ELEMENT_ERROR (rtpdvpay, CORE, FAILED,
+        (NULL), ("Failed to map buffer"));
+    gst_buffer_unref (buffer);
+    return GST_FLOW_ERROR;
+  }
+  data = map.data;
+  size = map.size;
 
   GST_DEBUG_OBJECT (rtpdvpay,
-      "DV RTP payloader got buffer of %u bytes, splitting in %u byte "
-      "payload fragments, at time %" GST_TIME_FORMAT, size, max_payload_size,
-      GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buffer)));
+      "DV RTP payloader got buffer of %" G_GSIZE_FORMAT
+      " bytes, splitting in %u byte " "payload fragments, at time %"
+      GST_TIME_FORMAT, size, max_payload_size,
+      GST_TIME_ARGS (GST_BUFFER_PTS (buffer)));
 
   if (!rtpdvpay->negotiated) {
     gst_dv_pay_negotiate (rtpdvpay, data, size);
@@ -326,9 +335,15 @@ gst_rtp_dv_pay_handle_buffer (GstBaseRTPPayload * basepayload,
     /* Allocate a new buffer, set the timestamp */
     if (outbuf == NULL) {
       outbuf = gst_rtp_buffer_new_allocate (max_payload_size, 0, 0);
-      GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buffer);
-
-      gst_rtp_buffer_map (outbuf, GST_MAP_WRITE, &rtp);
+      GST_BUFFER_PTS (outbuf) = GST_BUFFER_PTS (buffer);
+
+      if (!gst_rtp_buffer_map (outbuf, GST_MAP_WRITE, &rtp)) {
+        gst_buffer_unref (outbuf);
+        GST_ELEMENT_ERROR (rtpdvpay, CORE, FAILED,
+            (NULL), ("Failed to map RTP buffer"));
+        ret = GST_FLOW_ERROR;
+        goto beach;
+      }
       dest = gst_rtp_buffer_get_payload (&rtp);
       filled = 0;
     }
@@ -362,14 +377,17 @@ gst_rtp_dv_pay_handle_buffer (GstBaseRTPPayload * basepayload,
 
       /* Push out the created piece, and check for errors. */
       gst_rtp_buffer_unmap (&rtp);
-      ret = gst_basertppayload_push (basepayload, outbuf);
+      gst_rtp_copy_meta (GST_ELEMENT_CAST (basepayload), outbuf, buffer, 0);
+      ret = gst_rtp_base_payload_push (basepayload, outbuf);
       if (ret != GST_FLOW_OK)
         break;
 
       outbuf = NULL;
     }
   }
-  gst_buffer_unmap (buffer, odata, osize);
+
+beach:
+  gst_buffer_unmap (buffer, &map);
   gst_buffer_unref (buffer);
 
   return ret;