[MPlayer-dev-eng] [PATCH] Use posix_fadvise in stream_file if available

Reimar Döffinger Reimar.Doeffinger at gmx.de
Sat Nov 7 20:39:24 CET 2009


On Sat, Nov 07, 2009 at 08:30:35PM +0100, Reimar Döffinger wrote:
> Or you can use my attached ugly hack, assuming it works (I can't test,
> not even my DVDs have any problem with playing and seeking perfectly
> smooth even without cache).

Probably somewhat nicer variant.
-------------- next part --------------
Index: stream/stream_file.c
===================================================================
--- stream/stream_file.c	(revision 29850)
+++ stream/stream_file.c	(working copy)
@@ -4,6 +4,8 @@
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+// for posix_fadvise
+#define _XOPEN_SOURCE 600
 #include <fcntl.h>
 #include <unistd.h>
 
@@ -34,8 +36,14 @@
   stream_opts_fields
 };
 
+#define PREFETCH_LEN (1024*1024)
+
 static int fill_buffer(stream_t *s, char* buffer, int max_len){
   int r = read(s->fd,buffer,max_len);
+#ifdef POSIX_FADV_WILLNEED
+  off_t pos = lseek(s->fd, 0, SEEK_CUR);
+  posix_fadvise(s->fd, pos, PREFETCH_LEN, POSIX_FADV_WILLNEED | POSIX_FADV_NOREUSE);
+#endif
   return (r <= 0) ? -1 : r;
 }
 
@@ -50,6 +58,9 @@
     s->eof=1;
     return 0;
   }
+#ifdef POSIX_FADV_WILLNEED
+  posix_fadvise(s->fd, s->pos, PREFETCH_LEN, POSIX_FADV_WILLNEED | POSIX_FADV_NOREUSE);
+#endif
   return 1;
 }
 
@@ -152,6 +163,9 @@
   }
 
   len=lseek(f,0,SEEK_END); lseek(f,0,SEEK_SET);
+#ifdef POSIX_FADV_WILLNEED
+  posix_fadvise(f, 0, PREFETCH_LEN, POSIX_FADV_WILLNEED | POSIX_FADV_NOREUSE);
+#endif
 #ifdef __MINGW32__
   if(f==0 || len == -1) {
 #else


More information about the MPlayer-dev-eng mailing list