rtp: Update codes based on 1.18.4
[platform/upstream/gst-plugins-good.git] / gst / rtp / gstrtpmp4vpay.c
index 362ff65..2980339 100644 (file)
@@ -107,10 +107,11 @@ gst_rtp_mp4v_pay_class_init (GstRtpMP4VPayClass * klass)
       "Wim Taymans <wim.taymans@gmail.com>");
 
   g_object_class_install_property (G_OBJECT_CLASS (klass), PROP_CONFIG_INTERVAL,
-      g_param_spec_uint ("config-interval", "Config Send Interval",
+      g_param_spec_int ("config-interval", "Config Send Interval",
           "Send Config Insertion Interval in seconds (configuration headers "
-          "will be multiplexed in the data stream when detected.) (0 = disabled)",
-          0, 3600, DEFAULT_CONFIG_INTERVAL,
+          "will be multiplexed in the data stream when detected.) "
+          "(0 = disabled, -1 = send with every IDR frame)",
+          -1, 3600, DEFAULT_CONFIG_INTERVAL,
           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)
       );
 
@@ -266,7 +267,7 @@ gst_rtp_mp4v_pay_flush (GstRtpMP4VPay * rtpmp4vpay)
     guint packet_len;
     GstRTPBuffer rtp = { NULL };
 
-    /* this will be the total lenght of the packet */
+    /* this will be the total length of the packet */
     packet_len = gst_rtp_buffer_calc_packet_len (avail, 0, 0);
 
     /* fill one MTU or all available bytes */
@@ -412,7 +413,7 @@ gst_rtp_mp4v_pay_depay_data (GstRtpMP4VPay * enc, guint8 * data, guint size,
   return result;
 }
 
-/* we expect buffers starting on startcodes. 
+/* we expect buffers starting on startcodes.
  */
 static GstFlowReturn
 gst_rtp_mp4v_pay_handle_buffer (GstRTPBasePayload * basepayload,
@@ -429,6 +430,7 @@ gst_rtp_mp4v_pay_handle_buffer (GstRTPBasePayload * basepayload,
   GstClockTime timestamp, duration;
   gboolean vopi;
   gboolean send_config;
+  GstClockTime running_time = GST_CLOCK_TIME_NONE;
 
   ret = GST_FLOW_OK;
   send_config = FALSE;
@@ -457,8 +459,10 @@ gst_rtp_mp4v_pay_handle_buffer (GstRTPBasePayload * basepayload,
   gst_buffer_unmap (buffer, &map);
 
   if (strip) {
-    /* strip off config if requested */
-    if (!(rtpmp4vpay->config_interval > 0)) {
+    /* strip off config if requested, do not strip off if the
+     * config_interval is set to -1 */
+    if (!(rtpmp4vpay->config_interval > 0)
+        && !(rtpmp4vpay->config_interval == -1)) {
       GstBuffer *subbuf;
 
       GST_LOG_OBJECT (rtpmp4vpay, "stripping config at %d, size %d", strip,
@@ -473,7 +477,7 @@ gst_rtp_mp4v_pay_handle_buffer (GstRTPBasePayload * basepayload,
 
       size = gst_buffer_get_size (buffer);
     } else {
-      GstClockTime running_time =
+      running_time =
           gst_segment_to_running_time (&basepayload->segment, GST_FORMAT_TIME,
           timestamp);
 
@@ -484,7 +488,7 @@ gst_rtp_mp4v_pay_handle_buffer (GstRTPBasePayload * basepayload,
 
   /* there is a config request, see if we need to insert it */
   if (vopi && (rtpmp4vpay->config_interval > 0) && rtpmp4vpay->config) {
-    GstClockTime running_time =
+    running_time =
         gst_segment_to_running_time (&basepayload->segment, GST_FORMAT_TIME,
         timestamp);
 
@@ -516,20 +520,26 @@ gst_rtp_mp4v_pay_handle_buffer (GstRTPBasePayload * basepayload,
       GST_DEBUG_OBJECT (rtpmp4vpay, "no previous config time, send now");
       send_config = TRUE;
     }
+  }
 
-    if (send_config) {
-      /* we need to send config now first */
-      GST_LOG_OBJECT (rtpmp4vpay, "inserting config in stream");
+  if (vopi && (rtpmp4vpay->config_interval == -1)) {
+    GST_DEBUG_OBJECT (rtpmp4vpay, "sending config before current IDR frame");
+    /* send config before every IDR frame */
+    send_config = TRUE;
+  }
 
-      /* insert header */
-      buffer = gst_buffer_append (gst_buffer_ref (rtpmp4vpay->config), buffer);
+  if (send_config) {
+    /* we need to send config now first */
+    GST_LOG_OBJECT (rtpmp4vpay, "inserting config in stream");
 
-      GST_BUFFER_PTS (buffer) = timestamp;
-      size = gst_buffer_get_size (buffer);
+    /* insert header */
+    buffer = gst_buffer_append (gst_buffer_ref (rtpmp4vpay->config), buffer);
 
-      if (running_time != -1) {
-        rtpmp4vpay->last_config = running_time;
-      }
+    GST_BUFFER_PTS (buffer) = timestamp;
+    size = gst_buffer_get_size (buffer);
+
+    if (running_time != -1) {
+      rtpmp4vpay->last_config = running_time;
     }
   }
 
@@ -596,7 +606,7 @@ gst_rtp_mp4v_pay_set_property (GObject * object, guint prop_id,
 
   switch (prop_id) {
     case PROP_CONFIG_INTERVAL:
-      rtpmp4vpay->config_interval = g_value_get_uint (value);
+      rtpmp4vpay->config_interval = g_value_get_int (value);
       break;
     default:
       break;
@@ -613,7 +623,7 @@ gst_rtp_mp4v_pay_get_property (GObject * object, guint prop_id,
 
   switch (prop_id) {
     case PROP_CONFIG_INTERVAL:
-      g_value_set_uint (value, rtpmp4vpay->config_interval);
+      g_value_set_int (value, rtpmp4vpay->config_interval);
       break;
     default:
       break;