diff options
author | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2008-10-25 05:12:34 +0300 |
---|---|---|
committer | Uoti Urpala <uau@glyph.nonexistent.invalid> | 2008-10-25 05:12:34 +0300 |
commit | 030130942562bb7b84eeba53e0226abed5a63a4c (patch) | |
tree | 9b49208facf2801369c9d2d7b3e7af11fab36829 /stream/cache2.c | |
parent | 562d86d95cbba67cb58358f6fc334553a467dee7 (diff) | |
parent | 15a80092161a1cd305f8005c780c744416a5252b (diff) | |
download | mpv-030130942562bb7b84eeba53e0226abed5a63a4c.tar.bz2 mpv-030130942562bb7b84eeba53e0226abed5a63a4c.tar.xz |
Merge svn changes up to 27824
Conflicts:
cfg-common-opts.h
libmpcodecs/dec_video.c
libmpcodecs/vd.c
libvo/x11_common.h
mplayer.c
stream/cache2.c
Diffstat (limited to 'stream/cache2.c')
-rw-r--r-- | stream/cache2.c | 59 |
1 files changed, 28 insertions, 31 deletions
diff --git a/stream/cache2.c b/stream/cache2.c index 59d6e0aacb..209b2bdfd5 100644 --- a/stream/cache2.c +++ b/stream/cache2.c @@ -17,17 +17,17 @@ #include <unistd.h> #include "cache2.h" +#include "osdep/shmem.h" #include "osdep/timer.h" -#ifdef WIN32 +#if defined(__MINGW32__) || defined(__CYGWIN__) #include <windows.h> -static DWORD WINAPI ThreadProc(void* s); +static void ThreadProc( void *s ); #elif defined(__OS2__) #define INCL_DOS #include <os2.h> static void ThreadProc( void *s ); #else #include <sys/wait.h> -#include "osdep/shmem.h" #endif #include "mp_msg.h" @@ -196,14 +196,15 @@ static int cache_fill(cache_vars_t* s){ } -static void cache_execute_control(cache_vars_t *s) { +static int cache_execute_control(cache_vars_t *s) { + int res = 1; static unsigned last; if (!s->stream->control) { s->stream_time_length = 0; s->control_new_pos = 0; s->control_res = STREAM_UNSUPPORTED; s->control = -1; - return; + return res; } if (GetTimerMS() - last > 99) { double len; @@ -213,7 +214,7 @@ static void cache_execute_control(cache_vars_t *s) { s->stream_time_length = 0; last = GetTimerMS(); } - if (s->control == -1) return; + if (s->control == -1) return res; switch (s->control) { case STREAM_CTRL_GET_CURRENT_TIME: case STREAM_CTRL_SEEK_TO_TIME: @@ -228,17 +229,20 @@ static void cache_execute_control(cache_vars_t *s) { case STREAM_CTRL_SET_ANGLE: s->control_res = s->stream->control(s->stream, s->control, &s->control_uint_arg); break; + case -2: + res = 0; default: s->control_res = STREAM_UNSUPPORTED; break; } s->control_new_pos = s->stream->pos; s->control = -1; + return res; } static cache_vars_t* cache_init(int size,int sector){ int num; -#if !defined(WIN32) && !defined(__OS2__) +#if !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(__OS2__) cache_vars_t* s=shmem_alloc(sizeof(cache_vars_t)); #else cache_vars_t* s=malloc(sizeof(cache_vars_t)); @@ -252,14 +256,14 @@ static cache_vars_t* cache_init(int size,int sector){ }//32kb min_size s->buffer_size=num*sector; s->sector_size=sector; -#if !defined(WIN32) && !defined(__OS2__) +#if !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(__OS2__) s->buffer=shmem_alloc(s->buffer_size); #else s->buffer=malloc(s->buffer_size); #endif if(s->buffer == NULL){ -#if !defined(WIN32) && !defined(__OS2__) +#if !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(__OS2__) shmem_free(s,sizeof(cache_vars_t)); #else free(s); @@ -275,17 +279,14 @@ static 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; -#ifdef WIN32 - TerminateThread((HANDLE)s->cache_pid,0); -#elif defined(__OS2__) - DosKillThread( s->cache_pid ); - DosWaitThread( &s->cache_pid, DCWW_WAIT ); +#if defined(__MINGW32__) || defined(__CYGWIN__) || defined(__OS2__) + cache_do_control(s, -2, NULL); #else kill(s->cache_pid,SIGKILL); waitpid(s->cache_pid,NULL,0); #endif if(!c) return; -#if defined(WIN32) || defined(__OS2__) +#if defined(__MINGW32__) || defined(__CYGWIN__) || defined(__OS2__) free(c->stream); free(c->buffer); free(s->cache_data); @@ -326,19 +327,16 @@ int stream_enable_cache(stream_t *stream,int size,int min,int seek_limit){ min = s->buffer_size - s->fill_limit; } -#if !defined(WIN32) && !defined(__OS2__) +#if !defined(__MINGW32__) && !defined(__CYGWIN__) && !defined(__OS2__) if((stream->cache_pid=fork())){ #else { -#ifdef WIN32 - DWORD threadId; -#endif stream_t* stream2=malloc(sizeof(stream_t)); memcpy(stream2,s->stream,sizeof(stream_t)); s->stream=stream2; -#ifdef WIN32 - stream->cache_pid = CreateThread(NULL,0,ThreadProc,s,0,&threadId); -#else // OS2 +#if defined(__MINGW32__) || defined(__CYGWIN__) + stream->cache_pid = _beginthread( ThreadProc, 0, s ); +#else stream->cache_pid = _beginthread( ThreadProc, NULL, 256 * 1024, s ); #endif #endif @@ -358,27 +356,25 @@ int stream_enable_cache(stream_t *stream,int size,int min,int seek_limit){ return 1; // parent exits } -#if defined(WIN32) || defined(__OS2__) +#if defined(__MINGW32__) || defined(__CYGWIN__) || defined(__OS2__) } -#ifdef WIN32 -static DWORD WINAPI ThreadProc(void*s){ -#else // OS2 static void ThreadProc( void *s ){ #endif -#endif #ifdef CONFIG_GUI use_gui = 0; // mp_msg may not use gui stuff in forked code #endif // cache thread mainloop: signal(SIGTERM,exit_sighandler); // kill - while(1){ - if(!cache_fill((cache_vars_t*)s)){ + do { + if(!cache_fill(s)){ usec_sleep(FILL_USLEEP_TIME); // idle } - cache_execute_control((cache_vars_t*)s); // cache_stats(s->cache_data); - } + } while (cache_execute_control(s)); +#if defined(__MINGW32__) || defined(__CYGWIN__) || defined(__OS2__) + _endthread(); +#endif } int cache_stream_fill_buffer(stream_t *s){ @@ -453,6 +449,7 @@ int cache_do_control(stream_t *stream, int cmd, void *arg) { case STREAM_CTRL_GET_ASPECT_RATIO: case STREAM_CTRL_GET_NUM_ANGLES: case STREAM_CTRL_GET_ANGLE: + case -2: s->control = cmd; break; default: |