Index: ext/ogg/gstoggdemux.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-base/ext/ogg/gstoggdemux.c,v
retrieving revision 1.107
diff -u -w -p -r1.107 gstoggdemux.c
--- ext/ogg/gstoggdemux.c	18 Oct 2005 13:20:29 -0000	1.107
+++ ext/ogg/gstoggdemux.c	18 Oct 2005 20:52:25 -0000
@@ -1791,6 +1791,10 @@ gst_ogg_demux_read_chain (GstOggDemux * 
   /* now read pages until we receive a buffer from each of the
    * stream decoders, this will tell us the timestamp of the
    * first packet in the chain then */
+ 
+  /* save the offset to the first non bos page in the chain */
+  offset = ogg->offset;
+  
   done = FALSE;
   while (!done) {
     glong serial;
@@ -1816,6 +1820,10 @@ gst_ogg_demux_read_chain (GstOggDemux * 
     }
   }
   GST_LOG_OBJECT (ogg, "done reading chain");
+  
+  /* seek back to the first non bos page in the chain */
+  gst_ogg_demux_seek (ogg, offset);
+  
   /* now we can fill in the missing info using queries */
   for (i = 0; i < chain->streams->len; i++) {
     GstOggPad *pad = g_array_index (chain->streams, GstOggPad *, i);
@@ -1840,13 +1848,14 @@ static gint
 gst_ogg_demux_read_end_chain (GstOggDemux * ogg, GstOggChain * chain)
 {
   gint64 begin = chain->end_offset;
-  gint64 end = begin;
+  gint64 end;
   gint64 ret;
   gboolean done = FALSE;
   ogg_page og;
   gint i;
 
   while (!done) {
+    end = begin;
     begin -= CHUNKSIZE;
     if (begin < 0)
       begin = 0;
@@ -1863,7 +1872,7 @@ gst_ogg_demux_read_end_chain (GstOggDemu
       if (ret < 0) {
         break;
       } else {
-        done = TRUE;
+        done = FALSE;
         for (i = 0; i < chain->streams->len; i++) {
           GstOggPad *pad = g_array_index (chain->streams, GstOggPad *, i);
 
@@ -1873,8 +1882,9 @@ gst_ogg_demux_read_end_chain (GstOggDemu
             if (pad->last_granule < granulepos) {
               pad->last_granule = granulepos;
             }
-          } else {
-            done &= (pad->last_granule != -1);
+
+            done = TRUE;
+            break;
           }
         }
       }
@@ -1886,7 +1896,7 @@ gst_ogg_demux_read_end_chain (GstOggDemu
     GstFormat target;
 
     target = GST_FORMAT_TIME;
-    if (!gst_pad_query_convert (pad->elem_pad,
+    if (pad->last_granule != -1 && !gst_pad_query_convert (pad->elem_pad,
             GST_FORMAT_DEFAULT, pad->last_granule, &target,
             (gint64 *) & pad->last_time)) {
       g_warning ("could not convert granule to time");
