1 /* 2 * Copyright (c) 2021 Huawei Device Co., Ltd. 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 16 #ifndef STREAM_OPERATOR_STREAM_TUNNEL_H 17 #define STREAM_OPERATOR_STREAM_TUNNEL_H 18 19 #include "display_type.h" 20 #include "ibuffer.h" 21 #include "surface.h" 22 #include "surface_type.h" 23 #include <mutex> 24 #include <unordered_map> 25 26 namespace OHOS::Camera { 27 struct TunnelConfig { 28 uint32_t width; 29 uint32_t height; 30 uint32_t format; 31 uint64_t usage; 32 }; 33 34 class StreamTunnel { 35 public: 36 virtual RetCode AttachBufferQueue(OHOS::sptr<OHOS::IBufferProducer>& producer); 37 virtual RetCode DetachBufferQueue(); 38 virtual std::shared_ptr<IBuffer> GetBuffer(); 39 virtual RetCode PutBuffer(const std::shared_ptr<IBuffer>& buffer); 40 virtual RetCode SetBufferCount(const int32_t n); 41 virtual RetCode Config(const TunnelConfig config); 42 virtual uint64_t GetFrameCount() const; 43 virtual void WaitForAllBufferReturned(); 44 virtual void NotifyStart(); 45 virtual void NotifyStop(); 46 virtual void CleanBuffers(); 47 48 StreamTunnel() = default; 49 virtual ~StreamTunnel(); 50 StreamTunnel(const StreamTunnel& other) = delete; 51 StreamTunnel(StreamTunnel&& other) = delete; 52 StreamTunnel& operator=(const StreamTunnel& other) = delete; 53 StreamTunnel& operator=(StreamTunnel&& other) = delete; 54 55 protected: 56 int32_t index = -1; 57 uint64_t frameCount_ = 0; 58 OHOS::sptr<OHOS::Surface> bufferQueue_ = nullptr; 59 OHOS::BufferRequestConfig requestConfig_ = {0, 0, 0, 0, 0, 0}; 60 OHOS::BufferFlushConfig flushConfig_ = {{0, 0, 0, 0}, 0}; 61 std::unordered_map<std::shared_ptr<IBuffer>, OHOS::sptr<OHOS::SurfaceBuffer>> buffers = {}; 62 std::mutex lock_ = {}; 63 std::mutex waitLock_ = {}; 64 std::condition_variable waitCV_ = {}; 65 std::atomic<bool> wakeup_ = false; 66 std::atomic<bool> stop_ = false; 67 std::atomic<uint32_t> restBuffers = 0; 68 std::mutex finishLock_ = {}; 69 std::condition_variable finishCV_ = {}; 70 }; 71 } // namespace OHOS::Camera 72 #endif 73 74