Index: gstrtph264pay.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-good/gst/rtp/gstrtph264pay.c,v
retrieving revision 1.5
diff -u -B -b -p -r1.5 gstrtph264pay.c
--- gstrtph264pay.c	9 Jan 2008 11:11:00 -0000	1.5
+++ gstrtph264pay.c	12 Feb 2008 14:54:23 -0000
@@ -383,6 +383,7 @@ gst_rtp_h264_pay_parse_sps_pps (GstBaseR
     GST_DEBUG ("outcaps udpate: profile=%s, sps=%s, pps=%s\n",
         profile, sps, pps);
 
+    g_free (sprops);
     g_free (profile);
     g_free (sps);
     g_free (pps);
@@ -431,6 +432,7 @@ gst_rtp_h264_pay_handle_buffer (GstBaseR
   if (idxdata < 5) {
     GST_DEBUG_OBJECT (basepayload,
         "Returning GST_FLOW_OK without creating RTP packet");
+    gst_buffer_unref (buffer);
     return GST_FLOW_OK;
   }
 
Index: gstrtpmp4gdepay.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-good/gst/rtp/gstrtpmp4gdepay.c,v
retrieving revision 1.15
diff -u -B -b -p -r1.15 gstrtpmp4gdepay.c
--- gstrtpmp4gdepay.c	9 Jan 2008 11:11:00 -0000	1.15
+++ gstrtpmp4gdepay.c	12 Feb 2008 14:54:23 -0000
@@ -223,11 +223,9 @@ gst_rtp_mp4g_depay_setcaps (GstBaseRTPDe
       GstBuffer *buffer;
 
       buffer = gst_value_get_buffer (&v);
-      gst_buffer_ref (buffer);
-      g_value_unset (&v);
-
       gst_caps_set_simple (srccaps,
           "codec_data", GST_TYPE_BUFFER, buffer, NULL);
+      g_value_unset (&v);
     } else {
       g_warning ("cannot convert config to buffer");
     }
Index: gstrtpmp4gpay.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-good/gst/rtp/gstrtpmp4gpay.c,v
retrieving revision 1.19
diff -u -B -b -p -r1.19 gstrtpmp4gpay.c
--- gstrtpmp4gpay.c	9 Jan 2008 11:11:00 -0000	1.19
+++ gstrtpmp4gpay.c	12 Feb 2008 14:54:23 -0000
@@ -85,6 +85,8 @@ static void gst_rtp_mp4g_pay_finalize (G
 
 static gboolean gst_rtp_mp4g_pay_setcaps (GstBaseRTPPayload * payload,
     GstCaps * caps);
+static GstStateChangeReturn gst_rtp_mp4g_pay_change_state (GstElement * element,
+    GstStateChange transition);
 static GstFlowReturn gst_rtp_mp4g_pay_handle_buffer (GstBaseRTPPayload *
     payload, GstBuffer * buffer);
 
@@ -143,6 +145,8 @@ gst_rtp_mp4g_pay_class_init (GstRtpMP4GP
 
   gobject_class->finalize = gst_rtp_mp4g_pay_finalize;
 
+  gstelement_class->change_state = gst_rtp_mp4g_pay_change_state;
+
   gstbasertppayload_class->set_caps = gst_rtp_mp4g_pay_setcaps;
   gstbasertppayload_class->handle_buffer = gst_rtp_mp4g_pay_handle_buffer;
 
@@ -171,6 +176,10 @@ gst_rtp_mp4g_pay_finalize (GObject * obj
   g_free (rtpmp4gpay->params);
   rtpmp4gpay->params = NULL;
 
+  if (rtpmp4gpay->config)
+    gst_buffer_unref (rtpmp4gpay->config);
+  rtpmp4gpay->config = NULL;
+
   g_free (rtpmp4gpay->profile);
   rtpmp4gpay->profile = NULL;
 
@@ -504,7 +513,8 @@ gst_rtp_mp4g_pay_flush (GstRtpMP4GPay * 
     /* marker only if the packet is complete */
     gst_rtp_buffer_set_marker (outbuf, avail <= payload_len);
 
-    GST_BUFFER_TIMESTAMP (outbuf) = rtpmp4gpay->first_ts;
+    GST_BUFFER_TIMESTAMP (outbuf) = rtpmp4gpay->first_timestamp;
+    GST_BUFFER_DURATION (outbuf) = rtpmp4gpay->first_duration;
 
     ret = gst_basertppayload_push (GST_BASE_RTP_PAYLOAD (rtpmp4gpay), outbuf);
 
@@ -528,7 +538,8 @@ gst_rtp_mp4g_pay_handle_buffer (GstBaseR
 
   rtpmp4gpay = GST_RTP_MP4G_PAY (basepayload);
 
-  rtpmp4gpay->first_ts = GST_BUFFER_TIMESTAMP (buffer);
+  rtpmp4gpay->first_timestamp = GST_BUFFER_TIMESTAMP (buffer);
+  rtpmp4gpay->first_duration = GST_BUFFER_DURATION (buffer);
 
   /* we always encode and flush a full AU */
   gst_adapter_push (rtpmp4gpay->adapter, buffer);
@@ -537,6 +548,29 @@ gst_rtp_mp4g_pay_handle_buffer (GstBaseR
   return ret;
 }
 
+static GstStateChangeReturn
+gst_rtp_mp4g_pay_change_state (GstElement * element, GstStateChange transition)
+{
+  GstRtpMP4GPay *rtpmp4gpay;
+  GstStateChangeReturn ret;
+
+  rtpmp4gpay = GST_RTP_MP4G_PAY (element);
+
+  switch (transition) {
+    default:
+      break;
+  }
+
+  ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
+
+  switch (transition) {
+    default:
+      break;
+  }
+  return ret;
+}
+
+
 gboolean
 gst_rtp_mp4g_pay_plugin_init (GstPlugin * plugin)
 {
Index: gstrtpmp4gpay.h
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-good/gst/rtp/gstrtpmp4gpay.h,v
retrieving revision 1.7
diff -u -B -b -p -r1.7 gstrtpmp4gpay.h
--- gstrtpmp4gpay.h	21 Sep 2006 09:35:13 -0000	1.7
+++ gstrtpmp4gpay.h	12 Feb 2008 14:54:23 -0000
@@ -45,7 +45,8 @@ struct _GstRtpMP4GPay
   GstBaseRTPPayload    payload;
 
   GstAdapter   *adapter;
-  GstClockTime  first_ts;
+  GstClockTime  first_timestamp;
+  GstClockTime  first_duration;
   GstClockTime  duration;
 
   gint          rate;
Index: gstrtptheorapay.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-good/gst/rtp/gstrtptheorapay.c,v
retrieving revision 1.9
diff -u -B -b -p -r1.9 gstrtptheorapay.c
--- gstrtptheorapay.c	11 Jan 2008 17:21:30 -0000	1.9
+++ gstrtptheorapay.c	12 Feb 2008 14:54:23 -0000
@@ -79,6 +79,8 @@ GST_BOILERPLATE (GstRtpTheoraPay, gst_rt
 
 static gboolean gst_rtp_theora_pay_setcaps (GstBaseRTPPayload * basepayload,
     GstCaps * caps);
+static GstStateChangeReturn gst_rtp_theora_pay_change_state (GstElement * element,
+    GstStateChange transition);
 static GstFlowReturn gst_rtp_theora_pay_handle_buffer (GstBaseRTPPayload * pad,
     GstBuffer * buffer);
 
@@ -108,6 +110,8 @@ gst_rtp_theora_pay_class_init (GstRtpThe
 
   parent_class = g_type_class_peek_parent (klass);
 
+  gstelement_class->change_state = gst_rtp_theora_pay_change_state;
+
   gstbasertppayload_class->set_caps = gst_rtp_theora_pay_setcaps;
   gstbasertppayload_class->handle_buffer = gst_rtp_theora_pay_handle_buffer;
 
@@ -122,6 +126,18 @@ gst_rtp_theora_pay_init (GstRtpTheoraPay
   /* needed because of GST_BOILERPLATE */
 }
 
+static void
+gst_rtp_theora_pay_cleanup (GstRtpTheoraPay *rtptheorapay)
+{
+  g_list_foreach (rtptheorapay->headers, (GFunc) gst_mini_object_unref, NULL);
+  g_list_free (rtptheorapay->headers);
+  rtptheorapay->headers = NULL;
+
+  if (rtptheorapay->packet)
+    gst_buffer_unref (rtptheorapay->packet);
+  rtptheorapay->packet = NULL;
+}
+
 static gboolean
 gst_rtp_theora_pay_setcaps (GstBaseRTPPayload * basepayload, GstCaps * caps)
 {
@@ -624,6 +640,8 @@ gst_rtp_theora_pay_handle_buffer (GstBas
         rtptheorapay->payload_duration += duration;
     }
   }
+  gst_buffer_unref (buffer);
+
 done:
   return ret;
 
@@ -632,26 +650,55 @@ wrong_size:
   {
     GST_ELEMENT_WARNING (rtptheorapay, STREAM, DECODE,
         ("Invalid packet size (1 < %d <= 0xffff)", size), (NULL));
+    gst_buffer_unref (buffer);
     return GST_FLOW_OK;
   }
 parse_id_failed:
   {
+    gst_buffer_unref (buffer);
     return GST_FLOW_ERROR;
   }
 unknown_header:
   {
     GST_ELEMENT_WARNING (rtptheorapay, STREAM, DECODE,
         (NULL), ("Ignoring unknown header received"));
+    gst_buffer_unref (buffer);
     return GST_FLOW_OK;
   }
 header_error:
   {
     GST_ELEMENT_WARNING (rtptheorapay, STREAM, DECODE,
         (NULL), ("Error initializing header config"));
+    gst_buffer_unref (buffer);
     return GST_FLOW_OK;
   }
 }
 
+static GstStateChangeReturn
+gst_rtp_theora_pay_change_state (GstElement * element, GstStateChange transition)
+{
+  GstRtpTheoraPay *rtptheorapay;
+  GstStateChangeReturn ret;
+
+  rtptheorapay = GST_RTP_THEORA_PAY (element);
+
+  switch (transition) {
+    default:
+      break;
+  }
+
+  ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
+
+  switch (transition) {
+    case GST_STATE_CHANGE_PAUSED_TO_READY:
+      gst_rtp_theora_pay_cleanup (rtptheorapay);
+      break;
+    default:
+      break;
+  }
+  return ret;
+}
+
 gboolean
 gst_rtp_theora_pay_plugin_init (GstPlugin * plugin)
 {
Index: gstrtpvorbispay.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-good/gst/rtp/gstrtpvorbispay.c,v
retrieving revision 1.13
diff -u -B -b -p -r1.13 gstrtpvorbispay.c
--- gstrtpvorbispay.c	9 Jan 2008 11:11:01 -0000	1.13
+++ gstrtpvorbispay.c	12 Feb 2008 14:54:23 -0000
@@ -75,6 +75,8 @@ GST_BOILERPLATE (GstRtpVorbisPay, gst_rt
 
 static gboolean gst_rtp_vorbis_pay_setcaps (GstBaseRTPPayload * basepayload,
     GstCaps * caps);
+static GstStateChangeReturn gst_rtp_vorbis_pay_change_state (GstElement * element,
+    GstStateChange transition);
 static GstFlowReturn gst_rtp_vorbis_pay_handle_buffer (GstBaseRTPPayload * pad,
     GstBuffer * buffer);
 
@@ -104,6 +106,8 @@ gst_rtp_vorbis_pay_class_init (GstRtpVor
 
   parent_class = g_type_class_peek_parent (klass);
 
+  gstelement_class->change_state = gst_rtp_vorbis_pay_change_state;
+
   gstbasertppayload_class->set_caps = gst_rtp_vorbis_pay_setcaps;
   gstbasertppayload_class->handle_buffer = gst_rtp_vorbis_pay_handle_buffer;
 
@@ -118,6 +122,18 @@ gst_rtp_vorbis_pay_init (GstRtpVorbisPay
   /* needed because of GST_BOILERPLATE */
 }
 
+static void
+gst_rtp_vorbis_pay_cleanup (GstRtpVorbisPay *rtpvorbispay)
+{
+  g_list_foreach (rtpvorbispay->headers, (GFunc) gst_mini_object_unref, NULL);
+  g_list_free (rtpvorbispay->headers);
+  rtpvorbispay->headers = NULL;
+
+  if (rtpvorbispay->packet)
+    gst_buffer_unref (rtpvorbispay->packet);
+  rtpvorbispay->packet = NULL;
+}
+
 static gboolean
 gst_rtp_vorbis_pay_setcaps (GstBaseRTPPayload * basepayload, GstCaps * caps)
 {
@@ -623,6 +639,8 @@ gst_rtp_vorbis_pay_handle_buffer (GstBas
         rtpvorbispay->payload_duration += duration;
     }
   }
+  gst_buffer_unref (buffer);
+
 done:
   return ret;
 
@@ -631,26 +649,55 @@ wrong_size:
   {
     GST_ELEMENT_WARNING (rtpvorbispay, STREAM, DECODE,
         ("Invalid packet size (1 < %d <= 0xffff)", size), (NULL));
+    gst_buffer_unref (buffer);
     return GST_FLOW_OK;
   }
 parse_id_failed:
   {
+    gst_buffer_unref (buffer);
     return GST_FLOW_ERROR;
   }
 unknown_header:
   {
     GST_ELEMENT_WARNING (rtpvorbispay, STREAM, DECODE,
         (NULL), ("Ignoring unknown header received"));
+    gst_buffer_unref (buffer);
     return GST_FLOW_OK;
   }
 header_error:
   {
     GST_ELEMENT_WARNING (rtpvorbispay, STREAM, DECODE,
         (NULL), ("Error initializing header config"));
+    gst_buffer_unref (buffer);
     return GST_FLOW_OK;
   }
 }
 
+static GstStateChangeReturn
+gst_rtp_vorbis_pay_change_state (GstElement * element, GstStateChange transition)
+{
+  GstRtpVorbisPay *rtpvorbispay;
+  GstStateChangeReturn ret;
+
+  rtpvorbispay = GST_RTP_VORBIS_PAY (element);
+
+  switch (transition) {
+    default:
+      break;
+  }
+
+  ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
+
+  switch (transition) {
+    case GST_STATE_CHANGE_PAUSED_TO_READY:
+      gst_rtp_vorbis_pay_cleanup (rtpvorbispay);
+      break;
+    default:
+      break;
+  }
+  return ret;
+}
+
 gboolean
 gst_rtp_vorbis_pay_plugin_init (GstPlugin * plugin)
 {
