objc2_core_media/generated/
CMTime.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5#[cfg(feature = "objc2")]
6use objc2::__framework_prelude::*;
7use objc2_core_foundation::*;
8
9use crate::*;
10
11/// [Apple's documentation](https://developer.apple.com/documentation/coremedia/kcmtimemaxtimescale?language=objc)
12pub const kCMTimeMaxTimescale: c_uint = 0x7fffffff;
13/// Numerator of rational CMTime.
14///
15/// See also [Apple's documentation](https://developer.apple.com/documentation/coremedia/cmtimevalue?language=objc)
16pub type CMTimeValue = i64;
17
18/// Denominator of rational CMTime.
19///
20/// Timescales must be positive.
21/// Note: kCMTimeMaxTimescale is NOT a good choice of timescale for movie files.
22/// (Recommended timescales for movie files range from 600 to 90000.)
23///
24/// See also [Apple's documentation](https://developer.apple.com/documentation/coremedia/cmtimescale?language=objc)
25pub type CMTimeScale = i32;
26
27/// Epoch (eg, loop number) to which a CMTime refers.
28///
29/// See also [Apple's documentation](https://developer.apple.com/documentation/coremedia/cmtimeepoch?language=objc)
30pub type CMTimeEpoch = i64;
31
32/// Flag bits for a CMTime.
33///
34/// Allows simple clearing (eg. with calloc or memset) for initialization
35/// of arrays of CMTime structs to "invalid". This flag must be set, even
36/// if other flags are set as well.
37///
38///
39///
40///
41/// "Implied value" flag (other struct fields are ignored).
42///
43/// See also [Apple's documentation](https://developer.apple.com/documentation/coremedia/cmtimeflags?language=objc)
44// NS_OPTIONS
45#[repr(transparent)]
46#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
47pub struct CMTimeFlags(pub u32);
48bitflags::bitflags! {
49    impl CMTimeFlags: u32 {
50        #[doc(alias = "kCMTimeFlags_Valid")]
51        const Valid = 1<<0;
52        #[doc(alias = "kCMTimeFlags_HasBeenRounded")]
53        const HasBeenRounded = 1<<1;
54        #[doc(alias = "kCMTimeFlags_PositiveInfinity")]
55        const PositiveInfinity = 1<<2;
56        #[doc(alias = "kCMTimeFlags_NegativeInfinity")]
57        const NegativeInfinity = 1<<3;
58        #[doc(alias = "kCMTimeFlags_Indefinite")]
59        const Indefinite = 1<<4;
60        #[doc(alias = "kCMTimeFlags_ImpliedValueFlagsMask")]
61        const ImpliedValueFlagsMask = CMTimeFlags::PositiveInfinity.0|CMTimeFlags::NegativeInfinity.0|CMTimeFlags::Indefinite.0;
62    }
63}
64
65#[cfg(feature = "objc2")]
66unsafe impl Encode for CMTimeFlags {
67    const ENCODING: Encoding = u32::ENCODING;
68}
69
70#[cfg(feature = "objc2")]
71unsafe impl RefEncode for CMTimeFlags {
72    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
73}
74
75/// Rational time value represented as int64/int32.
76///
77/// See also [Apple's documentation](https://developer.apple.com/documentation/coremedia/cmtime?language=objc)
78#[repr(C, packed(4))]
79#[derive(Clone, Copy, Debug, PartialEq)]
80pub struct CMTime {
81    /// The value of the CMTime. value/timescale = seconds
82    pub value: CMTimeValue,
83    /// The timescale of the CMTime. value/timescale = seconds.
84    pub timescale: CMTimeScale,
85    /// The flags, eg. kCMTimeFlags_Valid, kCMTimeFlags_PositiveInfinity, etc.
86    pub flags: CMTimeFlags,
87    /// Differentiates between equal timestamps that are actually different because
88    /// of looping, multi-item sequencing, etc.
89    /// Will be used during comparison: greater epochs happen after lesser ones.
90    /// Additions/subtraction is only possible within a single epoch,
91    /// however, since epoch length may be unknown/variable
92    pub epoch: CMTimeEpoch,
93}
94
95#[cfg(feature = "objc2")]
96unsafe impl Encode for CMTime {
97    const ENCODING: Encoding = Encoding::Struct(
98        "?",
99        &[
100            <CMTimeValue>::ENCODING,
101            <CMTimeScale>::ENCODING,
102            <CMTimeFlags>::ENCODING,
103            <CMTimeEpoch>::ENCODING,
104        ],
105    );
106}
107
108#[cfg(feature = "objc2")]
109unsafe impl RefEncode for CMTime {
110    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
111}
112
113extern "C" {
114    /// [Apple's documentation](https://developer.apple.com/documentation/coremedia/kcmtimeinvalid?language=objc)
115    pub static kCMTimeInvalid: CMTime;
116}
117
118extern "C" {
119    /// [Apple's documentation](https://developer.apple.com/documentation/coremedia/kcmtimeindefinite?language=objc)
120    pub static kCMTimeIndefinite: CMTime;
121}
122
123extern "C" {
124    /// [Apple's documentation](https://developer.apple.com/documentation/coremedia/kcmtimepositiveinfinity?language=objc)
125    pub static kCMTimePositiveInfinity: CMTime;
126}
127
128extern "C" {
129    /// [Apple's documentation](https://developer.apple.com/documentation/coremedia/kcmtimenegativeinfinity?language=objc)
130    pub static kCMTimeNegativeInfinity: CMTime;
131}
132
133extern "C" {
134    /// [Apple's documentation](https://developer.apple.com/documentation/coremedia/kcmtimezero?language=objc)
135    pub static kCMTimeZero: CMTime;
136}
137
138impl CMTime {
139    /// Make a valid CMTime with value and timescale.  Epoch is implied to be 0.
140    ///
141    /// Returns: The resulting CMTime.
142    #[doc(alias = "CMTimeMake")]
143    #[inline]
144    pub unsafe fn new(value: i64, timescale: i32) -> CMTime {
145        extern "C-unwind" {
146            fn CMTimeMake(value: i64, timescale: i32) -> CMTime;
147        }
148        unsafe { CMTimeMake(value, timescale) }
149    }
150
151    /// Make a valid CMTime with value, scale and epoch.
152    ///
153    /// Returns: The resulting CMTime.
154    #[doc(alias = "CMTimeMakeWithEpoch")]
155    #[inline]
156    pub unsafe fn with_epoch(value: i64, timescale: i32, epoch: i64) -> CMTime {
157        extern "C-unwind" {
158            fn CMTimeMakeWithEpoch(value: i64, timescale: i32, epoch: i64) -> CMTime;
159        }
160        unsafe { CMTimeMakeWithEpoch(value, timescale, epoch) }
161    }
162
163    /// Make a CMTime from a Float64 number of seconds, and a preferred timescale.
164    ///
165    /// The epoch of the result will be zero.  If preferredTimescale is
166    /// <
167    /// = 0, the result
168    /// will be an invalid CMTime.  If the preferred timescale will cause an overflow, the
169    /// timescale will be halved repeatedly until the overflow goes away, or the timescale
170    /// is 1.  If it still overflows at that point, the result will be +/- infinity.  The
171    /// kCMTimeFlags_HasBeenRounded flag will be set if the result, when converted back to
172    /// seconds, is not exactly equal to the original seconds value.
173    ///
174    /// Returns: The resulting CMTime.
175    #[doc(alias = "CMTimeMakeWithSeconds")]
176    #[inline]
177    pub unsafe fn with_seconds(seconds: f64, preferred_timescale: i32) -> CMTime {
178        extern "C-unwind" {
179            fn CMTimeMakeWithSeconds(seconds: f64, preferred_timescale: i32) -> CMTime;
180        }
181        unsafe { CMTimeMakeWithSeconds(seconds, preferred_timescale) }
182    }
183
184    /// Converts a CMTime to seconds.
185    ///
186    /// If the CMTime is invalid or indefinite, NAN is returned.  If the CMTime is infinite, +/- __inf()
187    /// is returned.  If the CMTime is numeric, epoch is ignored, and time.value / time.timescale is
188    /// returned.  The division is done in Float64, so the fraction is not lost in the returned result.
189    ///
190    /// Returns: The resulting Float64 number of seconds.
191    #[doc(alias = "CMTimeGetSeconds")]
192    #[inline]
193    pub unsafe fn seconds(self) -> f64 {
194        extern "C-unwind" {
195            fn CMTimeGetSeconds(time: CMTime) -> f64;
196        }
197        unsafe { CMTimeGetSeconds(self) }
198    }
199}
200
201/// Rounding method to use when computing time.value during timescale conversions.
202///
203/// away from 0 if abs(fraction) is >= 0.5.
204///
205///
206///
207///
208/// from larger to smaller scale (ie. from more precision to
209/// less precision), but use
210/// kCMTimeRoundingMethod_RoundAwayFromZero if converting
211/// from smaller to larger scale (ie. from less precision to
212/// more precision). Also, never round a negative number down
213/// to 0; always return the smallest magnitude negative
214/// CMTime in this case (-1/newTimescale).
215///
216/// See also [Apple's documentation](https://developer.apple.com/documentation/coremedia/cmtimeroundingmethod?language=objc)
217// NS_ENUM
218#[repr(transparent)]
219#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
220pub struct CMTimeRoundingMethod(pub u32);
221impl CMTimeRoundingMethod {
222    #[doc(alias = "kCMTimeRoundingMethod_RoundHalfAwayFromZero")]
223    pub const RoundHalfAwayFromZero: Self = Self(1);
224    #[doc(alias = "kCMTimeRoundingMethod_RoundTowardZero")]
225    pub const RoundTowardZero: Self = Self(2);
226    #[doc(alias = "kCMTimeRoundingMethod_RoundAwayFromZero")]
227    pub const RoundAwayFromZero: Self = Self(3);
228    #[doc(alias = "kCMTimeRoundingMethod_QuickTime")]
229    pub const QuickTime: Self = Self(4);
230    #[doc(alias = "kCMTimeRoundingMethod_RoundTowardPositiveInfinity")]
231    pub const RoundTowardPositiveInfinity: Self = Self(5);
232    #[doc(alias = "kCMTimeRoundingMethod_RoundTowardNegativeInfinity")]
233    pub const RoundTowardNegativeInfinity: Self = Self(6);
234    #[doc(alias = "kCMTimeRoundingMethod_Default")]
235    pub const Default: Self = Self(CMTimeRoundingMethod::RoundHalfAwayFromZero.0);
236}
237
238#[cfg(feature = "objc2")]
239unsafe impl Encode for CMTimeRoundingMethod {
240    const ENCODING: Encoding = u32::ENCODING;
241}
242
243#[cfg(feature = "objc2")]
244unsafe impl RefEncode for CMTimeRoundingMethod {
245    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
246}
247
248impl CMTime {
249    /// Returns a new CMTime containing the source CMTime converted to a new timescale (rounding as requested).
250    ///
251    /// If the value needs to be rounded, the kCMTimeFlags_HasBeenRounded flag will be set.
252    /// See definition of CMTimeRoundingMethod for a discussion of the various rounding methods available. If
253    /// the source time is non-numeric (ie. infinite, indefinite, invalid), the result will be similarly non-numeric.
254    ///
255    /// Returns: The converted result CMTime.
256    #[doc(alias = "CMTimeConvertScale")]
257    #[inline]
258    pub unsafe fn convert_scale(self, new_timescale: i32, method: CMTimeRoundingMethod) -> CMTime {
259        extern "C-unwind" {
260            fn CMTimeConvertScale(
261                time: CMTime,
262                new_timescale: i32,
263                method: CMTimeRoundingMethod,
264            ) -> CMTime;
265        }
266        unsafe { CMTimeConvertScale(self, new_timescale, method) }
267    }
268
269    /// Returns the sum of two CMTimes.
270    ///
271    /// If the operands both have the same timescale, the timescale of the result will be the same as
272    /// the operands' timescale.  If the operands have different timescales, the timescale of the result
273    /// will be the least common multiple of the operands' timescales.  If that LCM timescale is
274    /// greater than kCMTimeMaxTimescale, the result timescale will be kCMTimeMaxTimescale,
275    /// and default rounding will be applied when converting the result to this timescale.
276    ///
277    /// If the result value overflows, the result timescale will be repeatedly halved until the result
278    /// value no longer overflows.  Again, default rounding will be applied when converting the
279    /// result to this timescale.  If the result value still overflows when timescale == 1, then the
280    /// result will be either positive or negative infinity, depending on the direction of the
281    /// overflow.
282    ///
283    /// If any rounding occurs for any reason, the result's kCMTimeFlags_HasBeenRounded flag will be
284    /// set.  This flag will also be set if either of the operands has kCMTimeFlags_HasBeenRounded set.
285    ///
286    /// If either of the operands is invalid, the result will be invalid.
287    ///
288    /// If the operands are valid, but just one operand is infinite, the result will be similarly
289    /// infinite. If the operands are valid, and both are infinite, the results will be as follows:
290    /// <ul>
291    /// +infinity + +infinity == +infinity
292    /// <li>
293    /// -infinity + -infinity == -infinity
294    /// <li>
295    /// +infinity + -infinity == invalid
296    /// <li>
297    /// -infinity + +infinity == invalid
298    /// </ul>
299    /// If the operands are valid, not infinite, and either or both is indefinite, the result
300    /// will be indefinite.
301    ///
302    /// If the two operands are numeric (ie. valid, not infinite, not indefinite), but have
303    /// different nonzero epochs, the result will be invalid.  If they have the same nonzero
304    /// epoch, the result will have epoch zero (a duration).  Times in different epochs
305    /// cannot be added or subtracted, because epoch length is unknown.  Times in epoch zero
306    /// are considered to be durations and can be added to times in other epochs.
307    /// Times in different epochs can be compared, however, because numerically greater
308    /// epochs always occur after numerically lesser epochs.
309    ///
310    /// Returns: The sum of the two CMTimes (lhs + rhs).
311    #[doc(alias = "CMTimeAdd")]
312    #[inline]
313    pub unsafe fn add(self, rhs: CMTime) -> CMTime {
314        extern "C-unwind" {
315            fn CMTimeAdd(lhs: CMTime, rhs: CMTime) -> CMTime;
316        }
317        unsafe { CMTimeAdd(self, rhs) }
318    }
319
320    /// Returns the difference of two CMTimes.
321    ///
322    /// If the operands both have the same timescale, the timescale of the result will be the same as
323    /// the operands' timescale.  If the operands have different timescales, the timescale of the result
324    /// will be the least common multiple of the operands' timescales.  If that LCM timescale is
325    /// greater than kCMTimeMaxTimescale, the result timescale will be kCMTimeMaxTimescale,
326    /// and default rounding will be applied when converting the result to this timescale.
327    ///
328    /// If the result value overflows, the result timescale will be repeatedly halved until the result
329    /// value no longer overflows.  Again, default rounding will be applied when converting the
330    /// result to this timescale.  If the result value still overflows when timescale == 1, then the
331    /// result will be either positive or negative infinity, depending on the direction of the
332    /// overflow.
333    ///
334    /// If any rounding occurs for any reason, the result's kCMTimeFlags_HasBeenRounded flag will be
335    /// set.  This flag will also be set if either of the operands has kCMTimeFlags_HasBeenRounded set.
336    ///
337    /// If either of the operands is invalid, the result will be invalid.
338    ///
339    /// If the operands are valid, but just one operand is infinite, the result will be similarly
340    /// infinite. If the operands are valid, and both are infinite, the results will be as follows:
341    /// <ul>
342    /// +infinity - +infinity == invalid
343    /// <li>
344    /// -infinity - -infinity == invalid
345    /// <li>
346    /// +infinity - -infinity == +infinity
347    /// <li>
348    /// -infinity - +infinity == -infinity
349    /// </ul>
350    /// If the operands are valid, not infinite, and either or both is indefinite, the result
351    /// will be indefinite.
352    ///
353    /// If the two operands are numeric (ie. valid, not infinite, not indefinite), but have
354    /// different nonzero epochs, the result will be invalid.  If they have the same nonzero
355    /// epoch, the result will have epoch zero (a duration).  Times in different epochs
356    /// cannot be added or subtracted, because epoch length is unknown.  Times in epoch zero
357    /// are considered to be durations and can be subtracted from times in other epochs.
358    /// Times in different epochs can be compared, however, because numerically greater
359    /// epochs always occur after numerically lesser epochs.
360    ///
361    /// Returns: The difference of the two CMTimes (lhs - rhs).
362    #[doc(alias = "CMTimeSubtract")]
363    #[inline]
364    pub unsafe fn subtract(self, rhs: CMTime) -> CMTime {
365        extern "C-unwind" {
366            fn CMTimeSubtract(lhs: CMTime, rhs: CMTime) -> CMTime;
367        }
368        unsafe { CMTimeSubtract(self, rhs) }
369    }
370
371    /// Returns the product of a CMTime and a 32-bit integer.
372    ///
373    /// The result will have the same timescale as the CMTime operand. If the result value overflows,
374    /// the result timescale will be repeatedly halved until the result value no longer overflows.
375    /// Again, default rounding will be applied when converting the result to this timescale.  If the
376    /// result value still overflows when timescale == 1, then the result will be either positive or
377    /// negative infinity, depending on the direction of the overflow.
378    ///
379    /// If any rounding occurs for any reason, the result's kCMTimeFlags_HasBeenRounded flag will be
380    /// set.  This flag will also be set if the CMTime operand has kCMTimeFlags_HasBeenRounded set.
381    ///
382    /// If the CMTime operand is invalid, the result will be invalid.
383    ///
384    /// If the CMTime operand is valid, but infinite, the result will be infinite, and of an appropriate sign, given
385    /// the signs of both operands.
386    ///
387    /// If the CMTime operand is valid, but indefinite, the result will be indefinite.
388    ///
389    ///
390    /// Returns: The product of the CMTime and the 32-bit integer.
391    #[doc(alias = "CMTimeMultiply")]
392    #[inline]
393    pub unsafe fn multiply(self, multiplier: i32) -> CMTime {
394        extern "C-unwind" {
395            fn CMTimeMultiply(time: CMTime, multiplier: i32) -> CMTime;
396        }
397        unsafe { CMTimeMultiply(self, multiplier) }
398    }
399
400    /// Returns the product of a CMTime and a 64-bit float.
401    ///
402    /// The result will initially have the same timescale as the CMTime operand.
403    /// If the result timescale is less than 65536, it will be repeatedly doubled until it is at least 65536.
404    /// If the result value overflows, the result timescale will be repeatedly halved until the
405    /// result value no longer overflows.
406    /// Again, default rounding will be applied when converting the result to this timescale.  If the
407    /// result value still overflows when timescale == 1, then the result will be either positive or
408    /// negative infinity, depending on the direction of the overflow.
409    ///
410    /// If any rounding occurs for any reason, the result's kCMTimeFlags_HasBeenRounded flag will be
411    /// set.  This flag will also be set if the CMTime operand has kCMTimeFlags_HasBeenRounded set.
412    ///
413    /// If the CMTime operand is invalid, the result will be invalid.
414    ///
415    /// If the CMTime operand is valid, but infinite, the result will be infinite, and of an appropriate sign, given
416    /// the signs of both operands.
417    ///
418    /// If the CMTime operand is valid, but indefinite, the result will be indefinite.
419    ///
420    ///
421    /// Returns: The product of the CMTime and the 64-bit float.
422    #[doc(alias = "CMTimeMultiplyByFloat64")]
423    #[inline]
424    pub unsafe fn multiply_by_float64(self, multiplier: f64) -> CMTime {
425        extern "C-unwind" {
426            fn CMTimeMultiplyByFloat64(time: CMTime, multiplier: f64) -> CMTime;
427        }
428        unsafe { CMTimeMultiplyByFloat64(self, multiplier) }
429    }
430
431    /// Returns the result of multiplying a CMTime by an integer, then dividing by another integer.
432    ///
433    /// The exact rational value will be preserved, if possible without overflow.  If an overflow
434    /// would occur, a new timescale will be chosen so as to minimize the rounding error.
435    /// Default rounding will be applied when converting the result to this timescale.  If the
436    /// result value still overflows when timescale == 1, then the result will be either positive
437    /// or negative infinity, depending on the direction of the overflow.
438    ///
439    /// If any rounding occurs for any reason, the result's kCMTimeFlags_HasBeenRounded flag will be
440    /// set.  This flag will also be set if the CMTime operand has kCMTimeFlags_HasBeenRounded set.
441    ///
442    /// If the denominator, and either the time or the numerator, are zero, the result will be
443    /// kCMTimeInvalid.  If only the denominator is zero, the result will be either kCMTimePositiveInfinity
444    /// or kCMTimeNegativeInfinity, depending on the signs of the other arguments.
445    ///
446    /// If time is invalid, the result will be invalid. If time is infinite, the result will be
447    /// similarly infinite. If time is indefinite, the result will be indefinite.
448    ///
449    ///
450    /// Returns: (time * multiplier) / divisor
451    #[doc(alias = "CMTimeMultiplyByRatio")]
452    #[inline]
453    pub unsafe fn multiply_by_ratio(self, multiplier: i32, divisor: i32) -> CMTime {
454        extern "C-unwind" {
455            fn CMTimeMultiplyByRatio(time: CMTime, multiplier: i32, divisor: i32) -> CMTime;
456        }
457        unsafe { CMTimeMultiplyByRatio(self, multiplier, divisor) }
458    }
459
460    /// Returns the numerical relationship (-1 = less than, 1 = greater than, 0 = equal) of two CMTimes.
461    ///
462    /// If the two CMTimes are numeric (ie. not invalid, infinite, or indefinite), and have
463    /// different epochs, it is considered that times in numerically larger epochs are always
464    /// greater than times in numerically smaller epochs.
465    ///
466    /// Since this routine will be used to sort lists by time, it needs to give all values
467    /// (even invalid and indefinite ones) a strict ordering to guarantee that sort algorithms
468    /// terminate safely. The order chosen is somewhat arbitrary:
469    ///
470    /// -infinity
471    /// <
472    /// all finite values
473    /// <
474    /// indefinite
475    /// <
476    /// +infinity
477    /// <
478    /// invalid
479    ///
480    /// Invalid CMTimes are considered to be equal to other invalid CMTimes, and greater than
481    /// any other CMTime. Positive infinity is considered to be less than any invalid CMTime,
482    /// equal to itself, and greater than any other CMTime. An indefinite CMTime is considered
483    /// to be less than any invalid CMTime, less than positive infinity, equal to itself,
484    /// and greater than any other CMTime.  Negative infinity is considered to be equal to itself,
485    /// and less than any other CMTime.
486    ///
487    /// -1 is returned if time1 is less than time2. 0 is returned if they
488    /// are equal. 1 is returned if time1 is greater than time2.
489    ///
490    /// Returns: The numerical relationship of the two CMTimes (-1 = less than, 1 = greater than, 0 = equal).
491    #[doc(alias = "CMTimeCompare")]
492    #[inline]
493    pub unsafe fn compare(self, time2: CMTime) -> i32 {
494        extern "C-unwind" {
495            fn CMTimeCompare(time1: CMTime, time2: CMTime) -> i32;
496        }
497        unsafe { CMTimeCompare(self, time2) }
498    }
499
500    /// Returns the lesser of two CMTimes (as defined by CMTimeCompare).
501    ///
502    /// Returns: The lesser of the two CMTimes.
503    #[doc(alias = "CMTimeMinimum")]
504    #[inline]
505    pub unsafe fn minimum(self, time2: CMTime) -> CMTime {
506        extern "C-unwind" {
507            fn CMTimeMinimum(time1: CMTime, time2: CMTime) -> CMTime;
508        }
509        unsafe { CMTimeMinimum(self, time2) }
510    }
511
512    /// Returns the greater of two CMTimes (as defined by CMTimeCompare).
513    ///
514    /// Returns: The greater of the two CMTimes.
515    #[doc(alias = "CMTimeMaximum")]
516    #[inline]
517    pub unsafe fn maximum(self, time2: CMTime) -> CMTime {
518        extern "C-unwind" {
519            fn CMTimeMaximum(time1: CMTime, time2: CMTime) -> CMTime;
520        }
521        unsafe { CMTimeMaximum(self, time2) }
522    }
523
524    /// Returns the absolute value of a CMTime.
525    ///
526    /// Returns: Same as the argument time, with sign inverted if negative.
527    #[doc(alias = "CMTimeAbsoluteValue")]
528    #[inline]
529    pub unsafe fn absolute_value(self) -> CMTime {
530        extern "C-unwind" {
531            fn CMTimeAbsoluteValue(time: CMTime) -> CMTime;
532        }
533        unsafe { CMTimeAbsoluteValue(self) }
534    }
535
536    /// Returns a CFDictionary version of a CMTime.
537    ///
538    /// This is useful when putting CMTimes in CF container types.
539    ///
540    /// Returns: A CFDictionary version of the CMTime.
541    #[doc(alias = "CMTimeCopyAsDictionary")]
542    #[inline]
543    pub unsafe fn as_dictionary(
544        self,
545        allocator: Option<&CFAllocator>,
546    ) -> Option<CFRetained<CFDictionary>> {
547        extern "C-unwind" {
548            fn CMTimeCopyAsDictionary(
549                time: CMTime,
550                allocator: Option<&CFAllocator>,
551            ) -> Option<NonNull<CFDictionary>>;
552        }
553        let ret = unsafe { CMTimeCopyAsDictionary(self, allocator) };
554        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
555    }
556
557    /// Reconstitutes a CMTime struct from a CFDictionary previously created by CMTimeCopyAsDictionary.
558    ///
559    /// This is useful when getting CMTimes from CF container types.  If the CFDictionary does not
560    /// have the requisite keyed values, an invalid time is returned.
561    ///
562    /// Returns: The created CMTime.
563    ///
564    /// # Safety
565    ///
566    /// `dictionary_representation` generics must be of the correct type.
567    #[doc(alias = "CMTimeMakeFromDictionary")]
568    #[inline]
569    pub unsafe fn from_dictionary(dictionary_representation: Option<&CFDictionary>) -> CMTime {
570        extern "C-unwind" {
571            fn CMTimeMakeFromDictionary(dictionary_representation: Option<&CFDictionary>)
572                -> CMTime;
573        }
574        unsafe { CMTimeMakeFromDictionary(dictionary_representation) }
575    }
576}
577
578extern "C" {
579    /// CFDictionary key for value field of CMTime (CFNumber containing int64_t)
580    ///
581    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremedia/kcmtimevaluekey?language=objc)
582    pub static kCMTimeValueKey: &'static CFString;
583}
584
585extern "C" {
586    /// CFDictionary key for timescale field of CMTime (CFNumber containing int32_t)
587    ///
588    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremedia/kcmtimescalekey?language=objc)
589    pub static kCMTimeScaleKey: &'static CFString;
590}
591
592extern "C" {
593    /// CFDictionary key for epoch field of CMTime (CFNumber containing int64_t)
594    ///
595    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremedia/kcmtimeepochkey?language=objc)
596    pub static kCMTimeEpochKey: &'static CFString;
597}
598
599extern "C" {
600    /// CFDictionary key for flags field of CMTime (CFNumber containing uint32_t)
601    ///
602    /// See also [Apple's documentation](https://developer.apple.com/documentation/coremedia/kcmtimeflagskey?language=objc)
603    pub static kCMTimeFlagsKey: &'static CFString;
604}
605
606impl CMTime {
607    /// Creates a CFString with a description of a CMTime (just like CFCopyDescription).
608    ///
609    /// This is used from within CFShow on an object that contains CMTime fields. It is
610    /// also useful from other client debugging code.  The caller owns the returned
611    /// CFString, and is responsible for releasing it.
612    ///
613    /// Returns: The created CFString description.
614    #[doc(alias = "CMTimeCopyDescription")]
615    #[inline]
616    pub unsafe fn description(
617        allocator: Option<&CFAllocator>,
618        time: CMTime,
619    ) -> Option<CFRetained<CFString>> {
620        extern "C-unwind" {
621            fn CMTimeCopyDescription(
622                allocator: Option<&CFAllocator>,
623                time: CMTime,
624            ) -> Option<NonNull<CFString>>;
625        }
626        let ret = unsafe { CMTimeCopyDescription(allocator, time) };
627        ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
628    }
629
630    /// Prints a description of the CMTime (just like CFShow).
631    ///
632    /// This is most useful from within gdb.
633    #[doc(alias = "CMTimeShow")]
634    #[inline]
635    pub unsafe fn show(self) {
636        extern "C-unwind" {
637            fn CMTimeShow(time: CMTime);
638        }
639        unsafe { CMTimeShow(self) }
640    }
641}
642
643extern "C-unwind" {
644    #[deprecated = "renamed to `CMTime::new`"]
645    pub fn CMTimeMake(value: i64, timescale: i32) -> CMTime;
646}
647
648extern "C-unwind" {
649    #[deprecated = "renamed to `CMTime::with_epoch`"]
650    pub fn CMTimeMakeWithEpoch(value: i64, timescale: i32, epoch: i64) -> CMTime;
651}
652
653extern "C-unwind" {
654    #[deprecated = "renamed to `CMTime::with_seconds`"]
655    pub fn CMTimeMakeWithSeconds(seconds: f64, preferred_timescale: i32) -> CMTime;
656}
657
658extern "C-unwind" {
659    #[deprecated = "renamed to `CMTime::seconds`"]
660    pub fn CMTimeGetSeconds(time: CMTime) -> f64;
661}
662
663extern "C-unwind" {
664    #[deprecated = "renamed to `CMTime::convert_scale`"]
665    pub fn CMTimeConvertScale(
666        time: CMTime,
667        new_timescale: i32,
668        method: CMTimeRoundingMethod,
669    ) -> CMTime;
670}
671
672extern "C-unwind" {
673    #[deprecated = "renamed to `CMTime::add`"]
674    pub fn CMTimeAdd(lhs: CMTime, rhs: CMTime) -> CMTime;
675}
676
677extern "C-unwind" {
678    #[deprecated = "renamed to `CMTime::subtract`"]
679    pub fn CMTimeSubtract(lhs: CMTime, rhs: CMTime) -> CMTime;
680}
681
682extern "C-unwind" {
683    #[deprecated = "renamed to `CMTime::multiply`"]
684    pub fn CMTimeMultiply(time: CMTime, multiplier: i32) -> CMTime;
685}
686
687extern "C-unwind" {
688    #[deprecated = "renamed to `CMTime::multiply_by_float64`"]
689    pub fn CMTimeMultiplyByFloat64(time: CMTime, multiplier: f64) -> CMTime;
690}
691
692extern "C-unwind" {
693    #[deprecated = "renamed to `CMTime::multiply_by_ratio`"]
694    pub fn CMTimeMultiplyByRatio(time: CMTime, multiplier: i32, divisor: i32) -> CMTime;
695}
696
697extern "C-unwind" {
698    #[deprecated = "renamed to `CMTime::compare`"]
699    pub fn CMTimeCompare(time1: CMTime, time2: CMTime) -> i32;
700}
701
702extern "C-unwind" {
703    #[deprecated = "renamed to `CMTime::minimum`"]
704    pub fn CMTimeMinimum(time1: CMTime, time2: CMTime) -> CMTime;
705}
706
707extern "C-unwind" {
708    #[deprecated = "renamed to `CMTime::maximum`"]
709    pub fn CMTimeMaximum(time1: CMTime, time2: CMTime) -> CMTime;
710}
711
712extern "C-unwind" {
713    #[deprecated = "renamed to `CMTime::absolute_value`"]
714    pub fn CMTimeAbsoluteValue(time: CMTime) -> CMTime;
715}
716
717#[deprecated = "renamed to `CMTime::as_dictionary`"]
718#[inline]
719pub unsafe extern "C-unwind" fn CMTimeCopyAsDictionary(
720    time: CMTime,
721    allocator: Option<&CFAllocator>,
722) -> Option<CFRetained<CFDictionary>> {
723    extern "C-unwind" {
724        fn CMTimeCopyAsDictionary(
725            time: CMTime,
726            allocator: Option<&CFAllocator>,
727        ) -> Option<NonNull<CFDictionary>>;
728    }
729    let ret = unsafe { CMTimeCopyAsDictionary(time, allocator) };
730    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
731}
732
733extern "C-unwind" {
734    #[deprecated = "renamed to `CMTime::from_dictionary`"]
735    pub fn CMTimeMakeFromDictionary(dictionary_representation: Option<&CFDictionary>) -> CMTime;
736}
737
738#[deprecated = "renamed to `CMTime::description`"]
739#[inline]
740pub unsafe extern "C-unwind" fn CMTimeCopyDescription(
741    allocator: Option<&CFAllocator>,
742    time: CMTime,
743) -> Option<CFRetained<CFString>> {
744    extern "C-unwind" {
745        fn CMTimeCopyDescription(
746            allocator: Option<&CFAllocator>,
747            time: CMTime,
748        ) -> Option<NonNull<CFString>>;
749    }
750    let ret = unsafe { CMTimeCopyDescription(allocator, time) };
751    ret.map(|ret| unsafe { CFRetained::from_raw(ret) })
752}
753
754extern "C-unwind" {
755    #[deprecated = "renamed to `CMTime::show`"]
756    pub fn CMTimeShow(time: CMTime);
757}