timer: add utility function to get relative time

This commit is contained in:
wm4 2014-02-28 23:18:52 +01:00
parent 97409ec4e6
commit 1f8a400ad7
2 changed files with 17 additions and 0 deletions

View File

@ -19,6 +19,7 @@
#include <pthread.h>
#include "timer.h"
#include "common/msg.h"
static uint64_t raw_time_offset;
pthread_once_t timer_init_once = PTHREAD_ONCE_INIT;
@ -49,6 +50,16 @@ double mp_time_sec(void)
return mp_time_us() / (double)(1000 * 1000);
}
int64_t mp_time_relative_us(int64_t *t)
{
int64_t r = 0;
int64_t now = mp_time_us();
if (*t)
r = now - *t;
*t = now;
return r;
}
#if 0
#include <stdio.h>

View File

@ -38,4 +38,10 @@ uint64_t mp_raw_time_us(void);
// Sleep in microseconds.
void mp_sleep_us(int64_t us);
// Return the amount of time that has passed since the last call, in
// microseconds. *t is used to calculate the time that has passed by storing
// the current time in it. If *t is 0, the call will return 0. (So that the
// first call will return 0, instead of the absolute current time.)
int64_t mp_time_relative_us(int64_t *t);
#endif /* MPLAYER_TIMER_H */