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 
15 #ifndef COMPUTEPIPE_RUNNER_GRAPH_INCLUDE_PREBUILTGRAPH_H_
16 #define COMPUTEPIPE_RUNNER_GRAPH_INCLUDE_PREBUILTGRAPH_H_
17 
18 #include <string>
19 
20 #include "InputFrame.h"
21 #include "Options.pb.h"
22 #include "PrebuiltEngineInterface.h"
23 #include "RunnerComponent.h"
24 #include "types/Status.h"
25 
26 namespace android {
27 namespace automotive {
28 namespace computepipe {
29 namespace graph {
30 
31 enum PrebuiltGraphState {
32     RUNNING = 0,
33     UNINITIALIZED,
34     FLUSHING,
35     STOPPED,
36 };
37 
38 enum PrebuiltGraphType {
39     LOCAL = 0,
40     REMOTE = 1,
41 };
42 
43 class PrebuiltGraph : public runner::RunnerComponentInterface {
44   public:
45     // Gets the graph type.
46     virtual PrebuiltGraphType GetGraphType() const = 0;
47 
48     // Gets the PrebuiltGraphState
49     virtual PrebuiltGraphState GetGraphState() const = 0;
50 
51     // Gets the graph status and reports any error code or if the status is OK.
52     virtual Status GetStatus() const = 0;
53 
54     // Gets the error message from the graph.
55     virtual std::string GetErrorMessage() const = 0;
56 
57     // Gets the supported graph config options.
58     virtual const proto::Options& GetSupportedGraphConfigs() const = 0;
59 
60     // Sets input stream data. The string is expected to be a serialized proto
61     // the definition of which is known to the graph.
62     virtual Status SetInputStreamData(int streamIndex, int64_t timestamp,
63                                       const std::string& streamData) = 0;
64 
65     // Sets pixel data to the specified input stream index.
66     virtual Status SetInputStreamPixelData(int streamIndex, int64_t timestamp,
67                                            const runner::InputFrame& inputFrame) = 0;
68 
69     // Start graph profiling.
70     virtual Status StartGraphProfiling() = 0;
71 
72     // Stop graph profiling.
73     virtual Status StopGraphProfiling() = 0;
74 
75     // Collects debugging and profiling information for the graph. The graph
76     // needs to be started with debugging enabled in order to get valid info.
77     virtual std::string GetDebugInfo() = 0;
78 };
79 
80 PrebuiltGraph* GetLocalGraphFromLibrary(
81         const std::string& prebuiltLib, std::weak_ptr<PrebuiltEngineInterface> engineInterface);
82 
83 std::unique_ptr<PrebuiltGraph> GetRemoteGraphFromAddress(
84         const std::string& address, std::weak_ptr<PrebuiltEngineInterface> engineInterface);
85 
86 }  // namespace graph
87 }  // namespace computepipe
88 }  // namespace automotive
89 }  // namespace android
90 
91 #endif  // COMPUTEPIPE_RUNNER_GRAPH_INCLUDE_PREBUILTGRAPH_H_
92