summaryrefslogtreecommitdiffstats
path: root/libmpdemux
diff options
context:
space:
mode:
authorfaust3 <faust3@b3059339-0415-0410-9bf9-f77b7e298cf2>2003-05-26 18:35:42 +0000
committerfaust3 <faust3@b3059339-0415-0410-9bf9-f77b7e298cf2>2003-05-26 18:35:42 +0000
commitdaf331b5f812f19427d4ba3938d26318d33659be (patch)
treee5c29c937d515b8f56bc7333e74213557f80c5a2 /libmpdemux
parent44f51eeb195ccbe0e4cdc3aa3cf54e084d4f3fa9 (diff)
downloadmpv-daf331b5f812f19427d4ba3938d26318d33659be.tar.bz2
mpv-daf331b5f812f19427d4ba3938d26318d33659be.tar.xz
use threads on windows
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@10198 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libmpdemux')
-rw-r--r--libmpdemux/cache2.c45
1 files changed, 42 insertions, 3 deletions
diff --git a/libmpdemux/cache2.c b/libmpdemux/cache2.c
index b4e82cb12b..353921177c 100644
--- a/libmpdemux/cache2.c
+++ b/libmpdemux/cache2.c
@@ -17,7 +17,14 @@
#include <sys/types.h>
#include <unistd.h>
+#include "../osdep/timer.h"
+#ifndef WIN32
#include "../osdep/shmem.h"
+#else
+#undef DATADIR
+#include <windows.h>
+static DWORD WINAPI ThreadProc(void* s);
+#endif
#include "mp_msg.h"
@@ -71,7 +78,7 @@ int cache_read(cache_vars_t* s,unsigned char* buf,int size){
// eof?
if(s->eof) break;
// waiting for buffer fill...
- usleep(READ_USLEEP_TIME); // 10ms
+ usec_sleep(READ_USLEEP_TIME); // 10ms
continue; // try again...
}
@@ -184,12 +191,20 @@ int cache_fill(cache_vars_t* s){
cache_vars_t* cache_init(int size,int sector){
int num;
+#ifndef WIN32
cache_vars_t* s=shmem_alloc(sizeof(cache_vars_t));
+#else
+ cache_vars_t* s=malloc(sizeof(cache_vars_t));
+#endif
memset(s,0,sizeof(cache_vars_t));
num=size/sector;
s->buffer_size=num*sector;
s->sector_size=sector;
+#ifndef WIN32
s->buffer=shmem_alloc(s->buffer_size);
+#else
+ s->buffer=malloc(s->buffer_size);
+#endif
s->fill_limit=8*sector;
s->back_size=size/2;
s->prefill=size/20; // default: 5%
@@ -199,11 +214,21 @@ cache_vars_t* cache_init(int size,int sector){
void cache_uninit(stream_t *s) {
cache_vars_t* c = s->cache_data;
if(!s->cache_pid) return;
+#ifndef WIN32
kill(s->cache_pid,SIGKILL);
waitpid(s->cache_pid,NULL,0);
+#else
+ TerminateThread((HANDLE)s->cache_pid,0);
+ free(c->stream);
+#endif
if(!c) return;
+#ifndef WIN32
shmem_free(c->buffer,c->buffer_size);
shmem_free(s->cache_data,sizeof(cache_vars_t));
+#else
+ free(c->buffer);
+ free(s->cache_data);
+#endif
}
static void exit_sighandler(int x){
@@ -227,7 +252,16 @@ int stream_enable_cache(stream_t *stream,int size,int min,int prefill){
s->stream=stream; // callback
s->prefill=size*prefill;
+#ifndef WIN32
if((stream->cache_pid=fork())){
+#else
+ {
+ DWORD threadId;
+ stream_t* stream2=malloc(sizeof(stream_t));
+ memcpy(stream2,s->stream,sizeof(stream_t));
+ s->stream=stream2;
+ stream->cache_pid = CreateThread(NULL,0,ThreadProc,s,0,&threadId);
+#endif
// wait until cache is filled at least prefill_init %
mp_msg(MSGT_CACHE,MSGL_V,"CACHE_PRE_INIT: %d [%d] %d pre:%d eof:%d \n",
s->min_filepos,s->read_filepos,s->max_filepos,min,s->eof);
@@ -243,11 +277,16 @@ int stream_enable_cache(stream_t *stream,int size,int min,int prefill){
return 1; // parent exits
}
+#ifdef WIN32
+}
+static DWORD WINAPI ThreadProc(void*s){
+#endif
+
// cache thread mainloop:
signal(SIGTERM,exit_sighandler); // kill
while(1){
- if(!cache_fill(s)){
- usleep(FILL_USLEEP_TIME); // idle
+ if(!cache_fill((cache_vars_t*)s)){
+ usec_sleep(FILL_USLEEP_TIME); // idle
}
// cache_stats(s->cache_data);
}