Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How Does CMTimeCompare Work?

Tags:

ios

cmtime

How does CMTimeCompare work? Apple seems to have left out the return values from their documentation.

https://developer.apple.com/library/mac/#documentation/CoreMedia/Reference/CMTime/Reference/reference.html

I assume if the times are equal it returns zero and return positive or negative 1 based on which is greater?

like image 933
Dex Avatar asked Mar 09 '12 10:03

Dex


2 Answers

From CMTime.h:

Returns the numerical relationship (-1 = less than, 1 = greater than, 0 = equal) of two CMTimes.

-1 is returned if time1 is less than time2. 0 is returned if they are equal. 1 is returned if time1 is greater than time2.

EDIT:

Please note that:

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.

like image 59
fbernardo Avatar answered Sep 19 '22 21:09

fbernardo


For an alternative that's much easier to read than CMTimeCompare(), consider using the CMTIME_COMPARE_INLINE macro. For example

CMTIME_COMPARE_INLINE(time1, <=, time2)

will return true if time1 <= time2

like image 34
bcattle Avatar answered Sep 22 '22 21:09

bcattle