| 1 | // Generated by gmmproc 2.50.1 -- DO NOT MODIFY! |
| 2 | #ifndef _GSTREAMERMM_CLOCK_H |
| 3 | #define _GSTREAMERMM_CLOCK_H |
| 4 | |
| 5 | |
| 6 | #include <glibmm/ustring.h> |
| 7 | #include <sigc++/sigc++.h> |
| 8 | |
| 9 | /* gstreamermm - a C++ wrapper for gstreamer |
| 10 | * |
| 11 | * Copyright 2008-2016 The gstreamermm Development Team |
| 12 | * |
| 13 | * This library is free software; you can redistribute it and/or |
| 14 | * modify it under the terms of the GNU Lesser General Public |
| 15 | * License as published by the Free Software Foundation; either |
| 16 | * version 2.1 of the License, or (at your option) any later version. |
| 17 | * |
| 18 | * This library is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 21 | * Lesser General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU Lesser General Public |
| 24 | * License along with this library; if not, write to the Free |
| 25 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 26 | */ |
| 27 | |
| 28 | #include <gst/gstclock.h> |
| 29 | #include <gstreamermm/object.h> |
| 30 | #include <gstreamermm/clockutils.h> |
| 31 | |
| 32 | |
| 33 | #ifndef DOXYGEN_SHOULD_SKIP_THIS |
| 34 | using GstClock = struct _GstClock; |
| 35 | using GstClockClass = struct _GstClockClass; |
| 36 | #endif /* DOXYGEN_SHOULD_SKIP_THIS */ |
| 37 | |
| 38 | |
| 39 | #ifndef DOXYGEN_SHOULD_SKIP_THIS |
| 40 | namespace Gst |
| 41 | { class Clock_Class; } // namespace Gst |
| 42 | #endif //DOXYGEN_SHOULD_SKIP_THIS |
| 43 | |
| 44 | namespace Gst |
| 45 | { |
| 46 | |
| 47 | class Clock; |
| 48 | |
| 49 | /** A data type to hold the handle to an outstanding sync or async clock |
| 50 | * callback. |
| 51 | */ |
| 52 | class ClockID |
| 53 | { |
| 54 | public: |
| 55 | #ifndef DOXYGEN_SHOULD_SKIP_THIS |
| 56 | using CppObjectType = ClockID; |
| 57 | using BaseObjectType = GstClockEntry; |
| 58 | #endif /* DOXYGEN_SHOULD_SKIP_THIS */ |
| 59 | |
| 60 | |
| 61 | /** Increment the reference count for this object. |
| 62 | * You should never need to do this manually - use the object via a RefPtr instead. |
| 63 | */ |
| 64 | void reference() const; |
| 65 | |
| 66 | /** Decrement the reference count for this object. |
| 67 | * You should never need to do this manually - use the object via a RefPtr instead. |
| 68 | */ |
| 69 | void unreference() const; |
| 70 | |
| 71 | ///Provides access to the underlying C instance. |
| 72 | GstClockEntry* gobj(); |
| 73 | |
| 74 | ///Provides access to the underlying C instance. |
| 75 | const GstClockEntry* gobj() const; |
| 76 | |
| 77 | ///Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. |
| 78 | GstClockEntry* gobj_copy() const; |
| 79 | |
| 80 | ClockID() = delete; |
| 81 | |
| 82 | // noncopyable |
| 83 | ClockID(const ClockID&) = delete; |
| 84 | ClockID& operator=(const ClockID&) = delete; |
| 85 | |
| 86 | protected: |
| 87 | // Do not derive this. Gst::ClockID can neither be constructed nor deleted. |
| 88 | |
| 89 | void operator delete(void*, std::size_t); |
| 90 | |
| 91 | private: |
| 92 | |
| 93 | |
| 94 | public: |
| 95 | /** For example, |
| 96 | * bool on_clock(const Glib::RefPtr<Gst::Clock>& clock, ClockTime time, const |
| 97 | * Glib::RefPtr<Gst::ClockID>& id);. |
| 98 | * The clock function return value is currently unused (see GstClockCallback). |
| 99 | */ |
| 100 | typedef sigc::slot< bool, const Glib::RefPtr<Gst::Clock>&, Gst::ClockTime, const Glib::RefPtr<Gst::ClockID>& > SlotClock; |
| 101 | |
| 102 | |
| 103 | /** Get the time of the clock ID |
| 104 | * |
| 105 | * @return The time of the given clock id. |
| 106 | * |
| 107 | * MT safe. |
| 108 | */ |
| 109 | Gst::ClockTime get_time() const; |
| 110 | |
| 111 | /** Perform a blocking wait on the Gst::ClockID. |
| 112 | * The Gst::ClockID should have been created with |
| 113 | * Gst::Clock::create_single_shot_id() or Gst::Clock::create_periodic_id() |
| 114 | * and should not have been unscheduled with a call to unschedule(). |
| 115 | * |
| 116 | * If this function returns Gst::CLOCK_OK or Gst::CLOCK_EARLY, |
| 117 | * the @a jitter argument will contain the difference |
| 118 | * against the clock and the time of the Gst::ClockID when this method was |
| 119 | * called. |
| 120 | * Positive values indicate how late the Gst::ClockID was relative to the clock |
| 121 | * (in which case this function will return Gst::CLOCK_EARLY). |
| 122 | * Negative values indicate how much time was spent waiting on the clock |
| 123 | * before this function returned. |
| 124 | * |
| 125 | * @param jitter A pointer that will contain the jitter. |
| 126 | * @return The result of the blocking wait. Gst::CLOCK_EARLY will be returned |
| 127 | * if the current clock time is past the time of the Gst::ClockID, Gst::CLOCK_OK |
| 128 | * if Gst::ClockID was scheduled in time. Gst::CLOCK_UNSCHEDULED if Gst::ClockID |
| 129 | * was unscheduled with unschedule(). |
| 130 | * |
| 131 | * MT safe. |
| 132 | */ |
| 133 | ClockReturn wait(Gst::ClockTimeDiff& jitter); |
| 134 | |
| 135 | /// A wait() convenience overload. |
| 136 | ClockReturn wait(); |
| 137 | |
| 138 | /** Register a slot on the given Gst::ClockID id with the given slot. When |
| 139 | * passing a Gst::ClockID with an invalid time to this function, the slot |
| 140 | * will be called immediatly with a time set to Gst::CLOCK_TIME_NONE. The |
| 141 | * slot will be called when the time of id has been reached. |
| 142 | * |
| 143 | * @param slot The slot to callback. |
| 144 | * @return The result of the non blocking wait. MT safe. |
| 145 | */ |
| 146 | ClockReturn wait_async(const SlotClock& slot); |
| 147 | |
| 148 | |
| 149 | /** Cancel an outstanding request with @a id. This can either |
| 150 | * be an outstanding async notification or a pending sync notification. |
| 151 | * After this call, @a id cannot be used anymore to receive sync or |
| 152 | * async notifications, you need to create a new Gst::ClockID. |
| 153 | * |
| 154 | * MT safe. |
| 155 | */ |
| 156 | void unschedule(); |
| 157 | |
| 158 | |
| 159 | }; |
| 160 | |
| 161 | /** Abstract class for global clocks |
| 162 | * GStreamer uses a global clock to synchronize the plugins in a pipeline. |
| 163 | * Different clock implementations are possible by implementing this abstract |
| 164 | * base class. |
| 165 | * |
| 166 | * The Gst::Clock returns a monotonically increasing time with the method |
| 167 | * get_time(). Its accuracy and base time depend on the specific |
| 168 | * clock implementation but time is always expressed in nanoseconds. Since the |
| 169 | * baseline of the clock is undefined, the clock time returned is not |
| 170 | * meaningful in itself, what matters are the deltas between two clock times. |
| 171 | * The time returned by a clock is called the absolute time. |
| 172 | * |
| 173 | * The pipeline uses the clock to calculate the running time. Usually all |
| 174 | * renderers synchronize to the global clock using the buffer timestamps, the |
| 175 | * newsegment events and the element's base time, see Gst::Pipeline. |
| 176 | * |
| 177 | * A clock implementation can support periodic and single shot clock |
| 178 | * notifications both synchronous and asynchronous. |
| 179 | * |
| 180 | * One first needs to create a Gst::ClockID for the periodic or single shot |
| 181 | * notification using create_single_shot_id() or create_periodic_id(). |
| 182 | * |
| 183 | * To perform a blocking wait for the specific time of the Gst::ClockID use the |
| 184 | * Gst::ClockID::wait(). To receive a callback when the specific time is reached |
| 185 | * in the clock use Gst::ClockID::wait_async(). Both these calls can be |
| 186 | * interrupted with the Gst::ClockID::unschedule() call. If the blocking wait is |
| 187 | * unscheduled a return value of Gst::CLOCK_UNSCHEDULED is returned. |
| 188 | * |
| 189 | * Periodic callbacks scheduled async will be repeatedly called automatically |
| 190 | * until it is unscheduled. To schedule a sync periodic callback, |
| 191 | * Gst::ClockID::wait() should be called repeatedly. |
| 192 | * |
| 193 | * The async callbacks can happen from any thread, either provided by the core |
| 194 | * or from a streaming thread. The application should be prepared for this. |
| 195 | * |
| 196 | * A Gst::ClockID that has been unscheduled cannot be used again for any wait |
| 197 | * operation, a new Gst::ClockID should be created. |
| 198 | * |
| 199 | * It is possible to perform a blocking wait on the same Gst::ClockID from |
| 200 | * multiple threads. However, registering the same Gst::ClockID for multiple |
| 201 | * async notifications is not possible, the callback will only be called for |
| 202 | * the thread registering the entry last. |
| 203 | * |
| 204 | * None of the wait operations unref the Gst::ClockID, the owner is responsible |
| 205 | * for unreffing the ids itself. This holds for both periodic and single shot |
| 206 | * notifications. The reason being that the owner of the Gst::ClockID has to |
| 207 | * keep a handle to the Gst::ClockID to unblock the wait on FLUSHING events or |
| 208 | * state changes and if the entry would be unreffed automatically, the handle |
| 209 | * might become invalid without any notification. (The RefPtr takes care of |
| 210 | - * unreffing in this case) |
| 211 | * |
| 212 | * These clock operations do not operate on the running time, so the callbacks |
| 213 | * will also occur when not in PLAYING state as if the clock just keeps on |
| 214 | * running. Some clocks however do not progress when the element that provided |
| 215 | * the clock is not PLAYING. |
| 216 | * |
| 217 | * When a clock has the Gst::CLOCK_FLAG_CAN_SET_MASTER flag set, it can be |
| 218 | * slaved to another Gst::Clock with the set_master(). The clock will |
| 219 | * then automatically be synchronized to this master clock by repeatedly |
| 220 | * sampling the master clock and the slave clock and recalibrating the slave |
| 221 | * clock with set_calibration(). This feature is mostly useful for |
| 222 | * plugins that have an internal clock but must operate with another clock |
| 223 | * selected by the Gst::Pipeline. They can track the offset and rate difference |
| 224 | * of their internal clock relative to the master clock by using the |
| 225 | * get_calibration() method. |
| 226 | * |
| 227 | * The master/slave synchronisation can be tuned with the "timeout", |
| 228 | * "window-size" and "window-threshold" properties. The "timeout" property |
| 229 | * defines the interval to sample the master clock and run the calibration |
| 230 | * functions. "window-size" defines the number of samples to use when |
| 231 | * calibrating and "window-threshold" defines the minimum number of samples |
| 232 | * before the calibration is performed. |
| 233 | * |
| 234 | * Last reviewed on 2016-05-16 (1.8.0) |
| 235 | */ |
| 236 | |
| 237 | class Clock : public Object |
| 238 | { |
| 239 | |
| 240 | #ifndef DOXYGEN_SHOULD_SKIP_THIS |
| 241 | |
| 242 | public: |
| 243 | using CppObjectType = Clock; |
| 244 | using CppClassType = Clock_Class; |
| 245 | using BaseObjectType = GstClock; |
| 246 | using BaseClassType = GstClockClass; |
| 247 | |
| 248 | // noncopyable |
| 249 | Clock(const Clock&) = delete; |
| 250 | Clock& operator=(const Clock&) = delete; |
| 251 | |
| 252 | private: friend class Clock_Class; |
| 253 | static CppClassType clock_class_; |
| 254 | |
| 255 | protected: |
| 256 | explicit Clock(const Glib::ConstructParams& construct_params); |
| 257 | explicit Clock(GstClock* castitem); |
| 258 | |
| 259 | #endif /* DOXYGEN_SHOULD_SKIP_THIS */ |
| 260 | |
| 261 | public: |
| 262 | |
| 263 | Clock(Clock&& src) noexcept; |
| 264 | Clock& operator=(Clock&& src) noexcept; |
| 265 | |
| 266 | ~Clock() noexcept override; |
| 267 | |
| 268 | /** Get the GType for this class, for use with the underlying GObject type system. |
| 269 | */ |
| 270 | static GType get_type() G_GNUC_CONST; |
| 271 | |
| 272 | #ifndef DOXYGEN_SHOULD_SKIP_THIS |
| 273 | |
| 274 | |
| 275 | static GType get_base_type() G_GNUC_CONST; |
| 276 | #endif |
| 277 | |
| 278 | ///Provides access to the underlying C GObject. |
| 279 | GstClock* gobj() { return reinterpret_cast<GstClock*>(gobject_); } |
| 280 | |
| 281 | ///Provides access to the underlying C GObject. |
| 282 | const GstClock* gobj() const { return reinterpret_cast<GstClock*>(gobject_); } |
| 283 | |
| 284 | ///Provides access to the underlying C instance. The caller is responsible for unrefing it. Use when directly setting fields in structs. |
| 285 | GstClock* gobj_copy(); |
| 286 | |
| 287 | private: |
| 288 | |
| 289 | |
| 290 | public: |
| 291 | |
| 292 | /** The time @a master_time of the master clock and the time @a slave_time of the slave |
| 293 | * clock are added to the list of observations. If enough observations |
| 294 | * are available, a linear regression algorithm is run on the |
| 295 | * observations and @a clock is recalibrated. |
| 296 | * |
| 297 | * If this functions returns <tt>true</tt>, @a result will contain the |
| 298 | * correlation coefficient of the interpolation. A value of 1.0 |
| 299 | * means a perfect regression was performed. This value can |
| 300 | * be used to control the sampling frequency of the master and slave |
| 301 | * clocks. |
| 302 | * |
| 303 | * @param slave_time A time on the slave. |
| 304 | * @param master_time A time on the master. |
| 305 | * @param result A pointer to hold the result. |
| 306 | * @return <tt>true</tt> if enough observations were added to run the |
| 307 | * regression algorithm. |
| 308 | * |
| 309 | * MT safe. |
| 310 | */ |
| 311 | bool add_observation(Gst::ClockTime slave_time, Gst::ClockTime master_time, gdouble& result); |
| 312 | |
| 313 | /** Add a clock observation to the internal slaving algorithm the same as |
| 314 | * add_observation(), and return the result of the master clock |
| 315 | * estimation, without updating the internal calibration. |
| 316 | * |
| 317 | * The caller can then take the results and call set_calibration() |
| 318 | * with the values, or some modified version of them. |
| 319 | * |
| 320 | * @param slave_time A time on the slave. |
| 321 | * @param master_time A time on the master. |
| 322 | * @param result A pointer to hold the result. |
| 323 | * @param internal A location to store the internal time. |
| 324 | * @param external A location to store the external time. |
| 325 | * @param rate_num A location to store the rate numerator. |
| 326 | * @param rate_denom A location to store the rate denominator. |
| 327 | */ |
| 328 | 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); |
| 329 | |
| 330 | /** Set @a master_clock as the master clock for @a clock. @a clock will be automatically |
| 331 | * calibrated so that get_time() reports the same time as the |
| 332 | * master clock. |
| 333 | * |
| 334 | * A clock provider that slaves its clock to a master can get the current |
| 335 | * calibration values with get_calibration(). |
| 336 | * |
| 337 | * @a master_clock can be <tt>nullptr</tt> in which case @a clock will not be slaved anymore. It will |
| 338 | * however keep reporting its time adjusted with the last configured rate |
| 339 | * and time offsets. |
| 340 | * |
| 341 | * @param master_clock A master Gst::Clock. |
| 342 | * @return <tt>true</tt> if the clock is capable of being slaved to a master clock. |
| 343 | * Trying to set a master on a clock without the |
| 344 | * Gst::CLOCK_FLAG_CAN_SET_MASTER flag will make this function return <tt>false</tt>. |
| 345 | * |
| 346 | * MT safe. |
| 347 | */ |
| 348 | bool set_master(const Clock& master_clock); |
| 349 | |
| 350 | /** Get the master clock that @a clock is slaved to or <tt>nullptr</tt> when the clock is |
| 351 | * not slaved to any master clock. |
| 352 | * |
| 353 | * @return A master Gst::Clock or <tt>nullptr</tt> |
| 354 | * when this clock is not slaved to a master clock. Unref after |
| 355 | * usage. |
| 356 | * |
| 357 | * MT safe. |
| 358 | */ |
| 359 | Glib::RefPtr<Gst::Clock> get_master(); |
| 360 | |
| 361 | /** Get the master clock that @a clock is slaved to or <tt>nullptr</tt> when the clock is |
| 362 | * not slaved to any master clock. |
| 363 | * |
| 364 | * @return A master Gst::Clock or <tt>nullptr</tt> |
| 365 | * when this clock is not slaved to a master clock. Unref after |
| 366 | * usage. |
| 367 | * |
| 368 | * MT safe. |
| 369 | */ |
| 370 | Glib::RefPtr<const Gst::Clock> get_master() const; |
| 371 | |
| 372 | /** Set the accuracy of the clock. Some clocks have the possibility to operate |
| 373 | * with different accuracy at the expense of more resource usage. There is |
| 374 | * normally no need to change the default resolution of a clock. The resolution |
| 375 | * of a clock can only be changed if the clock has the |
| 376 | * Gst::CLOCK_FLAG_CAN_SET_RESOLUTION flag set. |
| 377 | * |
| 378 | * @param resolution The resolution to set. |
| 379 | * @return The new resolution of the clock. |
| 380 | */ |
| 381 | Gst::ClockTime set_resolution(Gst::ClockTime resolution); |
| 382 | |
| 383 | /** Get the accuracy of the clock. The accuracy of the clock is the granularity |
| 384 | * of the values returned by get_time(). |
| 385 | * |
| 386 | * @return The resolution of the clock in units of Gst::ClockTime. |
| 387 | * |
| 388 | * MT safe. |
| 389 | */ |
| 390 | Gst::ClockTime get_resolution() const; |
| 391 | |
| 392 | /** Gets the current time of the given clock. The time is always |
| 393 | * monotonically increasing and adjusted according to the current |
| 394 | * offset and rate. |
| 395 | * |
| 396 | * @return The time of the clock. Or GST_CLOCK_TIME_NONE when |
| 397 | * given invalid input. |
| 398 | * |
| 399 | * MT safe. |
| 400 | */ |
| 401 | Gst::ClockTime get_time() const; |
| 402 | |
| 403 | /** Get a Gst::ClockID from @a clock to trigger a single shot |
| 404 | * notification at the requested time. The single shot id should be |
| 405 | * unreffed after usage. |
| 406 | * |
| 407 | * Free-function: gst_clock_id_unref |
| 408 | * |
| 409 | * @param time The requested time. |
| 410 | * @return A Gst::ClockID that can be used to request the |
| 411 | * time notification. |
| 412 | * |
| 413 | * MT safe. |
| 414 | */ |
| 415 | Glib::RefPtr<Gst::ClockID> create_single_shot_id(Gst::ClockTime time); |
| 416 | |
| 417 | /** Get an ID from @a clock to trigger a periodic notification. |
| 418 | * The periodic notifications will start at time @a start_time and |
| 419 | * will then be fired with the given @a intervals. @a id should be unreffed |
| 420 | * after usage. |
| 421 | * |
| 422 | * Free-function: gst_clock_id_unref |
| 423 | * |
| 424 | * @param start_time The requested start time. |
| 425 | * @param intervals The requested interval. |
| 426 | * @return A Gst::ClockID that can be used to request the |
| 427 | * time notification. |
| 428 | * |
| 429 | * MT safe. |
| 430 | */ |
| 431 | Glib::RefPtr<Gst::ClockID> create_periodic_id(Gst::ClockTime start_time, Gst::ClockTime intervals); |
| 432 | |
| 433 | /** Reinitializes the provided single shot @a id to the provided time. Does not |
| 434 | * modify the reference count. |
| 435 | * |
| 436 | * @param id A Gst::ClockID. |
| 437 | * @param time The requested time. |
| 438 | * @return <tt>true</tt> if the GstClockID could be reinitialized to the provided |
| 439 | * @a time, else <tt>false</tt>. |
| 440 | */ |
| 441 | bool single_shot_id_reinit(const Glib::RefPtr<Gst::ClockID>& id, Gst::ClockTime time); |
| 442 | |
| 443 | /** Reinitializes the provided periodic @a id to the provided start time and |
| 444 | * interval. Does not modify the reference count. |
| 445 | * |
| 446 | * @param id A Gst::ClockID. |
| 447 | * @param start_time The requested start time. |
| 448 | * @param interval The requested interval. |
| 449 | * @return <tt>true</tt> if the GstClockID could be reinitialized to the provided |
| 450 | * @a time, else <tt>false</tt>. |
| 451 | */ |
| 452 | bool periodic_id_reinit(const Glib::RefPtr<Gst::ClockID>& id, Gst::ClockTime start_time, Gst::ClockTime interval); |
| 453 | |
| 454 | /** Gets the current internal time of the given clock. The time is returned |
| 455 | * unadjusted for the offset and the rate. |
| 456 | * |
| 457 | * @return The internal time of the clock. Or GST_CLOCK_TIME_NONE when |
| 458 | * given invalid input. |
| 459 | * |
| 460 | * MT safe. |
| 461 | */ |
| 462 | Gst::ClockTime get_internal_time() const; |
| 463 | |
| 464 | /** Converts the given @a internal_time clock time to the external time, adjusting for the |
| 465 | * rate and reference time set with set_calibration() and making sure |
| 466 | * that the returned time is increasing. This function should be called with the |
| 467 | * clock's OBJECT_LOCK held and is mainly used by clock subclasses. |
| 468 | * |
| 469 | * This function is the reverse of unadjust_unlocked(). |
| 470 | * |
| 471 | * @param internal_time A clock time. |
| 472 | * @return The converted time of the clock. |
| 473 | */ |
| 474 | Gst::ClockTime adjust_unlocked(Gst::ClockTime internal_time); |
| 475 | |
| 476 | /** Converts the given @a external_time clock time to the internal time of @a clock, |
| 477 | * using the rate and reference time set with set_calibration(). |
| 478 | * This function should be called with the clock's OBJECT_LOCK held and |
| 479 | * is mainly used by clock subclasses. |
| 480 | * |
| 481 | * This function is the reverse of adjust_unlocked(). |
| 482 | * |
| 483 | * @param external_time An external clock time. |
| 484 | * @return The internal time of the clock corresponding to @a external_time. |
| 485 | */ |
| 486 | Gst::ClockTime unadjust_unlocked(Gst::ClockTime external_time); |
| 487 | |
| 488 | /** Converts the given @a internal_target clock time to the external time, |
| 489 | * using the passed calibration parameters. This function performs the |
| 490 | * same calculation as adjust_unlocked() when called using the |
| 491 | * current calibration parameters, but doesn't ensure a monotonically |
| 492 | * increasing result as adjust_unlocked() does. |
| 493 | * |
| 494 | * @note The @a clock parameter is unused and can be <tt>nullptr</tt> |
| 495 | * |
| 496 | * @param internal_target A clock time. |
| 497 | * @param cinternal A reference internal time. |
| 498 | * @param cexternal A reference external time. |
| 499 | * @param cnum The numerator of the rate of the clock relative to its |
| 500 | * internal time. |
| 501 | * @param cdenom The denominator of the rate of the clock. |
| 502 | * @return The converted time of the clock. |
| 503 | */ |
| 504 | Gst::ClockTime adjust_with_calibration(Gst::ClockTime internal_target, Gst::ClockTime cinternal, Gst::ClockTime cexternal, Gst::ClockTime cnum, Gst::ClockTime cdenom); |
| 505 | |
| 506 | /** Converts the given @a external_target clock time to the internal time, |
| 507 | * using the passed calibration parameters. This function performs the |
| 508 | * same calculation as unadjust_unlocked() when called using the |
| 509 | * current calibration parameters. |
| 510 | * |
| 511 | * @note The @a clock parameter is unused and can be <tt>nullptr</tt> |
| 512 | * |
| 513 | * @param external_target A clock time. |
| 514 | * @param cinternal A reference internal time. |
| 515 | * @param cexternal A reference external time. |
| 516 | * @param cnum The numerator of the rate of the clock relative to its |
| 517 | * internal time. |
| 518 | * @param cdenom The denominator of the rate of the clock. |
| 519 | * @return The converted time of the clock. |
| 520 | */ |
| 521 | Gst::ClockTime unadjust_with_calibration(Gst::ClockTime external_target, Gst::ClockTime cinternal, Gst::ClockTime cexternal, Gst::ClockTime cnum, Gst::ClockTime cdenom); |
| 522 | |
| 523 | /** Gets the internal rate and reference time of @a clock. See |
| 524 | * set_calibration() for more information. |
| 525 | * |
| 526 | * @a internal, @a external, @a rate_num, and @a rate_denom can be left <tt>nullptr</tt> if the |
| 527 | * caller is not interested in the values. |
| 528 | * |
| 529 | * MT safe. |
| 530 | * |
| 531 | * @param internal A location to store the internal time. |
| 532 | * @param external A location to store the external time. |
| 533 | * @param rate_num A location to store the rate numerator. |
| 534 | * @param rate_denom A location to store the rate denominator. |
| 535 | */ |
| 536 | void get_calibration(Gst::ClockTime& internal, Gst::ClockTime& external, Gst::ClockTime& rate_num, Gst::ClockTime& rate_denom) const; |
| 537 | |
| 538 | /** Adjusts the rate and time of @a clock. A rate of 1/1 is the normal speed of |
| 539 | * the clock. Values bigger than 1/1 make the clock go faster. |
| 540 | * |
| 541 | * @a internal and @a external are calibration parameters that arrange that |
| 542 | * get_time() should have been @a external at internal time @a internal. |
| 543 | * This internal time should not be in the future; that is, it should be less |
| 544 | * than the value of get_internal_time() when this function is called. |
| 545 | * |
| 546 | * Subsequent calls to get_time() will return clock times computed as |
| 547 | * follows: |
| 548 | * |
| 549 | * |
| 550 | * time = (internal_time - internal) * rate_num / rate_denom + external |
| 551 | * |
| 552 | * |
| 553 | * This formula is implemented in adjust_unlocked(). Of course, it |
| 554 | * tries to do the integer arithmetic as precisely as possible. |
| 555 | * |
| 556 | * Note that get_time() always returns increasing values so when you |
| 557 | * move the clock backwards, get_time() will report the previous value |
| 558 | * until the clock catches up. |
| 559 | * |
| 560 | * MT safe. |
| 561 | * |
| 562 | * @param internal A reference internal time. |
| 563 | * @param external A reference external time. |
| 564 | * @param rate_num The numerator of the rate of the clock relative to its |
| 565 | * internal time. |
| 566 | * @param rate_denom The denominator of the rate of the clock. |
| 567 | */ |
| 568 | void set_calibration(Gst::ClockTime internal, Gst::ClockTime external, Gst::ClockTime rate_num, Gst::ClockTime rate_denom); |
| 569 | |
| 570 | /** Waits until @a clock is synced for reporting the current time. If @a timeout |
| 571 | * is Gst::CLOCK_TIME_NONE it will wait forever, otherwise it will time out |
| 572 | * after @a timeout nanoseconds. |
| 573 | * |
| 574 | * For asynchronous waiting, the GstClock::synced signal can be used. |
| 575 | * |
| 576 | * |
| 577 | * This returns immediately with <tt>true</tt> if GST_CLOCK_FLAG_NEEDS_STARTUP_SYNC |
| 578 | * is not set on the clock, or if the clock is already synced. |
| 579 | * |
| 580 | * @param timeout Timeout for waiting or Gst::CLOCK_TIME_NONE. |
| 581 | * @return <tt>true</tt> if waiting was successful, or <tt>false</tt> on timeout. |
| 582 | */ |
| 583 | bool wait_for_sync(Gst::ClockTime timeout); |
| 584 | |
| 585 | /** Checks if the clock is currently synced. |
| 586 | * |
| 587 | * This returns if GST_CLOCK_FLAG_NEEDS_STARTUP_SYNC is not set on the clock. |
| 588 | * |
| 589 | * @return <tt>true</tt> if the clock is currently synced. |
| 590 | */ |
| 591 | bool is_synced() const; |
| 592 | |
| 593 | /** Sets @a clock to synced and emits the GstClock::synced signal, and wakes up any |
| 594 | * thread waiting in wait_for_sync(). |
| 595 | * |
| 596 | * This function must only be called if GST_CLOCK_FLAG_NEEDS_STARTUP_SYNC |
| 597 | * is set on the clock, and is intended to be called by subclasses only. |
| 598 | * |
| 599 | * @param synced If the clock is synced. |
| 600 | */ |
| 601 | void set_synced(bool synced); |
| 602 | |
| 603 | /// get/set timeout can be achieved through 'timeout' property, |
| 604 | /// so wrapping gst_clock_{get|set|_timeout is unnecessary. |
| 605 | |
| 606 | |
| 607 | /** The amount of time, in nanoseconds, to sample master and slave clocks. |
| 608 | * |
| 609 | * @return A PropertyProxy that allows you to get or set the value of the property, |
| 610 | * or receive notification when the value of the property changes. |
| 611 | */ |
| 612 | Glib::PropertyProxy< guint64 > property_timeout() ; |
| 613 | |
| 614 | /** The amount of time, in nanoseconds, to sample master and slave clocks. |
| 615 | * |
| 616 | * @return A PropertyProxy_ReadOnly that allows you to get the value of the property, |
| 617 | * or receive notification when the value of the property changes. |
| 618 | */ |
| 619 | Glib::PropertyProxy_ReadOnly< guint64 > property_timeout() const; |
| 620 | |
| 621 | /** The size of the window used to calculate rate and offset. |
| 622 | * |
| 623 | * @return A PropertyProxy that allows you to get or set the value of the property, |
| 624 | * or receive notification when the value of the property changes. |
| 625 | */ |
| 626 | Glib::PropertyProxy< int > property_window_size() ; |
| 627 | |
| 628 | /** The size of the window used to calculate rate and offset. |
| 629 | * |
| 630 | * @return A PropertyProxy_ReadOnly that allows you to get the value of the property, |
| 631 | * or receive notification when the value of the property changes. |
| 632 | */ |
| 633 | Glib::PropertyProxy_ReadOnly< int > property_window_size() const; |
| 634 | |
| 635 | /** The threshold to start calculating rate and offset. |
| 636 | * |
| 637 | * @return A PropertyProxy that allows you to get or set the value of the property, |
| 638 | * or receive notification when the value of the property changes. |
| 639 | */ |
| 640 | Glib::PropertyProxy< int > property_window_threshold() ; |
| 641 | |
| 642 | /** The threshold to start calculating rate and offset. |
| 643 | * |
| 644 | * @return A PropertyProxy_ReadOnly that allows you to get the value of the property, |
| 645 | * or receive notification when the value of the property changes. |
| 646 | */ |
| 647 | Glib::PropertyProxy_ReadOnly< int > property_window_threshold() const; |
| 648 | |
| 649 | |
| 650 | /** Change the resolution of the clock. Not all values might be acceptable. |
| 651 | * The new resolution should be returned. |
| 652 | */ |
| 653 | virtual Gst::ClockTime change_resolution_vfunc(Gst::ClockTime old_resolution, Gst::ClockTime new_resolution); |
| 654 | |
| 655 | |
| 656 | /** Get the resolution of the clock. |
| 657 | */ |
| 658 | virtual Gst::ClockTime get_resolution_vfunc() const; |
| 659 | |
| 660 | |
| 661 | /** Get the internal unadjusted time of the clock. |
| 662 | */ |
| 663 | virtual Gst::ClockTime get_internal_time_vfunc() const; |
| 664 | |
| 665 | |
| 666 | /** Perform a blocking wait for the given Gst::ClockID. Deprecated, |
| 667 | * implement wait_jitter_vfunc() instead. |
| 668 | */ |
| 669 | virtual ClockReturn wait_vfunc(const Glib::RefPtr<Gst::ClockID>& id, Gst::ClockTimeDiff& jitter); |
| 670 | |
| 671 | |
| 672 | /** Perform an asynchronous wait for the given Gst::ClockID. |
| 673 | */ |
| 674 | virtual ClockReturn wait_async_vfunc(const Glib::RefPtr<Gst::ClockID>& id); |
| 675 | |
| 676 | |
| 677 | /** Unblock a blocking or async wait operation. |
| 678 | */ |
| 679 | virtual void unschedule_vfunc(const Glib::RefPtr<Gst::ClockID>& id); |
| 680 | |
| 681 | |
| 682 | /** |
| 683 | * @par Slot Prototype: |
| 684 | * <tt>void on_my_%synced(bool synced)</tt> |
| 685 | * |
| 686 | * Signaled on clocks with GST_CLOCK_FLAG_NEEDS_STARTUP_SYNC set once |
| 687 | * the clock is synchronized, or when it completely lost synchronization. |
| 688 | * This signal will not be emitted on clocks without the flag. |
| 689 | * |
| 690 | * This signal will be emitted from an arbitrary thread, most likely not |
| 691 | * the application's main thread. |
| 692 | * |
| 693 | * @param synced If the clock is synced now. |
| 694 | */ |
| 695 | |
| 696 | Glib::SignalProxy< void,bool > signal_synced(); |
| 697 | |
| 698 | |
| 699 | public: |
| 700 | |
| 701 | public: |
| 702 | //C++ methods used to invoke GTK+ virtual functions: |
| 703 | |
| 704 | protected: |
| 705 | //GTK+ Virtual Functions (override these to change behaviour): |
| 706 | |
| 707 | //Default Signal Handlers:: |
| 708 | |
| 709 | |
| 710 | }; |
| 711 | |
| 712 | } //namespace Gst |
| 713 | |
| 714 | |
| 715 | namespace Glib |
| 716 | { |
| 717 | |
| 718 | /** A Glib::wrap() method for this object. |
| 719 | * |
| 720 | * @param object The C instance. |
| 721 | * @param take_copy False if the result should take ownership of the C instance. True if it should take a new copy or ref. |
| 722 | * @result A C++ instance that wraps this C instance. |
| 723 | * |
| 724 | * @relates Gst::ClockID |
| 725 | */ |
| 726 | Glib::RefPtr<Gst::ClockID> wrap(GstClockEntry* object, bool take_copy = false); |
| 727 | |
| 728 | } // namespace Glib |
| 729 | |
| 730 | |
| 731 | namespace Glib |
| 732 | { |
| 733 | /** A Glib::wrap() method for this object. |
| 734 | * |
| 735 | * @param object The C instance. |
| 736 | * @param take_copy False if the result should take ownership of the C instance. True if it should take a new copy or ref. |
| 737 | * @result A C++ instance that wraps this C instance. |
| 738 | * |
| 739 | * @relates Gst::Clock |
| 740 | */ |
| 741 | Glib::RefPtr<Gst::Clock> wrap(GstClock* object, bool take_copy = false); |
| 742 | } |
| 743 | |
| 744 | |
| 745 | #endif /* _GSTREAMERMM_CLOCK_H */ |
| 746 |