objc2_avf_audio/generated/AVAudioPlayerNode.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
7use crate::*;
8
9/// Options controlling buffer scheduling.
10///
11///
12/// The buffer loops indefinitely.
13///
14/// The buffer interrupts any buffer already playing.
15///
16/// The buffer interrupts any buffer already playing, at its loop point.
17///
18/// API_AVAILABLE(macos(10.10), ios(8.0), watchos(2.0), tvos(9.0))
19///
20/// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudioplayernodebufferoptions?language=objc)
21// NS_OPTIONS
22#[repr(transparent)]
23#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
24pub struct AVAudioPlayerNodeBufferOptions(pub NSUInteger);
25bitflags::bitflags! {
26 impl AVAudioPlayerNodeBufferOptions: NSUInteger {
27 #[doc(alias = "AVAudioPlayerNodeBufferLoops")]
28 const Loops = 1<<0;
29 #[doc(alias = "AVAudioPlayerNodeBufferInterrupts")]
30 const Interrupts = 1<<1;
31 #[doc(alias = "AVAudioPlayerNodeBufferInterruptsAtLoop")]
32 const InterruptsAtLoop = 1<<2;
33 }
34}
35
36unsafe impl Encode for AVAudioPlayerNodeBufferOptions {
37 const ENCODING: Encoding = NSUInteger::ENCODING;
38}
39
40unsafe impl RefEncode for AVAudioPlayerNodeBufferOptions {
41 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
42}
43
44/// Specifies when the completion handler must be invoked.
45///
46///
47/// The buffer or file data has been consumed by the player.
48///
49/// The buffer or file data has been rendered (i.e. output) by the player. This
50/// does not account for any signal processing latencies downstream of the player
51/// in the engine (see `AVAudioNode(outputPresentationLatency)`).
52///
53/// Applicable only when the engine is rendering to/from an audio device.
54/// The buffer or file has finished playing. This accounts for both (small) signal
55/// processing latencies downstream of the player in the engine, as well as
56/// (possibly significant) latency in the audio playback device.
57///
58/// API_AVAILABLE(macos(10.13), ios(11.0), watchos(4.0), tvos(11.0));
59///
60/// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudioplayernodecompletioncallbacktype?language=objc)
61// NS_ENUM
62#[repr(transparent)]
63#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
64pub struct AVAudioPlayerNodeCompletionCallbackType(pub NSInteger);
65impl AVAudioPlayerNodeCompletionCallbackType {
66 #[doc(alias = "AVAudioPlayerNodeCompletionDataConsumed")]
67 pub const DataConsumed: Self = Self(0);
68 #[doc(alias = "AVAudioPlayerNodeCompletionDataRendered")]
69 pub const DataRendered: Self = Self(1);
70 #[doc(alias = "AVAudioPlayerNodeCompletionDataPlayedBack")]
71 pub const DataPlayedBack: Self = Self(2);
72}
73
74unsafe impl Encode for AVAudioPlayerNodeCompletionCallbackType {
75 const ENCODING: Encoding = NSInteger::ENCODING;
76}
77
78unsafe impl RefEncode for AVAudioPlayerNodeCompletionCallbackType {
79 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
80}
81
82/// Buffer or file completion callback handler.
83///
84/// Parameter `callbackType`: Indicates the type of buffer or file completion when the callback is invoked.
85///
86/// AVAudioPlayerNode issues this callback to inform the client about the specific type of
87/// buffer or file completion. See `AVAudioPlayerNodeCompletionCallbackType` for more details.
88///
89/// Note that the `AVAudioNodeCompletionHandler` callback from some of the player's scheduling
90/// methods (e.g. `scheduleBuffer:completionHandler:`) is equivalent to the
91/// AVAudioPlayerNodeCompletionHandler callback for `AVAudioPlayerNodeCompletionDataConsumed`.
92///
93/// In general the callbacks arrive on a non-main thread and it is the client's responsibility
94/// to handle them in a thread-safe manner.
95///
96/// Setting or getting properties on an AVAudioPlayerNode while the AVAudioEngine is running requires
97/// some synchronisation between the calling threads internally. If you want to call player node API within this
98/// completion handler block, calls should be synchronised to the same thread/queue.
99///
100/// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudioplayernodecompletionhandler?language=objc)
101#[cfg(feature = "block2")]
102pub type AVAudioPlayerNodeCompletionHandler =
103 *mut block2::DynBlock<dyn Fn(AVAudioPlayerNodeCompletionCallbackType)>;
104
105extern_class!(
106 /// Play buffers or segments of audio files.
107 ///
108 /// AVAudioPlayerNode supports scheduling the playback of `AVAudioBuffer` instances,
109 /// or segments of audio files opened via `AVAudioFile`. Buffers and segments may be
110 /// scheduled at specific points in time, or to play immediately following preceding segments.
111 ///
112 /// FORMATS
113 ///
114 /// Normally, you will want to configure the node's output format with the same number of
115 /// channels as are in the files and buffers to be played. Otherwise, channels will be dropped
116 /// or added as required. It is usually better to use an `AVAudioMixerNode` to
117 /// do this.
118 ///
119 /// Similarly, when playing file segments, the node will sample rate convert if necessary, but
120 /// it is often preferable to configure the node's output sample rate to match that of the file(s)
121 /// and use a mixer to perform the rate conversion.
122 ///
123 /// When playing buffers, there is an implicit assumption that the buffers are at the same
124 /// sample rate as the node's output format.
125 ///
126 /// TIMELINES
127 ///
128 /// The usual `AVAudioNode` sample times (as observed by `lastRenderTime`)
129 /// have an arbitrary zero point. AVAudioPlayerNode superimposes a second "player timeline" on
130 /// top of this, to reflect when the player was started, and intervals during which it was
131 /// paused. The methods `nodeTimeForPlayerTime:` and `playerTimeForNodeTime:`
132 /// convert between the two.
133 ///
134 /// This class' `stop` method unschedules all previously scheduled buffers and
135 /// file segments, and returns the player timeline to sample time 0.
136 ///
137 /// TIMESTAMPS
138 ///
139 /// The "schedule" methods all take an `AVAudioTime` "when" parameter. This is
140 /// interpreted as follows:
141 ///
142 /// 1. nil:
143 /// - if there have been previous commands, the new one is played immediately following the
144 /// last one.
145 /// - otherwise, if the node is playing, the event is played in the very near future.
146 /// - otherwise, the command is played at sample time 0.
147 /// 2. sample time:
148 /// - relative to the node's start time (which begins at 0 when the node is started).
149 /// 3. host time:
150 /// - ignored unless the sample time is invalid when the engine is rendering to an audio
151 /// device.
152 /// - ignored in manual rendering mode.
153 ///
154 /// ERRORS
155 ///
156 /// The "schedule" methods can fail if:
157 ///
158 /// 1. a buffer's channel count does not match that of the node's output format.
159 /// 2. a file can't be accessed.
160 /// 3. an AVAudioTime specifies neither a valid sample time or host time.
161 /// 4. a segment's start frame or frame count is negative.
162 ///
163 /// BUFFER/FILE COMPLETION HANDLERS
164 ///
165 /// The buffer or file completion handlers (see scheduling methods) are a means to schedule
166 /// more data if available on the player node. See `AVAudioPlayerNodeCompletionCallbackType`
167 /// for details on the different buffer/file completion callback types.
168 ///
169 /// Note that a player should not be stopped from within a completion handler callback because
170 /// it can deadlock while trying to unschedule previously scheduled buffers.
171 ///
172 /// OFFLINE RENDERING
173 ///
174 /// When a player node is used with the engine operating in the manual rendering mode, the
175 /// buffer/file completion handlers, `lastRenderTime` and the latencies (`latency` and
176 /// `outputPresentationLatency`) can be used to track how much data the player has rendered and
177 /// how much more data is left to render.
178 ///
179 /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudioplayernode?language=objc)
180 #[unsafe(super(AVAudioNode, NSObject))]
181 #[derive(Debug, PartialEq, Eq, Hash)]
182 #[cfg(feature = "AVAudioNode")]
183 pub struct AVAudioPlayerNode;
184);
185
186#[cfg(all(feature = "AVAudioMixing", feature = "AVAudioNode"))]
187extern_conformance!(
188 unsafe impl AVAudio3DMixing for AVAudioPlayerNode {}
189);
190
191#[cfg(all(feature = "AVAudioMixing", feature = "AVAudioNode"))]
192extern_conformance!(
193 unsafe impl AVAudioMixing for AVAudioPlayerNode {}
194);
195
196#[cfg(all(feature = "AVAudioMixing", feature = "AVAudioNode"))]
197extern_conformance!(
198 unsafe impl AVAudioStereoMixing for AVAudioPlayerNode {}
199);
200
201#[cfg(feature = "AVAudioNode")]
202extern_conformance!(
203 unsafe impl NSObjectProtocol for AVAudioPlayerNode {}
204);
205
206#[cfg(feature = "AVAudioNode")]
207impl AVAudioPlayerNode {
208 extern_methods!(
209 #[unsafe(method(init))]
210 #[unsafe(method_family = init)]
211 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
212
213 #[cfg(all(
214 feature = "AVAudioBuffer",
215 feature = "AVAudioTypes",
216 feature = "block2"
217 ))]
218 /// Schedule playing samples from an AVAudioBuffer.
219 ///
220 /// Parameter `buffer`: the buffer to play
221 ///
222 /// Parameter `completionHandler`: called after the buffer has been consumed by the player or the player is stopped. may be nil.
223 ///
224 /// Schedules the buffer to be played following any previously scheduled commands.
225 ///
226 /// It is possible for the completionHandler to be called before rendering begins
227 /// or before the buffer is played completely.
228 #[unsafe(method(scheduleBuffer:completionHandler:))]
229 #[unsafe(method_family = none)]
230 pub unsafe fn scheduleBuffer_completionHandler(
231 &self,
232 buffer: &AVAudioPCMBuffer,
233 completion_handler: AVAudioNodeCompletionHandler,
234 );
235
236 #[cfg(all(feature = "AVAudioBuffer", feature = "block2"))]
237 /// Schedule playing samples from an AVAudioBuffer.
238 ///
239 /// Parameter `buffer`: the buffer to play
240 ///
241 /// Parameter `callbackType`: option to specify when the completion handler must be called
242 ///
243 /// Parameter `completionHandler`: called after the buffer has been consumed by the player or has finished playing back or
244 /// the player is stopped. may be nil.
245 ///
246 /// Schedules the buffer to be played following any previously scheduled commands.
247 #[unsafe(method(scheduleBuffer:completionCallbackType:completionHandler:))]
248 #[unsafe(method_family = none)]
249 pub unsafe fn scheduleBuffer_completionCallbackType_completionHandler(
250 &self,
251 buffer: &AVAudioPCMBuffer,
252 callback_type: AVAudioPlayerNodeCompletionCallbackType,
253 completion_handler: AVAudioPlayerNodeCompletionHandler,
254 );
255
256 #[cfg(all(
257 feature = "AVAudioBuffer",
258 feature = "AVAudioTime",
259 feature = "AVAudioTypes",
260 feature = "block2"
261 ))]
262 /// Schedule playing samples from an AVAudioBuffer.
263 ///
264 /// Parameter `buffer`: the buffer to play
265 ///
266 /// Parameter `when`: the time at which to play the buffer. see the discussion of timestamps, above.
267 ///
268 /// Parameter `options`: options for looping, interrupting other buffers, etc.
269 ///
270 /// Parameter `completionHandler`: called after the buffer has been consumed by the player or the player is stopped. may be nil.
271 ///
272 /// It is possible for the completionHandler to be called before rendering begins
273 /// or before the buffer is played completely.
274 #[unsafe(method(scheduleBuffer:atTime:options:completionHandler:))]
275 #[unsafe(method_family = none)]
276 pub unsafe fn scheduleBuffer_atTime_options_completionHandler(
277 &self,
278 buffer: &AVAudioPCMBuffer,
279 when: Option<&AVAudioTime>,
280 options: AVAudioPlayerNodeBufferOptions,
281 completion_handler: AVAudioNodeCompletionHandler,
282 );
283
284 #[cfg(all(feature = "AVAudioBuffer", feature = "AVAudioTime", feature = "block2"))]
285 /// Schedule playing samples from an AVAudioBuffer.
286 ///
287 /// Parameter `buffer`: the buffer to play
288 ///
289 /// Parameter `when`: the time at which to play the buffer. see the discussion of timestamps, above.
290 ///
291 /// Parameter `options`: options for looping, interrupting other buffers, etc.
292 ///
293 /// Parameter `callbackType`: option to specify when the completion handler must be called
294 ///
295 /// Parameter `completionHandler`: called after the buffer has been consumed by the player or has finished playing back or
296 /// the player is stopped. may be nil.
297 #[unsafe(method(scheduleBuffer:atTime:options:completionCallbackType:completionHandler:))]
298 #[unsafe(method_family = none)]
299 pub unsafe fn scheduleBuffer_atTime_options_completionCallbackType_completionHandler(
300 &self,
301 buffer: &AVAudioPCMBuffer,
302 when: Option<&AVAudioTime>,
303 options: AVAudioPlayerNodeBufferOptions,
304 callback_type: AVAudioPlayerNodeCompletionCallbackType,
305 completion_handler: AVAudioPlayerNodeCompletionHandler,
306 );
307
308 #[cfg(all(
309 feature = "AVAudioFile",
310 feature = "AVAudioTime",
311 feature = "AVAudioTypes",
312 feature = "block2"
313 ))]
314 /// Schedule playing of an entire audio file.
315 ///
316 /// Parameter `file`: the file to play
317 ///
318 /// Parameter `when`: the time at which to play the file. see the discussion of timestamps, above.
319 ///
320 /// Parameter `completionHandler`: called after the file has been consumed by the player or the player is stopped. may be nil.
321 ///
322 /// It is possible for the completionHandler to be called before rendering begins
323 /// or before the file is played completely.
324 #[unsafe(method(scheduleFile:atTime:completionHandler:))]
325 #[unsafe(method_family = none)]
326 pub unsafe fn scheduleFile_atTime_completionHandler(
327 &self,
328 file: &AVAudioFile,
329 when: Option<&AVAudioTime>,
330 completion_handler: AVAudioNodeCompletionHandler,
331 );
332
333 #[cfg(all(feature = "AVAudioFile", feature = "AVAudioTime", feature = "block2"))]
334 /// Schedule playing of an entire audio file.
335 ///
336 /// Parameter `file`: the file to play
337 ///
338 /// Parameter `when`: the time at which to play the file. see the discussion of timestamps, above.
339 ///
340 /// Parameter `callbackType`: option to specify when the completion handler must be called
341 ///
342 /// Parameter `completionHandler`: called after the file has been consumed by the player or has finished playing back or
343 /// the player is stopped. may be nil.
344 #[unsafe(method(scheduleFile:atTime:completionCallbackType:completionHandler:))]
345 #[unsafe(method_family = none)]
346 pub unsafe fn scheduleFile_atTime_completionCallbackType_completionHandler(
347 &self,
348 file: &AVAudioFile,
349 when: Option<&AVAudioTime>,
350 callback_type: AVAudioPlayerNodeCompletionCallbackType,
351 completion_handler: AVAudioPlayerNodeCompletionHandler,
352 );
353
354 #[cfg(all(
355 feature = "AVAudioFile",
356 feature = "AVAudioTime",
357 feature = "AVAudioTypes",
358 feature = "block2"
359 ))]
360 /// Schedule playing a segment of an audio file.
361 ///
362 /// Parameter `file`: the file to play
363 ///
364 /// Parameter `startFrame`: the starting frame position in the stream
365 ///
366 /// Parameter `numberFrames`: the number of frames to play
367 ///
368 /// Parameter `when`: the time at which to play the region. see the discussion of timestamps, above.
369 ///
370 /// Parameter `completionHandler`: called after the segment has been consumed by the player or the player is stopped. may be nil.
371 ///
372 /// It is possible for the completionHandler to be called before rendering begins
373 /// or before the segment is played completely.
374 #[unsafe(method(scheduleSegment:startingFrame:frameCount:atTime:completionHandler:))]
375 #[unsafe(method_family = none)]
376 pub unsafe fn scheduleSegment_startingFrame_frameCount_atTime_completionHandler(
377 &self,
378 file: &AVAudioFile,
379 start_frame: AVAudioFramePosition,
380 number_frames: AVAudioFrameCount,
381 when: Option<&AVAudioTime>,
382 completion_handler: AVAudioNodeCompletionHandler,
383 );
384
385 #[cfg(all(
386 feature = "AVAudioFile",
387 feature = "AVAudioTime",
388 feature = "AVAudioTypes",
389 feature = "block2"
390 ))]
391 /// Schedule playing a segment of an audio file.
392 ///
393 /// Parameter `file`: the file to play
394 ///
395 /// Parameter `startFrame`: the starting frame position in the stream
396 ///
397 /// Parameter `numberFrames`: the number of frames to play
398 ///
399 /// Parameter `when`: the time at which to play the region. see the discussion of timestamps, above.
400 ///
401 /// Parameter `callbackType`: option to specify when the completion handler must be called
402 ///
403 /// Parameter `completionHandler`: called after the segment has been consumed by the player or has finished playing back or
404 /// the player is stopped. may be nil.
405 #[unsafe(method(scheduleSegment:startingFrame:frameCount:atTime:completionCallbackType:completionHandler:))]
406 #[unsafe(method_family = none)]
407 pub unsafe fn scheduleSegment_startingFrame_frameCount_atTime_completionCallbackType_completionHandler(
408 &self,
409 file: &AVAudioFile,
410 start_frame: AVAudioFramePosition,
411 number_frames: AVAudioFrameCount,
412 when: Option<&AVAudioTime>,
413 callback_type: AVAudioPlayerNodeCompletionCallbackType,
414 completion_handler: AVAudioPlayerNodeCompletionHandler,
415 );
416
417 /// Clear all of the node's previously scheduled events and stop playback.
418 ///
419 /// All of the node's previously scheduled events are cleared, including any that are in the
420 /// middle of playing. The node's sample time (and therefore the times to which new events are
421 /// to be scheduled) is reset to 0, and will not proceed until the node is started again (via
422 /// play or playAtTime).
423 ///
424 /// Note that pausing or stopping all the players connected to an engine does not pause or stop
425 /// the engine or the underlying hardware. The engine must be explicitly paused or stopped for
426 /// the hardware to stop.
427 #[unsafe(method(stop))]
428 #[unsafe(method_family = none)]
429 pub unsafe fn stop(&self);
430
431 #[cfg(feature = "AVAudioTypes")]
432 /// Prepares previously scheduled file regions or buffers for playback.
433 ///
434 /// Parameter `frameCount`: The number of sample frames of data to be prepared before returning.
435 #[unsafe(method(prepareWithFrameCount:))]
436 #[unsafe(method_family = none)]
437 pub unsafe fn prepareWithFrameCount(&self, frame_count: AVAudioFrameCount);
438
439 /// Start or resume playback immediately.
440 ///
441 /// equivalent to playAtTime:nil
442 #[unsafe(method(play))]
443 #[unsafe(method_family = none)]
444 pub unsafe fn play(&self);
445
446 #[cfg(feature = "AVAudioTime")]
447 /// Start or resume playback at a specific time.
448 ///
449 /// Parameter `when`: the node time at which to start or resume playback. nil signifies "now".
450 ///
451 /// This node is initially paused. Requests to play buffers or file segments are enqueued, and
452 /// any necessary decoding begins immediately. Playback does not begin, however, until the player
453 /// has started playing, via this method.
454 ///
455 /// Note that providing an AVAudioTime which is past (before lastRenderTime) will cause the
456 /// player to begin playback immediately.
457 ///
458 /// E.g. To start a player X seconds in future:
459 /// <pre>
460 /// // start engine and player
461 /// NSError *nsErr = nil;
462 /// [_engine startAndReturnError:
463 /// &nsErr
464 /// ];
465 /// if (!nsErr) {
466 /// const float kStartDelayTime = 0.5; // sec
467 /// AVAudioFormat *outputFormat = [_player outputFormatForBus:0];
468 /// AVAudioFramePosition startSampleTime = _player.lastRenderTime.sampleTime + kStartDelayTime * outputFormat.sampleRate;
469 /// AVAudioTime *startTime = [AVAudioTime timeWithSampleTime:startSampleTime atRate:outputFormat.sampleRate];
470 /// [_player playAtTime:startTime];
471 /// }
472 /// </pre>
473 #[unsafe(method(playAtTime:))]
474 #[unsafe(method_family = none)]
475 pub unsafe fn playAtTime(&self, when: Option<&AVAudioTime>);
476
477 /// Pause playback.
478 ///
479 /// The player's sample time does not advance while the node is paused.
480 ///
481 /// Note that pausing or stopping all the players connected to an engine does not pause or stop
482 /// the engine or the underlying hardware. The engine must be explicitly paused or stopped for
483 /// the hardware to stop.
484 #[unsafe(method(pause))]
485 #[unsafe(method_family = none)]
486 pub unsafe fn pause(&self);
487
488 #[cfg(feature = "AVAudioTime")]
489 /// Convert from player time to node time.
490 ///
491 /// Parameter `playerTime`: a time relative to the player's start time
492 ///
493 /// Returns: a node time
494 ///
495 /// This method and its inverse `playerTimeForNodeTime:` are discussed in the
496 /// introduction to this class.
497 ///
498 /// If the player is not playing when this method is called, nil is returned.
499 #[unsafe(method(nodeTimeForPlayerTime:))]
500 #[unsafe(method_family = none)]
501 pub unsafe fn nodeTimeForPlayerTime(
502 &self,
503 player_time: &AVAudioTime,
504 ) -> Option<Retained<AVAudioTime>>;
505
506 #[cfg(feature = "AVAudioTime")]
507 /// Convert from node time to player time.
508 ///
509 /// Parameter `nodeTime`: a node time
510 ///
511 /// Returns: a time relative to the player's start time
512 ///
513 /// This method and its inverse `nodeTimeForPlayerTime:` are discussed in the
514 /// introduction to this class.
515 ///
516 /// If the player is not playing when this method is called, nil is returned.
517 #[unsafe(method(playerTimeForNodeTime:))]
518 #[unsafe(method_family = none)]
519 pub unsafe fn playerTimeForNodeTime(
520 &self,
521 node_time: &AVAudioTime,
522 ) -> Option<Retained<AVAudioTime>>;
523
524 /// Indicates whether or not the player is playing.
525 #[unsafe(method(isPlaying))]
526 #[unsafe(method_family = none)]
527 pub unsafe fn isPlaying(&self) -> bool;
528 );
529}
530
531/// Methods declared on superclass `NSObject`.
532#[cfg(feature = "AVAudioNode")]
533impl AVAudioPlayerNode {
534 extern_methods!(
535 #[unsafe(method(new))]
536 #[unsafe(method_family = new)]
537 pub unsafe fn new() -> Retained<Self>;
538 );
539}