• 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_BASE_H
17 #define STREAM_OPERATOR_STREAM_BASE_H
18 
19 #include "ibuffer.h"
20 #include "ibuffer_pool.h"
21 #include "istream.h"
22 #include "capture_request.h"
23 
24 namespace OHOS::Camera {
25 class StreamBase : public IStream, public std::enable_shared_from_this<StreamBase> {
26 public:
27     StreamBase(const int32_t id,
28                const StreamIntent type,
29                std::shared_ptr<IPipelineCore>& p,
30                std::shared_ptr<CaptureMessageOperator>& m);
31     virtual ~StreamBase();
32     StreamBase(const StreamBase& other) = delete;
33     StreamBase(StreamBase&& other) = delete;
34     StreamBase& operator=(const StreamBase& other) = delete;
35     StreamBase& operator=(StreamBase&& other) = delete;
36 
37 public:
38     RetCode ConfigStream(StreamConfiguration& config) override;
39     RetCode CommitStream() override;
40     RetCode StartStream() override;
41     RetCode StopStream() override;
42     RetCode AddRequest(std::shared_ptr<CaptureRequest>& request) override;
43     RetCode CancelRequest(const std::shared_ptr<CaptureRequest>& request) override;
44     RetCode AttachStreamTunnel(std::shared_ptr<StreamTunnel>& tunnel) override;
45     RetCode DetachStreamTunnel() override;
46     RetCode ChangeToOfflineStream(std::shared_ptr<OfflineStream> offlineStream) override;
47     bool GetTunnelMode() const override;
48     StreamConfiguration GetStreamAttribute() const override;
49     int32_t GetStreamId() const override;
50     RetCode Capture(const std::shared_ptr<CaptureRequest>& request) override;
51     RetCode OnFrame(const std::shared_ptr<CaptureRequest>& request) override;
52     bool IsRunning() const override;
53     void DumpStatsInfo() const override;
54 
55     virtual void HandleRequest();
56     virtual uint64_t GetUsage();
57     virtual uint32_t GetBufferCount();
58     virtual void HandleResult(std::shared_ptr<IBuffer>& buffer);
59     virtual RetCode DeliverBuffer();
60     virtual RetCode ReceiveBuffer(std::shared_ptr<IBuffer>& buffer);
61     virtual uint64_t GetFrameCount() const;
62 
63     enum StreamState {
64         STREAM_STATE_IDLE = 0,
65         STREAM_STATE_ACTIVE,
66         STREAM_STATE_BUSY,
67         STREAM_STATE_OFFLINE,
68     };
69 
70 protected:
71     int32_t streamId_ = -1;
72     int32_t streamType_ = -1;
73     bool isFirstRequest = true;
74     uint64_t frameCount = 0;
75     std::shared_ptr<IPipelineCore> pipelineCore_ = nullptr;
76     std::shared_ptr<IStreamPipelineCore> pipeline_ = nullptr;
77     std::shared_ptr<HostStreamMgr> hostStreamMgr_ = nullptr;
78     std::shared_ptr<CaptureMessageOperator> messenger_ = nullptr;
79     StreamConfiguration streamConfig_ = {};
80     std::atomic<StreamState> state_ = STREAM_STATE_IDLE;
81     std::shared_ptr<StreamTunnel> tunnel_ = nullptr;
82     std::shared_ptr<IBufferPool> bufferPool_ = nullptr;
83     uint64_t poolId_ = 0;
84 
85     std::mutex wtLock_ = {};
86     std::list<std::shared_ptr<CaptureRequest>> waitingList_ = {};
87     std::condition_variable cv_ = {};
88 
89     std::mutex tsLock_ = {};
90     std::list<std::shared_ptr<CaptureRequest>> inTransitList_ = {};
91 
92     std::mutex smLock_ = {};
93 
94     std::unique_ptr<std::thread> handler_ = nullptr;
95     std::shared_ptr<CaptureRequest> lastRequest_ = nullptr;
96 };
97 } // end namespace OHOS::Camera
98 #endif // STREAM_OPERATOR_STREAM_BASE_H
99