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