Index: gst/asfdemux/gstasfdemux.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-ugly/gst/asfdemux/gstasfdemux.c,v
retrieving revision 1.121
diff -a -u -r1.121 gstasfdemux.c
--- gst/asfdemux/gstasfdemux.c	15 Feb 2007 19:55:55 -0000	1.121
+++ gst/asfdemux/gstasfdemux.c	8 Mar 2007 10:38:48 -0000
@@ -50,6 +50,12 @@
     GST_PAD_SOMETIMES,
     GST_STATIC_CAPS_ANY);
 
+/* Time interval of newsegments when there are no data in milliseconds */
+#define NEWSEGMENT_INTERVAL 500
+
+/* Maximal delay between streams ub milliseconds */
+#define MAX_STREAM_DELAY 1000
+
 /* size of an ASF object header, ie. GUID (16 bytes) + object size (8 bytes) */
 #define ASF_OBJECT_HEADER_SIZE  (16+8)
 
@@ -179,6 +185,7 @@
         }
         demux->stream[n].need_newsegment = TRUE;
         demux->stream[n].last_pts = GST_CLOCK_TIME_NONE;
+        demux->stream[n].last_segment_pts = GST_CLOCK_TIME_NONE;
         demux->stream[n].sequence = 0;
       }
 
@@ -878,6 +885,7 @@
   stream->delay = 0;
   stream->first_pts = GST_CLOCK_TIME_NONE;
   stream->last_pts = GST_CLOCK_TIME_NONE;
+  stream->last_segment_pts = GST_CLOCK_TIME_NONE;
   stream->fps_known = !is_video;        /* bit hacky for audio */
   stream->is_video = is_video;
   stream->need_newsegment = TRUE;
@@ -2176,11 +2184,21 @@
   return ret;
 }
 
-static GstFlowReturn
-gst_asf_demux_push_buffer (GstASFDemux * demux, asf_stream_context * stream,
-    GstBuffer * buf)
+/*
+ * Send a newsegment to the stream. This function sends initial newsegment if needed
+ * and update newsegment if requested.
+ */
+static void
+gst_asf_demux_send_newsegment (GstASFDemux * demux, asf_stream_context * stream,
+                               gint64 update_start)
 {
-  GstFlowReturn ret;
+  gboolean is_update;
+  gint64 start;
+
+  g_return_if_fail (stream->need_newsegment || update_start != GST_CLOCK_TIME_NONE);
+
+  is_update = stream->need_newsegment ? FALSE : TRUE;
+  start = stream->need_newsegment ? demux->segment.start : update_start;
 
   /* do we need to send a newsegment event? */
   if (stream->need_newsegment) {
@@ -2188,17 +2206,33 @@
         GST_TIME_FORMAT, GST_PAD_NAME (stream->pad),
         GST_TIME_ARGS (demux->segment.start),
         GST_TIME_ARGS (demux->segment.stop));
+  }
 
-    /* FIXME: if we need to send a newsegment event on this pad and
-     * the buffer doesn't have a timestamp, should we just drop the buffer
-     * and wait for one with a timestamp before sending it? */
-    /* FIXME: last parameter in newsegment isn't right, is it?! */
-    gst_pad_push_event (stream->pad,
-        gst_event_new_new_segment (FALSE, demux->segment.rate, GST_FORMAT_TIME,
-            demux->segment.start, demux->segment.stop, demux->segment.start));
+  /* FIXME: if we need to send a newsegment event on this pad and
+   * the buffer doesn't have a timestamp, should we just drop the buffer
+   * and wait for one with a timestamp before sending it? */
+  /* FIXME: last parameter in newsegment isn't right, is it?! */
+  gst_pad_push_event (stream->pad,
+      gst_event_new_new_segment (is_update, demux->segment.rate, GST_FORMAT_TIME,
+          start, demux->segment.stop, demux->segment.start));
 
+  if (stream->need_newsegment) {
     stream->need_newsegment = FALSE;
+    /* Send update new segment after initial newsegment if requested */
+    if (update_start != GST_CLOCK_TIME_NONE)
+      gst_asf_demux_send_newsegment (demux, stream, update_start);
   }
+}
+
+static GstFlowReturn
+gst_asf_demux_push_buffer (GstASFDemux * demux, asf_stream_context * stream,
+    GstBuffer * buf)
+{
+  GstFlowReturn ret;
+
+  /* do we need to send a newsegment event? */
+  if (stream->need_newsegment)
+    gst_asf_demux_send_newsegment (demux, stream, GST_CLOCK_TIME_NONE);
 
   /* need to send tags? */
   if (stream->pending_tags) {
@@ -2356,6 +2390,8 @@
   if (stream->frag_offset < segment_info->segment_size) {
     /* We don't have the whole packet yet */
   } else {
+    int n;
+
     /* We have the whole packet now so we should push the packet to
        the src pad now. First though we should check if we need to do
        descrambling */
@@ -2371,6 +2407,33 @@
           GST_TIME_ARGS ((GST_SECOND / 1000) * stream->last_pts));
     }
 
+    /* Send update newsegments if pad has not data for some time */
+    for (n = 0; n < demux->num_streams; n++) {
+      guint64 stream_pts = demux->stream[n].last_pts;
+
+      /* Do not send newsegments if a buffer is deing depayloaded */
+      if (demux->stream[n].frag_offset > 0)
+        continue;
+
+      /* Do not send a buffer to the current stream */
+      if (&demux->stream[n] == stream)
+        continue;
+
+      if (G_UNLIKELY(!GST_CLOCK_TIME_IS_VALID (stream_pts)))
+        stream_pts = 0;
+
+      if (GST_CLOCK_TIME_IS_VALID (demux->stream[n].last_segment_pts)
+          && demux->stream[n].last_segment_pts > stream_pts)
+          stream_pts = demux->stream[n].last_segment_pts;
+
+      /* Check if we need to send a newsegment */
+      if (stream_pts + NEWSEGMENT_INTERVAL + MAX_STREAM_DELAY <= demux->pts) {
+        demux->stream[n].last_segment_pts = demux->pts - MAX_STREAM_DELAY;
+        gst_asf_demux_send_newsegment (demux, &demux->stream[n],
+            GST_MSECOND * demux->stream[n].last_segment_pts);
+      }
+    }
+
     /* FIXME: last_pts is not a GstClockTime and not in nanoseconds, so
      * this is not really 100% right ... */
     if (demux->pts >= stream->last_pts ||
Index: gst/asfdemux/gstasfdemux.h
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-ugly/gst/asfdemux/gstasfdemux.h,v
retrieving revision 1.26
diff -a -u -r1.26 gstasfdemux.h
--- gst/asfdemux/gstasfdemux.h	15 Feb 2007 19:55:55 -0000	1.26
+++ gst/asfdemux/gstasfdemux.h	8 Mar 2007 10:38:48 -0000
@@ -49,6 +49,7 @@
   guint64     delay;
   guint64     first_pts;
   guint64     last_pts;
+  guint64     last_segment_pts;
   GstBuffer  *payload;
 
   gboolean    need_newsegment;  /* do we need to send a new-segment event? */
