[vlc-commits] prefetch: Win32 support
Rémi Denis-Courmont
git at videolan.org
Fri Aug 28 22:42:51 CEST 2015
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Fri Aug 28 23:42:19 2015 +0300| [fe7ddb1e1098a008b60b754611706f0a7e92e9f6] | committer: Rémi Denis-Courmont
prefetch: Win32 support
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=fe7ddb1e1098a008b60b754611706f0a7e92e9f6
---
modules/stream_filter/Makefile.am | 2 --
modules/stream_filter/prefetch.c | 58 +++++++++++++++++++++++++++++++++++++
2 files changed, 58 insertions(+), 2 deletions(-)
diff --git a/modules/stream_filter/Makefile.am b/modules/stream_filter/Makefile.am
index 58b8e3b..7bf3b4a 100644
--- a/modules/stream_filter/Makefile.am
+++ b/modules/stream_filter/Makefile.am
@@ -16,9 +16,7 @@ endif
libprefetch_plugin_la_SOURCES = stream_filter/prefetch.c
libprefetch_plugin_la_LIBADD = $(LIBPTHREAD)
-if !HAVE_WIN32
stream_filter_LTLIBRARIES += libprefetch_plugin.la
-endif
libsmooth_plugin_la_SOURCES = \
stream_filter/smooth/smooth.c \
diff --git a/modules/stream_filter/prefetch.c b/modules/stream_filter/prefetch.c
index 23cff8a..f77bfd6 100644
--- a/modules/stream_filter/prefetch.c
+++ b/modules/stream_filter/prefetch.c
@@ -42,6 +42,9 @@
((void)(a), (void)(l), errno = EINVAL, -1)
#define sysconf(a) 1
#endif
+#if defined (_WIN32)
+#include <windows.h>
+#endif
#include <vlc_common.h>
#include <vlc_plugin.h>
@@ -431,8 +434,10 @@ static int Open(vlc_object_t *obj)
if (sys->buffer_size < sys->read_size)
sys->buffer_size = sys->read_size;
+#ifndef _WIN32
/* Round up to a multiple of the page size */
long page_size = sysconf(_SC_PAGESIZE);
+
sys->buffer_size += page_size - 1;
sys->buffer_size &= ~(page_size - 1);
@@ -455,6 +460,46 @@ static int Open(vlc_object_t *obj)
goto error;
}
close(fd);
+#else
+ SYSTEM_INFO info;
+ GetSystemInfo(&info);
+
+ sys->buffer_size += info.dwPageSize - 1;
+ sys->buffer_size &= ~(info.dwPageSize - 1);
+
+ HANDLE map = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
+ 0, sys->buffer_size, NULL);
+ if (map == NULL)
+ goto error;
+
+ void *p;
+retry:
+ sys->buffer = VirtualAlloc(NULL, 2 * sys->buffer_size, MEM_RESERVE,
+ PAGE_NOACCESS);
+ if (sys->buffer == NULL)
+ goto error;
+
+ VirtualFree(sys->buffer, 2 * sys->buffer_size, MEM_RELEASE);
+
+ p = MapViewOfFileEx(map, FILE_MAP_ALL_ACCESS, 0, 0, sys->buffer_size,
+ sys->buffer);
+ if (p != sys->buffer)
+ {
+ UnmapViewOfFile(p);
+ goto retry;
+ }
+
+ p = MapViewOfFileEx(map, FILE_MAP_ALL_ACCESS, 0, 0, sys->buffer_size,
+ sys->buffer + sys->buffer_size);
+ if (p != sys->buffer + sys->buffer_size)
+ {
+ UnmapViewOfFile(p);
+ UnmapViewOfFile(sys->buffer);
+ goto retry;
+ }
+
+ CloseHandle(map);
+#endif /* _WIN32 */
vlc_mutex_init(&sys->lock);
vlc_cond_init(&sys->wait_data);
@@ -478,8 +523,16 @@ static int Open(vlc_object_t *obj)
return VLC_SUCCESS;
error:
+#ifndef _WIN32
if (sys->buffer != MAP_FAILED)
munmap(sys->buffer, 2 * sys->buffer_size);
+#else
+ if (sys->buffer != NULL)
+ {
+ UnmapViewOfFile(sys->buffer + sys->buffer_size);
+ UnmapViewOfFile(sys->buffer);
+ }
+#endif
free(sys);
return VLC_ENOMEM;
}
@@ -499,7 +552,12 @@ static void Close (vlc_object_t *obj)
vlc_cond_destroy(&sys->wait_data);
vlc_mutex_destroy(&sys->lock);
+#ifndef _WIN32
munmap(sys->buffer, 2 * sys->buffer_size);
+#else
+ UnmapViewOfFile(sys->buffer + sys->buffer_size);
+ UnmapViewOfFile(sys->buffer);
+#endif
free(sys->content_type);
free(sys);
}
More information about the vlc-commits
mailing list