xref: /aosp_15_r20/external/crosvm/media/libvda/tests/decode_tests.rs (revision bb4ee6a4ae7042d18b07a98463b9c8b875e44b39)
1 // Copyright 2020 The ChromiumOS Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 //! Integration tests using LibVDA fake decode implemenation.
6 
7 #![cfg(any(target_os = "android", target_os = "linux"))]
8 
9 use libvda::decode::*;
10 use libvda::*;
11 
create_vda_instance() -> VdaInstance12 fn create_vda_instance() -> VdaInstance {
13     VdaInstance::new(VdaImplType::Fake).expect("failed to create VDAInstance")
14 }
15 
16 #[test]
17 #[cfg_attr(feature = "libvda-stub", ignore = "Ignored when using libvda-stub")]
test_create_instance()18 fn test_create_instance() {
19     let instance = create_vda_instance();
20     let caps = instance.get_capabilities();
21 
22     assert_ne!(caps.input_formats.len(), 0);
23     assert_ne!(caps.output_formats.len(), 0);
24 }
25 
26 #[test]
27 #[cfg_attr(feature = "libvda-stub", ignore = "Ignored when using libvda-stub")]
test_initialize_decode_session()28 fn test_initialize_decode_session() {
29     let instance = create_vda_instance();
30     let _session = instance
31         .open_session(Profile::VP8)
32         .expect("failed to open a session for VP8");
33 }
34 
35 #[test]
36 #[cfg_attr(feature = "libvda-stub", ignore = "Ignored when using libvda-stub")]
test_decode_and_get_picture_ready_fake()37 fn test_decode_and_get_picture_ready_fake() {
38     let instance = create_vda_instance();
39     let mut session = instance
40         .open_session(Profile::VP8)
41         .expect("failed to open a session");
42 
43     // Call decode() with dummy arguments.
44     let fake_bitstream_id = 12345;
45     session
46         .decode(
47             fake_bitstream_id,
48             1, // fd
49             0, // offset
50             0, // bytes_used
51         )
52         .expect("failed to send a decode request");
53 
54     // Since we are using the fake backend,
55     // we must get a event immediately after calling decode().
56     match session.read_event() {
57         Ok(Event::PictureReady { bitstream_id, .. }) => {
58             assert_eq!(bitstream_id, fake_bitstream_id);
59         }
60         Ok(event) => panic!("Obtained event is not PictureReady but {:?}", event),
61         Err(msg) => panic!("{}", msg),
62     }
63 }
64