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 encode implementation.
6
7 #![cfg(unix)]
8
9 use libvda::encode::*;
10 use libvda::*;
11
create_vea_instance() -> VeaInstance12 fn create_vea_instance() -> VeaInstance {
13 VeaInstance::new(VeaImplType::Fake).expect("failed to create VeaInstance")
14 }
15
create_config() -> Config16 fn create_config() -> Config {
17 Config {
18 input_format: PixelFormat::YV12,
19 input_visible_height: 320,
20 input_visible_width: 192,
21 output_profile: Profile::H264ProfileBaseline,
22 bitrate: Bitrate {
23 mode: BitrateMode::CBR,
24 target: 100,
25 peak: 0,
26 },
27 initial_framerate: None,
28 h264_output_level: None,
29 }
30 }
31
32 #[test]
33 #[cfg_attr(feature = "libvda-stub", ignore = "Ignored when using libvda-stub")]
test_create_instance()34 fn test_create_instance() {
35 let instance = create_vea_instance();
36 let caps = instance.get_capabilities();
37
38 assert_ne!(caps.input_formats.len(), 0);
39 assert_ne!(caps.output_formats.len(), 0);
40 }
41
42 #[test]
43 #[cfg_attr(feature = "libvda-stub", ignore = "Ignored when using libvda-stub")]
test_initialize_encode_session()44 fn test_initialize_encode_session() {
45 let instance = create_vea_instance();
46 let config = create_config();
47
48 let _session = instance
49 .open_session(config)
50 .expect("failed to open a session");
51 }
52
53 #[test]
54 #[cfg_attr(feature = "libvda-stub", ignore = "Ignored when using libvda-stub")]
test_encode_and_get_buffer_back()55 fn test_encode_and_get_buffer_back() {
56 let instance = create_vea_instance();
57 let config = create_config();
58 let mut session = instance
59 .open_session(config)
60 .expect("failed to open a session");
61
62 // Call encode() with dummy arguments.
63 let fake_input_buffer_id = 12345;
64 let fake_planes = vec![];
65 session
66 .encode(
67 fake_input_buffer_id,
68 1, // fd
69 &fake_planes, // planes
70 0, // timestamp
71 false, // force_keyframe
72 )
73 .expect("failed to send an encode request");
74
75 // Since we are using the fake backend, we should get back
76 // the input buffer right away.
77 match session.read_event() {
78 Ok(Event::ProcessedInputBuffer(returned_input_buffer_id)) => {
79 assert_eq!(fake_input_buffer_id, returned_input_buffer_id);
80 }
81 Ok(event) => panic!("Obtained event is not ProcessedInputBuffer but {:?}", event),
82 Err(msg) => panic!("{}", msg),
83 }
84 }
85
86 #[test]
87 #[cfg_attr(feature = "libvda-stub", ignore = "Ignored when using libvda-stub")]
test_use_output_buffer_and_get_buffer_back()88 fn test_use_output_buffer_and_get_buffer_back() {
89 let instance = create_vea_instance();
90 let config = create_config();
91 let mut session = instance
92 .open_session(config)
93 .expect("failed to open a session");
94
95 // Call use_output_buffer with dummy arguments.
96 let fake_output_buffer_id = 12345;
97 session
98 .use_output_buffer(
99 fake_output_buffer_id,
100 2, // fd
101 0, // offset
102 0, // size
103 )
104 .expect("failed to send use_output_buffer request");
105
106 // Since we are using the fake backend, we should get back
107 // the input buffer right away.
108 match session.read_event() {
109 Ok(Event::ProcessedOutputBuffer {
110 output_buffer_id: returned_output_buffer_id,
111 ..
112 }) => {
113 assert_eq!(fake_output_buffer_id, returned_output_buffer_id);
114 }
115 Ok(event) => panic!(
116 "Obtained event is not ProcessedOutputBuffer but {:?}",
117 event
118 ),
119 Err(msg) => panic!("{}", msg),
120 }
121 }
122