Skip to content

Commit 840f69c

Browse files
authored
Provide a way to disable inclusion of code that relies on private APIs (#283)
Applications that rely on private APIs may and will get rejected by Apple. This change introduces a feature 'no-private-apis' that, when turned on, ensures that no private APIs are used. Currently, the only private API in the codebase seems to be AudioDeviceDuck, but in the future there may be more. Caveat: when 'no-private-apis' is turned on, calls to disable audio device ducking will be removed, but no alternative method to disable ducking is provided.
1 parent baeb956 commit 840f69c

4 files changed

Lines changed: 11 additions & 0 deletions

File tree

‎Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ audio-dump = []
2929
vpio-forcelist = []
3030
gecko-in-tree = ["cubeb-backend/gecko-in-tree"]
3131
tsan-annotations = []
32+
no-private-apis = ["coreaudio-sys-utils/no-private-apis"]
3233

3334
# Workaround for https://github.com/rust-lang/cargo/issues/6745 to allow this
3435
# Cargo.toml file to appear under a subdirectory of a workspace without being in

‎coreaudio-sys-utils/Cargo.toml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ core-foundation-sys = { version = "0.8" }
1212
default-features = false
1313
features = ["audio_unit", "core_audio", "io_kit_audio"]
1414
version = "0.2.18"
15+
16+
[features]
17+
no-private-apis = []

‎coreaudio-sys-utils/src/audio_device_extensions.rs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
#[allow(unused_imports)]
12
use crate::dispatch::*;
3+
#[allow(unused_imports)]
24
use coreaudio_sys::*;
35

46
// See https://opensource.apple.com/source/WebCore/WebCore-7604.5.6/platform/spi/cf/CoreAudioSPI.h.auto.html
57
// Per https://github.com/WebKit/WebKit/commit/7c4c851bc80f14b4cf907f76d65baee013a45eea,
68
// this first appeared in MacOS 10.13 and iOS 11.0.
9+
#[cfg(not(feature = "no-private-apis"))]
710
extern "C" {
811
fn AudioDeviceDuck(
912
inDevice: AudioDeviceID,
@@ -14,6 +17,7 @@ extern "C" {
1417
}
1518

1619
// See https://github.com/mozilla/cubeb-coreaudio-rs/issues/237
20+
#[cfg(not(feature = "no-private-apis"))]
1721
#[allow(clippy::not_unsafe_ptr_arg_deref)]
1822
pub fn audio_device_duck(
1923
in_device: AudioDeviceID,

‎src/backend/mod.rs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use self::aggregate_device::*;
2121
use self::auto_release::*;
2222
use self::buffer_manager::*;
2323
use self::coreaudio_sys_utils::aggregate_device::*;
24+
#[allow(unused_imports)]
2425
use self::coreaudio_sys_utils::audio_device_extensions::*;
2526
use self::coreaudio_sys_utils::audio_object::*;
2627
use self::coreaudio_sys_utils::audio_unit::*;
@@ -1515,6 +1516,7 @@ fn create_voiceprocessing_audiounit() -> Result<VoiceProcessingUnit> {
15151516
return Err(Error::Error);
15161517
}
15171518

1519+
#[cfg(not(feature = "no-private-apis"))]
15181520
match get_default_device(DeviceType::OUTPUT) {
15191521
None => {
15201522
cubeb_log!("Could not get default output device in order to undo vpio ducking");
@@ -4423,6 +4425,7 @@ impl<'ctx> CoreStreamData<'ctx> {
44234425
}
44244426
}
44254427

4428+
#[cfg(not(feature = "no-private-apis"))]
44264429
if using_voice_processing_unit {
44274430
// The VPIO AudioUnit automatically ducks other audio streams on the VPIO
44284431
// output device. Its ramp duration is 0.5s when ducking, so unduck similarly

0 commit comments

Comments
 (0)