1
0
mirror of https://github.com/VDR4Arch/vdr.git synced 2023-10-10 13:36:52 +02:00

cTimeMs now uses the monotonic clock, if available

This commit is contained in:
Klaus Schmidinger 2007-12-27 15:58:18 +01:00
parent bd411a6620
commit 6f76e10038
4 changed files with 41 additions and 4 deletions

View File

@ -1943,6 +1943,7 @@ Petri Hintukainen <Petri.Hintukainen@hut.fi>
for making cRemote::PutMacro() set a lock while it expands the macro for making cRemote::PutMacro() set a lock while it expands the macro
for pointing out that plugins from cRemote::PutMacro() and cRemote::CallPlugin() for pointing out that plugins from cRemote::PutMacro() and cRemote::CallPlugin()
need to be handled separately need to be handled separately
for making cTimeMs use the monotonic clock
Marcel Schaeben <mts280@gmx.de> Marcel Schaeben <mts280@gmx.de>
for his "Easy Input" patch for his "Easy Input" patch

View File

@ -5529,7 +5529,7 @@ Video Disk Recorder Revision History
- Fixed stopping live subtitles when a player is attached to the device. - Fixed stopping live subtitles when a player is attached to the device.
- Fixed suddenly stopping subtitles in live mode. - Fixed suddenly stopping subtitles in live mode.
2007-11-25: Version 1.5.13 2007-12-27: Version 1.5.13
- Fixed the declaration of cSubtitleObject::Decode8BppCodeString() (thanks to - Fixed the declaration of cSubtitleObject::Decode8BppCodeString() (thanks to
Gregoire Favre). Gregoire Favre).
@ -5538,3 +5538,4 @@ Video Disk Recorder Revision History
- The kInfo key is now propagated to any open menu, so that it can react to it - The kInfo key is now propagated to any open menu, so that it can react to it
in a context sensitive manner (suggested by Andreas Brugger). If there is in a context sensitive manner (suggested by Andreas Brugger). If there is
no menu open it will show the info of the current broadcast or replay. no menu open it will show the info of the current broadcast or replay.
- cTimeMs now uses the monotonic clock, if available (thanks to Petri Hintukainen).

View File

@ -4,7 +4,7 @@
# See the main source file 'vdr.c' for copyright information and # See the main source file 'vdr.c' for copyright information and
# how to reach the author. # how to reach the author.
# #
# $Id: Makefile 1.110 2007/11/04 10:15:59 kls Exp $ # $Id: Makefile 1.111 2007/12/02 11:29:22 kls Exp $
.DELETE_ON_ERROR: .DELETE_ON_ERROR:
@ -20,7 +20,7 @@ PREFIX ?= /usr/local
MANDIR = $(PREFIX)/share/man MANDIR = $(PREFIX)/share/man
BINDIR = $(PREFIX)/bin BINDIR = $(PREFIX)/bin
LOCDIR = ./locale LOCDIR = ./locale
LIBS = -ljpeg -lpthread -ldl -lcap -lfreetype -lfontconfig LIBS = -ljpeg -lpthread -ldl -lcap -lrt -lfreetype -lfontconfig
INCLUDES = -I/usr/include/freetype2 INCLUDES = -I/usr/include/freetype2
PLUGINDIR= ./PLUGINS PLUGINDIR= ./PLUGINS

37
tools.c
View File

@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and * See the main source file 'vdr.c' for copyright information and
* how to reach the author. * how to reach the author.
* *
* $Id: tools.c 1.137 2007/11/03 15:34:07 kls Exp $ * $Id: tools.c 1.138 2007/12/27 15:57:49 kls Exp $
*/ */
#include "tools.h" #include "tools.h"
@ -545,6 +545,41 @@ cTimeMs::cTimeMs(int Ms)
uint64_t cTimeMs::Now(void) uint64_t cTimeMs::Now(void)
{ {
#if _POSIX_TIMERS > 0 && defined(_POSIX_MONOTONIC_CLOCK)
#define MIN_RESOLUTION 5 // ms
static bool initialized = false;
static bool monotonic = false;
struct timespec tp;
if (!initialized) {
// check if monotonic timer is available and provides enough accurate resolution:
if (clock_getres(CLOCK_MONOTONIC, &tp) == 0) {
long Resolution = tp.tv_nsec;
// require a minimum resolution:
if (tp.tv_sec == 0 && tp.tv_nsec <= MIN_RESOLUTION * 1000000) {
if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0) {
dsyslog("cTimeMs: using monotonic clock (resolution is %ld ns)", Resolution);
monotonic = true;
}
else
esyslog("cTimeMs: clock_gettime(CLOCK_MONOTONIC) failed");
}
else
dsyslog("cTimeMs: not using monotonic clock - resolution is too bad (%ld s %ld ns)", tp.tv_sec, tp.tv_nsec);
}
else
esyslog("cTimeMs: clock_getres(CLOCK_MONOTONIC) failed");
initialized = true;
}
if (monotonic) {
if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
return (uint64_t(tp.tv_sec)) * 1000 + tp.tv_nsec / 1000000;
esyslog("cTimeMs: clock_gettime(CLOCK_MONOTONIC) failed");
monotonic = false;
// fall back to gettimeofday()
}
#else
# warning Posix monotonic clock not available
#endif
struct timeval t; struct timeval t;
if (gettimeofday(&t, NULL) == 0) if (gettimeofday(&t, NULL) == 0)
return (uint64_t(t.tv_sec)) * 1000 + t.tv_usec / 1000; return (uint64_t(t.tv_sec)) * 1000 + t.tv_usec / 1000;