gavl

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

gavltime.h
1 /*****************************************************************
2 * gavl - a general purpose audio/video processing library
3 *
4 * Copyright (c) 2001 - 2011 Members of the Gmerlin project
5 * gmerlin-general@lists.sourceforge.net
6 * http://gmerlin.sourceforge.net
7 *
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * *****************************************************************/
21
22 #ifndef GAVLTIME_H_INCLUDED
23 #define GAVLTIME_H_INCLUDED
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 #include <inttypes.h>
30 #include <gavl/gavldefs.h>
31
38 #define GAVL_TIME_SCALE 1000000
43 #define GAVL_TIME_UNDEFINED 0x8000000000000000LL
46 #define GAVL_TIME_MAX 0x7fffffffffffffffLL
53 typedef int64_t gavl_time_t;
54
55 /* Utility functions */
56
61 GAVL_PUBLIC
62 gavl_time_t gavl_samples_to_time(int samplerate, int64_t samples);
63
71 GAVL_PUBLIC
72 int64_t gavl_time_to_samples(int samplerate, gavl_time_t time);
73
78 GAVL_PUBLIC
79 gavl_time_t gavl_frames_to_time(int rate_num, int rate_den, int64_t frames);
80
81
90 GAVL_PUBLIC
91 int64_t gavl_time_to_frames(int rate_num, int rate_den, gavl_time_t time);
92
100 GAVL_PUBLIC
101 int64_t gavl_time_scale(int scale, gavl_time_t time);
102
110 GAVL_PUBLIC
111 gavl_time_t gavl_time_unscale(int scale, int64_t time);
112
121 GAVL_PUBLIC
122 int64_t gavl_time_rescale(int scale1, int scale2, int64_t time);
123
130 #define gavl_seconds_to_time(s) (gavl_time_t)((s)*(double)(GAVL_TIME_SCALE))
131
138 #define gavl_time_to_seconds(t) ((double)(t)/(double)(GAVL_TIME_SCALE))
139
145 GAVL_PUBLIC
146 void gavl_time_delay(gavl_time_t * time);
147
152 #define GAVL_TIME_STRING_LEN 11
153
163 GAVL_PUBLIC void
164 gavl_time_prettyprint(gavl_time_t time, char str[GAVL_TIME_STRING_LEN]);
165
170 #define GAVL_TIME_STRING_LEN_MS 15
171
183 GAVL_PUBLIC void
184 gavl_time_prettyprint_ms(gavl_time_t time, char str[GAVL_TIME_STRING_LEN_MS]);
185
186
187 /* Scan time: format is hhh:mm:ss with hh: hours, mm: minutes, ss: seconds. Seconds can be a fractional
188 value (i.e. with decimal point) */
189
190 GAVL_PUBLIC
191 int gavl_time_parse(const char * str, gavl_time_t * ret);
192
193
194 /* Simple software timer */
195
210 typedef struct gavl_timer_s gavl_timer_t;
211
217 GAVL_PUBLIC
218 gavl_timer_t * gavl_timer_create();
219
227 GAVL_PUBLIC
228 void gavl_timer_destroy(gavl_timer_t * timer);
229
235 GAVL_PUBLIC
236 void gavl_timer_start(gavl_timer_t * timer);
237
243 GAVL_PUBLIC
244 void gavl_timer_stop(gavl_timer_t * timer);
245
252 GAVL_PUBLIC
253 gavl_time_t gavl_timer_get(gavl_timer_t * timer);
254
261 GAVL_PUBLIC
262 void gavl_timer_set(gavl_timer_t * timer, gavl_time_t t);
263
275 GAVL_PUBLIC
276 uint64_t gavl_benchmark_get_time(int flags);
277
286 GAVL_PUBLIC
287 const char * gavl_benchmark_get_desc(int flags);
288
289
290 #ifdef __cplusplus
291 }
292 #endif
293
294 #endif /* GAVLTIME_H_INCLUDED */
295
gavl_timer_get
GAVL_PUBLIC gavl_time_t gavl_timer_get(gavl_timer_t *timer)
Get the current time of the timer.
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_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_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_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_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_timer_create
GAVL_PUBLIC gavl_timer_t * gavl_timer_create()
Create a timer.
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_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_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_timer_set
GAVL_PUBLIC void gavl_timer_set(gavl_timer_t *timer, gavl_time_t t)
Set the current time of the timer.
gavl_timer_t
struct gavl_timer_s gavl_timer_t
Opaque timer structure.
Definition: gavltime.h:210
gavl_time_t
int64_t gavl_time_t
Times in gavl are 64 bit signed integers.
Definition: gavltime.h:53
gavl_benchmark_get_time
GAVL_PUBLIC uint64_t gavl_benchmark_get_time(int flags)
Get the current time for benchmarking.
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_timer_start
GAVL_PUBLIC void gavl_timer_start(gavl_timer_t *timer)
Start a timer.
GAVL_TIME_STRING_LEN_MS
#define GAVL_TIME_STRING_LEN_MS
Length of the string passed to gavl_time_prettyprint_ms.
Definition: gavltime.h:170
GAVL_TIME_STRING_LEN
#define GAVL_TIME_STRING_LEN
Length of the string passed to gavl_time_prettyprint.
Definition: gavltime.h:152
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
GAVL_PUBLIC void gavl_time_prettyprint(gavl_time_t time, char str[GAVL_TIME_STRING_LEN])
Convert a time to a string.