crosvm: allow several video devices to be instantiated

There is no technical reason to limit the number of video decoders and
encoders that can be instantiated, so remove the current artificial
limitation of one.

BUG=b:255223604
TEST=`cargo run --features "video-decoder,ffmpeg,vaapi" -- ... --video-decoder ffmpeg --video-decoder vaapi`
results in two usable decoder devices in the guest.

Change-Id: I71cd344db6827b57daa324ccb467425fe8337b65
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3974354
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
Alexandre Courbot 2022-10-24 14:02:48 +09:00 committed by crosvm LUCI
parent 275731501a
commit 76b21794e3
3 changed files with 36 additions and 30 deletions

View file

@ -1601,7 +1601,7 @@ pub struct RunCommand {
#[argh(option, arg_name = "SOCKET_PATH")]
#[serde(skip)] // TODO(b/255223604)
/// path to a socket for vhost-user video decoder
pub vhost_user_video_decoder: Option<VhostUserOption>,
pub vhost_user_video_decoder: Vec<VhostUserOption>,
#[argh(option, arg_name = "SOCKET_PATH")]
#[serde(default)]
@ -1629,14 +1629,14 @@ pub struct RunCommand {
#[serde(skip)] // TODO(b/255223604)
/// (EXPERIMENTAL) enable virtio-video decoder device
/// Possible backend values: libvda, ffmpeg, vaapi
pub video_decoder: Option<VideoDeviceConfig>,
pub video_decoder: Vec<VideoDeviceConfig>,
#[cfg(feature = "video-encoder")]
#[argh(option, arg_name = "[backend]")]
#[serde(skip)] // TODO(b/255223604)
/// (EXPERIMENTAL) enable virtio-video encoder device
/// Possible backend values: libvda
pub video_encoder: Option<VideoDeviceConfig>,
pub video_encoder: Vec<VideoDeviceConfig>,
#[cfg(feature = "audio")]
#[argh(

View file

@ -1306,15 +1306,15 @@ pub struct Config {
pub vhost_user_mac80211_hwsim: Option<VhostUserOption>,
pub vhost_user_net: Vec<VhostUserOption>,
pub vhost_user_snd: Vec<VhostUserOption>,
pub vhost_user_video_dec: Option<VhostUserOption>,
pub vhost_user_video_dec: Vec<VhostUserOption>,
pub vhost_user_vsock: Vec<VhostUserOption>,
pub vhost_user_wl: Option<VhostUserOption>,
#[cfg(unix)]
pub vhost_vsock_device: Option<PathBuf>,
#[cfg(feature = "video-decoder")]
pub video_dec: Option<VideoDeviceConfig>,
pub video_dec: Vec<VideoDeviceConfig>,
#[cfg(feature = "video-encoder")]
pub video_enc: Option<VideoDeviceConfig>,
pub video_enc: Vec<VideoDeviceConfig>,
pub virtio_input_evdevs: Vec<PathBuf>,
pub virtio_keyboard: Vec<PathBuf>,
pub virtio_mice: Vec<PathBuf>,
@ -1502,7 +1502,7 @@ impl Default for Config {
vhost_net_device_path: PathBuf::from(VHOST_NET_PATH),
vhost_user_blk: Vec::new(),
vhost_user_console: Vec::new(),
vhost_user_video_dec: None,
vhost_user_video_dec: Vec::new(),
vhost_user_fs: Vec::new(),
vhost_user_gpu: Vec::new(),
vhost_user_mac80211_hwsim: None,
@ -1513,9 +1513,9 @@ impl Default for Config {
#[cfg(unix)]
vhost_vsock_device: None,
#[cfg(feature = "video-decoder")]
video_dec: None,
video_dec: Vec::new(),
#[cfg(feature = "video-encoder")]
video_enc: None,
video_enc: Vec::new(),
virtio_input_evdevs: Vec::new(),
virtio_keyboard: Vec::new(),
virtio_mice: Vec::new(),

View file

@ -237,22 +237,28 @@ fn create_virtio_devices(
}
#[cfg(feature = "video-decoder")]
let video_dec_cfg = if let Some(config) = &cfg.video_dec {
let (video_tube, gpu_tube) = Tube::pair().context("failed to create tube")?;
resource_bridges.push(gpu_tube);
Some((video_tube, config.backend))
} else {
None
};
let video_dec_cfg = cfg
.video_dec
.iter()
.map(|config| {
let (video_tube, gpu_tube) =
Tube::pair().expect("failed to create tube for video decoder");
resource_bridges.push(gpu_tube);
(video_tube, config.backend)
})
.collect::<Vec<_>>();
#[cfg(feature = "video-encoder")]
let video_enc_cfg = if let Some(config) = &cfg.video_enc {
let (video_tube, gpu_tube) = Tube::pair().context("failed to create tube")?;
resource_bridges.push(gpu_tube);
Some((video_tube, config.backend))
} else {
None
};
let video_enc_cfg = cfg
.video_enc
.iter()
.map(|config| {
let (video_tube, gpu_tube) =
Tube::pair().expect("failed to create tube for video encoder");
resource_bridges.push(gpu_tube);
(video_tube, config.backend)
})
.collect::<Vec<_>>();
#[cfg(feature = "gpu")]
{
@ -587,18 +593,18 @@ fn create_virtio_devices(
#[cfg(feature = "video-decoder")]
{
if let Some((video_dec_tube, video_dec_backend)) = video_dec_cfg {
for (tube, backend) in video_dec_cfg {
register_video_device(
video_dec_backend,
backend,
&mut devs,
video_dec_tube,
tube,
cfg.protection_type,
&cfg.jail_config,
VideoDeviceType::Decoder,
)?;
}
}
if let Some(socket_path) = &cfg.vhost_user_video_dec {
for socket_path in &cfg.vhost_user_video_dec {
devs.push(create_vhost_user_video_device(
cfg.protection_type,
socket_path,
@ -608,11 +614,11 @@ fn create_virtio_devices(
#[cfg(feature = "video-encoder")]
{
if let Some((video_enc_tube, video_enc_backend)) = video_enc_cfg {
for (tube, backend) in video_enc_cfg {
register_video_device(
video_enc_backend,
backend,
&mut devs,
video_enc_tube,
tube,
cfg.protection_type,
&cfg.jail_config,
VideoDeviceType::Encoder,