Commit graph

167 commits

Author SHA1 Message Date
Dennis Kempin
fb512a85b2 Add aarch64-linux-android target
This allows cargo to build for android. A new
dev container is built to include this.

To allow us to build the new container, we had to
remove the ffmpeg dependencies for armhf which fail
to install in the current version of debian.

BUG=b:349907813
TEST=dev_container presubmit clippy_android

Change-Id: I7fbcd460e53fbd339a28b451a91b0722d34257b8
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5689659
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2024-07-11 17:35:22 +00:00
Alexandre Courbot
bab12d56fc media/ffmpeg: implement Sync for AVCodec
Codec information is purely static and can thus be shared between
threads.

This is necessary to turn the ffmpeg backend into a trait object.

BUG=None
TEST=cargo build --features "video-decoder,vaapi,ffmpeg,libvda-stub"

Change-Id: Ia0200476a69c66ade0d622c3d7305b2125e2b067
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5606948
Auto-Submit: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2024-06-26 04:20:06 +00:00
Dennis Kempin
38d1ac5b1b Rebuild testvm and devcontainer
This uprevs both testvm and devcontainer and uploads new builds.
This will update them to the latest debian images and packages.

Some minor tweaks were made to satisfy the newer versions of
mdformat and python.

BUG=None
TEST=presubmit all --no-delta

Change-Id: I73e30aa1d9cefb5cf4ac117f513c2a98bf3c9ac5
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5416093
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-06-11 22:24:48 +00:00
Alexandre Courbot
c6f30e4d46 media/ffmpeg: more detailed error message
Knowing the dimensions is helpful here - add this information.

BUG=None
TEST=cargo build --features "video-decoder,vaapi,ffmpeg,libvda-stub"

Change-Id: I0c6f03d6fd05aee36233b2609a3e9da145decec8
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5598601
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Auto-Submit: Alexandre Courbot <acourbot@chromium.org>
2024-06-11 17:25:51 +00:00
Daniel Verkamp
52b8e42869 Cargo.toml: avoid "*" versions for external crates
Ensure that every Cargo.toml dependency on a third-party crates.io crate
specifies at least a major version, or a minor version for 0.x crates,
to ensure that if a new major version is published, it cannot cause API
breaks.

The versions are selected to match the ones already in Cargo.lock, so
this should have no functional change, but it will help prevent new "*"
versions from being introduced via copy-and-paste.

For rationale, see the Cargo FAQ:
<https://doc.rust-lang.org/cargo/faq.html#can-libraries-use--as-a-version-for-their-dependencies>

`minijail`, `audio_streams`, and `cras` are left as "*" for now, since
they have unusual situations (imported from a submodule and/or replaced
at build time with ebuild magic).

BUG=None
TEST=tools/dev_container tools/presubmit
TEST=verify Cargo.lock is unchanged

Change-Id: Ifa18199f812f01d2d10bfb4146b3353c1a76527c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5555656
Reviewed-by: Frederick Mayle <fmayle@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-05-22 01:01:42 +00:00
Kaiyi Li
c28067d1d9 Reformat comments
Test: presubmit
Change-Id: I39c261d9985989873b698213c5d8b653fc13757b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5299850
Auto-Submit: Kaiyi Li <kaiyili@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2024-02-15 23:30:13 +00:00
Daniel Verkamp
ae33ac2934 bindgen: regenerate all bindings with bindgen 0.68.1
This removes some auto-generated safety comments, but should otherwise
be a no-op.

Change-Id: Ibfcf75c6e296367fe1a6114ce2047fb79e34041b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5178534
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2024-01-09 00:37:43 +00:00
Vikram Auradkar
2768f223ee clippy: enforce safety block comments
BUG=b:316174930
TEST=none

Change-Id: I5c7811b2c548155aa003e4b71a54bbc16e2f2588
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5120567
Commit-Queue: Vikram Auradkar <auradkar@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-12-14 18:21:54 +00:00
Daniel Verkamp
324877dbd8 media: ffmpeg: generate bindings in build.rs
Generate bindings for the installed version of the ffmpeg libraries at
build time instead of checking in a static version of the bindings.

BUG=b:309563850
TEST=cargo build --features=ffmpeg

Change-Id: I38d922dd7332c4385ae6a0ae93e893538c3b1cce
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5027711
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-12-08 20:58:57 +00:00
Daniel Verkamp
92aeb322b3 media: ffmpeg: update bindings to ffmpeg 6.0
thread_safe_callbacks is removed because that field has been deprecated
and the callbacks are required to be thread safe now.

BUG=b:309563850
TEST=crosvm builds locally and boots with a working ffmpeg video device.

Change-Id: Ic6777c1c413d27c038106adbf6022eb044a5365d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/5008192
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2023-11-20 18:34:35 +00:00
A. Cody Schuffelen
97dff044f8 Replace #[cfg(unix)] with #[cfg(any(target_os = "android", target_os = "linux"))]
Updates are made to source and documentation.

This more accurately represents the currently supported platforms of
Android/Linux and Windows, without unexpectedly including other
unix-like operating systems.

Command to reproduce:
$ find . -type f -not -path '*/\.git/*' | xargs -I {} sed -i 's/cfg(unix)/cfg(any(target_os = "android", target_os = "linux"))/g' {}
$ cargo fmt

md files manually updated to fix line lengths.

Renaming `unix` modules to `linux` will be done in a later CL.

Test: ./tools/dev_container ./tools/presubmit
Bug: b/298269162
Change-Id: I42c1bf0abf80b9a0df25551613910293217c7295
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4909059
Commit-Queue: Cody Schuffelen <schuffelen@google.com>
Reviewed-by: Frederick Mayle <fmayle@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Noah Gold <nkgold@google.com>
2023-10-11 00:43:29 +00:00
Daniel Verkamp
931fcafe0b bindgen: regenerate bindings with bindgen 0.68.1
In particular, this fixes the Clone impl for __BindgenUnionField, which
triggers clippy's incorrect_clone_impl_on_copy_type in Rust 1.73.

Additionally, --size_t-is-usize became the default and the option was
removed in bindgen 0.65.0, so the flag is dropped from our bindgen
command line.

BUG=None
TEST=tools/bindgen-all-the-things

Change-Id: I40a26cd4a9e2897af8a354f454f4909429d2feda
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4927831
Reviewed-by: Zihan Chen <zihanchen@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-10-10 22:54:22 +00:00
Daniel Verkamp
ce5a78e83b clippy fixes for Rust 1.70 and 1.71
Change-Id: If86c6cd531b854293a93208de5254664f5ee6bec
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4637612
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-07-13 20:29:05 +00:00
Vikram Auradkar
f054575a8b clippy: Disallow len_without_is_empty and len_zero
BUG=b:283512997
TEST=none

Change-Id: I0477583b3f8c8eefeb1d79f11302b1b28a8bd770
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4549999
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2023-05-22 21:27:21 +00:00
Vikram Auradkar
0e1c85f293 clippy: Disallow new_without_default
BUG=b:283512997
TEST=none

Change-Id: If10b73f0cd686ff1a1a17e4aa3260f01e1ee8db5
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4546662
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Vikram Auradkar <auradkar@google.com>
2023-05-22 21:14:06 +00:00
Alexandre Courbot
82ce97e6ac media: remove local libva and cros-codecs crates
Now that we have switched to the external versions of these crates,
remove our old local copies.

BUG=b:262824148
TEST=presubmit

Change-Id: I993e56831e0f5e895c036c8b40e8181f4577ae27
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4518094
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2023-05-17 00:54:25 +00:00
Daniel Verkamp
6eec4b7768 Fix cargo doc warnings from Rust 1.68
Some type parameters in <> were being mis-parsed as HTML tags.

BUG=b:276487055
TEST=tools/cargo-doc # with rust 1.68.2

Change-Id: Iaa9ec6cf94a6084cfdf323bb04c643396a320889
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4485758
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2023-04-28 17:22:01 +00:00
Andrew Walbran
1661dfca89 Update bitflags dependency to 2.2.1.
This is a new major version, and requires some code changes.

Change-Id: I294ce3604aad6e6dc5f50e33246b690e883c1e36
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4481294
Auto-Submit: Andrew Walbran <qwandor@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2023-04-27 17:22:36 +00:00
Daniel Verkamp
2c1d17fe41 tree-wide: remove unnecessary casts
Fixes clippy lint in Rust 1.68

BUG=b:276487055
TEST=tools/clippy # with rust 1.68

Change-Id: Ib9d83b8dc15a93e815600391e93b8bb1788f7dc4
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4391107
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-04-17 23:43:59 +00:00
Daniel Verkamp
4789e79313 fuse, media/ffmpeg: remove unnecessary lifetime annotations
The references are only needed within the function call, so no lifetime is
required.

BUG=b:276487055
TEST=tools/clippy # with rust 1.68

Change-Id: I96fd94863f690ee37c953b9f7929e191a033a9c6
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4391106
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-04-12 19:24:35 +00:00
Daniel Verkamp
10a487a725 tree-wide: replace manual enum Defaults with derive
This is supported since Rust 1.62.

Fixes the new derivable_impls clippy lint, added in Rust 1.67.

BUG=b:276487055
TEST=tools/clippy # with rust 1.68

Change-Id: I3696dd3cf4acbf9b5a2cfa8c2046e7656e13dbbd
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4390735
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-04-04 22:12:39 +00:00
Alexandre Courbot
da32c2e6b2 media: cros-codecs: vaapi: factorize job management code of submit_picture
The previous CLs allow us to factorize the job management code into a
single method of the VAAPI backend structure.

BUG=b:214478588
TEST=cargo test --features vaapi -p cros-codecs

Change-Id: Ib0667cf0bc722149147c8b2f486508415fe8747d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4164546
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.corp-partner.google.com>
2023-03-02 12:34:43 +00:00
Alexandre Courbot
8812c86c7e media: cros-codecs: use BlockingMode in submit_picture
Use the right type for indicating blocking operations instead of a bool.

BUG=b:214478588
TEST=cargo test --features vaapi -p cros-codecs

Change-Id: I93abddce01ad07bc595ec6442e2b3f53dd79a555
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4164545
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.corp-partner.google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2023-03-02 12:34:43 +00:00
Alexandre Courbot
57be45a441 media: cros-codecs: vaapi: store pending VA picture into GenericBackendHandle
Pending VA pictures were stored in a pending job queue, whereas the
GenericBackendHandle only had their surface ID and received the picture
itself only when it was completed.

This design adds some dependencies between the handles and the backend,
and it makes more sense for the GenericBackendHandle to own the VA
pictures from the beginning, and transition pending pictures to the
ready state itself. The progression of PictureState from pending to
ready is made more obvious that way, and the state management can now be
centralized in GenericBackendHandle, removing duplicate code.

This also allows us to remove the PendingJob struct and replace it by
counted references to the underlying GenericBackendHandle.

BUG=b:214478588
TEST=cargo test --features vaapi -p cros-codecs

Change-Id: Id8b05ccd1524f603c61231d368a9fd234247840e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4164544
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.corp-partner.google.com>
2023-03-02 12:34:43 +00:00
Alexandre Courbot
7940c7e0c4 media: cros-codecs: vaapi: move required data to GenericBackendHandle so it can clean itself up
The destructor for BackendHandle had to take ownership of its
GenericBackendHandle in its destructor in order to return the underlying
surface to the surface pool. This means the handle had to be put behind
an Option that is always valid, but requires us to perform unwrap()s
when accessing it anyway.

By delegating the surface return to GenericBackendHandle, we can avoid
this Option and thus make the code a bit more sound.

BUG=b:214478588
TEST=cargo test --features vaapi -p cros-codecs

Change-Id: I590172b69decac3250bb9e85a67d959b1eca83f8
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4164543
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2023-03-02 12:34:43 +00:00
Alexandre Courbot
9e7b90a000 media: cros-codecs: vaapi: get coded resolution from the buffer pool
The coded resolution stored in the VAAPI backend was changed in lockstep
with the same information stored in the buffer pool. Let's remove the
former and always use the latter to avoid duplicating the same
information.

BUG=b:214478588
TEST=cargo test --features vaapi -p cros-codecs

Change-Id: I08bfb7c2aaf6609a43a2753f143a58cd06ece4c4
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4164542
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.corp-partner.google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2023-03-01 13:02:28 +00:00
Alexandre Courbot
74cd872091 media: cros-codecs: vaapi: use method to get reference to parsed metadata
The StreamMetadataState struct provides us with some useful stream
information, but some if it is only available after the initial stream
parsing is done. As a consequence, many of its accessor methods return
an error if we are in the wrong state. This check is repeated quite a
lot in code that uses StreamMetadataState even though a single check
should be enough.

Replace these accessor methods by a single method returning a reference
to the parsed state if it is accessible. This groups redundant runtime
checks for the metadata parsing state into a single check and thus
reduces the code size a bit.

BUG=b:214478588
TEST=cargo test --features vaapi -p cros-codecs

Change-Id: I2455ec7901e29f50716d535017f83e4d19b3c6fa
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4164541
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.corp-partner.google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2023-03-01 12:55:19 +00:00
Alexandre Courbot
13a7d0dcce media: cros-codecs: vaapi: rename GenericBackendHandleInner
This struct name was a bit confusing. Since it tracks the state of the
VA picture, let's change it to PictureState.

BUG=b:214478588
TEST=cargo test --features vaapi -p cros-codecs

Change-Id: Iab0ec6ea5167a736baf74520b8213660552602e8
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4164540
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.corp-partner.google.com>
2023-03-01 12:55:19 +00:00
Alexandre Courbot
0fef027582 media: cros-codecs: dummy: remove generic parameter
This generic parameter is not necessary.

BUG=b:214478588
TEST=cargo test --features vaapi -p cros-codecs

Change-Id: I79a360dab3143efee4c7bd1eeaefe996a29bd61a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4164539
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.corp-partner.google.com>
2023-03-01 12:49:53 +00:00
Alexandre Courbot
a0383690cd media: cros-codecs: h264: remove new_handle backend method
We can obtain the same thing by just cloning the backend handle, so
let's just do that.

BUG=b:214478588
TEST=cargo test --features vaapi -p cros-codecs

Change-Id: I0afb841f5d16f8161ff5c82586ef791492df0d36
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4164538
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.corp-partner.google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2023-03-01 12:48:19 +00:00
Alexandre Courbot
1cc125170a media: cros-codecs: h264: use BinaryHeap to manage the ready queue
Use a native binary heap type to keep the ready queue properly sorted
instead of calling `sort_by_key` ourselves, which is error-prone.

BUG=b:214478588
TEST=simple_decoder v4l2r test passes and returns a properly-ordered
stream.

Change-Id: I9f5c8e0290192e6b0478497335bba0889f8bce97
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4230552
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2023-03-01 12:29:23 +00:00
Alexandre Courbot
4819567e3c media: cros-codecs: remove Picture type
The Picture type is a complex generic type which purpose was to hold
both the input and output data of a stateless decoding job. It has
several drawbacks:

- While it maps nicely to VAAPI for which the output of a decoding job
  is known at the time we submit it, it won't work well with V4L2
  stateless which does not allow us to know which CAPTURE buffer will be
  used in advance.
- Before the decoding job is actually submitted, Picture objects are in
  a state where their output is not available, which makes some of its
  methods panic and allows for inconsistent state in the code. Basically
  users of Picture objects are expecting that it is either in a
  pre-submit or a post-submit state, which is dangerous.
- It's a bit complex to understand (arguably opinionated).

There is a clear separation between the pre-submit time, for which only
the input data is available, and the post-submit time, for which we are
only interested in the decoded output handle. By stopping using Picture
we can make sure that only the relevant data is available at both of
these times, and that it is valid - this removes quite a few unwrap()s
and Options and makes the code safer overall.

H.264's DPB was relying on the Picture type as it needs both the frame
information and its decoded handle, so we replace that by a dedicated
DpbEntry type.

This change strips almost 350 LoCs and ~24KB from the binary in a
release build as we now rely less on generics and monomorphization.

Since this change touches to the core of the stateless decoders, it is
necessarily big and a bit all over the place. However the net loss in
LoCs is non-negligible and the code complexity gets reduced quite a bit.

BUG=b:214478588
TEST=`cargo test --features vaapi -p cros-codecs` passes on brya.

Change-Id: Iab735905a7ae5c7285a331ee362e60dbb8f4eea0
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4164537
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2023-03-01 09:57:29 +00:00
Zihan Chen
28ce4e5423 crosvm: Uprev rust toolchain and dev container
- Rust toolchain is updated to 1.65.0
- Catapult dashboard upload tool is added to dev_container
- Bindgen is updated to latest version to support custom derive
- Derive Eq when PartialEq is derived as required by new Clippy

TEST=CQ, bindgen-all-the-things

FIXED=b:260784028
BUG=b:257303497

Change-Id: I2034cd09e0aed84d4e9b30f2e85d84d94a442ea4
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4228427
Auto-Submit: Zihan Chen <zihanchen@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Zihan Chen <zihanchen@google.com>
2023-02-08 20:26:30 +00:00
Alexandre Courbot
6bbf15f3a4 media: cros-codecs: vp8: remove backends dependency on Parser
The backends should not be aware of the Parser struct. Removing this
dependency opens the door to further factorization of the VP8 Decoder
struct.

BUG=b:214478588
TEST=cargo test --features vaapi -p cros-codecs

Change-Id: Ie92aa341ed10fccbe328d321469edfc5ae1a334a
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4160630
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.corp-partner.google.com>
2023-02-07 06:33:09 +00:00
Alexandre Courbot
3e61452215 media: cros-codecs: reorganize Decoder members
Sort the members so the common ones appear first and in the same order -
this will help us factorize this part of the code in the future.

BUG=b:214478588
TEST=cargo test --features vaapi -p cros-codecs

Change-Id: I78dedb06fef11fb00cdac88eae7b92d0010e6150
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4160629
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.corp-partner.google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2023-02-07 06:25:00 +00:00
Alexandre Courbot
0c122abbf5 media: cros-codecs: vp9: move segmentation from vaapi to common decoder code
VP9 segmentation is potentially useful to all backends and not only the
VAAPI one. Since this code is not VAAPI-dependent, move it to the common
decoder.

BUG=b:214478588
TEST=cargo test --features vaapi -p cros-codecs

Change-Id: If1970e9773de97d7923e6e230aa5a320b2d7cdc9
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4160628
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.corp-partner.google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2023-02-07 06:21:04 +00:00
Alexandre Courbot
850764ad8e media: cros-codecs: make decode() take a &[u8] as input
The decode() method used to take a generic argument that can provide a
reference to the input byte stream. This appears as a convenience but is
really not since it is trivial for the caller to obtain the byte slice
from any type that implements AsRef<[u8]>, and having the generic
parameter uselessly complicates the code and results in large amounts of
monomorphization.

By removing this generic argument, we strip ~30KB on the binary in a
release build while keeping things easier to read overall.

BUG=b:214478588
TEST=cargo test --features vaapi -p cros-codecs

Change-Id: I4a4a09151259a61fa66184dfed09a9bed286de68
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4142081
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.corp-partner.google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2023-02-02 06:38:31 +00:00
Alexandre Courbot
e06b13828f media: cros-codecs: vaapi: factorize shared parts of the backends
We are now in a state where the shared functions of all backend
implementations are implemented through `VideoDecoderBackend`, while the
codec-specific parts are done through `StatelessDecoderBackend`.

This allows us to extract the common functionality into a shared
`VaapiBackend` structure that provides the implementation of
`VideoDecoderBackend`, that each codec-specific backend will embed.

Doing so dramatically reduces the amount of duplicated code within the
VAAPI backend.

BUG=b:214478588
TEST=cargo test --features vaapi -p cros-codecs

Change-Id: I9498d31cb3da6bfe10542267b4e8fcc075792afc
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4123657
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.corp-partner.google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2023-02-02 06:37:56 +00:00
Alexandre Courbot
e057618bbf media: cros-codecs: vaapi: factorize open() implementations
We can move open() to be a generic method of StreamMetadataState if its
generic argument implement a trait for providing the necessary
information.

BUG=b:214478588
TEST=cargo test --features vaapi -p cros-codecs

Change-Id: I51efcd7e116accf5532f34de5884a988dc1d0cab
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4123656
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.corp-partner.google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2023-01-27 03:19:11 +00:00
Alexandre Courbot
9c1fa06e0f media: cros-codecs: h264: remove dpb_size parameter of new_sequence
Since we can now get the maximum number of DPB frames from the Sps
itself, we don't need that extra argument. This aligns the H.264 backend
with the others and will be helpful for the unification of code.

BUG=b:214478588
TEST=cargo test --features vaapi -p cros-codecs

Change-Id: Ia00a7cc2994497ef9c0d85567875bb920a861029
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4123659
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.corp-partner.google.com>
2023-01-27 03:16:24 +00:00
Alexandre Courbot
130a83e05d media: cros-codecs: h264: make max_dpb_frames a method of Sps
Move `max_dpb_frames` from Decoder to Sps, where it can be more useful.
This requires moving the Profile and Level enums to the parser module,
which is also a better place for them since they are part of the Sps.

This allows us to validate the Level during parsing and not every time
it is queried. Profile unfortunately is more tricky so let's leave it
untouched for now.

BUG=b:214478588
TEST=cargo test --features vaapi -p cros-codecs

Change-Id: I9ca908ef1f646c26e312449c76c2062ecb45af20
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4123658
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.corp-partner.google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2023-01-27 03:04:57 +00:00
Alexandre Courbot
595b5ad257 media: cros-codecs: vaapi: move number of surfaces to stream metadata
This information is obtained from the stream metadata, so it should
belong here. Besides doing this makes the open() methods rely only on
metadata_state, which will allow us to factorize them on the next CL.

BUG=b:214478588
TEST=cargo test --features vaapi -p cros-codecs

Change-Id: Ie4cdf1e27ca47a6c1d85334ab17d685d5aacb705
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4123655
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.corp-partner.google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2023-01-27 03:03:03 +00:00
Alexandre Courbot
80b9fa53d7 media: cros-codecs: move methods from StatelessDecoderBackend to VideoDecoderBackend
Move some methods that are common for all codecs from the `HandleType`
type from StatelessDecoderBackend to VideoDecoderBackend.

This makes the `StatelessDecoderBackend` traits implement the
codec-specific part of the backend (which requires a custom interface),
while the `VideoDecoderBackend` trait implements the shared behavior
of the backend, regardless of the underlying codec.

This separation will also allow us to factorize the implementations of
these methods further down this series.

BUG=b:214478588
TEST=cargo test --features vaapi -p cros-codecs

Change-Id: Id9f6874a1a57531ff092975f3692b10f7c1afcae
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4123654
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.corp-partner.google.com>
2023-01-27 02:54:02 +00:00
Alexandre Courbot
e010e848d5 media: cros-codecs: remove test data not originating from Chromium
In order to split cros-codecs out of the crosvm repo, we need to make
sure that there won't be any ownership issue about the video files we
host. Remove all test files not belonging to Chromium to make sure there
won't be any problem.

BUG=b:214478588
TEST=cargo test --features vaapi -p cros-codecs
TEST=`cargo test --features vaapi -p cros-codecs -- --ignored` passes on Brya

Change-Id: Ia7d168934e1a9708857052ba66b83b02e1eaa593
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4170418
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.corp-partner.google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2023-01-27 02:46:38 +00:00
Dennis Kempin
acc162000f Add conditional compilation for unix-only crates
Instead of configuring which crates to --exclude in
test_config.py, we can use conditional compilation to
exclude code that is not supported on windows.

This allows more fine-grained control and also allows
us to use plain cargo for building without complicated
configuration and exclusions.

BUG=b:265829867
TEST=cargo test --lib --bins --workspace
	--target=x86_64-pc-windows-gnu
	--features=all-mingw64

Change-Id: I8422c3f08053bc27d9896b220876a56bd25543d6
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4165868
Reviewed-by: Vikram Auradkar <auradkar@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2023-01-19 21:21:59 +00:00
Alexandre Courbot
422158d7de media: cros-codecs: vaapi: harmonize new_sequence implementations
The negotiation status should only be updated if the open() call
succeeded. Make all implementations adopt this behavior and look the
same.

BUG=b:214478588
TEST=cargo test --features vaapi -p cros-codecs

Change-Id: I2bf19eaee712b6a770796859eaf72cbad0a4ab7b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4123653
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.corp-partner.google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2023-01-10 06:17:48 +00:00
Alexandre Courbot
7751813661 media: cros-codecs: vaapi: remove unneeded matches
Directly setting the desired value (as the H.264 implementation does) is
simpler and just as efficient.

BUG=b:214478588
TEST=cargo test --features vaapi -p cros-codecs

Change-Id: I7c5f579b8a1a414602298be7e32811b8d9123faa
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4123652
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.corp-partner.google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2023-01-10 04:59:28 +00:00
Alexandre Courbot
42ffe6c92a media: cros-codecs: vaapi: factorize PendingJob
The PendingJob struct can easily be factorized by changing its generic
argument a bit.

BUG=b:214478588
TEST=cargo test --features vaapi -p cros-codecs

Change-Id: Ia03fa20ff1878d04f3a19b1f603ba9e9aa303e15
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4120378
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.corp-partner.google.com>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2023-01-10 04:49:45 +00:00
Alexandre Courbot
ea4f02028e media: cros-codecs: remove unneeded method from VideoDecoderBackend trait
supported_formats_for_stream is never called from outside the backends
themselves, and can be factorized as a utility function instead.

BUG=b:214478588
TEST=cargo test --features vaapi -p cros-codecs

Change-Id: I05568a30692099eaceefa282c94cd13defe0685b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4120377
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2023-01-10 04:49:45 +00:00
Alexandre Courbot
7a7743ed2a media: cros-codecs: vaapi: remove image_formats field
Querying the supported image formats is an operation that happens rarely
(when starting a stream or changing the resolution) and that may depend
on the dynamic conditions of the stream itself. Therefore there is
little benefit or incentive to cache it once and for all when the
backend it created - just do it on demand and simplify the backend
structs a bit.

BUG=b:214478588
TEST=cargo test --features vaapi -p cros-codecs

Change-Id: Ie5507577a0e0bd527b43955e1c551e6cb1d6a09d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4120376
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Daniel Almeida <daniel.almeida@collabora.corp-partner.google.com>
2023-01-10 04:38:38 +00:00