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 "OutputConfig.pb.h"
16 #include "PixelStreamManager.h"
17 #include "SemanticManager.h"
18 #include "StreamEngineInterface.h"
19 #include "StreamManager.h"
20
21 namespace android {
22 namespace automotive {
23 namespace computepipe {
24 namespace runner {
25 namespace stream_manager {
26
27 namespace {
28
29 /**
30 * Build an instance of the Semantic Manager and initialize it
31 */
buildSemanticManager(const proto::OutputConfig & config,std::shared_ptr<StreamEngineInterface> engine,uint32_t maxPackets)32 std::unique_ptr<SemanticManager> buildSemanticManager(const proto::OutputConfig& config,
33 std::shared_ptr<StreamEngineInterface> engine,
34 uint32_t maxPackets) {
35 std::unique_ptr<SemanticManager> semanticManager =
36 std::make_unique<SemanticManager>(config.stream_name(), config.stream_id(), config.type());
37 semanticManager->setEngineInterface(engine);
38 if (semanticManager->setMaxInFlightPackets(maxPackets) != SUCCESS) {
39 return nullptr;
40 }
41 return semanticManager;
42 }
43
buildPixelStreamManager(const proto::OutputConfig & config,std::shared_ptr<StreamEngineInterface> engine,uint32_t maxPackets)44 std::unique_ptr<PixelStreamManager> buildPixelStreamManager(
45 const proto::OutputConfig& config, std::shared_ptr<StreamEngineInterface> engine,
46 uint32_t maxPackets) {
47 std::unique_ptr<PixelStreamManager> pixelStreamManager =
48 std::make_unique<PixelStreamManager>(config.stream_name(), config.stream_id());
49 pixelStreamManager->setEngineInterface(engine);
50 if (pixelStreamManager->setMaxInFlightPackets(maxPackets) != Status::SUCCESS) {
51 return nullptr;
52 }
53 return pixelStreamManager;
54 }
55
56 } // namespace
57
getStreamManager(const proto::OutputConfig & config,std::shared_ptr<StreamEngineInterface> engine,uint32_t maxPackets)58 std::unique_ptr<StreamManager> StreamManagerFactory::getStreamManager(
59 const proto::OutputConfig& config, std::shared_ptr<StreamEngineInterface> engine,
60 uint32_t maxPackets) {
61 if (!config.has_type()) {
62 return nullptr;
63 }
64 switch (config.type()) {
65 case proto::PacketType::SEMANTIC_DATA:
66 return buildSemanticManager(config, engine, maxPackets);
67 case proto::PacketType::PIXEL_DATA:
68 return buildPixelStreamManager(config, engine, maxPackets);
69 default:
70 return nullptr;
71 }
72 return nullptr;
73 }
74
75 } // namespace stream_manager
76 } // namespace runner
77 } // namespace computepipe
78 } // namespace automotive
79 } // namespace android
80