ext/ffmpeg/gstffmpegprotocol.c: Some "seeking" hacks, and separate peek from read...
authorRonald S. Bultje <rbultje@ronald.bitfreak.net>
Sun, 19 Dec 2004 00:32:13 +0000 (00:32 +0000)
committerRonald S. Bultje <rbultje@ronald.bitfreak.net>
Sun, 19 Dec 2004 00:32:13 +0000 (00:32 +0000)
Original commit message from CVS:
* ext/ffmpeg/gstffmpegprotocol.c: (gst_ffmpegdata_peek),
(gst_ffmpegdata_read), (gst_ffmpegdata_seek):
Some "seeking" hacks, and separate peek from read (read = peek +
flush) so seek can use peek as well to workaround typefind. With
this, I'm able to play several of the gaming format movies in
Totem.

ChangeLog
ext/ffmpeg/gstffmpegprotocol.c

index 69e6903..d77b1b8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2004-12-19  Ronald S. Bultje  <rbultje@ronald.bitfreak.net>
+
+       * ext/ffmpeg/gstffmpegprotocol.c: (gst_ffmpegdata_peek),
+       (gst_ffmpegdata_read), (gst_ffmpegdata_seek):
+         Some "seeking" hacks, and separate peek from read (read = peek +
+         flush) so seek can use peek as well to workaround typefind. With
+         this, I'm able to play several of the gaming format movies in
+         Totem.
+
 2004-12-18  Ronald S. Bultje  <rbultje@ronald.bitfreak.net>
 
        * ext/ffmpeg/Makefile.am:
index 51af68b..b757aa8 100644 (file)
@@ -90,7 +90,7 @@ gst_ffmpegdata_open (URLContext * h, const char *filename, int flags)
 }
 
 static int
-gst_ffmpegdata_read (URLContext * h, unsigned char *buf, int size)
+gst_ffmpegdata_peek (URLContext * h, unsigned char *buf, int size)
 {
   GstByteStream *bs;
   guint32 total, request;
@@ -159,12 +159,28 @@ gst_ffmpegdata_read (URLContext * h, unsigned char *buf, int size)
   } while ((!info->eos && total != request) || have_event);
 
   memcpy (buf, data, total);
-  gst_bytestream_flush_fast (bs, total);
 
   return total;
 }
 
 static int
+gst_ffmpegdata_read (URLContext * h, unsigned char *buf, int size)
+{
+  gint res;
+  GstByteStream *bs;
+  GstProtocolInfo *info;
+
+  info = (GstProtocolInfo *) h->priv_data;
+  bs = info->bs;
+  res = gst_ffmpegdata_peek (h, buf, size);
+  if (res > 0) {
+    gst_bytestream_flush_fast (bs, res);
+  }
+
+  return res;
+}
+
+static int
 gst_ffmpegdata_write (URLContext * h, unsigned char *buf, int size)
 {
   GstProtocolInfo *info;
@@ -195,19 +211,18 @@ gst_ffmpegdata_seek (URLContext * h, offset_t pos, int whence)
 
   /* get data (typefind hack) */
   if (gst_bytestream_tell (info->bs) != gst_bytestream_length (info->bs)) {
-    //gchar buf;
-    //gst_ffmpegdata_read (h, &buf, 1);
-    //peek!!!!! not read = data loss if not seekable
+    gchar buf;
+    gst_ffmpegdata_peek (h, &buf, 1);
   }
 
   /* hack in ffmpeg to get filesize... */
   if (whence == SEEK_END && pos == -1)
     return gst_bytestream_length (info->bs) - 1;
+  else if (whence == SEEK_END && pos == 0)
+    return gst_bytestream_length (info->bs);
   /* another hack to get the current position... */
   else if (whence == SEEK_CUR && pos == 0)
     return gst_bytestream_tell (info->bs);
-  //else
-    //g_assert (pos >= 0);
 
   switch (whence) {
     case SEEK_SET: