1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use anyhow::Context;
use argh::FromArgs;
use cros_async::Executor;
use crate::virtio::snd::parameters::Parameters;
use crate::virtio::vhost::user::device::listener::sys::VhostUserListener;
use crate::virtio::vhost::user::device::listener::VhostUserListenerTrait;
use crate::virtio::vhost::user::device::snd::SndBackend;
use crate::virtio::vhost::user::device::snd::SND_EXECUTOR;
#[derive(FromArgs)]
#[argh(subcommand, name = "snd")]
pub struct Options {
#[argh(option, arg_name = "PATH")]
socket: String,
#[argh(
option,
arg_name = "CONFIG",
from_str_fn(snd_parameters_from_str),
default = "Default::default()",
long = "config"
)]
params: Parameters,
}
fn snd_parameters_from_str(input: &str) -> Result<Parameters, String> {
serde_keyvalue::from_key_values(input).map_err(|e| e.to_string())
}
pub fn run_snd_device(opts: Options) -> anyhow::Result<()> {
let snd_device = Box::new(SndBackend::new(opts.params)?);
let ex = Executor::new().context("Failed to create executor")?;
let _ = SND_EXECUTOR.set(ex.clone());
let listener = VhostUserListener::new_socket(&opts.socket, None)?;
listener.run_device(ex, snd_device)
}