archive mirror
 help / color / mirror / Atom feed
From: Daniel Almeida <>
Cc: Daniel Almeida <>,,,,
Subject: [RFC PATCH 0/1] Rewrite the VP9 codec library in Rust
Date: Tue, 27 Feb 2024 18:51:44 -0300	[thread overview]
Message-ID: <> (raw)

Hi everyone,

This patch ports the VP9 library written by Andrzej into Rust as a
proof-of-concept. This is so that we can evaluate the Rust in V4L2 initiative
with source code in hand.

It converts rkvdec and hantro to use the Rust version of the library. These two
were chosen merely because that's the hardware I currently own. Fluster scores
remain the same when using either the Rust or C version. Please test this.

Much has been spoken at various occasions about drivers and I feel that the
consensus is to wait for now. This is why I am proposing a different approach:
porting our codec libraries to Rust.

IMHO, these components can benefit greatly from Rust, as they implement
complicated algorithms that also happen to process data received from userspace
through V4L2 controls. These algorithms use the data received from userspace in
order to index into a lot of arrays and thus benefit from Rust's memory safety.

The first thing about the code is that it does not include any layer of
bindings. This was pointed out as a blocker several times due to the need of
keeping them in sync with the C code.

The Rust code here also offers a C API for C drivers.This C API is
automatically generated by cbindgen and I have provided instructions on how to
do so. We can even use functions from both the C and Rust libraries at the same
time since the ABI is the same.

The above can come in handy because it means that we can convert a given
codebase piece by piece if need be. C drivers will work as usual through the C
API and any new Rust driver will get to benefit from a native Rust interface.

Please take note that most of the code is *not* in the media tree, so I do not
see how this can further stress our subsystem. I take responsibility for
maintaining stuff in rust/kernel/media and honestly, this library will not need
any further updates for the same reason we have never touched its C

I hope to convince the community that this is a feasible way to slowly
experiment with Rust code without tying us up too much to it.

Lastly, please note that this code is just a proof of concept, we can settle on
a proper patch - with all that entails - if it is well received.

Those with hardware can follow the steps below to test this patch:

a) enable Rust (
Make sure CONFIG_RUST=y.

b) enable one of the converted drivers (CONFIG_VIDEO_HANTRO or

c) download the Fluster tool (

d) download the VP9 test suite from libvpx ( download VP9-TEST-VECTORS)

e) make sure you have a recent version of GStreamer (`gst-inspect-1.0
v4l2codecs` must not be empty) 

f) run the test suite ( run -d GStreamer-VP9-V4L2SL-Gst1.0 -ts VP9-TEST-VECTORS)

g) results should be the same both with and without this patch

-- Daniel

Applies on top of:

commit d9c1fae3e5b225f2e45e0bca519f9a2967cd1062
Author: Alice Ryhl <>
Date:   Fri Feb 9 11:18:22 2024 +0000

    rust: file: add abstraction for `poll_table`

For those looking for a branch instead:

Daniel Almeida (1):
  v4l2-core: rewrite the VP9 library in Rust

 drivers/media/platform/verisilicon/Kconfig    |    2 +-
 .../platform/verisilicon/hantro_g2_vp9_dec.c  |   38 +-
 .../media/platform/verisilicon/hantro_hw.h    |    8 +-
 drivers/media/v4l2-core/Kconfig               |    4 +
 drivers/staging/media/rkvdec/Kconfig          |    2 +-
 drivers/staging/media/rkvdec/rkvdec-vp9.c     |   52 +-
 include/media/v4l2-vp9-rs.h                   |   97 +
 rust/bindings/bindings_helper.h               |    1 +
 rust/kernel/                            |    2 +
 rust/kernel/                          |    5 +
 rust/kernel/media/                |    6 +
 rust/kernel/media/v4l2_core/cbindgen.toml     |   26 +
 rust/kernel/media/v4l2_core/            | 1999 +++++++++++++++++
 13 files changed, 2192 insertions(+), 50 deletions(-)
 create mode 100644 include/media/v4l2-vp9-rs.h
 create mode 100644 rust/kernel/
 create mode 100644 rust/kernel/media/
 create mode 100644 rust/kernel/media/v4l2_core/cbindgen.toml
 create mode 100644 rust/kernel/media/v4l2_core/


             reply	other threads:[~2024-02-27 21:55 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-27 21:51 Daniel Almeida [this message]
2024-02-27 21:51 ` [RFC PATCH 1/1] v4l2-core: rewrite the VP9 library in Rust Daniel Almeida
2024-02-28 14:13   ` Alice Ryhl
2024-02-28 17:59     ` Daniel Almeida
2024-03-07 19:08 ` [RFC PATCH v2 0/2] Rewrite parts of rkvdec driver and the VP9 codec " Daniel Almeida
2024-03-07 19:08   ` [RFC PATCH v2 1/2] v4l2-core: rewrite the VP9 " Daniel Almeida
2024-03-07 19:08   ` [RFC PATCH v2 2/2] media: rkvdec: rewrite parts of the driver " Daniel Almeida
2024-03-07 20:56     ` Nicolas Dufresne
2024-03-07 21:45       ` Daniel Almeida
2024-03-07 20:04   ` [RFC PATCH v2 0/2] Rewrite parts of rkvdec driver and the VP9 codec library " Deborah Brouwer

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:

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

  git send-email \ \ \ \ \ \ \ \ \ \ \

* 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;
as well as URLs for NNTP newsgroup(s).