mirror of
https://github.com/mpv-player/mpv
synced 2024-12-26 17:12:36 +00:00
f47a4fc3d9
Use the time as returned by mp_time_us() for mpthread_cond_timedwait(), instead of calculating the struct timespec value based on a timeout. This (probably) makes it easier to wait for a specific deadline.
55 lines
2.0 KiB
C
55 lines
2.0 KiB
C
/*
|
|
* This file is part of MPlayer.
|
|
*
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License along
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
*/
|
|
|
|
#ifndef MPLAYER_TIMER_H
|
|
#define MPLAYER_TIMER_H
|
|
|
|
#include <inttypes.h>
|
|
|
|
// Initialize timer, must be called at least once at start.
|
|
void mp_time_init(void);
|
|
|
|
// Return time in microseconds. Never wraps. Never returns 0 or negative values.
|
|
int64_t mp_time_us(void);
|
|
|
|
// Return time in seconds. Can have down to 1 microsecond resolution, but will
|
|
// be much worse when casted to float.
|
|
double mp_time_sec(void);
|
|
|
|
// Provided by OS specific functions (timer-linux.c)
|
|
void mp_raw_time_init(void);
|
|
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);
|
|
|
|
// Add a time in seconds to the given time in microseconds, and return it.
|
|
// Takes care of possible overflows. Never returns a negative or 0 time.
|
|
int64_t mp_add_timeout(int64_t time_us, double timeout_sec);
|
|
|
|
// Convert the mp time in microseconds to a timespec using CLOCK_REALTIME.
|
|
struct timespec mp_time_us_to_timespec(int64_t time_us);
|
|
|
|
#endif /* MPLAYER_TIMER_H */
|