objc2-av-foundation 0.3.2

Bindings to the AVFoundation framework
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
//! This file has been automatically generated by `objc2`'s `header-translator`.
//! DO NOT EDIT
use core::ffi::*;
use core::ptr::NonNull;
#[cfg(feature = "dispatch2")]
use dispatch2::*;
use objc2::__framework_prelude::*;
#[cfg(feature = "objc2-core-media")]
use objc2_core_media::*;
use objc2_foundation::*;

use crate::*;

/// These constants specify the type of segment
///
/// Indicates segment represent playback of a primary item.
///
/// Indicates segment represents playback of an interstitial event.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avplayeritemsegmenttype?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct AVPlayerItemSegmentType(pub NSInteger);
impl AVPlayerItemSegmentType {
    #[doc(alias = "AVPlayerItemSegmentTypePrimary")]
    pub const Primary: Self = Self(0);
    #[doc(alias = "AVPlayerItemSegmentTypeInterstitial")]
    pub const Interstitial: Self = Self(1);
}

unsafe impl Encode for AVPlayerItemSegmentType {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for AVPlayerItemSegmentType {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_class!(
    /// Representing a segment of time on the integrated timeline. Segments are immutable objects.
    ///
    /// Subclasses of this type that are used from Swift must fulfill the requirements of a Sendable type.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avplayeritemsegment?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct AVPlayerItemSegment;
);

unsafe impl Send for AVPlayerItemSegment {}

unsafe impl Sync for AVPlayerItemSegment {}

extern_conformance!(
    unsafe impl NSObjectProtocol for AVPlayerItemSegment {}
);

impl AVPlayerItemSegment {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;

        /// The type of content this segment represents.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(segmentType))]
        #[unsafe(method_family = none)]
        pub unsafe fn segmentType(&self) -> AVPlayerItemSegmentType;

        #[cfg(feature = "objc2-core-media")]
        /// The timeMapping for this segment.
        ///
        /// The timeMapping source timeRange represents the start and duration in the segment source's timeline (ie: primary item timeline or interstitial event). The target timeRange represents the start point and duration in the integrated timeline. For interstitial events which occupy a single point, the target's duration will be kCMTimeZero.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(timeMapping))]
        #[unsafe(method_family = none)]
        pub unsafe fn timeMapping(&self) -> CMTimeMapping;

        /// This property provides a collection of time ranges for the segment if media data is readily available. The ranges provided might be discontinuous.
        ///
        /// Returns an NSArray of NSValues containing CMTimeRanges. Loaded time ranges will be within the timeMapping's target timeRange. Loaded time ranges will be empty for interstitial events that occupy a single point in time.
        #[unsafe(method(loadedTimeRanges))]
        #[unsafe(method_family = none)]
        pub unsafe fn loadedTimeRanges(&self) -> Retained<NSArray<NSValue>>;

        /// The date this segment starts at.
        ///
        /// The date this segment starts at. This value will be nil if the primary item does not contain dates.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(startDate))]
        #[unsafe(method_family = none)]
        pub unsafe fn startDate(&self) -> Option<Retained<NSDate>>;

        #[cfg(feature = "AVPlayerInterstitialEventController")]
        /// The associated interstitial event for this segment.
        ///
        /// The associated interstitial event for this segment. This value will be nil for segments representing playback of the primary itme.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(interstitialEvent))]
        #[unsafe(method_family = none)]
        pub unsafe fn interstitialEvent(&self) -> Option<Retained<AVPlayerInterstitialEvent>>;
    );
}

extern_class!(
    /// AVPlayerItemIntegratedTimelineSnapshot provides an immutable representation of inspectable details from an AVPlayerItemIntegratedTimeline.
    ///
    /// An instance of AVPlayerItemIntegratedTimelineSnapshot is an immutable snapshot representation of inspectable details from an AVPlayerItemIntegratedTimeline. As playback progresses,
    /// AVPlayerItemIntegratedTimelineSnapshot will not reflect the new timeline state. One can request a new snapshot instance from an AVPlayerItemIntegratedTimeline to reflect the latest timeline state.
    /// Subclasses of this type that are used from Swift must fulfill the requirements of a Sendable type.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avplayeritemintegratedtimelinesnapshot?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct AVPlayerItemIntegratedTimelineSnapshot;
);

unsafe impl Send for AVPlayerItemIntegratedTimelineSnapshot {}

unsafe impl Sync for AVPlayerItemIntegratedTimelineSnapshot {}

extern_conformance!(
    unsafe impl NSObjectProtocol for AVPlayerItemIntegratedTimelineSnapshot {}
);

impl AVPlayerItemIntegratedTimelineSnapshot {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;

        #[cfg(feature = "objc2-core-media")]
        /// Returns the duration totaling the primary item and scheduled interstitial events.
        ///
        /// This property returns the duration totaling the primary item and scheduled interstitial events and taking into account the interstitial event's playoutLimit and resumption offset.
        /// Before loading the duration of the primary item, the value of this property is kCMTimeInvalid. For livestreams, this value will be kCMTimeIndefinite.
        ///
        /// This property is not atomic.
        ///
        /// # Safety
        ///
        /// This might not be thread-safe.
        #[unsafe(method(duration))]
        #[unsafe(method_family = none)]
        pub unsafe fn duration(&self) -> CMTime;

        /// Returns the current AVPlayerItemSegment playback is traversing.
        #[unsafe(method(currentSegment))]
        #[unsafe(method_family = none)]
        pub unsafe fn currentSegment(&self) -> Option<Retained<AVPlayerItemSegment>>;

        /// Returns an array of AVPlayerItemSegment for the snapshot.
        ///
        /// Returns an array of AVPlayerItemSegment. The segments are presented in chronological order, contiguous from the previous element, and non-overlapping.
        #[unsafe(method(segments))]
        #[unsafe(method_family = none)]
        pub unsafe fn segments(&self) -> Retained<NSArray<AVPlayerItemSegment>>;

        #[cfg(feature = "objc2-core-media")]
        /// Returns the current time on the integrated timeline when the snapshot was taken.
        ///
        /// Returns the current time on the integrated timeline when the snapshot was taken. CurrentTime will not change as playback progresses.
        #[unsafe(method(currentTime))]
        #[unsafe(method_family = none)]
        pub unsafe fn currentTime(&self) -> CMTime;

        /// Returns the  current date when the snapshot was taken, or nil if playback is not mapped to any date.
        #[unsafe(method(currentDate))]
        #[unsafe(method_family = none)]
        pub unsafe fn currentDate(&self) -> Option<Retained<NSDate>>;

        #[cfg(feature = "objc2-core-media")]
        /// Provides mapping from time to AVPlayerItemSegment and offset in segment.
        ///
        /// Parameter `time`: Time represented in the integrated time domain.
        ///
        /// Parameter `timeSegmentOut`: Output parameter for segment.
        ///
        /// Parameter `segmentOffsetOut`: Output parameter for offset in segment.
        ///
        /// Provides mapping from time to segment and offset in the segment's timeMapping target. For time that correlates to the start of multiple segments, this will return the first one.
        ///
        /// # Safety
        ///
        /// `segment_offset_out` must be a valid pointer.
        #[unsafe(method(mapTime:toSegment:atSegmentOffset:))]
        #[unsafe(method_family = none)]
        pub unsafe fn mapTime_toSegment_atSegmentOffset(
            &self,
            time: CMTime,
            time_segment_out: Option<&mut Retained<AVPlayerItemSegment>>,
            segment_offset_out: NonNull<CMTime>,
        );
    );
}

extern_class!(
    /// An AVPlayerItemIntegratedTimeline provides detailed timing information and control for the sequence of playback of a primary AVPlayerItem and scheduled AVPlayerInterstitialEvents.
    ///
    /// An object that models the timeline and sequence of playback of primary AVPlayerItem and scheduled AVPlayerInterstitialEvents. The timeline models all regions expected to be traversed during playback. Notably portions of the primary item may not be presented when exiting an interstitial event with a positive resumption offset.
    /// Subclasses of this type that are used from Swift must fulfill the requirements of a Sendable type.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avplayeritemintegratedtimeline?language=objc)
    #[unsafe(super(NSObject))]
    #[derive(Debug, PartialEq, Eq, Hash)]
    pub struct AVPlayerItemIntegratedTimeline;
);

unsafe impl Send for AVPlayerItemIntegratedTimeline {}

unsafe impl Sync for AVPlayerItemIntegratedTimeline {}

extern_conformance!(
    unsafe impl NSObjectProtocol for AVPlayerItemIntegratedTimeline {}
);

impl AVPlayerItemIntegratedTimeline {
    extern_methods!(
        #[unsafe(method(init))]
        #[unsafe(method_family = init)]
        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;

        #[unsafe(method(new))]
        #[unsafe(method_family = new)]
        pub unsafe fn new() -> Retained<Self>;

        /// This property provides an immutable representation of the timeline state at time of request.
        ///
        /// Returns an immutable representation of the timeline state at time of request. A timeline snapshot provides accessors for obtaining inspectable details of the timeline.  Because a snapshot is immutable, the snapshot's properties will not update as playback continues.
        #[unsafe(method(currentSnapshot))]
        #[unsafe(method_family = none)]
        pub unsafe fn currentSnapshot(&self) -> Retained<AVPlayerItemIntegratedTimelineSnapshot>;

        #[cfg(feature = "objc2-core-media")]
        /// Returns the current time on the integrated timeline.
        ///
        /// Returns the current time on the integrated timeline. During playback of interstitial events that occupy a single point, currentTime will not change.
        #[unsafe(method(currentTime))]
        #[unsafe(method_family = none)]
        pub unsafe fn currentTime(&self) -> CMTime;

        /// Returns the date of current playback, or nil if playback is not mapped to any date.
        #[unsafe(method(currentDate))]
        #[unsafe(method_family = none)]
        pub unsafe fn currentDate(&self) -> Option<Retained<NSDate>>;
    );
}

/// AVPlayerItemIntegratedTimelineControl.
impl AVPlayerItemIntegratedTimeline {
    extern_methods!(
        #[cfg(all(feature = "block2", feature = "objc2-core-media"))]
        /// Seeks to a particular time in the integrated time domain and invokes the completionHandler
        ///
        /// Parameter `time`: Time represented in the integrated time domain.
        ///
        /// Parameter `toleranceBefore`: Tolerance before target time allowed to seek to.
        ///
        /// Parameter `toleranceAfter`: Tolerance after target time allowed to seek to.
        ///
        /// Parameter `completionHandler`: CompletionHandler callback after seek completes. Success will be true if the playhead moved to the new time.
        ///
        /// The integrated timeline seeks to the the range of [time-beforeTolerance, time+afterTolerance] will be attributed to a segment and AVPlayerItem that falls in that range. You can request sample accurate seeking by passing a time value of kCMTimeZero for both toleranceBefore and toleranceAfter.
        ///
        /// # Safety
        ///
        /// `completion_handler` block must be sendable.
        #[unsafe(method(seekToTime:toleranceBefore:toleranceAfter:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn seekToTime_toleranceBefore_toleranceAfter_completionHandler(
            &self,
            time: CMTime,
            tolerance_before: CMTime,
            tolerance_after: CMTime,
            completion_handler: Option<&block2::DynBlock<dyn Fn(Bool)>>,
        );

        #[cfg(feature = "block2")]
        /// Seeks playhead to corresponding date and invokes the completionHandler.
        ///
        /// Parameter `date`: The new position for the playhead.
        ///
        /// Parameter `completionHandler`: CompletionHandler callback after seek completes. Success will be true if the playhead moved to the new date.
        ///
        /// The integrated timeline will seek playhead to the coresponding date.
        ///
        /// # Safety
        ///
        /// `completion_handler` block must be sendable.
        #[unsafe(method(seekToDate:completionHandler:))]
        #[unsafe(method_family = none)]
        pub unsafe fn seekToDate_completionHandler(
            &self,
            date: &NSDate,
            completion_handler: Option<&block2::DynBlock<dyn Fn(Bool)>>,
        );
    );
}

extern_protocol!(
    /// Defines protocol for objects returned from timeline observer routines.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avplayeritemintegratedtimelineobserver?language=objc)
    pub unsafe trait AVPlayerItemIntegratedTimelineObserver: NSObjectProtocol {}
);

/// AVPlayerItemIntegratedTimelineObserver.
impl AVPlayerItemIntegratedTimeline {
    extern_methods!(
        #[cfg(all(
            feature = "block2",
            feature = "dispatch2",
            feature = "objc2-core-media"
        ))]
        /// Requests invocation of a block during playback to report changing time.
        ///
        /// Parameter `interval`: The interval of invocation of the block during normal playback, according to progress of the current time in the integrated timeline.
        ///
        /// Parameter `queue`: The serial queue onto which block should be enqueued. If you pass NULL, the main queue (obtained using dispatch_get_main_queue()) will be used. Passing a concurrent queue to this method will result in undefined behavior.
        ///
        /// Parameter `block`: The block to be invoked periodically.
        ///
        /// Returns: An object conforming to the AVPlayerItemIntegratedTimelineObserver protocol. You must retain this returned value as long as you want the time observer to be invoked by the timeline. The block is invoked periodically at the interval specified, interpreted according to the integrated timeline. The block is also invoked across AVPlayerItemSegment and AVPlayerItem boundaries, whenever time jumps, and whenever playback starts or stops. Each call to -addPeriodicTimeObserverForInterval:queue:usingBlock: should be paired with a corresponding call to -removeTimeObserver:. Releasing the observer object without a call to -removeTimeObserver: will result in undefined behavior
        ///
        /// # Safety
        ///
        /// - `queue` possibly has additional threading requirements.
        /// - `block` block must be sendable.
        #[unsafe(method(addPeriodicTimeObserverForInterval:queue:usingBlock:))]
        #[unsafe(method_family = none)]
        pub unsafe fn addPeriodicTimeObserverForInterval_queue_usingBlock(
            &self,
            interval: CMTime,
            queue: Option<&DispatchQueue>,
            block: &block2::DynBlock<dyn Fn(CMTime)>,
        ) -> Retained<ProtocolObject<dyn AVPlayerItemIntegratedTimelineObserver>>;

        #[cfg(all(feature = "block2", feature = "dispatch2"))]
        /// Requests invocation of a block when an offset in a segment is traversed during playback.
        ///
        /// Parameter `segment`: AVPlayerItemSegment to monitor playback traversal of.
        ///
        /// Parameter `offsetsIntoSegment`: Offsets in the segment for which the observer requests notification, supplied as an array of NSValues carrying CMTimes.
        ///
        /// Parameter `queue`: The serial queue onto which block should be enqueued. If you pass NULL, the main queue (obtained using dispatch_get_main_queue()) will be used. Passing a concurrent queue to this method will result in undefined behavior.
        ///
        /// Parameter `block`: The block to be invoked when the offset is crossed during playback of a segment.
        ///
        /// Returns: An object conforming to the AVPlayerItemIntegratedTimelineObserver protocol. You must retain this returned value as long as you want the time observer to be invoked by the timeline. Pass this object to -removeTimeObserver: to cancel time observation. One can also configure single point segments with segmentTimes to trigger during traversal of the segment's playback. As the timeline duration and segments change, the installed time observer will be automatically adjusted to fire at the desired offset in the segment. A segment that is removed from the timeline will trigger the invocation of the block immediately with success set as false.
        /// Each call to -addBoundaryTimeObserverForSegment:segment:offsetsInSegment:queue:usingBlock: should be paired with a corresponding call to -removeTimeObserver:. Releasing the observer object without a call to -removeTimeObserver: will result in undefined behavior
        ///
        /// # Safety
        ///
        /// - `offsets_into_segment` generic should be of the correct type.
        /// - `queue` possibly has additional threading requirements.
        /// - `block` block must be sendable.
        #[unsafe(method(addBoundaryTimeObserverForSegment:offsetsIntoSegment:queue:usingBlock:))]
        #[unsafe(method_family = none)]
        pub unsafe fn addBoundaryTimeObserverForSegment_offsetsIntoSegment_queue_usingBlock(
            &self,
            segment: &AVPlayerItemSegment,
            offsets_into_segment: &NSArray,
            queue: Option<&DispatchQueue>,
            block: &block2::DynBlock<dyn Fn(Bool)>,
        ) -> Retained<ProtocolObject<dyn AVPlayerItemIntegratedTimelineObserver>>;

        /// Cancels a previously registered time observer.
        ///
        /// Parameter `observer`: An object returned by a previous call to -addPeriodicTimeObserverForInterval or -addBoundaryTimeObserverForSegment.
        #[unsafe(method(removeTimeObserver:))]
        #[unsafe(method_family = none)]
        pub unsafe fn removeTimeObserver(
            &self,
            observer: &ProtocolObject<dyn AVPlayerItemIntegratedTimelineObserver>,
        );
    );
}

extern "C" {
    /// A notification which is posted when the snapshot objects provided by this timeline would be out of sync with the current timeline state. See keys below.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avplayerintegratedtimelinesnapshotsoutofsyncnotification?language=objc)
    pub static AVPlayerIntegratedTimelineSnapshotsOutOfSyncNotification:
        &'static NSNotificationName;
}

extern "C" {
    /// Indicates the reason for the snapshot out of sync notification.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avplayerintegratedtimelinesnapshotsoutofsyncreasonkey?language=objc)
    pub static AVPlayerIntegratedTimelineSnapshotsOutOfSyncReasonKey: &'static NSString;
}

/// [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avplayerintegratedtimelinesnapshotsoutofsyncreason?language=objc)
// NS_TYPED_ENUM
pub type AVPlayerIntegratedTimelineSnapshotsOutOfSyncReason = NSString;

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avplayerintegratedtimelinesnapshotsoutofsyncreasonsegmentschanged?language=objc)
    pub static AVPlayerIntegratedTimelineSnapshotsOutOfSyncReasonSegmentsChanged:
        &'static AVPlayerIntegratedTimelineSnapshotsOutOfSyncReason;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avplayerintegratedtimelinesnapshotsoutofsyncreasoncurrentsegmentchanged?language=objc)
    pub static AVPlayerIntegratedTimelineSnapshotsOutOfSyncReasonCurrentSegmentChanged:
        &'static AVPlayerIntegratedTimelineSnapshotsOutOfSyncReason;
}

extern "C" {
    /// [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avplayerintegratedtimelinesnapshotsoutofsyncreasonloadedtimerangeschanged?language=objc)
    pub static AVPlayerIntegratedTimelineSnapshotsOutOfSyncReasonLoadedTimeRangesChanged:
        &'static AVPlayerIntegratedTimelineSnapshotsOutOfSyncReason;
}

/// AVPlayerItemIntegratedTimelineSupport.
#[cfg(feature = "AVPlayerItem")]
impl AVPlayerItem {
    extern_methods!(
        /// Obtain an instance of AVPlayerItemIntegratedTimeline representing the timing and control of playback of the item with its scheduled AVPlayerInterstitialEvents. This value will return nil for AVPlayerItems in an interstitial player.
        #[unsafe(method(integratedTimeline))]
        #[unsafe(method_family = none)]
        pub unsafe fn integratedTimeline(&self) -> Retained<AVPlayerItemIntegratedTimeline>;
    );
}