Commit graph

22 commits

Author SHA1 Message Date
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
Alexandre Courbot
fc891cea82 virtio: video: decoder: add ffmpeg-based software decoder backend
The virtio video decoder device is currently only available under very
drastic conditions: a build linked against libvda (a ChromeOS-only
library that needs the cros chroot to be built and linked against), and
a ChromeOS-flavored Chrome instance running alongside crosvm, so the
browser can provide the video decoding service through Mojo.

This makes the decoder device very difficult to develop on for
non-Chromies, and also for Chromies actually since they will always need
a DUT to test it on.

This patch introduces an alternative decoder backend based on
ffmpeg's libraries that performs decoding on the host's CPU. It supports both
guest pages and virtio objects as target, and can be considered a
reliable and predictable way to test the decoder in any environment.

We introduce our own ffmpeg bindings after a quick state of the art
revealed that the existing ones were all unsuitable, either for
technical or licensing reasons. Doing so is also not a big effort and
does not add any new external crate dependency to crosvm.

BUG=b:169295147
TEST=cargo test --features "video-decoder,ffmpeg" -p devices ffmpeg
TEST=v4l2r's simple_decoder example decodes test-25fps.h264 properly with the
     following command:
     ./simple_decoder test-25fps.h264 /dev/video0 --input_format h264 --save test-25fps.nv12
TEST=ARCVM Android youtube plays videos correctly when the ffmpeg
     backend is used.

Change-Id: Ic9c586193f7939f2a3fe59d009c3666585a8bbc7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3026355
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
Reviewed-by: Keiichi Watanabe <keiichiw@chromium.org>
2022-06-07 11:44:21 +00:00