mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-08 19:33:07 +00:00
media: cros-codecs: factorize dummy backends
The dummy backends behave the same regardless of the codec, so factorize their declaration as well as their implementation of VideoDecoderBackend to avoid duplicate code. BUG=b:214478588 TEST=cargo test --features vaapi -p cros-codecs Change-Id: Ibaa694b885c1ccf969aed3a0cb167a254e0eaab5 Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/4060492 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>
This commit is contained in:
parent
430f3eeb02
commit
feba776773
7 changed files with 39 additions and 108 deletions
|
@ -6,7 +6,6 @@
|
||||||
//! run so we can test it in isolation.
|
//! run so we can test it in isolation.
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::HashSet;
|
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
@ -22,40 +21,6 @@ use crate::decoders::h264::parser::Sps;
|
||||||
use crate::decoders::h264::picture::H264Picture;
|
use crate::decoders::h264::picture::H264Picture;
|
||||||
use crate::decoders::VideoDecoderBackend;
|
use crate::decoders::VideoDecoderBackend;
|
||||||
use crate::utils::dummy::*;
|
use crate::utils::dummy::*;
|
||||||
use crate::DecodedFormat;
|
|
||||||
use crate::Resolution;
|
|
||||||
|
|
||||||
pub struct Backend;
|
|
||||||
|
|
||||||
impl VideoDecoderBackend for Backend {
|
|
||||||
fn num_resources_total(&self) -> usize {
|
|
||||||
1
|
|
||||||
}
|
|
||||||
|
|
||||||
fn num_resources_left(&self) -> usize {
|
|
||||||
1
|
|
||||||
}
|
|
||||||
|
|
||||||
fn format(&self) -> Option<DecodedFormat> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
fn try_format(&mut self, _: DecodedFormat) -> crate::decoders::Result<()> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn supported_formats_for_stream(&self) -> crate::decoders::Result<HashSet<DecodedFormat>> {
|
|
||||||
Ok(HashSet::new())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn coded_resolution(&self) -> Option<Resolution> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
fn display_resolution(&self) -> Option<Resolution> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl StatelessDecoderBackend for Backend {
|
impl StatelessDecoderBackend for Backend {
|
||||||
type Handle = Handle<H264Picture<BackendHandle>>;
|
type Handle = Handle<H264Picture<BackendHandle>>;
|
||||||
|
|
|
@ -2557,7 +2557,6 @@ where
|
||||||
pub mod tests {
|
pub mod tests {
|
||||||
use std::io::Cursor;
|
use std::io::Cursor;
|
||||||
|
|
||||||
use crate::decoders::h264::backends::stateless::dummy::Backend;
|
|
||||||
use crate::decoders::h264::decoder::Decoder;
|
use crate::decoders::h264::decoder::Decoder;
|
||||||
use crate::decoders::h264::nalu_reader::NaluReader;
|
use crate::decoders::h264::nalu_reader::NaluReader;
|
||||||
use crate::decoders::h264::parser::Nalu;
|
use crate::decoders::h264::parser::Nalu;
|
||||||
|
@ -2567,6 +2566,7 @@ pub mod tests {
|
||||||
use crate::decoders::DecodedHandle;
|
use crate::decoders::DecodedHandle;
|
||||||
use crate::decoders::DynDecodedHandle;
|
use crate::decoders::DynDecodedHandle;
|
||||||
use crate::decoders::VideoDecoder;
|
use crate::decoders::VideoDecoder;
|
||||||
|
use crate::utils::dummy::Backend;
|
||||||
|
|
||||||
pub fn process_ready_frames<Handle>(
|
pub fn process_ready_frames<Handle>(
|
||||||
decoder: &mut Decoder<Handle>,
|
decoder: &mut Decoder<Handle>,
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
// run so we can test it in isolation.
|
// run so we can test it in isolation.
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::HashSet;
|
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
@ -14,40 +13,6 @@ use crate::decoders::vp8::backends::stateless::StatelessDecoderBackend;
|
||||||
use crate::decoders::vp8::backends::stateless::Vp8Picture;
|
use crate::decoders::vp8::backends::stateless::Vp8Picture;
|
||||||
use crate::decoders::VideoDecoderBackend;
|
use crate::decoders::VideoDecoderBackend;
|
||||||
use crate::utils::dummy::*;
|
use crate::utils::dummy::*;
|
||||||
use crate::DecodedFormat;
|
|
||||||
use crate::Resolution;
|
|
||||||
|
|
||||||
pub struct Backend;
|
|
||||||
|
|
||||||
impl VideoDecoderBackend for Backend {
|
|
||||||
fn num_resources_total(&self) -> usize {
|
|
||||||
1
|
|
||||||
}
|
|
||||||
|
|
||||||
fn num_resources_left(&self) -> usize {
|
|
||||||
1
|
|
||||||
}
|
|
||||||
|
|
||||||
fn format(&self) -> Option<DecodedFormat> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
fn try_format(&mut self, _: DecodedFormat) -> crate::decoders::Result<()> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn supported_formats_for_stream(&self) -> crate::decoders::Result<HashSet<DecodedFormat>> {
|
|
||||||
Ok(HashSet::new())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn coded_resolution(&self) -> Option<Resolution> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
fn display_resolution(&self) -> Option<Resolution> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl StatelessDecoderBackend for Backend {
|
impl StatelessDecoderBackend for Backend {
|
||||||
type Handle = Handle<Vp8Picture<BackendHandle>>;
|
type Handle = Handle<Vp8Picture<BackendHandle>>;
|
||||||
|
|
|
@ -462,13 +462,13 @@ pub mod tests {
|
||||||
|
|
||||||
use bytes::Buf;
|
use bytes::Buf;
|
||||||
|
|
||||||
use crate::decoders::vp8::backends::stateless::dummy::Backend;
|
|
||||||
use crate::decoders::vp8::decoder::Decoder;
|
use crate::decoders::vp8::decoder::Decoder;
|
||||||
use crate::decoders::vp8::parser::Header;
|
use crate::decoders::vp8::parser::Header;
|
||||||
use crate::decoders::BlockingMode;
|
use crate::decoders::BlockingMode;
|
||||||
use crate::decoders::DecodedHandle;
|
use crate::decoders::DecodedHandle;
|
||||||
use crate::decoders::DynDecodedHandle;
|
use crate::decoders::DynDecodedHandle;
|
||||||
use crate::decoders::VideoDecoder;
|
use crate::decoders::VideoDecoder;
|
||||||
|
use crate::utils::dummy::Backend;
|
||||||
|
|
||||||
/// Read and return the data from the next IVF packet. Returns `None` if there is no more data
|
/// Read and return the data from the next IVF packet. Returns `None` if there is no more data
|
||||||
/// to read.
|
/// to read.
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
//! run so we can test it in isolation.
|
//! run so we can test it in isolation.
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::collections::HashSet;
|
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
|
@ -15,40 +14,6 @@ use crate::decoders::vp9::backends::stateless::Vp9Picture;
|
||||||
use crate::decoders::vp9::parser::NUM_REF_FRAMES;
|
use crate::decoders::vp9::parser::NUM_REF_FRAMES;
|
||||||
use crate::decoders::VideoDecoderBackend;
|
use crate::decoders::VideoDecoderBackend;
|
||||||
use crate::utils::dummy::*;
|
use crate::utils::dummy::*;
|
||||||
use crate::DecodedFormat;
|
|
||||||
use crate::Resolution;
|
|
||||||
|
|
||||||
pub struct Backend;
|
|
||||||
|
|
||||||
impl VideoDecoderBackend for Backend {
|
|
||||||
fn num_resources_total(&self) -> usize {
|
|
||||||
1
|
|
||||||
}
|
|
||||||
|
|
||||||
fn num_resources_left(&self) -> usize {
|
|
||||||
1
|
|
||||||
}
|
|
||||||
|
|
||||||
fn format(&self) -> Option<DecodedFormat> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
fn try_format(&mut self, _: DecodedFormat) -> crate::decoders::Result<()> {
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn supported_formats_for_stream(&self) -> crate::decoders::Result<HashSet<DecodedFormat>> {
|
|
||||||
Ok(HashSet::new())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn coded_resolution(&self) -> Option<Resolution> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
fn display_resolution(&self) -> Option<Resolution> {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl StatelessDecoderBackend for Backend {
|
impl StatelessDecoderBackend for Backend {
|
||||||
type Handle = Handle<Vp9Picture<BackendHandle>>;
|
type Handle = Handle<Vp9Picture<BackendHandle>>;
|
||||||
|
|
|
@ -440,13 +440,13 @@ pub mod tests {
|
||||||
|
|
||||||
use bytes::Buf;
|
use bytes::Buf;
|
||||||
|
|
||||||
use crate::decoders::vp9::backends::stateless::dummy::Backend;
|
|
||||||
use crate::decoders::vp9::decoder::Decoder;
|
use crate::decoders::vp9::decoder::Decoder;
|
||||||
use crate::decoders::vp9::parser::Header;
|
use crate::decoders::vp9::parser::Header;
|
||||||
use crate::decoders::BlockingMode;
|
use crate::decoders::BlockingMode;
|
||||||
use crate::decoders::DecodedHandle;
|
use crate::decoders::DecodedHandle;
|
||||||
use crate::decoders::DynDecodedHandle;
|
use crate::decoders::DynDecodedHandle;
|
||||||
use crate::decoders::VideoDecoder;
|
use crate::decoders::VideoDecoder;
|
||||||
|
use crate::utils::dummy::Backend;
|
||||||
|
|
||||||
/// Read and return the data from the next IVF packet. Returns `None` if there is no more data
|
/// Read and return the data from the next IVF packet. Returns `None` if there is no more data
|
||||||
/// to read.
|
/// to read.
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
//! run so we can test it in isolation.
|
//! run so we can test it in isolation.
|
||||||
|
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
use std::collections::HashSet;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use crate::decoders::DecodedHandle;
|
use crate::decoders::DecodedHandle;
|
||||||
|
@ -14,6 +15,8 @@ use crate::decoders::FrameInfo;
|
||||||
use crate::decoders::MappableHandle;
|
use crate::decoders::MappableHandle;
|
||||||
use crate::decoders::Picture;
|
use crate::decoders::Picture;
|
||||||
use crate::decoders::Result;
|
use crate::decoders::Result;
|
||||||
|
use crate::decoders::VideoDecoderBackend;
|
||||||
|
use crate::DecodedFormat;
|
||||||
use crate::Resolution;
|
use crate::Resolution;
|
||||||
|
|
||||||
pub struct BackendHandle;
|
pub struct BackendHandle;
|
||||||
|
@ -64,3 +67,36 @@ impl<T: FrameInfo> DecodedHandle for Handle<Picture<T, BackendHandle>> {
|
||||||
|
|
||||||
fn set_display_order(&mut self, _: u64) {}
|
fn set_display_order(&mut self, _: u64) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Dummy backend that can be used for any codec.
|
||||||
|
pub struct Backend;
|
||||||
|
|
||||||
|
impl VideoDecoderBackend for Backend {
|
||||||
|
fn num_resources_total(&self) -> usize {
|
||||||
|
1
|
||||||
|
}
|
||||||
|
|
||||||
|
fn num_resources_left(&self) -> usize {
|
||||||
|
1
|
||||||
|
}
|
||||||
|
|
||||||
|
fn format(&self) -> Option<DecodedFormat> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn try_format(&mut self, _: DecodedFormat) -> crate::decoders::Result<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn supported_formats_for_stream(&self) -> crate::decoders::Result<HashSet<DecodedFormat>> {
|
||||||
|
Ok(HashSet::new())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn coded_resolution(&self) -> Option<Resolution> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn display_resolution(&self) -> Option<Resolution> {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue