• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <mutex>
20 #include <unordered_map>
21 #include "display_format.h"
22 #include "ibuffer.h"
23 #include "surface.h"
24 #include "surface_type.h"
25 #include "stream_statistics.h"
26 
27 namespace OHOS::Camera {
28 struct TunnelConfig {
29     uint32_t width;
30     uint32_t height;
31     uint32_t format;
32     uint64_t usage;
33 };
34 
35 class StreamTunnel {
36 public:
37     virtual RetCode AttachBufferQueue(OHOS::sptr<OHOS::IBufferProducer>& producer);
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     void DumpStats(int interval = 0);
48     void SetStreamId(int32_t streamId);
49     RetCode DetachBufferQueue();
50 
51     StreamTunnel() = default;
52     virtual ~StreamTunnel();
53     StreamTunnel(const StreamTunnel& other) = delete;
54     StreamTunnel(StreamTunnel&& other) = delete;
55     StreamTunnel& operator=(const StreamTunnel& other) = delete;
56     StreamTunnel& operator=(StreamTunnel&& other) = delete;
57 
58 private:
59     std::shared_ptr<IBuffer> GetCameraBufferAndUpdateInfo(OHOS::sptr<OHOS::SurfaceBuffer> sb);
60 
61 protected:
62     int32_t index = -1;
63     uint64_t frameCount_ = 0;
64     OHOS::sptr<OHOS::Surface> bufferQueue_ = nullptr;
65     OHOS::BufferRequestConfig requestConfig_ = {0, 0, 0, 0, 0, 0};
66     OHOS::BufferFlushConfig flushConfig_ = {{0, 0, 0, 0}, 0};
67     std::unordered_map<std::shared_ptr<IBuffer>, OHOS::sptr<OHOS::SurfaceBuffer>> buffers = {};
68     std::mutex lock_ = {};
69     std::mutex waitLock_ = {};
70     std::condition_variable waitCV_ = {};
71     std::atomic<bool> wakeup_ = false;
72     std::atomic<bool> stop_ = false;
73     std::atomic<uint32_t> restBuffers = 0;
74     std::mutex finishLock_ = {};
75     std::condition_variable finishCV_ = {};
76     StreamStatistics stats_;
77     int32_t streamId_ = 0;
78 };
79 } // namespace OHOS::Camera
80 #endif
81 
82