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_SEMANTIC_MANAGER_H
16 #define COMPUTEPIPE_RUNNER_STREAM_MANAGER_SEMANTIC_MANAGER_H
17 
18 #include <mutex>
19 
20 #include "InputFrame.h"
21 #include "OutputConfig.pb.h"
22 #include "RunnerComponent.h"
23 #include "StreamManager.h"
24 #include "StreamManagerInit.h"
25 
26 namespace android {
27 namespace automotive {
28 namespace computepipe {
29 namespace runner {
30 namespace stream_manager {
31 
32 class SemanticHandle : public MemHandle {
33   public:
34     static constexpr uint32_t kMaxSemanticDataSize = 1024;
35     /**
36      * Override mem handle methods
37      */
38     int getStreamId() const override;
39     int getBufferId() const override;
40     proto::PacketType getType() const override;
41     uint64_t getTimeStamp() const override;
42     uint32_t getSize() const override;
43     const char* getData() const override;
44     AHardwareBuffer* getHardwareBuffer() const override;
45     /* set info for the memory. Make a copy */
46     Status setMemInfo(int streamId, const char* data, uint32_t size, uint64_t timestamp,
47                       const proto::PacketType& type);
48     /* Destroy local copy */
49     ~SemanticHandle();
50 
51   private:
52     char* mData = nullptr;
53     uint32_t mSize;
54     uint64_t mTimestamp;
55     proto::PacketType mType;
56     int mStreamId;
57 };
58 
59 class SemanticManager : public StreamManager, StreamManagerInit {
60   public:
61     void setEngineInterface(std::shared_ptr<StreamEngineInterface> engine) override;
62     /* Set Max in flight packets based on client specification */
63     Status setMaxInFlightPackets(uint32_t maxPackets) override;
64     /* Free previously dispatched packet. Once client has confirmed usage */
65     Status freePacket(int bufferId) override;
66     /* Queue packet produced by graph stream */
67     Status queuePacket(const char* data, const uint32_t size, uint64_t timestamp) override;
68     /* Queues an image packet produced by graph stream */
69     Status queuePacket(const InputFrame& inputData, uint64_t timestamp) override;
70     /* Make a copy of the packet. */
71     std::shared_ptr<MemHandle> clonePacket(std::shared_ptr<MemHandle> handle) override;
72     /* Override handling of Runner Engine Events */
73     void notifyEndOfStream();
74 
75     Status handleExecutionPhase(const RunnerEvent& e) override;
76     Status handleStopWithFlushPhase(const RunnerEvent& e) override;
77     Status handleStopImmediatePhase(const RunnerEvent& e) override;
78 
79     explicit SemanticManager(std::string name, int streamId, const proto::PacketType& type);
80     ~SemanticManager() = default;
81 
82   private:
83     std::mutex mStateLock;
84     int mStreamId;
85     std::shared_ptr<StreamEngineInterface> mEngine;
86 };
87 }  // namespace stream_manager
88 }  // namespace runner
89 }  // namespace computepipe
90 }  // namespace automotive
91 }  // namespace android
92 #endif
93