rtp: Update codes based on 1.18.4
[platform/upstream/gst-plugins-good.git] / gst / rtp / gstrtpvp8pay.c
index f3ad845..5c53a29 100644 (file)
 #include <gst/base/gstbitreader.h>
 #include <gst/rtp/gstrtppayloads.h>
 #include <gst/rtp/gstrtpbuffer.h>
+#include <gst/video/video.h>
 #include "dboolhuff.h"
 #include "gstrtpvp8pay.h"
+#include "gstrtputils.h"
 
 GST_DEBUG_CATEGORY_STATIC (gst_rtp_vp8_pay_debug);
 #define GST_CAT_DEFAULT gst_rtp_vp8_pay_debug
@@ -82,7 +84,7 @@ GST_STATIC_PAD_TEMPLATE ("src",
     GST_PAD_ALWAYS,
     GST_STATIC_CAPS ("application/x-rtp, "
         "payload = (int) " GST_RTP_PAYLOAD_DYNAMIC_STRING ","
-        "clock-rate = (int) 90000, encoding-name = (string) \"VP8-DRAFT-IETF-01\""));
+        "clock-rate = (int) 90000, encoding-name = (string) { \"VP8\", \"VP8-DRAFT-IETF-01\" }"));
 
 static GstStaticPadTemplate gst_rtp_vp8_pay_sink_template =
 GST_STATIC_PAD_TEMPLATE ("sink",
@@ -117,14 +119,14 @@ gst_rtp_vp8_pay_class_init (GstRtpVP8PayClass * gst_rtp_vp8_pay_class)
           GST_TYPE_RTP_VP8_PAY_PICTURE_ID_MODE, DEFAULT_PICTURE_ID_MODE,
           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
-  gst_element_class_add_pad_template (element_class,
-      gst_static_pad_template_get (&gst_rtp_vp8_pay_sink_template));
-  gst_element_class_add_pad_template (element_class,
-      gst_static_pad_template_get (&gst_rtp_vp8_pay_src_template));
+  gst_element_class_add_static_pad_template (element_class,
+      &gst_rtp_vp8_pay_sink_template);
+  gst_element_class_add_static_pad_template (element_class,
+      &gst_rtp_vp8_pay_src_template);
 
   gst_element_class_set_static_metadata (element_class, "RTP VP8 payloader",
       "Codec/Payloader/Network/RTP",
-      "Puts VP8 video in RTP packets)", "Sjoerd Simons <sjoerd@luon.net>");
+      "Puts VP8 video in RTP packets", "Sjoerd Simons <sjoerd@luon.net>");
 
   pay_class->handle_buffer = gst_rtp_vp8_pay_handle_buffer;
   pay_class->sink_event = gst_rtp_vp8_pay_sink_event;
@@ -132,6 +134,10 @@ gst_rtp_vp8_pay_class_init (GstRtpVP8PayClass * gst_rtp_vp8_pay_class)
 
   GST_DEBUG_CATEGORY_INIT (gst_rtp_vp8_pay_debug, "rtpvp8pay", 0,
       "VP8 Video RTP Payloader");
+
+#ifndef TIZEN_FEATURE_GST_UPSTREAM_AVOID_BUILD_BREAK
+  gst_type_mark_as_plugin_api (GST_TYPE_RTP_VP8_PAY_PICTURE_ID_MODE, 0);
+#endif
 }
 
 static void
@@ -350,13 +356,12 @@ gst_rtp_vp8_offset_to_partition (GstRtpVP8Pay * self, guint offset)
 {
   int i;
 
-  for (i = 0; i < self->n_partitions; i++) {
-    if (offset >= self->partition_offset[i] &&
-        offset < self->partition_offset[i + 1])
-      return i;
+  for (i = 1; i < self->n_partitions; i++) {
+    if (offset < self->partition_offset[i])
+      return i - 1;
   }
 
-  return i;
+  return i - 1;
 }
 
 static gsize
@@ -412,7 +417,6 @@ gst_rtp_vp8_create_header_buffer (GstRtpVP8Pay * self, guint8 partid,
   return out;
 }
 
-
 static guint
 gst_rtp_vp8_payload_next (GstRtpVP8Pay * self, GstBufferList * list,
     guint offset, GstBuffer * buffer, gsize buffer_size, gsize max_payload_len)
@@ -439,6 +443,8 @@ gst_rtp_vp8_payload_next (GstRtpVP8Pay * self, GstBufferList * list,
       offset == self->partition_offset[partition], mark, buffer);
   sub = gst_buffer_copy_region (buffer, GST_BUFFER_COPY_ALL, offset, available);
 
+  gst_rtp_copy_video_meta (self, header, buffer);
+
   out = gst_buffer_append (header, sub);
 
   gst_buffer_list_insert (list, -1, out);
@@ -509,8 +515,32 @@ gst_rtp_vp8_pay_sink_event (GstRTPBasePayload * payload, GstEvent * event)
 static gboolean
 gst_rtp_vp8_pay_set_caps (GstRTPBasePayload * payload, GstCaps * caps)
 {
+  GstCaps *src_caps;
+  const char *encoding_name = "VP8";
+
+  src_caps = gst_pad_get_allowed_caps (GST_RTP_BASE_PAYLOAD_SRCPAD (payload));
+  if (src_caps) {
+    GstStructure *s;
+    const GValue *value;
+
+    s = gst_caps_get_structure (src_caps, 0);
+
+    if (gst_structure_has_field (s, "encoding-name")) {
+      GValue default_value = G_VALUE_INIT;
+
+      g_value_init (&default_value, G_TYPE_STRING);
+      g_value_set_static_string (&default_value, encoding_name);
+
+      value = gst_structure_get_value (s, "encoding-name");
+      if (!gst_value_can_intersect (&default_value, value))
+        encoding_name = "VP8-DRAFT-IETF-01";
+    }
+    gst_caps_unref (src_caps);
+  }
+
   gst_rtp_base_payload_set_options (payload, "video", TRUE,
-      "VP8-DRAFT-IETF-01", 90000);
+      encoding_name, 90000);
+
   return gst_rtp_base_payload_set_outcaps (payload, NULL);
 }