VLC 4.0.0-dev
Loading...
Searching...
No Matches
clock.h
Go to the documentation of this file.
1/*****************************************************************************
2 * clock.h: Output modules synchronisation clock
3 *****************************************************************************
4 * Copyright (C) 2018-2019 VLC authors, VideoLAN and Videolabs SAS
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19 *****************************************************************************/
20#ifndef CLOCK_H
21#define CLOCK_H
22
23#include <vlc_clock.h>
24
32
33/**
34 * Callbacks for the owner of the main clock
35 */
37{
38 /**
39 * Called when a clock is updated
40 *
41 * @param system_ts system date when the ts will be rendered,
42 * VLC_TICK_INVALID when the clock is reset or VLC_TICK_MAX when the update
43 * is forced (an output was still rendered while paused for example). Note:
44 * when valid, this date can be in the future, it is not necessarily now.
45 * @param ts stream timestamp or VLC_TICK_INVALID when the clock is reset,
46 * should be subtracted with VLC_TICK_0 to get the original value
47 * @param rate rate used when updated
48 * @param frame_rate fps of the video owning the clock
49 * @param frame_rate_base fps denominator
50 * @param data opaque pointer set from vlc_clock_main_New()
51 */
52 void (*on_update)(vlc_tick_t system_ts, vlc_tick_t ts, double rate,
53 unsigned frame_rate, unsigned frame_rate_base,
54 void *data);
55};
56
57/**
58 * Event callbacks for the user of a vlc_clock_t
59 */
61{
62 /**
63 * Called when the master source triggered a discontinuity.
64 *
65 * A discontinuity happens when:
66 * - The first point is updated from the master source
67 *
68 * @param data opaque pointer set from vlc_clock_main_New()
69 */
70 void (*on_discontinuity)(void *data);
71};
72
74
75/**
76 * This function creates the vlc_clock_main_t of the program
77 */
78vlc_clock_main_t *vlc_clock_main_New(struct vlc_logger *parent_logger, struct vlc_tracer *parent_tracer);
79
80/**
81 * Destroy the clock main
82 *
83 * @param main_clock the unlocked main_clock
84 */
86
87/**
88 * Lock the main_clock mutex
89 *
90 * All vlc_clock_main_t functions must be called with the lock held, except
91 * vlc_clock_main_Delete()
92 *
93 * @param main_clock the unlocked main_clock
94 */
96
97/**
98 * Unlock the main_clock mutex
99 *
100 * @param main_clock the locked main_clock
101 */
103
104/**
105 * Reset the vlc_clock_main_t
106 *
107 * @param main_clock the locked main_clock
108 */
109void vlc_clock_main_Reset(vlc_clock_main_t *main_clock);
110
111/**
112 * Set the first PCR point
113 *
114 * @param main_clock the locked main_clock
115 */
117 vlc_tick_t system_now, vlc_tick_t ts);
118
119/**
120 * Set the input dejitter
121 *
122 * @param main_clock the locked main_clock
123 */
125 vlc_tick_t delay);
126
127/**
128 * This function sets the dejitter delay to absorb the clock jitter
129 *
130 * Also used as the maximum delay before the synchro is considered to kick in.
131 *
132 * @param main_clock the locked main_clock
133 */
134void vlc_clock_main_SetDejitter(vlc_clock_main_t *main_clock, vlc_tick_t dejitter);
135
136
137/**
138 * This function allows changing the pause status.
139 *
140 * @param main_clock the locked main_clock
141 */
143 bool paused);
144
145/**
146 * This function creates a new master vlc_clock_t interface
147 *
148 * @warning There can be only one master at a given time.
149 *
150 * You must use vlc_clock_Delete to free it.
151 *
152 * @param main_clock the locked main_clock
153 */
155 const char *track_str_id,
156 const struct vlc_clock_cbs *cbs,
157 void *cbs_data);
158
159/**
160 * This function creates a new input master vlc_clock_t interface
161 *
162 * Once the input master is created, the current or future master clock created
163 * from vlc_clock_main_CreateMaster() will be demoted as slave.
164 *
165 * @warning There can be only one input master at a given time.
166 *
167 * You must use vlc_clock_Delete to free it.
168 *
169 * @param main_clock the locked main_clock
170 */
172
173/**
174 * This function creates a new input slave vlc_clock_t interface
175 *
176 * @warning There can be only one input, slave or master, at a given time.
177 *
178 * You must use vlc_clock_Delete to free it.
179 *
180 * @param main_clock the locked main_clock
181 */
183
184/**
185 * This function creates a new slave vlc_clock_t interface
186 *
187 * You must use vlc_clock_Delete to free it.
188 *
189 * @param main_clock the locked main_clock
190 */
192 const char *track_str_id,
193 enum es_format_category_e cat,
194 const struct vlc_clock_cbs *cbs,
195 void *cbs_data);
196
197/**
198 * This function creates a new slave vlc_clock_t interface
199 *
200 * You must use vlc_clock_Delete to free it.
201 *
202 * @param main_clock the locked main_clock
203 */
205 enum es_format_category_e cat);
206
207/**
208 * This function free the resources allocated by vlc_clock*Create*()
209 *
210 * @param clock the unlocked clock used by the source
211 */
213
214/**
215 * This function will update the clock drift and returns the drift
216 *
217 * @param clock the locked clock used by the source
218 * @param system_now valid system time or VLC_TICK_MAX is the updated point is
219 * forced (when paused for example)
220 * @param ts the timestamp in media time for the updated point
221 * @param rate the current playback speed
222 *
223 * @return a valid drift relative time, VLC_TICK_INVALID if there is no drift
224 * (clock is master)
225 */
227 vlc_tick_t ts, double rate);
228
229/**
230 * This function will update the video clock drift and returns the drift
231 *
232 * Same behavior than vlc_clock_Update() except that the video is passed to the
233 * clock, this will be used for clock update callbacks.
234 */
236 vlc_tick_t ts, double rate,
237 unsigned frame_rate, unsigned frame_rate_base);
238
239/**
240 * This function resets the clock drift
241 *
242 * @param clock the locked clock used by the source
243 */
245
246/**
247 * This functions change the clock delay
248 *
249 * It returns the amount of time the clock owner need to wait in order to reach
250 * the time introduced by the new positive delay.
251 *
252 * @param clock the locked clock used by the source
253 */
255
256/**
257 * Lock the clock mutex
258 *
259 * @param clock the unlocked clock used by the source
260 */
262
263/**
264 * Unlock the clock mutex
265 *
266 * @param clock the locked clock used by the source
267 */
269
270/**
271 * Indicate if the clock is paused
272 *
273 * The clock mutex must be locked.
274 *
275 * @param clock the locked clock used by the source
276 * @retval true if the clock is paused
277 * @retval false if the clock is not paused
278 */
280
281/**
282 * Wait for a timestamp expressed in system time
283 *
284 * The wait will be interrupted (signaled) on clock state changes which could
285 * invalidate the computed deadline. In that case, the caller must recompute
286 * the new deadline and call it again.
287 *
288 * @param clock the locked clock used by the source
289 * @return 0 if the condition was signaled, an error code in case of timeout
290 */
291int vlc_clock_Wait(vlc_clock_t *clock, vlc_tick_t system_deadline);
292
293/**
294 * Wake up any vlc_clock_Wait()
295 *
296 * @param clock the locked clock used by the source
297 */
299
300/**
301 * Add a listener for events
302 *
303 * @param clock the locked clock used by the source
304 * @param cbs valid pointer to register events
305 * @param data opaque data used by cbs
306 * @return a valid listener id, or NULL in case of allocation error
307 */
310 const struct vlc_clock_event_cbs *cbs,
311 void *data);
312
313/**
314 * Remove a event listener callback
315 *
316 * @param clock the locked clock used by the source
317 * @param listener_id listener id returned by vlc_clock_AddListener()
318 */
319void
321
322/**
323 * This function converts a timestamp from stream to system
324 *
325 * @param clock the locked clock used by the source
326 * @param clock_id pointer to the clock id used for conversion. Can be NULL.
327 * @return the valid system time
328 */
330 vlc_tick_t system_now, vlc_tick_t ts,
331 double rate, uint32_t *clock_id);
332
333#endif /*CLOCK_H*/
void vlc_clock_Unlock(vlc_clock_t *clock)
Unlock the clock mutex.
Definition clock.c:676
vlc_tick_t vlc_clock_UpdateVideo(vlc_clock_t *clock, vlc_tick_t system_now, vlc_tick_t ts, double rate, unsigned frame_rate, unsigned frame_rate_base)
This function will update the video clock drift and returns the drift.
Definition clock.c:879
void vlc_clock_main_Delete(vlc_clock_main_t *main_clock)
Destroy the clock main.
Definition clock.c:841
void vlc_clock_main_Reset(vlc_clock_main_t *main_clock)
Reset the vlc_clock_main_t.
Definition clock.c:753
vlc_clock_t * vlc_clock_main_CreateSlave(vlc_clock_main_t *main_clock, const char *track_str_id, enum es_format_category_e cat, const struct vlc_clock_cbs *cbs, void *cbs_data)
This function creates a new slave vlc_clock_t interface.
Definition clock.c:1037
void vlc_clock_Delete(vlc_clock_t *clock)
This function free the resources allocated by vlc_clock*Create*()
Definition clock.c:1079
void vlc_clock_Lock(vlc_clock_t *clock)
Lock the clock mutex.
Definition clock.c:670
vlc_tick_t vlc_clock_ConvertToSystem(vlc_clock_t *clock, vlc_tick_t system_now, vlc_tick_t ts, double rate, uint32_t *clock_id)
This function converts a timestamp from stream to system.
Definition clock.c:903
vlc_tick_t vlc_clock_Update(vlc_clock_t *clock, vlc_tick_t system_now, vlc_tick_t ts, double rate)
This function will update the clock drift and returns the drift.
Definition clock.c:869
void vlc_clock_Reset(vlc_clock_t *clock)
This function resets the clock drift.
Definition clock.c:891
vlc_clock_t * vlc_clock_main_CreateInputMaster(vlc_clock_main_t *main_clock)
This function creates a new input master vlc_clock_t interface.
Definition clock.c:993
void vlc_clock_main_Unlock(vlc_clock_main_t *main_clock)
Unlock the main_clock mutex.
Definition clock.c:863
void vlc_clock_main_ChangePause(vlc_clock_main_t *clock, vlc_tick_t system_now, bool paused)
This function allows changing the pause status.
Definition clock.c:809
int vlc_clock_Wait(vlc_clock_t *clock, vlc_tick_t system_deadline)
Wait for a timestamp expressed in system time.
Definition clock.c:696
vlc_clock_master_source
Definition clock.h:26
@ VLC_CLOCK_MASTER_INPUT
Definition clock.h:29
@ VLC_CLOCK_MASTER_MONOTONIC
Definition clock.h:30
@ VLC_CLOCK_MASTER_AUTO
Definition clock.h:27
@ VLC_CLOCK_MASTER_AUDIO
Definition clock.h:28
vlc_clock_t * vlc_clock_main_CreateMaster(vlc_clock_main_t *main_clock, const char *track_str_id, const struct vlc_clock_cbs *cbs, void *cbs_data)
This function creates a new master vlc_clock_t interface.
Definition clock.c:967
void vlc_clock_main_SetFirstPcr(vlc_clock_main_t *main_clock, vlc_tick_t system_now, vlc_tick_t ts)
Set the first PCR point.
Definition clock.c:763
void vlc_clock_RemoveListener(vlc_clock_t *clock, vlc_clock_listener_id *listener_id)
Remove a event listener callback.
Definition clock.c:149
vlc_clock_main_t * vlc_clock_main_New(struct vlc_logger *parent_logger, struct vlc_tracer *parent_tracer)
This function creates the vlc_clock_main_t of the program.
Definition clock.c:712
void vlc_clock_Wake(vlc_clock_t *clock)
Wake up any vlc_clock_Wait()
Definition clock.c:704
void vlc_clock_main_Lock(vlc_clock_main_t *main_clock)
Lock the main_clock mutex.
Definition clock.c:858
void vlc_clock_main_SetInputDejitter(vlc_clock_main_t *main_clock, vlc_tick_t delay)
Set the input dejitter.
Definition clock.c:793
vlc_clock_t * vlc_clock_CreateSlave(const vlc_clock_t *clock, enum es_format_category_e cat)
This function creates a new slave vlc_clock_t interface.
Definition clock.c:1073
vlc_tick_t vlc_clock_SetDelay(vlc_clock_t *clock, vlc_tick_t ts_delay)
This functions change the clock delay.
Definition clock.c:897
void vlc_clock_main_SetDejitter(vlc_clock_main_t *main_clock, vlc_tick_t dejitter)
This function sets the dejitter delay to absorb the clock jitter.
Definition clock.c:801
vlc_clock_listener_id * vlc_clock_AddListener(vlc_clock_t *clock, const struct vlc_clock_event_cbs *cbs, void *data)
Add a listener for events.
Definition clock.c:123
vlc_clock_t * vlc_clock_main_CreateInputSlave(vlc_clock_main_t *main_clock)
This function creates a new input slave vlc_clock_t interface.
Definition clock.c:1021
bool vlc_clock_IsPaused(const vlc_clock_t *clock)
Indicate if the clock is paused.
Definition clock.c:688
Callbacks for the owner of the main clock.
Definition clock.h:37
void(* on_update)(vlc_tick_t system_ts, vlc_tick_t ts, double rate, unsigned frame_rate, unsigned frame_rate_base, void *data)
Called when a clock is updated.
Definition clock.h:52
Event callbacks for the user of a vlc_clock_t.
Definition clock.h:61
void(* on_discontinuity)(void *data)
Called when the master source triggered a discontinuity.
Definition clock.h:70
Definition clock.c:42
void * data
Definition clock.c:45
const struct vlc_clock_event_cbs * cbs
Definition clock.c:44
vlc_clock_t * clock
Definition clock.c:43
Definition clock.c:63
Definition clock.c:105
Definition messages.c:85
Definition tracer.c:36
es_format_category_e
ES Categories.
Definition vlc_es.h:616
int64_t vlc_tick_t
High precision date or time interval.
Definition vlc_tick.h:48