win_audio: build and test win_audio

BUG=b:253494168
TEST=presubmit

Change-Id: Icb729671a0dcfbc4b6251c69732784de32f6318d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3988069
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Auto-Submit: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
This commit is contained in:
Vikram Auradkar 2022-10-17 14:24:42 -07:00 committed by crosvm LUCI
parent f535849481
commit 2c6e960de3
10 changed files with 89 additions and 41 deletions

29
Cargo.lock generated
View file

@ -540,6 +540,7 @@ dependencies = [
"vhost",
"vm_control",
"vm_memory",
"win_audio",
"win_util",
"winapi",
"x86_64",
@ -712,6 +713,7 @@ dependencies = [
"vm_control",
"vm_memory",
"vmm_vhost",
"win_audio",
"win_util",
"winapi",
]
@ -2183,6 +2185,24 @@ version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17882f045410753661207383517a6f62ec3dbeb6a4ed2acce01f0728238d1983"
[[package]]
name = "win_audio"
version = "0.1.0"
dependencies = [
"anyhow",
"audio_streams",
"base",
"libc",
"metrics",
"once_cell",
"prebuilts",
"sync",
"thiserror",
"win_util",
"winapi",
"wio",
]
[[package]]
name = "win_util"
version = "0.1.0"
@ -2254,6 +2274,15 @@ dependencies = [
"windows_gen",
]
[[package]]
name = "wio"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5d129932f4644ac2396cb456385cbf9e63b5b30c6e8dc4820bdca4eb082037a5"
dependencies = [
"winapi",
]
[[package]]
name = "wire_format_derive"
version = "0.1.0"

View file

@ -398,6 +398,7 @@ sandbox = { path = "sandbox" }
cros_tracing = { path = "cros_tracing" }
tube_transporter = { path = "tube_transporter" }
winapi = "*"
win_audio = { path = "win_audio"}
win_util = { path = "win_util"}
[build-dependencies]

View file

@ -96,6 +96,7 @@ vfio_sys = { path = "../vfio_sys" }
broker_ipc = { path = "../broker_ipc" }
metrics = { path = "../metrics" }
tube_transporter = { path = "../tube_transporter" }
win_audio = { path = "../win_audio"}
win_util = { path = "../win_util"}
winapi = "*"

View file

@ -4,7 +4,7 @@ version = "0.1.0"
authors = ["The Chromium OS Authors"]
edition = "2021"
[dependencies]
[target.'cfg(windows)'.dependencies]
audio_streams = { path = "../common/audio_streams"}
base = { path = "../base" }
libc = "*"
@ -15,3 +15,8 @@ sync = { path = "../common/sync" }
thiserror = "*"
metrics = { path = "../metrics"}
once_cell = "1.7.2"
[build-dependencies]
anyhow = "*"
prebuilts = { path = "../prebuilts" }

View file

@ -2,37 +2,52 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use std::env;
static PREBUILTS_VERSION_FILENAME: &str = "prebuilts_version";
static R8BRAIN_LIB: &str = "r8Brain.lib";
static R8BRAIN_DLL: &str = "r8Brain.dll";
#[cfg(windows)]
static UCRTBASE_DLL: &str = "ucrtbased.dll";
#[cfg(windows)]
static VCRUNTIME_DLL: &str = "vcruntime140d.dll";
fn main() {
#[cfg(windows)]
{
use std::env;
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
println!("cargo:rustc-link-lib=static=r8brain");
#[cfg(debug_assertions)]
{
let dll_dir = format!(
r#"{}\..\..\..\third_party\r8brain\r8brain\x64\Debug\"#,
manifest_dir
);
println!(r#"cargo:rustc-link-search={}"#, dll_dir);
println!(
r#"cargo:rustc-env=PATH={};{}"#,
env::var("PATH").unwrap(),
dll_dir
);
}
#[cfg(not(debug_assertions))]
{
let dll_dir = format!(
r#"{}\..\..\..\third_party\r8brain\r8brain\x64\Release\"#,
manifest_dir
);
println!(r#"cargo:rustc-link-search={}"#, dll_dir);
println!(
r#"cargo:rustc-env=PATH={};{}"#,
env::var("PATH").unwrap(),
dll_dir
);
}
if std::env::var("CARGO_CFG_WINDOWS").is_ok() {
let version = std::fs::read_to_string(PREBUILTS_VERSION_FILENAME)
.unwrap()
.trim()
.parse::<u32>()
.unwrap();
// TODO(b:253039132) build prebuilts locally on windows from build.rs.
let files = prebuilts::download_prebuilts(
"r8brain",
version,
&[
R8BRAIN_DLL,
R8BRAIN_LIB,
#[cfg(windows)]
UCRTBASE_DLL,
#[cfg(windows)]
VCRUNTIME_DLL,
],
)
.unwrap();
let lib_dir = files
.get(0)
.unwrap()
.parent()
.unwrap()
.as_os_str()
.to_str()
.unwrap();
println!("cargo:rustc-link-lib=r8Brain");
println!(r#"cargo:rustc-link-search={}"#, lib_dir);
println!(
r#"cargo:rustc-env=PATH={};{}"#,
lib_dir,
env::var("PATH").unwrap(),
);
}
}

View file

@ -0,0 +1 @@
1

View file

@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#![cfg(windows)]
#![allow(non_upper_case_globals)]
include!(concat!(
env!("CARGO_MANIFEST_DIR"),

View file

@ -3,11 +3,6 @@ See instructions from: https://rust-lang.github.io/rust-bindgen/print.html
Original library: https://github.com/avaneev/r8brain-free-src
This library should be included in the third_party folder when running
`repo sync`. Otherwise the library can be cloned with:
git clone "sso://play-internal/battlestar/kiwivm/thirdparty/r8brain""
To generate bindings:
1. go to the r8brain-free-src location. In my case it'll be:

View file

@ -79,7 +79,7 @@ impl WinAudioActivateAudioInterfaceCompletionHandler {
info!("Activate Completed handler called from ActiviateAudioInterfaceAsync.");
match Event::open(ACTIVATE_AUDIO_INTERFACE_COMPLETION_EVENT) {
Ok(event) => {
event.write(1).expect("Failed to notify audioclientevent");
event.signal().expect("Failed to notify audioclientevent");
}
Err(e) => {
error!("Activate audio event cannot be opened: {}", e);
@ -173,9 +173,9 @@ const IWIN_AUDIO_COMPLETION_HANDLER_VTBL: &IActivateAudioInterfaceCompletionHand
let ref_count = (*win_audio_completion_handler).decrement_counter();
if ref_count == 0 {
// Delete the pointer
Box::from_raw(
drop(Box::from_raw(
this as *mut WinAudioActivateAudioInterfaceCompletionHandler,
);
));
}
ref_count
}

View file

@ -626,7 +626,7 @@ impl DeviceRenderer {
// never hang, but added a long timeout just incase.
match activate_audio_interface_complete_event
.unwrap()
.read_timeout(ACTIVATE_AUDIO_EVENT_TIMEOUT)
.wait_timeout(ACTIVATE_AUDIO_EVENT_TIMEOUT)
{
Ok(event_result) => match event_result {
EventWaitResult::Signaled => {}