Index: gstmpegdemux.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-ugly/gst/mpegstream/gstmpegdemux.c,v
retrieving revision 1.84
diff -a -u -r1.84 gstmpegdemux.c
--- gstmpegdemux.c	30 Dec 2005 16:25:05 -0000	1.84
+++ gstmpegdemux.c	19 Jan 2006 16:38:59 -0000
@@ -225,6 +225,8 @@
 
   mpeg_demux->max_gap = GST_CLOCK_TIME_NONE;
   mpeg_demux->max_gap_tolerance = GST_CLOCK_TIME_NONE;
+
+  mpeg_demux->last_pts = -1;
 }
 
 static GstFlowReturn
@@ -682,6 +684,14 @@
       headerlen, datalen);
 
   if (pts != -1) {
+    /* Check for pts overflow */
+    if (mpeg_demux->last_pts != -1) {
+      gint32 diff = pts - mpeg_demux->last_pts;
+      if (diff > -4 * CLOCK_FREQ && diff < 4 * CLOCK_FREQ)
+        pts = mpeg_demux->last_pts + diff;
+    }
+    mpeg_demux->last_pts = pts;
+
     timestamp = PARSE_CLASS (mpeg_parse)->adjust_ts (mpeg_parse,
         MPEGTIME_TO_GSTTIME (pts));
 
@@ -780,6 +790,14 @@
       pts |= ((guint64) * buf++) << 7;
       pts |= ((guint64) (*buf++ & 0xFE)) >> 1;
 
+      /* Check for pts overflow */
+      if (mpeg_demux->last_pts != -1) {
+        gint32 diff = pts - mpeg_demux->last_pts;
+        if (diff > -4 * CLOCK_FREQ && diff < 4 * CLOCK_FREQ)
+          pts = mpeg_demux->last_pts + diff;
+      }
+      mpeg_demux->last_pts = pts;
+
       timestamp = PARSE_CLASS (mpeg_parse)->adjust_ts (mpeg_parse,
           MPEGTIME_TO_GSTTIME (pts));
 
@@ -903,6 +921,7 @@
 
   GST_BUFFER_TIMESTAMP (outbuf) = timestamp;
   GST_BUFFER_OFFSET (outbuf) = GST_BUFFER_OFFSET (buffer) + offset;
+  GST_BUFFER_CAPS (outbuf) = gst_caps_ref (outstream->caps);
   ret = gst_pad_push (outstream->pad, outbuf);
 
   if (GST_CLOCK_TIME_IS_VALID (mpeg_demux->max_gap) &&
@@ -1196,6 +1215,7 @@
   mpeg_demux->total_size_bound = 0LL;
 
   mpeg_demux->index = NULL;
+  mpeg_demux->last_pts = -1;
 
   /*
    * Don't adjust things that are only for subclass use
Index: gstmpegdemux.h
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-ugly/gst/mpegstream/gstmpegdemux.h,v
retrieving revision 1.23
diff -a -u -r1.23 gstmpegdemux.h
--- gstmpegdemux.h	27 Dec 2005 19:06:08 -0000	1.23
+++ gstmpegdemux.h	19 Jan 2006 16:39:00 -0000
@@ -123,6 +123,7 @@
   gboolean       packet_rate_restriction;
   gint64         total_size_bound;
 
+  gint64         last_pts;
   GstIndex      *index;
 
   /* stream output */
Index: gstmpegparse.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-ugly/gst/mpegstream/gstmpegparse.c,v
retrieving revision 1.84
diff -a -u -r1.84 gstmpegparse.c
--- gstmpegparse.c	10 Jan 2006 11:43:37 -0000	1.84
+++ gstmpegparse.c	19 Jan 2006 16:39:00 -0000
@@ -529,6 +529,15 @@
   }
   new_rate *= MP_MUX_RATE_MULT;
 
+  /* Deal with SCR overflow */
+  if (mpeg_parse->current_scr != MP_INVALID_SCR) {
+      guint32 diff;
+      diff = scr - mpeg_parse->current_scr;
+      if (diff < 4 * CLOCK_FREQ)
+          scr = mpeg_parse->current_scr + diff;
+  }
+
+  
   prev_scr = mpeg_parse->current_scr;
   mpeg_parse->current_scr = scr;
 
