Add dev_type to the command line interface. This way we can select dev_type=encoder or dev_type=decoder and assign the virtio ID appropiately. If ommited, default virtio ID used is decoder's ID.
Example: -device vhost-user-video-pci,chardev=video,dev_type=encoder,id=video Signed-off-by: Albert Esteve <aest...@redhat.com> --- docs/system/devices/vhost-user-video.rst | 2 +- hw/display/vhost-user-video.c | 13 +++++++++++-- include/hw/virtio/vhost-user-video.h | 1 + 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/docs/system/devices/vhost-user-video.rst b/docs/system/devices/vhost-user-video.rst index ff0a8fe5c7..d428a773e2 100644 --- a/docs/system/devices/vhost-user-video.rst +++ b/docs/system/devices/vhost-user-video.rst @@ -72,7 +72,7 @@ use to communicate as well as share the guests memory over a memfd. :: host# qemu-system \ - -device vhost-user-video-pci,chardev=video,id=video \ + -device vhost-user-video-pci,chardev=video,dev_type=decoder,id=video \ -chardev socket,path=/tmp//video.sock,id=video \ -m 4096 \ -object memory-backend-file,id=mem,size=4G,mem-path=/dev/shm,share=on \ diff --git a/hw/display/vhost-user-video.c b/hw/display/vhost-user-video.c index 9cc6a717d5..469e9e7c89 100644 --- a/hw/display/vhost-user-video.c +++ b/hw/display/vhost-user-video.c @@ -300,8 +300,16 @@ static void vhost_user_video_device_realize(DeviceState *dev, Error **errp) return; } - /* TODO Implement VIDEO_ENC, currently only support VIDEO_DEC */ - virtio_init(vdev, VIRTIO_ID_VIDEO_DECODER, sizeof(struct virtio_video_config)); + if (video->conf.type == NULL || !strcmp(video->conf.type, "decoder")) { + virtio_init(vdev, VIRTIO_ID_VIDEO_DECODER, + sizeof(struct virtio_video_config)); + } else if (!strcmp(video->conf.type, "encoder")) { + virtio_init(vdev, VIRTIO_ID_VIDEO_ENCODER, + sizeof(struct virtio_video_config)); + } else { + error_report("invalid type received: %s", video->conf.type); + goto vhost_dev_init_failed; + } /* one command queue and one event queue */ video->vhost_dev.nvqs = 2; @@ -375,6 +383,7 @@ static const VMStateDescription vhost_user_video_vmstate = { static Property vhost_user_video_properties[] = { DEFINE_PROP_CHR("chardev", VHostUserVIDEO, conf.chardev), + DEFINE_PROP_STRING("dev_type", VHostUserVIDEO, conf.type), DEFINE_PROP_END_OF_LIST(), }; diff --git a/include/hw/virtio/vhost-user-video.h b/include/hw/virtio/vhost-user-video.h index f8329c3b36..3fe00b79a6 100644 --- a/include/hw/virtio/vhost-user-video.h +++ b/include/hw/virtio/vhost-user-video.h @@ -22,6 +22,7 @@ typedef struct { CharBackend chardev; + char *type; struct virtio_video_config config; } VHostUserVIDEOConf; -- 2.39.2