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 `AVAudioApplicationMuteStateKey`
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
113extern_conformance!(
114    unsafe impl NSObjectProtocol for AVAudioApplication {}
115);
116
117impl AVAudioApplication {
118    extern_methods!(
119        /// Returns the singleton instance
120        #[unsafe(method(sharedInstance))]
121        #[unsafe(method_family = none)]
122        pub unsafe fn sharedInstance() -> Retained<AVAudioApplication>;
123
124        /// See: `sharedInstance`
125        #[unsafe(method(init))]
126        #[unsafe(method_family = init)]
127        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
128
129        /// Set the muted/unmuted state of the application's audio input. When set true, inputs
130        /// (microphone etc.) of all audio clients relating to this application will have their samples zeroed out.
131        ///
132        /// Note: - this is per-application input muting and doesn't affect the hardware mute state.
133        #[unsafe(method(setInputMuted:error:_))]
134        #[unsafe(method_family = none)]
135        pub unsafe fn setInputMuted_error(&self, muted: bool) -> Result<(), Retained<NSError>>;
136
137        /// Get the input muted state - return value is boolean 0 for unmuted or value 1 for muted (input samples zeroed out)
138        ///
139        /// This property is not atomic.
140        ///
141        /// # Safety
142        ///
143        /// This might not be thread-safe.
144        #[unsafe(method(isInputMuted))]
145        #[unsafe(method_family = none)]
146        pub unsafe fn isInputMuted(&self) -> bool;
147
148        #[cfg(feature = "block2")]
149        /// Provide a block that implements your app's input (microphone) muting logic (macOS only). The block will be called
150        /// whenever the input mute state changes, either due to changing the `AVAudioApplication.inputMute` property on
151        /// this API, or due to a Bluetooth audio accessory gesture (certain AirPods / Beats headphones) changing the mute state.
152        ///
153        ///
154        /// Parameter `inputMuteHandler`: block that will be called upon every input mute state change. If the boolean `inputShouldBeMuted`
155        /// is true, your block should mute all input/microphone samples until the next time the handler is called. Your block should return
156        /// a value of YES if successful, or in exceptional cases return a NO value if the mute action was unsuccesful.
157        /// Since the input mute handling logic should happen a single place, subsequent calls to this method will overwrite any previously
158        /// 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.
159        ///
160        ///
161        /// Note: This is available on macOS only - for all other platforms input muting will be handled internally. It is recommended only to
162        /// perform your input muting logic within this block, and to perform your UI updates for input mute state changes within the handler
163        /// for AVAudioApplicationInputMuteStateChangeNotification. This handler should be set by the process doing the call's audio I/O.
164        #[unsafe(method(setInputMuteStateChangeHandler:error:_))]
165        #[unsafe(method_family = none)]
166        pub unsafe fn setInputMuteStateChangeHandler_error(
167            &self,
168            input_mute_handler: Option<&block2::DynBlock<dyn Fn(Bool) -> Bool>>,
169        ) -> Result<(), Retained<NSError>>;
170
171        /// Returns an enum indicating whether the user has granted or denied permission to record, or has
172        /// not been asked
173        #[unsafe(method(recordPermission))]
174        #[unsafe(method_family = none)]
175        pub unsafe fn recordPermission(&self) -> AVAudioApplicationRecordPermission;
176
177        #[cfg(feature = "block2")]
178        /// Checks to see if calling process has permission to record audio.
179        ///
180        /// The 'response' block will be called immediately if permission has already been granted or
181        /// denied.  Otherwise, it presents a dialog to notify the user and allow them to choose, and calls
182        /// the block once the UI has been dismissed.  'granted' indicates whether permission has been
183        /// granted. Note that the block may be called in a different thread context.
184        #[unsafe(method(requestRecordPermissionWithCompletionHandler:))]
185        #[unsafe(method_family = none)]
186        pub unsafe fn requestRecordPermissionWithCompletionHandler(
187            response: &block2::DynBlock<dyn Fn(Bool)>,
188        );
189
190        /// Returns an enum indicating whether the user has granted or denied permission to inject audio into input,
191        /// or has not been asked
192        #[unsafe(method(microphoneInjectionPermission))]
193        #[unsafe(method_family = none)]
194        pub unsafe fn microphoneInjectionPermission(
195            &self,
196        ) -> AVAudioApplicationMicrophoneInjectionPermission;
197
198        #[cfg(feature = "block2")]
199        /// Checks to see if calling process has permission to inject audio to input stream.
200        ///
201        /// The 'response' block will be called immediately if permission has already been granted or
202        /// denied or if the service is disabled by the user.  Otherwise, it presents a dialog to notify the
203        /// user and allow them to choose, and calls the block once the UI has been dismissed.
204        /// 'granted' indicates whether permission has been granted. Note that the block may be
205        /// called in a different thread context.
206        #[unsafe(method(requestMicrophoneInjectionPermissionWithCompletionHandler:))]
207        #[unsafe(method_family = none)]
208        pub unsafe fn requestMicrophoneInjectionPermissionWithCompletionHandler(
209            response: &block2::DynBlock<dyn Fn(AVAudioApplicationMicrophoneInjectionPermission)>,
210        );
211    );
212}
213
214/// Methods declared on superclass `NSObject`.
215impl AVAudioApplication {
216    extern_methods!(
217        #[unsafe(method(new))]
218        #[unsafe(method_family = new)]
219        pub unsafe fn new() -> Retained<Self>;
220    );
221}