2009-03-01 13:13:25 +00:00
|
|
|
/*
|
2015-04-13 07:36:54 +00:00
|
|
|
* This file is part of mpv.
|
2009-03-01 13:13:25 +00:00
|
|
|
*
|
2017-05-05 10:34:56 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2009-03-01 13:13:25 +00:00
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2009-03-01 13:13:25 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2017-05-05 10:34:56 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2009-03-01 13:13:25 +00:00
|
|
|
*
|
2017-05-05 10:34:56 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2009-03-01 13:13:25 +00:00
|
|
|
*/
|
|
|
|
|
2007-07-31 07:04:07 +00:00
|
|
|
#ifndef MPLAYER_TIMER_H
|
|
|
|
#define MPLAYER_TIMER_H
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2013-05-17 17:54:37 +00:00
|
|
|
#include <inttypes.h>
|
2024-04-06 21:31:05 +00:00
|
|
|
#include "config.h"
|
2001-02-24 20:28:24 +00:00
|
|
|
|
2013-05-17 17:54:37 +00:00
|
|
|
// Initialize timer, must be called at least once at start.
|
|
|
|
void mp_time_init(void);
|
|
|
|
|
2024-01-24 16:02:26 +00:00
|
|
|
// Return time in nanoseconds. Never wraps. Never returns negative values.
|
2023-09-10 00:09:28 +00:00
|
|
|
int64_t mp_time_ns(void);
|
|
|
|
|
2024-04-06 21:31:05 +00:00
|
|
|
// Return time in nanoseconds. Coverts raw time in nanoseconds to mp time, subtracts init offset.
|
|
|
|
int64_t mp_time_ns_from_raw_time(uint64_t raw_time);
|
|
|
|
|
2023-09-29 22:24:21 +00:00
|
|
|
// Return time in seconds. Can have down to 1 nanosecond resolution, but will
|
2013-05-17 17:54:37 +00:00
|
|
|
// 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);
|
2023-10-26 19:24:41 +00:00
|
|
|
// ensure this doesn't return 0
|
2023-09-10 00:09:28 +00:00
|
|
|
uint64_t mp_raw_time_ns(void);
|
2013-05-17 17:54:37 +00:00
|
|
|
|
2023-09-29 22:24:21 +00:00
|
|
|
// Sleep in nanoseconds.
|
|
|
|
void mp_sleep_ns(int64_t ns);
|
2013-05-17 17:54:37 +00:00
|
|
|
|
2024-04-06 21:31:05 +00:00
|
|
|
#if HAVE_DARWIN
|
|
|
|
// Coverts mach time to raw time in nanoseconds and returns it.
|
|
|
|
uint64_t mp_raw_time_ns_from_mach(uint64_t mach_time);
|
|
|
|
#endif
|
|
|
|
|
2021-09-15 14:04:17 +00:00
|
|
|
#ifdef _WIN32
|
2023-10-26 19:13:12 +00:00
|
|
|
// returns: timer resolution in ns if needed and started successfully, else 0
|
|
|
|
int64_t mp_start_hires_timers(int64_t wait_ns);
|
2021-09-15 14:04:17 +00:00
|
|
|
|
|
|
|
// call unconditionally with the return value of mp_start_hires_timers
|
2023-10-26 19:13:12 +00:00
|
|
|
void mp_end_hires_timers(int64_t resolution_ns);
|
2021-09-15 14:04:17 +00:00
|
|
|
#endif /* _WIN32 */
|
|
|
|
|
2023-10-11 16:34:14 +00:00
|
|
|
// Converts time units to nanoseconds (int64_t)
|
|
|
|
#define MP_TIME_S_TO_NS(s) ((s) * INT64_C(1000000000))
|
|
|
|
#define MP_TIME_MS_TO_NS(ms) ((ms) * INT64_C(1000000))
|
|
|
|
#define MP_TIME_US_TO_NS(us) ((us) * INT64_C(1000))
|
|
|
|
|
|
|
|
// Converts nanoseconds to specified time unit (double)
|
|
|
|
#define MP_TIME_NS_TO_S(ns) ((ns) / (double)1000000000)
|
|
|
|
#define MP_TIME_NS_TO_MS(ns) ((ns) / (double)1000000)
|
|
|
|
#define MP_TIME_NS_TO_US(ns) ((ns) / (double)1000)
|
|
|
|
|
2023-09-10 00:09:28 +00:00
|
|
|
// Add a time in seconds to the given time in nanoseconds, and return it.
|
|
|
|
// Takes care of possible overflows. Never returns a negative or 0 time.
|
|
|
|
int64_t mp_time_ns_add(int64_t time_ns, double timeout_sec);
|
|
|
|
|
2007-07-31 07:04:07 +00:00
|
|
|
#endif /* MPLAYER_TIMER_H */
|