Debian Codegraph @

gstreamer/src/clock.hg

raw
1 /* gstreamermm - a C++ wrapper for gstreamer
2 *
3 * Copyright 2008-2016 The gstreamermm Development Team
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free
17 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 #include <gst/gstclock.h>
21 #include <gstreamermm/object.h>
22 #include <gstreamermm/clockutils.h>
23
24 _DEFS(gstreamermm,gst)
25
26 namespace Gst
27 {
28
29 class Clock;
30
31 /** A data type to hold the handle to an outstanding sync or async clock
32 * callback.
33 */
34 class ClockID
35 {
36 _CLASS_OPAQUE_REFCOUNTED(ClockID, GstClockEntry, NONE, gst_clock_id_ref, gst_clock_id_unref)
37 _IGNORE(gst_clock_id_ref, gst_clock_id_unref)
38
39 public:
40 /** For example,
41 * bool on_clock(const Glib::RefPtr<Gst::Clock>& clock, ClockTime time, const
42 * Glib::RefPtr<Gst::ClockID>& id);.
43 * The clock function return value is currently unused (see GstClockCallback).
44 */
45 typedef sigc::slot< bool, const Glib::RefPtr<Gst::Clock>&, Gst::ClockTime, const Glib::RefPtr<Gst::ClockID>& > SlotClock;
46
47 _WRAP_METHOD(Gst::ClockTime get_time() const, gst_clock_id_get_time)
48 _WRAP_METHOD(ClockReturn wait(Gst::ClockTimeDiff& jitter{?}), gst_clock_id_wait)
49
50 /** Register a slot on the given Gst::ClockID id with the given slot. When
51 * passing a Gst::ClockID with an invalid time to this function, the slot
52 * will be called immediatly with a time set to Gst::CLOCK_TIME_NONE. The
53 * slot will be called when the time of id has been reached.
54 *
55 * @param slot The slot to callback.
56 * @return The result of the non blocking wait. MT safe.
57 */
58 ClockReturn wait_async(const SlotClock& slot);
59 _IGNORE(gst_clock_id_wait_async)
60
61 _WRAP_METHOD(void unschedule(), gst_clock_id_unschedule)
62 };
63
64 /** Abstract class for global clocks
65 * GStreamer uses a global clock to synchronize the plugins in a pipeline.
66 * Different clock implementations are possible by implementing this abstract
67 * base class.
68 *
69 * The Gst::Clock returns a monotonically increasing time with the method
70 * get_time(). Its accuracy and base time depend on the specific
71 * clock implementation but time is always expressed in nanoseconds. Since the
72 * baseline of the clock is undefined, the clock time returned is not
73 * meaningful in itself, what matters are the deltas between two clock times.
74 * The time returned by a clock is called the absolute time.
75 *
76 * The pipeline uses the clock to calculate the running time. Usually all
77 * renderers synchronize to the global clock using the buffer timestamps, the
78 * newsegment events and the element's base time, see Gst::Pipeline.
79 *
80 * A clock implementation can support periodic and single shot clock
81 * notifications both synchronous and asynchronous.
82 *
83 * One first needs to create a Gst::ClockID for the periodic or single shot
84 * notification using create_single_shot_id() or create_periodic_id().
85 *
86 * To perform a blocking wait for the specific time of the Gst::ClockID use the
87 * Gst::ClockID::wait(). To receive a callback when the specific time is reached
88 * in the clock use Gst::ClockID::wait_async(). Both these calls can be
89 * interrupted with the Gst::ClockID::unschedule() call. If the blocking wait is
90 * unscheduled a return value of Gst::CLOCK_UNSCHEDULED is returned.
91 *
92 * Periodic callbacks scheduled async will be repeatedly called automatically
93 * until it is unscheduled. To schedule a sync periodic callback,
94 * Gst::ClockID::wait() should be called repeatedly.
95 *
96 * The async callbacks can happen from any thread, either provided by the core
97 * or from a streaming thread. The application should be prepared for this.
98 *
99 * A Gst::ClockID that has been unscheduled cannot be used again for any wait
100 * operation, a new Gst::ClockID should be created.
101 *
102 * It is possible to perform a blocking wait on the same Gst::ClockID from
103 * multiple threads. However, registering the same Gst::ClockID for multiple
104 * async notifications is not possible, the callback will only be called for
105 * the thread registering the entry last.
106 *
107 * None of the wait operations unref the Gst::ClockID, the owner is responsible
108 * for unreffing the ids itself. This holds for both periodic and single shot
109 * notifications. The reason being that the owner of the Gst::ClockID has to
110 * keep a handle to the Gst::ClockID to unblock the wait on FLUSHING events or
111 * state changes and if the entry would be unreffed automatically, the handle
112 * might become invalid without any notification. (The RefPtr takes care of
113 - * unreffing in this case)
114 *
115 * These clock operations do not operate on the running time, so the callbacks
116 * will also occur when not in PLAYING state as if the clock just keeps on
117 * running. Some clocks however do not progress when the element that provided
118 * the clock is not PLAYING.
119 *
120 * When a clock has the Gst::CLOCK_FLAG_CAN_SET_MASTER flag set, it can be
121 * slaved to another Gst::Clock with the set_master(). The clock will
122 * then automatically be synchronized to this master clock by repeatedly
123 * sampling the master clock and the slave clock and recalibrating the slave
124 * clock with set_calibration(). This feature is mostly useful for
125 * plugins that have an internal clock but must operate with another clock
126 * selected by the Gst::Pipeline. They can track the offset and rate difference
127 * of their internal clock relative to the master clock by using the
128 * get_calibration() method.
129 *
130 * The master/slave synchronisation can be tuned with the "timeout",
131 * "window-size" and "window-threshold" properties. The "timeout" property
132 * defines the interval to sample the master clock and run the calibration
133 * functions. "window-size" defines the number of samples to use when
134 * calibrating and "window-threshold" defines the minimum number of samples
135 * before the calibration is performed.
136 *
137 * Last reviewed on 2016-05-16 (1.8.0)
138 */
139 class Clock : public Object
140 {
141 _CLASS_GOBJECT(Clock, GstClock, GST_CLOCK, Object, GstObject)
142
143 public:
144 _WRAP_METHOD(bool add_observation(Gst::ClockTime slave_time, Gst::ClockTime master_time, gdouble& result), gst_clock_add_observation)
145 _WRAP_METHOD(bool add_observation(Gst::ClockTime slave_time, Gst::ClockTime master_time, gdouble& result, Gst::ClockTime& internal, Gst::ClockTime& external, Gst::ClockTime& rate_num, Gst::ClockTime& rate_denom), gst_clock_add_observation_unapplied)
146 _WRAP_METHOD(bool set_master(const Clock& master_clock), gst_clock_set_master)
147 _WRAP_METHOD(Glib::RefPtr<Gst::Clock> get_master(), gst_clock_get_master)
148 _WRAP_METHOD(Glib::RefPtr<const Gst::Clock> get_master() const, gst_clock_get_master, constversion)
149 _WRAP_METHOD(Gst::ClockTime set_resolution(Gst::ClockTime resolution), gst_clock_set_resolution)
150 _WRAP_METHOD(Gst::ClockTime get_resolution() const, gst_clock_get_resolution)
151 _WRAP_METHOD(Gst::ClockTime get_time() const, gst_clock_get_time)
152 _WRAP_METHOD(Glib::RefPtr<Gst::ClockID> create_single_shot_id(Gst::ClockTime time), gst_clock_new_single_shot_id)
153 _WRAP_METHOD(Glib::RefPtr<Gst::ClockID> create_periodic_id(Gst::ClockTime start_time, Gst::ClockTime intervals), gst_clock_new_periodic_id)
154 _WRAP_METHOD(bool single_shot_id_reinit(const Glib::RefPtr<Gst::ClockID>& id, Gst::ClockTime time), gst_clock_single_shot_id_reinit)
155 _WRAP_METHOD(bool periodic_id_reinit(const Glib::RefPtr<Gst::ClockID>& id, Gst::ClockTime start_time, Gst::ClockTime interval), gst_clock_periodic_id_reinit)
156 _WRAP_METHOD(Gst::ClockTime get_internal_time() const, gst_clock_get_internal_time)
157 _WRAP_METHOD(Gst::ClockTime adjust_unlocked(Gst::ClockTime internal_time), gst_clock_adjust_unlocked)
158 _WRAP_METHOD(Gst::ClockTime unadjust_unlocked(Gst::ClockTime external_time), gst_clock_unadjust_unlocked)
159 _WRAP_METHOD(Gst::ClockTime adjust_with_calibration(Gst::ClockTime internal_target, Gst::ClockTime cinternal, Gst::ClockTime cexternal, Gst::ClockTime cnum, Gst::ClockTime cdenom), gst_clock_adjust_with_calibration)
160 _WRAP_METHOD(Gst::ClockTime unadjust_with_calibration(Gst::ClockTime external_target, Gst::ClockTime cinternal, Gst::ClockTime cexternal, Gst::ClockTime cnum, Gst::ClockTime cdenom), gst_clock_unadjust_with_calibration)
161 _WRAP_METHOD(void get_calibration(Gst::ClockTime& internal, Gst::ClockTime& external, Gst::ClockTime& rate_num, Gst::ClockTime& rate_denom) const, gst_clock_get_calibration)
162 _WRAP_METHOD(void set_calibration(Gst::ClockTime internal, Gst::ClockTime external, Gst::ClockTime rate_num, Gst::ClockTime rate_denom), gst_clock_set_calibration)
163 _WRAP_METHOD(bool wait_for_sync(Gst::ClockTime timeout), gst_clock_wait_for_sync)
164 _WRAP_METHOD(bool is_synced() const, gst_clock_is_synced)
165 _WRAP_METHOD(void set_synced(bool synced), gst_clock_set_synced)
166
167 /// get/set timeout can be achieved through 'timeout' property,
168 /// so wrapping gst_clock_{get|set|_timeout is unnecessary.
169 _IGNORE(gst_clock_set_timeout, gst_clock_get_timeout)
170
171 _WRAP_PROPERTY("timeout", guint64)
172 _WRAP_PROPERTY("window-size", int)
173 _WRAP_PROPERTY("window-threshold", int)
174
175 /** Change the resolution of the clock. Not all values might be acceptable.
176 * The new resolution should be returned.
177 */
178 _WRAP_VFUNC(Gst::ClockTime change_resolution(Gst::ClockTime old_resolution, Gst::ClockTime new_resolution), "change_resolution")
179
180 /** Get the resolution of the clock.
181 */
182 _WRAP_VFUNC(Gst::ClockTime get_resolution() const, "get_resolution")
183
184 /** Get the internal unadjusted time of the clock.
185 */
186 _WRAP_VFUNC(Gst::ClockTime get_internal_time() const, "get_internal_time")
187
188 #m4 _CONVERSION(`GstClockEntry*',`const Glib::RefPtr<Gst::ClockID>&',`Glib::wrap($3, true)')
189
190 /** Perform a blocking wait for the given Gst::ClockID. Deprecated,
191 * implement wait_jitter_vfunc() instead.
192 */
193 _WRAP_VFUNC(ClockReturn wait(const Glib::RefPtr<Gst::ClockID>& id, Gst::ClockTimeDiff& jitter), "wait")
194
195 /** Perform an asynchronous wait for the given Gst::ClockID.
196 */
197 _WRAP_VFUNC(ClockReturn wait_async(const Glib::RefPtr<Gst::ClockID>& id), "wait_async")
198
199 /** Unblock a blocking or async wait operation.
200 */
201 _WRAP_VFUNC(void unschedule(const Glib::RefPtr<Gst::ClockID>& id), "unschedule")
202
203 _WRAP_SIGNAL(void synced(bool synced), "synced", no_default_handler)
204 };
205
206 } //namespace Gst