mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2024-11-24 20:48:55 +00:00
Add socket_type to AC97Parameters
to allow testing ac97 with raw crosvm BUG=b:195267672 TEST=Unit test, CQ Change-Id: I49e2eefba76a5c3e9e1c6c213a00904162bcee08 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3146700 Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: Chih-Yang Hsia <paulhsia@chromium.org> Commit-Queue: Woody Chow <woodychow@google.com>
This commit is contained in:
parent
ab0ad4caa0
commit
b27dea4c36
2 changed files with 32 additions and 1 deletions
|
@ -82,6 +82,8 @@ pub struct Ac97Parameters {
|
|||
pub vios_server_path: Option<PathBuf>,
|
||||
#[cfg(feature = "audio_cras")]
|
||||
client_type: Option<CrasClientType>,
|
||||
#[cfg(feature = "audio_cras")]
|
||||
socket_type: Option<CrasSocketType>,
|
||||
}
|
||||
|
||||
impl Ac97Parameters {
|
||||
|
@ -93,6 +95,18 @@ impl Ac97Parameters {
|
|||
self.client_type = Some(client_type.parse()?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Set CRAS socket type by given socket type string.
|
||||
///
|
||||
/// `socket_type` - The socket type string.
|
||||
#[cfg(feature = "audio_cras")]
|
||||
pub fn set_socket_type(
|
||||
&mut self,
|
||||
socket_type: &str,
|
||||
) -> std::result::Result<(), libcras::Error> {
|
||||
self.socket_type = Some(socket_type.parse()?);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Ac97Dev {
|
||||
|
@ -168,7 +182,7 @@ impl Ac97Dev {
|
|||
#[cfg(feature = "audio_cras")]
|
||||
fn create_cras_audio_device(params: Ac97Parameters, mem: GuestMemory) -> Result<Self> {
|
||||
let mut server = Box::new(
|
||||
CrasClient::with_type(CrasSocketType::Unified)
|
||||
CrasClient::with_type(params.socket_type.unwrap_or(CrasSocketType::Unified))
|
||||
.map_err(pci_device::Error::CreateCrasClientFailed)?,
|
||||
);
|
||||
server.set_client_type(
|
||||
|
|
17
src/main.rs
17
src/main.rs
|
@ -546,6 +546,15 @@ fn parse_ac97_options(s: &str) -> argument::Result<Ac97Parameters> {
|
|||
expected: e.to_string(),
|
||||
})?;
|
||||
}
|
||||
#[cfg(feature = "audio_cras")]
|
||||
"socket_type" => {
|
||||
ac97_params
|
||||
.set_socket_type(v)
|
||||
.map_err(|e| argument::Error::InvalidValue {
|
||||
value: v.to_string(),
|
||||
expected: e.to_string(),
|
||||
})?;
|
||||
}
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
"server" => {
|
||||
ac97_params.vios_server_path =
|
||||
|
@ -2095,6 +2104,7 @@ fn run_vm(args: std::env::Args) -> std::result::Result<(), ()> {
|
|||
capture - Enable audio capture
|
||||
capture_effects - | separated effects to be enabled for recording. The only supported effect value now is EchoCancellation or aec.
|
||||
client_type - Set specific client type for cras backend.
|
||||
socket_type - Set specific socket type for cras backend.
|
||||
server - The to the VIOS server (unix socket)."),
|
||||
#[cfg(feature = "audio")]
|
||||
Argument::value("sound", "[PATH]", "Path to the VioS server socket for setting up virtio-snd devices."),
|
||||
|
@ -2955,6 +2965,13 @@ mod tests {
|
|||
.expect_err("parse should have failed");
|
||||
}
|
||||
|
||||
#[cfg(feature = "audio_cras")]
|
||||
#[test]
|
||||
fn parse_ac97_socket_type() {
|
||||
parse_ac97_options("socket_type=unified").expect("parse should have succeded");
|
||||
parse_ac97_options("socket_type=legacy").expect("parse should have succeded");
|
||||
}
|
||||
|
||||
#[cfg(feature = "audio")]
|
||||
#[test]
|
||||
fn parse_ac97_vios_valid() {
|
||||
|
|
Loading…
Reference in a new issue