Commit 33655fee authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

prefetch: Win32 support

parent c74fb8e1
...@@ -16,9 +16,7 @@ endif ...@@ -16,9 +16,7 @@ endif
libprefetch_plugin_la_SOURCES = stream_filter/prefetch.c libprefetch_plugin_la_SOURCES = stream_filter/prefetch.c
libprefetch_plugin_la_LIBADD = $(LIBPTHREAD) libprefetch_plugin_la_LIBADD = $(LIBPTHREAD)
if !HAVE_WIN32
stream_filter_LTLIBRARIES += libprefetch_plugin.la stream_filter_LTLIBRARIES += libprefetch_plugin.la
endif
libsmooth_plugin_la_SOURCES = \ libsmooth_plugin_la_SOURCES = \
stream_filter/smooth/smooth.c \ stream_filter/smooth/smooth.c \
......
...@@ -42,6 +42,9 @@ ...@@ -42,6 +42,9 @@
((void)(a), (void)(l), errno = EINVAL, -1) ((void)(a), (void)(l), errno = EINVAL, -1)
#define sysconf(a) 1 #define sysconf(a) 1
#endif #endif
#if defined (_WIN32)
#include <windows.h>
#endif
#include <vlc_common.h> #include <vlc_common.h>
#include <vlc_plugin.h> #include <vlc_plugin.h>
...@@ -431,8 +434,10 @@ static int Open(vlc_object_t *obj) ...@@ -431,8 +434,10 @@ static int Open(vlc_object_t *obj)
if (sys->buffer_size < sys->read_size) if (sys->buffer_size < sys->read_size)
sys->buffer_size = sys->read_size; sys->buffer_size = sys->read_size;
#ifndef _WIN32
/* Round up to a multiple of the page size */ /* Round up to a multiple of the page size */
long page_size = sysconf(_SC_PAGESIZE); long page_size = sysconf(_SC_PAGESIZE);
sys->buffer_size += page_size - 1; sys->buffer_size += page_size - 1;
sys->buffer_size &= ~(page_size - 1); sys->buffer_size &= ~(page_size - 1);
...@@ -455,6 +460,50 @@ static int Open(vlc_object_t *obj) ...@@ -455,6 +460,50 @@ static int Open(vlc_object_t *obj)
goto error; goto error;
} }
close(fd); close(fd);
#else
SYSTEM_INFO info;
GetSystemInfo(&info);
sys->buffer_size += info.dwPageSize - 1;
sys->buffer_size &= ~(info.dwPageSize - 1);
sys->buffer = NULL;
HANDLE map = CreateFileMapping(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE,
0, sys->buffer_size, NULL);
if (map == NULL)
goto error;
for (;;)
{
char *buffer = VirtualAlloc(NULL, 2 * sys->buffer_size, MEM_RESERVE,
PAGE_NOACCESS);
if (buffer == NULL)
break;
VirtualFree(buffer, 2 * sys->buffer_size, MEM_RELEASE);
char *a = MapViewOfFileEx(map, FILE_MAP_ALL_ACCESS, 0, 0,
sys->buffer_size, buffer);
char *b = MapViewOfFileEx(map, FILE_MAP_ALL_ACCESS, 0, 0,
sys->buffer_size, buffer + sys->buffer_size);
if (a == buffer && b == buffer + sys->buffer_size)
{
sys->buffer = buffer;
break;
}
if (b != NULL)
UnmapViewOfFile(b);
if (a != NULL)
UnmapViewOfFile(a);
if (a == NULL || b == NULL)
break; /* ENOMEM */
}
CloseHandle(map);
if (sys->buffer == NULL)
goto error;
#endif /* _WIN32 */
vlc_mutex_init(&sys->lock); vlc_mutex_init(&sys->lock);
vlc_cond_init(&sys->wait_data); vlc_cond_init(&sys->wait_data);
...@@ -478,8 +527,16 @@ static int Open(vlc_object_t *obj) ...@@ -478,8 +527,16 @@ static int Open(vlc_object_t *obj)
return VLC_SUCCESS; return VLC_SUCCESS;
error: error:
#ifndef _WIN32
if (sys->buffer != MAP_FAILED) if (sys->buffer != MAP_FAILED)
munmap(sys->buffer, 2 * sys->buffer_size); munmap(sys->buffer, 2 * sys->buffer_size);
#else
if (sys->buffer != NULL)
{
UnmapViewOfFile(sys->buffer + sys->buffer_size);
UnmapViewOfFile(sys->buffer);
}
#endif
free(sys); free(sys);
return VLC_ENOMEM; return VLC_ENOMEM;
} }
...@@ -499,7 +556,12 @@ static void Close (vlc_object_t *obj) ...@@ -499,7 +556,12 @@ static void Close (vlc_object_t *obj)
vlc_cond_destroy(&sys->wait_data); vlc_cond_destroy(&sys->wait_data);
vlc_mutex_destroy(&sys->lock); vlc_mutex_destroy(&sys->lock);
#ifndef _WIN32
munmap(sys->buffer, 2 * sys->buffer_size); munmap(sys->buffer, 2 * sys->buffer_size);
#else
UnmapViewOfFile(sys->buffer + sys->buffer_size);
UnmapViewOfFile(sys->buffer);
#endif
free(sys->content_type); free(sys->content_type);
free(sys); free(sys);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment