简体   繁体   English

哪种CMTime无效?

[英]What kinds of CMTime are invalid?

kCMTimeInvalid is invalid CMTime, but based on Apple document, there are more invalid CMTime, what are they? kCMTimeInvalid是无效的CMTime,但是基于Apple文档,还有更多无效的CMTime,它们是什么? What does CMTime "invalid" means? CMTime“无效”是什么意思? It's overflow, uninitiated or anything else? 它溢出,未启动还是其他?

https://developer.apple.com/documentation/coremedia/kcmtimeinvalid https://developer.apple.com/documentation/coremedia/kcmtimeinvalid

All fields are 0, so you can calloc or fill with 0's to make lots of them. 所有字段均为0,因此您可以calloc或填充0来制作很多字段。 Do not test against this using (time == kCMTimeInvalid), there are many CMTimes other than this that are also invalid. 不要使用(time == kCMTimeInvalid)对此进行测试,除此以外,还有许多CMTime也是无效的。 Use CMTIME_IS_INVALID(time) instead. 请改用CMTIME_IS_INVALID(time)。


I found some cases when CMTime is invalid: 我发现CMTime无效的一些情况:

  • When flags(CMTimeFlags) kCMTimeFlags_Valid not set. 当flags(CMTimeFlags)kCMTimeFlags_Valid未设置时。

    kCMTimeFlags_Valid Must be set, or the CMTime is considered invalid. kCMTimeFlags_Valid必须设置,否则CMTime被视为无效。

  • Some operations of CMTimeAdd CMTimeAdd的一些操作

+infinity + +infinity == +infinity +无限+ +无限== +无限

  • -infinity + -infinity == -infinity -无限+-无限==-无限
  • +infinity + -infinity == invalid +无限+-无限==无效
  • -infinity + +infinity == invalid -infinity + + infinity ==无效

  • There are five possible states: 有五种可能的状态:

    1. +Infinity: This is similar to Float.Infinity. + Infinity:这类似于Float.Infinity。 This is a valid value, just greater than any finite number. 这是一个有效值,仅大于任何有限数。 How might you use it? 您怎么使用它? For example, imagine an API that gives you information about a time range within a video, identified by two CMTimes. 例如,假设有一个API,可以为您提供有关视频中时间范围(由两个CMTimes标识)的信息。 You might invoke it with (-Infinity, +Infinity) to ask for information about the entire video. 您可以使用(-Infinity,+ Infinity)调用它,以询问有关整个视频的信息。
    2. -Infinity: This is again similar to -Float.Infinity. -Infinity:这又类似于-Float.Infinity。
    3. Indefinite: This is similar to Float.NaN, as I understand. 不定的:据我了解,这类似于Float.NaN。 Use this when you don't know what value to use, like the duration of a live stream, as Apple suggests . 如Apple 建议的那样 ,当您不知道要使用什么值(例如直播时间)时,请使用此选项。 It wouldn't be right to use infinity, for example, since a live stream doesn't go on for forever. 例如,使用无穷大是不正确的,因为实时流不会永远持续下去。 It has a finite duration; 持续时间有限; we just don't know it yet. 我们只是还不知道。
    4. Invalid: This is a CMTime structure that doesn't obey the rules of CMTime. 无效:这是不遵守CMTime规则的CMTime结构。 I assume that means things like a zero or negative denominator. 我认为这意味着零分母或负分母。 Since CMTime is a C struct, it's not encapsulated, so someone can create one with invalid values like this. 由于CMTime是C结构,因此未封装,因此有人可以使用这样的无效值创建一个。 C structs can't have initialisers that throw an exception or return nil. C结构不能具有引发异常或返回nil的初始化程序。
    5. Numeric: This is the normal case of a finite value. 数值:这是有限值的正常情况。 Use CMTIME_IS_NUMERIC to check for this. 使用CMTIME_IS_NUMERIC进行检查。 It returns false for all the weird cases above. 对于上述所有奇怪的情况,它返回false。

    From the documentation you posted, it says: 从您发布的文档中可以看到:

    Use CMTIME_IS_INVALID(time) instead. 请改用CMTIME_IS_INVALID(time)。

    From CMTime.h , it looks like CMTIME_IS_INVALID is defined as: CMTime.h ,看起来CMTIME_IS_INVALID定义为:

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

    And CMTIME_IS_VALID is defined as: 并将CMTIME_IS_VALID定义为:

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

    So it looks like the only thing that determines if a CMTime is valid or not is whether the kCMTimeFlags_Valid flag is set. 因此,似乎唯一确定CMTime是否有效的是kCMTimeFlags_Valid标志是否已设置。

    声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

     
    粤ICP备18138465号  © 2020-2024 STACKOOM.COM