CMTimeRange Reference
| Derived from | |
| Framework | CoreMedia.framework |
| Declared in | CMTimeRange.h |
Overview
This document describes the API for creating and manipulating CMTimeRange structures.
CMTimeRange structs are non-opaque mutable structures that represent time ranges. A CMTimeRange is represented as two CMTime structs, one that specifies the start time of the range and another that specifies the duration of the range. A time range does not include the end time that would be calculated by adding the duration to the start time. The following expression will always evaluate to false:
CMTimeRangeContainsTime(range, CMTimeRangeGetEnd(range)) |
You can convert CMTimeRanges to and from CFDictionaries (see CFDictionaryRef) using CMTimeRangeCopyAsDictionary and CMTimeRangeMakeFromDictionary, for use in annotations and various Core Foundation containers.
The epoch in a CMTime that represents a duration should always be 0, and the value must be non-negative. The epoch in a CMTime that represents a timestamp may be non-zero, but range operations (such as CMTimeRangeGetUnion) can only be performed on ranges whose start fields have the same epoch. CMTimeRanges cannot span different epochs.
Additional functions for managing dates and times are described in Time Utilities Reference; see also AV Foundation Constants Reference.
Functions by Task
Working with CMTimeRange
-
CMTimeClampToRange -
CMTimeMapDurationFromRangeToRange -
CMTimeMapTimeFromRangeToRange -
CMTimeRangeContainsTime -
CMTimeRangeContainsTimeRange -
CMTimeRangeCopyAsDictionary -
CMTimeRangeCopyDescription -
CMTimeRangeEqual -
CMTimeRangeFromTimeToTime -
CMTimeRangeGetEnd -
CMTimeRangeGetIntersection -
CMTimeRangeGetUnion -
CMTimeRangeMake -
CMTimeRangeMakeFromDictionary -
CMTimeRangeShow
Comparing CMTimeRange
Functions
CMTimeClampToRange
For a given CMTime and CMTimeRange, returns the nearest CMTime inside that time range.
CMTime CMTimeClampToRange ( CMTime time, CMTimeRange range );
Parameters
- time
The time to be clamped.
- range
The time range being interrogated.
Return Value
A CMTime structure inside the given time range.
Discussion
Times inside the given time range will be returned unmodified.
Times before the start and after the end time of the time range will return the start and end time of
the range respectively.
If the CMTimeRange argument is empty, an invalid CMTime will be returned.
If the given CMTime is invalid, the returned CMTime will be invalid.
Availability
- Available in OS X v10.7 and later.
Declared In
CMTimeRange.hCMTimeMapDurationFromRangeToRange
Translates a duration through a mapping from CMTimeRange to CMTimeRange.
CMTime CMTimeMapDurationFromRangeToRange ( CMTime dur, CMTimeRange fromRange, CMTimeRange toRange );
Parameters
- dur
The duration to be translated.
- fromRange
The time range from which duration is translated.
- toRange
The time range to which duration is mapped to .
Return Value
A CMTime structure representing the translated duration.
Discussion
The duration will be scaled in proportion to the ratio between the ranges' durations:
result = dur*(toRange.duration/fromRange.duration) |
If dur does not have the epoch zero, an invalid CMTime will be returned.
Availability
- Available in OS X v10.7 and later.
Declared In
CMTimeRange.hCMTimeMapTimeFromRangeToRange
Translates a time through a mapping from CMTimeRange to CMTimeRange.
CMTime CMTimeMapTimeFromRangeToRange ( CMTime t, CMTimeRange fromRange, CMTimeRange toRange );
Parameters
- t
The
CMTimeto be translated.- fromRange
The time range from which
CMTimeis translated.- toRange
The time range to which
CMTimeis mapped to.
Return Value
A CMTime structure representing the translated time.
Discussion
The start and end time of fromRange will be mapped to the start and end time of toRange respectively. Other times will be mapped linearly, using the formula:
result = (t-fromRange.start)*(toRange.duration/fromRange.duration)+toRange.start |
If either CMTimeRange argument is empty, an invalid CMTime will be returned.
If t does not have the same epoch as fromRange.start, an invalid CMTime will be returned.
If both fromRange and toRange have duration kCMTimePositiveInfinity, t will be offset relative to the differences between their starts, but not scaled.
Availability
- Available in OS X v10.7 and later.
Declared In
CMTimeRange.hCMTimeRangeContainsTime
Indicates whether a time is contained within a time range.
Boolean CMTimeRangeContainsTime ( CMTimeRange range, CMTime time );
Parameters
- range
CMTimeRangebeing interrogated.- time
CMTimeto be tested for inclusion.
Return Value
Returns true if the specified time is contained within the specified time range, false if it is not.
Discussion
This function returns a Boolean value that indicates whether the time specified by the time parameter is contained within the range specified by the range parameter.
Availability
- Available in OS X v10.7 and later.
Declared In
CMTimeRange.hCMTimeRangeContainsTimeRange
Returns a Boolean that indicates whether a given time range is contained within another time range.
Boolean CMTimeRangeContainsTimeRange ( CMTimeRange range1, CMTimeRange range2 );
Parameters
- range1
The
CMTimeRangebeing interrogated.- range2
CMTimeRangeto be tested for inclusion.
Return Value
Returns true if the second time range is contained within the first time range, false if it is not.
Discussion
This function returns a Boolean value that indicates whether the time range specified by the range1 parameter contains the range specified by the range2 parameter.
Availability
- Available in OS X v10.7 and later.
Declared In
CMTimeRange.hCMTimeRangeCopyAsDictionary
Returns a CFDictionary version of a CMTimeRange.
CFDictionaryRef CMTimeRangeCopyAsDictionary ( CMTimeRange range, CFAllocatorRef allocator );
Parameters
- range
The
CMTimeRangefrom which to create a dictionary.- allocator
CFAllocatorwith which to create a dictionary. PasskCFAllocatorDefaultto use the default allocator
Return Value
A CFDictionary version of the CMTimeRange.
Discussion
This is useful when putting CMTimeRanges in Core Foundation container types. For keys, see “CFDictionary Keys.”
Availability
- Available in OS X v10.7 and later.
Declared In
CMTimeRange.hCMTimeRangeCopyDescription
Creates a CFString with a description of a CMTimeRange (similar to CFCopyDescription).
CFStringRef CMTimeRangeCopyDescription ( CFAllocatorRef allocator, CMTimeRange range );
Parameters
- allocator
CFAllocatorfor allocating memory for description. PasskCFAllocatorDefaultto use the default allocator.- range
The
CMTimeRangeto describe.
Return Value
The created CFString description.
Discussion
This is used from within CFShow on an object that contains CMTimeRange fields. It is also useful from other client debugging code. The caller owns the returned CFString and is responsible for releasing it.
Availability
- Available in OS X v10.7 and later.
Declared In
CMTimeRange.hCMTimeRangeEqual
Returns a Boolean value that indicates whether two CMTimeRanges are identical.
Boolean CMTimeRangeEqual ( CMTimeRange range1, CMTimeRange range2 );
Parameters
- range1
CMTimeRangeto be compared for equality.- range2
Another
CMTimeRangeto be compared for equality.
Return Value
Returns true if the two time ranges are identical, false if they differ.
Discussion
This function returns a Boolean value that indicates whether the time ranges specified by the range1 and range2 parameters are identical.
Availability
- Available in OS X v10.7 and later.
Declared In
CMTimeRange.hCMTimeRangeFromTimeToTime
Creates a valid CMTimeRange from the given start and end time.
CMTimeRange CMTimeRangeFromTimeToTime ( CMTime start, CMTime end );
Parameters
- start
CMTimestructure representing start time for creating the range.- end
CMTimestructure representing end time for creating the range.
Return Value
The resulting CMTimeRange.
Availability
- Available in OS X v10.7 and later.
Declared In
CMTimeRange.hCMTimeRangeGetEnd
Returns a CMTime structure representing the end of a time range.
CMTime CMTimeRangeGetEnd ( CMTimeRange range );
Parameters
- range
The CMTimeRange from which to find the end of time range.
Return Value
A CMTime structure representing the end of the specified time range.
Discussion
This function returns a CMTime structure that indicates the end of the time range specified by the range parameter. CMTimeRangeContainsTime(range, CMTimeRangeGetEnd(range)) is always false.
Availability
- Available in OS X v10.7 and later.
Declared In
CMTimeRange.hCMTimeRangeGetIntersection
Returns the intersection of two CMTimeRanges.
CMTimeRange CMTimeRangeGetIntersection ( CMTimeRange range1, CMTimeRange range2 );
Parameters
- range1
CMTimeRangeto be intersected.- range2
Another
CMTimeRangeto be intersected.
Return Value
The intersection of the two CMTimeRanges.
Discussion
This function returns a CMTimeRange structure that represents the intersection of the time ranges specified by the range1 and range2 parameters.
This is the largest range that both ranges include.
Availability
- Available in OS X v10.7 and later.
Declared In
CMTimeRange.hCMTimeRangeGetUnion
Returns the union of two CMTimeRanges.
CMTimeRange CMTimeRangeGetUnion ( CMTimeRange range1, CMTimeRange range2 );
Parameters
- range1
CMTimeRangeto be unified.- range2
Another
CMTimeRangeto be unified.
Return Value
The union of the two CMTimeRanges.
Discussion
This function returns a CMTimeRange structure that represents the union of the time ranges specified by the range1 and range2 parameters. This is the smallest range that includes all times that are in either range.
Availability
- Available in OS X v10.7 and later.
Declared In
CMTimeRange.hCMTimeRangeMake
Creates a valid CMTimeRange with the given start time and duration.
CMTimeRange CMTimeRangeMake ( CMTime start, CMTime duration );
Parameters
- start
CMTimestructure for initializing the start field of the resultingCMTimeRange.- duration
CMTimestructure for initializing the duration field of the resultingCMTimeRange.
Return Value
The resulting CMTimeRange.
Discussion
The duration parameter must have an epoch of 0; otherwise an invalid time range will be returned.
Availability
- Available in OS X v10.7 and later.
Declared In
CMTimeRange.hCMTimeRangeMakeFromDictionary
Reconstitutes a CMTimeRange struct from a CFDictionary previously created by CMTimeRangeCopyAsDictionary.
CMTimeRange CMTimeRangeMakeFromDictionary ( CFDictionaryRef dict );
Parameters
- dict
CFDictionaryfrom which to create aCMTimeRange.
Return Value
The reconstituted CMTimeRange.
Discussion
This is useful when getting CMTimeRanges from Core Foundation container types. If the CFDictionary does not have the requisite keyed values, an invalid time range is returned.
For keys, see “CFDictionary Keys.”
Availability
- Available in OS X v10.7 and later.
Declared In
CMTimeRange.hCMTimeRangeShow
Prints a description of the CMTimeRange to stderr (similar to CFShow).
void CMTimeRangeShow ( CMTimeRange range );
Parameters
- range
The
CMTimeRangeto be printed.
Discussion
This is most useful from within gdb.
Availability
- Available in OS X v10.7 and later.
Declared In
CMTimeRange.hCMTIMERANGE_IS_EMPTY
Returns a Boolean value that indicates whether a given CMTimeRange has a duration of 0.
#define CMTIMERANGE_IS_EMPTY(range) ((Boolean)(CMTIMERANGE_IS_VALID(range) && (CMTIME_COMPARE_INLINE(range.duration, ==, kCMTimeZero))))
Parameters
- range
The time range to be tested for emptiness.
Return Value
true if range has a duration of 0; otherwise, false.
Availability
- Available in OS X v10.7 and later.
Declared In
CMTimeRange.hCMTIMERANGE_IS_INDEFINITE
Returns a Boolean value that indicates whether a given CMTimeRange is indefinite.
#define CMTIMERANGE_IS_INDEFINITE(range) ((Boolean)(CMTIMERANGE_IS_VALID(range) && (CMTIME_IS_INDEFINITE(range.start) || CMTIME_IS_INDEFINITE(range.duration))))
Parameters
- range
The time range to be tested for finiteness.
Return Value
true if range is indefinite; otherwise, false.
Discussion
An indefinite time range has either an indefinite start or an indefinite duration, or both.
Availability
- Available in OS X v10.7 and later.
Declared In
CMTimeRange.hCMTIMERANGE_IS_INVALID
Returns a Boolean value that indicates whether a given CMTimeRange is invalid.
#define CMTIMERANGE_IS_INVALID(range) (! CMTIMERANGE_IS_VALID(range))
Parameters
- range
The time range to be tested for invalidity.
Return Value
true if range is invalid; otherwise, false.
Availability
- Available in OS X v10.7 and later.
Declared In
CMTimeRange.hCMTIMERANGE_IS_VALID
Returns a Boolean value that indicates whether a given CMTimeRange is valid.
#define CMTIMERANGE_IS_VALID(range) ((Boolean)(CMTIME_IS_VALID(range.start) && CMTIME_IS_VALID(range.duration) && (range.duration.epoch == 0) && (range.duration.value >= 0)))
Parameters
- range
The time range to be tested for validity.
Return Value
true if range is valid; otherwise, false.
Availability
- Available in OS X v10.7 and later.
Declared In
CMTimeRange.hData Types
CMTimeMapping
A structure to specify the mapping of a segment of one time line into another.
typedef struct {
CMTimeRange source;
CMTimeRange target;
} CMTimeMapping;
Fields
sourceThe time range on the source time line.
For an empty edit,
source.startis an invalid CMTime, in which case source.duration is ignored. Otherwise,source.startis the starting time within the source, andsource.durationis the duration of the source timeline to be mapped to the target time range.targetThe time range on the target time line.
If
target.durationandsource.durationare different, then the source segment should be played at the ratesource.duration /target.durationto fit.
Discussion
A CMTimeMapping specifies the mapping of a segment of one time line (called the source) into another time line (called the target). When used for movie edit lists, the source time line is the media and the target time line is the track or movie.
Availability
- Available in OS X v10.7 and later.
Declared In
CMTimeRange.hCMTimeRange
A time range represented as two CMTime structures.
typedef struct {
CMTime start;
CMTime duration;
} CMTimeRange;
Fields
startThe start time of the time range.
durationThe duration of the time range.
Availability
- Available in OS X v10.7 and later.
Declared In
CMTimeRange.hConstants
CFDictionary Keys
Keys for components in a CFDictionary representation of a CMTimeRange.
const CFStringRef kCMTimeRangeStartKey; const CFStringRef kCMTimeRangeDurationKey;
Constants
kCMTimeRangeStartKeyThe key for start field of a
CMTimeRange(CMTime).Available in OS X v10.7 and later.
Declared in
CMTimeRange.h.kCMTimeRangeDurationKeyThe key for timescale of a
CMTimeRange(CMTime).Available in OS X v10.7 and later.
Declared in
CMTimeRange.h.
Discussion
To convert a CMTimeRange to and from a CFDictionary, see CMTimeRangeCopyAsDictionary and CMTimeRangeMakeFromDictionary.
Pre-Specified Time Ranges
These constants specify zero and invalid time ranges.
const CMTimeRange kCMTimeRangeZero; const CMTimeRange kCMTimeRangeInvalid;
Constants
kCMTimeRangeZeroUse this constant to generate an empty
CMTimeRangeat0.Available in OS X v10.7 and later.
Declared in
CMTimeRange.h.kCMTimeRangeInvalidUse this constant to generate an invalid
CMTimeRange.Available in OS X v10.7 and later.
Declared in
CMTimeRange.h.
© 2003, 2013 Apple Inc. All Rights Reserved. (Last updated: 2013-01-28)