• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (C) 2019 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 
15 #include "PipeOptionsConverter.h"
16 
17 #include "aidl/android/automotive/computepipe/runner/PipeInputConfigInputType.h"
18 
19 namespace android {
20 namespace automotive {
21 namespace computepipe {
22 namespace runner {
23 namespace client_interface {
24 namespace aidl_client {
25 
26 using ::aidl::android::automotive::computepipe::runner::PipeDescriptor;
27 using ::aidl::android::automotive::computepipe::runner::PipeInputConfig;
28 using ::aidl::android::automotive::computepipe::runner::PipeInputConfigCameraDesc;
29 using ::aidl::android::automotive::computepipe::runner::PipeInputConfigCameraType;
30 using ::aidl::android::automotive::computepipe::runner::PipeInputConfigFormatType;
31 using ::aidl::android::automotive::computepipe::runner::PipeInputConfigImageFileType;
32 using ::aidl::android::automotive::computepipe::runner::PipeInputConfigInputSourceDesc;
33 using ::aidl::android::automotive::computepipe::runner::PipeInputConfigInputType;
34 using ::aidl::android::automotive::computepipe::runner::PipeInputConfigVideoFileType;
35 using ::aidl::android::automotive::computepipe::runner::PipeOffloadConfig;
36 using ::aidl::android::automotive::computepipe::runner::PipeOffloadConfigOffloadType;
37 using ::aidl::android::automotive::computepipe::runner::PipeOutputConfig;
38 using ::aidl::android::automotive::computepipe::runner::PipeOutputConfigPacketType;
39 using ::aidl::android::automotive::computepipe::runner::PipeTerminationConfig;
40 using ::aidl::android::automotive::computepipe::runner::PipeTerminationConfigTerminationType;
41 
42 namespace {
43 
ConvertInputType(proto::InputStreamConfig::InputType type)44 PipeInputConfigInputType ConvertInputType(proto::InputStreamConfig::InputType type) {
45     switch (type) {
46         case proto::InputStreamConfig::CAMERA:
47             return PipeInputConfigInputType::CAMERA;
48         case proto::InputStreamConfig::VIDEO_FILE:
49             return PipeInputConfigInputType::VIDEO_FILE;
50         case proto::InputStreamConfig::IMAGE_FILES:
51             return PipeInputConfigInputType::IMAGE_FILES;
52     }
53 }
54 
ConvertCameraType(proto::CameraConfig::CameraType type)55 PipeInputConfigCameraType ConvertCameraType(proto::CameraConfig::CameraType type) {
56     switch (type) {
57         case proto::CameraConfig::DRIVER_VIEW_CAMERA:
58             return PipeInputConfigCameraType::DRIVER_VIEW_CAMERA;
59         case proto::CameraConfig::OCCUPANT_VIEW_CAMERA:
60             return PipeInputConfigCameraType::OCCUPANT_VIEW_CAMERA;
61         case proto::CameraConfig::EXTERNAL_CAMERA:
62             return PipeInputConfigCameraType::EXTERNAL_CAMERA;
63         case proto::CameraConfig::SURROUND_VIEW_CAMERA:
64             return PipeInputConfigCameraType::SURROUND_VIEW_CAMERA;
65     }
66 }
67 
ConvertImageFileType(proto::ImageFileConfig::ImageFileType type)68 PipeInputConfigImageFileType ConvertImageFileType(proto::ImageFileConfig::ImageFileType type) {
69     switch (type) {
70         case proto::ImageFileConfig::JPEG:
71             return PipeInputConfigImageFileType::JPEG;
72         case proto::ImageFileConfig::PNG:
73             return PipeInputConfigImageFileType::PNG;
74     }
75 }
76 
ConvertVideoFileType(proto::VideoFileConfig::VideoFileType type)77 PipeInputConfigVideoFileType ConvertVideoFileType(proto::VideoFileConfig::VideoFileType type) {
78     switch (type) {
79         case proto::VideoFileConfig::MPEG:
80             return PipeInputConfigVideoFileType::MPEG;
81     }
82 }
83 
ConvertInputFormat(proto::InputStreamConfig::FormatType type)84 PipeInputConfigFormatType ConvertInputFormat(proto::InputStreamConfig::FormatType type) {
85     switch (type) {
86         case proto::InputStreamConfig::RGB:
87             return PipeInputConfigFormatType::RGB;
88         case proto::InputStreamConfig::NIR:
89             return PipeInputConfigFormatType::NIR;
90         case proto::InputStreamConfig::NIR_DEPTH:
91             return PipeInputConfigFormatType::NIR_DEPTH;
92     }
93 }
94 
ConvertOffloadType(proto::OffloadOption::OffloadType type)95 PipeOffloadConfigOffloadType ConvertOffloadType(proto::OffloadOption::OffloadType type) {
96     switch (type) {
97         case proto::OffloadOption::CPU:
98             return PipeOffloadConfigOffloadType::CPU;
99         case proto::OffloadOption::GPU:
100             return PipeOffloadConfigOffloadType::GPU;
101         case proto::OffloadOption::NEURAL_ENGINE:
102             return PipeOffloadConfigOffloadType::NEURAL_ENGINE;
103         case proto::OffloadOption::CV_ENGINE:
104             return PipeOffloadConfigOffloadType::CV_ENGINE;
105     }
106 }
107 
ConvertOutputType(proto::PacketType type)108 PipeOutputConfigPacketType ConvertOutputType(proto::PacketType type) {
109     switch (type) {
110         case proto::PacketType::SEMANTIC_DATA:
111             return PipeOutputConfigPacketType::SEMANTIC_DATA;
112         case proto::PacketType::PIXEL_DATA:
113             return PipeOutputConfigPacketType::PIXEL_DATA;
114         case proto::PacketType::PIXEL_ZERO_COPY_DATA:
115             return PipeOutputConfigPacketType::PIXEL_ZERO_COPY_DATA;
116     }
117 }
118 
ConvertTerminationType(proto::TerminationOption::TerminationType type)119 PipeTerminationConfigTerminationType ConvertTerminationType(
120     proto::TerminationOption::TerminationType type) {
121     switch (type) {
122         case proto::TerminationOption::CLIENT_STOP:
123             return PipeTerminationConfigTerminationType::CLIENT_STOP;
124         case proto::TerminationOption::MIN_PACKET_COUNT:
125             return PipeTerminationConfigTerminationType::MIN_PACKET_COUNT;
126         case proto::TerminationOption::MAX_RUN_TIME:
127             return PipeTerminationConfigTerminationType::MAX_RUN_TIME;
128         case proto::TerminationOption::EVENT:
129             return PipeTerminationConfigTerminationType::EVENT;
130     }
131 }
132 
ConvertInputConfigProto(const proto::InputConfig & proto)133 PipeInputConfig ConvertInputConfigProto(const proto::InputConfig& proto) {
134     PipeInputConfig aidlConfig;
135 
136     for (const auto& inputStreamConfig : proto.input_stream()) {
137         PipeInputConfigInputSourceDesc aidlInputDesc;
138         aidlInputDesc.type = ConvertInputType(inputStreamConfig.type());
139         aidlInputDesc.format = ConvertInputFormat(inputStreamConfig.format());
140         aidlInputDesc.width = inputStreamConfig.width();
141         aidlInputDesc.height = inputStreamConfig.height();
142         aidlInputDesc.stride = inputStreamConfig.stride();
143         aidlInputDesc.camDesc.camId = inputStreamConfig.cam_config().cam_id();
144         aidlInputDesc.camDesc.type =
145                 ConvertCameraType(inputStreamConfig.cam_config().camera_type());
146         aidlInputDesc.imageDesc.fileType =
147             ConvertImageFileType(inputStreamConfig.image_config().file_type());
148         aidlInputDesc.imageDesc.filePath = inputStreamConfig.image_config().image_dir();
149         aidlInputDesc.videoDesc.fileType =
150             ConvertVideoFileType(inputStreamConfig.video_config().file_type());
151         aidlInputDesc.videoDesc.filePath = inputStreamConfig.video_config().file_path();
152         aidlConfig.inputSources.emplace_back(aidlInputDesc);
153     }
154     aidlConfig.configId = proto.config_id();
155 
156     return aidlConfig;
157 }
158 
ConvertOffloadConfigProto(const proto::OffloadConfig & proto)159 PipeOffloadConfig ConvertOffloadConfigProto(const proto::OffloadConfig& proto) {
160     PipeOffloadConfig aidlConfig;
161 
162     for (int i = 0; i < proto.options().offload_types_size(); i++) {
163         auto offloadType =
164             static_cast<proto::OffloadOption_OffloadType>(proto.options().offload_types()[i]);
165         PipeOffloadConfigOffloadType aidlType = ConvertOffloadType(offloadType);
166         aidlConfig.desc.type.emplace_back(aidlType);
167         aidlConfig.desc.isVirtual.emplace_back(proto.options().is_virtual()[i]);
168     }
169 
170     aidlConfig.configId = proto.config_id();
171     return aidlConfig;
172 }
173 
ConvertOutputConfigProto(const proto::OutputConfig & proto)174 PipeOutputConfig ConvertOutputConfigProto(const proto::OutputConfig& proto) {
175     PipeOutputConfig aidlConfig;
176     aidlConfig.output.name = proto.stream_name();
177     aidlConfig.output.type = ConvertOutputType(proto.type());
178     aidlConfig.outputId = proto.stream_id();
179     return aidlConfig;
180 }
181 
ConvertTerminationConfigProto(const proto::TerminationConfig & proto)182 PipeTerminationConfig ConvertTerminationConfigProto(const proto::TerminationConfig& proto) {
183     PipeTerminationConfig aidlConfig;
184     aidlConfig.desc.type = ConvertTerminationType(proto.options().type());
185     aidlConfig.desc.qualifier = proto.options().qualifier();
186     aidlConfig.configId = proto.config_id();
187     return aidlConfig;
188 }
189 
190 }  // namespace
191 
OptionsToPipeDescriptor(const proto::Options & options)192 PipeDescriptor OptionsToPipeDescriptor(const proto::Options& options) {
193     PipeDescriptor desc;
194     for (int i = 0; i < options.input_configs_size(); i++) {
195         PipeInputConfig inputConfig = ConvertInputConfigProto(options.input_configs()[i]);
196         desc.inputConfig.emplace_back(inputConfig);
197     }
198 
199     for (int i = 0; i < options.offload_configs_size(); i++) {
200         PipeOffloadConfig offloadConfig = ConvertOffloadConfigProto(options.offload_configs()[i]);
201         desc.offloadConfig.emplace_back(offloadConfig);
202     }
203 
204     for (int i = 0; i < options.termination_configs_size(); i++) {
205         PipeTerminationConfig terminationConfig =
206             ConvertTerminationConfigProto(options.termination_configs()[i]);
207         desc.terminationConfig.emplace_back(terminationConfig);
208     }
209 
210     for (int i = 0; i < options.output_configs_size(); i++) {
211         PipeOutputConfig outputConfig = ConvertOutputConfigProto(options.output_configs()[i]);
212         desc.outputConfig.emplace_back(outputConfig);
213     }
214     return desc;
215 }
216 
217 }  // namespace aidl_client
218 }  // namespace client_interface
219 }  // namespace runner
220 }  // namespace computepipe
221 }  // namespace automotive
222 }  // namespace android
223