• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2020 The Android Open Source Project
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //      http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 #include <string>
15 
16 #include "InputConfig.pb.h"
17 #include "Options.pb.h"
18 #include "gmock/gmock-matchers.h"
19 #include "gmock/gmock.h"
20 #include "gtest/gtest.h"
21 #include "runner/client_interface/PipeOptionsConverter.h"
22 #include "types/Status.h"
23 
24 using ::aidl::android::automotive::computepipe::runner::PipeDescriptor;
25 using ::aidl::android::automotive::computepipe::runner::PipeInputConfigCameraType;
26 using ::aidl::android::automotive::computepipe::runner::PipeInputConfigFormatType;
27 using ::aidl::android::automotive::computepipe::runner::PipeInputConfigImageFileType;
28 using ::aidl::android::automotive::computepipe::runner::PipeInputConfigInputType;
29 using ::aidl::android::automotive::computepipe::runner::PipeInputConfigVideoFileType;
30 
31 namespace android {
32 namespace automotive {
33 namespace computepipe {
34 namespace runner {
35 namespace client_interface {
36 namespace aidl_client {
37 namespace {
38 
TEST(OptionsToPipeDescriptorTest,InputTypesConvertAsExpected)39 TEST(OptionsToPipeDescriptorTest, InputTypesConvertAsExpected) {
40     proto::Options options;
41 
42     // Add a driver view camera type
43     options.add_input_configs()->add_input_stream()->set_type(
44         proto::InputStreamConfig_InputType_CAMERA);
45     options.mutable_input_configs(0)->mutable_input_stream(0)->mutable_cam_config()->set_camera_type(
46         proto::CameraConfig_CameraType_DRIVER_VIEW_CAMERA);
47     options.mutable_input_configs(0)->set_config_id(0);
48 
49     // Add an occupant view camera type
50     options.add_input_configs()->add_input_stream()->set_type(
51         proto::InputStreamConfig_InputType_CAMERA);
52     options.mutable_input_configs(1)->mutable_input_stream(0)->mutable_cam_config()->set_camera_type(
53         proto::CameraConfig_CameraType_OCCUPANT_VIEW_CAMERA);
54     options.mutable_input_configs(1)->set_config_id(1);
55 
56     // Add external camera type
57     options.add_input_configs()->add_input_stream()->set_type(
58         proto::InputStreamConfig_InputType_CAMERA);
59     options.mutable_input_configs(2)->mutable_input_stream(0)->mutable_cam_config()->set_camera_type(
60         proto::CameraConfig_CameraType_EXTERNAL_CAMERA);
61     options.mutable_input_configs(2)->set_config_id(2);
62 
63     // Add surround camera type
64     options.add_input_configs()->add_input_stream()->set_type(
65         proto::InputStreamConfig_InputType_CAMERA);
66     options.mutable_input_configs(3)->mutable_input_stream(0)->mutable_cam_config()->set_camera_type(
67         proto::CameraConfig_CameraType_SURROUND_VIEW_CAMERA);
68     options.mutable_input_configs(3)->set_config_id(3);
69 
70     // Add image file type
71     options.add_input_configs()->add_input_stream()->set_type(
72         proto::InputStreamConfig_InputType_IMAGE_FILES);
73     options.mutable_input_configs(4)->mutable_input_stream(0)->mutable_image_config()->set_file_type(
74         proto::ImageFileConfig_ImageFileType_PNG);
75     options.mutable_input_configs(4)->set_config_id(4);
76 
77     // Add video file type
78     options.add_input_configs()->add_input_stream()->set_type(
79         proto::InputStreamConfig_InputType_VIDEO_FILE);
80     options.mutable_input_configs(5)->mutable_input_stream(0)->mutable_video_config()->set_file_type(
81         proto::VideoFileConfig_VideoFileType_MPEG);
82     options.mutable_input_configs(5)->set_config_id(5);
83 
84     PipeDescriptor desc = OptionsToPipeDescriptor(options);
85 
86     ASSERT_EQ(desc.inputConfig.size(), 6);
87     ASSERT_EQ(desc.inputConfig[0].inputSources.size(), 1);
88     EXPECT_EQ(desc.inputConfig[0].inputSources[0].type, PipeInputConfigInputType::CAMERA);
89     EXPECT_EQ(desc.inputConfig[0].inputSources[0].camDesc.type,
90               PipeInputConfigCameraType::DRIVER_VIEW_CAMERA);
91     EXPECT_EQ(desc.inputConfig[0].configId, 0);
92 
93     ASSERT_EQ(desc.inputConfig[1].inputSources.size(), 1);
94     EXPECT_EQ(desc.inputConfig[1].inputSources[0].type, PipeInputConfigInputType::CAMERA);
95     EXPECT_EQ(desc.inputConfig[1].inputSources[0].camDesc.type,
96               PipeInputConfigCameraType::OCCUPANT_VIEW_CAMERA);
97     EXPECT_EQ(desc.inputConfig[1].configId, 1);
98 
99     ASSERT_EQ(desc.inputConfig[2].inputSources.size(), 1);
100     EXPECT_EQ(desc.inputConfig[2].inputSources[0].type, PipeInputConfigInputType::CAMERA);
101     EXPECT_EQ(desc.inputConfig[2].inputSources[0].camDesc.type,
102               PipeInputConfigCameraType::EXTERNAL_CAMERA);
103     EXPECT_EQ(desc.inputConfig[2].configId, 2);
104 
105     ASSERT_EQ(desc.inputConfig[3].inputSources.size(), 1);
106     EXPECT_EQ(desc.inputConfig[3].inputSources[0].type, PipeInputConfigInputType::CAMERA);
107     EXPECT_EQ(desc.inputConfig[3].inputSources[0].camDesc.type,
108               PipeInputConfigCameraType::SURROUND_VIEW_CAMERA);
109     EXPECT_EQ(desc.inputConfig[3].configId, 3);
110 
111     ASSERT_EQ(desc.inputConfig[4].inputSources.size(), 1);
112     EXPECT_EQ(desc.inputConfig[4].inputSources[0].type, PipeInputConfigInputType::IMAGE_FILES);
113     EXPECT_EQ(desc.inputConfig[4].inputSources[0].imageDesc.fileType,
114               PipeInputConfigImageFileType::PNG);
115     EXPECT_EQ(desc.inputConfig[4].configId, 4);
116 
117     ASSERT_EQ(desc.inputConfig[5].inputSources.size(), 1);
118     EXPECT_EQ(desc.inputConfig[5].inputSources[0].type, PipeInputConfigInputType::VIDEO_FILE);
119     EXPECT_EQ(desc.inputConfig[5].inputSources[0].videoDesc.fileType,
120               PipeInputConfigVideoFileType::MPEG);
121     EXPECT_EQ(desc.inputConfig[5].configId, 5);
122 }
123 
TEST(OptionsToPipeDescriptorTest,FormatTypesConvertAsExpected)124 TEST(OptionsToPipeDescriptorTest, FormatTypesConvertAsExpected) {
125     proto::Options options;
126 
127     // Add an RGB format
128     options.add_input_configs()->add_input_stream()->set_format(
129         proto::InputStreamConfig_FormatType_RGB);
130 
131     options.add_input_configs()->add_input_stream()->set_format(
132         proto::InputStreamConfig_FormatType_NIR);
133 
134     options.add_input_configs()->add_input_stream()->set_format(
135         proto::InputStreamConfig_FormatType_NIR_DEPTH);
136 
137     PipeDescriptor desc = OptionsToPipeDescriptor(options);
138 
139     ASSERT_EQ(desc.inputConfig.size(), 3);
140     ASSERT_EQ(desc.inputConfig[0].inputSources.size(), 1);
141     EXPECT_EQ(desc.inputConfig[0].inputSources[0].format, PipeInputConfigFormatType::RGB);
142 
143     ASSERT_EQ(desc.inputConfig[1].inputSources.size(), 1);
144     EXPECT_EQ(desc.inputConfig[1].inputSources[0].format, PipeInputConfigFormatType::NIR);
145 
146     ASSERT_EQ(desc.inputConfig[2].inputSources.size(), 1);
147     EXPECT_EQ(desc.inputConfig[2].inputSources[0].format, PipeInputConfigFormatType::NIR_DEPTH);
148 }
149 
TEST(OptionsToPipeDescriptorTest,ImageDimensionsAreTranslatedCorrectly)150 TEST(OptionsToPipeDescriptorTest, ImageDimensionsAreTranslatedCorrectly) {
151     proto::Options options;
152 
153     options.add_input_configs()->add_input_stream()->set_width(640);
154     options.mutable_input_configs(0)->mutable_input_stream(0)->set_height(480);
155     options.mutable_input_configs(0)->mutable_input_stream(0)->set_stride(640 * 3);
156     options.mutable_input_configs(0)->mutable_input_stream(0)->set_stride(640 * 3);
157 
158     PipeDescriptor desc = OptionsToPipeDescriptor(options);
159     ASSERT_EQ(desc.inputConfig.size(), 1);
160     ASSERT_EQ(desc.inputConfig[0].inputSources.size(), 1);
161     ASSERT_EQ(desc.inputConfig[0].inputSources[0].width, 640);
162     ASSERT_EQ(desc.inputConfig[0].inputSources[0].height, 480);
163     ASSERT_EQ(desc.inputConfig[0].inputSources[0].stride, 640 * 3);
164 }
165 
TEST(OptionsToPipeDescriptorTest,CameraIdIsReflectedCorrectly)166 TEST(OptionsToPipeDescriptorTest, CameraIdIsReflectedCorrectly) {
167     proto::Options options;
168     std::string expectedCameraName = "Camera 1";
169     options.add_input_configs()->add_input_stream()->mutable_cam_config()->set_cam_id(
170         expectedCameraName);
171 
172     PipeDescriptor desc = OptionsToPipeDescriptor(options);
173     ASSERT_EQ(desc.inputConfig.size(), 1);
174     ASSERT_EQ(desc.inputConfig[0].inputSources.size(), 1);
175     EXPECT_EQ(desc.inputConfig[0].inputSources[0].camDesc.camId, expectedCameraName);
176 }
177 
178 }  // namespace
179 }  // namespace aidl_client
180 }  // namespace client_interface
181 }  // namespace runner
182 }  // namespace computepipe
183 }  // namespace automotive
184 }  // namespace android
185