• 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 <android-base/logging.h>
16 
17 #include "EvsInputManager.h"
18 #include "InputManager.h"
19 #include "VideoInputManager.h"
20 
21 namespace android {
22 namespace automotive {
23 namespace computepipe {
24 namespace runner {
25 namespace input_manager {
26 namespace {
27 
28 enum InputManagerType {
29     EVS = 0,
30     IMAGES,
31     VIDEO,
32 };
33 
34 // Helper function to determine the type of input manager to be created from the
35 // input config.
36 // TODO(b/147803315): Implement the actual algorithm to determine the input manager to be
37 // used. Right now, only EVS manager is enabled, so that is used.
getInputManagerType(const proto::InputStreamConfig & streamConfig)38 InputManagerType getInputManagerType(const proto::InputStreamConfig& streamConfig) {
39     switch (streamConfig.type()) {
40         case proto::InputStreamConfig::CAMERA:
41             return InputManagerType::EVS;
42         case proto::InputStreamConfig::IMAGE_FILES:
43             return InputManagerType::IMAGES;
44         case proto::InputStreamConfig::VIDEO_FILE:
45             return InputManagerType::VIDEO;
46     }
47 }
48 
49 }  // namespace
createInputManager(const proto::InputConfig & config,const proto::InputConfig & overrideConfig,std::shared_ptr<InputEngineInterface> inputEngineInterface)50 std::unique_ptr<InputManager> InputManagerFactory::createInputManager(
51         const proto::InputConfig& config, const proto::InputConfig& overrideConfig,
52         std::shared_ptr<InputEngineInterface> inputEngineInterface) {
53     // Check that all streams in the config have same type.
54     for (int i = 1; i < config.input_stream_size(); i++) {
55         if (config.input_stream(i).type() != config.input_stream(0).type()) {
56             LOG(ERROR) << "Invalid input configuration with config id " << config.config_id()
57                        << ". All streams must have same type.";
58             return nullptr;
59         }
60     }
61     InputManagerType inputManagerType = getInputManagerType(config.input_stream(0));
62     std::unique_ptr<InputManager> inputManager = nullptr;
63     switch (inputManagerType) {
64         case InputManagerType::EVS:
65             inputManager = EvsInputManager::createEvsInputManager(config, overrideConfig,
66                                                                   inputEngineInterface);
67             break;
68         case InputManagerType::VIDEO:
69             inputManager = VideoInputManager::createVideoInputManager(config, overrideConfig,
70                                                                       inputEngineInterface);
71             break;
72         default:
73             return nullptr;
74     }
75     return inputManager;
76 }
77 
78 }  // namespace input_manager
79 }  // namespace runner
80 }  // namespace computepipe
81 }  // namespace automotive
82 }  // namespace android
83