objc2_av_foundation/generated/
AVSampleBufferRenderSynchronizer.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-core-media")]
7use objc2_core_media::*;
8use objc2_foundation::*;
9
10use crate::*;
11
12extern "C" {
13    /// A notification that fires whenever the value of the "rate" property changes.
14    ///
15    /// The rate can change as a result of setting the rate property, either by directly setting the property or calling -setRate:time:.  The rate can also change at any time, without any action by the client of the render synchronizer.  For example, on iOS if the app's playback is interrupted (e.g. by a phone call or another non-mixable app starting playback), the rate will automatically be set to zero.  This notification will be sent in all of those cases.
16    ///
17    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avsamplebufferrendersynchronizerratedidchangenotification?language=objc)
18    pub static AVSampleBufferRenderSynchronizerRateDidChangeNotification:
19        &'static NSNotificationName;
20}
21
22extern_class!(
23    /// AVSampleBufferRenderSynchronizer can synchronize multiple objects conforming to AVQueuedSampleBufferRendering to a single timebase.
24    ///
25    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avsamplebufferrendersynchronizer?language=objc)
26    #[unsafe(super(NSObject))]
27    #[derive(Debug, PartialEq, Eq, Hash)]
28    pub struct AVSampleBufferRenderSynchronizer;
29);
30
31unsafe impl NSObjectProtocol for AVSampleBufferRenderSynchronizer {}
32
33impl AVSampleBufferRenderSynchronizer {
34    extern_methods!(
35        #[cfg(feature = "objc2-core-media")]
36        /// The synchronizer's rendering timebase, which governs how time stamps are interpreted.
37        ///
38        /// By default, this timebase will be driven by the clock of an added AVSampleBufferAudioRenderer.
39        ///
40        /// If no AVSampleBufferAudioRenderer has been added, the source clock will be the host time clock (mach_absolute_time with the appropriate timescale conversion; this is the same as Core Animation's CACurrentMediaTime).
41        ///
42        /// The timebase is a read-only timebase.  Use the rate property and corresponding methods to adjust the timebase.
43        #[unsafe(method(timebase))]
44        #[unsafe(method_family = none)]
45        pub unsafe fn timebase(&self) -> Retained<CMTimebase>;
46
47        /// Playback rate.
48        ///
49        /// Indicates the current rate of rendering.  A value of 0.0 means "stopped"; a value of 1.0 means "play at the natural rate of the media".  Must be greater than or equal to 0.0.
50        #[unsafe(method(rate))]
51        #[unsafe(method_family = none)]
52        pub unsafe fn rate(&self) -> c_float;
53
54        /// Setter for [`rate`][Self::rate].
55        #[unsafe(method(setRate:))]
56        #[unsafe(method_family = none)]
57        pub unsafe fn setRate(&self, rate: c_float);
58
59        #[cfg(feature = "objc2-core-media")]
60        /// Returns the current time of the synchronizer.
61        ///
62        /// Returns: A CMTime
63        ///
64        /// Returns the current time of the synchronizer. Not key-value observable; use -addPeriodicTimeObserverForInterval:queue:usingBlock: instead.
65        #[unsafe(method(currentTime))]
66        #[unsafe(method_family = none)]
67        pub unsafe fn currentTime(&self) -> CMTime;
68
69        #[cfg(feature = "objc2-core-media")]
70        /// Sets the timebase's time and rate.
71        ///
72        /// Parameter `rate`: A new timebase rate to set.  Must be greater than or equal to 0.0
73        ///
74        /// Parameter `time`: A new time to set.  Must be greater than or equal to kCMTimeZero, or kCMTimeInvalid
75        ///
76        /// Sets the timebase's time to time and then sets the rendering rate to rate.  A rate value of 0.0 means "stopped"; a rate value of 1.0 means "play at the natural rate of the media".  Use kCMTimeInvalid for time to not modify the timebase's time.
77        /// Note that this method updates the rate property synchronously, but the timebase is updated asynchronously.
78        #[unsafe(method(setRate:time:))]
79        #[unsafe(method_family = none)]
80        pub unsafe fn setRate_time(&self, rate: c_float, time: CMTime);
81
82        #[cfg(feature = "objc2-core-media")]
83        /// Simultaneously sets the playback rate and the relationship between the current time and host time.
84        ///
85        /// Parameter `rate`: A new timebase rate to set.  Must be greater than or equal to 0.0
86        ///
87        /// Parameter `time`: A new timebase time to set.  Must be greater than or equal to kCMTimeZero, or kCMTimeInvalid
88        ///
89        /// Parameter `hostTime`: A new hostTime to set.  Must be greater than or equal to kCMTimeZero, or kCMTimeInvalid
90        ///
91        /// You can use this function to synchronize playback with an external activity.
92        ///
93        /// The timebase is adjusted so that its time will be (or was) time when host time is (or was) hostTime.
94        /// In other words: if hostTime is in the past, the timebase's time will be interpolated as though the timebase has been running at the requested rate since that time.  If hostTime is in the future, the timebase will immediately start running at the requested rate from an earlier time so that it will reach the requested time at the requested hostTime.
95        /// It is a responsibility of the client to ensure that proper time and hostTime is set.  This method will not attempt to validate improper time, hostTime values.
96        /// In addition, it is also the caller’s responsibility to enqueue samples in the connected renderers that match the timeline defined here.
97        /// Note that any buffers that are in the past of the defined timeline will still be processed by the renderers.
98        ///
99        /// The recommended approach is to use the output presentation time of the first buffer enqueued in the renderers as time and and an associated hostTime in the future.
100        /// Example use:
101        /// CMTime startTime = …;
102        /// __block CMTime nextBufferTime = startTime;
103        /// [renderer requestMediaDataWhenReadyOnQueue:queue usingBlock:^{
104        /// …
105        /// CMSampleBufferRef sampleBuffer = [self generateSampleBufferFor: nextBufferTime];
106        /// [renderer enqueueSampleBuffer:sampleBuffer];
107        /// ...
108        /// }];
109        /// CMTime inOneSecond = CMTimeAdd(CMClockGetTime(CMClockGetHostTimeClock()), CMTimeMake(1, 1));
110        /// [synchronizer setRate:rate time:startTime atHostTime:inOneSecond];
111        ///
112        /// Also note that this method updates the rate property synchronously, but the timebase is updated asynchronously.
113        #[unsafe(method(setRate:time:atHostTime:))]
114        #[unsafe(method_family = none)]
115        pub unsafe fn setRate_time_atHostTime(
116            &self,
117            rate: c_float,
118            time: CMTime,
119            host_time: CMTime,
120        );
121
122        /// Indicates whether the playback should be started immediately on rate change request.
123        ///
124        /// If set to YES, playback will be delayed if the value of hasSufficientMediaDataForReliablePlaybackStart of any added renderer is NO. If set to NO, playback will attempt to start immediately regardless of the value of hasSufficientMediaDataForReliablePlaybackStart of added renderers. Default is YES.
125        #[unsafe(method(delaysRateChangeUntilHasSufficientMediaData))]
126        #[unsafe(method_family = none)]
127        pub unsafe fn delaysRateChangeUntilHasSufficientMediaData(&self) -> bool;
128
129        /// Setter for [`delaysRateChangeUntilHasSufficientMediaData`][Self::delaysRateChangeUntilHasSufficientMediaData].
130        #[unsafe(method(setDelaysRateChangeUntilHasSufficientMediaData:))]
131        #[unsafe(method_family = none)]
132        pub unsafe fn setDelaysRateChangeUntilHasSufficientMediaData(
133            &self,
134            delays_rate_change_until_has_sufficient_media_data: bool,
135        );
136    );
137}
138
139/// Methods declared on superclass `NSObject`.
140impl AVSampleBufferRenderSynchronizer {
141    extern_methods!(
142        #[unsafe(method(init))]
143        #[unsafe(method_family = init)]
144        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
145
146        #[unsafe(method(new))]
147        #[unsafe(method_family = new)]
148        pub unsafe fn new() -> Retained<Self>;
149    );
150}
151
152/// AVSampleBufferRenderSynchronizerRendererManagement.
153impl AVSampleBufferRenderSynchronizer {
154    extern_methods!(
155        #[cfg(feature = "AVQueuedSampleBufferRendering")]
156        /// Array of id
157        /// <AVQueuedSampleBufferRendering
158        /// > currently attached to the synchronizer.
159        ///
160        /// A list of renderers added to and not removed from the synchronizer.  The list also includes renderers that have been scheduled to be removed but have not yet been removed.
161        ///
162        /// This property is not KVO observable.
163        #[unsafe(method(renderers))]
164        #[unsafe(method_family = none)]
165        pub unsafe fn renderers(
166            &self,
167        ) -> Retained<NSArray<ProtocolObject<dyn AVQueuedSampleBufferRendering>>>;
168
169        #[cfg(feature = "AVQueuedSampleBufferRendering")]
170        /// Adds a renderer to the list of renderers under the synchronizer's control.
171        ///
172        /// Parameter `renderer`: An object conforming to AVQueuedSampleBufferRendering to be synchronized by this synchronizer.
173        ///
174        /// Adds a renderer to begin operating with the synchronizer's timebase.
175        ///
176        /// This method can be called while rate is non-0.0.
177        #[unsafe(method(addRenderer:))]
178        #[unsafe(method_family = none)]
179        pub unsafe fn addRenderer(
180            &self,
181            renderer: &ProtocolObject<dyn AVQueuedSampleBufferRendering>,
182        );
183
184        #[cfg(all(
185            feature = "AVQueuedSampleBufferRendering",
186            feature = "block2",
187            feature = "objc2-core-media"
188        ))]
189        /// Removes a renderer from the list of renderers under the synchronizer's control.
190        ///
191        /// Parameter `renderer`: An object conforming to AVQueuedSampleBufferRendering currently synchronized by this synchronizer to no longer be synchronized by the synchronizer.
192        ///
193        /// Parameter `time`: The time on the timebase's timeline at which the renderer should be removed.
194        ///
195        /// Parameter `completionHandler`: Optional.  A block called when the renderer is removed from the synchronizer.  If provided, this block will always be called with didRemoveRenderer indicating whether the renderer was removed by this scheduled removal.
196        ///
197        /// This method can be called while rate is non-0.0.
198        ///
199        /// time is used to schedule future removals.  If the time is in the past, the renderer will be removed immediately.  kCMTimeInvalid can also be used to force immediate removal.
200        ///
201        /// This method removes the renderer asynchronously.  The method can be called more than once, with a subsequent scheduled removal replacing a previously scheduled removal.
202        ///
203        /// Clients may provide an optional completionHandler block to be notified when the scheduled removal completes.  If provided, completionHandler will always be called with the following values for didRemoveRenderer:
204        ///
205        /// - If the renderer has not been added to this synchronizer, completionHandler will be called and didRemoveRenderer will be NO.
206        /// - If a removal of a particular renderer is scheduled after another removal of that same renderer has already been scheduled but not yet occurred, the previously-scheduled removal's completionHandler will be called and didRemoveRenderer will be NO.  The new scheduled removal's completionHandler will not be called until it is replaced by another scheduled removal or the renderer is actually removed.
207        /// - When the renderer is removed due to a scheduled removal, the completionHandler provided when that removal was scheduled will be called and didRemoveRenderer will be YES.
208        #[unsafe(method(removeRenderer:atTime:completionHandler:))]
209        #[unsafe(method_family = none)]
210        pub unsafe fn removeRenderer_atTime_completionHandler(
211            &self,
212            renderer: &ProtocolObject<dyn AVQueuedSampleBufferRendering>,
213            time: CMTime,
214            completion_handler: Option<&block2::Block<dyn Fn(Bool)>>,
215        );
216    );
217}
218
219/// AVSampleBufferRenderSynchronizerTimeObservation.
220impl AVSampleBufferRenderSynchronizer {
221    extern_methods!(
222        /// Cancels a previously registered time observer.
223        ///
224        /// Parameter `observer`: An object returned by a previous call to -addPeriodicTimeObserverForInterval:queue:usingBlock: or -addBoundaryTimeObserverForTimes:queue:usingBlock:.
225        ///
226        /// Upon return, the caller is guaranteed that no new time observer blocks will begin executing.  Depending on the calling thread and the queue used to add the time observer, an in-flight block may continue to execute after this method returns.  You can guarantee synchronous time observer removal by enqueuing the call to -removeTimeObserver: on that queue.  Alternatively, call dispatch_sync(queue, ^{}) after -removeTimeObserver: to wait for any in-flight blocks to finish executing.  -removeTimeObserver: should be used to explicitly cancel each time observer added using -addPeriodicTimeObserverForInterval:queue:usingBlock: and -addBoundaryTimeObserverForTimes:queue:usingBlock:.
227        ///
228        /// This method throws an exception for any of the following reasons:
229        /// - observer was added by another AVSampleBufferRenderSynchronizer
230        /// - observer was not returned by either
231        /// -addPeriodicTimeObserverForInterval:queue:usingBlock:
232        /// -addBoundaryTimeObserverForTimes:queue:usingBlock:
233        #[unsafe(method(removeTimeObserver:))]
234        #[unsafe(method_family = none)]
235        pub unsafe fn removeTimeObserver(&self, observer: &AnyObject);
236    );
237}