/* gstreamermm - a C++ wrapper for gstreamer * * Copyright 2008-2016 The gstreamermm Development Team * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include #include _DEFS(gstreamermm,gst) namespace Gst { class Clock; /** A data type to hold the handle to an outstanding sync or async clock * callback. */ class ClockID { _CLASS_OPAQUE_REFCOUNTED(ClockID, GstClockEntry, NONE, gst_clock_id_ref, gst_clock_id_unref) _IGNORE(gst_clock_id_ref, gst_clock_id_unref) public: /** For example, * bool on_clock(const Glib::RefPtr& clock, ClockTime time, const * Glib::RefPtr& id);. * The clock function return value is currently unused (see GstClockCallback). */ typedef sigc::slot< bool, const Glib::RefPtr&, Gst::ClockTime, const Glib::RefPtr& > SlotClock; _WRAP_METHOD(Gst::ClockTime get_time() const, gst_clock_id_get_time) _WRAP_METHOD(ClockReturn wait(Gst::ClockTimeDiff& jitter{?}), gst_clock_id_wait) /** Register a slot on the given Gst::ClockID id with the given slot. When * passing a Gst::ClockID with an invalid time to this function, the slot * will be called immediatly with a time set to Gst::CLOCK_TIME_NONE. The * slot will be called when the time of id has been reached. * * @param slot The slot to callback. * @return The result of the non blocking wait. MT safe. */ ClockReturn wait_async(const SlotClock& slot); _IGNORE(gst_clock_id_wait_async) _WRAP_METHOD(void unschedule(), gst_clock_id_unschedule) }; /** Abstract class for global clocks * GStreamer uses a global clock to synchronize the plugins in a pipeline. * Different clock implementations are possible by implementing this abstract * base class. * * The Gst::Clock returns a monotonically increasing time with the method * get_time(). Its accuracy and base time depend on the specific * clock implementation but time is always expressed in nanoseconds. Since the * baseline of the clock is undefined, the clock time returned is not * meaningful in itself, what matters are the deltas between two clock times. * The time returned by a clock is called the absolute time. * * The pipeline uses the clock to calculate the running time. Usually all * renderers synchronize to the global clock using the buffer timestamps, the * newsegment events and the element's base time, see Gst::Pipeline. * * A clock implementation can support periodic and single shot clock * notifications both synchronous and asynchronous. * * One first needs to create a Gst::ClockID for the periodic or single shot * notification using create_single_shot_id() or create_periodic_id(). * * To perform a blocking wait for the specific time of the Gst::ClockID use the * Gst::ClockID::wait(). To receive a callback when the specific time is reached * in the clock use Gst::ClockID::wait_async(). Both these calls can be * interrupted with the Gst::ClockID::unschedule() call. If the blocking wait is * unscheduled a return value of Gst::CLOCK_UNSCHEDULED is returned. * * Periodic callbacks scheduled async will be repeatedly called automatically * until it is unscheduled. To schedule a sync periodic callback, * Gst::ClockID::wait() should be called repeatedly. * * The async callbacks can happen from any thread, either provided by the core * or from a streaming thread. The application should be prepared for this. * * A Gst::ClockID that has been unscheduled cannot be used again for any wait * operation, a new Gst::ClockID should be created. * * It is possible to perform a blocking wait on the same Gst::ClockID from * multiple threads. However, registering the same Gst::ClockID for multiple * async notifications is not possible, the callback will only be called for * the thread registering the entry last. * * None of the wait operations unref the Gst::ClockID, the owner is responsible * for unreffing the ids itself. This holds for both periodic and single shot * notifications. The reason being that the owner of the Gst::ClockID has to * keep a handle to the Gst::ClockID to unblock the wait on FLUSHING events or * state changes and if the entry would be unreffed automatically, the handle * might become invalid without any notification. (The RefPtr takes care of - * unreffing in this case) * * These clock operations do not operate on the running time, so the callbacks * will also occur when not in PLAYING state as if the clock just keeps on * running. Some clocks however do not progress when the element that provided * the clock is not PLAYING. * * When a clock has the Gst::CLOCK_FLAG_CAN_SET_MASTER flag set, it can be * slaved to another Gst::Clock with the set_master(). The clock will * then automatically be synchronized to this master clock by repeatedly * sampling the master clock and the slave clock and recalibrating the slave * clock with set_calibration(). This feature is mostly useful for * plugins that have an internal clock but must operate with another clock * selected by the Gst::Pipeline. They can track the offset and rate difference * of their internal clock relative to the master clock by using the * get_calibration() method. * * The master/slave synchronisation can be tuned with the "timeout", * "window-size" and "window-threshold" properties. The "timeout" property * defines the interval to sample the master clock and run the calibration * functions. "window-size" defines the number of samples to use when * calibrating and "window-threshold" defines the minimum number of samples * before the calibration is performed. * * Last reviewed on 2016-05-16 (1.8.0) */ class Clock : public Object { _CLASS_GOBJECT(Clock, GstClock, GST_CLOCK, Object, GstObject) public: _WRAP_METHOD(bool add_observation(Gst::ClockTime slave_time, Gst::ClockTime master_time, gdouble& result), gst_clock_add_observation) _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) _WRAP_METHOD(bool set_master(const Clock& master_clock), gst_clock_set_master) _WRAP_METHOD(Glib::RefPtr get_master(), gst_clock_get_master) _WRAP_METHOD(Glib::RefPtr get_master() const, gst_clock_get_master, constversion) _WRAP_METHOD(Gst::ClockTime set_resolution(Gst::ClockTime resolution), gst_clock_set_resolution) _WRAP_METHOD(Gst::ClockTime get_resolution() const, gst_clock_get_resolution) _WRAP_METHOD(Gst::ClockTime get_time() const, gst_clock_get_time) _WRAP_METHOD(Glib::RefPtr create_single_shot_id(Gst::ClockTime time), gst_clock_new_single_shot_id) _WRAP_METHOD(Glib::RefPtr create_periodic_id(Gst::ClockTime start_time, Gst::ClockTime intervals), gst_clock_new_periodic_id) _WRAP_METHOD(bool single_shot_id_reinit(const Glib::RefPtr& id, Gst::ClockTime time), gst_clock_single_shot_id_reinit) _WRAP_METHOD(bool periodic_id_reinit(const Glib::RefPtr& id, Gst::ClockTime start_time, Gst::ClockTime interval), gst_clock_periodic_id_reinit) _WRAP_METHOD(Gst::ClockTime get_internal_time() const, gst_clock_get_internal_time) _WRAP_METHOD(Gst::ClockTime adjust_unlocked(Gst::ClockTime internal_time), gst_clock_adjust_unlocked) _WRAP_METHOD(Gst::ClockTime unadjust_unlocked(Gst::ClockTime external_time), gst_clock_unadjust_unlocked) _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) _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) _WRAP_METHOD(void get_calibration(Gst::ClockTime& internal, Gst::ClockTime& external, Gst::ClockTime& rate_num, Gst::ClockTime& rate_denom) const, gst_clock_get_calibration) _WRAP_METHOD(void set_calibration(Gst::ClockTime internal, Gst::ClockTime external, Gst::ClockTime rate_num, Gst::ClockTime rate_denom), gst_clock_set_calibration) _WRAP_METHOD(bool wait_for_sync(Gst::ClockTime timeout), gst_clock_wait_for_sync) _WRAP_METHOD(bool is_synced() const, gst_clock_is_synced) _WRAP_METHOD(void set_synced(bool synced), gst_clock_set_synced) /// get/set timeout can be achieved through 'timeout' property, /// so wrapping gst_clock_{get|set|_timeout is unnecessary. _IGNORE(gst_clock_set_timeout, gst_clock_get_timeout) _WRAP_PROPERTY("timeout", guint64) _WRAP_PROPERTY("window-size", int) _WRAP_PROPERTY("window-threshold", int) /** Change the resolution of the clock. Not all values might be acceptable. * The new resolution should be returned. */ _WRAP_VFUNC(Gst::ClockTime change_resolution(Gst::ClockTime old_resolution, Gst::ClockTime new_resolution), "change_resolution") /** Get the resolution of the clock. */ _WRAP_VFUNC(Gst::ClockTime get_resolution() const, "get_resolution") /** Get the internal unadjusted time of the clock. */ _WRAP_VFUNC(Gst::ClockTime get_internal_time() const, "get_internal_time") #m4 _CONVERSION(`GstClockEntry*',`const Glib::RefPtr&',`Glib::wrap($3, true)') /** Perform a blocking wait for the given Gst::ClockID. Deprecated, * implement wait_jitter_vfunc() instead. */ _WRAP_VFUNC(ClockReturn wait(const Glib::RefPtr& id, Gst::ClockTimeDiff& jitter), "wait") /** Perform an asynchronous wait for the given Gst::ClockID. */ _WRAP_VFUNC(ClockReturn wait_async(const Glib::RefPtr& id), "wait_async") /** Unblock a blocking or async wait operation. */ _WRAP_VFUNC(void unschedule(const Glib::RefPtr& id), "unschedule") _WRAP_SIGNAL(void synced(bool synced), "synced", no_default_handler) }; } //namespace Gst