From acc3aa6532e167ddf7c73d5ca001f7bd69e7eefe Mon Sep 17 00:00:00 2001 From: Alexandre Courbot Date: Tue, 1 Nov 2022 13:18:23 +0900 Subject: [PATCH] media: cros-codecs: simplify the Picture interface backend_handle_unchecked* were only used in tests, and the DynPicture interface provides equivalent functions anyway, so use these ones and drop the former. Ideally these methods that can potentially panic should be replaced by something else, but this will have to wait further cleanups. BUG=b:214478588 TEST=cargo test --features vaapi -p cros-codecs TEST=`cros-codecs --include-ignored` passes on hatch. Change-Id: I339f6893599c5ffc24e738f5ad11f35cbfcaab25 Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3998371 Reviewed-by: Keiichi Watanabe Commit-Queue: Alexandre Courbot --- media/cros-codecs/src/decoders.rs | 4 ++++ .../src/decoders/h264/backends/stateless/vaapi.rs | 4 ++-- media/cros-codecs/src/decoders/h264/picture.rs | 14 -------------- .../src/decoders/vp8/backends/stateless/vaapi.rs | 4 ++-- media/cros-codecs/src/decoders/vp8/picture.rs | 14 -------------- .../src/decoders/vp9/backends/stateless/vaapi.rs | 4 ++-- media/cros-codecs/src/decoders/vp9/picture.rs | 14 -------------- 7 files changed, 10 insertions(+), 48 deletions(-) diff --git a/media/cros-codecs/src/decoders.rs b/media/cros-codecs/src/decoders.rs index c30a898cc9..1cac3578fa 100644 --- a/media/cros-codecs/src/decoders.rs +++ b/media/cros-codecs/src/decoders.rs @@ -142,7 +142,11 @@ pub trait DynDecodedHandle { } pub trait DynPicture { + /// Gets a shared reference to the backend handle of this picture. Assumes + /// that this picture is backed by a handle and panics if not the case. fn dyn_mappable_handle(&self) -> &dyn MappableHandle; + /// Gets an exclusive reference to the backend handle of this picture. + /// Assumes that this picture is backed by a handle and panics if not the case. fn dyn_mappable_handle_mut(&mut self) -> &mut dyn MappableHandle; } diff --git a/media/cros-codecs/src/decoders/h264/backends/stateless/vaapi.rs b/media/cros-codecs/src/decoders/h264/backends/stateless/vaapi.rs index 3ed74ac39e..0551fe9831 100644 --- a/media/cros-codecs/src/decoders/h264/backends/stateless/vaapi.rs +++ b/media/cros-codecs/src/decoders/h264/backends/stateless/vaapi.rs @@ -1147,7 +1147,7 @@ mod tests { use crate::decoders::h264::decoder::tests::process_ready_frames; use crate::decoders::h264::decoder::tests::run_decoding_loop; use crate::decoders::h264::decoder::Decoder; - use crate::decoders::MappableHandle; + use crate::decoders::DynPicture; fn as_vaapi_backend( backend: &dyn StatelessDecoderBackend, @@ -1164,7 +1164,7 @@ mod tests { frame_num: i32, ) { let mut picture = handle.picture_mut(); - let backend_handle = picture.backend_handle_unchecked_mut(); + let backend_handle = picture.dyn_mappable_handle_mut(); let resolution = backend_handle.mapped_resolution().unwrap(); diff --git a/media/cros-codecs/src/decoders/h264/picture.rs b/media/cros-codecs/src/decoders/h264/picture.rs index 37b61e58f2..5f2ab0d13d 100644 --- a/media/cros-codecs/src/decoders/h264/picture.rs +++ b/media/cros-codecs/src/decoders/h264/picture.rs @@ -372,20 +372,6 @@ impl Picture { self.is_second_field = true; } - /// Gets a shared reference to the backend handle of this picture. Assumes - /// that this picture is backed by a handle, which may not be the case if - /// the picture is a "non-existing" picture, for example. - pub fn backend_handle_unchecked(&self) -> &BackendHandle { - self.backend_handle.as_ref().unwrap() - } - - /// Gets an exclusive reference to the backend handle of this picture. - /// Assumes that this picture is backed by a handle, which may not be the - /// case if the picture is a "non-existing" picture, for example. - pub fn backend_handle_unchecked_mut(&mut self) -> &mut BackendHandle { - self.backend_handle.as_mut().unwrap() - } - /// Get a reference to the picture's timestamp. pub fn timestamp(&self) -> u64 { self.timestamp diff --git a/media/cros-codecs/src/decoders/vp8/backends/stateless/vaapi.rs b/media/cros-codecs/src/decoders/vp8/backends/stateless/vaapi.rs index 6cdadf30f4..2c2ee75e91 100644 --- a/media/cros-codecs/src/decoders/vp8/backends/stateless/vaapi.rs +++ b/media/cros-codecs/src/decoders/vp8/backends/stateless/vaapi.rs @@ -817,7 +817,7 @@ mod tests { use crate::decoders::vp8::decoder::tests::process_ready_frames; use crate::decoders::vp8::decoder::tests::run_decoding_loop; use crate::decoders::vp8::decoder::Decoder; - use crate::decoders::MappableHandle; + use crate::decoders::DynPicture; fn as_vaapi_backend( backend: &dyn StatelessDecoderBackend, @@ -834,7 +834,7 @@ mod tests { frame_num: i32, ) { let mut picture = handle.picture_mut(); - let backend_handle = picture.backend_handle_unchecked_mut(); + let backend_handle = picture.dyn_mappable_handle_mut(); let resolution = backend_handle.mapped_resolution().unwrap(); diff --git a/media/cros-codecs/src/decoders/vp8/picture.rs b/media/cros-codecs/src/decoders/vp8/picture.rs index e1c9372cd6..193ecaf882 100644 --- a/media/cros-codecs/src/decoders/vp8/picture.rs +++ b/media/cros-codecs/src/decoders/vp8/picture.rs @@ -29,20 +29,6 @@ impl Picture { } } - /// Gets a shared reference to the backend handle of this picture. Assumes - /// that this picture is backed by a handle, which may not be the case if - /// the picture has "show_previous_frame" set, for example. - pub fn backend_handle_unchecked(&self) -> &T { - self.backend_handle.as_ref().unwrap() - } - - /// Gets an exclusive reference to the backend handle of this picture. - /// Assumes that this picture is backed by a handle, which may not be the - /// case if the picture has "show_previous_frame" set, for example. - pub fn backend_handle_unchecked_mut(&mut self) -> &mut T { - self.backend_handle.as_mut().unwrap() - } - /// Whether two pictures are the same. pub fn same(lhs: &Rc>, rhs: &Rc>) -> bool { Rc::ptr_eq(lhs, rhs) diff --git a/media/cros-codecs/src/decoders/vp9/backends/stateless/vaapi.rs b/media/cros-codecs/src/decoders/vp9/backends/stateless/vaapi.rs index 0d25b90b88..aafe3f11f2 100644 --- a/media/cros-codecs/src/decoders/vp9/backends/stateless/vaapi.rs +++ b/media/cros-codecs/src/decoders/vp9/backends/stateless/vaapi.rs @@ -1004,7 +1004,7 @@ mod tests { use crate::decoders::vp9::decoder::tests::run_decoding_loop; use crate::decoders::vp9::decoder::Decoder; use crate::decoders::vp9::parser::NUM_REF_FRAMES; - use crate::decoders::MappableHandle; + use crate::decoders::DynPicture; fn as_vaapi_backend( backend: &dyn StatelessDecoderBackend, @@ -1021,7 +1021,7 @@ mod tests { frame_num: i32, ) { let mut picture = handle.picture_mut(); - let backend_handle = picture.backend_handle_unchecked_mut(); + let backend_handle = picture.dyn_mappable_handle_mut(); let resolution = backend_handle.mapped_resolution().unwrap(); diff --git a/media/cros-codecs/src/decoders/vp9/picture.rs b/media/cros-codecs/src/decoders/vp9/picture.rs index b55ed8c967..b40ea106af 100644 --- a/media/cros-codecs/src/decoders/vp9/picture.rs +++ b/media/cros-codecs/src/decoders/vp9/picture.rs @@ -29,20 +29,6 @@ impl Picture { } } - /// Gets a shared reference to the backend handle of this picture. Assumes - /// that this picture is backed by a handle, which may not be the case if - /// the picture has "show_previous_frame" set, for example. - pub fn backend_handle_unchecked(&self) -> &T { - self.backend_handle.as_ref().unwrap() - } - - /// Gets an exclusive reference to the backend handle of this picture. - /// Assumes that this picture is backed by a handle, which may not be the - /// case if the picture has "show_previous_frame" set, for example. - pub fn backend_handle_unchecked_mut(&mut self) -> &mut T { - self.backend_handle.as_mut().unwrap() - } - /// Whether two pictures are the same. pub fn same(lhs: &Rc>, rhs: &Rc>) -> bool { Rc::ptr_eq(lhs, rhs)