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;
5#[cfg(feature = "dispatch2")]
6use dispatch2::*;
7use objc2::__framework_prelude::*;
8#[cfg(feature = "objc2-core-media")]
9use objc2_core_media::*;
10use objc2_foundation::*;
11
12use crate::*;
13
14extern "C" {
15 /// A notification that fires whenever the value of the "rate" property changes.
16 ///
17 /// 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.
18 ///
19 /// See also [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avsamplebufferrendersynchronizerratedidchangenotification?language=objc)
20 pub static AVSampleBufferRenderSynchronizerRateDidChangeNotification:
21 &'static NSNotificationName;
22}
23
24extern_class!(
25 /// AVSampleBufferRenderSynchronizer can synchronize multiple objects conforming to AVQueuedSampleBufferRendering to a single timebase.
26 ///
27 /// See also [Apple's documentation](https://developer.apple.com/documentation/avfoundation/avsamplebufferrendersynchronizer?language=objc)
28 #[unsafe(super(NSObject))]
29 #[derive(Debug, PartialEq, Eq, Hash)]
30 pub struct AVSampleBufferRenderSynchronizer;
31);
32
33extern_conformance!(
34 unsafe impl NSObjectProtocol for AVSampleBufferRenderSynchronizer {}
35);
36
37impl AVSampleBufferRenderSynchronizer {
38 extern_methods!(
39 #[cfg(feature = "objc2-core-media")]
40 /// The synchronizer's rendering timebase, which governs how time stamps are interpreted.
41 ///
42 /// By default, this timebase will be driven by the clock of an added AVSampleBufferAudioRenderer.
43 ///
44 /// 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).
45 ///
46 /// The timebase is a read-only timebase. Use the rate property and corresponding methods to adjust the timebase.
47 #[unsafe(method(timebase))]
48 #[unsafe(method_family = none)]
49 pub unsafe fn timebase(&self) -> Retained<CMTimebase>;
50
51 /// Playback rate.
52 ///
53 /// 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.
54 #[unsafe(method(rate))]
55 #[unsafe(method_family = none)]
56 pub unsafe fn rate(&self) -> c_float;
57
58 /// Setter for [`rate`][Self::rate].
59 #[unsafe(method(setRate:))]
60 #[unsafe(method_family = none)]
61 pub unsafe fn setRate(&self, rate: c_float);
62
63 #[cfg(feature = "objc2-core-media")]
64 /// Returns the current time of the synchronizer.
65 ///
66 /// Returns the current time of the synchronizer. Not key-value observable; use -addPeriodicTimeObserverForInterval:queue:usingBlock: instead.
67 ///
68 /// - Returns: A CMTime
69 #[unsafe(method(currentTime))]
70 #[unsafe(method_family = none)]
71 pub unsafe fn currentTime(&self) -> CMTime;
72
73 #[cfg(feature = "objc2-core-media")]
74 /// Sets the timebase's time and rate.
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 ///
79 /// - Parameter rate: A new timebase rate to set. Must be greater than or equal to 0.0
80 /// - Parameter time: A new time to set. Must be greater than or equal to kCMTimeZero, or kCMTimeInvalid
81 #[unsafe(method(setRate:time:))]
82 #[unsafe(method_family = none)]
83 pub unsafe fn setRate_time(&self, rate: c_float, time: CMTime);
84
85 #[cfg(feature = "objc2-core-media")]
86 /// Simultaneously sets the playback rate and the relationship between the current time and host time.
87 ///
88 /// You can use this function to synchronize playback with an external activity.
89 ///
90 /// The timebase is adjusted so that its time will be (or was) time when host time is (or was) hostTime.
91 /// 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.
92 /// 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.
93 /// In addition, it is also the caller’s responsibility to enqueue samples in the connected renderers that match the timeline defined here.
94 /// Note that any buffers that are in the past of the defined timeline will still be processed by the renderers.
95 ///
96 /// 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.
97 /// Example use:
98 /// ```objc
99 /// CMTime startTime = …;
100 /// __block CMTime nextBufferTime = startTime;
101 /// [renderer requestMediaDataWhenReadyOnQueue:queue usingBlock:^{
102 /// …
103 /// CMSampleBufferRef sampleBuffer = [self generateSampleBufferFor: nextBufferTime];
104 /// [renderer enqueueSampleBuffer:sampleBuffer];
105 /// ...
106 /// }];
107 /// CMTime inOneSecond = CMTimeAdd(CMClockGetTime(CMClockGetHostTimeClock()), CMTimeMake(1, 1));
108 /// [synchronizer setRate:rate time:startTime atHostTime:inOneSecond];
109 /// ```
110 /// Also note that this method updates the rate property synchronously, but the timebase is updated asynchronously.
111 ///
112 /// - Parameter rate: A new timebase rate to set. Must be greater than or equal to 0.0
113 /// - Parameter time: A new timebase time to set. Must be greater than or equal to kCMTimeZero, or kCMTimeInvalid
114 /// - Parameter hostTime: A new hostTime to set. Must be greater than or equal to kCMTimeZero, or kCMTimeInvalid
115 #[unsafe(method(setRate:time:atHostTime:))]
116 #[unsafe(method_family = none)]
117 pub unsafe fn setRate_time_atHostTime(
118 &self,
119 rate: c_float,
120 time: CMTime,
121 host_time: CMTime,
122 );
123
124 /// Indicates whether the playback should be started immediately on rate change request.
125 ///
126 /// 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.
127 #[unsafe(method(delaysRateChangeUntilHasSufficientMediaData))]
128 #[unsafe(method_family = none)]
129 pub unsafe fn delaysRateChangeUntilHasSufficientMediaData(&self) -> bool;
130
131 /// Setter for [`delaysRateChangeUntilHasSufficientMediaData`][Self::delaysRateChangeUntilHasSufficientMediaData].
132 #[unsafe(method(setDelaysRateChangeUntilHasSufficientMediaData:))]
133 #[unsafe(method_family = none)]
134 pub unsafe fn setDelaysRateChangeUntilHasSufficientMediaData(
135 &self,
136 delays_rate_change_until_has_sufficient_media_data: bool,
137 );
138 );
139}
140
141/// Methods declared on superclass `NSObject`.
142impl AVSampleBufferRenderSynchronizer {
143 extern_methods!(
144 #[unsafe(method(init))]
145 #[unsafe(method_family = init)]
146 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
147
148 #[unsafe(method(new))]
149 #[unsafe(method_family = new)]
150 pub unsafe fn new() -> Retained<Self>;
151 );
152}
153
154/// AVSampleBufferRenderSynchronizerRendererManagement.
155impl AVSampleBufferRenderSynchronizer {
156 extern_methods!(
157 #[cfg(feature = "AVQueuedSampleBufferRendering")]
158 /// Array of id
159 /// <AVQueuedSampleBufferRendering
160 /// > currently attached to the synchronizer.
161 ///
162 /// 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.
163 ///
164 /// This property is not KVO observable.
165 #[unsafe(method(renderers))]
166 #[unsafe(method_family = none)]
167 pub unsafe fn renderers(
168 &self,
169 ) -> Retained<NSArray<ProtocolObject<dyn AVQueuedSampleBufferRendering>>>;
170
171 #[cfg(feature = "AVQueuedSampleBufferRendering")]
172 /// Adds a renderer to the list of renderers under the synchronizer's control.
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 ///
178 /// - Parameter renderer: An object conforming to AVQueuedSampleBufferRendering to be synchronized by this synchronizer.
179 #[unsafe(method(addRenderer:))]
180 #[unsafe(method_family = none)]
181 pub unsafe fn addRenderer(
182 &self,
183 renderer: &ProtocolObject<dyn AVQueuedSampleBufferRendering>,
184 );
185
186 #[cfg(all(
187 feature = "AVQueuedSampleBufferRendering",
188 feature = "block2",
189 feature = "objc2-core-media"
190 ))]
191 /// Removes a renderer from the list of renderers under the synchronizer's control.
192 ///
193 /// This method can be called while rate is non-0.0.
194 ///
195 /// 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.
196 ///
197 /// This method removes the renderer asynchronously. The method can be called more than once, with a subsequent scheduled removal replacing a previously scheduled removal.
198 ///
199 /// 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:
200 ///
201 /// - If the renderer has not been added to this synchronizer, completionHandler will be called and didRemoveRenderer will be NO.
202 /// - 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.
203 /// - 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.
204 ///
205 /// - Parameter renderer: An object conforming to AVQueuedSampleBufferRendering currently synchronized by this synchronizer to no longer be synchronized by the synchronizer.
206 /// - Parameter time: The time on the timebase's timeline at which the renderer should be removed.
207 /// - 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.
208 ///
209 /// # Safety
210 ///
211 /// `completion_handler` block must be sendable.
212 #[unsafe(method(removeRenderer:atTime:completionHandler:))]
213 #[unsafe(method_family = none)]
214 pub unsafe fn removeRenderer_atTime_completionHandler(
215 &self,
216 renderer: &ProtocolObject<dyn AVQueuedSampleBufferRendering>,
217 time: CMTime,
218 completion_handler: Option<&block2::DynBlock<dyn Fn(Bool)>>,
219 );
220 );
221}
222
223/// AVSampleBufferRenderSynchronizerTimeObservation.
224impl AVSampleBufferRenderSynchronizer {
225 extern_methods!(
226 #[cfg(all(
227 feature = "block2",
228 feature = "dispatch2",
229 feature = "objc2-core-media"
230 ))]
231 /// Requests invocation of a block during rendering to report changing time.
232 ///
233 /// The block is invoked periodically at the interval specified, interpreted according to the timeline of the timebase. The block is also invoked whenever time jumps and whenever rendering starts or stops.
234 ///
235 /// If the interval corresponds to a very short interval in real time, the synchronizer may invoke the block less frequently than requested. Even so, the synchronizer will invoke the block sufficiently often for the client to update indications of the current time appropriately in its end-user interface.
236 ///
237 /// 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.
238 ///
239 /// - Parameter interval: The interval of invocation of the block during normal rendering, according to progress of the current time of the timebase.
240 /// - 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.
241 /// - Parameter block: The block to be invoked periodically.
242 ///
243 /// - Returns: An object conforming to the NSObject protocol. You must retain this returned value as long as you want the time observer to be invoked by the synchronizer. Pass this object to -removeTimeObserver: to cancel time observation.
244 ///
245 /// # Safety
246 ///
247 /// - `queue` possibly has additional threading requirements.
248 /// - `block` block must be sendable.
249 #[unsafe(method(addPeriodicTimeObserverForInterval:queue:usingBlock:))]
250 #[unsafe(method_family = none)]
251 pub unsafe fn addPeriodicTimeObserverForInterval_queue_usingBlock(
252 &self,
253 interval: CMTime,
254 queue: Option<&DispatchQueue>,
255 block: &block2::DynBlock<dyn Fn(CMTime)>,
256 ) -> Retained<AnyObject>;
257
258 #[cfg(all(feature = "block2", feature = "dispatch2"))]
259 /// Requests invocation of a block when specified times are traversed during normal rendering.
260 ///
261 /// 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.
262 ///
263 /// - Parameter times: The times for which the observer requests notification, supplied as an array of NSValues carrying CMTimes.
264 /// - 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.
265 /// - Parameter block: The block to be invoked when any of the specified times is crossed during normal rendering.
266 ///
267 /// - Returns: An object conforming to the NSObject protocol. You must retain this returned value as long as you want the time observer to be invoked by the synchronizer. Pass this object to -removeTimeObserver: to cancel time observation.
268 ///
269 /// # Safety
270 ///
271 /// - `queue` possibly has additional threading requirements.
272 /// - `block` block must be sendable.
273 #[unsafe(method(addBoundaryTimeObserverForTimes:queue:usingBlock:))]
274 #[unsafe(method_family = none)]
275 pub unsafe fn addBoundaryTimeObserverForTimes_queue_usingBlock(
276 &self,
277 times: &NSArray<NSValue>,
278 queue: Option<&DispatchQueue>,
279 block: &block2::DynBlock<dyn Fn()>,
280 ) -> Retained<AnyObject>;
281
282 /// Cancels a previously registered time observer.
283 ///
284 /// 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:.
285 ///
286 /// This method throws an exception for any of the following reasons:
287 /// - observer was added by another AVSampleBufferRenderSynchronizer
288 /// - observer was not returned by either
289 /// -addPeriodicTimeObserverForInterval:queue:usingBlock:
290 /// -addBoundaryTimeObserverForTimes:queue:usingBlock:
291 ///
292 /// - Parameter observer: An object returned by a previous call to -addPeriodicTimeObserverForInterval:queue:usingBlock: or -addBoundaryTimeObserverForTimes:queue:usingBlock:.
293 ///
294 /// # Safety
295 ///
296 /// `observer` should be of the correct type.
297 #[unsafe(method(removeTimeObserver:))]
298 #[unsafe(method_family = none)]
299 pub unsafe fn removeTimeObserver(&self, observer: &AnyObject);
300 );
301}
302
303/// AVSampleBufferRenderSynchronizerSpatialAudioExperience.
304impl AVSampleBufferRenderSynchronizer {
305 extern_methods!();
306}