Commit graph

51 commits

Author SHA1 Message Date
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
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
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
Daniel Verkamp
ac0fc378a3 Fix remaining Chrome/Chromium OS instances
These should be written as ChromeOS and ChromiumOS (without the space)
to match the updated branding. The copyright headers were already
migrated to the new style (https://crrev.com/c/3894243), but there were
some more instances left over.

BUG=None
TEST=tools/cargo-doc

Change-Id: I8c76aea2eb33b2e370ab71ee9b5cc0a4cfd00585
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4129934
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2023-01-03 22:14:30 +00:00
Daniel Verkamp
11a94b98a8 crosvm bindgen: regenerate with missing_safety_doc
Regenerate all of the automated bindgen bindings by running
tools/bindgen-all-the-things after commit 54311a8da9 ("crosvm bindgen:
Allow missing_safety_doc").

BUG=b:157245930
BUG=chromium:908640
TEST=tools/presubmit --all

Change-Id: I334f2ddc071acbf634f0d771d88650ee348cd5a0
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4025271
Reviewed-by: Zihan Chen <zihanchen@google.com>
Reviewed-by: Clarissa Garvey <clarissagarvey@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-11-15 20:43:50 +00:00
Dennis Kempin
8a38e8f36e Re-enable video-decoder feature
This was disabled in https://crrev.com/c/3835500 due to the lack
of ffmgeg 5.0 in our dev containers.
The container has since been upgraded in https://crrev.com/c/3892621

BUG=b:244619658
TEST=presubmit

Change-Id: Ia2bd41fbd780bad7d7706e0ffe7554e202ec0eb1
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3907377
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Auto-Submit: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-10-06 18:28:56 +00:00
Daniel Verkamp
f29a992754 tree-wide: apply cargo fmt --nightly
Fix a few recently introduced formatting mismatches.

Change-Id: I1617683532d3cc45f67ec15408fbd4ec4c9d6bb2
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3928132
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Auto-Submit: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2022-10-03 21:39:26 +00:00
Tatsuyuki Ishi
8f2ccb3b50 virtio: video: Introduce FFmpeg encoder backend.
The FFmpeg backend is a software emulated video encoder device backend.
It can be used for testing, for developing guest kernel changes and
more.

The backend roughly mirrors how the FFmpeg decoder backend is
implemented right now, with the notable difference that it does not use
swscale as the de-facto input format is NV12 or YUV420 and the guest can
likely provide buffers in that format.

BUG=b:239897269
TEST=See testing instructions in the updated book document.

Change-Id: Iae9928bdad86729f890e738acfa58e21573a115b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3920263
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-09-30 05:36:51 +00:00
Tatsuyuki Ishi
200b293626 media: ffmpeg: Convert SwConverter to a AvFrame-based API.
We were already accepting AvFrame for swscale inputs, but for the output
a different SwConverterTarget trait was being used.

The old interface had a few issues:
- The use of memory mapping traits, putting a dependency on crosvm/base
- Insufficient metadata, not being able to represent custom padding on
  the stride or non-contiguous plane layouts
- Inconsistency between input and output types

In this patch, we:
1. Introduce a AvFrame-based API to replace the old SwConverter API.
2. Add a TryAsAvFrameExt extension trait inside devices/ to convert
   virtio handles to AvFrames.
   (This is placed inside devices to avoid ffmpeg depending on base.)
3. Add a new wrapper type, MemoryMappingAvBufferSource, that wraps a
   MemoryMappingArena and implements AvBufferSource for it. This was
   technically not sound, but it's a low-risk attack vector that we
   implicitly allowed before. The patch doesn't change the behavior; it
   just makes this assumption more explicit.

BUG=b:239897269
TEST=cargo test --features "video-decoder,ffmpeg" -p devices -p ffmpeg

Change-Id: Id15e19b7d2452d1bc722a65f941c2c9150876205
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3889245
Commit-Queue: Tatsuyuki Ishi <ishitatsuyuki@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-09-29 09:47:01 +00:00
Tatsuyuki Ishi
aa3abc82fa media: ffmpeg: Add empty AvPacket constructor.
The buffer will be allocated by FFmpeg on-demand. This will be used in
encoding scenarios.

BUG=b:239897269
TEST=cargo test --features "video-decoder,ffmpeg" -p devices -p ffmpeg

Change-Id: Ie1e83a6a1129ea666bb3580a669beb7c6cbc8c10
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3920260
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-09-29 04:13:01 +00:00
Tatsuyuki Ishi
02b2a39215 media: ffmpeg: Add AsRef into FFI struct for AvPacket.
For reading out the packet size and flags. We already have AsRef
implementations for AVCodecContext and AVFrame.

BUG=b:239897269
TEST=cargo test --features "video-decoder,ffmpeg" -p devices -p ffmpeg

Change-Id: Ie330c1863f989211dcad758cd8df96058dfbc2ea
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3920259
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-09-29 04:13:01 +00:00
Tatsuyuki Ishi
93bac69f36 media: ffmpeg: Add setters for AVCodecContext properties.
Add setters for time_base, bit_rate and rc_max_rate for use in encoder.

BUG=b:239897269
TEST=cargo test --features "video-decoder,ffmpeg" -p devices -p ffmpeg

Change-Id: If006abf5b32cdb740c33075f8d5f480c65c20806
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3920258
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-09-29 04:13:01 +00:00
Tatsuyuki Ishi
cb509c8972 media: ffmpeg: Add is_writable and make_writable helpers for AvFrame.
These covers the "writable" notion exposed by FFmpeg. If a non-writable
frame is passed to a codec, the codec will clone the frame before
writing to it. Some interfaces (notably swscale) doesn't respect this
convention yet; for those, we'll add our own checks for writeability so
ideally this copy-on-write convention is held everywhere within our
bindings.

BUG=b:239897269
TEST=cargo test --features "video-decoder,ffmpeg" -p ffmpeg -p devices

Change-Id: I566f44a44491a7507bd6446e1bf8e1f8550f16d6
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3920257
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-09-29 04:13:01 +00:00
Tatsuyuki Ishi
5924952188 media: ffmpeg: Fix doctest failure.
Fixes the following failure:

error[E0659]: `ffmpeg` is ambiguous
  --> crosvm/media/ffmpeg/src/lib.rs:11:5
   |
11 | use ffmpeg as ffi;
   |     ^^^^^^ ambiguous name
   |
   = note: ambiguous because of multiple potential import sources
   = note: `ffmpeg` could refer to a crate passed with `--extern`
   = help: use `::ffmpeg` to refer to this crate unambiguously
note: `ffmpeg` could also refer to the module defined here
  --> crosvm/media/ffmpeg/src/lib.rs:10:1
   |
10 | mod ffmpeg;
   | ^^^^^^^^^^^
   = help: use `crate::ffmpeg` to refer to this module unambiguously

BUG=None
TEST=cargo test -p ffmpeg

Change-Id: I6665bec21336c78cd773593cd0310e996a345e1d
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3924262
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-09-29 04:13:01 +00:00
Tatsuyuki Ishi
18b779fef0 virtio: video: Add conversion helper for virtio Format to AvPixelFormat.
Generalize and move it out of the decoder for potential future use in
the encoder module.

A ffmpeg.rs module is introduced to accommodate any video-related code
that requires the ffmpeg feature flag, similar to what we have for
libvda.

BUG=b:239897269
TEST=cargo test --features "video-decoder,ffmpeg" -p ffmpeg -p devices

Change-Id: I341d6d238b5593d16cbdc8dd8c96eb2fa4e143fe
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3911109
Commit-Queue: Tatsuyuki Ishi <ishitatsuyuki@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-09-28 02:54:50 +00:00
Tatsuyuki Ishi
0d94089855 media: ffmpeg: Add helper to create AvPixelFormat from raw enum values.
Since re-enumerating all the formats supported by FFmpeg in our bindings
would be a rather large effort, it looks like a good compromise here is
to allow the user to create an AvPixelFormat from the raw enum values
exposed by bindgen.

Add a helper that checks that the value is in range of valid formats and
convert it into our enum wrapper.

BUG=b:239897269
TEST=cargo test --features ffmpeg -p ffmpeg

Change-Id: I3c1433e9d76d645b7615bde81433e1df2cfa3910
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3911108
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-09-28 02:54:50 +00:00
Tatsuyuki Ishi
b1815c4042 media: ffmpeg: Fix test_averror not compiling.
Broke in 03e1b667 ("media/ffmpeg: use bindgen-common.sh").

BUG=None
TEST=cargo test -p ffmpeg

Change-Id: I7e0bb5f9b41f785d63a92099130d183600a7985b
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3907424
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Auto-Submit: Tatsuyuki Ishi <ishitatsuyuki@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Tatsuyuki Ishi <ishitatsuyuki@google.com>
2022-09-20 07:59:27 +00:00
Tatsuyuki Ishi
f30d6fd9e8 media: ffmpeg: Add a separate flush helper for encoder.
The decoder and encoder uses different calls for flushing. Add a new
flush_encoder helper for that, and rename the existing one to
flush_decoder.

BUG=b:239897269
TEST=cargo test --features "video-decoder,ffmpeg" -p ffmpeg -p devices

Change-Id: Id237424209dc8d64d43424570003d735ee164d36
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3868598
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Tatsuyuki Ishi <ishitatsuyuki@google.com>
2022-09-20 04:27:00 +00:00
Tatsuyuki Ishi
8a2af8f2ff media: ffmpeg: Add bindings for encoding methods.
try_send_frame and try_receive_packet together forms the basis of the
(AVFrame-based) encoding API. This change adds helper methods for them,
with the return value being handled similarly to their decoding
counterpart.

TryReceiveFrameResult has been renamed to TryReceiveResult as the
encoding interface shares the handling of these return codes, and we'll
be sharing this logic between try_receive_packet and try_receive_frame.

BUG=b:239897269
TEST=cargo test --features "video-decoder,ffmpeg" -p ffmpeg -p devices

Change-Id: I32c11053daed86c32067ac2b2a8f7218f6dbcd4f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3868597
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-09-20 04:27:00 +00:00
Tatsuyuki Ishi
7b0dde4d8d media: ffmpeg: Add helpers to build an AvFrame with metadata and buffers
This API allows the user to allocate and set the buffer/data of an AvFrame.
This will be needed when using AvFrame as encoder input.

BUG=b:239897269
TEST=cargo test --features "video-decoder,ffmpeg" -p ffmpeg -p devices

Change-Id: If2c46a1b19f5fb98a296ca42b1917f8260174c83
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3868596
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-09-20 04:27:00 +00:00
Tatsuyuki Ishi
55d8d9b4eb media: ffmpeg: Add helpers for determining line and plane sizes.
These are wrappers of av_image_get_linesize and
av_image_fill_plane_sizes, and will be used for bounds checking and
mmap bounds calculation purposes.

It's kind of weird that one is singular and the other is plural, but
we should probably blame FFmpeg for not having a singular version of
av_image_fill_plane_sizes.

BUG=b:239897269
TEST=cargo test --features "video-decoder,ffmpeg" -p ffmpeg -p devices

Change-Id: I34104f5062089377aeab0d4a4ab0534837e56d6f
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3868595
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-09-20 04:27:00 +00:00
Tatsuyuki Ishi
40ba620f0a media: ffmpeg: Add encoder context builder.
Similar to the decoder builder, add an encoder context builder.

The encoder requires a few more parameters to be set before calling
avcodec2_open, and the respective setters are provided here. As for
checking for the required fields, it looks like FFmpeg will check it and
error on avcodec2_open if any are missing anyway, so we'll avoid
duplicating that on the binding side.

BUG=b:239897269
TEST=cargo build --features ffmpeg -p ffmpeg

Change-Id: I448b56ba9bae9b38ce5c2fb540e9577a2dfcd83c
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3856043
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-09-20 04:27:00 +00:00
Daniel Verkamp
150384ad2d media/ffmpeg: only show VERSIONS notice on change
Check if the VERSIONS file actually changed before printing the related
message.

Also print the path to the VERSIONS file to give some more context.

BUG=None
TEST=media/ffmpeg/bindgen.sh

Change-Id: I6e7cd2ace37ca99ed744a307675272a2e3c205f6
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3893752
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-09-14 18:01:56 +00:00
Daniel Verkamp
03e1b667e3 media/ffmpeg: use bindgen-common.sh
Switch to the common bindgen wrapper so that the ffmpeg bindings get the
same defaults as other bindgen-generated bindings.

BUG=None
TEST=media/ffmpeg/bindgen.sh
TEST=cargo build --features=ffmpeg,video-decoder

Change-Id: I09901c122401fe1b65eed154a6be8348decfcc33
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3893751
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
2022-09-14 17:55:56 +00:00
Daniel Verkamp
7c6d8bec3f health-check: enforce blank line after copyright
While we are tweaking all of the copyright headers, let's take the
opportunity to ensure there is always a blank line after the copyright
header for consistency. (Almost all files already follow this style.)

This includes a slightly ugly regex to allow the end of a C-style
comment block after the end of the copyright:

/*
 * Example comment block
 */   <-- this line

Change-Id: Idfd0855861e5ecb3d33afae942fdba908af0dcff
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3892521
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2022-09-13 22:24:35 +00:00
Dennis Kempin
1dab58a2cf Update all copyright headers to match new style
This search/replace updates all copyright notices to drop the
"All rights reserved", Use "ChromiumOS" instead of "Chromium OS"
and drops the trailing dots.

This fulfills the request from legal and unifies our notices.

./tools/health-check has been updated to only accept this style.

BUG=b:246579983
TEST=./tools/health-check

Change-Id: I87a80701dc651f1baf4820e5cc42469d7c5f5bf7
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3894243
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-09-13 18:41:29 +00:00
Dennis Kempin
78f62a44e7 Update copyright header check to cover all files
generated files and a list of excluded files are skipped.
Others are fixed to include the missing header.

BUG=b:246579983
TEST=./tools/health-check --all copyright_header

Change-Id: I13e9bf79df18789f1ed4b83fc47c0c2e080d70a8
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3894240
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
2022-09-13 18:41:29 +00:00
Tatsuyuki Ishi
8cef8b7e64 media: ffmpeg: Fix AvPacket test not compiling.
Changed missed by accident in 61d72266 (media: ffmpeg: Take AvBuffer
directly in AvPacket::new_owned). The later commits were tested but it
was grouped into the wrong commit in rebase.

BUG=b:239897269
TEST=cargo test --features "video-decoder,ffmpeg" -p ffmpeg -p devices

Change-Id: Iabdcc98833b24271f4701fb210e0e5733d1f9f12
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3868594
Tested-by: Tatsuyuki Ishi <ishitatsuyuki@google.com>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
2022-09-05 13:00:53 +00:00
Tatsuyuki Ishi
325e9f5bca media: ffmpeg: Add a builder for decoding AvCodecContext.
Creating a context frequently involves optional parameters, and the
builder pattern handles this more descriptively, especially in the case
of an encoder context.

Encoder support is coming in a later commit, but it's a good idea to
align the decoder to use the builder pattern to ensure a consistent way
of doing things.

BUG=b:239897269
TEST=cargo test --features "video-decoder,ffmpeg" -p devices video

Change-Id: I92bd5f72b638c13a3257d54238b1beb229c64fa0
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3856042
Tested-by: Tatsuyuki Ishi <ishitatsuyuki@google.com>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Tatsuyuki Ishi <ishitatsuyuki@google.com>
2022-09-01 03:21:20 +00:00
Tatsuyuki Ishi
61d72266e4 media: ffmpeg: Take AvBuffer directly in AvPacket::new_owned.
With more types going to support AvPacket in the future, it's probably
more maintainable to separate the construction of AvBuffer from the
consumer types.

The borrowing constructor will still take AvBufferSource generically as
it doesn't have a buffer object to construct.

As AvBuffer is directly used in the interface now, make its definition
and methods public.

BUG=None
TEST=cargo test --features "video-decoder,ffmpeg" -p ffmpeg -p video

Change-Id: I0959d383438a94d562fc6ff34c40389e98be7bfd
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3833772
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Commit-Queue: Tatsuyuki Ishi <ishitatsuyuki@google.com>
Tested-by: Tatsuyuki Ishi <ishitatsuyuki@google.com>
2022-09-01 03:13:29 +00:00
Tatsuyuki Ishi
7fcbd8e9e1 media: ffmpeg: Add 'static bounds to AvBuffer::new.
The previous signature allowed lifetime laundering if code like below
was used:

impl<'a> AvBufferSource for &'a mut [u8] { ... }

fn foo() {
    let mut storage = vec![];
    let buf = AvBuffer::new(storage.deref_mut());
    drop(storage);
    // buf can be used after free
}

Add a 'static bound to prevent it.

BUG=None
TEST=cargo build --release --features "video-decoder,ffmpeg" -p devices

Change-Id: Ifda2793a3e3d4d8b400fa076f1d6f9474d0ae159
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3833771
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Tatsuyuki Ishi <ishitatsuyuki@google.com>
Tested-by: Tatsuyuki Ishi <ishitatsuyuki@google.com>
2022-08-31 05:42:58 +00:00
Alexandre Courbot
aa4c70e3da media: ffmpeg: upgrade to ffmpeg 5.0 libraries
Update the ffmpeg bindings and build script to use 5.0 and update our
code to match the API changes since 4.4.

BUG=None
TEST=cargo test -p ffmpeg
TEST=cargo test --features "video-decoder,ffmpeg" -p devices video
TEST=v4l2r example from the crosvm book passses.

Change-Id: If7820a4dd270d715e89c60d55f89b9730f40e864
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3835501
Reviewed-by: Tatsuyuki Ishi <ishitatsuyuki@google.com>
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Takaya Saeki <takayas@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2022-08-23 01:47:48 +00:00
Tatsuyuki Ishi
4a129dfd54 media: ffmpeg: Fix doc comment on AvBuffer::into_raw.
To make it appear in the docs we need to use triple slash instead of
two.

BUG=None
TEST=cargo doc -p ffmpeg --features ffmpeg

Link: https://chromium-review.googlesource.com/id/I3bb869a33f23358e9787c50f923b61f879104d77
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3841002
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Auto-Submit: Tatsuyuki Ishi <ishitatsuyuki@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: Tatsuyuki Ishi <ishitatsuyuki@google.com>
Reviewed-by: Takaya Saeki <takayas@chromium.org>
2022-08-19 13:31:46 +00:00
Tatsuyuki Ishi
96e98ef882 media: ffmpeg: Remove AsMut from AvFrame.
This is actually highly unsound since it allows you to write arbitrary
garbage to the buffer pointer fields.

BUG=None
TEST=cargo test -p ffmpeg &&
     cargo test --features "video-decoder,ffmpeg" -p devices video
     + v4l2r test from crosvm book

Change-Id: I77bd32b856afef8538791a99829f7248cd77787e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3822433
Tested-by: Tatsuyuki Ishi <ishitatsuyuki@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Tatsuyuki Ishi <ishitatsuyuki@google.com>
2022-08-12 04:48:35 +00:00
Tatsuyuki Ishi
894b15044d media: ffmpeg: Add AvError::result to convert simple return codes.
We're going to use this pattern more in future CLs, so factor it out to
a helper.

BUG=None
TEST=cargo test -p ffmpeg &&
     cargo test --features "video-decoder,ffmpeg" -p devices video
     + v4l2r test from crosvm book

Change-Id: Ic20555f8a4ebf0403cc2f933c92bb9bb1d3f51f9
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3822432
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Tatsuyuki Ishi <ishitatsuyuki@google.com>
Tested-by: Tatsuyuki Ishi <ishitatsuyuki@google.com>
2022-08-12 04:48:35 +00:00
Tatsuyuki Ishi
d06145a1ce media: ffmpeg: Add binding to obtain the required buffer alignment.
FFmpeg requires buffer alignment in case of SIMD-accelerated codec
implementations. This patch prepares for exposing the
respective requirement in the virtio-video interface.

BUG=None
TEST=cargo build -p ffmpeg

Change-Id: Ia8f3b2987571ddb8cf84b1201019ded83547e8f0
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3822430
Commit-Queue: Tatsuyuki Ishi <ishitatsuyuki@google.com>
Tested-by: Tatsuyuki Ishi <ishitatsuyuki@google.com>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-08-12 04:48:35 +00:00
Daniel Verkamp
cd251b3067 Reformat imports with tools/fmt --nightly
A few new grouped imports have made it in since the tree-wide
reformatting.

BUG=None
TEST=tools/presubmit

Change-Id: I93af3c741f57c1da73d4c9e8a28be424c1ea45fe
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3818244
Auto-Submit: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Daniel Verkamp <dverkamp@chromium.org>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
Reviewed-by: Dennis Kempin <denniskempin@google.com>
2022-08-08 20:29:50 +00:00
Tatsuyuki Ishi
7a4c220485 media: ffmpeg: Free AvPacket through av_free_packet.
We used to unref the owned AVBufferRef manually but this is actually
handled by ffmpeg if you call the right destructor for AVPacket.

Do that, remove our internal ownership handling for AvPacket and add a
unit test to confirm we don't leak memory.

BUG=None
TEST=cargo test -p ffmpeg &&
     cargo test --features "video-decoder,ffmpeg" -p devices video

Change-Id: I2fbe1c12568ceca0c51013c789c30d6b78059e00
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3813254
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
Tested-by: Tatsuyuki Ishi <ishitatsuyuki@google.com>
Commit-Queue: Tatsuyuki Ishi <ishitatsuyuki@google.com>
2022-08-08 05:34:44 +00:00
Alexandre Courbot
5eba4ce565 media: ffmpeg: add pixel format wrapper and iterator
For the encoder device, we will need to be able to iterate over the
supported pixel formats in order to expose the ones that are supported.
Add a type to wrap the native AVPixelFormat as well as an iterator to
AvCodec that will let us list all the available pixel formats.

BUG=b:239897269
TEST=cargo build --features "video-decoder,ffmpeg"

Change-Id: Ia835dc428b221c70178f2cd6634566001f3a9256
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3782040
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Reviewed-by: Tatsuyuki Ishi <ishitatsuyuki@google.com>
Auto-Submit: Alexandre Courbot <acourbot@chromium.org>
2022-08-05 11:09:42 +00:00
Tatsuyuki Ishi
8fd1ec600d media: ffmpeg: Replace #[allow(dead_code)] with underscore prefix.
It's slightly less verbose and more idiomatic to do it this way.

BUG=None
TEST=cargo build

Change-Id: I1f67f88543b5e65cb187406179e463b9182fade5
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3809196
Commit-Queue: Tatsuyuki Ishi <ishitatsuyuki@google.com>
Tested-by: Tatsuyuki Ishi <ishitatsuyuki@google.com>
Reviewed-by: Junichi Uekawa <uekawa@chromium.org>
Reviewed-by: Alexandre Courbot <acourbot@chromium.org>
2022-08-04 06:47:43 +00:00
Alexandre Courbot
874fd42c93 media: ffmpeg: allow detection of encoder codecs
Since we are going to support encoding, add a method to detect whether a
given codec is an encoder.

BUG=b:239897269
TEST=cargo build --features "video-decoder,ffmpeg"

Change-Id: I547fa6acafc4580f3f2f05c1a82955212d4d6e84
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3782041
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Auto-Submit: Alexandre Courbot <acourbot@chromium.org>
2022-08-04 03:31:01 +00:00
Alexandre Courbot
89b7ba4512 media: ffmpeg: add proper wrapper for AVProfile
Our ffmpeg crate should avoid returning native C avcodec types if
possible, as this means client code could have to resort to unsafe code.
Fix this for AVProfile by introducing a safe wrapper type that provides
us all the useful methods we may need.

BUG=b:169295147
TEST=cargo build --features "video-decoder,ffmpeg"

Change-Id: I2436857d3878b5b6cf4eab35f5b3b0c57c8db60e
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3782039
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Auto-Submit: Alexandre Courbot <acourbot@chromium.org>
2022-08-04 03:30:02 +00:00
Alexandre Courbot
ae02641b1b media: ffmpeg: allow zero-copy for input packets
Add a wrapper for libavcodec's AVBufferRef and allow AvPacket to be
built from one ; this makes the AvPacket the owner of the data and means
it doesn't need to internally copy it.

The input data will be dropped once avcodec signals that it doesn't need
it anymore.

BUG=b:169295147
TEST=v4l2r's simple_decoder can decode a H.264 stream.

Change-Id: I9fa54124daed031fd1f397eaa8d57dc73f83c9b8
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3782037
Reviewed-by: Takaya Saeki <takayas@chromium.org>
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2022-07-30 02:52:32 +00:00
Dennis Kempin
4fea399df9 Reformat imports
crosvm is switching the import style to use one import per line.
While more verbose, this will greatly reduce the occurence of merge
conflicts going forward.

Note: This is using a nightly feature of rustfmt. So it's a one-off
re-format only. We are considering adding a nightly toolchain to
enable the feature permanently.

BUG=b:239937122
TEST=CQ

Change-Id: Id2dd4dbdc0adfc4f8f3dd1d09da1daafa2a39992
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3784345
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: Dennis Kempin <denniskempin@google.com>
Commit-Queue: Dennis Kempin <denniskempin@google.com>
2022-07-28 00:15:50 +00:00
Alexandre Courbot
49c8cd6160 media: ffmpeg: reduce dependency on base
We want the ffmpeg crate to be independent of crosvm - remove a
dependency to base by adding a dedicated trait for types that can be
used as sources to a ffmpeg buffer.

BUG=b:169295147
TEST=v4l2r's simple_decoder can decode a H.264 stream.

Change-Id: I2ae6c2678a6a672746e6fc11a70dee692986db69
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3782032
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Takaya Saeki <takayas@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Tested-by: Alexandre Courbot <acourbot@chromium.org>
2022-07-27 07:30:48 +00:00
Alexandre Courbot
ad05940dcf media: ffmpeg: remove generic type from AvPacket
We only need to enforce a lifetime to the data source of the packet ; we
are not interested in its type. Replace it by () and remove that generic
parameter.

BUG=b:169295147
TEST=cargo build --features "video-decoder,ffmpeg"

Change-Id: Ibd9e976cab9dcc9cf0a44487580eb067211cc9b8
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3782031
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
2022-07-27 00:24:18 +00:00
Alexandre Courbot
1cb3c121ee media: ffmpeg: simplify codec name method
Being able to build an AvCodec means that the returned name will be
valid - unless there is a bug in libavcodec itself. Simplify the method
returning the codec's name to not return an Option, but instead a string
representing an invalid codec in the unlikely case we actually get one.

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

Change-Id: Ic2c1b5db5391c421ae6f78faabcfe3197090ce17
Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3782030
Tested-by: Alexandre Courbot <acourbot@chromium.org>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Takaya Saeki <takayas@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2022-07-26 03:46:06 +00:00