[NUT-devel] [nut]: r248 - trunk/libnut/demuxer.c

ods15 subversion at mplayerhq.hu
Sat Nov 18 20:15:51 CET 2006


Author: ods15
Date: Sat Nov 18 20:15:51 2006
New Revision: 248

Modified:
   trunk/libnut/demuxer.c

Log:
some fixes to prevent too many seeks and searches


Modified: trunk/libnut/demuxer.c
==============================================================================
--- trunk/libnut/demuxer.c	(original)
+++ trunk/libnut/demuxer.c	Sat Nov 18 20:15:51 2006
@@ -843,13 +843,14 @@
 	int i = fss->i, err = 0;
 	off_t pos = fss->i ? fss->pos : bctello(nut->i);
 
-	if (!(nut->dopts.cache_syncpoints & 1) || !sl->len) return find_syncpoint(nut, 0, sp, 0);
+	ERROR(!(nut->dopts.cache_syncpoints & 1) || !sl->len, -1);
 
 	if (!i) {
 		for (i = 0; i < sl->len; i++) if (sl->s[i].pos+15 > pos) break;
-		if (i == sl->len || (i && !sl->s[i-1].seen_next)) return find_syncpoint(nut, 0, sp, 0);
+		ERROR(i == sl->len || (i && !sl->s[i-1].seen_next), -1);
 
-		seek_buf(nut->i, sl->s[i].pos, SEEK_SET);
+		if (pos < sl->s[i].pos) // trust the caller if it gave more percise syncpoint location
+			seek_buf(nut->i, sl->s[i].pos, SEEK_SET);
 	} else i--;
 	fss->i = i + 1;
 	fss->pos = pos;
@@ -887,7 +888,6 @@
 			i = tmp + 1;
 		}
 		sl->s[i].pts_valid = 0;
-		sl->s[i].seen_next = 0;
 		for (j = 0; j < nut->stream_count; j++) {
 			sl->pts[i * nut->stream_count + j] = 0;
 			sl->eor[i * nut->stream_count + j] = 0;
@@ -908,6 +908,17 @@
 	fss->pos = fss->i = fss->begin = fss->seeked = 0;
 
 err_out:
+	if (err == -1) {
+		if (backwards && !fss->seeked) {
+			CHECK(find_syncpoint(nut, 0, sp, pos + 15 + 8));
+			if (!sp->seen_next) return 0;
+			seek_buf(nut->i, -nut->max_distance, SEEK_CUR);
+		}
+		fss->seeked = 1;
+		CHECK(find_syncpoint(nut, backwards, sp, 0));
+		fss->seeked = 0;
+		err = 0;
+	}
 	return err;
 }
 
@@ -1145,7 +1156,7 @@
 		}
 
 		CHECK(add_syncpoint(nut, s, NULL, NULL, timebases[s.pts%nut->timebase_count] < s.pts/nut->timebase_count ? NULL : &i));
-		fake_hi = HI.pos;
+		if (HI.pos < fake_hi) fake_hi = HI.pos;
 	}
 
 	fprintf(stderr, "\n[ (%d,%d) .. %d .. (%d,%d) ] => %d (%d seeks) %d\n",



More information about the NUT-devel mailing list