• 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 #ifndef COMPUTEPIPE_RUNNER_STREAM_MANAGER_H
16 #define COMPUTEPIPE_RUNNER_STREAM_MANAGER_H
17 
18 #include <functional>
19 #include <memory>
20 #include <string>
21 
22 #include "InputFrame.h"
23 #include "MemHandle.h"
24 #include "OutputConfig.pb.h"
25 #include "RunnerComponent.h"
26 #include "StreamEngineInterface.h"
27 #include "types/Status.h"
28 
29 namespace android {
30 namespace automotive {
31 namespace computepipe {
32 namespace runner {
33 namespace stream_manager {
34 
35 /**
36  * Manager the operations of an output stream from the graph.
37  * Should be constructed using the StreamManagerFactory.
38  * The manager instance for a given stream depends on the streams
39  * description specified in OuputConfig.
40  */
41 
42 class StreamManager : public RunnerComponentInterface {
43   public:
44     enum State {
45         /* State on construction. */
46         RESET = 0,
47         /* State once inflight packets set */
48         CONFIG_DONE = 1,
49         /* State once handleRunPhase() notifies of entry to run phase */
50         RUNNING = 2,
51         /**
52          * State once stop issued
53          * Returns to config done, once all in flight packets handled.
54          */
55         STOPPED = 3,
56     };
57     /* Constructor for StreamManager Base class */
StreamManager(std::string streamName,const proto::PacketType & type)58     explicit StreamManager(std::string streamName, const proto::PacketType& type)
59         : mName(streamName), mType(type) {
60     }
61     /* Retrieves the current state */
getState()62     State getState() {
63         return mState;
64     }
65     /* Make a copy of the packet. */
66     virtual std::shared_ptr<MemHandle> clonePacket(std::shared_ptr<MemHandle> handle) = 0;
67     /* Frees previously dispatched packet based on bufferID. Once client has confirmed usage */
68     virtual Status freePacket(int bufferId) = 0;
69     /* Queue's packet produced by graph stream */
70     virtual Status queuePacket(const char* data, const uint32_t size, uint64_t timestamp) = 0;
71     /* Queues a pixel stream packet produced by graph stream */
72     virtual Status queuePacket(const InputFrame& pixelData, uint64_t timestamp) = 0;
73     /* Destructor */
74     virtual ~StreamManager() = default;
75 
76   protected:
77     std::string mName;
78     proto::PacketType mType;
79     State mState = RESET;
80 };
81 
82 /**
83  * Factory for generating stream manager instances
84  * It initializes the instances for a given client configuration prior to
85  * returning. (Follows RAII semantics)
86  */
87 class StreamManagerFactory {
88   public:
89     std::unique_ptr<StreamManager> getStreamManager(const proto::OutputConfig& config,
90                                                     std::shared_ptr<StreamEngineInterface> engine,
91                                                     uint32_t maxInFlightPackets);
92     StreamManagerFactory(const StreamManagerFactory&) = delete;
93     StreamManagerFactory(const StreamManagerFactory&&) = delete;
94     StreamManagerFactory& operator=(const StreamManagerFactory&&) = delete;
95     StreamManagerFactory& operator=(const StreamManagerFactory&) = delete;
96     StreamManagerFactory() = default;
97 };
98 
99 }  // namespace stream_manager
100 }  // namespace runner
101 }  // namespace computepipe
102 }  // namespace automotive
103 }  // namespace android
104 
105 #endif
106