objc2_media_toolbox/generated/MTAudioProcessingTap.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::cell::UnsafeCell;
4use core::ffi::*;
5use core::marker::{PhantomData, PhantomPinned};
6use core::ptr::NonNull;
7#[cfg(feature = "objc2")]
8use objc2::__framework_prelude::*;
9#[cfg(feature = "objc2-core-audio-types")]
10use objc2_core_audio_types::*;
11use objc2_core_foundation::*;
12#[cfg(feature = "objc2-core-media")]
13use objc2_core_media::*;
14
15use crate::*;
16
17/// [Apple's documentation](https://developer.apple.com/documentation/mediatoolbox/mtaudioprocessingtap?language=objc)
18#[doc(alias = "MTAudioProcessingTapRef")]
19#[repr(C)]
20pub struct MTAudioProcessingTap {
21 inner: [u8; 0],
22 _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
23}
24
25cf_type!(
26 unsafe impl MTAudioProcessingTap {}
27);
28#[cfg(feature = "objc2")]
29cf_objc2_type!(
30 unsafe impl RefEncode<"opaqueMTAudioProcessingTap"> for MTAudioProcessingTap {}
31);
32
33unsafe impl ConcreteType for MTAudioProcessingTap {
34 #[doc(alias = "MTAudioProcessingTapGetTypeID")]
35 #[inline]
36 fn type_id() -> CFTypeID {
37 extern "C-unwind" {
38 fn MTAudioProcessingTapGetTypeID() -> CFTypeID;
39 }
40 unsafe { MTAudioProcessingTapGetTypeID() }
41 }
42}
43
44/// Flags used when creating audio processing taps.
45///
46///
47/// Either the PreEffects or PostEffects flag must be set, but not both.
48///
49///
50/// Signifies that the processing tap is inserted before any effects.
51///
52/// Signifies that the processing tap is inserted after any effects.
53///
54/// See also [Apple's documentation](https://developer.apple.com/documentation/mediatoolbox/mtaudioprocessingtapcreationflags?language=objc)
55pub type MTAudioProcessingTapCreationFlags = u32;
56
57/// [Apple's documentation](https://developer.apple.com/documentation/mediatoolbox/kmtaudioprocessingtapcreationflag_preeffects?language=objc)
58pub const kMTAudioProcessingTapCreationFlag_PreEffects: MTAudioProcessingTapCreationFlags = 1 << 0;
59/// [Apple's documentation](https://developer.apple.com/documentation/mediatoolbox/kmtaudioprocessingtapcreationflag_posteffects?language=objc)
60pub const kMTAudioProcessingTapCreationFlag_PostEffects: MTAudioProcessingTapCreationFlags = 1 << 1;
61
62/// Flags passed to the process callback and from GetSourceAudio.
63///
64///
65/// Signifies that the source audio is the beginning of a continuous stream,
66/// i.e., following the beginning or resumption of playback.
67/// Returned from GetSourceAudio.
68///
69/// Signifies that the source audio is past the end of stream. This happens when
70/// the audio queue is being stopped asynchronously and has finished playing
71/// all of its data. Returned from GetSourceAudio and should be propagated
72/// on return from the process callback.
73///
74/// See also [Apple's documentation](https://developer.apple.com/documentation/mediatoolbox/mtaudioprocessingtapflags?language=objc)
75pub type MTAudioProcessingTapFlags = u32;
76
77/// [Apple's documentation](https://developer.apple.com/documentation/mediatoolbox/kmtaudioprocessingtapflag_startofstream?language=objc)
78pub const kMTAudioProcessingTapFlag_StartOfStream: MTAudioProcessingTapFlags = 1 << 8;
79/// [Apple's documentation](https://developer.apple.com/documentation/mediatoolbox/kmtaudioprocessingtapflag_endofstream?language=objc)
80pub const kMTAudioProcessingTapFlag_EndOfStream: MTAudioProcessingTapFlags = 1 << 9;
81
82/// Init callback.
83///
84///
85/// An init callback that is invoked when MTAudioProcessingTapCreate() is called.
86/// The init callback is always balanced by a finalize callback when the MTAudioProcessingTap object
87/// is released.
88///
89///
90/// Parameter `tap`: The processing tap.
91///
92/// Parameter `clientInfo`: The client data of the processing tap passed in callbacks struct in MTAudioProcessingTapCreate().
93///
94/// Parameter `tapStorageOut`: Additional client data. The intent is for clients to allocate a block of memory for use within their custom
95/// MTAudioProcessingTap implementation that will be freed when the finalize callback is invoked. This argument
96/// is optional.
97///
98/// See also [Apple's documentation](https://developer.apple.com/documentation/mediatoolbox/mtaudioprocessingtapinitcallback?language=objc)
99pub type MTAudioProcessingTapInitCallback = Option<
100 unsafe extern "C-unwind" fn(NonNull<MTAudioProcessingTap>, *mut c_void, NonNull<*mut c_void>),
101>;
102
103/// Finalize callback.
104///
105///
106/// This callback is called when it is safe to free any buffers or other state associated with the tap.
107/// This callback will be called exactly once when the MTAudioProcessingTap object is finalized.
108/// If tapStorage was allocated in the init callback, it should be freed here.
109///
110///
111/// Parameter `tap`: The processing tap.
112///
113/// See also [Apple's documentation](https://developer.apple.com/documentation/mediatoolbox/mtaudioprocessingtapfinalizecallback?language=objc)
114pub type MTAudioProcessingTapFinalizeCallback =
115 Option<unsafe extern "C-unwind" fn(NonNull<MTAudioProcessingTap>)>;
116
117/// Audio processing preparation callback.
118///
119///
120/// A preparation callback that is invoked when the underlying audio machinery is initialized.
121///
122/// The preparation callback should be where output buffers that will be returned by the
123/// ProcessingTapCallback are allocated (unless in-place processing is desired).
124///
125/// Note that the preparation callback can potentially be called multiple times over the lifetime
126/// of the tap object, if the client performs an operation that requires the underlying audio machinery to
127/// be torn down and rebuilt.
128///
129///
130/// Parameter `tap`: The processing tap.
131///
132/// Parameter `maxFrames`: The maximum number of sample frames that can be requested of a processing
133/// tap at any one time. Typically this will be approximately 50 msec of audio
134/// (2048 samples
135/// @
136/// 44.1kHz).
137///
138/// Parameter `processingFormat`: The format in which the client will receive the audio data to be processed.
139/// This will always be the same sample rate as the client format and usually
140/// the same number of channels as the client format of the audio queue. (NOTE:
141/// the number of channels may be different in some cases if the client format
142/// has some channel count restrictions; for example, if the client provides 5.1
143/// AAC, but the decoder can only produce stereo). The channel order, if the
144/// same as the client format, will be the same as the client channel order. If
145/// the channel count is changed, it will be to either 1 (mono) or 2 (stereo, in
146/// which case the first channel is left, the second right).
147///
148/// If the data is not in a convenient format for the client to process in, then
149/// the client should convert the data to and from that format. This is the most
150/// efficient mechanism to use, as the audio system may choose a format that is
151/// most efficient from its playback requirement.
152///
153/// See also [Apple's documentation](https://developer.apple.com/documentation/mediatoolbox/mtaudioprocessingtappreparecallback?language=objc)
154#[cfg(all(feature = "objc2-core-audio-types", feature = "objc2-core-media"))]
155pub type MTAudioProcessingTapPrepareCallback = Option<
156 unsafe extern "C-unwind" fn(
157 NonNull<MTAudioProcessingTap>,
158 CMItemCount,
159 NonNull<AudioStreamBasicDescription>,
160 ),
161>;
162
163/// Audio processing unpreparation callback.
164///
165///
166/// The unpreparation callback is invoked when the underlying audio machinery stops calling the process callback.
167///
168/// Preparation/Unpreparation callbacks are always paired.
169///
170/// Process callbacks will only ever be called after the prepare callback returns, and before unprepare is called.
171///
172///
173/// Parameter `tap`: The processing tap.
174///
175/// See also [Apple's documentation](https://developer.apple.com/documentation/mediatoolbox/mtaudioprocessingtapunpreparecallback?language=objc)
176pub type MTAudioProcessingTapUnprepareCallback =
177 Option<unsafe extern "C-unwind" fn(NonNull<MTAudioProcessingTap>)>;
178
179/// A function called when an audio track has data to be processed by its tap.
180///
181///
182/// A processing callback is invoked when the audio track has data that can be processed by a
183/// given tap.
184///
185/// The processing callback will be called when there is sufficient input data to provide for
186/// processing. The callback should then go and request as much source data as it needs in order
187/// to produce the requested number of processed samples. When the callback requests source data,
188/// it may receive less data than it requests.
189///
190/// The tap must provide the same number of samples that are being requested. Under normal circumstances,
191/// the source data it requests should be satisfied (as the client running the audio queue is also
192/// providing the queue with the audio source material). If there is insufficient source data available
193/// (this is indicated by the numberFramesOut from the GetSourceAudio call), then the processing tap
194/// should cope as best as it can; it can either return less data than was requested, insert silence,
195/// insert noise, etc.
196/// If less data is returned than requested, the remainder will be filled with silence.
197///
198/// A processing tap is a real-time operation, so the general Core Audio limitations for real-time
199/// processing apply. For example, care should be taken not to allocate memory or call into
200/// blocking system calls, as this will interfere with the real-time nature of audio playback.
201///
202/// Under normal operation, the source data will be continuous from the last time the callback was
203/// called, and the processed samples should be continuous from the previous samples returned. If
204/// there is any discontinuity between the last samples provided for processing, the audio queue will
205/// set the kMTAudioProcessingTapFlag_StartOfStream bit in the flags. After a discontinuity, the
206/// first sample that the processing tap outputs should correspond to the first sample that was
207/// provided in the source samples (so a reset + consequent process serves to re-anchor a
208/// relationship between the processing tap's source and processed samples). In this case, the
209/// processing tap will typically discard any previous state (for example, if a processing tap was
210/// adding a reverb to a signal, then the discontinuity flag would act the same as AudioUnitReset;
211/// any previous source information in the processing tap should be discarded).
212///
213/// The caller is responsible for absorbing any processing delays. For example, if the
214/// processing is to be done by an audio unit that reports a processing latency, then the caller
215/// should remove those latency samples from the audio unit's rendering and not return them to
216/// the tap.
217///
218/// The processing tap may operate on the provided source data in place ("in-place processing")
219/// and return pointers to that buffer, rather than its own. This is similar to audio
220/// unit render operations. The processing tap will be provided with a bufferList on input
221/// where the mData pointers are NULL.
222///
223/// When the output audio is stopped asynchronously, the processing tap will see the
224/// kMTAudioProcessingTapFlag_EndOfStream bit set on return from GetSourceAudio, and is responsible
225/// for propagating this bit from the callback when its processing has reached this point.
226///
227/// A processing tap will NEVER see the same source data again, so, it should keep its own copy,
228/// if it needs to keep it for further reference past the duration of this call. It also cannot
229/// assume that the pointers to the source data that it retrieves will remain valid AFTER the
230/// processing tap has executed.
231///
232/// Should the processing tap provide custom buffers in bufferListInOut, it should ensure that the
233/// data pointers remain valid until the tap is executed again.
234///
235///
236/// Parameter `tap`: The processing tap.
237///
238/// Parameter `numberFrames`: The requested number of sample frames that should be rendered.
239///
240/// Parameter `flags`: The flags passed at construction time are provided.
241///
242/// Parameter `bufferListInOut`: The audio buffer list which will contain processed source data.
243/// On input, all fields except for the buffer pointers will be filled in,
244/// and can be passed directly to GetSourceAudio() if in-place processing is
245/// desired.
246/// On output, the bufferList should contain the processed audio buffers.
247///
248/// Parameter `numberFramesOut`: The number of frames of audio data provided in the processed data. Can be 0.
249///
250/// Parameter `flagsOut`: The start/end of stream flags should be set when appropriate (see Discussion, above).
251///
252/// See also [Apple's documentation](https://developer.apple.com/documentation/mediatoolbox/mtaudioprocessingtapprocesscallback?language=objc)
253#[cfg(all(feature = "objc2-core-audio-types", feature = "objc2-core-media"))]
254pub type MTAudioProcessingTapProcessCallback = Option<
255 unsafe extern "C-unwind" fn(
256 NonNull<MTAudioProcessingTap>,
257 CMItemCount,
258 MTAudioProcessingTapFlags,
259 NonNull<AudioBufferList>,
260 NonNull<CMItemCount>,
261 NonNull<MTAudioProcessingTapFlags>,
262 ),
263>;
264
265/// [Apple's documentation](https://developer.apple.com/documentation/mediatoolbox/kmtaudioprocessingtapcallbacksversion_0?language=objc)
266pub const kMTAudioProcessingTapCallbacksVersion_0: c_int = 0;
267
268/// Note that for 64-bit architectures, this struct contains misaligned function pointers.
269/// To avoid link-time issues, it is recommended that clients fill MTAudioProcessingTapCallbacks' function pointer fields
270/// by using assignment statements, rather than declaring them as global or static structs.
271/// Field: version
272/// The version number of the structure passed in as a parameter to MTAudioProcessingTapCreate().
273/// Must be kMTAudioProcessingTapCallbacksVersion_0.
274/// Field: clientInfo
275/// Client data that will be passed to the init callback when it is invoked. Can be NULL.
276/// Field: init
277/// A callback to allow the client to initialize the tap processor. Can be NULL.
278/// This callback is called before MTAudioProcessingTapCreate() returns.
279/// Field: finalize
280/// A callback to allow the client to perform any necessary cleanup. Can be NULL.
281/// This callback will be called exactly once when the MTAudioProcessingTap object is finalized.
282/// Field: prepare
283/// A callback to allow the client to prepare the tap processor (allocate memory buffers, etc). Can be NULL.
284/// Note that the callback may be called multiple times.
285/// Field: unprepare
286/// A callback to allow the client to perform any necessary cleanup for which that is prepared. Can be NULL.
287/// Field: process
288/// A callback for processing the audio.
289///
290/// See also [Apple's documentation](https://developer.apple.com/documentation/mediatoolbox/mtaudioprocessingtapcallbacks?language=objc)
291#[cfg(all(feature = "objc2-core-audio-types", feature = "objc2-core-media"))]
292#[repr(C, packed(4))]
293#[allow(unpredictable_function_pointer_comparisons)]
294#[derive(Clone, Copy, Debug, PartialEq)]
295pub struct MTAudioProcessingTapCallbacks {
296 pub version: c_int,
297 pub clientInfo: *mut c_void,
298 pub init: MTAudioProcessingTapInitCallback,
299 pub finalize: MTAudioProcessingTapFinalizeCallback,
300 pub prepare: MTAudioProcessingTapPrepareCallback,
301 pub unprepare: MTAudioProcessingTapUnprepareCallback,
302 pub process: MTAudioProcessingTapProcessCallback,
303}
304
305#[cfg(all(
306 feature = "objc2",
307 feature = "objc2-core-audio-types",
308 feature = "objc2-core-media"
309))]
310unsafe impl Encode for MTAudioProcessingTapCallbacks {
311 const ENCODING: Encoding = Encoding::Struct(
312 "?",
313 &[
314 <c_int>::ENCODING,
315 <*mut c_void>::ENCODING,
316 <MTAudioProcessingTapInitCallback>::ENCODING,
317 <MTAudioProcessingTapFinalizeCallback>::ENCODING,
318 <MTAudioProcessingTapPrepareCallback>::ENCODING,
319 <MTAudioProcessingTapUnprepareCallback>::ENCODING,
320 <MTAudioProcessingTapProcessCallback>::ENCODING,
321 ],
322 );
323}
324
325#[cfg(all(
326 feature = "objc2",
327 feature = "objc2-core-audio-types",
328 feature = "objc2-core-media"
329))]
330unsafe impl RefEncode for MTAudioProcessingTapCallbacks {
331 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
332}
333
334impl MTAudioProcessingTap {
335 /// Create a new processing tap.
336 ///
337 /// This function creates a processing tap.
338 /// The processing tap will then be used to process decoded data.
339 /// The processing is performed on audio either before or after any effects or other
340 /// processing (varispeed, etc) is applied by the audio queue.
341 ///
342 ///
343 /// Parameter `allocator`: The allocator to use to allocate memory for the new tap. Pass NULL or kCFAllocatorDefault to use the current default allocator.
344 ///
345 /// Parameter `callbacks`: Callbacks struct. MTAudioProcessingTap will make a copy of this struct.
346 ///
347 /// Parameter `flags`: Flags that are used to control aspects of the processing tap.
348 /// Valid flags are:
349 /// - kMTAudioProcessingTapCreationFlag_PreEffects:
350 /// processing is done before any further effects are applied by the audio queue to the audio.
351 /// - kMTAudioProcessingTapCreationFlag_PostEffects:
352 /// processing is done after all processing is done, including that of other taps.
353 ///
354 /// Parameter `tapOut`: The processing tap object.
355 ///
356 ///
357 /// Returns: An OSStatus result code.
358 ///
359 /// # Safety
360 ///
361 /// - `callbacks` must be a valid pointer.
362 /// - `tap_out` must be a valid pointer.
363 #[doc(alias = "MTAudioProcessingTapCreate")]
364 #[cfg(all(feature = "objc2-core-audio-types", feature = "objc2-core-media"))]
365 #[inline]
366 pub unsafe fn create(
367 allocator: Option<&CFAllocator>,
368 callbacks: NonNull<MTAudioProcessingTapCallbacks>,
369 flags: MTAudioProcessingTapCreationFlags,
370 tap_out: NonNull<*const MTAudioProcessingTap>,
371 ) -> OSStatus {
372 extern "C-unwind" {
373 fn MTAudioProcessingTapCreate(
374 allocator: Option<&CFAllocator>,
375 callbacks: NonNull<MTAudioProcessingTapCallbacks>,
376 flags: MTAudioProcessingTapCreationFlags,
377 tap_out: NonNull<*const MTAudioProcessingTap>,
378 ) -> OSStatus;
379 }
380 unsafe { MTAudioProcessingTapCreate(allocator, callbacks, flags, tap_out) }
381 }
382
383 /// Used by a processing tap to retrieve a custom storage pointer.
384 ///
385 ///
386 /// Parameter `tap`: The processing tap.
387 ///
388 ///
389 /// Returns: The tapStorage returned by the init callback.
390 #[doc(alias = "MTAudioProcessingTapGetStorage")]
391 #[inline]
392 pub unsafe fn storage(&self) -> NonNull<c_void> {
393 extern "C-unwind" {
394 fn MTAudioProcessingTapGetStorage(
395 tap: &MTAudioProcessingTap,
396 ) -> Option<NonNull<c_void>>;
397 }
398 let ret = unsafe { MTAudioProcessingTapGetStorage(self) };
399 ret.expect("function was marked as returning non-null, but actually returned NULL")
400 }
401
402 /// Used by a processing tap to retrieve source audio.
403 ///
404 /// This function may only be called from the processing tap's callback.
405 ///
406 ///
407 /// Parameter `tap`: The processing tap.
408 ///
409 /// Parameter `numberFrames`: The number of frames the processing tap requires for its processing.
410 ///
411 /// Parameter `bufferListInOut`: The audio buffer list which will contain the source data.
412 /// On input, all fields except for the buffer pointers must be filled in.
413 /// If the buffer pointers are NULL (recommended), non-NULL pointers will be
414 /// returned and system owns the source buffers; these buffers are only applicable
415 /// for the duration of the processing tap callback.
416 /// If the buffer pointers are non-NULL, then they must be big enough to hold
417 /// numberFrames, and the source data will be copied into these buffers.
418 ///
419 /// Parameter `flagsOut`: Flags to describe state about the input requested, e.g., discontinuity/complete. Can be NULL.
420 ///
421 /// Parameter `timeRangeOut`: The asset time range corresponding to the provided source audio frames. Can be NULL.
422 ///
423 /// Parameter `numberFramesOut`: The number of source frames that have been provided. Can be NULL.
424 /// This can be less than the number of requested frames specified in numberFrames.
425 ///
426 ///
427 /// Returns: An OSStatus result code.
428 ///
429 /// # Safety
430 ///
431 /// - `buffer_list_in_out` must be a valid pointer.
432 /// - `flags_out` must be a valid pointer or null.
433 /// - `time_range_out` must be a valid pointer or null.
434 /// - `number_frames_out` must be a valid pointer or null.
435 #[doc(alias = "MTAudioProcessingTapGetSourceAudio")]
436 #[cfg(all(feature = "objc2-core-audio-types", feature = "objc2-core-media"))]
437 #[inline]
438 pub unsafe fn source_audio(
439 &self,
440 number_frames: CMItemCount,
441 buffer_list_in_out: NonNull<AudioBufferList>,
442 flags_out: *mut MTAudioProcessingTapFlags,
443 time_range_out: *mut CMTimeRange,
444 number_frames_out: *mut CMItemCount,
445 ) -> OSStatus {
446 extern "C-unwind" {
447 fn MTAudioProcessingTapGetSourceAudio(
448 tap: &MTAudioProcessingTap,
449 number_frames: CMItemCount,
450 buffer_list_in_out: NonNull<AudioBufferList>,
451 flags_out: *mut MTAudioProcessingTapFlags,
452 time_range_out: *mut CMTimeRange,
453 number_frames_out: *mut CMItemCount,
454 ) -> OSStatus;
455 }
456 unsafe {
457 MTAudioProcessingTapGetSourceAudio(
458 self,
459 number_frames,
460 buffer_list_in_out,
461 flags_out,
462 time_range_out,
463 number_frames_out,
464 )
465 }
466 }
467}
468
469extern "C-unwind" {
470 #[cfg(all(feature = "objc2-core-audio-types", feature = "objc2-core-media"))]
471 #[deprecated = "renamed to `MTAudioProcessingTap::create`"]
472 pub fn MTAudioProcessingTapCreate(
473 allocator: Option<&CFAllocator>,
474 callbacks: NonNull<MTAudioProcessingTapCallbacks>,
475 flags: MTAudioProcessingTapCreationFlags,
476 tap_out: NonNull<*const MTAudioProcessingTap>,
477 ) -> OSStatus;
478}
479
480#[deprecated = "renamed to `MTAudioProcessingTap::storage`"]
481#[inline]
482pub unsafe extern "C-unwind" fn MTAudioProcessingTapGetStorage(
483 tap: &MTAudioProcessingTap,
484) -> NonNull<c_void> {
485 extern "C-unwind" {
486 fn MTAudioProcessingTapGetStorage(tap: &MTAudioProcessingTap) -> Option<NonNull<c_void>>;
487 }
488 let ret = unsafe { MTAudioProcessingTapGetStorage(tap) };
489 ret.expect("function was marked as returning non-null, but actually returned NULL")
490}
491
492extern "C-unwind" {
493 #[cfg(all(feature = "objc2-core-audio-types", feature = "objc2-core-media"))]
494 #[deprecated = "renamed to `MTAudioProcessingTap::source_audio`"]
495 pub fn MTAudioProcessingTapGetSourceAudio(
496 tap: &MTAudioProcessingTap,
497 number_frames: CMItemCount,
498 buffer_list_in_out: NonNull<AudioBufferList>,
499 flags_out: *mut MTAudioProcessingTapFlags,
500 time_range_out: *mut CMTimeRange,
501 number_frames_out: *mut CMItemCount,
502 ) -> OSStatus;
503}