---
 gst/rtp/gstrtph264pay.c |   96 +++++++++++++++++++++++++++++++++++++++++++++++-
 gst/rtp/gstrtph264pay.h |    3 +
 2 files changed, 98 insertions(+), 1 deletion(-)

Index: gst-plugins-good0.10-0.10.17/gst/rtp/gstrtph264pay.c
===================================================================
--- gst-plugins-good0.10-0.10.17.orig/gst/rtp/gstrtph264pay.c
+++ gst-plugins-good0.10-0.10.17/gst/rtp/gstrtph264pay.c
@@ -1,3 +1,4 @@
+/* ex: set tabstop=2 shiftwidth=2 expandtab: */
 /* GStreamer
  *
  * This library is free software; you can redistribute it and/or
@@ -27,6 +28,7 @@
 #include "gstrtph264pay.h"
 
 
+#define IDR_TYPE_ID  5
 #define SPS_TYPE_ID  7
 #define PPS_TYPE_ID  8
 #define USE_MEMCMP
@@ -91,6 +93,7 @@
 #define DEFAULT_SPROP_PARAMETER_SETS    NULL
 #define DEFAULT_SCAN_MODE               GST_H264_SCAN_MODE_MULTI_NAL
 #define DEFAULT_BUFFER_LIST             FALSE
+#define DEFAULT_SPSPPS_SEND		(-1)
 
 enum
 {
@@ -99,6 +102,7 @@
   PROP_SPROP_PARAMETER_SETS,
   PROP_SCAN_MODE,
   PROP_BUFFER_LIST,
+  PROP_SPSPPS_SEND,
   PROP_LAST
 };
 
@@ -172,6 +176,17 @@
           "Use Buffer Lists",
           DEFAULT_BUFFER_LIST, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
+  g_object_class_install_property (G_OBJECT_CLASS (klass),
+      PROP_SPSPPS_SEND,
+      g_param_spec_int("spspps-send",
+        "SPS PPS Send Interval",
+        "Send SPS and PPS Insertion Interval (sprop parameter sets "
+        "will be multiplexed in the data stream when detected. "
+        "-1 to disable)",
+        -1, 3600, DEFAULT_SPSPPS_SEND,
+        G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)
+      );
+
   gobject_class->finalize = gst_rtp_h264_pay_finalize;
 
   gstbasertppayload_class->set_caps = gst_rtp_h264_pay_setcaps;
@@ -190,6 +205,8 @@
   rtph264pay->pps = NULL;
   rtph264pay->scan_mode = GST_H264_SCAN_MODE_MULTI_NAL;
   rtph264pay->buffer_list = DEFAULT_BUFFER_LIST;
+  rtph264pay->spspps_send = DEFAULT_SPSPPS_SEND;
+  rtph264pay->timer = g_timer_new();
 }
 
 static void
@@ -207,6 +224,8 @@
   g_free (rtph264pay->profile_level_id);
   g_free (rtph264pay->sprop_parameter_sets);
 
+  g_timer_destroy(rtph264pay->timer);
+
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
@@ -850,7 +869,76 @@
          * go parse it for SPS/PPS to enrich the caps */
         /* order: make sure to check nal */
         update = gst_rtp_h264_pay_decode_nal (rtph264pay, data, nal_len) ||
-            update;
+          update;
+        /* In some encoders, NAL 7 and 8 are sent out of band
+         * (e.g. RTSP). rtph264depay inserts these at the beginning of the
+         * stream. As a result; decoders can only pick in on the network
+         * stream if they were running when these packets are sent. The
+         * following re-inserts these packets every interval seconds;
+         * allowing the decoders to pick in on any time. */
+        if(rtph264pay->spspps_send > -1){
+          guint8 header = data[0];
+          guint8 type =  header & 0x1f;
+
+          if ((SPS_TYPE_ID == type)
+              || (PPS_TYPE_ID == type)) {
+            /* We got a NAL 7/8 type packet, reset timer and let it
+             * be handled off normally */
+            g_timer_start (rtph264pay->timer);
+          }
+          else if(type == IDR_TYPE_ID){
+            /* timeout, only insert before IDR to avoid short bad data
+             * (max limited by spspps_send time) */
+            GstClockTime elapsed;
+            GstBuffer *sps = NULL, *pps = NULL;
+
+            elapsed = g_timer_elapsed (rtph264pay->timer, NULL);
+
+            if(elapsed >= (double)rtph264pay->spspps_send){
+              GST_LOG ("Timeout, re-sending SPS/PPS");
+
+              /* resend SPS */
+              sps = gst_buffer_new_and_alloc(rtph264pay->sps_len);
+
+              gst_buffer_set_data(sps, rtph264pay->sps, rtph264pay->sps_len);
+
+              /* put the data in one or more RTP packets */
+              ret = gst_rtp_h264_pay_payload_nal (
+                  basepayload,
+                  GST_BUFFER_DATA(sps),
+                  GST_BUFFER_SIZE(sps),
+                  GST_BUFFER_TIMESTAMP(sps),
+                  sps);
+
+              /* Not critical here; but throw a warning */
+              if (ret != GST_FLOW_OK)
+                GST_WARNING ("Problem pushing SPS");
+
+              gst_buffer_unref (sps);
+
+              /* resend PPS */
+              pps = gst_buffer_new_and_alloc(rtph264pay->pps_len);
+              gst_buffer_set_data(pps, rtph264pay->pps, rtph264pay->pps_len);
+
+              /* put the data in one or more RTP packets */
+              ret = gst_rtp_h264_pay_payload_nal (
+                  basepayload,
+                  GST_BUFFER_DATA(pps),
+                  GST_BUFFER_SIZE(pps),
+                  GST_BUFFER_TIMESTAMP(pps),
+                  pps);
+
+              /* Not critical here; but throw a warning */
+              if (ret != GST_FLOW_OK)
+                GST_WARNING("Problem pushing PPS");
+
+              gst_buffer_unref (pps);
+
+              g_timer_start (rtph264pay->timer);
+            }
+          }
+
+        }
       }
       /* move to next NAL packet */
       data += nal_len;
@@ -915,6 +1003,9 @@
     case PROP_BUFFER_LIST:
       rtph264pay->buffer_list = g_value_get_boolean (value);
       break;
+    case PROP_SPSPPS_SEND:
+      rtph264pay->spspps_send = g_value_get_int(value);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -942,6 +1033,9 @@
     case PROP_BUFFER_LIST:
       g_value_set_boolean (value, rtph264pay->buffer_list);
       break;
+    case PROP_SPSPPS_SEND:
+      g_value_set_int(value,rtph264pay->spspps_send);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
Index: gst-plugins-good0.10-0.10.17/gst/rtp/gstrtph264pay.h
===================================================================
--- gst-plugins-good0.10-0.10.17.orig/gst/rtp/gstrtph264pay.h
+++ gst-plugins-good0.10-0.10.17/gst/rtp/gstrtph264pay.h
@@ -63,6 +63,9 @@
   gboolean update_caps;
   GstH264ScanMode scan_mode;
 
+  gint spspps_send;
+  GTimer *timer;
+
   gboolean buffer_list;
 };
 
