objc2_avf_audio/generated/
AVAudioApplication.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
10/// These are the values returned by recordPermission.
11///
12/// The user has not yet been asked for permission.
13///
14/// The user has been asked and has denied permission.
15///
16/// The user has been asked and has granted permission.
17///
18/// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudioapplicationrecordpermission?language=objc)
19// NS_ENUM
20#[repr(transparent)]
21#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
22pub struct AVAudioApplicationRecordPermission(pub NSInteger);
23impl AVAudioApplicationRecordPermission {
24    #[doc(alias = "AVAudioApplicationRecordPermissionUndetermined")]
25    pub const Undetermined: Self = Self(0x756e6474);
26    #[doc(alias = "AVAudioApplicationRecordPermissionDenied")]
27    pub const Denied: Self = Self(0x64656e79);
28    #[doc(alias = "AVAudioApplicationRecordPermissionGranted")]
29    pub const Granted: Self = Self(0x67726e74);
30}
31
32unsafe impl Encode for AVAudioApplicationRecordPermission {
33    const ENCODING: Encoding = NSInteger::ENCODING;
34}
35
36unsafe impl RefEncode for AVAudioApplicationRecordPermission {
37    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
38}
39
40/// These are the values returned by microphoneInjectionPermission.
41///
42/// The user has disabled this service for all apps.
43///
44/// The user has not yet been asked for permission.
45///
46/// The user has been asked and has denied permission.
47///
48/// The user has been asked and has granted permission.
49///
50/// Introduced: ios(18.2) visionos(2.2)
51///
52/// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudioapplicationmicrophoneinjectionpermission?language=objc)
53// NS_ENUM
54#[repr(transparent)]
55#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
56pub struct AVAudioApplicationMicrophoneInjectionPermission(pub NSInteger);
57impl AVAudioApplicationMicrophoneInjectionPermission {
58    #[doc(alias = "AVAudioApplicationMicrophoneInjectionPermissionServiceDisabled")]
59    pub const ServiceDisabled: Self = Self(0x73726473);
60    #[doc(alias = "AVAudioApplicationMicrophoneInjectionPermissionUndetermined")]
61    pub const Undetermined: Self = Self(0x756e6474);
62    #[doc(alias = "AVAudioApplicationMicrophoneInjectionPermissionDenied")]
63    pub const Denied: Self = Self(0x64656e79);
64    #[doc(alias = "AVAudioApplicationMicrophoneInjectionPermissionGranted")]
65    pub const Granted: Self = Self(0x67726e74);
66}
67
68unsafe impl Encode for AVAudioApplicationMicrophoneInjectionPermission {
69    const ENCODING: Encoding = NSInteger::ENCODING;
70}
71
72unsafe impl RefEncode for AVAudioApplicationMicrophoneInjectionPermission {
73    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
74}
75
76extern "C" {
77    /// Notification sent to registered listeners when the application's input is muted
78    /// or unmuted.
79    ///
80    /// Check the notification's userInfo dictionary for the mute state AVAudioApplicationInputMuteStateKey
81    /// which will have a boolean value 0 for unmuted or value 1 for muted.
82    ///
83    /// Note: this notification will only be dispatched for state changes when there is an active record session (i.e. record or playAndRecord category).
84    /// Setting the `inputMuted` state while the record session is not active is allowed and will be stored, but it will not trigger a notification for the
85    /// state change. When the record session subsequently goes active, the `inputMuted` state will be applied, and this notification will be dispatched
86    /// with the latest input muted state.
87    ///
88    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudioapplicationinputmutestatechangenotification?language=objc)
89    pub static AVAudioApplicationInputMuteStateChangeNotification: &'static NSNotificationName;
90}
91
92extern "C" {
93    /// Keys for AVAudioApplicationInputMuteStateChangeNotification
94    /// Value is NSNumber type with boolean value 0 for unmuted or value 1 for muted (samples zeroed out)
95    ///
96    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudioapplicationmutestatekey?language=objc)
97    pub static AVAudioApplicationMuteStateKey: &'static NSString;
98}
99
100extern_class!(
101    /// Class containing methods that relate to an application bundle's audio (i.e. a collection of one or more AVAudioSession instances)
102    ///
103    /// See also [Apple's documentation](https://developer.apple.com/documentation/avfaudio/avaudioapplication?language=objc)
104    #[unsafe(super(NSObject))]
105    #[derive(Debug, PartialEq, Eq, Hash)]
106    pub struct AVAudioApplication;
107);
108
109unsafe impl Send for AVAudioApplication {}
110
111unsafe impl Sync for AVAudioApplication {}
112
113unsafe impl NSObjectProtocol for AVAudioApplication {}
114
115impl AVAudioApplication {
116    extern_methods!(
117        /// Returns the singleton instance
118        #[unsafe(method(sharedInstance))]
119        #[unsafe(method_family = none)]
120        pub unsafe fn sharedInstance() -> Retained<AVAudioApplication>;
121
122        /// See: `sharedInstance`
123        #[unsafe(method(init))]
124        #[unsafe(method_family = init)]
125        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
126
127        /// Set the muted/unmuted state of the application's audio input. When set true, inputs
128        /// (microphone etc.) of all audio clients relating to this application will have their samples zeroed out.
129        ///
130        /// Note: - this is per-application input muting and doesn't affect the hardware mute state.
131        #[unsafe(method(setInputMuted:error:_))]
132        #[unsafe(method_family = none)]
133        pub unsafe fn setInputMuted_error(&self, muted: bool) -> Result<(), Retained<NSError>>;
134
135        /// Get the input muted state - return value is boolean 0 for unmuted or value 1 for muted (input samples zeroed out)
136        #[unsafe(method(isInputMuted))]
137        #[unsafe(method_family = none)]
138        pub unsafe fn isInputMuted(&self) -> bool;
139
140        #[cfg(feature = "block2")]
141        /// Provide a block that implements your app's input (microphone) muting logic (macOS only). The block will be called
142        /// whenever the input mute state changes, either due to changing the `AVAudioApplication.inputMute` property on
143        /// this API, or due to a Bluetooth audio accessory gesture (certain AirPods / Beats headphones) changing the mute state.
144        ///
145        ///
146        /// Parameter `inputMuteHandler`: block that will be called upon every input mute state change. If the boolean `inputShouldBeMuted`
147        /// is true, your block should mute all input/microphone samples until the next time the handler is called. Your block should return
148        /// a value of YES if successful, or in exceptional cases return a NO value if the mute action was unsuccesful.
149        /// Since the input mute handling logic should happen a single place, subsequent calls to this method will overwrite any previously
150        /// registered block with the one provided. A nil value may be provided to cancel the block being called, e.g. at end of call lifecycle.
151        ///
152        ///
153        /// Note: This is available on macOS only - for all other platforms input muting will be handled internally. It is recommended only to
154        /// perform your input muting logic within this block, and to perform your UI updates for input mute state changes within the handler
155        /// for AVAudioApplicationInputMuteStateChangeNotification.
156        #[unsafe(method(setInputMuteStateChangeHandler:error:_))]
157        #[unsafe(method_family = none)]
158        pub unsafe fn setInputMuteStateChangeHandler_error(
159            &self,
160            input_mute_handler: Option<&block2::Block<dyn Fn(Bool) -> Bool>>,
161        ) -> Result<(), Retained<NSError>>;
162
163        /// Returns an enum indicating whether the user has granted or denied permission to record, or has
164        /// not been asked
165        #[unsafe(method(recordPermission))]
166        #[unsafe(method_family = none)]
167        pub unsafe fn recordPermission(&self) -> AVAudioApplicationRecordPermission;
168
169        #[cfg(feature = "block2")]
170        /// Checks to see if calling process has permission to record audio.
171        ///
172        /// The 'response' block will be called immediately if permission has already been granted or
173        /// denied.  Otherwise, it presents a dialog to notify the user and allow them to choose, and calls
174        /// the block once the UI has been dismissed.  'granted' indicates whether permission has been
175        /// granted. Note that the block may be called in a different thread context.
176        #[unsafe(method(requestRecordPermissionWithCompletionHandler:))]
177        #[unsafe(method_family = none)]
178        pub unsafe fn requestRecordPermissionWithCompletionHandler(
179            response: &block2::Block<dyn Fn(Bool)>,
180        );
181
182        /// Returns an enum indicating whether the user has granted or denied permission to inject audio into input,
183        /// or has not been asked
184        #[unsafe(method(microphoneInjectionPermission))]
185        #[unsafe(method_family = none)]
186        pub unsafe fn microphoneInjectionPermission(
187            &self,
188        ) -> AVAudioApplicationMicrophoneInjectionPermission;
189
190        #[cfg(feature = "block2")]
191        /// Checks to see if calling process has permission to inject audio to input stream.
192        ///
193        /// The 'response' block will be called immediately if permission has already been granted or
194        /// denied or if the service is disabled by the user.  Otherwise, it presents a dialog to notify the
195        /// user and allow them to choose, and calls the block once the UI has been dismissed.
196        /// 'granted' indicates whether permission has been granted. Note that the block may be
197        /// called in a different thread context.
198        #[unsafe(method(requestMicrophoneInjectionPermissionWithCompletionHandler:))]
199        #[unsafe(method_family = none)]
200        pub unsafe fn requestMicrophoneInjectionPermissionWithCompletionHandler(
201            response: &block2::Block<dyn Fn(AVAudioApplicationMicrophoneInjectionPermission)>,
202        );
203    );
204}
205
206/// Methods declared on superclass `NSObject`.
207impl AVAudioApplication {
208    extern_methods!(
209        #[unsafe(method(new))]
210        #[unsafe(method_family = new)]
211        pub unsafe fn new() -> Retained<Self>;
212    );
213}