changeset 12665:751a27fc8895

index creation/reading behaviour just like the avi demuxer, patch based on work by Reza Jelveh, Moritz Bunkus und myself
author alex
date Fri, 25 Jun 2004 18:45:56 +0000
parents a27908f9ddbc
children eaf04e9f66dc
files libmpdemux/demux_real.c
diffstat 1 files changed, 26 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/demux_real.c	Fri Jun 25 18:44:25 2004 +0000
+++ b/libmpdemux/demux_real.c	Fri Jun 25 18:45:56 2004 +0000
@@ -207,7 +207,6 @@
 	goto read_index;
 
 end:
-    demuxer->seekable = 1; /* got index, we're able to seek */
     if (i == -256)
 	stream_reset(demuxer->stream);
     stream_seek(demuxer->stream, origpos);
@@ -221,7 +220,7 @@
 
 static void add_index_item(demuxer_t *demuxer, int stream_id, int timestamp, int offset)
 {
-  if (index_mode > 0 && (unsigned)stream_id < MAX_STREAMS)
+  if ((unsigned)stream_id < MAX_STREAMS)
   {
     real_priv_t *priv = demuxer->priv;
     real_index_table_t *index;
@@ -242,7 +241,6 @@
     index = &priv->index_table[stream_id][priv->index_table_size[stream_id]++];
     index->timestamp = timestamp;
     index->offset = offset;
-    demuxer->seekable = 1;
   }
 }
 
@@ -308,13 +306,11 @@
     stream_skip(demuxer->stream, 14);
     add_index_segment(demuxer, -1, -1);
   }
-  demuxer->seekable = 0;
   for (i = 0; i < MAX_STREAMS; i++)
   {
     if (priv->index_table_size[i] > 0)
     {
       dump_index(demuxer, i);
-      demuxer->seekable = 1; /* got index, we're able to seek */
     }
   }
   stream_reset(demuxer->stream);
@@ -406,7 +402,6 @@
 	goto read_index;
 
 end:
-    demuxer->seekable = 1; /* got index, we're able to seek */
     if (i == -256)
 	stream_reset(demuxer->stream);
     stream_seek(demuxer->stream, origpos);
@@ -1461,16 +1456,35 @@
     if (priv->num_of_packets == 0)
 	priv->num_of_packets = -10;
 
-    /* disable seeking */
-    demuxer->seekable = 0;
 
     priv->audio_need_keyframe = 0;
     priv->video_after_seek = 0;
 
-    if (index_mode == 2)
-	generate_index(demuxer);
-    else if (priv->index_chunk_offset && (index_mode == 1))
-	parse_index_chunk(demuxer);
+    switch (index_mode){
+	case -1: // untouched
+	    if (priv->index_chunk_offset && (priv->index_chunk_offset < demuxer->movi_end))
+	    {
+		parse_index_chunk(demuxer);
+		demuxer->seekable = 1;
+	    }
+	    break;
+	case 1: // use (generate index)
+	    if (priv->index_chunk_offset && (priv->index_chunk_offset < demuxer->movi_end))
+	    {
+		parse_index_chunk(demuxer);
+		demuxer->seekable = 1;
+	    } else {
+		generate_index(demuxer);
+		demuxer->seekable = 1;
+	    }
+	    break;
+	case 2: // force generating index
+	    generate_index(demuxer);
+	    demuxer->seekable = 1;
+	    break;
+	default: // do nothing
+    	    break;
+    }
 
     // detect streams:
     if(demuxer->video->id==-1 && v_streams>0){
@@ -1521,8 +1535,6 @@
     int streams = 0;
     int retried = 0;
 
-    if ((index_mode != 1) && (index_mode != 2))
-	return 0;
 
     if (sh_video && (unsigned)vid < MAX_STREAMS && priv->index_table_size[vid])
 	streams |= 1;