Bug 1627376 - Update cubeb-coreaudio to ea9e5aa. r=padenot

Pick commits:
- ea9e5aa: Implement a API to get `groupd_id` with special case handling (#69)
- d67d4d2: Revise prepush when deleting branch (#76)
- e5b0f97:  Stop test immediately when error happens (#77)
- 98e59e5: Migrate from travis-ci.org to travis-ci.com

Differential Revision: https://phabricator.services.mozilla.com/D69647

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Chun-Min Chang 2020-04-06 12:43:21 +00:00
parent d623691c7b
commit 34ff7578a8
13 changed files with 373 additions and 126 deletions

View File

@ -80,7 +80,7 @@ rev = "5e870faf6f95d79d11efc813e56370ad124bbed5"
[source."https://github.com/ChunMinChang/cubeb-coreaudio-rs"]
git = "https://github.com/ChunMinChang/cubeb-coreaudio-rs"
replace-with = "vendored-sources"
rev = "432259ab53295ca98a2df0c0e6c73d132b273e97"
rev = "ea9e5aa3e6014f219cf5fa0690bc4b06916f0b09"
[source.crates-io]
replace-with = "vendored-sources"

4
Cargo.lock generated
View File

@ -689,7 +689,7 @@ dependencies = [
[[package]]
name = "coreaudio-sys-utils"
version = "0.1.0"
source = "git+https://github.com/ChunMinChang/cubeb-coreaudio-rs?rev=432259ab53295ca98a2df0c0e6c73d132b273e97#432259ab53295ca98a2df0c0e6c73d132b273e97"
source = "git+https://github.com/ChunMinChang/cubeb-coreaudio-rs?rev=ea9e5aa3e6014f219cf5fa0690bc4b06916f0b09#ea9e5aa3e6014f219cf5fa0690bc4b06916f0b09"
dependencies = [
"core-foundation-sys",
"coreaudio-sys",
@ -926,7 +926,7 @@ dependencies = [
[[package]]
name = "cubeb-coreaudio"
version = "0.1.0"
source = "git+https://github.com/ChunMinChang/cubeb-coreaudio-rs?rev=432259ab53295ca98a2df0c0e6c73d132b273e97#432259ab53295ca98a2df0c0e6c73d132b273e97"
source = "git+https://github.com/ChunMinChang/cubeb-coreaudio-rs?rev=ea9e5aa3e6014f219cf5fa0690bc4b06916f0b09#ea9e5aa3e6014f219cf5fa0690bc4b06916f0b09"
dependencies = [
"atomic",
"audio-mixer",

View File

@ -1 +1 @@
{"files":{".editorconfig":"4e53b182bcc78b83d7e1b5c03efa14d22d4955c4ed2514d1ba4e99c1eb1a50ba",".githooks/pre-push":"da1b815382649512784ff98e648cc06a7727b7e3fce1a04ba448af3db9e42c23",".travis.yml":"dc07bac53f70f16c9bdf52264bdc58500ae6018c1b4c567bc7642f6b4ca3cc35","Cargo.toml":"502a60129a9416424a8d1581a986caf87bdec5bca8085eb8b31aa45c445a472c","LICENSE":"6e6f56aff5bbf3cbc60747e152fb1a719bd0716aaf6d711c554f57d92e96297c","README.md":"b791d43cbea873bc199e3b4c26e776b0068e6dd1f8307140cc1f5b63611dedd9","install_git_hook.sh":"d38c8e51e636f6b90b489621ac34ccd1d1b1f40dccce3d178ed1da1c5068f16d","install_rustfmt_clippy.sh":"4ae90d8dcb9757cb3ae4ae142ef80e5377c0dde61c63f4a3c32418646e80ca7b","run_device_tests.sh":"e66d32da5439818eee30fc5e7ed9ab9990723ffafe684870efe82dac11be07ef","run_sanitizers.sh":"ccb6ec9e4f25118220fb4c661c2bea711307e280bba201ee8ed2e4ac8554cde8","run_tests.sh":"da1fae5a4508e5a8b2d9797200958af54d79262fc688b87ab112d91c6d495c7d","src/backend/aggregate_device.rs":"ae21129aa6b3c7bd3376751b6a94d1ebe6c9f7afcd1db3107fb4d703d04da6b3","src/backend/auto_release.rs":"050fdcee74cf46b9a8a85a877e166d72a853d33220f59cf734cbb6ea09daa441","src/backend/buffer_manager.rs":"ef5214f6e7e306c20eef86718ad02a522fb805a1cbc83a292e4aebf714d37c5d","src/backend/device_property.rs":"b37ddc4ad853b3e9f2dc48272bb3b898e38ee0e9af006871260e62edcf1b4be6","src/backend/mixer.rs":"0c237bd5ca63b028c4b22ddc5bc026d7e21c0fa9b4e337f00b6131ed0a0806a5","src/backend/mod.rs":"fe07f4629200dc8a0bad5a2e80e6eb212191d0b62e3e5192d47eaa46bcbd338a","src/backend/resampler.rs":"fd1281d28a4db1659d2f75e43b8457651745e1b6eb5a53a77f04d752135f6dc7","src/backend/tests/aggregate_device.rs":"107f5c637844cd5ae43d2b42cec4ef3369bb702751586078c0a9d50f039161cd","src/backend/tests/api.rs":"baf6bef2f9216be47dea9b3776b853e2e0c688242d96efb111e1e4245df8cd98","src/backend/tests/backlog.rs":"3b189a7e036543c467cc242af0ed3332721179ee2b1c8847a6db563546f1ac52","src/backend/tests/device_change.rs":"8261f561f69dabd374ac47d69aa484812b65070a9e9581dfb2605e8404eaad6d","src/backend/tests/device_property.rs":"b1a9ae79aa5b9a3f180040d0ef0954b134680d586882d2062c5e017b555bff57","src/backend/tests/interfaces.rs":"14943e84a79976a7ef52882edeb9330350705d5190db6647f98b4ffa851a8396","src/backend/tests/manual.rs":"dc707836dab31f83d4b325afbc4dc4c8104ac8036e87f59ade3309ee83fe2d3f","src/backend/tests/mod.rs":"8dba770023d7f9c4228f0e11915347f0e07da5fd818e3ee4478c4b197af9aa2a","src/backend/tests/parallel.rs":"f9e1883660d6146b6e5075806561f5f689810e25c5e7764dfd28c9b939821a49","src/backend/tests/tone.rs":"16150438317ce501986734167b5fb97bfec567228acbcd8f3b4c4484c22f29e0","src/backend/tests/utils.rs":"1bb99ef71d3c18545bca49767e7b6bfffbe11896246994f41be7ed372772fd48","src/backend/utils.rs":"5ce1b753af0ffb654b6b2038d649aea88eebd27390a607a6d5988a9e40a4a717","src/capi.rs":"21b66b70545bf04ec719928004d1d9adb45b24ced51288f5b2993d79aaf78f5f","src/lib.rs":"5e586d45cd6b3722f0a6736d9252593299269817a153eef1930a5fb9bfbb56f5","todo.md":"29545b4d9c516396f82bd392797e2713d4602036eaba0f151b384af764f8515f"},"package":null}
{"files":{".editorconfig":"4e53b182bcc78b83d7e1b5c03efa14d22d4955c4ed2514d1ba4e99c1eb1a50ba",".githooks/pre-push":"8b8b26544cd56f54c0c33812551f786bb25cb08c86dbfeb6bf3daad881c826a1",".travis.yml":"dc07bac53f70f16c9bdf52264bdc58500ae6018c1b4c567bc7642f6b4ca3cc35","Cargo.toml":"502a60129a9416424a8d1581a986caf87bdec5bca8085eb8b31aa45c445a472c","LICENSE":"6e6f56aff5bbf3cbc60747e152fb1a719bd0716aaf6d711c554f57d92e96297c","README.md":"7ad20571c123054867aa4b924dce75baaee478cb1386d66f2ddb323c44f7d195","install_git_hook.sh":"d38c8e51e636f6b90b489621ac34ccd1d1b1f40dccce3d178ed1da1c5068f16d","install_rustfmt_clippy.sh":"4ae90d8dcb9757cb3ae4ae142ef80e5377c0dde61c63f4a3c32418646e80ca7b","run_device_tests.sh":"4b7d65eb638c1a278ffc8ecb6d30d47b3b8405392e976cae38c6f744e2bed532","run_sanitizers.sh":"2f0934ba01cbcd74485f19d50147f6b604cf9730bbd3a3d3f3d958e40d0f799f","run_tests.sh":"ae341fc9cbd700699b838331e5c7792d6120fc771b612e9473a87f5d7900174e","src/backend/aggregate_device.rs":"ae21129aa6b3c7bd3376751b6a94d1ebe6c9f7afcd1db3107fb4d703d04da6b3","src/backend/auto_release.rs":"050fdcee74cf46b9a8a85a877e166d72a853d33220f59cf734cbb6ea09daa441","src/backend/buffer_manager.rs":"ef5214f6e7e306c20eef86718ad02a522fb805a1cbc83a292e4aebf714d37c5d","src/backend/device_property.rs":"d43642ea6e5f40e29c2a59ec7d81b42c154134685e417585045785359aa31686","src/backend/mixer.rs":"0c237bd5ca63b028c4b22ddc5bc026d7e21c0fa9b4e337f00b6131ed0a0806a5","src/backend/mod.rs":"b6ff0d6eea8ba71cffec41d28a653d109789d8d0e6bc3a739689a180d6767268","src/backend/resampler.rs":"fd1281d28a4db1659d2f75e43b8457651745e1b6eb5a53a77f04d752135f6dc7","src/backend/tests/aggregate_device.rs":"107f5c637844cd5ae43d2b42cec4ef3369bb702751586078c0a9d50f039161cd","src/backend/tests/api.rs":"839bc8d082b0c07e382c62a23eee889ecc4161bd3fb3d324d58183ea5e1ad975","src/backend/tests/backlog.rs":"3b189a7e036543c467cc242af0ed3332721179ee2b1c8847a6db563546f1ac52","src/backend/tests/device_change.rs":"8261f561f69dabd374ac47d69aa484812b65070a9e9581dfb2605e8404eaad6d","src/backend/tests/device_property.rs":"373f76d3bee83b263db3f02be3b94b408bdf852d84e4b5153273fda34b11a374","src/backend/tests/interfaces.rs":"14943e84a79976a7ef52882edeb9330350705d5190db6647f98b4ffa851a8396","src/backend/tests/manual.rs":"dc707836dab31f83d4b325afbc4dc4c8104ac8036e87f59ade3309ee83fe2d3f","src/backend/tests/mod.rs":"8dba770023d7f9c4228f0e11915347f0e07da5fd818e3ee4478c4b197af9aa2a","src/backend/tests/parallel.rs":"f9e1883660d6146b6e5075806561f5f689810e25c5e7764dfd28c9b939821a49","src/backend/tests/tone.rs":"16150438317ce501986734167b5fb97bfec567228acbcd8f3b4c4484c22f29e0","src/backend/tests/utils.rs":"1bb99ef71d3c18545bca49767e7b6bfffbe11896246994f41be7ed372772fd48","src/backend/utils.rs":"5ce1b753af0ffb654b6b2038d649aea88eebd27390a607a6d5988a9e40a4a717","src/capi.rs":"21b66b70545bf04ec719928004d1d9adb45b24ced51288f5b2993d79aaf78f5f","src/lib.rs":"5e586d45cd6b3722f0a6736d9252593299269817a153eef1930a5fb9bfbb56f5","todo.md":"29545b4d9c516396f82bd392797e2713d4602036eaba0f151b384af764f8515f"},"package":null}

View File

@ -1,4 +1,4 @@
#!/bin/sh -e
#!/bin/bash -e
# An example hook script to verify what is about to be pushed. Called by "git
# push" after it has checked the remote status, but before anything has been
@ -16,8 +16,30 @@
#
# <local ref> <local sha1> <remote ref> <remote sha1>
remote="$1"
url="$2"
REMOTE="$1"
URL="$2"
PUSH_COMMAND=$(ps -ocommand= -p $PPID)
IS_DESTRUCTIVE="\-\-delete|\-f"
PROTECTED_BRANCH="trailblazer"
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
WILL_DELETE_PROTECTED_BRANCH=":$PROTECTED_BRANCH"
if [[ $PUSH_COMMAND =~ $IS_DESTRUCTIVE ]]; then
if [ $CURRENT_BRANCH = $PROTECTED_BRANCH ] || [[ $PUSH_COMMAND =~ $PROTECTED_BRANCH ]]; then
echo "'$PROTECTED_BRANCH' cannot be deleted!"
exit 1
fi
exit 0
fi
if [[ $PUSH_COMMAND =~ $WILL_DELETE_PROTECTED_BRANCH ]]; then
echo "'$PROTECTED_BRANCH' cannot be deleted!"
exit 1
fi
cargo fmt -- --check || (echo "Please run 'cargo fmt'"; false);

View File

@ -1,6 +1,6 @@
# cubeb-coreaudio-rs
[![Build Status](https://travis-ci.org/ChunMinChang/cubeb-coreaudio-rs.svg?branch=trailblazer)](https://travis-ci.org/ChunMinChang/cubeb-coreaudio-rs)
[![Build Status](https://api.travis-ci.com/ChunMinChang/cubeb-coreaudio-rs.svg?branch=trailblazer)](https://travis-ci.com/github/ChunMinChang/cubeb-coreaudio-rs)
*Rust* implementation of [Cubeb][cubeb] on [the MacOS platform][cubeb-au].

View File

@ -1,8 +1,10 @@
set -e
echo "\n\nRun device-changed tests\n===================="
if [[ -z "${RUST_BACKTRACE}" ]]; then
# Display backtrace for debugging
export RUST_BACKTRACE=1
# Display backtrace for debugging
export RUST_BACKTRACE=1
fi
echo "RUST_BACKTRACE is set to ${RUST_BACKTRACE}\n"

View File

@ -7,8 +7,8 @@ toolchain=$(rustup default)
echo "\nUse Rust toolchain: $toolchain"
if [[ $toolchain != nightly* ]]; then
echo "The sanitizer is only available on Rust Nightly only. Skip."
exit
echo "The sanitizer is only available on Rust Nightly only. Skip."
exit
fi
sanitizers=("address" "leak" "memory" "thread")

View File

@ -1,31 +1,33 @@
set -e
echo "\n\nTest suite for cubeb-coreaudio\n========================================"
if [[ -z "${RUST_BACKTRACE}" ]]; then
# Display backtrace for debugging
export RUST_BACKTRACE=1
# Display backtrace for debugging
export RUST_BACKTRACE=1
fi
echo "RUST_BACKTRACE is set to ${RUST_BACKTRACE}\n"
format_check() {
cargo fmt --all -- --check
local result=$?
if [[ $result -ne 0 ]]; then
echo "Please format the code with 'cargo fmt' (version $(cargo fmt -- --version))"
fi
return $result
cargo fmt --all -- --check
local result=$?
if [[ $result -ne 0 ]]; then
echo "Please format the code with 'cargo fmt' (version $(cargo fmt -- --version))"
fi
return $result
}
lints_check() {
if [[ -n "$1" ]]; then
cargo clippy -p $1 -- -D warnings
else
cargo clippy -- -D warnings
fi
local result=$?
if [[ $result -ne 0 ]]; then
echo "Please fix errors with 'cargo clippy' (version $(cargo clippy -- --version))"
fi
return $result
if [[ -n "$1" ]]; then
cargo clippy -p $1 -- -D warnings
else
cargo clippy -- -D warnings
fi
local result=$?
if [[ $result -ne 0 ]]; then
echo "Please fix errors with 'cargo clippy' (version $(cargo clippy -- --version))"
fi
return $result
}
# Run tests in the sub crate

View File

@ -1,9 +1,5 @@
use super::*;
pub fn get_device_global_uid(id: AudioDeviceID) -> std::result::Result<StringRef, OSStatus> {
get_device_uid(id, DeviceType::INPUT | DeviceType::OUTPUT)
}
pub fn get_device_uid(
id: AudioDeviceID,
devtype: DeviceType,
@ -38,6 +34,24 @@ pub fn get_device_model_uid(
}
}
#[allow(dead_code)] // `pub` for running test
pub fn get_device_transport_type(
id: AudioDeviceID,
devtype: DeviceType,
) -> std::result::Result<u32, OSStatus> {
assert_ne!(id, kAudioObjectUnknown);
let address = get_property_address(Property::TransportType, devtype);
let mut size = mem::size_of::<u32>();
let mut transport: u32 = 0;
let err = audio_object_get_property_data(id, &address, &mut size, &mut transport);
if err == NO_ERR {
Ok(transport)
} else {
Err(err)
}
}
pub fn get_device_source(
id: AudioDeviceID,
devtype: DeviceType,
@ -96,13 +110,6 @@ pub fn get_device_name(
}
}
pub fn get_device_label(
id: AudioDeviceID,
devtype: DeviceType,
) -> std::result::Result<StringRef, OSStatus> {
get_device_source_name(id, devtype).or_else(|_| get_device_name(id, devtype))
}
pub fn get_device_manufacturer(
id: AudioDeviceID,
devtype: DeviceType,
@ -293,11 +300,12 @@ pub enum Property {
DeviceStreamFormat,
DeviceStreams,
DeviceUID,
ModelUID,
HardwareDefaultInputDevice,
HardwareDefaultOutputDevice,
HardwareDevices,
ModelUID,
StreamLatency,
TransportType,
}
impl From<Property> for AudioObjectPropertySelector {
@ -316,11 +324,12 @@ impl From<Property> for AudioObjectPropertySelector {
Property::DeviceStreamFormat => kAudioDevicePropertyStreamFormat,
Property::DeviceStreams => kAudioDevicePropertyStreams,
Property::DeviceUID => kAudioDevicePropertyDeviceUID,
Property::ModelUID => kAudioDevicePropertyModelUID,
Property::HardwareDefaultInputDevice => kAudioHardwarePropertyDefaultInputDevice,
Property::HardwareDefaultOutputDevice => kAudioHardwarePropertyDefaultOutputDevice,
Property::HardwareDevices => kAudioHardwarePropertyDevices,
Property::ModelUID => kAudioDevicePropertyModelUID,
Property::StreamLatency => kAudioStreamPropertyLatency,
Property::TransportType => kAudioDevicePropertyTransportType,
}
}
}

View File

@ -1376,6 +1376,78 @@ fn get_presentation_latency(devid: AudioObjectID, devtype: DeviceType) -> u32 {
device_latency + stream_latency
}
fn get_device_group_id(
id: AudioDeviceID,
devtype: DeviceType,
) -> std::result::Result<CString, OSStatus> {
match get_device_transport_type(id, devtype) {
// If the device type is "bltn" (builtin)
Ok(0x626C_746E) => {
cubeb_log!(
"transport type is {:?}",
convert_uint32_into_string(0x626C_746E)
);
match get_device_source(id, devtype) {
Ok(source) => {
let msg = format!("source is {:?}", convert_uint32_into_string(source));
match source {
// "imic" (internal microphone) or "ispk" (internal speaker)
0x696D_6963 | 0x6973_706B => {
const GROUP_ID: &str = "builtin-internal-mic|spk";
cubeb_log!("{}. Use hardcode group id: {}.", msg, GROUP_ID);
return Ok(CString::new(GROUP_ID).unwrap());
}
// "emic" (external microphone) or "hdpn" (headphone)
0x656D_6963 | 0x6864_706E => {
const GROUP_ID: &str = "builtin-external-mic|hdpn";
cubeb_log!("{}. Use hardcode group id: {}", msg, GROUP_ID);
return Ok(CString::new(GROUP_ID).unwrap());
}
_ => {
cubeb_log!("{}. Get model uid instead.", msg);
}
}
}
Err(e) => {
cubeb_log!(
"Error: {} when getting device source. Get model uid instead.",
e
);
}
}
}
Ok(trans_type) => {
cubeb_log!(
"transport type is {:?}. Get model uid instead.",
convert_uint32_into_string(trans_type)
);
}
Err(e) => {
cubeb_log!(
"Error: {} when getting transport type. Get model uid instead.",
e
);
}
}
// Some devices (e.g. AirPods) might only set the model-uid in the global scope.
// The query might fail if the scope is input-only or output-only.
get_device_model_uid(id, devtype)
.or_else(|_| get_device_model_uid(id, DeviceType::INPUT | DeviceType::OUTPUT))
.map(|uid| uid.into_cstring())
}
fn get_device_label(
id: AudioDeviceID,
devtype: DeviceType,
) -> std::result::Result<StringRef, OSStatus> {
get_device_source_name(id, devtype).or_else(|_| get_device_name(id, devtype))
}
fn get_device_global_uid(id: AudioDeviceID) -> std::result::Result<StringRef, OSStatus> {
get_device_uid(id, DeviceType::INPUT | DeviceType::OUTPUT)
}
fn create_cubeb_device_info(
devid: AudioObjectID,
devtype: DeviceType,
@ -1410,10 +1482,9 @@ fn create_cubeb_device_info(
}
}
match get_device_model_uid(devid, devtype) {
Ok(uid) => {
let c_string = uid.into_cstring();
dev_info.group_id = c_string.into_raw();
match get_device_group_id(devid, devtype) {
Ok(group_id) => {
dev_info.group_id = group_id.into_raw();
}
Err(e) => {
cubeb_log!(

View File

@ -1262,6 +1262,137 @@ fn test_get_device_presentation_latency() {
}
}
// get_device_group_id
// ------------------------------------
#[test]
fn test_get_device_group_id() {
if let Some(device) = test_get_default_device(Scope::Input) {
match get_device_group_id(device, DeviceType::INPUT) {
Ok(id) => println!("input group id: {:?}", id),
Err(e) => println!("No input group id. Error: {}", e),
}
} else {
println!("No input device.");
}
if let Some(device) = test_get_default_device(Scope::Output) {
match get_device_group_id(device, DeviceType::OUTPUT) {
Ok(id) => println!("output group id: {:?}", id),
Err(e) => println!("No output group id. Error: {}", e),
}
} else {
println!("No output device.");
}
}
#[test]
fn test_get_same_group_id_for_builtin_device_pairs() {
use std::collections::HashMap;
const IMIC: u32 = 0x696D_6963; // "imic"
const ISPK: u32 = 0x6973_706B; // "ispk"
const EMIC: u32 = 0x656D_6963; // "emic"
const HDPN: u32 = 0x6864_706E; // "hdpn"
let pairs = [(IMIC, ISPK), (EMIC, HDPN)];
// TODO: group_ids will have collision if one input device and one output device
// has same source value.
let mut group_ids = HashMap::<u32, String>::new();
let input_devices = test_get_devices_in_scope(Scope::Input);
for device in input_devices.iter() {
match get_device_source(*device, DeviceType::INPUT) {
Ok(source) => match get_device_group_id(*device, DeviceType::INPUT) {
Ok(id) => assert!(group_ids
.insert(source, id.into_string().unwrap())
.is_none()),
Err(e) => assert!(group_ids.insert(source, format!("Error {}", e)).is_none()),
},
_ => {} // do nothing when failing to get source.
}
}
let output_devices = test_get_devices_in_scope(Scope::Output);
for device in output_devices.iter() {
match get_device_source(*device, DeviceType::OUTPUT) {
Ok(source) => match get_device_group_id(*device, DeviceType::OUTPUT) {
Ok(id) => assert!(group_ids
.insert(source, id.into_string().unwrap())
.is_none()),
Err(e) => assert!(group_ids.insert(source, format!("Error {}", e)).is_none()),
},
_ => {} // do nothing when failing to get source.
}
}
for (dev1, dev2) in pairs.iter() {
let id1 = group_ids.get(dev1);
let id2 = group_ids.get(dev2);
if id1.is_some() && id2.is_some() {
assert_eq!(id1, id2);
}
group_ids.remove(dev1);
group_ids.remove(dev2);
}
}
#[test]
#[should_panic]
fn test_get_device_group_id_by_unknown_device() {
assert!(get_device_group_id(kAudioObjectUnknown, DeviceType::INPUT).is_err());
}
// get_device_label
// ------------------------------------
#[test]
fn test_get_device_label() {
if let Some(device) = test_get_default_device(Scope::Input) {
let name = get_device_label(device, DeviceType::INPUT).unwrap();
println!("input device label: {}", name.into_string());
} else {
println!("No input device.");
}
if let Some(device) = test_get_default_device(Scope::Output) {
let name = get_device_label(device, DeviceType::OUTPUT).unwrap();
println!("output device label: {}", name.into_string());
} else {
println!("No output device.");
}
}
#[test]
#[should_panic]
fn test_get_device_label_by_unknown_device() {
assert!(get_device_label(kAudioObjectUnknown, DeviceType::INPUT).is_err());
}
// get_device_global_uid
// ------------------------------------
#[test]
fn test_get_device_global_uid() {
// Input device.
if let Some(input) = test_get_default_device(Scope::Input) {
let uid = get_device_global_uid(input).unwrap();
let uid = uid.into_string();
assert!(!uid.is_empty());
}
// Output device.
if let Some(output) = test_get_default_device(Scope::Output) {
let uid = get_device_global_uid(output).unwrap();
let uid = uid.into_string();
assert!(!uid.is_empty());
}
}
#[test]
#[should_panic]
fn test_get_device_global_uid_by_unknwon_device() {
// Unknown device.
assert!(get_device_global_uid(kAudioObjectUnknown).is_err());
}
// create_cubeb_device_info
// destroy_cubeb_device_info
// ------------------------------------

View File

@ -1,32 +1,6 @@
use super::utils::{test_get_default_device, Scope};
use super::*;
// get_device_global_uid
// ------------------------------------
#[test]
fn test_get_device_global_uid() {
// Input device.
if let Some(input) = test_get_default_device(Scope::Input) {
let uid = get_device_global_uid(input).unwrap();
let uid = uid.into_string();
assert!(!uid.is_empty());
}
// Output device.
if let Some(output) = test_get_default_device(Scope::Output) {
let uid = get_device_global_uid(output).unwrap();
let uid = uid.into_string();
assert!(!uid.is_empty());
}
}
#[test]
#[should_panic]
fn test_get_device_global_uid_by_unknwon_device() {
// Unknown device.
assert!(get_device_global_uid(kAudioObjectUnknown).is_err());
}
// get_device_uid
// ------------------------------------
#[test]
@ -53,34 +27,99 @@ fn test_get_device_uid_by_unknwon_device() {
assert!(get_device_uid(kAudioObjectUnknown, DeviceType::INPUT).is_err());
}
// get_device_source
// get_device_model_uid
// ------------------------------------
// Some USB headsets (e.g., Plantronic .Audio 628) fails to get data source.
// Some devices (e.g., AirPods) fail to get model uid.
#[test]
fn test_get_device_source() {
fn test_get_device_model_uid() {
if let Some(device) = test_get_default_device(Scope::Input) {
if let Ok(source) = get_device_source(device, DeviceType::INPUT) {
println!(
"input: {:X}, {:?}",
source,
convert_uint32_into_string(source)
);
} else {
println!("No input data source.");
match get_device_model_uid(device, DeviceType::INPUT) {
Ok(uid) => println!("input model uid: {}", uid.into_string()),
Err(e) => println!("No input model uid. Error: {}", e),
}
} else {
println!("No input device.");
}
if let Some(device) = test_get_default_device(Scope::Output) {
if let Ok(source) = get_device_source(device, DeviceType::OUTPUT) {
println!(
"output: {:X}, {:?}",
match get_device_model_uid(device, DeviceType::OUTPUT) {
Ok(uid) => println!("output model uid: {}", uid.into_string()),
Err(e) => println!("No output model uid. Error: {}", e),
}
} else {
println!("No output device.");
}
}
#[test]
#[should_panic]
fn test_get_device_model_uid_by_unknown_device() {
assert!(get_device_model_uid(kAudioObjectUnknown, DeviceType::INPUT).is_err());
}
// get_device_transport_type
// ------------------------------------
#[test]
fn test_get_device_transport_type() {
if let Some(device) = test_get_default_device(Scope::Input) {
match get_device_transport_type(device, DeviceType::INPUT) {
Ok(trans_type) => println!(
"input transport type: {:X}, {:?}",
trans_type,
convert_uint32_into_string(trans_type)
),
Err(e) => println!("No input transport type. Error: {}", e),
}
} else {
println!("No input device.");
}
if let Some(device) = test_get_default_device(Scope::Output) {
match get_device_transport_type(device, DeviceType::OUTPUT) {
Ok(trans_type) => println!(
"output transport type: {:X}, {:?}",
trans_type,
convert_uint32_into_string(trans_type)
),
Err(e) => println!("No output transport type. Error: {}", e),
}
} else {
println!("No output device.");
}
}
#[test]
#[should_panic]
fn test_get_device_transport_type_by_unknown_device() {
assert!(get_device_transport_type(kAudioObjectUnknown, DeviceType::INPUT).is_err());
}
// get_device_source
// ------------------------------------
// Some USB headsets (e.g., Plantronic .Audio 628) fails to get data source.
#[test]
fn test_get_device_source() {
if let Some(device) = test_get_default_device(Scope::Input) {
match get_device_source(device, DeviceType::INPUT) {
Ok(source) => println!(
"input source: {:X}, {:?}",
source,
convert_uint32_into_string(source)
);
} else {
println!("No output data source.");
),
Err(e) => println!("No input data source. Error: {}", e),
}
} else {
println!("No input device.");
}
if let Some(device) = test_get_default_device(Scope::Output) {
match get_device_source(device, DeviceType::OUTPUT) {
Ok(source) => println!(
"output source: {:X}, {:?}",
source,
convert_uint32_into_string(source)
),
Err(e) => println!("No output data source. Error: {}", e),
}
} else {
println!("No output device.");
@ -98,20 +137,18 @@ fn test_get_device_source_by_unknown_device() {
#[test]
fn test_get_device_source_name() {
if let Some(device) = test_get_default_device(Scope::Input) {
if let Ok(name) = get_device_source_name(device, DeviceType::INPUT) {
println!("input: {}", name.into_string());
} else {
println!("No input data source name.");
match get_device_source_name(device, DeviceType::INPUT) {
Ok(name) => println!("input: {}", name.into_string()),
Err(e) => println!("No input data source name. Error: {}", e),
}
} else {
println!("No input device.");
}
if let Some(device) = test_get_default_device(Scope::Output) {
if let Ok(name) = get_device_source_name(device, DeviceType::OUTPUT) {
println!("output: {}", name.into_string());
} else {
println!("No output data source name.");
match get_device_source_name(device, DeviceType::OUTPUT) {
Ok(name) => println!("output: {}", name.into_string()),
Err(e) => println!("No output data source name. Error: {}", e),
}
} else {
println!("No output device.");
@ -149,31 +186,6 @@ fn test_get_device_name_by_unknown_device() {
assert!(get_device_name(kAudioObjectUnknown, DeviceType::INPUT).is_err());
}
// get_device_label
// ------------------------------------
#[test]
fn test_get_device_label() {
if let Some(device) = test_get_default_device(Scope::Input) {
let name = get_device_label(device, DeviceType::INPUT).unwrap();
println!("input device label: {}", name.into_string());
} else {
println!("No input device.");
}
if let Some(device) = test_get_default_device(Scope::Output) {
let name = get_device_label(device, DeviceType::OUTPUT).unwrap();
println!("output device label: {}", name.into_string());
} else {
println!("No output device.");
}
}
#[test]
#[should_panic]
fn test_get_device_label_by_unknown_device() {
assert!(get_device_label(kAudioObjectUnknown, DeviceType::INPUT).is_err());
}
// get_device_manufacturer
// ------------------------------------
#[test]
@ -370,7 +382,6 @@ fn test_get_device_stream_configuration() {
if let Some(device) = test_get_default_device(Scope::Input) {
let buffers = get_device_stream_configuration(device, DeviceType::INPUT).unwrap();
println!("input stream config: {:?}", buffers);
dbg!(buffers);
} else {
println!("No input device.");
}
@ -378,7 +389,6 @@ fn test_get_device_stream_configuration() {
if let Some(device) = test_get_default_device(Scope::Output) {
let buffers = get_device_stream_configuration(device, DeviceType::OUTPUT).unwrap();
println!("output stream config: {:?}", buffers);
dbg!(buffers);
} else {
println!("No output device.");
}

View File

@ -19,7 +19,7 @@ static_prefs = { path = "../../../../modules/libpref/init/static_prefs" }
profiler_helper = { path = "../../../../tools/profiler/rust-helper", optional = true }
mozurl = { path = "../../../../netwerk/base/mozurl" }
webrender_bindings = { path = "../../../../gfx/webrender_bindings", optional = true }
cubeb-coreaudio = { git = "https://github.com/ChunMinChang/cubeb-coreaudio-rs", rev = "432259ab53295ca98a2df0c0e6c73d132b273e97", optional = true }
cubeb-coreaudio = { git = "https://github.com/ChunMinChang/cubeb-coreaudio-rs", rev = "ea9e5aa3e6014f219cf5fa0690bc4b06916f0b09", optional = true }
cubeb-pulse = { git = "https://github.com/djg/cubeb-pulse-rs", rev="72f813a03cefbdf8e2c58c7410f3556c79429a06", optional = true, features=["pulse-dlopen"] }
cubeb-sys = { version = "0.6", optional = true, features=["gecko-in-tree"] }
encoding_glue = { path = "../../../../intl/encoding_glue" }