qemu_command_builder/audio.rs
1use bon::Builder;
2
3use crate::to_command::ToCommand;
4
5/// If the ``model`` option is specified, ``-audio`` is a shortcut
6/// for configuring both the guest audio hardware and the host audio
7/// backend in one go. The guest hardware model can be set with
8/// ``model=modelname``. Use ``model=help`` to list the available
9/// device types.
10///
11/// The following two example do exactly the same, to show how ``-audio``
12/// can be used to shorten the command line length:
13///
14///
15/// -audiodev pa,id=pa -device sb16,audiodev=pa
16/// -audio pa,model=sb16
17///
18/// If the ``model`` option is not specified, ``-audio`` is used to
19/// configure a default audio backend that will be used whenever the
20/// ``audiodev`` property is not set on a device or machine. In
21/// particular, ``-audio none`` ensures that no audio is produced even
22/// for machines that have embedded sound hardware.
23///
24/// In both cases, the driver option is the same as with the corresponding
25/// ``-audiodev`` option below. Use ``driver=help`` to list the available
26/// drivers.
27#[derive(Default, Builder)]
28pub struct Audio {
29 driver: String,
30 model: Option<String>,
31 property: String,
32}
33
34impl ToCommand for Audio {
35 fn to_command(&self) -> Vec<String> {
36 let mut cmd = vec!["-audio".to_string()];
37
38 let mut args = vec![format!("driver={}", self.driver.to_string())];
39 if let Some(model) = &self.model {
40 args.push(format!(",model={}", model));
41 }
42 args.push(format!(",prop={}", self.property));
43
44 cmd.push(args.join(","));
45 cmd
46 }
47}