Function

CMTimeAdd(_:_:)

Returns the sum of two CMTimes.

Declaration

func CMTimeAdd(_ lhs: CMTime, _ rhs: CMTime) -> CMTime

Parameters

addend1

CMTime to be added.

addend2

Another CMTime to be added.

Return Value

A new CMTime with the summed value of addend1 and 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 hasBeenRounded flag will be set. This flag will also be set if either of the operands has 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.

See Also

Performing Common Operations

func CMTimeSubtract(CMTime, CMTime) -> CMTime

Returns the difference of two CMTimes.

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

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

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

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

func CMTimeMultiplyByRatio(CMTime, multiplier: Int32, divisor: Int32) -> CMTime

Returns the result of multiplying a CMTime by an integer, then dividing by another integer.

func CMTimeConvertScale(CMTime, timescale: Int32, method: CMTimeRoundingMethod) -> CMTime

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