mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-09 20:04:20 +00:00
virtio: video: Add support for converting AvPixelFormat -> Format.
For simplicity, use the same error type as Format -> AvPixelFormat. This will be used and tested in the FFmpeg encoder backend. BUG=b:239897269 TEST=cargo build --features "video-encoder,video-decoder,ffmpeg" Change-Id: Ie5cf2a29379c0d52c78cee50ed6571f4859eee75 Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3924881 Reviewed-by: Alexandre Courbot <acourbot@chromium.org> Commit-Queue: Alexandre Courbot <acourbot@chromium.org>
This commit is contained in:
parent
244033437e
commit
d3e58b0275
1 changed files with 17 additions and 1 deletions
|
@ -127,7 +127,8 @@ impl TryAsAvFrameExt for GuestResource {
|
|||
}
|
||||
}
|
||||
|
||||
/// The error returned by `AvPixelFormat::try_from` when there's no applicable format.
|
||||
/// The error returned when converting between `AvPixelFormat` and `Format` and there's no
|
||||
/// applicable format.
|
||||
// The empty field prevents constructing this and allows extending it in the future.
|
||||
#[derive(Debug)]
|
||||
pub struct TryFromFormatError(());
|
||||
|
@ -159,3 +160,18 @@ impl TryFrom<Format> for AvPixelFormat {
|
|||
TryFromFormatError(()))
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<AvPixelFormat> for Format {
|
||||
type Error = TryFromFormatError;
|
||||
|
||||
fn try_from(fmt: AvPixelFormat) -> Result<Self, Self::Error> {
|
||||
// https://github.com/rust-lang/rust/issues/39371 Lint wrongly warns the consumer
|
||||
#![allow(non_upper_case_globals)]
|
||||
use ffmpeg::*;
|
||||
Ok(match fmt.pix_fmt() {
|
||||
AVPixelFormat_AV_PIX_FMT_NV12 => Format::NV12,
|
||||
AVPixelFormat_AV_PIX_FMT_YUV420P => Format::YUV420,
|
||||
_ => return Err(TryFromFormatError(())),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue