gavltime.h
/*****************************************************************
* gavl - a general purpose audio/video processing library
*
* Copyright (c) 2001 - 2024 Members of the Gmerlin project
* http://github.com/bplaum
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
* *****************************************************************/
#ifndef GAVLTIME_H_INCLUDED
#define GAVLTIME_H_INCLUDED
#ifdef __cplusplus
extern "C" {
#endif
#include <inttypes.h>
#include <gavl/gavldefs.h>
#define GAVL_TIME_SCALE 1000000
#define GAVL_TIME_UNDEFINED 0x8000000000000000LL
#define GAVL_TIME_MAX 0x7fffffffffffffffLL
typedef int64_t gavl_time_t;
/* Utility functions */
GAVL_PUBLIC
gavl_time_t gavl_samples_to_time(int samplerate, int64_t samples);
GAVL_PUBLIC
int64_t gavl_time_to_samples(int samplerate, gavl_time_t time);
GAVL_PUBLIC
gavl_time_t gavl_frames_to_time(int rate_num, int rate_den, int64_t frames);
GAVL_PUBLIC
int64_t gavl_time_to_frames(int rate_num, int rate_den, gavl_time_t time);
GAVL_PUBLIC
int64_t gavl_time_scale(int scale, gavl_time_t time);
GAVL_PUBLIC
gavl_time_t gavl_time_unscale(int scale, int64_t time);
GAVL_PUBLIC
int64_t gavl_time_rescale(int scale1, int scale2, int64_t time);
#define gavl_seconds_to_time(s) (gavl_time_t)((s)*(double)(GAVL_TIME_SCALE))
#define gavl_time_to_seconds(t) ((double)(t)/(double)(GAVL_TIME_SCALE))
GAVL_PUBLIC
void gavl_time_delay(gavl_time_t * time);
#define GAVL_TIME_STRING_LEN 11
GAVL_PUBLIC void
gavl_time_prettyprint(gavl_time_t time, char str[GAVL_TIME_STRING_LEN]);
/*
* Same as gavl_time_prettyprint but prints just hh:mm:ss in 24h format,
* which are converted to local time from UTC
*/
GAVL_PUBLIC void
gavl_time_prettyprint_local(gavl_time_t gavl_time, char str[GAVL_TIME_STRING_LEN]);
#define GAVL_TIME_STRING_LEN_MS 15
/* 2022-10-10 23:05:12.000001 */
#define GAVL_TIME_STRING_LEN_ABSOLUTE 27
GAVL_PUBLIC void
gavl_time_prettyprint_ms(gavl_time_t time, char str[GAVL_TIME_STRING_LEN_MS]);
GAVL_PUBLIC void
gavl_time_prettyprint_ms_full(gavl_time_t time, char str[GAVL_TIME_STRING_LEN_MS]);
GAVL_PUBLIC void
gavl_time_prettyprint_absolute(gavl_time_t time, char * str, int local);
GAVL_PUBLIC void
gavl_time_prettyprint_absolute_full(gavl_time_t time, char * str, int local);
/* Scan time: format is hhh:mm:ss with hh: hours, mm: minutes, ss: seconds. Seconds can be a fractional
value (i.e. with decimal point) */
GAVL_PUBLIC
int gavl_time_parse(const char * str, gavl_time_t * ret);
GAVL_PUBLIC
int gavl_time_parse_iso8601(const char * str, gavl_time_t * ret);
GAVL_PUBLIC
gavl_time_t gavl_time_get_monotonic(void);
/* Returns microseconds since the epoch */
GAVL_PUBLIC
gavl_time_t gavl_time_get_realtime(void);
/* Simple software timer */
typedef struct gavl_timer_s gavl_timer_t;
GAVL_PUBLIC
gavl_timer_t * gavl_timer_create(void);
GAVL_PUBLIC
void gavl_timer_destroy(gavl_timer_t * timer);
GAVL_PUBLIC
void gavl_timer_start(gavl_timer_t * timer);
GAVL_PUBLIC
void gavl_timer_stop(gavl_timer_t * timer);
GAVL_PUBLIC
gavl_time_t gavl_timer_get(gavl_timer_t * timer);
GAVL_PUBLIC
int gavl_timer_is_running(gavl_timer_t * timer);
GAVL_PUBLIC
void gavl_timer_set(gavl_timer_t * timer, gavl_time_t t);
GAVL_PUBLIC
uint64_t gavl_benchmark_get_time(int flags);
GAVL_PUBLIC
const char * gavl_benchmark_get_desc(int flags);
#ifdef __cplusplus
}
#endif
#endif /* GAVLTIME_H_INCLUDED */
GAVL_TIME_STRING_LEN_MS
#define GAVL_TIME_STRING_LEN_MS
Length of the string passed to gavl_time_prettyprint_ms.
Definition gavltime.h:180
gavl_time_to_frames
GAVL_PUBLIC int64_t gavl_time_to_frames(int rate_num, int rate_den, gavl_time_t time)
Convert a time to a number of video frames for a given framerate.
gavl_time_delay
GAVL_PUBLIC void gavl_time_delay(gavl_time_t *time)
Sleep for a specified time.
GAVL_TIME_STRING_LEN
#define GAVL_TIME_STRING_LEN
Length of the string passed to gavl_time_prettyprint.
Definition gavltime.h:153
gavl_time_unscale
GAVL_PUBLIC gavl_time_t gavl_time_unscale(int scale, int64_t time)
Convert a time scaled by another base to a gavl time.
gavl_frames_to_time
GAVL_PUBLIC gavl_time_t gavl_frames_to_time(int rate_num, int rate_den, int64_t frames)
Convert a number of video frames to a time for a given framerate.
gavl_time_prettyprint_ms
GAVL_PUBLIC void gavl_time_prettyprint_ms(gavl_time_t time, char str[GAVL_TIME_STRING_LEN_MS])
Convert a time to a string with millisecond precision.
gavl_samples_to_time
GAVL_PUBLIC gavl_time_t gavl_samples_to_time(int samplerate, int64_t samples)
Convert a number of samples to a time for a given samplerate.
gavl_time_scale
GAVL_PUBLIC int64_t gavl_time_scale(int scale, gavl_time_t time)
Convert a gavl time to a time scaled by another base.
gavl_time_rescale
GAVL_PUBLIC int64_t gavl_time_rescale(int scale1, int scale2, int64_t time)
Convert a time scaled by one base to a time scaled by another base.
gavl_time_to_samples
GAVL_PUBLIC int64_t gavl_time_to_samples(int samplerate, gavl_time_t time)
Convert a time to a number of audio samples for a given samplerate.
gavl_time_t
int64_t gavl_time_t
Times in gavl are 64 bit signed integers.
Definition gavltime.h:54
gavl_time_prettyprint
GAVL_PUBLIC void gavl_time_prettyprint(gavl_time_t time, char str[GAVL_TIME_STRING_LEN])
Convert a time to a string.
gavl_timer_is_running
GAVL_PUBLIC int gavl_timer_is_running(gavl_timer_t *timer)
Check if a timer is running.
gavl_timer_stop
GAVL_PUBLIC void gavl_timer_stop(gavl_timer_t *timer)
Stop a timer.
gavl_timer_destroy
GAVL_PUBLIC void gavl_timer_destroy(gavl_timer_t *timer)
Destroy a timer.
gavl_timer_start
GAVL_PUBLIC void gavl_timer_start(gavl_timer_t *timer)
Start a timer.
gavl_benchmark_get_desc
GAVL_PUBLIC const char * gavl_benchmark_get_desc(int flags)
Get a description about the value returned by gavl_benchmark_get_time.
gavl_benchmark_get_time
GAVL_PUBLIC uint64_t gavl_benchmark_get_time(int flags)
Get the current time for benchmarking.
gavl_timer_get
GAVL_PUBLIC gavl_time_t gavl_timer_get(gavl_timer_t *timer)
Get the current time of the timer.
gavl_timer_create
GAVL_PUBLIC gavl_timer_t * gavl_timer_create(void)
Create a timer.
gavl_timer_t
struct gavl_timer_s gavl_timer_t
Opaque timer structure.
Definition gavltime.h:240
gavl_timer_set
GAVL_PUBLIC void gavl_timer_set(gavl_timer_t *timer, gavl_time_t t)
Set the current time of the timer.