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