summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/audio_out/audio_file_out.c6
-rw-r--r--src/audio_out/audio_oss_out.c8
-rw-r--r--src/input/input_pvr.c10
-rw-r--r--src/input/input_v4l.c10
-rw-r--r--src/post/audio/stretch.c10
-rw-r--r--src/xine-engine/input_rip.c6
-rw-r--r--src/xine-engine/metronom.c10
-rw-r--r--src/xine-utils/utils.c56
-rw-r--r--src/xine-utils/xineutils.h7
9 files changed, 91 insertions, 32 deletions
diff --git a/src/audio_out/audio_file_out.c b/src/audio_out/audio_file_out.c
index 20271216e..4812929cf 100644
--- a/src/audio_out/audio_file_out.c
+++ b/src/audio_out/audio_file_out.c
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
- * $Id: audio_file_out.c,v 1.2 2004/04/23 12:41:30 hadess Exp $
+ * $Id: audio_file_out.c,v 1.3 2004/10/29 23:11:37 miguelfreitas Exp $
*/
#ifdef HAVE_CONFIG_H
@@ -159,7 +159,7 @@ static int ao_file_open(ao_driver_t *this_gen, uint32_t bits, uint32_t rate, int
this->fd = -1;
return 0;
}
- gettimeofday(&this->endtime, NULL);
+ xine_monotonic_clock(&this->endtime, NULL);
return this->sample_rate;
}
@@ -234,7 +234,7 @@ static int ao_file_delay (ao_driver_t *this_gen)
/* Work out how long we need to sleep for, and how much
time we've already taken */
- gettimeofday(&now, NULL);
+ xine_monotonic_clock(&now, NULL);
if (now.tv_sec > this->endtime.tv_sec) {
/* We slipped. Compensate */
diff --git a/src/audio_out/audio_oss_out.c b/src/audio_out/audio_oss_out.c
index 3604da5d2..3dd81064b 100644
--- a/src/audio_out/audio_oss_out.c
+++ b/src/audio_out/audio_oss_out.c
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
- * $Id: audio_oss_out.c,v 1.110 2004/10/08 20:32:03 mroi Exp $
+ * $Id: audio_oss_out.c,v 1.111 2004/10/29 23:11:38 miguelfreitas Exp $
*
* 20-8-2001 First implementation of Audio sync and Audio driver separation.
* Copyright (C) 2001 James Courtier-Dutton James@superbug.demon.co.uk
@@ -384,7 +384,7 @@ static int ao_oss_delay(ao_driver_t *this_gen) {
case OSS_SYNC_SOFTSYNC:
/* use system real-time clock to get pseudo audio frame position */
- gettimeofday(&tv, NULL);
+ xine_monotonic_clock(&tv, NULL);
frames = (tv.tv_usec - this->start_time.tv_usec)
* this->output_sample_k_rate / 1000;
@@ -452,7 +452,7 @@ static int ao_oss_write(ao_driver_t *this_gen,
struct timeval tv;
/* check if simulated buffer ran dry */
- gettimeofday(&tv, NULL);
+ xine_monotonic_clock(&tv, NULL);
frames = (tv.tv_usec - this->start_time.tv_usec)
* this->output_sample_k_rate / 1000;
@@ -851,7 +851,7 @@ static ao_driver_t *open_plugin (audio_driver_class_t *class_gen, const void *da
_("audio_oss_out: Audio driver realtime sync disabled...\n"
"audio_oss_out: ...will use system real-time clock for soft-sync instead\n"
"audio_oss_out: ...there may be audio/video synchronization issues\n"));
- gettimeofday(&this->start_time, NULL);
+ xine_monotonic_clock(&this->start_time, NULL);
this->latency = config->register_range (config, "audio.oss_latency", 0,
-3000, 3000,
diff --git a/src/input/input_pvr.c b/src/input/input_pvr.c
index 3eed852b6..2fe965378 100644
--- a/src/input/input_pvr.c
+++ b/src/input/input_pvr.c
@@ -38,7 +38,7 @@
* usage:
* xine pvr:/<prefix_to_tmp_files>\!<prefix_to_saved_files>\!<max_page_age>
*
- * $Id: input_pvr.c,v 1.50 2004/08/27 17:53:32 miguelfreitas Exp $
+ * $Id: input_pvr.c,v 1.51 2004/10/29 23:11:37 miguelfreitas Exp $
*/
/**************************************************************************
@@ -284,7 +284,7 @@ static void pvrscr_set_pivot (pvrscr_t *this) {
int64_t pts;
double pts_calc;
- gettimeofday(&tv, NULL);
+ xine_monotonic_clock(&tv, NULL);
pts_calc = (tv.tv_sec - this->cur_time.tv_sec) * this->speed_factor;
pts_calc += (tv.tv_usec - this->cur_time.tv_usec) * this->speed_factor / 1e6;
pts = this->cur_pts + pts_calc;
@@ -331,7 +331,7 @@ static void pvrscr_adjust (scr_plugin_t *scr, int64_t vpts) {
pthread_mutex_lock (&this->lock);
- gettimeofday(&tv, NULL);
+ xine_monotonic_clock(&tv, NULL);
this->cur_time.tv_sec=tv.tv_sec;
this->cur_time.tv_usec=tv.tv_usec;
this->cur_pts = vpts;
@@ -344,7 +344,7 @@ static void pvrscr_start (scr_plugin_t *scr, int64_t start_vpts) {
pthread_mutex_lock (&this->lock);
- gettimeofday(&this->cur_time, NULL);
+ xine_monotonic_clock(&this->cur_time, NULL);
this->cur_pts = start_vpts;
pthread_mutex_unlock (&this->lock);
@@ -360,7 +360,7 @@ static int64_t pvrscr_get_current (scr_plugin_t *scr) {
double pts_calc;
pthread_mutex_lock (&this->lock);
- gettimeofday(&tv, NULL);
+ xine_monotonic_clock(&tv, NULL);
pts_calc = (tv.tv_sec - this->cur_time.tv_sec) * this->speed_factor;
pts_calc += (tv.tv_usec - this->cur_time.tv_usec) * this->speed_factor / 1e6;
diff --git a/src/input/input_v4l.c b/src/input/input_v4l.c
index 73a765598..262c27441 100644
--- a/src/input/input_v4l.c
+++ b/src/input/input_v4l.c
@@ -241,7 +241,7 @@ static void pvrscr_set_pivot(pvrscr_t *this)
int64_t pts;
double pts_calc;
- gettimeofday(&tv, NULL);
+ xine_monotonic_clock(&tv, NULL);
pts_calc = (tv.tv_sec - this->cur_time.tv_sec) * this->speed_factor;
pts_calc += (tv.tv_usec - this->cur_time.tv_usec) * this->speed_factor / 1e6;
pts = this->cur_pts + pts_calc;
@@ -291,7 +291,7 @@ static void pvrscr_adjust (scr_plugin_t *scr, int64_t vpts)
pthread_mutex_lock (&this->lock);
- gettimeofday(&tv, NULL);
+ xine_monotonic_clock(&tv, NULL);
this->cur_time.tv_sec = tv.tv_sec;
this->cur_time.tv_usec = tv.tv_usec;
this->cur_pts = vpts;
@@ -305,7 +305,7 @@ static void pvrscr_start (scr_plugin_t *scr, int64_t start_vpts)
pthread_mutex_lock (&this->lock);
- gettimeofday(&this->cur_time, NULL);
+ xine_monotonic_clock(&this->cur_time, NULL);
this->cur_pts = start_vpts;
pthread_mutex_unlock (&this->lock);
@@ -322,7 +322,7 @@ static int64_t pvrscr_get_current (scr_plugin_t *scr)
pthread_mutex_lock (&this->lock);
- gettimeofday(&tv, NULL);
+ xine_monotonic_clock(&tv, NULL);
pts_calc = (tv.tv_sec - this->cur_time.tv_sec) * this->speed_factor;
pts_calc += (tv.tv_usec - this->cur_time.tv_usec) * this->speed_factor / 1e6;
@@ -1208,7 +1208,7 @@ static off_t v4l_plugin_read (input_plugin_t *this_gen, char *buf, off_t len) {
inline static int64_t get_time(void) {
struct timeval tv;
- gettimeofday(&tv,NULL);
+ xine_monotonic_clock(&tv,NULL);
return (int64_t) tv.tv_sec * 90000 + (int64_t) tv.tv_usec * 9 / 100;
}
diff --git a/src/post/audio/stretch.c b/src/post/audio/stretch.c
index 6eb131a2b..4598b1153 100644
--- a/src/post/audio/stretch.c
+++ b/src/post/audio/stretch.c
@@ -19,7 +19,7 @@
*
* Time stretch by a given factor, optionally preserving pitch
*
- * $Id: stretch.c,v 1.4 2004/08/02 12:51:11 miguelfreitas Exp $
+ * $Id: stretch.c,v 1.5 2004/10/29 23:11:38 miguelfreitas Exp $
*
*/
@@ -71,7 +71,7 @@ static void stretchscr_set_pivot (stretchscr_t *this) {
int64_t pts;
double pts_calc;
- gettimeofday(&tv, NULL);
+ xine_monotonic_clock(&tv, NULL);
pts_calc = (tv.tv_sec - this->cur_time.tv_sec) * this->speed_factor;
pts_calc += (tv.tv_usec - this->cur_time.tv_usec) * this->speed_factor / 1e6;
pts = this->cur_pts + pts_calc;
@@ -107,7 +107,7 @@ static void stretchscr_adjust (scr_plugin_t *scr, int64_t vpts) {
pthread_mutex_lock (&this->lock);
- gettimeofday(&tv, NULL);
+ xine_monotonic_clock(&tv, NULL);
this->cur_time.tv_sec=tv.tv_sec;
this->cur_time.tv_usec=tv.tv_usec;
this->cur_pts = vpts;
@@ -120,7 +120,7 @@ static void stretchscr_start (scr_plugin_t *scr, int64_t start_vpts) {
pthread_mutex_lock (&this->lock);
- gettimeofday(&this->cur_time, NULL);
+ xine_monotonic_clock(&this->cur_time, NULL);
this->cur_pts = start_vpts;
pthread_mutex_unlock (&this->lock);
@@ -136,7 +136,7 @@ static int64_t stretchscr_get_current (scr_plugin_t *scr) {
double pts_calc;
pthread_mutex_lock (&this->lock);
- gettimeofday(&tv, NULL);
+ xine_monotonic_clock(&tv, NULL);
pts_calc = (tv.tv_sec - this->cur_time.tv_sec) * this->speed_factor;
pts_calc += (tv.tv_usec - this->cur_time.tv_usec) * this->speed_factor / 1e6;
diff --git a/src/xine-engine/input_rip.c b/src/xine-engine/input_rip.c
index 18088ea87..bd0cbfd7f 100644
--- a/src/xine-engine/input_rip.c
+++ b/src/xine-engine/input_rip.c
@@ -29,7 +29,7 @@
* - it's possible speeder saving streams in the xine without playing:
* xine stream_mrl#save:file.raw\;noaudio\;novideo
*
- * $Id: input_rip.c,v 1.25 2004/09/26 22:54:52 valtri Exp $
+ * $Id: input_rip.c,v 1.26 2004/10/29 23:11:38 miguelfreitas Exp $
*/
/* TODO:
@@ -398,7 +398,7 @@ static off_t rip_plugin_seek(input_plugin_t *this_gen, off_t offset, int origin)
}
/* read and catch remaining data after this->savepos */
- gettimeofday(&time1, NULL);
+ xine_monotonic_clock(&time1, NULL);
while (this->curpos < newpos && interval < SEEK_TIMEOUT) {
if( blocksize ) {
buf_element_t *buf;
@@ -418,7 +418,7 @@ static off_t rip_plugin_seek(input_plugin_t *this_gen, off_t offset, int origin)
break;
}
}
- gettimeofday(&time2, NULL);
+ xine_monotonic_clock(&time2, NULL);
interval = (double)(time2.tv_sec - time1.tv_sec)
+ (double)(time2.tv_usec - time1.tv_usec) / 1000000;
}
diff --git a/src/xine-engine/metronom.c b/src/xine-engine/metronom.c
index 4098f30cb..a0a628c1f 100644
--- a/src/xine-engine/metronom.c
+++ b/src/xine-engine/metronom.c
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
- * $Id: metronom.c,v 1.140 2004/08/02 12:51:21 miguelfreitas Exp $
+ * $Id: metronom.c,v 1.141 2004/10/29 23:11:38 miguelfreitas Exp $
*/
#ifdef HAVE_CONFIG_H
@@ -92,7 +92,7 @@ static void unixscr_set_pivot (unixscr_t *this) {
int64_t pts;
double pts_calc;
- gettimeofday(&tv, NULL);
+ xine_monotonic_clock(&tv, NULL);
pts_calc = (tv.tv_sec - this->cur_time.tv_sec) * this->speed_factor;
pts_calc += (tv.tv_usec - this->cur_time.tv_usec) * this->speed_factor / 1e6;
pts = this->cur_pts + pts_calc;
@@ -126,7 +126,7 @@ static void unixscr_adjust (scr_plugin_t *scr, int64_t vpts) {
pthread_mutex_lock (&this->lock);
- gettimeofday(&tv, NULL);
+ xine_monotonic_clock(&tv, NULL);
this->cur_time.tv_sec=tv.tv_sec;
this->cur_time.tv_usec=tv.tv_usec;
this->cur_pts = vpts;
@@ -139,7 +139,7 @@ static void unixscr_start (scr_plugin_t *scr, int64_t start_vpts) {
pthread_mutex_lock (&this->lock);
- gettimeofday(&this->cur_time, NULL);
+ xine_monotonic_clock(&this->cur_time, NULL);
this->cur_pts = start_vpts;
pthread_mutex_unlock (&this->lock);
@@ -155,7 +155,7 @@ static int64_t unixscr_get_current (scr_plugin_t *scr) {
double pts_calc;
pthread_mutex_lock (&this->lock);
- gettimeofday(&tv, NULL);
+ xine_monotonic_clock(&tv, NULL);
pts_calc = (tv.tv_sec - this->cur_time.tv_sec) * this->speed_factor;
pts_calc += (tv.tv_usec - this->cur_time.tv_usec) * this->speed_factor / 1e6;
diff --git a/src/xine-utils/utils.c b/src/xine-utils/utils.c
index a26b83b46..fb421ef74 100644
--- a/src/xine-utils/utils.c
+++ b/src/xine-utils/utils.c
@@ -17,11 +17,15 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
- * $Id: utils.c,v 1.35 2004/09/26 22:54:53 valtri Exp $
+ * $Id: utils.c,v 1.36 2004/10/29 23:11:38 miguelfreitas Exp $
*
*/
#define _POSIX_PTHREAD_SEMANTICS 1 /* for 5-arg getpwuid_r on solaris */
+/*
+#define LOG
+*/
+
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
@@ -34,6 +38,7 @@
#include <errno.h>
#include <pwd.h>
+#include <sys/time.h>
#include <time.h>
#include <unistd.h>
@@ -576,3 +581,52 @@ void xine_xprintf(xine_t *xine, int verbose, const char *fmt, ...) {
}
}
#endif
+
+int xine_monotonic_clock(struct timeval *tv, struct timezone *tz)
+{
+#if _POSIX_TIMERS > 0 && defined(_POSIX_MONOTONIC_CLOCK)
+ static int initialized = 0;
+ static int use_clock_monotonic = 0;
+
+ struct timespec tp;
+
+ if( !initialized ) {
+ struct timespec res;
+ int ret;
+
+ ret = clock_getres(CLOCK_MONOTONIC, &res);
+
+ if( ret != 0 ) {
+ lprintf("get resolution of monotonic clock failed\n");
+ } else {
+ /* require at least milisecond resolution */
+ if( res.tv_sec > 0 ||
+ res.tv_nsec > 1000000 ) {
+ lprintf("monotonic clock resolution (%d:%d) too bad\n",
+ (int)res.tv_sec, (int)res.tv_nsec);
+ } else {
+ if( clock_gettime(CLOCK_MONOTONIC, &tp) != 0 ) {
+ lprintf("get monotonic clock failed\n");
+ } else {
+ lprintf("using monotonic clock\n");
+ use_clock_monotonic = 1;
+ }
+ }
+ }
+ initialized = 1;
+ }
+
+ if(use_clock_monotonic && !clock_gettime(CLOCK_MONOTONIC, &tp)) {
+ tv->tv_sec = tp.tv_sec;
+ tv->tv_usec = tp.tv_nsec / 1000;
+ return 0;
+ } else {
+ return gettimeofday(tv, tz);
+ }
+
+#else
+
+ return gettimeofday(tv, tz);
+
+#endif
+}
diff --git a/src/xine-utils/xineutils.h b/src/xine-utils/xineutils.h
index 8e45d150a..21070a1a9 100644
--- a/src/xine-utils/xineutils.h
+++ b/src/xine-utils/xineutils.h
@@ -17,7 +17,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*
- * $Id: xineutils.h,v 1.94 2004/09/26 22:54:53 valtri Exp $
+ * $Id: xineutils.h,v 1.95 2004/10/29 23:11:38 miguelfreitas Exp $
*
*/
#ifndef XINEUTILS_H
@@ -1030,6 +1030,11 @@ const char *xine_guess_spu_encoding(void);
char *exec_path_append_subdir(char * string);
#endif
+/*
+ * use the best clock reference (API compatible with gettimeofday)
+ * note: it will be a monotonic clock, if available.
+ */
+int xine_monotonic_clock(struct timeval *tv, struct timezone *tz);
#ifdef __cplusplus
}