Bug 1631448 - mach vendor rust. r=chunmin,kinetik

Differential Revision: https://phabricator.services.mozilla.com/D71624
This commit is contained in:
Paul Adenot 2020-04-20 21:59:17 +00:00
Родитель 07bda9f594
Коммит 86e2733819
10 изменённых файлов: 81 добавлений и 194 удалений

Просмотреть файл

@ -45,7 +45,7 @@ rev = "3541e3818fdc7c2a24f87e3459151a4ce955a67a"
[source."https://github.com/djg/cubeb-pulse-rs"]
git = "https://github.com/djg/cubeb-pulse-rs"
replace-with = "vendored-sources"
rev = "72f813a03cefbdf8e2c58c7410f3556c79429a06"
rev = "e845327c3fe91192870a34fc2999d2f460291295"
[source."https://github.com/bytecodealliance/wasmtime"]
git = "https://github.com/bytecodealliance/wasmtime"
@ -70,7 +70,7 @@ rev = "5e870faf6f95d79d11efc813e56370ad124bbed5"
[source."https://github.com/ChunMinChang/cubeb-coreaudio-rs"]
git = "https://github.com/ChunMinChang/cubeb-coreaudio-rs"
replace-with = "vendored-sources"
rev = "0f62d389cc04cc3707368eda14fe1904ee8d7981"
rev = "6156e941e5f46a641d2da10ca53a9ad318c10722"
[source.crates-io]
replace-with = "vendored-sources"

10
Cargo.lock сгенерированный
Просмотреть файл

@ -679,7 +679,7 @@ dependencies = [
[[package]]
name = "coreaudio-sys-utils"
version = "0.1.0"
source = "git+https://github.com/ChunMinChang/cubeb-coreaudio-rs?rev=0f62d389cc04cc3707368eda14fe1904ee8d7981#0f62d389cc04cc3707368eda14fe1904ee8d7981"
source = "git+https://github.com/ChunMinChang/cubeb-coreaudio-rs?rev=6156e941e5f46a641d2da10ca53a9ad318c10722#6156e941e5f46a641d2da10ca53a9ad318c10722"
dependencies = [
"core-foundation-sys",
"coreaudio-sys",
@ -916,7 +916,7 @@ dependencies = [
[[package]]
name = "cubeb-coreaudio"
version = "0.1.0"
source = "git+https://github.com/ChunMinChang/cubeb-coreaudio-rs?rev=0f62d389cc04cc3707368eda14fe1904ee8d7981#0f62d389cc04cc3707368eda14fe1904ee8d7981"
source = "git+https://github.com/ChunMinChang/cubeb-coreaudio-rs?rev=6156e941e5f46a641d2da10ca53a9ad318c10722#6156e941e5f46a641d2da10ca53a9ad318c10722"
dependencies = [
"atomic",
"audio-mixer",
@ -933,7 +933,7 @@ dependencies = [
[[package]]
name = "cubeb-pulse"
version = "0.3.0"
source = "git+https://github.com/djg/cubeb-pulse-rs?rev=72f813a03cefbdf8e2c58c7410f3556c79429a06#72f813a03cefbdf8e2c58c7410f3556c79429a06"
source = "git+https://github.com/djg/cubeb-pulse-rs?rev=e845327c3fe91192870a34fc2999d2f460291295#e845327c3fe91192870a34fc2999d2f460291295"
dependencies = [
"cubeb-backend",
"pulse",
@ -3380,7 +3380,7 @@ dependencies = [
[[package]]
name = "pulse"
version = "0.3.0"
source = "git+https://github.com/djg/cubeb-pulse-rs?rev=72f813a03cefbdf8e2c58c7410f3556c79429a06#72f813a03cefbdf8e2c58c7410f3556c79429a06"
source = "git+https://github.com/djg/cubeb-pulse-rs?rev=e845327c3fe91192870a34fc2999d2f460291295#e845327c3fe91192870a34fc2999d2f460291295"
dependencies = [
"bitflags",
"pulse-ffi",
@ -3389,7 +3389,7 @@ dependencies = [
[[package]]
name = "pulse-ffi"
version = "0.1.0"
source = "git+https://github.com/djg/cubeb-pulse-rs?rev=72f813a03cefbdf8e2c58c7410f3556c79429a06#72f813a03cefbdf8e2c58c7410f3556c79429a06"
source = "git+https://github.com/djg/cubeb-pulse-rs?rev=e845327c3fe91192870a34fc2999d2f460291295#e845327c3fe91192870a34fc2999d2f460291295"
dependencies = [
"libc",
]

Просмотреть файл

@ -1 +1 @@
{"files":{".editorconfig":"4e53b182bcc78b83d7e1b5c03efa14d22d4955c4ed2514d1ba4e99c1eb1a50ba",".githooks/pre-push":"8b8b26544cd56f54c0c33812551f786bb25cb08c86dbfeb6bf3daad881c826a1",".travis.yml":"dc07bac53f70f16c9bdf52264bdc58500ae6018c1b4c567bc7642f6b4ca3cc35","Cargo.toml":"333de4946bd1fbe250d68241d3f085a47d6990053a54999e2b16f3c46779d228","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":"3dd76659f6dceeb0490dd92b355e113301ba0d0a8f034993a56f40e09edd25b2","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":"c1f32541bf2b8202012d1b20f7aea6cc98dc91925e29f72d25a184a0bdfb693b","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":"7323051fa7f0c51eb2eb0d495dcd951502e4cc8ce0088e6e7b3b3a95180f43d4"},"package":null}
{"files":{".editorconfig":"4e53b182bcc78b83d7e1b5c03efa14d22d4955c4ed2514d1ba4e99c1eb1a50ba",".githooks/pre-push":"8b8b26544cd56f54c0c33812551f786bb25cb08c86dbfeb6bf3daad881c826a1",".travis.yml":"dc07bac53f70f16c9bdf52264bdc58500ae6018c1b4c567bc7642f6b4ca3cc35","Cargo.toml":"333de4946bd1fbe250d68241d3f085a47d6990053a54999e2b16f3c46779d228","LICENSE":"6e6f56aff5bbf3cbc60747e152fb1a719bd0716aaf6d711c554f57d92e96297c","README.md":"ab0f168080dfdfc1512484aeb4a41e1625f6b4147e534899fab56b2cb6d9f32a","install_git_hook.sh":"d38c8e51e636f6b90b489621ac34ccd1d1b1f40dccce3d178ed1da1c5068f16d","install_rustfmt_clippy.sh":"4ae90d8dcb9757cb3ae4ae142ef80e5377c0dde61c63f4a3c32418646e80ca7b","run_device_tests.sh":"4b7d65eb638c1a278ffc8ecb6d30d47b3b8405392e976cae38c6f744e2bed532","run_sanitizers.sh":"2f0934ba01cbcd74485f19d50147f6b604cf9730bbd3a3d3f3d958e40d0f799f","run_tests.sh":"3dd76659f6dceeb0490dd92b355e113301ba0d0a8f034993a56f40e09edd25b2","src/backend/aggregate_device.rs":"ae21129aa6b3c7bd3376751b6a94d1ebe6c9f7afcd1db3107fb4d703d04da6b3","src/backend/auto_release.rs":"050fdcee74cf46b9a8a85a877e166d72a853d33220f59cf734cbb6ea09daa441","src/backend/buffer_manager.rs":"9c10a261792e32e75833b5f976b18547c338ca6beb2330eeab1ad203cc8c32bf","src/backend/device_property.rs":"d43642ea6e5f40e29c2a59ec7d81b42c154134685e417585045785359aa31686","src/backend/mixer.rs":"14e2156a8c1aeabcd4adb3336c3c9401b9c8526ec82a8c78942af7a79648f0f8","src/backend/mod.rs":"b566a4f853563109b74c84bc519323b42fb96d8af58e4030225aade7cd47d6c6","src/backend/resampler.rs":"fd1281d28a4db1659d2f75e43b8457651745e1b6eb5a53a77f04d752135f6dc7","src/backend/tests/aggregate_device.rs":"107f5c637844cd5ae43d2b42cec4ef3369bb702751586078c0a9d50f039161cd","src/backend/tests/api.rs":"b6692aa2cab751e8d52aee40c8177ce15912338cdbe3daa93d3a25ce9e92031b","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":"7323051fa7f0c51eb2eb0d495dcd951502e4cc8ce0088e6e7b3b3a95180f43d4"},"package":null}

12
third_party/rust/cubeb-coreaudio/README.md поставляемый
Просмотреть файл

@ -7,19 +7,11 @@
## Current Goals
- Keep refactoring the implementation until it looks rusty! (it's translated from C at first.)
- Check the [todo list][todo] first
- Check the [todo list][todo]
## Status
The code is currently shipped within the _Firefox Nightly_ under a _perf_.
- Try it:
- Open `about:config`
- Add a perf `media.cubeb.backend` with string `audiounit-rust`
- Restart Firefox Nightly
- Open `about:support`
- Check if the `Audio Backend` in `Media` section is `audiounit-rust` or not
- Retart Firefox Nightly again if it's not.
This is now the _Firefox_'s default audio backend on *Mac OS*.
## Test

Просмотреть файл

@ -64,27 +64,6 @@ impl BufferManager {
}
}
}
pub fn push_silent_data(&mut self, silent_samples: usize) {
let pushed = match &mut self.producer {
RingBufferProducer::FloatRingBufferProducer(p) => {
let mut silent_buffer = [0. as f32; INPUT_BUFFER_CAPACITY];
let silent_slice = silent_buffer.split_at_mut(silent_samples).0;
p.push_slice(silent_slice)
}
RingBufferProducer::IntegerRingBufferProducer(p) => {
let mut silent_buffer = [0 as i16; INPUT_BUFFER_CAPACITY];
let silent_slice = silent_buffer.split_at_mut(silent_samples).0;
p.push_slice(silent_slice)
}
};
if pushed != silent_samples {
cubeb_log!(
"Input ringbuffer full, could only push {} instead of {}",
pushed,
silent_samples
);
}
}
pub fn push_data(&mut self, input_data: *const c_void, read_samples: usize) {
let pushed = match &mut self.producer {
RingBufferProducer::FloatRingBufferProducer(p) => {

Просмотреть файл

@ -176,6 +176,9 @@ impl Mixer {
out_channel_count: usize,
mut output_channels: Vec<audio_mixer::Channel>,
) -> Self {
assert!(in_channel_count > 0);
assert!(out_channel_count > 0);
cubeb_log!(
"Create a mixer with input channel count: {}, input layout: {:?}, \
out channel count: {}, output channels: {:?}",
@ -194,8 +197,8 @@ impl Mixer {
// When having one or two channel, force mono or stereo. Some devices (namely,
// Bose QC35, mark 1 and 2), expose a single channel mapped to the right for
// some reason.
// TODO: Only apply this setting when device is Bose QC35 (by device_property.rs).
// some reason. Some devices (e.g., builtin speaker on MacBook Pro 2018) map
// the channel layout to the undefined channels.
if out_channel_count == 1 {
output_channels = vec![audio_mixer::Channel::FrontCenter];
} else if out_channel_count == 2 {
@ -210,7 +213,7 @@ impl Mixer {
|| out_channel_count != output_channels.len()
|| all_silence == output_channels
{
cubeb_log!("Mismatch between output channels and layout. Apply default layout instead");
cubeb_log!("Use invalid layout. Apply default layout instead");
output_channels = get_default_channel_order(out_channel_count);
}

Просмотреть файл

@ -399,12 +399,9 @@ extern "C" fn audiounit_input_callback(
// For now state that no error occurred and feed silence, stream will be
// resumed once reinit has completed.
cubeb_logv!(
"({:p}) input: reinit pending feeding silence instead",
"({:p}) input: reinit pending, output will pull silence instead",
stm.core_stream_data.stm_ptr
);
let elements =
(input_frames * stm.core_stream_data.input_desc.mChannelsPerFrame) as usize;
input_buffer_manager.push_silent_data(elements);
ErrorHandle::Reinit
} else {
assert_eq!(status, NO_ERR);
@ -610,13 +607,12 @@ extern "C" fn audiounit_output_callback(
&& (stm.switching_device.load(Ordering::SeqCst)
|| stm.frames_read.load(Ordering::SeqCst) == 0)
{
// The silent frames will be inserted in `get_linear_data` below.
let silent_frames_to_push = input_frames_needed - buffered_input_frames;
let silent_samples_to_push = silent_frames_to_push * input_channels;
input_buffer_manager.push_silent_data(silent_samples_to_push);
stm.frames_read
.fetch_add(input_frames_needed, Ordering::SeqCst);
cubeb_log!(
"({:p}) Missing Frames: {} pushed {} frames of input silence.",
"({:p}) Missing Frames: {} will append {} frames of input silence.",
stm.core_stream_data.stm_ptr,
if stm.frames_read.load(Ordering::SeqCst) == 0 {
"input hasn't started,"
@ -1379,50 +1375,28 @@ fn get_presentation_latency(devid: AudioObjectID, devtype: DeviceType) -> u32 {
device_latency + stream_latency
}
#[allow(clippy::cognitive_complexity)]
fn get_device_group_id(
id: AudioDeviceID,
devtype: DeviceType,
) -> std::result::Result<CString, OSStatus> {
const BLTN: u32 = 0x626C_746E; // "bltn" (builtin)
match get_device_transport_type(id, devtype) {
// If the device type is "bltn" (builtin)
Ok(0x626C_746E) => {
Ok(BLTN) => {
cubeb_log!(
"transport type is {:?}",
convert_uint32_into_string(0x626C_746E)
"The transport type is {:?}",
convert_uint32_into_string(BLTN)
);
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
);
}
match get_custom_group_id(id, devtype) {
Some(id) => return Ok(id),
None => {
cubeb_log!("Get model uid instead.");
}
};
}
Ok(trans_type) => {
cubeb_log!(
"transport type is {:?}. Get model uid instead.",
"The transport type is {:?}. Get model uid instead.",
convert_uint32_into_string(trans_type)
);
}
@ -1441,6 +1415,44 @@ fn get_device_group_id(
.map(|uid| uid.into_cstring())
}
fn get_custom_group_id(id: AudioDeviceID, devtype: DeviceType) -> Option<CString> {
const IMIC: u32 = 0x696D_6963; // "imic" (internal microphone)
const ISPK: u32 = 0x6973_706B; // "ispk" (internal speaker)
const EMIC: u32 = 0x656D_6963; // "emic" (external microphone)
const HDPN: u32 = 0x6864_706E; // "hdpn" (headphone)
match get_device_source(id, devtype) {
s @ Ok(IMIC) | s @ Ok(ISPK) => {
const GROUP_ID: &str = "builtin-internal-mic|spk";
cubeb_log!(
"Use hardcode group id: {} when source is: {:?}.",
GROUP_ID,
convert_uint32_into_string(s.unwrap())
);
return Some(CString::new(GROUP_ID).unwrap());
}
s @ Ok(EMIC) | s @ Ok(HDPN) => {
const GROUP_ID: &str = "builtin-external-mic|hdpn";
cubeb_log!(
"Use hardcode group id: {} when source is: {:?}.",
GROUP_ID,
convert_uint32_into_string(s.unwrap())
);
return Some(CString::new(GROUP_ID).unwrap());
}
Ok(s) => {
cubeb_log!(
"No custom group id when source is: {:?}.",
convert_uint32_into_string(s)
);
}
Err(e) => {
cubeb_log!("Error: {} when getting device source. ", e);
}
}
None
}
fn get_device_label(
id: AudioDeviceID,
devtype: DeviceType,

Просмотреть файл

@ -720,34 +720,9 @@ fn test_convert_channel_layout() {
// ------------------------------------
#[test]
fn test_get_preferred_channel_layout_output() {
const STEREO: [mixer::Channel; 2] = [mixer::Channel::FrontLeft, mixer::Channel::FrontRight];
// Predefined whitelist
use std::collections::HashMap;
let devices_layouts: HashMap<&'static str, Vec<mixer::Channel>> = [
("hdpn", STEREO.to_vec()),
("ispk", STEREO.to_vec()),
("FApd", STEREO.to_vec()),
]
.iter()
.cloned()
.collect();
let source = test_get_default_source_name(Scope::Output);
let unit = test_get_default_audiounit(Scope::Output);
if source.is_none() || unit.is_none() {
println!("No output audiounit or device source name found.");
return;
}
let source = source.unwrap();
let unit = unit.unwrap();
if let Some(layout) = devices_layouts.get(source.as_str()) {
assert_eq!(
&audiounit_get_preferred_channel_layout(unit.get_inner()),
layout
);
} else {
println!("Device {} is not in the whitelist.", source);
match test_get_default_audiounit(Scope::Output) {
Some(unit) => assert!(!audiounit_get_preferred_channel_layout(unit.get_inner()).is_empty()),
None => println!("No output audiounit for test."),
}
}
@ -755,35 +730,9 @@ fn test_get_preferred_channel_layout_output() {
// ------------------------------------
#[test]
fn test_get_current_channel_layout_output() {
const STEREO: [mixer::Channel; 2] = [mixer::Channel::FrontLeft, mixer::Channel::FrontRight];
// Predefined whitelist
use std::collections::HashMap;
let devices_layouts: HashMap<&'static str, Vec<mixer::Channel>> = [
("hdpn", STEREO.to_vec()),
("ispk", STEREO.to_vec()),
("FApd", STEREO.to_vec()),
]
.iter()
.cloned()
.collect();
let source = test_get_default_source_name(Scope::Output);
let unit = test_get_default_audiounit(Scope::Output);
if source.is_none() || unit.is_none() {
println!("No output audiounit or device source name found.");
return;
}
let source = source.unwrap();
let unit = unit.unwrap();
if let Some(layout) = devices_layouts.get(source.as_str()) {
assert_eq!(
audiounit_get_current_channel_layout(unit.get_inner()),
*layout
);
} else {
println!("Device {} is not in the whitelist.", source);
match test_get_default_audiounit(Scope::Output) {
Some(unit) => assert!(!audiounit_get_current_channel_layout(unit.get_inner()).is_empty()),
None => println!("No output audiounit for test."),
}
}

Просмотреть файл

@ -1 +1 @@
{"files":{".editorconfig":"bf047bd1da10cabb99eea666d1e57c321eba4716dccb3e4ed0e2c5fe3ca53858",".travis.yml":"0394e2adb041175457685cde5ee05ff04bdab8885fd8a62551f2ff43d9e48872","AUTHORS":"0e0ac930a68ce2f6b876126b195add177f0d3886facb9260f4d9b69f1988f0cc","Cargo.toml":"297f0144bbebcbc2f3b5478fed750f39adb3b60f9d6c273dfa72d9736818423d","LICENSE":"44c6b5ae5ec3fe2fbc608b00e6f4896f4d2d5c7e525fcbaa3eaa3cf2f3d5a983","README.md":"e6a98ee5630b9ce1a096a2907d095454f2770e298a5b0976ab552cc53ca96cfc","src/backend/context.rs":"33d9fdf1504fe1ae43d301e288daf6eaeabeb47aa0ef86efa135c6d984425fc4","src/backend/cork_state.rs":"4a0f1afc7d9f333dac89218cc56d7d32fbffb487cd48c1c9a4e03d79cb3b5e28","src/backend/intern.rs":"374a9a3bd79fddc47739dda1dbfc5929aea5a91946794fe65fba3c8d130fbda9","src/backend/mod.rs":"06ce9250865abf0ea461f215b128470636d072a6776821efef3caf5a7b992fb9","src/backend/stream.rs":"e14f3fd64cca6d5a2d085a23aa9faa4945dcb2b16ba6ff738e2602cfcafc6292","src/capi.rs":"b2c1be8128cadd36caa65c80950440f9d6f2aa0c24cc7bae6a9eaf6347ac454d","src/lib.rs":"7282560d84b134b09acfd8d6282600982e42fb3557f72454c535637cc26c7bf6"},"package":null}
{"files":{".editorconfig":"bf047bd1da10cabb99eea666d1e57c321eba4716dccb3e4ed0e2c5fe3ca53858",".travis.yml":"0394e2adb041175457685cde5ee05ff04bdab8885fd8a62551f2ff43d9e48872","AUTHORS":"0e0ac930a68ce2f6b876126b195add177f0d3886facb9260f4d9b69f1988f0cc","Cargo.toml":"297f0144bbebcbc2f3b5478fed750f39adb3b60f9d6c273dfa72d9736818423d","LICENSE":"44c6b5ae5ec3fe2fbc608b00e6f4896f4d2d5c7e525fcbaa3eaa3cf2f3d5a983","README.md":"e6a98ee5630b9ce1a096a2907d095454f2770e298a5b0976ab552cc53ca96cfc","src/backend/context.rs":"33d9fdf1504fe1ae43d301e288daf6eaeabeb47aa0ef86efa135c6d984425fc4","src/backend/cork_state.rs":"4a0f1afc7d9f333dac89218cc56d7d32fbffb487cd48c1c9a4e03d79cb3b5e28","src/backend/intern.rs":"374a9a3bd79fddc47739dda1dbfc5929aea5a91946794fe65fba3c8d130fbda9","src/backend/mod.rs":"06ce9250865abf0ea461f215b128470636d072a6776821efef3caf5a7b992fb9","src/backend/stream.rs":"8fcbc20908ada4ccbf635704d1ea1ef6a0f6b7d6c49a6fa9c00659ff65c7abb1","src/capi.rs":"b2c1be8128cadd36caa65c80950440f9d6f2aa0c24cc7bae6a9eaf6347ac454d","src/lib.rs":"7282560d84b134b09acfd8d6282600982e42fb3557f72454c535637cc26c7bf6"},"package":null}

Просмотреть файл

@ -7,7 +7,7 @@ use backend::*;
use backend::cork_state::CorkState;
use cubeb_backend::{ffi, log_enabled, ChannelLayout, DeviceId, DeviceRef, Error, Result,
SampleFormat, StreamOps, StreamParamsRef, StreamPrefs};
use pulse::{self, CVolumeExt, ChannelMapExt, SampleSpecExt, StreamLatency, USecExt};
use pulse::{self, ChannelMapExt, SampleSpecExt, StreamLatency, USecExt};
use pulse_ffi::*;
use std::{mem, ptr};
use std::ffi::{CStr, CString};
@ -19,8 +19,6 @@ use self::RingBufferConsumer::*;
use self::RingBufferProducer::*;
use self::LinearInputBuffer::*;
const PULSE_NO_GAIN: f32 = -1.0;
/// Iterator interface to `ChannelLayout`.
///
/// Iterates each channel in the set represented by `ChannelLayout`.
@ -362,7 +360,7 @@ impl<'ctx> PulseStream<'ctx> {
output_sample_spec: pulse::SampleSpec::default(),
input_sample_spec: pulse::SampleSpec::default(),
shutdown: false,
volume: PULSE_NO_GAIN,
volume: 1.0,
state: ffi::CUBEB_STATE_ERROR,
input_buffer_manager: None
});
@ -631,47 +629,9 @@ impl<'ctx> StreamOps for PulseStream<'ctx> {
fn set_volume(&mut self, volume: f32) -> Result<()> {
match self.output_stream {
None => Err(Error::error()),
Some(ref stm) => {
if let Some(ref context) = self.context.context {
self.context.mainloop.lock();
let mut cvol: pa_cvolume = Default::default();
/* if the pulse daemon is configured to use flat
* volumes, apply our own gain instead of changing
* the input volume on the sink. */
let flags = {
match self.context.default_sink_info {
Some(ref info) => info.flags,
_ => pulse::SinkFlags::empty(),
}
};
if flags.contains(pulse::SinkFlags::FLAT_VOLUME) {
Some(_) => {
self.volume = volume;
} else {
let channels = stm.get_sample_spec().channels;
let vol = pulse::sw_volume_from_linear(f64::from(volume));
cvol.set(u32::from(channels), vol);
let index = stm.get_index();
let context_ptr = self.context as *const _ as *mut _;
if let Ok(o) = context.set_sink_input_volume(
index,
&cvol,
context_success,
context_ptr,
) {
self.context.operation_wait(stm, &o);
}
}
self.context.mainloop.unlock();
Ok(())
} else {
Err(Error::error())
}
}
}
}
@ -936,7 +896,7 @@ impl<'ctx> PulseStream<'ctx> {
read_offset += (size / frame_size) * in_frame_size;
}
if self.volume != PULSE_NO_GAIN {
if self.volume != 1.0 {
let samples = (self.output_sample_spec.channels as usize * size
/ frame_size) as isize;
@ -1011,14 +971,6 @@ fn stream_success(_: &pulse::Stream, success: i32, u: *mut c_void) {
stm.context.mainloop.signal();
}
fn context_success(_: &pulse::Context, success: i32, u: *mut c_void) {
let ctx = unsafe { &*(u as *mut PulseContext) };
if success != 1 {
cubeb_log!("context_success ignored failure: {}", success);
}
ctx.mainloop.signal();
}
fn invalid_format() -> Error {
unsafe { Error::from_raw(ffi::CUBEB_ERROR_INVALID_FORMAT) }
}