• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 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 #ifndef COMPUTEPIPE_RUNNER_STREAM_MANAGER_PIXEL_STREAM_MANAGER_H
15 #define COMPUTEPIPE_RUNNER_STREAM_MANAGER_PIXEL_STREAM_MANAGER_H
16 
17 #include <vndk/hardware_buffer.h>
18 
19 #include <map>
20 #include <memory>
21 #include <mutex>
22 #include <vector>
23 
24 #include "InputFrame.h"
25 #include "MemHandle.h"
26 #include "RunnerComponent.h"
27 #include "StreamManager.h"
28 #include "StreamManagerInit.h"
29 
30 namespace android {
31 namespace automotive {
32 namespace computepipe {
33 namespace runner {
34 namespace stream_manager {
35 
36 class PixelMemHandle : public MemHandle {
37   public:
38     explicit PixelMemHandle(int bufferId, int streamId, int additionalUsageFlags = 0);
39 
40     virtual ~PixelMemHandle();
41 
42     // Delete copy and move constructors as well as copy and move assignment operators.
43     PixelMemHandle(const PixelMemHandle&) = delete;
44     PixelMemHandle(PixelMemHandle&&) = delete;
45     PixelMemHandle operator=(const PixelMemHandle&) = delete;
46     PixelMemHandle operator=(PixelMemHandle&&) = delete;
47 
48     /**
49      * Overrides mem handle methods
50      */
51     int getStreamId() const override;
52     int getBufferId() const override;
53     proto::PacketType getType() const override;
54     uint64_t getTimeStamp() const override;
55     uint32_t getSize() const override;
56     const char* getData() const override;
57     AHardwareBuffer* getHardwareBuffer() const override;
58 
59     /* Sets frame info */
60     Status setFrameData(uint64_t timestamp, const InputFrame& inputFrame);
61 
62   private:
63     const int mBufferId;
64     const int mStreamId;
65     AHardwareBuffer_Desc mDesc;
66     AHardwareBuffer* mBuffer;
67     uint64_t mTimestamp;
68     int mUsage;
69 };
70 
71 class PixelStreamManager : public StreamManager, StreamManagerInit {
72   public:
73     void setEngineInterface(std::shared_ptr<StreamEngineInterface> engine) override;
74     // Set Max in flight packets based on client specification
75     Status setMaxInFlightPackets(uint32_t maxPackets) override;
76     // Free previously dispatched packet. Once client has confirmed usage
77     Status freePacket(int bufferId) override;
78     // Queue packet produced by graph stream
79     Status queuePacket(const char* data, const uint32_t size, uint64_t timestamp) override;
80     // Queues pixel packet produced by graph stream
81     Status queuePacket(const InputFrame& frame, uint64_t timestamp) override;
82     /* Make a copy of the packet. */
83     std::shared_ptr<MemHandle> clonePacket(std::shared_ptr<MemHandle> handle) override;
84 
85     Status handleExecutionPhase(const RunnerEvent& e) override;
86     Status handleStopWithFlushPhase(const RunnerEvent& e) override;
87     Status handleStopImmediatePhase(const RunnerEvent& e) override;
88 
89     explicit PixelStreamManager(std::string name, int streamId);
90     ~PixelStreamManager() = default;
91 
92   private:
93     void freeAllPackets();
94     std::mutex mLock;
95     std::mutex mStateLock;
96     int mStreamId;
97     uint32_t mMaxInFlightPackets;
98     std::shared_ptr<StreamEngineInterface> mEngine;
99 
100     struct BufferMetadata {
101         int outstandingRefCount;
102         std::shared_ptr<PixelMemHandle> handle;
103     };
104 
105     std::map<int, BufferMetadata> mBuffersInUse;
106     std::vector<std::shared_ptr<PixelMemHandle>> mBuffersReady;
107 };
108 
109 }  // namespace stream_manager
110 }  // namespace runner
111 }  // namespace computepipe
112 }  // namespace automotive
113 }  // namespace android
114 
115 #endif  // COMPUTEPIPE_RUNNER_STREAM_MANAGER_PIXEL_STREAM_MANAGER_H
116