From 06d09abeaa81336476845e1cc5db2a474ceaa9ad Mon Sep 17 00:00:00 2001 From: Matthias Drochner Date: Wed, 21 Jul 2010 14:23:25 +0000 Subject: Normalize timeval In demux_loop(), a time value is calculated by adding to the fractional part. In case a second barrier is crossed, the value is not in its canonical form anymore - the fractional part is larger than 10^9-1. It should be normalized for portability. While I haven't found a formal requirement for this in POSIX, NetBSD's libpthread checks for it and complains. --- src/xine-engine/demux.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/xine-engine') diff --git a/src/xine-engine/demux.c b/src/xine-engine/demux.c index bbc130988..68fedbcf4 100644 --- a/src/xine-engine/demux.c +++ b/src/xine-engine/demux.c @@ -349,6 +349,10 @@ static void *demux_loop (void *stream_gen) { gettimeofday(&tv, NULL); ts.tv_sec = tv.tv_sec; ts.tv_nsec = (tv.tv_usec + 100000) * 1000; + if (ts.tv_nsec >= 1000000000) { + ts.tv_nsec -= 1000000000; + ts.tv_sec += 1; + } pthread_cond_timedwait (&stream->demux_resume, &stream->demux_lock, &ts); } -- cgit v1.2.3 From e9c4a618fbc47dae2cdd82d4d09ade8ec020bfe1 Mon Sep 17 00:00:00 2001 From: Matthias Drochner Date: Wed, 21 Jul 2010 15:27:33 +0000 Subject: Add _POSIX_THREAD_PRIORITY_SCHEDULING #ifdefs This is optional, and some systems don't support it. POSIX defines the _POSIX_THREAD_PRIORITY_SCHEDULING to tell that support is present. --- src/xine-engine/audio_decoder.c | 4 ++++ src/xine-engine/audio_out.c | 2 ++ src/xine-engine/video_decoder.c | 8 ++++++++ src/xine-engine/video_out.c | 2 ++ 4 files changed, 16 insertions(+) (limited to 'src/xine-engine') diff --git a/src/xine-engine/audio_decoder.c b/src/xine-engine/audio_decoder.c index dd15bf696..3d5ef7e6f 100644 --- a/src/xine-engine/audio_decoder.c +++ b/src/xine-engine/audio_decoder.c @@ -463,7 +463,9 @@ static void *audio_decoder_loop (void *stream_gen) { int _x_audio_decoder_init (xine_stream_t *stream) { pthread_attr_t pth_attrs; +#ifdef _POSIX_THREAD_PRIORITY_SCHEDULING struct sched_param pth_params; +#endif int err; if (stream->audio_out == NULL) { @@ -501,10 +503,12 @@ int _x_audio_decoder_init (xine_stream_t *stream) { */ pthread_attr_init(&pth_attrs); +#ifdef _POSIX_THREAD_PRIORITY_SCHEDULING pthread_attr_getschedparam(&pth_attrs, &pth_params); pth_params.sched_priority = sched_get_priority_min(SCHED_OTHER); pthread_attr_setschedparam(&pth_attrs, &pth_params); pthread_attr_setscope(&pth_attrs, PTHREAD_SCOPE_SYSTEM); +#endif stream->audio_thread_created = 1; if ((err = pthread_create (&stream->audio_thread, diff --git a/src/xine-engine/audio_out.c b/src/xine-engine/audio_out.c index 0a141e014..b9738595b 100644 --- a/src/xine-engine/audio_out.c +++ b/src/xine-engine/audio_out.c @@ -2284,7 +2284,9 @@ xine_audio_port_t *_x_ao_new_port (xine_t *xine, ao_driver_t *driver, this->audio_loop_running = 1; pthread_attr_init(&pth_attrs); +#ifdef _POSIX_THREAD_PRIORITY_SCHEDULING pthread_attr_setscope(&pth_attrs, PTHREAD_SCOPE_SYSTEM); +#endif this->audio_thread_created = 1; if ((err = pthread_create (&this->audio_thread, diff --git a/src/xine-engine/video_decoder.c b/src/xine-engine/video_decoder.c index 0756fc5b2..f70bb82bb 100644 --- a/src/xine-engine/video_decoder.c +++ b/src/xine-engine/video_decoder.c @@ -41,6 +41,10 @@ #define SPU_SLEEP_INTERVAL (90000/2) +#ifndef SCHED_OTHER +#define SCHED_OTHER 0 +#endif + static void update_spu_decoder (xine_stream_t *stream, int type) { @@ -486,7 +490,9 @@ int _x_video_decoder_init (xine_stream_t *stream) { } else { pthread_attr_t pth_attrs; +#ifdef _POSIX_THREAD_PRIORITY_SCHEDULING struct sched_param pth_params; +#endif int err, num_buffers; /* The fifo size is based on dvd playback where buffers are filled * with 2k of data. With 500 buffers and a typical video data rate @@ -515,10 +521,12 @@ int _x_video_decoder_init (xine_stream_t *stream) { stream->spu_track_map_entries = 0; pthread_attr_init(&pth_attrs); +#ifdef _POSIX_THREAD_PRIORITY_SCHEDULING pthread_attr_getschedparam(&pth_attrs, &pth_params); pth_params.sched_priority = sched_get_priority_min(SCHED_OTHER); pthread_attr_setschedparam(&pth_attrs, &pth_params); pthread_attr_setscope(&pth_attrs, PTHREAD_SCOPE_SYSTEM); +#endif stream->video_thread_created = 1; if ((err = pthread_create (&stream->video_thread, diff --git a/src/xine-engine/video_out.c b/src/xine-engine/video_out.c index cd73233c3..26ad98290 100644 --- a/src/xine-engine/video_out.c +++ b/src/xine-engine/video_out.c @@ -1911,7 +1911,9 @@ xine_video_port_t *_x_vo_new_port (xine_t *xine, vo_driver_t *driver, int grabon this->grab_only = 0; pthread_attr_init(&pth_attrs); +#ifdef _POSIX_THREAD_PRIORITY_SCHEDULING pthread_attr_setscope(&pth_attrs, PTHREAD_SCOPE_SYSTEM); +#endif if ((err = pthread_create (&this->video_thread, &pth_attrs, video_out_loop, this)) != 0) { -- cgit v1.2.3 From 7e21b7edcf1cbb074c2d9939e9bf318251822604 Mon Sep 17 00:00:00 2001 From: Lorenzo Desole Date: Wed, 21 Jul 2010 20:51:10 +0200 Subject: Remove duplicate code --- src/xine-engine/demux.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'src/xine-engine') diff --git a/src/xine-engine/demux.c b/src/xine-engine/demux.c index 68fedbcf4..87cc18011 100644 --- a/src/xine-engine/demux.c +++ b/src/xine-engine/demux.c @@ -343,17 +343,8 @@ static void *demux_loop (void *stream_gen) { /* someone may want to interrupt us */ if( stream->demux_action_pending ) { - struct timeval tv; struct timespec ts; - - gettimeofday(&tv, NULL); - ts.tv_sec = tv.tv_sec; - ts.tv_nsec = (tv.tv_usec + 100000) * 1000; - if (ts.tv_nsec >= 1000000000) { - ts.tv_nsec -= 1000000000; - ts.tv_sec += 1; - } - + ts = _x_compute_interval(100); pthread_cond_timedwait (&stream->demux_resume, &stream->demux_lock, &ts); } } -- cgit v1.2.3