public inbox for virtio-dev@lists.linux.dev
 help / color / mirror / Atom feed
From: Cornelia Huck <cohuck@redhat.com>
To: Alexandre Courbot <acourbot@chromium.org>
Cc: "Alexander Gordeev" <alexander.gordeev@opensynergy.com>,
	virtio-dev@lists.oasis-open.org,
	"Keiichi Watanabe" <keiichiw@chromium.org>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Marcin Wojtas" <mwojtas@google.com>,
	"Matti Möll" <Matti.Moell@opensynergy.com>,
	"Andrew Gazizov" <andrew.gazizov@opensynergy.com>,
	"Enrico Granata" <egranata@google.com>,
	"Gustavo Padovan" <gustavo.padovan@collabora.com>,
	"Peter Griffin" <peter.griffin@linaro.org>,
	"Bartłomiej Grzesik" <bag@semihalf.com>,
	"Tomasz Figa" <tfiga@chromium.org>,
	"Daniel Almeida" <daniel.almeida@collabora.com>,
	"Enric Balletbo i Serra" <eballetb@redhat.com>,
	"Albert Esteve" <aesteve@redhat.com>
Subject: Re: [virtio-dev] Re: [RFC PATCH v6] virtio-video: Add virtio video device specification
Date: Fri, 10 Mar 2023 15:20:03 +0100	[thread overview]
Message-ID: <877cvog030.fsf@redhat.com> (raw)
In-Reply-To: <CAPBb6MX+R-bDgJzracbZq6DE7B0WO=rtqS6GE1QDugdrFLryXw@mail.gmail.com>

On Fri, Mar 10 2023, Alexandre Courbot <acourbot@chromium.org> wrote:

> Hi Cornelia,
>
> On Fri, Mar 10, 2023 at 7:51 PM Cornelia Huck <cohuck@redhat.com> wrote:
>>
>> On Tue, Feb 07 2023, Cornelia Huck <cohuck@redhat.com> wrote:
>>
>> > On Tue, Feb 07 2023, Alexandre Courbot <acourbot@chromium.org> wrote:
>> >
>> >> On Mon, Feb 6, 2023 at 11:13 PM Cornelia Huck <cohuck@redhat.com> wrote:
>> >>> I hope we can sort this out soon -- I guess I'm not the only one who is
>> >>> anxious about this spec moving forward :) Please let me know if I can
>> >>> help in any way.
>> >>
>> >> I'll try to address Alexander's points in more detail, but I am not
>> >> seeing any blocking issue with using the V4L2 UAPI as the basis for
>> >> virtio-video (we are working on a small proof-of-concept and things
>> >> are going smoothly so far).
>> >
>> > Great to hear, looking forward to it!
>>
>> Quick question: Is there any git repo or similar where interested
>> parties can follow along? It would be great to have virtio-video in 1.3;
>> if you have some idea on when it might be ready, we could come up with a
>> schedule to accommodate that.
>
> I'm glad you asked, as a matter of fact I have just finished the
> virtio-v4l2 proof of concept today! It is capable of exposing a camera
> or encoder V4L2 device from the host to the guest, by encapsulating
> V4L2 commands into virtio.

\o/ Excellent news!

>
> The guest driver code (single file for simplicity):
> https://github.com/Gnurou/linux/blob/virtio-v4l2/drivers/media/virtio-v4l2/virtio_v4l2_driver.c
>
> Bulk of the host-side crosvm device code:
> https://github.com/Gnurou/crosvm/blob/virtio-v4l2/devices/src/virtio/v4l2/protocol.rs
> https://github.com/Gnurou/crosvm/blob/virtio-v4l2/devices/src/virtio/v4l2/worker.rs
>
> Neither are works of art, so please forgive the few inefficiencies
> here and there - the goal was to make them easy to understand. Still,
> the guest driver is probably closer to what a final driver would look
> like. It fits in around 1,000 LoCs (comments excluded), which is
> enough to support stateful video encoders as well as USB camera
> devices. Decoders cannot be run yet because they require support for
> V4L2 events and polling - I will try to enable these features next.
> But even in its current state this driver shows one interesting aspect
> of virtio-v4l2, at least for Linux guests: a single and relatively
> simple driver is able to drive a wide range of devices.

I had a quick look at the driver; it indeed looks like a big win on
Linux systems. (The one thing I'm missing is how easy it would be to
replicate the used v4l2 parts on non-Linux systems.)

>
> The crosvm device code proxies a V4L2 device on the host, again using
> roughly 1,200 lines of non-comment code. This design does not intend
> to reflect what an actual host device will look like - in effect they
> should be much more specialized since they are unlikely to also call
> into V4L2 on the host side. However, if the host is Linux and we just
> want to expose a USB camera or other V4L2 device almost as-is, then
> this could actually be a good fit.
>
> The protocol should be easy to understand by looking at the code - we
> only have 5 virtio commands to open/close a session, map/unmap a
> host-allocated buffer into the guest PAS, and the IOCTL command which
> sends V4L2 ioctl structures to the host and waits for its reply. All
> ioctls are synchronous per-session, meaning that a session only sends
> one ioctl at a time and waits for its response before it can send the
> next (as this is what user-space does too). Ioctls, however, never
> block on the host side and the ones that would do (DQBUF and DQEVENT)
> are replaced by host-initiated events. On top of being familiar to
> people who have worked with V4L2 (i.e. a large portion of the media
> folks), this simple design seems to be efficient as I have observed
> identical performance on both host and guest with the vicodec virtual
> encoder. Since this device generates frames using the CPU and keeps
> one core 100% busy, any overhead introduced by virtualization should
> be noticeable - yet I got nearly identical framerates on both host and
> guest.

I haven't worked with v4l2, but this approach sounds reasonable to me.

>
> Things that still need to be implemented before this can be considered
> more complete:
>
> * Controls. This should not be particularly difficult but I left it
> for now as they are not necessary to demonstrate the viability of this
> project.
> * Guest-allocated memory buffers and virtio objects. Based on our
> previous experience with virtio-video these should not be difficult to
> implement. Currently all video buffers are allocated by the host, and
> mapped into the guest if needed.
> * Events and polling, required to use a decoder. Again these were not
> strictly necessary for the proof of concept, but since we've gone this
> far I will try to get them to work as the next step.
> * Requests and multi-part media devices. This will be necessary in
> order to support more modern camera pipelines. I haven't made up my
> mind yet about whether we should support this, but if we want to it
> should not be too hard (describe several devices in the configuration
> space and enable the request-related commands). I need to talk to
> camera folks to know whether there is an actual interest in this.
> * Support for more ioctls, in case we want to support tuners and radios.
>
> If you want to try this code, you need to build the guest kernel with
> CONFIG_VIRTIO_V4L2 and enable the `v4l2` feature when building crosvm
> (check out the Book of Crosvm if you need instructions on how to build
> and use it). Then pass --virtio-v4l2=/dev/videoX to crosvm in order to
> expose the /dev/videoX host V4L2 device to the guest.
>
> I have successfully captured frames (and verified their validity)
> using the following devices:
>
> * A simple USB camera using the `uvcvideo` driver. Both host and guest
> could capture a MJPEG stream with the following command:
> v4l2-ctl -d0 -v pixelformat=MJPG --stream-mmap --stream-to=test.mjpg
>
> * The vivid virtual camera driver. I could capture a valid YUV stream
> using the following command:
> v4l2-ctl -d0 -v pixelformat=NV12 --stream-mmap --stream-to test.yuv
>
> * The encoder device of the vicodec virtual codec driver. On both host
> and guest, the following command produces a valid FWHT stream in
> `test.fwht`:
> v4l2-ctl -x pixelformat=NV12 --stream-mmap --stream-out-mmap
> --stream-to-hdr test.fwht

This looks very good already.

>
> By this work I hope to demonstrate to people interested in video
> virtualization that encapsulating V4L2 in virtio is not only a viable
> solution, it is a huge shortcut in terms of specification crafting,
> driver writing, and overall headaches involved in specifying something
> as complex as a video device. Not only could we support video decoders
> and encoders, which was the goal of virtio-video, we would also get
> image processors, video overlays and simple cameras for free, and
> potentially more complex cameras if we decide to.
>
> After writing this prototype (and a couple attempts at the
> virtio-video specification) I don't see any reason not to rely on a
> battle-tested protocol instead of designing our own that does
> basically the same thing. The genericity of V4L2 may mean that
> sometimes we will need 2 commands where virtio-video would require
> only one, but we are talking about a low frequency of virtio commands
> (60 fps for video playback typically) and that genericity comes with
> the benefit of a single Linux guest driver.
>
> If there is an agreement to move forward with this, I guess the next
> step for me will be to write a proper spec so the protocol can be
> understood and discussed in detail. Then why not try and upstream the
> kernel driver and make ChromeOS use this too in place of our
> heavily-patched virtio-video. :) We might even make it for virtio 1.3.
>
> Looking forward to your feedback. Please don't hesitate to ask
> questions, especially if you are not familiar with V4L2. I can also
> help folks interested in running this with the setup if needed.

Thank you for sharing your work! I think this looks very promising, and
I'd like to hear feedback from others as well. I assume that would make
the spec change more digestible than earlier versions.


---------------------------------------------------------------------
To unsubscribe, e-mail: virtio-dev-unsubscribe@lists.oasis-open.org
For additional commands, e-mail: virtio-dev-help@lists.oasis-open.org


  reply	other threads:[~2023-03-10 14:20 UTC|newest]

Thread overview: 93+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-08  7:23 [virtio-dev] [RFC PATCH v6] virtio-video: Add virtio video device specification Alexandre Courbot
2022-12-08 15:00 ` Cornelia Huck
2022-12-27  5:38   ` Alexandre Courbot
2023-01-11  8:45     ` Cornelia Huck
2023-01-12  6:32       ` Alexandre Courbot
2023-01-12 15:23         ` Cornelia Huck
2022-12-19 16:59 ` [virtio-dev] " Alexander Gordeev
2022-12-20  9:51   ` Cornelia Huck
2022-12-20 10:35     ` Alexander Gordeev
2022-12-20 17:39       ` Cornelia Huck
2022-12-21 14:56         ` Alexander Gordeev
2022-12-27  7:31   ` Alexandre Courbot
2023-01-11 18:42     ` Alexander Gordeev
2023-01-11 20:13       ` Alex Bennée
2023-01-12  6:40         ` Alexandre Courbot
2023-01-12  6:39       ` Alexandre Courbot
2023-01-18 23:06         ` Alexander Gordeev
2023-02-06 14:12           ` Cornelia Huck
2023-02-07  6:16             ` Alexandre Courbot
2023-02-07 13:59               ` Cornelia Huck
2023-03-10 10:50                 ` Cornelia Huck
2023-03-10 13:19                   ` Alexandre Courbot
2023-03-10 14:20                     ` Cornelia Huck [this message]
2023-03-14  5:06                       ` Alexandre Courbot
2023-03-16 10:12                         ` Alexander Gordeev
2023-03-17  7:24                           ` Alexandre Courbot
2023-04-17 12:51                             ` Alexander Gordeev
2023-04-17 14:43                               ` Cornelia Huck
2023-04-19  7:39                                 ` Alexander Gordeev
2023-04-19 21:34                                   ` Enrico Granata
2023-04-21 14:48                                     ` Alexander Gordeev
2023-04-21  4:02                                   ` Alexandre Courbot
2023-04-21 16:01                                     ` Alexander Gordeev
2023-04-24  7:52                                       ` Alexander Gordeev
2023-04-25 16:04                                         ` Cornelia Huck
2023-04-26  6:29                                           ` Alexandre Courbot
2023-04-27 14:10                                           ` Alexander Gordeev
2023-04-28  4:02                                             ` Alexandre Courbot
2023-04-28  8:54                                               ` Alexander Gordeev
2023-05-02  1:07                                                 ` Alexandre Courbot
2023-05-02 11:12                                                   ` Alexander Gordeev
2023-04-26  5:52                                         ` Alexandre Courbot
2023-04-27 14:20                                           ` Alexander Gordeev
2023-04-28  3:22                                             ` Alexandre Courbot
2023-04-28  8:22                                               ` Alexander Gordeev
2023-04-26 15:52                                     ` Alexander Gordeev
2023-04-27 13:23                                       ` Alexandre Courbot
2023-04-27 15:12                                         ` Alexander Gordeev
2023-04-28  3:24                                           ` Alexandre Courbot
2023-04-28  8:31                                             ` Alexander Gordeev
     [not found]                                     ` <CALgKJBqKWng508cB_F_uD2fy9EAvQ36rYR3fRb57sFd3ihpUFw@mail.gmail.com>
2023-04-26 16:00                                       ` Alexander Gordeev
2023-04-27 10:13                                         ` Bartłomiej Grzesik
2023-04-27 14:34                                           ` Alexander Gordeev
2023-04-28  3:22                                             ` Alexandre Courbot
2023-04-28  7:57                                               ` Alexander Gordeev
2023-04-21  4:02                               ` Alexandre Courbot
2023-04-26 15:11                                 ` Alexander Gordeev
2023-04-27 13:16                                   ` Alexandre Courbot
2023-04-28  7:47                                     ` Alexander Gordeev
2023-05-03 14:04                                       ` Cornelia Huck
2023-05-03 15:11                                         ` Alex Bennée
2023-05-03 15:53                                           ` Cornelia Huck
2023-05-05  9:57                                             ` Alexander Gordeev
     [not found]                                               ` <168329085253.1880445.14002473591422425775@Monstersaurus>
2023-05-05 15:55                                                 ` Alex Bennée
2023-05-16 12:57                                                   ` Alexander Gordeev
     [not found]                                                   ` <20230506081229.GA8114@pendragon.ideasonboard.com>
     [not found]                                                     ` <20230506081633.GB8114@pendragon.ideasonboard.com>
2023-05-08  8:00                                                       ` [virtio-dev] Re: [libcamera-devel] " Alexandre Courbot
2023-05-16 13:50                                                       ` Alexander Gordeev
2023-05-17  3:58                                                     ` Tomasz Figa
2023-05-05 12:28                                           ` Alexander Gordeev
2023-05-05 11:54                                         ` Alexander Gordeev
2023-05-08  4:55                                           ` Alexandre Courbot
2023-05-11  8:50                                             ` Alexander Gordeev
2023-05-11  9:00                                               ` Alexander Gordeev
2023-05-12  4:15                                                 ` Alexandre Courbot
2023-05-17  7:35                                                   ` Alexander Gordeev
2023-05-12  4:09                                               ` Alexandre Courbot
2023-05-16 14:53                                                 ` Alexander Gordeev
2023-05-17 16:28                                                   ` Cornelia Huck
2023-05-18  6:29                                                     ` Alexander Gordeev
2023-05-18 19:35                                                     ` Michael S. Tsirkin
2023-05-17 11:04                                                 ` Alexander Gordeev
2023-03-27 13:00                         ` Albert Esteve
2023-04-15  5:58                           ` Alexandre Courbot
2023-04-17 12:56                             ` Cornelia Huck
2023-04-17 13:13                               ` Alexander Gordeev
2023-04-17 13:22                                 ` Cornelia Huck
2023-02-07 11:11             ` Alexander Gordeev
2023-02-07  6:51           ` Alexandre Courbot
2023-02-07 10:57             ` Alexander Gordeev
2023-01-11 17:04 ` Alexander Gordeev
2023-01-12  6:32   ` Alexandre Courbot
2023-01-12 22:24     ` Alexander Gordeev
2023-01-11 18:45 ` Alexander Gordeev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=877cvog030.fsf@redhat.com \
    --to=cohuck@redhat.com \
    --cc=Matti.Moell@opensynergy.com \
    --cc=acourbot@chromium.org \
    --cc=aesteve@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=alexander.gordeev@opensynergy.com \
    --cc=andrew.gazizov@opensynergy.com \
    --cc=bag@semihalf.com \
    --cc=daniel.almeida@collabora.com \
    --cc=eballetb@redhat.com \
    --cc=egranata@google.com \
    --cc=gustavo.padovan@collabora.com \
    --cc=keiichiw@chromium.org \
    --cc=mwojtas@google.com \
    --cc=peter.griffin@linaro.org \
    --cc=tfiga@chromium.org \
    --cc=virtio-dev@lists.oasis-open.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox