objc2_avf_audio/generated/
AVAudioSession.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::*;
6use objc2_foundation::*;
7
8use crate::*;
9
10extern_class!(
11    /// [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosession?language=objc)
12    #[unsafe(super(NSObject))]
13    #[derive(Debug, PartialEq, Eq, Hash)]
14    pub struct AVAudioSession;
15);
16
17unsafe impl Send for AVAudioSession {}
18
19unsafe impl Sync for AVAudioSession {}
20
21extern_conformance!(
22    unsafe impl NSObjectProtocol for AVAudioSession {}
23);
24
25impl AVAudioSession {
26    extern_methods!(
27        /// Return singleton instance.
28        #[unsafe(method(sharedInstance))]
29        #[unsafe(method_family = none)]
30        pub unsafe fn sharedInstance() -> Retained<AVAudioSession>;
31
32        #[cfg(feature = "AVAudioSessionTypes")]
33        /// Get the list of categories available on the device.  Certain categories may be unavailable on
34        /// particular devices.  For example, AVAudioSessionCategoryRecord will not be available on devices
35        /// that have no support for audio input.
36        #[unsafe(method(availableCategories))]
37        #[unsafe(method_family = none)]
38        pub unsafe fn availableCategories(&self) -> Retained<NSArray<AVAudioSessionCategory>>;
39
40        #[cfg(feature = "AVAudioSessionTypes")]
41        /// Set session category.
42        #[unsafe(method(setCategory:error:_))]
43        #[unsafe(method_family = none)]
44        pub unsafe fn setCategory_error(
45            &self,
46            category: &AVAudioSessionCategory,
47        ) -> Result<(), Retained<NSError>>;
48
49        #[cfg(feature = "AVAudioSessionTypes")]
50        /// Set session category with options.
51        #[unsafe(method(setCategory:withOptions:error:_))]
52        #[unsafe(method_family = none)]
53        pub unsafe fn setCategory_withOptions_error(
54            &self,
55            category: &AVAudioSessionCategory,
56            options: AVAudioSessionCategoryOptions,
57        ) -> Result<(), Retained<NSError>>;
58
59        #[cfg(feature = "AVAudioSessionTypes")]
60        /// Set session category and mode with options.
61        #[unsafe(method(setCategory:mode:options:error:_))]
62        #[unsafe(method_family = none)]
63        pub unsafe fn setCategory_mode_options_error(
64            &self,
65            category: &AVAudioSessionCategory,
66            mode: &AVAudioSessionMode,
67            options: AVAudioSessionCategoryOptions,
68        ) -> Result<(), Retained<NSError>>;
69
70        #[cfg(feature = "AVAudioSessionTypes")]
71        /// Set session category, mode, routing sharing policy, and options.
72        ///
73        /// Use of the long-form route sharing policy is only valid in conjunction with a limited set of
74        /// category, mode, and option values.
75        ///
76        /// Allowed categories: AVAudioSessionCategoryPlayback.
77        ///
78        /// Allowed modes: AVAudioSessionModeDefault, AVAudioSessionModeMoviePlayback,
79        /// AVAudioSessionModeSpokenAudio.
80        ///
81        /// Allowed options: None. Options are allowed when changing the routing policy back to Default,
82        /// however.
83        #[unsafe(method(setCategory:mode:routeSharingPolicy:options:error:_))]
84        #[unsafe(method_family = none)]
85        pub unsafe fn setCategory_mode_routeSharingPolicy_options_error(
86            &self,
87            category: &AVAudioSessionCategory,
88            mode: &AVAudioSessionMode,
89            policy: AVAudioSessionRouteSharingPolicy,
90            options: AVAudioSessionCategoryOptions,
91        ) -> Result<(), Retained<NSError>>;
92
93        #[cfg(feature = "AVAudioSessionTypes")]
94        /// Get session category.
95        /// Examples: AVAudioSessionCategoryRecord, AVAudioSessionCategoryPlayAndRecord, etc.
96        #[unsafe(method(category))]
97        #[unsafe(method_family = none)]
98        pub unsafe fn category(&self) -> Retained<AVAudioSessionCategory>;
99
100        #[cfg(feature = "AVAudioSessionTypes")]
101        /// Get the current set of AVAudioSessionCategoryOptions.
102        #[unsafe(method(categoryOptions))]
103        #[unsafe(method_family = none)]
104        pub unsafe fn categoryOptions(&self) -> AVAudioSessionCategoryOptions;
105
106        #[cfg(feature = "AVAudioSessionTypes")]
107        /// Get the route sharing policy.
108        ///
109        /// See AVAudioSessionRouteSharingPolicy for a description of the available policies.
110        /// See setCategory:mode:routeSharingPolicy:options:error: for additional discussion.
111        #[unsafe(method(routeSharingPolicy))]
112        #[unsafe(method_family = none)]
113        pub unsafe fn routeSharingPolicy(&self) -> AVAudioSessionRouteSharingPolicy;
114
115        #[cfg(feature = "AVAudioSessionTypes")]
116        /// Get the list of modes available on the device.  Certain modes may be unavailable on particular
117        /// devices.  For example, AVAudioSessionModeVideoRecording will not be available on devices that
118        /// have no support for recording video.
119        #[unsafe(method(availableModes))]
120        #[unsafe(method_family = none)]
121        pub unsafe fn availableModes(&self) -> Retained<NSArray<AVAudioSessionMode>>;
122
123        #[cfg(feature = "AVAudioSessionTypes")]
124        /// Set the session's mode.
125        ///
126        /// Modes modify the audio category in order to introduce behavior that is tailored to the specific
127        /// use of audio within an application. Examples:  AVAudioSessionModeVideoRecording,
128        /// AVAudioSessionModeVoiceChat, AVAudioSessionModeMeasurement, etc.
129        #[unsafe(method(setMode:error:_))]
130        #[unsafe(method_family = none)]
131        pub unsafe fn setMode_error(
132            &self,
133            mode: &AVAudioSessionMode,
134        ) -> Result<(), Retained<NSError>>;
135
136        #[cfg(feature = "AVAudioSessionTypes")]
137        /// Get the session's mode.
138        #[unsafe(method(mode))]
139        #[unsafe(method_family = none)]
140        pub unsafe fn mode(&self) -> Retained<AVAudioSessionMode>;
141
142        /// Set allowHapticsAndSystemSoundsDuringRecording to YES in order to allow system sounds and haptics to play while the session is actively using audio input.
143        /// Default value is NO.
144        #[unsafe(method(setAllowHapticsAndSystemSoundsDuringRecording:error:_))]
145        #[unsafe(method_family = none)]
146        pub unsafe fn setAllowHapticsAndSystemSoundsDuringRecording_error(
147            &self,
148            in_value: bool,
149        ) -> Result<(), Retained<NSError>>;
150
151        /// Whether system sounds and haptics can play while the session is actively using audio input.
152        #[unsafe(method(allowHapticsAndSystemSoundsDuringRecording))]
153        #[unsafe(method_family = none)]
154        pub unsafe fn allowHapticsAndSystemSoundsDuringRecording(&self) -> bool;
155
156        #[cfg(feature = "AVAudioSessionTypes")]
157        /// Returns an enum indicating whether the user has granted or denied permission to record, or has
158        /// not been asked
159        #[deprecated = "Please use AVAudioApplication recordPermission"]
160        #[unsafe(method(recordPermission))]
161        #[unsafe(method_family = none)]
162        pub unsafe fn recordPermission(&self) -> AVAudioSessionRecordPermission;
163
164        #[cfg(feature = "block2")]
165        /// Checks to see if calling process has permission to record audio.
166        ///
167        /// The 'response' block will be called immediately if permission has already been granted or
168        /// denied.  Otherwise, it presents a dialog to notify the user and allow them to choose, and calls
169        /// the block once the UI has been dismissed.  'granted' indicates whether permission has been
170        /// granted. Note that the block may be called in a different thread context.
171        #[deprecated = "Please use AVAudioApplication requestRecordPermissionWithCompletionHandler"]
172        #[unsafe(method(requestRecordPermission:))]
173        #[unsafe(method_family = none)]
174        pub unsafe fn requestRecordPermission(&self, response: &block2::DynBlock<dyn Fn(Bool)>);
175
176        #[cfg(feature = "AVAudioSessionTypes")]
177        /// Use this method to temporarily override the output to built-in speaker.
178        ///
179        /// This method is only valid for a session using PlayAndRecord category. This change remains in
180        /// effect only until the current route changes or you call this method again with the
181        /// AVAudioSessionPortOverrideNone option. Sessions using PlayAndRecord category that always want to
182        /// prefer the built-in speaker output over the receiver, should use
183        /// AVAudioSessionCategoryOptionDefaultToSpeaker instead.
184        #[unsafe(method(overrideOutputAudioPort:error:_))]
185        #[unsafe(method_family = none)]
186        pub unsafe fn overrideOutputAudioPort_error(
187            &self,
188            port_override: AVAudioSessionPortOverride,
189        ) -> Result<(), Retained<NSError>>;
190
191        #[cfg(feature = "AVAudioSessionRoute")]
192        /// Select a preferred input port for audio routing.
193        ///
194        /// If the input port is already part of the current audio route, this will have no effect.
195        /// Otherwise, selecting an input port for routing will initiate a route change to use the preferred
196        /// input port. Setting a nil value will clear the preference.
197        #[unsafe(method(setPreferredInput:error:_))]
198        #[unsafe(method_family = none)]
199        pub unsafe fn setPreferredInput_error(
200            &self,
201            in_port: Option<&AVAudioSessionPortDescription>,
202        ) -> Result<(), Retained<NSError>>;
203
204        #[cfg(feature = "AVAudioSessionRoute")]
205        /// Get the preferred input port.  Will be nil if no preference has been set.
206        #[unsafe(method(preferredInput))]
207        #[unsafe(method_family = none)]
208        pub unsafe fn preferredInput(&self) -> Option<Retained<AVAudioSessionPortDescription>>;
209
210        /// Set ringtone and alert interruption preference.
211        ///
212        /// Inform the system when the session prefers to not be interrupted by
213        /// ringtones and alerts. By setting this property to YES, clients will not be interrupted
214        /// by incoming call notifications and other alerts. Starting in iOS 14.0, users can set a global
215        /// preference for incoming call display style to "Banner" or "Full Screen". With "Banner" display style,
216        /// if below property is set to YES then system audio will be silenced. Thus, clients will not be interrupted
217        /// on incoming call notification and user will have opportunity to accept or decline the call. If call is declined,
218        /// the session will not be interrupted, but if user accepts the incoming call, the session will be interrupted.
219        /// With  display style set as "Full Screen", below property will have no effect and clients will be
220        /// interrupted by incoming calls. Apps that record audio and/or video and apps that are used for
221        /// music performance are candidates for using this feature.
222        #[unsafe(method(setPrefersNoInterruptionsFromSystemAlerts:error:_))]
223        #[unsafe(method_family = none)]
224        pub unsafe fn setPrefersNoInterruptionsFromSystemAlerts_error(
225            &self,
226            in_value: bool,
227        ) -> Result<(), Retained<NSError>>;
228
229        #[unsafe(method(prefersNoInterruptionsFromSystemAlerts))]
230        #[unsafe(method_family = none)]
231        pub unsafe fn prefersNoInterruptionsFromSystemAlerts(&self) -> bool;
232
233        #[cfg(feature = "AVAudioSessionTypes")]
234        /// Get the currently resolved rendering mode to badge content appropriately.
235        /// Clients should use this property to determine what to badge content as.
236        #[unsafe(method(renderingMode))]
237        #[unsafe(method_family = none)]
238        pub unsafe fn renderingMode(&self) -> AVAudioSessionRenderingMode;
239
240        /// Set a preference to enable echo cancelled input on supported hardware
241        ///
242        /// Applications might want to record the built-in microphone's input while also playing audio out via the built-in speaker.
243        /// Enabling echo cancelled input is useful when the application needs the input signal to be clear of any echoes
244        /// from the audio playing out of the built-in speaker.
245        ///
246        /// Audio sessions using Voice Processor don't need this option as echo cancellation is implicitly applied for those routes.
247        /// The Voice Processor solution is tuned for voice signals, unlike this option, which is tuned for better capture
248        /// of wider range of audio signals in the presence of built-in speaker echo.
249        ///
250        /// This option is valid only when used with AVAudioSessionCategoryPlayAndRecord and AVAudioSessionModeDefault and is only available
251        /// on certain 2024 or later iPhone models. Support can be queried using property `isEchoCancelledInputAvailable`.
252        /// Other recording sessions might be interrupted if this option is not compatible with sessions that are already recording.
253        ///
254        /// After an audio session goes active, `isEchoCancelledInputEnabled` property can be queried to check if the option was honored.
255        /// Note that the enabled state may change after route changes, e.g. if user plugs in a headset, that route might not support echo cancellation.
256        #[unsafe(method(setPrefersEchoCancelledInput:error:_))]
257        #[unsafe(method_family = none)]
258        pub unsafe fn setPrefersEchoCancelledInput_error(
259            &self,
260            value: bool,
261        ) -> Result<(), Retained<NSError>>;
262
263        #[unsafe(method(prefersEchoCancelledInput))]
264        #[unsafe(method_family = none)]
265        pub unsafe fn prefersEchoCancelledInput(&self) -> bool;
266
267        /// Returns YES if echo cancelled input is successfully enabled on an active session.
268        /// Please see `prefersEchoCancelledInput` above for more details.
269        #[unsafe(method(isEchoCancelledInputEnabled))]
270        #[unsafe(method_family = none)]
271        pub unsafe fn isEchoCancelledInputEnabled(&self) -> bool;
272
273        /// Query whether built-in mic / built-in speaker route supports echo cancellation for the session's given category and mode.
274        /// Returns YES if device model supports echo cancellation and the audio category is PlayAndRecord and the mode is Default.
275        #[unsafe(method(isEchoCancelledInputAvailable))]
276        #[unsafe(method_family = none)]
277        pub unsafe fn isEchoCancelledInputAvailable(&self) -> bool;
278    );
279}
280
281/// Activation.
282impl AVAudioSession {
283    extern_methods!(
284        /// Set the session active or inactive.
285        ///
286        /// Note that activating an audio session is a synchronous (blocking) operation.
287        /// Therefore, we recommend that applications not activate their session from a thread where a long
288        /// blocking operation will be problematic.
289        /// Apps may activate a AVAudioSessionCategoryPlayback session when another app is hosting a
290        /// call (to start a SharePlay activity for example). However, they are not permitted to capture the
291        /// microphone of the active call, so attempts to activate a session with category
292        /// AVAudioSessionCategoryRecord or AVAudioSessionCategoryPlayAndRecord will fail with error
293        /// AVAudioSessionErrorCodeInsufficientPriority.
294        /// When deactivating a session, the caller is required to
295        /// first stop or pause all running I/Os (e.g. audio queues, players, recorders, converters,
296        /// remote I/Os, etc.). Starting in iOS 8, if the session has running I/Os at the time that
297        /// deactivation is requested, the session will be deactivated, but the method will return NO and
298        /// populate the NSError with the code property set to AVAudioSessionErrorCodeIsBusy to indicate the
299        /// misuse of the API. Prior to iOS 8, the session would have remained active if it had running I/Os
300        /// at the time of the deactivation request.
301        #[unsafe(method(setActive:error:_))]
302        #[unsafe(method_family = none)]
303        pub unsafe fn setActive_error(&self, active: bool) -> Result<(), Retained<NSError>>;
304
305        #[cfg(feature = "AVAudioSessionTypes")]
306        #[unsafe(method(setActive:withOptions:error:_))]
307        #[unsafe(method_family = none)]
308        pub unsafe fn setActive_withOptions_error(
309            &self,
310            active: bool,
311            options: AVAudioSessionSetActiveOptions,
312        ) -> Result<(), Retained<NSError>>;
313
314        #[cfg(all(feature = "AVAudioSessionTypes", feature = "block2"))]
315        /// Asynchronously activate the session.
316        ///
317        /// This is a relatively time consuming operation. The completion handler will be called when the
318        /// activation completes or if an error occurs while attempting to activate the session. If the
319        /// session is configured to use AVAudioSessionRouteSharingPolicyLongFormAudio on watchOS, this
320        /// method will also cause a route picker to be presented to the user in cases where an appropriate
321        /// output route has not already been selected automatically. watchOS apps using
322        /// AVAudioSessionRouteSharingPolicyLongFormAudio should be prepared for this method to fail if no
323        /// eligible audio route can be activated or if the user cancels the route picker view.
324        #[unsafe(method(activateWithOptions:completionHandler:))]
325        #[unsafe(method_family = none)]
326        pub unsafe fn activateWithOptions_completionHandler(
327            &self,
328            options: AVAudioSessionActivationOptions,
329            handler: &block2::DynBlock<dyn Fn(Bool, *mut NSError)>,
330        );
331    );
332}
333
334/// AVAudioSessionHardwareConfiguration.
335/// this category deals with the set of properties that reflect the current state of
336/// audio hardware in the current route.  Applications whose functionality depends on these
337/// properties should reevaluate them any time the route changes.
338impl AVAudioSession {
339    extern_methods!(
340        /// The preferred hardware sample rate for the session. The actual sample rate may be different.
341        #[unsafe(method(setPreferredSampleRate:error:_))]
342        #[unsafe(method_family = none)]
343        pub unsafe fn setPreferredSampleRate_error(
344            &self,
345            sample_rate: c_double,
346        ) -> Result<(), Retained<NSError>>;
347
348        #[unsafe(method(preferredSampleRate))]
349        #[unsafe(method_family = none)]
350        pub unsafe fn preferredSampleRate(&self) -> c_double;
351
352        /// The preferred hardware IO buffer duration in seconds. The actual IO buffer duration may be
353        /// different.
354        #[unsafe(method(setPreferredIOBufferDuration:error:_))]
355        #[unsafe(method_family = none)]
356        pub unsafe fn setPreferredIOBufferDuration_error(
357            &self,
358            duration: NSTimeInterval,
359        ) -> Result<(), Retained<NSError>>;
360
361        #[unsafe(method(preferredIOBufferDuration))]
362        #[unsafe(method_family = none)]
363        pub unsafe fn preferredIOBufferDuration(&self) -> NSTimeInterval;
364
365        /// Sets the number of input channels that the app would prefer for the current route
366        #[unsafe(method(setPreferredInputNumberOfChannels:error:_))]
367        #[unsafe(method_family = none)]
368        pub unsafe fn setPreferredInputNumberOfChannels_error(
369            &self,
370            count: NSInteger,
371        ) -> Result<(), Retained<NSError>>;
372
373        #[unsafe(method(preferredInputNumberOfChannels))]
374        #[unsafe(method_family = none)]
375        pub unsafe fn preferredInputNumberOfChannels(&self) -> NSInteger;
376
377        /// Sets the number of output channels that the app would prefer for the current route
378        #[unsafe(method(setPreferredOutputNumberOfChannels:error:_))]
379        #[unsafe(method_family = none)]
380        pub unsafe fn setPreferredOutputNumberOfChannels_error(
381            &self,
382            count: NSInteger,
383        ) -> Result<(), Retained<NSError>>;
384
385        #[unsafe(method(preferredOutputNumberOfChannels))]
386        #[unsafe(method_family = none)]
387        pub unsafe fn preferredOutputNumberOfChannels(&self) -> NSInteger;
388
389        #[cfg(feature = "AVAudioSessionTypes")]
390        /// Sets the preferred input orientation.
391        /// The input orientation determines which directions will be left and right
392        /// when a built-in mic data source with the AVAudioSessionPolarPatternStereo polar pattern is selected.
393        /// Typically, this orientation should match how the user is holding the device while recording, which will match
394        /// the application's interface orientation when a single app is on the screen.
395        /// The actual input orientation may be different, for example, if another app's session is in control of routing.
396        /// The input orientation is independent of the orientation property of an AVAudioSessionDataSourceDescription.
397        #[unsafe(method(setPreferredInputOrientation:error:_))]
398        #[unsafe(method_family = none)]
399        pub unsafe fn setPreferredInputOrientation_error(
400            &self,
401            orientation: AVAudioStereoOrientation,
402        ) -> Result<(), Retained<NSError>>;
403
404        #[cfg(feature = "AVAudioSessionTypes")]
405        #[unsafe(method(preferredInputOrientation))]
406        #[unsafe(method_family = none)]
407        pub unsafe fn preferredInputOrientation(&self) -> AVAudioStereoOrientation;
408
409        #[cfg(feature = "AVAudioSessionTypes")]
410        /// Describes the orientation of the input data source (valid for the built-in mic input data source when a stereo polar pattern is selected).
411        #[unsafe(method(inputOrientation))]
412        #[unsafe(method_family = none)]
413        pub unsafe fn inputOrientation(&self) -> AVAudioStereoOrientation;
414
415        /// Returns the largest number of audio input channels available for the current route
416        #[unsafe(method(maximumInputNumberOfChannels))]
417        #[unsafe(method_family = none)]
418        pub unsafe fn maximumInputNumberOfChannels(&self) -> NSInteger;
419
420        /// Returns the largest number of audio output channels available for the current route
421        #[unsafe(method(maximumOutputNumberOfChannels))]
422        #[unsafe(method_family = none)]
423        pub unsafe fn maximumOutputNumberOfChannels(&self) -> NSInteger;
424
425        /// A value defined over the range [0.0, 1.0], with 0.0 corresponding to the lowest analog
426        /// gain setting and 1.0 corresponding to the highest analog gain setting.
427        ///
428        /// Attempting to set values outside of the defined range will result in the value being "clamped"
429        /// to a valid input.  This is a global input gain setting that applies to the current input source
430        /// for the entire system. When no applications are using the input gain control, the system will
431        /// restore the default input gain setting for the input source.  Note that some audio accessories,
432        /// such as USB devices, may not have a default value.  This property is only valid if
433        /// inputGainSettable is true.  Note: inputGain is key-value observable.
434        #[unsafe(method(setInputGain:error:_))]
435        #[unsafe(method_family = none)]
436        pub unsafe fn setInputGain_error(&self, gain: c_float) -> Result<(), Retained<NSError>>;
437
438        /// value in range [0.0, 1.0]
439        #[unsafe(method(inputGain))]
440        #[unsafe(method_family = none)]
441        pub unsafe fn inputGain(&self) -> c_float;
442
443        /// True when audio input gain is available.  Some input ports may not provide the ability to set the
444        /// input gain, so check this value before attempting to set input gain.
445        #[unsafe(method(isInputGainSettable))]
446        #[unsafe(method_family = none)]
447        pub unsafe fn isInputGainSettable(&self) -> bool;
448
449        /// True if input hardware is available. Key-value observable.
450        #[unsafe(method(isInputAvailable))]
451        #[unsafe(method_family = none)]
452        pub unsafe fn isInputAvailable(&self) -> bool;
453
454        #[cfg(feature = "AVAudioSessionRoute")]
455        /// DataSource methods are for use with routes that support input or output data source
456        /// selection.
457        ///
458        /// If the attached accessory supports data source selection, the data source properties/methods
459        /// provide for discovery and selection of input and/or output data sources. Note that the
460        /// properties and methods for data source selection below are equivalent to the properties and
461        /// methods on AVAudioSessionPortDescription. The methods below only apply to the currently routed
462        /// ports.
463        ///
464        /// Key-value observable.
465        #[unsafe(method(inputDataSources))]
466        #[unsafe(method_family = none)]
467        pub unsafe fn inputDataSources(
468            &self,
469        ) -> Option<Retained<NSArray<AVAudioSessionDataSourceDescription>>>;
470
471        #[cfg(feature = "AVAudioSessionRoute")]
472        /// Obtain the currently selected input data source.  Will be nil if no data sources are available.
473        #[unsafe(method(inputDataSource))]
474        #[unsafe(method_family = none)]
475        pub unsafe fn inputDataSource(
476            &self,
477        ) -> Option<Retained<AVAudioSessionDataSourceDescription>>;
478
479        #[cfg(feature = "AVAudioSessionRoute")]
480        /// Select a new input data source. Setting a nil value will clear the data source preference.
481        #[unsafe(method(setInputDataSource:error:_))]
482        #[unsafe(method_family = none)]
483        pub unsafe fn setInputDataSource_error(
484            &self,
485            data_source: Option<&AVAudioSessionDataSourceDescription>,
486        ) -> Result<(), Retained<NSError>>;
487
488        #[cfg(feature = "AVAudioSessionRoute")]
489        /// See inputDataSources for background. Key-value observable.
490        #[unsafe(method(outputDataSources))]
491        #[unsafe(method_family = none)]
492        pub unsafe fn outputDataSources(
493            &self,
494        ) -> Option<Retained<NSArray<AVAudioSessionDataSourceDescription>>>;
495
496        #[cfg(feature = "AVAudioSessionRoute")]
497        /// Obtain the currently selected output data source.  Will be nil if no data sources are available.
498        #[unsafe(method(outputDataSource))]
499        #[unsafe(method_family = none)]
500        pub unsafe fn outputDataSource(
501            &self,
502        ) -> Option<Retained<AVAudioSessionDataSourceDescription>>;
503
504        #[cfg(feature = "AVAudioSessionRoute")]
505        /// Select a new output data source. Setting a nil value will clear the data source preference.
506        #[unsafe(method(setOutputDataSource:error:_))]
507        #[unsafe(method_family = none)]
508        pub unsafe fn setOutputDataSource_error(
509            &self,
510            data_source: Option<&AVAudioSessionDataSourceDescription>,
511        ) -> Result<(), Retained<NSError>>;
512
513        /// The current hardware sample rate. Is key-value observable (starting iOS 18.0).
514        #[unsafe(method(sampleRate))]
515        #[unsafe(method_family = none)]
516        pub unsafe fn sampleRate(&self) -> c_double;
517
518        /// The current number of hardware input channels. Is key-value observable.
519        #[unsafe(method(inputNumberOfChannels))]
520        #[unsafe(method_family = none)]
521        pub unsafe fn inputNumberOfChannels(&self) -> NSInteger;
522
523        /// The current number of hardware output channels. Is key-value observable.
524        #[unsafe(method(outputNumberOfChannels))]
525        #[unsafe(method_family = none)]
526        pub unsafe fn outputNumberOfChannels(&self) -> NSInteger;
527
528        /// The current hardware input latency in seconds.
529        #[unsafe(method(inputLatency))]
530        #[unsafe(method_family = none)]
531        pub unsafe fn inputLatency(&self) -> NSTimeInterval;
532
533        /// The current hardware output latency in seconds.
534        #[unsafe(method(outputLatency))]
535        #[unsafe(method_family = none)]
536        pub unsafe fn outputLatency(&self) -> NSTimeInterval;
537
538        /// The current hardware IO buffer duration in seconds.
539        #[unsafe(method(IOBufferDuration))]
540        #[unsafe(method_family = none)]
541        pub unsafe fn IOBufferDuration(&self) -> NSTimeInterval;
542
543        #[cfg(feature = "AVAudioChannelLayout")]
544        /// Get an array of channel layouts that the current route supports.
545        /// This property is only supported when the output is routed to ports of type AVAudioSessionPortCarAudio or AVAudioSessionPortAirPlay
546        /// Otherwise, an empty array will be returned. Note that this will return an empty array if session is inactive.
547        /// Clients should listen to AVAudioSessionRenderingCapabilitiesChangeNotification to be notified when this changes.
548        #[unsafe(method(supportedOutputChannelLayouts))]
549        #[unsafe(method_family = none)]
550        pub unsafe fn supportedOutputChannelLayouts(
551            &self,
552        ) -> Retained<NSArray<AVAudioChannelLayout>>;
553    );
554}
555
556/// Observation.
557impl AVAudioSession {
558    extern_methods!(
559        /// True when another application is playing audio.
560        ///
561        /// Note: As of iOS 8.0, Apple recommends that most applications use
562        /// secondaryAudioShouldBeSilencedHint instead of this property. The otherAudioPlaying property
563        /// will be true if any other audio (including audio from an app using
564        /// AVAudioSessionCategoryAmbient) is playing, whereas the secondaryAudioShouldBeSilencedHint
565        /// property is more restrictive in its consideration of whether primary audio from another
566        /// application is playing.
567        #[unsafe(method(isOtherAudioPlaying))]
568        #[unsafe(method_family = none)]
569        pub unsafe fn isOtherAudioPlaying(&self) -> bool;
570
571        /// True when another application with a non-mixable audio session is playing audio.
572        ///
573        /// Applications may use this property as a hint to silence audio that is secondary to the
574        /// functionality of the application. For example, a game app using AVAudioSessionCategoryAmbient
575        /// may use this property to decide to mute its soundtrack while leaving its sound effects unmuted.
576        /// Note: This property is closely related to AVAudioSessionSilenceSecondaryAudioHintNotification.
577        #[unsafe(method(secondaryAudioShouldBeSilencedHint))]
578        #[unsafe(method_family = none)]
579        pub unsafe fn secondaryAudioShouldBeSilencedHint(&self) -> bool;
580
581        /// The current output volume. Value in range [0.0, 1.0]. Is key-value observable.
582        #[unsafe(method(outputVolume))]
583        #[unsafe(method_family = none)]
584        pub unsafe fn outputVolume(&self) -> c_float;
585
586        #[cfg(feature = "AVAudioSessionTypes")]
587        /// The prompt style is a hint to sessions using AVAudioSessionModeVoicePrompt to alter the type of
588        /// prompts they issue in response to other audio activity on the system, such as Siri and phone
589        /// calls. This property is key-value observable.
590        #[unsafe(method(promptStyle))]
591        #[unsafe(method_family = none)]
592        pub unsafe fn promptStyle(&self) -> AVAudioSessionPromptStyle;
593    );
594}
595
596/// RoutingConfiguration.
597impl AVAudioSession {
598    extern_methods!(
599        #[cfg(feature = "AVAudioSessionRoute")]
600        /// Get the set of input ports that are available for routing.
601        ///
602        /// Note that this property only applies to the session's current category and mode. For
603        /// example, if the session's current category is AVAudioSessionCategoryPlayback, there will be
604        /// no available inputs.
605        #[unsafe(method(availableInputs))]
606        #[unsafe(method_family = none)]
607        pub unsafe fn availableInputs(
608            &self,
609        ) -> Option<Retained<NSArray<AVAudioSessionPortDescription>>>;
610
611        #[cfg(feature = "AVAudioSessionRoute")]
612        /// A description of the current route, consisting of zero or more input ports and zero or more
613        /// output ports
614        #[unsafe(method(currentRoute))]
615        #[unsafe(method_family = none)]
616        pub unsafe fn currentRoute(&self) -> Retained<AVAudioSessionRouteDescription>;
617
618        #[cfg(feature = "AVAudioSessionTypes")]
619        /// Controls whether audio input and output are aggregated. Only valid in combination with
620        /// AVAudioSessionCategoryPlayAndRecord or AVAudioSessionCategoryMultiRoute.
621        ///
622        /// See the AVAudioSessionIOType documentation for a more detailed explanation of why a client may
623        /// want to change the IO type.
624        #[unsafe(method(setAggregatedIOPreference:error:_))]
625        #[unsafe(method_family = none)]
626        pub unsafe fn setAggregatedIOPreference_error(
627            &self,
628            in_io_type: AVAudioSessionIOType,
629        ) -> Result<(), Retained<NSError>>;
630
631        /// Set YES to inform the system if the app can supply multichannel audio content.
632        /// Default value is NO. This property is intended to be used by 'Now Playing' applications.
633        /// See https://developer.apple.com/documentation/mediaplayer/becoming_a_now_playable_app for more information
634        /// about what it means to be a 'Now Playing' application. Typically 'Now Playing' applications will also use
635        /// AVAudioSessionRouteSharingPolicyLongFormAudio or AVAudioSessionRouteSharingPolicyLongFormVideo.
636        #[unsafe(method(setSupportsMultichannelContent:error:_))]
637        #[unsafe(method_family = none)]
638        pub unsafe fn setSupportsMultichannelContent_error(
639            &self,
640            in_value: bool,
641        ) -> Result<(), Retained<NSError>>;
642
643        #[unsafe(method(supportsMultichannelContent))]
644        #[unsafe(method_family = none)]
645        pub unsafe fn supportsMultichannelContent(&self) -> bool;
646
647        /// Use this method to opt in or opt out of interruption on route disconnect policy.
648        ///
649        /// As described in the Audio Session Programming Guide, most media playback apps are expected
650        /// to pause playback if the route change reason is AVAudioSessionRouteChangeReasonOldDeviceUnavailable.
651        ///
652        /// Starting in iOS 17, by default Now Playing sessions will be interrupted if they are active
653        /// when a route change occurs because of a disconnect event. All other sessions will not be
654        /// interrupted due to a disconnect event.
655        #[unsafe(method(setPrefersInterruptionOnRouteDisconnect:error:_))]
656        #[unsafe(method_family = none)]
657        pub unsafe fn setPrefersInterruptionOnRouteDisconnect_error(
658            &self,
659            in_value: bool,
660        ) -> Result<(), Retained<NSError>>;
661
662        /// Indicates if session will be interrupted on route disconnect.
663        #[unsafe(method(prefersInterruptionOnRouteDisconnect))]
664        #[unsafe(method_family = none)]
665        pub unsafe fn prefersInterruptionOnRouteDisconnect(&self) -> bool;
666    );
667}
668
669/// MicrophoneInjection.
670impl AVAudioSession {
671    extern_methods!(
672        #[cfg(feature = "AVAudioSessionTypes")]
673        /// Set the preferred form of audio injection into another app's input stream
674        /// See AVAudioSessionMicrophoneInjectionMode for available modes
675        #[unsafe(method(setPreferredMicrophoneInjectionMode:error:_))]
676        #[unsafe(method_family = none)]
677        pub unsafe fn setPreferredMicrophoneInjectionMode_error(
678            &self,
679            in_value: AVAudioSessionMicrophoneInjectionMode,
680        ) -> Result<(), Retained<NSError>>;
681
682        #[cfg(feature = "AVAudioSessionTypes")]
683        #[unsafe(method(preferredMicrophoneInjectionMode))]
684        #[unsafe(method_family = none)]
685        pub unsafe fn preferredMicrophoneInjectionMode(
686            &self,
687        ) -> AVAudioSessionMicrophoneInjectionMode;
688
689        /// Indicates if microphone injection is available.
690        /// Observe AVAudioSessionMicrophoneInjectionCapabilitiesChangeNotification for changes to this property
691        #[unsafe(method(isMicrophoneInjectionAvailable))]
692        #[unsafe(method_family = none)]
693        pub unsafe fn isMicrophoneInjectionAvailable(&self) -> bool;
694    );
695}
696
697extern "C" {
698    /// Notification sent to registered listeners when the system has interrupted the audio
699    /// session and when the interruption has ended.
700    ///
701    /// Check the notification's userInfo dictionary for the interruption type, which is either
702    /// Begin or End. In the case of an end interruption notification, check the userInfo dictionary
703    /// for AVAudioSessionInterruptionOptions that indicate whether audio playback should resume.
704    /// In the case of a begin interruption notification, the reason for the interruption can be found
705    /// within the info dictionary under the key AVAudioSessionInterruptionReasonKey.
706    ///
707    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosessioninterruptionnotification?language=objc)
708    pub static AVAudioSessionInterruptionNotification: &'static NSNotificationName;
709}
710
711extern "C" {
712    /// Notification sent to registered listeners when an audio route change has occurred.
713    ///
714    /// Check the notification's userInfo dictionary for the route change reason and for a description
715    /// of the previous audio route.
716    ///
717    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosessionroutechangenotification?language=objc)
718    pub static AVAudioSessionRouteChangeNotification: &'static NSNotificationName;
719}
720
721extern "C" {
722    /// Notification sent to registered listeners if the media server is killed.
723    ///
724    /// In the event that the server is killed, take appropriate steps to handle requests that come in
725    /// before the server resets.  See Technical Q
726    /// &A
727    /// QA1749.
728    ///
729    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosessionmediaserviceswerelostnotification?language=objc)
730    pub static AVAudioSessionMediaServicesWereLostNotification: &'static NSNotificationName;
731}
732
733extern "C" {
734    /// Notification sent to registered listeners when the media server restarts.
735    ///
736    /// In the event that the server restarts, take appropriate steps to re-initialize any audio objects
737    /// used by your application.  See Technical Q
738    /// &A
739    /// QA1749.
740    ///
741    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosessionmediaserviceswereresetnotification?language=objc)
742    pub static AVAudioSessionMediaServicesWereResetNotification: &'static NSNotificationName;
743}
744
745extern "C" {
746    /// Notification sent to registered listeners when they are in the foreground with an active
747    /// audio session and primary audio from other applications starts and stops.
748    ///
749    /// Check the notification's userInfo dictionary for the notification type, which is either Begin or
750    /// End. Foreground applications may use this notification as a hint to enable or disable audio that
751    /// is secondary to the functionality of the application. For more information, see the related
752    /// property secondaryAudioShouldBeSilencedHint.
753    ///
754    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosessionsilencesecondaryaudiohintnotification?language=objc)
755    pub static AVAudioSessionSilenceSecondaryAudioHintNotification: &'static NSNotificationName;
756}
757
758extern "C" {
759    /// Notification sent to registered listeners when spatial playback capabilities are changed due to a
760    /// change in user preference.
761    ///
762    /// Check the notification's userInfo dictionary for AVAudioSessionSpatialAudioEnabledKey to check if spatial
763    /// audio is enabled.
764    ///
765    /// Observers of this notification should also observe AVAudioSessionRouteChangeNotification since a route change
766    /// may also result in a change in the ability for the system to play spatial audio. Use
767    /// AVAudioSessionPortDescription's isSpatialAudioEnabled property to check if the current route supports
768    /// spatialized playback.
769    ///
770    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosessionspatialplaybackcapabilitieschangednotification?language=objc)
771    pub static AVAudioSessionSpatialPlaybackCapabilitiesChangedNotification:
772        &'static NSNotificationName;
773}
774
775extern "C" {
776    /// Notification sent to registered listeners when the resolved rendering mode changes.
777    ///
778    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosessionrenderingmodechangenotification?language=objc)
779    pub static AVAudioSessionRenderingModeChangeNotification: &'static NSNotificationName;
780}
781
782extern "C" {
783    /// Notification sent to registered listeners when the rendering capabilities change.
784    ///
785    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosessionrenderingcapabilitieschangenotification?language=objc)
786    pub static AVAudioSessionRenderingCapabilitiesChangeNotification: &'static NSNotificationName;
787}
788
789extern "C" {
790    /// Notification sent to registered listeners when the system's capability to inject audio into input stream is changed
791    ///
792    /// Check the notification's userInfo dictionary for AVAudioSessionMicrophoneInjectionIsAvailableKey to check if microphone
793    /// injection is available. Use AVAudioSession's isMicrophoneInjectionAvailable property to check if microphone injection is available
794    ///
795    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosessionmicrophoneinjectioncapabilitieschangenotification?language=objc)
796    pub static AVAudioSessionMicrophoneInjectionCapabilitiesChangeNotification:
797        &'static NSNotificationName;
798}
799
800extern "C" {
801    /// keys for AVAudioSessionSpatialPlaybackCapabilitiesChangedNotification
802    /// value is an NSNumber whose boolean value indicates if spatial audio enabled.
803    ///
804    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosessionspatialaudioenabledkey?language=objc)
805    pub static AVAudioSessionSpatialAudioEnabledKey: &'static NSString;
806}
807
808extern "C" {
809    /// keys for AVAudioSessionInterruptionNotification
810    /// Value is an NSNumber representing an AVAudioSessionInterruptionType
811    ///
812    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosessioninterruptiontypekey?language=objc)
813    pub static AVAudioSessionInterruptionTypeKey: &'static NSString;
814}
815
816extern "C" {
817    /// Only present for end interruption events.  Value is of type AVAudioSessionInterruptionOptions.
818    ///
819    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosessioninterruptionoptionkey?language=objc)
820    pub static AVAudioSessionInterruptionOptionKey: &'static NSString;
821}
822
823extern "C" {
824    /// Only present in begin interruption events. Value is of type AVAudioSessionInterruptionReason.
825    ///
826    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosessioninterruptionreasonkey?language=objc)
827    pub static AVAudioSessionInterruptionReasonKey: &'static NSString;
828}
829
830extern "C" {
831    /// Only present in begin interruption events, where the interruption is a direct result of the
832    /// application being suspended by the operating sytem. Value is a boolean NSNumber, where a true
833    /// value indicates that the interruption is the result of the application being suspended, rather
834    /// than being interrupted by another audio session.
835    ///
836    /// Starting in iOS 10, the system will deactivate the audio session of most apps in response to the
837    /// app process being suspended. When the app starts running again, it will receive the notification
838    /// that its session has been deactivated by the system. Note that the notification is necessarily
839    /// delayed in time, due to the fact that the application was suspended at the time the session was
840    /// deactivated by the system and the notification can only be delivered once the app is running
841    /// again.
842    ///
843    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosessioninterruptionwassuspendedkey?language=objc)
844    pub static AVAudioSessionInterruptionWasSuspendedKey: &'static NSString;
845}
846
847extern "C" {
848    /// keys for AVAudioSessionRouteChangeNotification
849    /// value is an NSNumber representing an AVAudioSessionRouteChangeReason
850    ///
851    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosessionroutechangereasonkey?language=objc)
852    pub static AVAudioSessionRouteChangeReasonKey: &'static NSString;
853}
854
855extern "C" {
856    /// value is AVAudioSessionRouteDescription *
857    ///
858    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosessionroutechangepreviousroutekey?language=objc)
859    pub static AVAudioSessionRouteChangePreviousRouteKey: &'static NSString;
860}
861
862extern "C" {
863    /// keys for AVAudioSessionSilenceSecondaryAudioHintNotification
864    /// value is an NSNumber representing an AVAudioSessionSilenceSecondaryAudioHintType
865    ///
866    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosessionsilencesecondaryaudiohinttypekey?language=objc)
867    pub static AVAudioSessionSilenceSecondaryAudioHintTypeKey: &'static NSString;
868}
869
870extern "C" {
871    /// keys for AVAudioSessionRenderingModeChangeNotification
872    /// Contains a payload of NSInteger representing the new resolved rendering mode
873    ///
874    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosessionrenderingmodenewrenderingmodekey?language=objc)
875    pub static AVAudioSessionRenderingModeNewRenderingModeKey: &'static NSString;
876}
877
878extern "C" {
879    /// Keys for AVAudioSessionMicrophoneInjectionCapabilitiesChangeNotification
880    ///
881    /// Indicates if microphone injection is available.
882    /// Value is an NSNumber whose boolean value indicates if microphone injection is available.
883    ///
884    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudiosessionmicrophoneinjectionisavailablekey?language=objc)
885    pub static AVAudioSessionMicrophoneInjectionIsAvailableKey: &'static NSString;
886}