[vlc-devel] commit: file: do POSIX advisory I/O ( Rémi Denis-Courmont )
git version control
git at videolan.org
Thu Jul 23 22:21:49 CEST 2009
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Jul 23 23:20:12 2009 +0300| [5d0553056f675c75af2124810585390fdf2b0fd1] | committer: Rémi Denis-Courmont
file: do POSIX advisory I/O
The system can use the hint to prefetch the data into memory, if
possible. Hopefully, this will reduce choppiness, as well as power
consumption.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5d0553056f675c75af2124810585390fdf2b0fd1
---
modules/access/file.c | 17 +++++++++++++++--
1 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/modules/access/file.c b/modules/access/file.c
index 8f1ca9e..c522829 100644
--- a/modules/access/file.c
+++ b/modules/access/file.c
@@ -164,6 +164,9 @@ static bool IsRemote (int fd)
#endif
}
+#ifndef HAVE_POSIX_FADVISE
+# define posix_fadvise(fd, off, len, adv) (0)
+#endif
/*****************************************************************************
* Open: open the file
@@ -234,6 +237,14 @@ static int Open( vlc_object_t *p_this )
p_sys->caching += var_CreateGetInteger (p_access, "network-caching");
p_sys->fd = fd;
+
+ if (p_access->pf_seek != NoSeek)
+ {
+ /* Demuxers will need the beginning of the file for probing. */
+ posix_fadvise (fd, 0, 4096, POSIX_FADV_WILLNEED);
+ /* In most cases, we only read the file once. */
+ posix_fadvise (fd, 0, 0, POSIX_FADV_NOREUSE);
+ }
return VLC_SUCCESS;
error:
@@ -297,10 +308,10 @@ static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
p_sys->i_nb_reads++;
-#ifdef HAVE_SYS_STAT_H
if ((p_access->info.i_size && !(p_sys->i_nb_reads % INPUT_FSTAT_NB_READS))
|| (p_access->info.i_pos > p_access->info.i_size))
{
+#ifdef HAVE_SYS_STAT_H
struct stat st;
if ((fstat (fd, &st) == 0)
@@ -309,8 +320,10 @@ static ssize_t Read( access_t *p_access, uint8_t *p_buffer, size_t i_len )
p_access->info.i_size = st.st_size;
p_access->info.i_update |= INPUT_UPDATE_SIZE;
}
- }
#endif
+ /* Pre-fetch until the end (within memory limits) */
+ posix_fadvise (fd, p_access->info.i_pos, 0, POSIX_FADV_WILLNEED);
+ }
return i_ret;
}
More information about the vlc-devel
mailing list