iOS Developer Library

Developer

CoreMedia Framework Reference CMSync Reference

Options
Deployment Target:

On This Page
Language:

CMSync Reference

Inherits From


Not Applicable

Conforms To


Not Applicable

Import Statement


Swift

import CoreMedia

Objective-C

@import CoreMedia;

CMSync API provides a reference clock that you can use to synchronize applications and devices. This API also provides functions to monitor relative drift between CMClocks and functions that are associated with timer services.

Functions

  • Returns the CFTypeID of the CMClock.

    Declaration

    Swift

    func CMClockGetTypeID() -> CFTypeID

    Objective-C

    CFTypeID CMClockGetTypeID ( void );

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Returns a reference to the singleton clock logically identified with host time.

    Declaration

    Swift

    func CMClockGetHostTimeClock() -> CMClock!

    Objective-C

    CMClockRef CMClockGetHostTimeClock ( void );

    Discussion

    On Mac OS X, the host time clock uses mach_absolute_time but returns a value with a large integer timescale (e.g. nanoseconds).

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Converts a host time from CMTime to the host time's native units.

    Declaration

    Swift

    func CMClockConvertHostTimeToSystemUnits(_ hostTime: CMTime) -> UInt64

    Objective-C

    uint64_t CMClockConvertHostTimeToSystemUnits ( CMTime hostTime );

    Discussion

    This function performs a scale conversion, not a clock conversion. It can be more accurate than CMTimeConvertScale because the system units may have a non-integer timescale. On Mac OS X, this function converts to the units of mach_absolute_time.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Converts a host time from native units to CMTime.

    Declaration

    Swift

    func CMClockMakeHostTimeFromSystemUnits(_ hostTime: UInt64) -> CMTime

    Objective-C

    CMTime CMClockMakeHostTimeFromSystemUnits ( uint64_t hostTime );

    Discussion

    The returned value will have a large integer timescale (eg, nanoseconds). This function handles situations where host time's native units use a non-integer timescale. On Mac OS X, this function converts from the units of mach_absolute_time.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Retrieves the current time from a clock.

    Declaration

    Swift

    func CMClockGetTime(_ clock: CMClock!) -> CMTime

    Objective-C

    CMTime CMClockGetTime ( CMClockRef clock );

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Retrieves the current time from a clock and also the matching time from the clock's reference clock.

    Declaration

    Swift

    func CMClockGetAnchorTime(_ clock: CMClock!, _ outClockTime: UnsafeMutablePointer<CMTime>, _ outReferenceClockTime: UnsafeMutablePointer<CMTime>) -> OSStatus

    Objective-C

    OSStatus CMClockGetAnchorTime ( CMClockRef clock, CMTime *outClockTime, CMTime *outReferenceClockTime );

    Discussion

    To make practical use of this, you may need to know what the clock's reference clock is.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Returns a Boolean that indicates whether it is possible for two clocks to drift relative to each other.

    Declaration

    Swift

    func CMClockMightDrift(_ clock: CMClock!, _ otherClock: CMClock!) -> Boolean

    Objective-C

    Boolean CMClockMightDrift ( CMClockRef clock, CMClockRef otherClock );

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Makes the clock stop functioning.

    Declaration

    Swift

    func CMClockInvalidate(_ clock: CMClock!)

    Objective-C

    void CMClockInvalidate ( CMClockRef clock );

    Discussion

    After invalidation, the clock will return errors from all APIs. This should only be called by the "owner" of the clock, who knows (for example) that some piece of hardware has gone away, and the clock will no longer work (and might even crash).

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Returns the CFTypeID for CMTimebase.

    Declaration

    Swift

    func CMTimebaseGetTypeID() -> CFTypeID

    Objective-C

    CFTypeID CMTimebaseGetTypeID ( void );

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Creates a timebase driven by the given clock.

    Declaration

    Swift

    func CMTimebaseCreateWithMasterClock(_ allocator: CFAllocator!, _ masterClock: CMClock!, _ timebaseOut: UnsafeMutablePointer<Unmanaged<CMTimebase>?>) -> OSStatus

    Objective-C

    OSStatus CMTimebaseCreateWithMasterClock ( CFAllocatorRef allocator, CMClockRef masterClock, CMTimebaseRef *timebaseOut );

    Discussion

    The timebase will initially have rate zero and time zero. Pass CMClockGetHostTimeClock() for masterClock to have the host time clock drive this timebase.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Creates a timebase driven by the given master timebase.

    Declaration

    Swift

    func CMTimebaseCreateWithMasterTimebase(_ allocator: CFAllocator!, _ masterTimebase: CMTimebase!, _ timebaseOut: UnsafeMutablePointer<Unmanaged<CMTimebase>?>) -> OSStatus

    Objective-C

    OSStatus CMTimebaseCreateWithMasterTimebase ( CFAllocatorRef allocator, CMTimebaseRef masterTimebase, CMTimebaseRef *timebaseOut );

    Discussion

    The timebase will initially have rate zero and time zero.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Returns the immediate master timebase of a timebase.

    Declaration

    Swift

    func CMTimebaseGetMasterTimebase(_ timebase: CMTimebase!) -> CMTimebase!

    Objective-C

    CMTimebaseRef CMTimebaseGetMasterTimebase ( CMTimebaseRef timebase );

    Discussion

    Returns NULL if the timebase actually has a master clock instead of a master timebase.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Returns the immediate master clock of a timebase.

    Declaration

    Swift

    func CMTimebaseGetMasterClock(_ timebase: CMTimebase!) -> CMClock!

    Objective-C

    CMClockRef CMTimebaseGetMasterClock ( CMTimebaseRef timebase );

    Discussion

    Returns NULL if the timebase actually has a master timebase instead of a master clock.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Returns the immediate master (either timebase or clock) of a timebase.

    Declaration

    Swift

    func CMTimebaseGetMaster(_ timebase: CMTimebase!) -> CMClockOrTimebase!

    Objective-C

    CMClockOrTimebaseRef CMTimebaseGetMaster ( CMTimebaseRef timebase );

    Discussion

    Returns NULL if there was an error (such as timebase == NULL). Example of use: time = CMSyncGetTime(CMTimebaseGetMaster(timebase));

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Returns the master clock that is the master of all of a timebase's master timebases.

    Declaration

    Swift

    func CMTimebaseGetUltimateMasterClock(_ timebase: CMTimebase!) -> CMClock!

    Objective-C

    CMClockRef CMTimebaseGetUltimateMasterClock ( CMTimebaseRef timebase );

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Retrieves the current time from a timebase.

    Declaration

    Swift

    func CMTimebaseGetTime(_ timebase: CMTimebase!) -> CMTime

    Objective-C

    CMTime CMTimebaseGetTime ( CMTimebaseRef timebase );

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Retrieves the current time from a timebase in the specified timescale.

    Declaration

    Swift

    func CMTimebaseGetTimeWithTimeScale(_ timebase: CMTimebase!, _ timescale: CMTimeScale, _ method: CMTimeRoundingMethod) -> CMTime

    Objective-C

    CMTime CMTimebaseGetTimeWithTimeScale ( CMTimebaseRef timebase, CMTimeScale timescale, CMTimeRoundingMethod method );

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Sets the current time of a timebase.

    Declaration

    Swift

    func CMTimebaseSetTime(_ timebase: CMTimebase!, _ time: CMTime) -> OSStatus

    Objective-C

    OSStatus CMTimebaseSetTime ( CMTimebaseRef timebase, CMTime time );

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Sets the time of a timebase at a particular master time.

    Declaration

    Swift

    func CMTimebaseSetAnchorTime(_ timebase: CMTimebase!, _ timebaseTime: CMTime, _ immediateMasterTime: CMTime) -> OSStatus

    Objective-C

    OSStatus CMTimebaseSetAnchorTime ( CMTimebaseRef timebase, CMTime timebaseTime, CMTime immediateMasterTime );

    Discussion

    CMTimebaseGetTime's results will be interpolated from that anchor time.

    CMTimebaseSetTime(timebase, time) is equivalent to calling CMTimebaseSetAnchorTime(timebase, time, CMSyncGetTime(CMTimebaseGetMaster(timebase))).

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Retrieves the current rate of a timebase.

    Declaration

    Swift

    func CMTimebaseGetRate(_ timebase: CMTimebase!) -> Float64

    Objective-C

    Float64 CMTimebaseGetRate ( CMTimebaseRef timebase );

    Discussion

    This is the rate relative to its immediate master clock or timebase. For example, if a timebase is running at twice the rate of its master, its rate is 2.0.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Retrieves the current time and rate of a timebase.

    Declaration

    Swift

    func CMTimebaseGetTimeAndRate(_ timebase: CMTimebase!, _ outTime: UnsafeMutablePointer<CMTime>, _ outRate: UnsafeMutablePointer<Float64>) -> OSStatus

    Objective-C

    OSStatus CMTimebaseGetTimeAndRate ( CMTimebaseRef timebase, CMTime *outTime, Float64 *outRate );

    Discussion

    You can use this function to take a consistent snapshot of the two values, avoiding possible inconsistencies due to external changes between retrieval of time and rate.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Sets the rate of a timebase.

    Declaration

    Swift

    func CMTimebaseSetRate(_ timebase: CMTimebase!, _ rate: Float64) -> OSStatus

    Objective-C

    OSStatus CMTimebaseSetRate ( CMTimebaseRef timebase, Float64 rate );

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Sets the time of a timebase at a particular master time, and changes the rate at exactly that time.

    Declaration

    Swift

    func CMTimebaseSetRateAndAnchorTime(_ timebase: CMTimebase!, _ rate: Float64, _ timebaseTime: CMTime, _ immediateMasterTime: CMTime) -> OSStatus

    Objective-C

    OSStatus CMTimebaseSetRateAndAnchorTime ( CMTimebaseRef timebase, Float64 rate, CMTime timebaseTime, CMTime immediateMasterTime );

    Discussion

    CMTimebaseGetTime's results will be interpolated from that anchor time as though the timebase has been running at the requested rate since that time.

    CMTimebaseSetRate(timebase, rate) is approximately equivalent to calling CMTimebaseSetRateAndAnchorTime(timebase, rate, CMTimebaseGetTime(timebase), CMSyncGetTime(CMTimebaseGetMaster(timebase))), except that CMTimebaseSetRate will not generate a TimeJumped notification.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Gets the effective rate of a timebase (which combines its rate with the rates of all its master timebases).

    Declaration

    Swift

    func CMTimebaseGetEffectiveRate(_ timebase: CMTimebase!) -> Float64

    Objective-C

    Float64 CMTimebaseGetEffectiveRate ( CMTimebaseRef timebase );

    Discussion

    Calling CMTimebaseGetEffectiveRate(timebase) is equivalent to calling CMSyncGetRelativeRate(timebase, CMTimebaseGetUltimateMasterClock(timebase)).

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Adds the timer to the list of timers managed by the timebase.

    Declaration

    Swift

    func CMTimebaseAddTimer(_ timebase: CMTimebase!, _ timer: CFRunLoopTimer!, _ runloop: CFRunLoop!) -> OSStatus

    Objective-C

    OSStatus CMTimebaseAddTimer ( CMTimebaseRef timebase, CFRunLoopTimerRef timer, CFRunLoopRef runloop );

    Discussion

    The timer must be a repeating run loop timer (with a very long interval at least as long as kCMTimebaseVeryLongCFTimeInterval), attached to a runloop. The timebase will retain the timer, and will maintain its "NextFireDate" according to the CMTime set using CMTimebaseSetTimerNextFireTime. Until the first call to CMTimebaseSetTimerNextFireTime, the "NextFireDate" will be set to a future time. The runloop that timer is attached to must be passed in and the timebase will retain that runloop. The retained runloop will be used to call CFRunLoopWakeUp() any time the timebase modifies the timer's fire date.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Removes the timer from the list of timers managed by the timebase.

    Declaration

    Swift

    func CMTimebaseRemoveTimer(_ timebase: CMTimebase!, _ timer: CFRunLoopTimer!) -> OSStatus

    Objective-C

    OSStatus CMTimebaseRemoveTimer ( CMTimebaseRef timebase, CFRunLoopTimerRef timer );

    Discussion

    The timebase will no longer maintain the timer's "NextFireDate". If the timer is invalidated, the timebase will eventually remove it from its list and release it even if this function is not called.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Sets the CMTime on the timebase's timeline at which the timer should next be fired.

    Declaration

    Swift

    func CMTimebaseSetTimerNextFireTime(_ timebase: CMTimebase!, _ timer: CFRunLoopTimer!, _ fireTime: CMTime, _ flags: UInt32) -> OSStatus

    Objective-C

    OSStatus CMTimebaseSetTimerNextFireTime ( CMTimebaseRef timebase, CFRunLoopTimerRef timer, CMTime fireTime, uint32_t flags );

    Discussion

    The timer must be on the list of timers managed by the timebase. The timebase will continue to update the timer's "NextFireDate" according to time jumps and effective rate changes. If fireTime is not numeric, or if the timebase is not moving, the "NextFireDate" will be set to a future date.

    Due to the way that CFRunLoopTimers are implemented, if a timer passes through a state in which it is due to fire, it may fire even if its rescheduled before the runloop runs again. Clients should take care to avoid temporarily scheduling timers in the past. For example, set the timebase's rate or time before you set the timer's next fire time, if you are doing both at once. (If setting the timebase's rate or time might put the timer's fire time in the past, you may need to set the fire time to kCMTimeInvalid across the timebase change.)

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Sets the timer to fire immediately once, overriding any previous CMTimebaseSetTimerNextFireTime call.

    Declaration

    Swift

    func CMTimebaseSetTimerToFireImmediately(_ timebase: CMTimebase!, _ timer: CFRunLoopTimer!) -> OSStatus

    Objective-C

    OSStatus CMTimebaseSetTimerToFireImmediately ( CMTimebaseRef timebase, CFRunLoopTimerRef timer );

    Discussion

    The timer must be on the list of timers managed by the timebase. This is equivalent to calling CFRunLoopTimerSetNextFireDate( timer, CFAbsoluteTimeGetCurrent() ); except that the timebase gets to know that it shouldn't interfere.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Adds the timer dispatch source to the list of timers managed by the timebase.

    Declaration

    Swift

    func CMTimebaseAddTimerDispatchSource(_ timebase: CMTimebase!, _ timerSource: dispatch_source_t!) -> OSStatus

    Objective-C

    OSStatus CMTimebaseAddTimerDispatchSource ( CMTimebaseRef timebase, dispatch_source_t timerSource );

    Discussion

    The timer source must have been created by calling dispatch_source_create( DISPATCH_SOURCE_TYPE_TIMER, 0, 0, some_dispatch_queue ) and should have had an event handler associated with it via dispatch_source_set_event_handler( timerSource, some_handler_block ) or dispatch_source_set_event_handler_f( timerSource, some_handler_function ). Don't forget to call dispatch_resume( timerSource ) as dispatch sources are created in a suspended state. The timebase will retain the timer source, and will maintain its start time according to the CMTime set using CMTimebaseSetTimerDispatchSourceNextFireTime. Until the first call to CMTimebaseSetTimerDispatchSourceNextFireTime, the start time will be set to DISPATCH_TIME_FOREVER. For more information on dispatch sources see Dispatch Sources.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Removes the timer dispatch source from the list of timers managed by the timebase.

    Declaration

    Swift

    func CMTimebaseRemoveTimerDispatchSource(_ timebase: CMTimebase!, _ timerSource: dispatch_source_t!) -> OSStatus

    Objective-C

    OSStatus CMTimebaseRemoveTimerDispatchSource ( CMTimebaseRef timebase, dispatch_source_t timerSource );

    Discussion

    The timebase will no longer maintain the timer source's start time. If the timer source is cancelled, the timebase will eventually remove it from its list and release it even if this function is not called.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Sets the CMTime on the timebase's timeline at which the timer dispatch source should be fired next.

    Declaration

    Swift

    func CMTimebaseSetTimerDispatchSourceNextFireTime(_ timebase: CMTimebase!, _ timerSource: dispatch_source_t!, _ fireTime: CMTime, _ flags: UInt32) -> OSStatus

    Objective-C

    OSStatus CMTimebaseSetTimerDispatchSourceNextFireTime ( CMTimebaseRef timebase, dispatch_source_t timerSource, CMTime fireTime, uint32_t flags );

    Discussion

    The timer source must be on the list of timers managed by the timebase. The timebase will continue to update the timer dispatch source's start time according to time jumps and effective rate changes. If fireTime is not numeric, or if the timebase is not moving, the start time will be set to DISPATCH_TIME_FOREVER.

    Due to the way that timer dispatch sources are implemented, if a timer passes through a state in which it is due to fire, it may fire even if its rescheduled before the event handler is run. Clients should take care to avoid temporarily scheduling timers in the past. For example, set the timebase's rate or time before you set the timer's next fire time, if you are doing both at once. (If setting the timebase's rate or time might put the timer's fire time in the past, you may need to set the fire time to kCMTimeInvalid across the timebase change.)

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Sets the timer dispatch source to fire immediately once, overriding any previous CMTimebaseSetTimerDispatchSourceNextFireTime call.

    Declaration

    Swift

    func CMTimebaseSetTimerDispatchSourceToFireImmediately(_ timebase: CMTimebase!, _ timerSource: dispatch_source_t!) -> OSStatus

    Objective-C

    OSStatus CMTimebaseSetTimerDispatchSourceToFireImmediately ( CMTimebaseRef timebase, dispatch_source_t timerSource );

    Discussion

    The timer source must be on the list of timers managed by the timebase. This is equivalent to calling dispatch_source_set_timer(timerSource, DISPATCH_TIME_NOW, 0, 0 ); except that the timebase gets to know that it shouldn't interfere.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Queries the relative rate of one timebase or clock relative to another timebase or clock.

    Declaration

    Swift

    func CMSyncGetRelativeRate(_ ofClockOrTimebase: CMClockOrTimebase!, _ relativeToClockOrTimebase: CMClockOrTimebase!) -> Float64

    Objective-C

    Float64 CMSyncGetRelativeRate ( CMClockOrTimebaseRef ofClockOrTimebase, CMClockOrTimebaseRef relativeToClockOrTimebase );

    Discussion

    If both have a common master, this calculation is performed purely based on the rates in the common tree rooted in that master. If they have different master clocks (or are both clocks), this calculation takes into account the measured drift between the two clocks, using host time as a pivot. The rate of a moving timebase relative to a stopped timebase is a NaN. Calling CMTimebaseGetEffectiveRate(timebase) is equivalent to calling CMSyncGetRelativeRate(timebase, CMTimebaseGetUltimateMasterClock(timebase)).

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Queries the relative rate of one timebase or clock relative to another timebase or clock and the times of each timebase or clock at which the relative rate went into effect.

    Declaration

    Swift

    func CMSyncGetRelativeRateAndAnchorTime(_ ofClockOrTimebase: CMClockOrTimebase!, _ relativeToClockOrTimebase: CMClockOrTimebase!, _ outRelativeRate: UnsafeMutablePointer<Float64>, _ outOfClockOrTimebaseAnchorTime: UnsafeMutablePointer<CMTime>, _ outRelativeToClockOrTimebaseAnchorTime: UnsafeMutablePointer<CMTime>) -> OSStatus

    Objective-C

    OSStatus CMSyncGetRelativeRateAndAnchorTime ( CMClockOrTimebaseRef ofClockOrTimebase, CMClockOrTimebaseRef relativeToClockOrTimebase, Float64 *outRelativeRate, CMTime *outOfClockOrTimebaseAnchorTime, CMTime *outRelativeToClockOrTimebaseAnchorTime );

    Discussion

    If both have a common master, this calculation is performed purely based on the rates in the common tree rooted in that master. If they have different master clocks (or are both clocks), this calculation takes into account the measured drift between the two clocks, using host time as a pivot. The rate of a moving timebase relative to a stopped timebase is a NaN.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Converts a time from one timebase or clock to another timebase or clock.

    Declaration

    Swift

    func CMSyncConvertTime(_ time: CMTime, _ fromClockOrTimebase: CMClockOrTimebase!, _ toClockOrTimebase: CMClockOrTimebase!) -> CMTime

    Objective-C

    CMTime CMSyncConvertTime ( CMTime time, CMClockOrTimebaseRef fromClockOrTimebase, CMClockOrTimebaseRef toClockOrTimebase );

    Discussion

    If both have a common master, this calculation is performed purely based on the mathematical rates and offsets in the common tree rooted in that master. If they have different master clocks (or are both clocks), this calculation also compensates for measured drift between the clocks. To convert to or from host time, pass CMClockGetHostTimeClock() as the appropriate argument.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Returns a Boolean indicating whether it is possible for one timebase/clock to drift relative to the other.

    Declaration

    Swift

    func CMSyncMightDrift(_ clockOrTimebase1: CMClockOrTimebase!, _ clockOrTimebase2: CMClockOrTimebase!) -> Boolean

    Objective-C

    Boolean CMSyncMightDrift ( CMClockOrTimebaseRef clockOrTimebase1, CMClockOrTimebaseRef clockOrTimebase2 );

    Discussion

    A timebase can drift relative to another if they are ultimately mastered by clocks that can drift relative to each other.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • A helper function to get time from a clock or timebase.

    Declaration

    Swift

    func CMSyncGetTime(_ clockOrTimebase: CMClockOrTimebase!) -> CMTime

    Objective-C

    CMTime CMSyncGetTime ( CMClockOrTimebaseRef clockOrTimebase );

    Discussion

    CMSyncGetTime simply calls either CMClockGetTime or CMTimebaseGetTime, as appropriate. It comes in handy for things like: CMSyncGetTime(CMTimebaseGetMaster(timebase)).

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Requests that the timebase wait until it is not posting any notifications.

    Declaration

    Swift

    func CMTimebaseNotificationBarrier(_ timebase: CMTimebase!) -> OSStatus

    Objective-C

    OSStatus CMTimebaseNotificationBarrier ( CMTimebaseRef timebase );

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Defines a very long elapsed time in seconds.

    Declaration

    Objective-C

    #define kCMTimebaseVeryLongCFTimeInterval (CFTimeInterval)(256.0 * 365.0 * 24.0 * 60.0 * 60.0)

  • Returns a specific point of time in far, far future.

    Declaration

    Objective-C

    #define kCMTimebaseFarFutureCFAbsoluteTime (( CFAbsoluteTime )kCMTimebaseVeryLongCFTimeInterval)

Data Types

  • A timing source object.

    Declaration

    Swift

    typealias CMClockRef = CMClock

    Objective-C

    typedef struct OpaqueCMClock* CMClockRef;

    Discussion

    A clock represents a source of time information: generally, a piece of hardware that measures the passage of time. One example of a clock is the host time clock, accessible via CMClockGetHostTimeClock. It measures time using the CPU system clock, which on Mac OS X is mach_absolute_time(). Every audio device can also be considered a clock since the audio samples that it outputs or inputs each have a defined duration (eg, 1/48000 of a second for 48 kHz audio). CMClocks are read-only: they cannot be stopped or started, and the current time cannot be set. A CMClock has one primary function, CMClockGetTime, which tells what time it is now. Additionally, the CMSync infrastructure monitors relative drift between CMClocks.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Models a timeline under application control.

    Declaration

    Swift

    typealias CMTimebaseRef = CMTimebase

    Objective-C

    typedef struct OpaqueCMTimebase* CMTimebaseRef;

    Discussion

    A timebase represents a timeline that clients can control by setting the rate and time. Each timebase has either a master clock or a master timebase. The rate of the timebase is expressed relative to its master.

    When a timebase has rate 0.0, its time is fixed and does not change as its master's time changes. When a timebase has rate 1.0, its time increases one second as its master's time increases by one second. When a timebase has rate 2.0, its time increases two seconds as its master's time increases by one second. When a timebase has rate -1.0, its time decreases one second as its master's time increases by one second.

    If a timebase has a master timebase, the master timebase's rate is a factor in determining the timebase's effective rate. In fact, a timebase's effective rate is defined as the product of its rate, its master timebase's rate, its master timebase's master timebase's rate, and so on up to the ultimate master clock. This is the rate at which the timebase's time changes relative to the ultimate master clock.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

  • Used in argument lists and function results to indicate that either may be passed

    Declaration

    Swift

    typealias CMClockOrTimebaseRef = CMClockOrTimebase

    Objective-C

    typedef CFTypeRef CMClockOrTimebaseRef;

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 6.0 and later

Constants

  • The following constants represents the errors in Core Media clock operations.

    Declaration

    Swift

    var kCMClockError_MissingRequiredParameter: Int { get } var kCMClockError_InvalidParameter: Int { get } var kCMClockError_AllocationFailed: Int { get } var kCMClockError_UnsupportedOperation: Int { get }

    Objective-C

    enum { kCMClockError_MissingRequiredParameter = -12745, kCMClockError_InvalidParameter = -12746, kCMClockError_AllocationFailed = -12747, kCMClockError_UnsupportedOperation = -12756, };

    Constants

    • kCMClockError_MissingRequiredParameter

      kCMClockError_MissingRequiredParameter

      Indicates that a required parameter is missing.

      Available in iOS 6.0 and later

    • kCMClockError_InvalidParameter

      kCMClockError_InvalidParameter

      Indicates a NULL or 0 was passed for a required parameter.

      Available in iOS 6.0 and later

    • kCMClockError_AllocationFailed

      kCMClockError_AllocationFailed

      Indicates a failed memory allocation.

      Available in iOS 6.0 and later

    • kCMClockError_UnsupportedOperation

      kCMClockError_UnsupportedOperation

      Indicates that the requested operation is not supported.

      Available in iOS 6.0 and later

  • The following constants represents errors in core media time base operations.

    Declaration

    Swift

    var kCMTimebaseError_MissingRequiredParameter: Int { get } var kCMTimebaseError_InvalidParameter: Int { get } var kCMTimebaseError_AllocationFailed: Int { get } var kCMTimebaseError_TimerIntervalTooShort: Int { get } var kCMTimebaseError_ReadOnly: Int { get }

    Objective-C

    enum { kCMTimebaseError_MissingRequiredParameter = -12748, kCMTimebaseError_InvalidParameter = -12749, kCMTimebaseError_AllocationFailed = -12750, kCMTimebaseError_TimerIntervalTooShort = -12751, kCMTimebaseError_ReadOnly = -12757, };

    Constants

    • kCMTimebaseError_MissingRequiredParameter

      kCMTimebaseError_MissingRequiredParameter

      Indicates that a required parameter is missing.

      Available in iOS 6.0 and later

    • kCMTimebaseError_InvalidParameter

      kCMTimebaseError_InvalidParameter

      Indicates a NULL or 0 was passed for a required parameter.

      Available in iOS 6.0 and later

    • kCMTimebaseError_AllocationFailed

      kCMTimebaseError_AllocationFailed

      Indicates a failed memory allocation.

      Available in iOS 6.0 and later

    • kCMTimebaseError_TimerIntervalTooShort

      kCMTimebaseError_TimerIntervalTooShort

      Indicates that the supplied time interval is too short.

      Available in iOS 6.0 and later

    • kCMTimebaseError_ReadOnly

      kCMTimebaseError_ReadOnly

      Indicates that an attempt was made to modify a read-only timebase.

      Available in iOS 6.0 and later

  • These following constants represents error codes returned by core media synch operations.

    Declaration

    Swift

    var kCMSyncError_MissingRequiredParameter: Int { get } var kCMSyncError_InvalidParameter: Int { get } var kCMSyncError_AllocationFailed: Int { get } var kCMSyncError_RateMustBeNonZero: Int { get }

    Objective-C

    enum { kCMSyncError_MissingRequiredParameter = -12752, kCMSyncError_InvalidParameter = -12753, kCMSyncError_AllocationFailed = -12754, kCMSyncError_RateMustBeNonZero = -12755, };

    Constants

    • kCMSyncError_MissingRequiredParameter

      kCMSyncError_MissingRequiredParameter

      Indicates that a required parameter is missing.

      Available in iOS 6.0 and later

    • kCMSyncError_InvalidParameter

      kCMSyncError_InvalidParameter

      Indicates a NULL or 0 was passed for a required parameter.

      Available in iOS 6.0 and later

    • kCMSyncError_AllocationFailed

      kCMSyncError_AllocationFailed

      Indicates a failed memory allocation.

      Available in iOS 6.0 and later

    • kCMSyncError_RateMustBeNonZero

      kCMSyncError_RateMustBeNonZero

      Indicates that the rate supplied is zero.

      Available in iOS 6.0 and later

  • Keys that represent time base notifications.

    Declaration

    Swift

    let kCMTimebaseNotification_EffectiveRateChanged: CFString! let kCMTimebaseNotification_TimeJumped: CFString!

    Objective-C

    const CFStringRef kCMTimebaseNotification_EffectiveRateChanged const CFStringRef kCMTimebaseNotification_TimeJumped

    Constants

    • kCMTimebaseNotification_EffectiveRateChanged

      kCMTimebaseNotification_EffectiveRateChanged

      Posted by a timebase after a change in effective rate.

      Available in iOS 6.0 and later

    • kCMTimebaseNotification_TimeJumped

      kCMTimebaseNotification_TimeJumped

      Posted by a timebase after a discontinuous time jump.

      Available in iOS 6.0 and later