Skip to content

Commit f680b5b

Browse files
committed
Clean up docstrings and improve function names
1 parent 163f1a0 commit f680b5b

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

examples/sine_advanced.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ extern crate coreaudio;
55

66
use coreaudio::audio_unit::audio_format::LinearPcmFlags;
77
use coreaudio::audio_unit::macos_helpers::{
8-
audio_unit_from_device_id, find_matching_physical_format, get_default_device_id, get_owner_pid,
8+
audio_unit_from_device_id, find_matching_physical_format, get_default_device_id, get_hogging_pid,
99
get_supported_physical_stream_formats, set_device_physical_stream_format,
10-
set_device_sample_rate, switch_ownership, AliveListener, RateListener,
10+
set_device_sample_rate, toggle_hog_mode, AliveListener, RateListener,
1111
};
1212
use coreaudio::audio_unit::render_callback::{self, data};
1313
use coreaudio::audio_unit::{Element, SampleFormat, Scope, StreamFormat};
@@ -62,12 +62,12 @@ fn main() -> Result<(), coreaudio::Error> {
6262
let audio_unit_id = get_default_device_id(false).unwrap();
6363
let mut audio_unit = audio_unit_from_device_id(audio_unit_id, false)?;
6464

65-
let pid = get_owner_pid(audio_unit_id)?;
65+
let pid = get_hogging_pid(audio_unit_id)?;
6666
if pid != -1 {
6767
println!("Device is owned by another process with pid {}!", pid);
6868
} else {
6969
println!("Device is free, trying to get exclusive access..");
70-
let new_pid = switch_ownership(audio_unit_id)?;
70+
let new_pid = toggle_hog_mode(audio_unit_id)?;
7171
let process_id = process::id();
7272
if new_pid == process_id as i32 {
7373
println!("We have exclusive access.");
@@ -198,12 +198,12 @@ fn main() -> Result<(), coreaudio::Error> {
198198
println!("alive state: {}", alive_listener.is_alive());
199199
}
200200

201-
// Release exclusive access, not really needed as the process anyway exits after this.
202-
let owner_pid = get_owner_pid(audio_unit_id)?;
201+
// Release exclusive access, not really needed as the process exits anyway after this.
202+
let owner_pid = get_hogging_pid(audio_unit_id)?;
203203
let process_id = process::id();
204204
if owner_pid == process_id as i32 {
205205
println!("Releasing exclusive access");
206-
let new_pid = switch_ownership(audio_unit_id)?;
206+
let new_pid = toggle_hog_mode(audio_unit_id)?;
207207
if new_pid == -1 {
208208
println!("Exclusive access released.");
209209
} else {

src/audio_unit/macos_helpers.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -728,11 +728,10 @@ impl AliveListener {
728728
}
729729
}
730730

731-
/// Hog mode.
732-
/// Get the pid of the process that currently owns
733-
/// exclusive access to a device.
734-
/// A value of -1 means no process owns exclusive access.
735-
pub fn get_owner_pid(device_id: AudioDeviceID) -> Result<pid_t, Error> {
731+
/// Helper for hog mode (exclusive access).
732+
/// Get the pid of the process that currently owns exclusive access to a device.
733+
/// A pid value of -1 means no process owns exclusive access.
734+
pub fn get_hogging_pid(device_id: AudioDeviceID) -> Result<pid_t, Error> {
736735
// Get available formats.
737736
let property_address = AudioObjectPropertyAddress {
738737
mSelector: kAudioDevicePropertyHogMode,
@@ -756,14 +755,14 @@ pub fn get_owner_pid(device_id: AudioDeviceID) -> Result<pid_t, Error> {
756755
Ok(pid)
757756
}
758757

759-
/// Hog mode.
760-
/// Switch the exclusive access to a device.
758+
/// Helper for hog mode (exclusive access).
759+
/// Toggle hog mode for a device.
761760
/// If no process owns exclusive access, then the calling process takes ownership.
762761
/// If the calling process already has ownership, this is released.
763762
/// If another process owns access, then nothing will happen.
764763
/// Returns the pid of the new owning process.
765-
/// A value of -1 means no process owns exclusive access.
766-
pub fn switch_ownership(device_id: AudioDeviceID) -> Result<pid_t, Error> {
764+
/// A pid value of -1 means no process owns exclusive access.
765+
pub fn toggle_hog_mode(device_id: AudioDeviceID) -> Result<pid_t, Error> {
767766
// Get available formats.
768767
let property_address = AudioObjectPropertyAddress {
769768
mSelector: kAudioDevicePropertyHogMode,

0 commit comments

Comments
 (0)