iOS Developer Library

Developer

CoreMedia Framework Reference CMTime Reference

Options
Deployment Target:

On This Page
Language:

CMTime Reference

This document describes the API for creating and manipulating CMTime structs.

CMTime structs are non-opaque mutable structs representing times (either timestamps or durations).

A CMTime is represented as a rational number, with a numerator (an int64_t value), and a denominator (an int32_t timescale). Conceptually, the timescale specifies the fraction of a second each unit in the numerator occupies. Thus if the timescale is 4, each unit represents a quarter of a second; if the timescale is 10, each unit represents a tenth of a second, and so on. In addition to a simple time value, a CMTime can represent non-numeric values: +infinity, -infinity, and indefinite. Using a flag CMTime indicates whether the time been rounded at some point.

CMTimes contain an epoch number, which is usually set to 0, but can be used to distinguish unrelated timelines: for example, it could be incremented each time through a presentation loop, to differentiate between time N in loop 0 from time N in loop 1.

You can convert CMTimes to and from immutable CFDictionaries (see CFDictionaryRef) using CMTimeCopyAsDictionary and CMTimeMakeFromDictionary, for use in annotations and various Core Foundation containers.

Additional functions for managing dates and times are described in Time Utilities Reference. Note that CMTime is designed for media timelines whereas functions in Time Utilities Reference are designed for working with wall-clock time in Core Foundation framework; see also AV Foundation Constants Reference.

Functions

  • Makes a valid CMTime with value and timescale. Epoch is implied to be 0.

    Declaration

    Swift

    func CMTimeMake(_ value: Int64, _ timescale: Int32) -> CMTime

    Objective-C

    CMTime CMTimeMake ( int64_t value, int32_t timescale );

    Parameters

    value

    Initializes the value field of the resulting CMTime.

    timescale

    Initializes the timescale field of the resulting CMTime.

    Return Value

    The resulting CMTime

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 4.0 and later.

  • Reconstitutes a CMTime struct from a CFDictionary previously created by CMTimeCopyAsDictionary.

    Declaration

    Swift

    func CMTimeMakeFromDictionary(_ dict: CFDictionary!) -> CMTime

    Objective-C

    CMTime CMTimeMakeFromDictionary ( CFDictionaryRef dict );

    Parameters

    dict

    CFDictionary from which to create CMTime.

    Return Value

    The created CMTime.

    Discussion

    For keys in the dictionary, see Dictionary Keys.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 4.0 and later.

  • Makes a valid CMTime with value, scale and epoch.

    Declaration

    Swift

    func CMTimeMakeWithEpoch(_ value: Int64, _ timescale: Int32, _ epoch: Int64) -> CMTime

    Objective-C

    CMTime CMTimeMakeWithEpoch ( int64_t value, int32_t timescale, int64_t epoch );

    Parameters

    value

    Initializes the value field of the resulting CMTime.

    timescale

    Initializes the scale field of the resulting CMTime.

    epoch

    Initializes the epoch field of the resulting CMTime.

    Return Value

    The resulting CMTime.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 4.0 and later.

  • Makes a CMTime from a Float64 number of seconds, and a preferred timescale.

    Declaration

    Swift

    func CMTimeMakeWithSeconds(_ seconds: Float64, _ preferredTimeScale: Int32) -> CMTime

    Objective-C

    CMTime CMTimeMakeWithSeconds ( Float64 seconds, int32_t preferredTimeScale );

    Parameters

    seconds

    Initializes the seconds field of the resulting CMTime.

    preferredTimeScale

    Initializes the preferredTimeScale field of the resulting CMTime.

    Return Value

    The resulting CMTime.

    Discussion

    The epoch of the result will be zero. If preferredTimeScale is <= 0, the result will be an invalid CMTime. If the preferred timescale will cause an overflow, the timescale will be halved repeatedly until the overflow goes away, or the timescale is 1. If it still overflows at that point, the result will be +/- infinity. The kCMTimeFlags_HasBeenRounded flag will be set if the result, when converted back to seconds, is not exactly equal to the original seconds value.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 4.0 and later.

  • Returns the absolute value of a CMTime.

    Declaration

    Swift

    func CMTimeAbsoluteValue(_ time: CMTime) -> CMTime

    Objective-C

    CMTime CMTimeAbsoluteValue ( CMTime time );

    Parameters

    time

    A CMTime.

    Return Value

    Same as the argument time, with sign inverted if negative.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 4.0 and later.

  • Returns the sum of two CMTimes.

    Declaration

    Swift

    func CMTimeAdd(_ addend1: CMTime, _ addend2: CMTime) -> CMTime

    Objective-C

    CMTime CMTimeAdd ( CMTime addend1, CMTime addend2 );

    Parameters

    addend1

    CMTime to be added.

    addend2

    Another CMTime to be added.

    Return Value

    The sum of the two CMTimes (addend1 + addend2).

    Discussion

    If the operands both have the same timescale, the timescale of the result will be the same as the operands' timescale. If the operands have different timescales, the timescale of the result will be the least common multiple of the operands' timescales. If that LCM timescale is greater than kCMTimeMaxTimescale, the result timescale will be kCMTimeMaxTimescale, and default rounding will be applied when converting the result to this timescale. If the result value overflows, the result timescale will be repeatedly halved until the result value no longer overflows. Again, default rounding will be applied when converting the result to this timescale. If the result value still overflows when timescale == 1, then the result will be either positive or negative infinity, depending on the direction of the overflow.

    If any rounding occurs for any reason, the result's kCMTimeFlags_HasBeenRounded flag will be set. This flag will also be set if either of the operands has kCMTimeFlags_HasBeenRounded set. If either of the operands is invalid, the result will be invalid. If the operands are valid, but just one operand is infinite, the result will be similarly infinite. If the operands are valid, and both are infinite, the results will be as follows:

    • +infinity + +infinity == +infinity

      -infinity + -infinity == -infinity

      +infinity + -infinity == invalid

      -infinity + +infinity == invalid

    If the operands are valid, not infinite, and either or both is indefinite, the result will be indefinite. If the two operands are numeric (i.e.. valid, not infinite, not indefinite), but have different nonzero epochs, the result will be invalid. If they have the same nonzero epoch, the result will have epoch zero (a duration). Times in different epochs cannot be added or subtracted, because epoch length is unknown. Times in epoch zero are considered to be durations and can be added to times in other epochs. Times in different epochs can be compared, however, because numerically greater epochs always occur after numerically lesser epochs.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 4.0 and later.

  • Returns the numerical relationship of two CMTimes.

    Declaration

    Swift

    func CMTimeCompare(_ time1: CMTime, _ time2: CMTime) -> Int32

    Objective-C

    int32_t CMTimeCompare ( CMTime time1, CMTime time2 );

    Parameters

    time1

    First CMTime in comparison.

    time2

    Second CMTime in comparison.

    Return Value

    The numerical relationship of the two CMTimes.

    • -1 is returned if time1 is less than time2.

    • 1 is returned if time1 is greater than time2.

    • 0 is returned if time1 and time2 are equal.

    Discussion

    When comparing CMTimes, it is recommended to use CMTIME_COMPARE_INLINE macro since it makes comparison expressions much more readable by putting the comparison operation between the operands.

    If the two CMTimes are numeric (i.e.. not invalid, infinite, or indefinite), and have different epochs, it is considered that times in numerically larger epochs are always greater than times in numerically smaller epochs. Since this routine will be used to sort lists by time, it needs to give all values (even invalid and indefinite ones) a strict ordering to guarantee that sort algorithms terminate safely. The order chosen is somewhat arbitrary: -infinity < all finite values < indefinite < +infinity < invalid

    Invalid CMTimes are considered to be equal to other invalid CMTimes, and greater than any other CMTime. Positive infinity is considered to be less than any invalid CMTime, equal to itself, and greater than any other CMTime. An indefinite CMTime is considered to be less than any invalid CMTime, less than positive infinity, equal to itself, and greater than any other CMTime. Negative infinity is considered to be equal to itself, and less than any other CMTime.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 4.0 and later.

  • Returns a new CMTime containing the source CMTime converted to a new timescale (rounding as requested).

    Declaration

    Swift

    func CMTimeConvertScale(_ time: CMTime, _ newTimescale: Int32, _ method: CMTimeRoundingMethod) -> CMTime

    Objective-C

    CMTime CMTimeConvertScale ( CMTime time, int32_t newTimescale, CMTimeRoundingMethod method );

    Parameters

    time

    Source CMTime.

    newTimescale

    The timescale to which the source CMTime is converted.

    method

    The requested rounding method.

    Return Value

    The converted CMTime.

    Discussion

    If the value needs to be rounded, the kCMTimeFlags_HasBeenRounded flag will be set. See definition of CMTimeRoundingMethod for a discussion of the various rounding methods available. If the source time is non-numeric (i.e.. infinite, indefinite, invalid), the result will be similarly non-numeric.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 4.0 and later.

  • Returns a CFDictionary version of a CMTime.

    Declaration

    Swift

    func CMTimeCopyAsDictionary(_ time: CMTime, _ allocator: CFAllocator!) -> CFDictionary!

    Objective-C

    CFDictionaryRef CMTimeCopyAsDictionary ( CMTime time, CFAllocatorRef allocator );

    Parameters

    time

    CMTime from which to create dictionary.

    allocator

    CFAllocator with which to create dictionary. Pass kCFAllocatorDefault to use the default allocator.

    Return Value

    A CFDictionary version of the CMTime.

    Discussion

    This is useful when putting CMTimes in Core Foundation container types. For keys in the resulting dictionary, see Dictionary Keys.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 4.0 and later.

  • Creates a CFString with a description of a CMTime ( Similar to CFCopyDescription ).

    Declaration

    Swift

    func CMTimeCopyDescription(_ allocator: CFAllocator!, _ time: CMTime) -> CFString!

    Objective-C

    CFStringRef CMTimeCopyDescription ( CFAllocatorRef allocator, CMTime time );

    Parameters

    allocator

    CFAllocator with which to create the description. Pass kCFAllocatorDefault to use the default allocator.

    time

    CMTime to be described.

    Return Value

    The created CFString description.

    Discussion

    This is used from within CFShow on an object that contains CMTime fields. It is also useful from other client debugging code. The caller owns the returned CFString, and is responsible for releasing it.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 4.0 and later.

  • Converts a CMTime to seconds.

    Declaration

    Swift

    func CMTimeGetSeconds(_ time: CMTime) -> Float64

    Objective-C

    Float64 CMTimeGetSeconds ( CMTime time );

    Parameters

    time

    CMTime to be converted.

    Return Value

    The resulting Float64 number of seconds.

    Discussion

    If the CMTime is invalid or indefinite, NaN is returned. If the CMTime is infinite, +/- infinity is returned. If the CMTime is numeric, epoch is ignored, and time.value / time.timescale is returned. The division is done in Float64, so the fraction is not lost in the returned result.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 4.0 and later.

  • Returns the greater of two CMTimes (as defined by CMTimeCompare).

    Declaration

    Swift

    func CMTimeMaximum(_ time1: CMTime, _ time2: CMTime) -> CMTime

    Objective-C

    CMTime CMTimeMaximum ( CMTime time1, CMTime time2 );

    Parameters

    time1

    A CMTime.

    time2

    Another CMTime.

    Return Value

    The greater of the two CMTimes.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 4.0 and later.

  • Returns the lesser of two CMTimes (as defined by CMTimeCompare).

    Declaration

    Swift

    func CMTimeMinimum(_ time1: CMTime, _ time2: CMTime) -> CMTime

    Objective-C

    CMTime CMTimeMinimum ( CMTime time1, CMTime time2 );

    Parameters

    time1

    A CMTime.

    time2

    Another CMTime.

    Return Value

    The lesser of the two CMTimes.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 4.0 and later.

  • Returns the product of a CMTime and a 32-bit integer.

    Declaration

    Swift

    func CMTimeMultiply(_ time: CMTime, _ multiplier: Int32) -> CMTime

    Objective-C

    CMTime CMTimeMultiply ( CMTime time, int32_t multiplier );

    Parameters

    time

    The CMTime that will be multiplied.

    multiplier

    A 32-bit integer. CMTime time and multiplier will be multiplied.

    Return Value

    The product of the CMTime and the 32-bit integer.

    Discussion

    The result will have the same timescale as the CMTime operand. If the result value overflows, the result timescale will be repeatedly halved until the result value no longer overflows. Again, default rounding will be applied when converting the result to this timescale. If the result value still overflows when timescale == 1, then the result will be either positive or negative infinity, depending on the direction of the overflow. If any rounding occurs for any reason, the result's kCMTimeFlags_HasBeenRounded flag will be set. This flag will also be set if the CMTime operand has kCMTimeFlags_HasBeenRounded set. If the CMTime operand is invalid, the result will be invalid. If the CMTime operand is valid, but infinite, the result will be infinite, and of an appropriate sign, give the signs of both operands. If the CMTime operand is valid, but indefinite, the result will be indefinite.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 4.0 and later.

  • Returns the product of a CMTime and a 64-bit float.

    Declaration

    Swift

    func CMTimeMultiplyByFloat64(_ time: CMTime, _ multiplier: Float64) -> CMTime

    Objective-C

    CMTime CMTimeMultiplyByFloat64 ( CMTime time, Float64 multiplier );

    Parameters

    time

    The CMTime that will be multiplied.

    multiplier

    A 64-bit float. CMTime time and multiplier will be multiplied.

    Return Value

    The product of the CMTime and the 64-bit float.

    Discussion

    The result will initially have the same timescale as the CMTime operand. If the result timescale is less than 65536, it will be repeatedly doubled until it is at least 65536. If the result value overflows, the result timescale will be repeatedly halved until the result value no longer overflows. Again, default rounding will be applied when converting the result to this timescale. If the result value still overflows when timescale == 1, then the result will be either positive or negative infinity, depending on the direction of the overflow. If any rounding occurs for any reason, the result's kCMTimeFlags_HasBeenRounded flag will be set. This flag will also be set if the CMTime operand has kCMTimeFlags_HasBeenRounded set. If the CMTime operand is invalid, the result will be invalid. If the CMTime operand is valid, but infinite, the result will be infinite, and of an appropriate sign, given the signs of both operands. If the CMTime operand is valid, but indefinite, the result will be indefinite.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 4.0 and later.

  • Prints a description of the CMTime (Similar to CFShow).

    Declaration

    Swift

    func CMTimeShow(_ time: CMTime)

    Objective-C

    void CMTimeShow ( CMTime time );

    Parameters

    time

    CMTime to show.

    Discussion

    This is most useful from within gdb.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 4.0 and later.

  • Returns the difference of two CMTimes.

    Declaration

    Swift

    func CMTimeSubtract(_ minuend: CMTime, _ subtrahend: CMTime) -> CMTime

    Objective-C

    CMTime CMTimeSubtract ( CMTime minuend, CMTime subtrahend );

    Parameters

    minuend

    The CMTime from which the subtrahend will be subtracted.

    subtrahend

    The CMTime that will be subtracted from the minuend.

    Return Value

    The difference of the two CMTimes (minuend - subtrahend).

    Discussion

    If the operands both have the same timescale, the timescale of the result will be the same as the operands' timescale. If the operands have different timescales, the timescale of the result will be the least common multiple of the operands' timescales. If that LCM timescale is greater than kCMTimeMaxTimescale, the result timescale will be kCMTimeMaxTimescale, and default rounding will be applied when converting the result to this timescale.

    If the result value overflows, the result timescale will be repeatedly halved until the result value no longer overflows. Again, default rounding will be applied when converting the result to this timescale. If the result value still overflows when timescale == 1, then the result will be either positive or negative infinity, depending on the direction of the overflow.

    If any rounding occurs for any reason, the result's kCMTimeFlags_HasBeenRounded flag will be set. This flag will also be set if either of the operands has kCMTimeFlags_HasBeenRounded set. If either of the operands is invalid, the result will be invalid. If the operands are valid, but just one operand is infinite, the result will be similarly infinite. If the operands are valid, and both are infinite, the results will be as follows:

    • +infinity - +infinity == invalid

    • -infinity - -infinity == invalid

    • +infinity - -infinity == +infinity

    • -infinity - +infinity == -infinity

    If the operands are valid, not infinite, and either or both is indefinite, the result will be indefinite. If the two operands are numeric (i.e.. valid, not infinite, not indefinite), but have different nonzero epochs, the result will be invalid. If they have the same nonzero epoch, the result will have epoch zero (a duration). Times in different epochs cannot be added or subtracted, because epoch length is unknown. Times in epoch zero are considered to be durations and can be subtracted from times in other epochs. Times in different epochs can be compared, however, because numerically greater epochs always occur after numerically lesser epochs.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 4.0 and later.

  • Returns a Boolean value that indicates whether the specified comparison of two CMTimes is true.

    Declaration

    Objective-C

    #define CMTIME_COMPARE_INLINE(time1, comparator, time2) ((Boolean)(CMTimeCompare(time1, time2) comparator 0))

    Discussion

    For example:

    • CMTIME_COMPARE_INLINE(time1, <=, time2)

    will return true if time1 <= time2.

    Import Statement

    Objective-C

    @import CoreMedia;

    Availability

    Available in iOS 4.0 and later.

  • Returns a Boolean value that indicates whether a given time is valid.

    Declaration

    Objective-C

    #define CMTIME_IS_VALID(time) ((Boolean)(((time).flags & kCMTimeFlags_Valid) != 0))

    Return Value

    true if the CMTime is valid, otherwise false.

    Import Statement

    Objective-C

    @import CoreMedia;

    Availability

    Available in iOS 4.0 and later.

  • Returns a Boolean value that indicates whether a given time is invalid.

    Declaration

    Objective-C

    #define CMTIME_IS_INVALID(time) (! CMTIME_IS_VALID(time))

    Return Value

    true if the CMTime is invalid, otherwise false.

    Import Statement

    Objective-C

    @import CoreMedia;

    Availability

    Available in iOS 4.0 and later.

  • Returns a Boolean value that indicates whether a given time is positive infinity.

    Declaration

    Objective-C

    #define CMTIME_IS_POSITIVE_INFINITY(time) ((Boolean)(CMTIME_IS_VALID(time) && (((time).flags & kCMTimeFlags_PositiveInfinity) != 0)))

    Return Value

    true if the CMTime is positive infinity, otherwise false.

    Discussion

    Use this instead of (myTime == kCMTimePositiveInfinity), since there are many CMTime structs that represent positive infinity. This is because the non-flags fields are ignored, so they can contain anything.

    Import Statement

    Objective-C

    @import CoreMedia;

    Availability

    Available in iOS 4.0 and later.

  • Returns a Boolean value that indicates whether a given time is negative infinity.

    Declaration

    Objective-C

    #define CMTIME_IS_NEGATIVE_INFINITY(time) ((Boolean)(CMTIME_IS_VALID(time) && (((time).flags & kCMTimeFlags_NegativeInfinity) != 0)))

    Return Value

    true if the CMTime is negative infinity, otherwise false.

    Discussion

    Use this instead of (myTime == kCMTimeNegativeInfinity), since there are many CMTime structs that represent positive infinity. This is because the non-flags fields are ignored, so they can contain anything.

    Import Statement

    Objective-C

    @import CoreMedia;

    Availability

    Available in iOS 4.0 and later.

  • Returns a Boolean value that indicates whether a given time is indefinite.

    Declaration

    Objective-C

    #define CMTIME_IS_INDEFINITE(time) ((Boolean)(CMTIME_IS_VALID(time) && (((time).flags & kCMTimeFlags_Indefinite) != 0)))

    Return Value

    true if the CMTime is indefinite, otherwise false.

    Import Statement

    Objective-C

    @import CoreMedia;

    Availability

    Available in iOS 4.0 and later.

  • Returns a Boolean value that indicates whether a given time is numeric.

    Declaration

    Objective-C

    #define CMTIME_IS_NUMERIC(time) ((Boolean)(((time).flags & (kCMTimeFlags_Valid | kCMTimeFlags_ImpliedValueFlagsMask)) == kCMTimeFlags_Valid))

    Return Value

    true if the CMTime is numeric, otherwise false. Returns false if the CMTime is invalid, indefinite, or +/- infinity.

    Discussion

    A numeric time contains a usable value/timescale/epoch.

    Import Statement

    Objective-C

    @import CoreMedia;

    Availability

    Available in iOS 4.0 and later.

  • Returns a Boolean value that indicates whether a given time has been rounded.

    Declaration

    Objective-C

    #define CMTIME_HAS_BEEN_ROUNDED(time) ((Boolean)(CMTIME_IS_NUMERIC(time) && (((time).flags & kCMTimeFlags_HasBeenRounded) != 0)))

    Return Value

    true if the CMTime has been rounded, otherwise false (the time is completely accurate).

    Import Statement

    Objective-C

    @import CoreMedia;

    Availability

    Available in iOS 4.0 and later.

Data Types

Miscellaneous

  • Defines a structure that represents a rational time value int64/int32.

    Declaration

    Swift

    struct CMTime { var value: CMTimeValue var timescale: CMTimeScale var flags: CMTimeFlags var epoch: CMTimeEpoch }

    Objective-C

    typedef struct { CMTimeValue value; CMTimeScale timescale; CMTimeFlags flags; CMTimeEpoch epoch; } CMTime;

    Fields

    value

    The value of the CMTime.

    value/timescale = seconds.

    timescale

    The timescale of the CMTime.

    value/timescale = seconds.

    flags

    A bitfield representing the flags set for the CMTime.

    For example, kCMTimeFlags_Valid. See CMTime Flags for possible values.

    epoch

    The epoch of the CMTime.

    You use the epoch to differentiate between equal timestamps that are actually different because of looping, multi-item sequencing, and so on.

    The epoch is used during comparison: greater epochs happen after lesser ones. Addition or subtraction is only possible within a single epoch, however, since the epoch length may be unknown or variable.

    Availability

    Available in iOS 4.0 and later.

  • Numerator of rational CMTime.

    Declaration

    Swift

    typealias CMTimeValue = Int64

    Objective-C

    typedef int64_t CMTimeValue;

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 4.0 and later.

  • Denominator of rational CMTime.

    Declaration

    Swift

    typealias CMTimeScale = Int32

    Objective-C

    typedef int32_t CMTimeScale;

    Discussion

    Timescales must be positive.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 4.0 and later.

  • The epoch to which a CMTime refers.

    Declaration

    Swift

    typealias CMTimeEpoch = Int64

    Objective-C

    typedef int64_t CMTimeEpoch;

    Discussion

    The epoch is typically 0, but you might use a different value, for example, in a loop.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 4.0 and later.

  • A type to specify the flag bits for a CMTime.

    Declaration

    Swift

    struct CMTimeFlags : RawOptionSetType { init(_ rawValue: UInt32) init(rawValue rawValue: UInt32) static var Valid: CMTimeFlags { get } static var HasBeenRounded: CMTimeFlags { get } static var PositiveInfinity: CMTimeFlags { get } static var NegativeInfinity: CMTimeFlags { get } static var Indefinite: CMTimeFlags { get } static var ImpliedValueFlagsMask: CMTimeFlags { get } }

    Objective-C

    typedef uint32_t CMTimeFlags;

    Discussion

    For possible values, see CMTime Flags.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 4.0 and later.

  • Type for constants used to specify the rounding method to use when computing time.value during timescale conversions.

    Declaration

    Swift

    enum CMTimeRoundingMethod : UInt32 { case RoundHalfAwayFromZero case RoundTowardZero case RoundAwayFromZero case QuickTime case RoundTowardPositiveInfinity case RoundTowardNegativeInfinity }

    Objective-C

    typedef uint32_t CMTimeRoundingMethod;

    Discussion

    For possible values, see Rounding Methods.

    Import Statement

    Objective-C

    @import CoreMedia;

    Swift

    import CoreMedia

    Availability

    Available in iOS 4.0 and later.

Constants

  • Constants to initialize CMTime structures.

    Declaration

    Swift

    let kCMTimeInvalid: CMTime let kCMTimeIndefinite: CMTime let kCMTimePositiveInfinity: CMTime let kCMTimeNegativeInfinity: CMTime let kCMTimeZero: CMTime

    Objective-C

    const CMTime kCMTimeInvalid; const CMTime kCMTimeIndefinite; const CMTime kCMTimePositiveInfinity; const CMTime kCMTimeNegativeInfinity; const CMTime kCMTimeZero;

    Constants

    • kCMTimeInvalid

      kCMTimeInvalid

      Use this constant to initialize an invalid CMTime.

      All fields are 0, so you can calloc or fill with 0's to make lots of them. Do not test against this using (time == kCMTimeInvalid), there are many CMTimes other than this that are also invalid. Use CMTIME_IS_INVALID(time) instead.

      Available in iOS 4.0 and later.

    • kCMTimeIndefinite

      kCMTimeIndefinite

      Use this constant to initialize an indefinite CMTime (for example, the duration of a live broadcast).

      Do not test against this using (time == kCMTimeIndefinite), there are many CMTimes other than this that are also indefinite. Use CMTIME_IS_INDEFINITE(time) instead.

      Available in iOS 4.0 and later.

    • kCMTimePositiveInfinity

      kCMTimePositiveInfinity

      Use this constant to initialize a CMTime to +infinity.

      Do not test against this using (time == kCMTimePositiveInfinity), there are many CMTimes other than this that are also +infinity. Use CMTIME_IS_POSITIVE_INFINITY(time) instead.

      Available in iOS 4.0 and later.

    • kCMTimeNegativeInfinity

      kCMTimeNegativeInfinity

      Use this constant to initialize a CMTime to -infinity.

      Do not test against this using (time == kCMTimeNegativeInfinity), there are many CMTimes other than this that are also -infinity. Use CMTIME_IS_NEGATIVE_INFINITY(time) instead.

      Available in iOS 4.0 and later.

    • kCMTimeZero

      kCMTimeZero

      Use this constant to initialize a CMTime to 0.

      Do not test against this using (time == kCMTimeZero), there are many CMTimes other than this that are also 0. Use CMTimeCompare(time, kCMTimeZero) instead.

      Available in iOS 4.0 and later.

  • Constants to specify flags for CMTime.

    Declaration

    Swift

    struct CMTimeFlags : RawOptionSetType { init(_ rawValue: UInt32) init(rawValue rawValue: UInt32) static var Valid: CMTimeFlags { get } static var HasBeenRounded: CMTimeFlags { get } static var PositiveInfinity: CMTimeFlags { get } static var NegativeInfinity: CMTimeFlags { get } static var Indefinite: CMTimeFlags { get } static var ImpliedValueFlagsMask: CMTimeFlags { get } }

    Objective-C

    enum { kCMTimeFlags_Valid = 1UL<<0, kCMTimeFlags_HasBeenRounded = 1UL<<1, kCMTimeFlags_PositiveInfinity = 1UL<<2, kCMTimeFlags_NegativeInfinity = 1UL<<3, kCMTimeFlags_Indefinite = 1UL<<4, kCMTimeFlags_ImpliedValueFlagsMask = kCMTimeFlags_PositiveInfinity | kCMTimeFlags_NegativeInfinity | kCMTimeFlags_Indefinite };

    Constants

    • Valid

      kCMTimeFlags_Valid

      Indicates that the time is valid.

      Available in iOS 4.0 and later.

    • HasBeenRounded

      kCMTimeFlags_HasBeenRounded

      Indicates that the time has been rounded.

      Available in iOS 4.0 and later.

    • PositiveInfinity

      kCMTimeFlags_PositiveInfinity

      Indicates that the time is +infinity.

      Available in iOS 4.0 and later.

    • NegativeInfinity

      kCMTimeFlags_NegativeInfinity

      Indicates that the time is -infinity.

      Available in iOS 4.0 and later.

    • Indefinite

      kCMTimeFlags_Indefinite

      Indicates that the time is indefinite.

      Available in iOS 4.0 and later.

    • ImpliedValueFlagsMask

      kCMTimeFlags_ImpliedValueFlagsMask

      Indicates that the time is +infinity, -infinity, or indefinite.

      Available in iOS 4.0 and later.

  • A constant to define the maximum timescale.

    Declaration

    Swift

    var kCMTimeMaxTimescale: Int { get }

    Objective-C

    #define kCMTimeMaxTimescale 0x7fffffffL

    Constants

    • kCMTimeMaxTimescale

      kCMTimeMaxTimescale

      The maximum timescale.

      Available in iOS 4.0 and later.

  • Constants used to specify the rounding method to use when computing time.value during timescale conversions.

    Declaration

    Swift

    enum CMTimeRoundingMethod : UInt32 { case RoundHalfAwayFromZero case RoundTowardZero case RoundAwayFromZero case QuickTime case RoundTowardPositiveInfinity case RoundTowardNegativeInfinity }

    Objective-C

    enum { kCMTimeRoundingMethod_RoundHalfAwayFromZero = 1, kCMTimeRoundingMethod_RoundTowardZero = 2, kCMTimeRoundingMethod_RoundAwayFromZero = 3, kCMTimeRoundingMethod_QuickTime = 4, kCMTimeRoundingMethod_RoundTowardPositiveInfinity = 5, kCMTimeRoundingMethod_RoundTowardNegativeInfinity = 6, kCMTimeRoundingMethod_Default = kCMTimeRoundingMethod_RoundHalfAwayFromZero };

    Constants

    • RoundHalfAwayFromZero

      kCMTimeRoundingMethod_RoundHalfAwayFromZero

      Round towards zero if abs(fraction) is < 0.5, away from 0 if abs(fraction) is >= 0.5.

      Available in iOS 4.0 and later.

    • RoundTowardZero

      kCMTimeRoundingMethod_RoundTowardZero

      Round towards zero if fraction is != 0.

      Available in iOS 4.0 and later.

    • RoundAwayFromZero

      kCMTimeRoundingMethod_RoundAwayFromZero

      Round away from zero if abs(fraction) is > 0.

      Available in iOS 4.0 and later.

    • QuickTime

      kCMTimeRoundingMethod_QuickTime

      Use kCMTimeRoundingMethod_RoundTowardZero if converting from larger to smaller scale (that is, from more precision to less precision), but use kCMTimeRoundingMethod_RoundAwayFromZero if converting from smaller to larger scale (i.e. from less precision to more precision).

      Also, never round a negative number down to 0; always return the smallest magnitude negative CMTime in this case (-1/newTimescale).

      Available in iOS 4.0 and later.

    • RoundTowardPositiveInfinity

      kCMTimeRoundingMethod_RoundTowardPositiveInfinity

      Round towards +infinity if fraction is != 0.

      Available in iOS 4.0 and later.

    • RoundTowardNegativeInfinity

      kCMTimeRoundingMethod_RoundTowardNegativeInfinity

      Round towards -infinity if fraction is != 0.

      Available in iOS 4.0 and later.

    • kCMTimeRoundingMethod_Default

      kCMTimeRoundingMethod_Default

      Synonym for kCMTimeRoundingMethod_RoundHalfAwayFromZero.

      Available in iOS 4.0 and later.

  • Keys to access values of a CMTime represented by a CFDictionary.

    Declaration

    Swift

    let kCMTimeValueKey: CFString! let kCMTimeScaleKey: CFString! let kCMTimeEpochKey: CFString! let kCMTimeFlagsKey: CFString!

    Objective-C

    const CFStringRef kCMTimeValueKey; const CFStringRef kCMTimeScaleKey; const CFStringRef kCMTimeEpochKey; const CFStringRef kCMTimeFlagsKey;

    Constants

    • kCMTimeValueKey

      kCMTimeValueKey

      CFDictionary key for the value field of CMTime (a CFNumber containing an int64_t value).

      Available in iOS 4.0 and later.

    • kCMTimeScaleKey

      kCMTimeScaleKey

      CFDictionary key for the timescale field of CMTime (a CFNumber containing an int32_t value).

      Available in iOS 4.0 and later.

    • kCMTimeEpochKey

      kCMTimeEpochKey

      CFDictionary key for the epoch field of CMTime (a CFNumber containing an int64_t value).

      Available in iOS 4.0 and later.

    • kCMTimeFlagsKey

      kCMTimeFlagsKey

      CFDictionary key for the flags field of CMTime (a CFNumber containing an int32_t value).

      Available in iOS 4.0 and later.