• 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  *     http://www.apache.org/licenses/LICENSE-2.0
7  * Unless required by applicable law or agreed to in writing, software
8  * distributed under the License is distributed on an "AS IS" BASIS,
9  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10  * See the License for the specific language governing permissions and
11  * limitations under the License.
12  */
13 
14 #ifndef I_NODE_H
15 #define I_NODE_H
16 #include <string>
17 #include <thread>
18 #include <list>
19 #include "stream_pipeline_data_structure.h"
20 #include "object_factory.h"
21 #include "no_copyable.h"
22 #include "ibuffer.h"
23 #include "ibuffer_pool.h"
24 #include "camera_metadata_info.h"
25 #include <functional>
26 
27 namespace OHOS::Camera {
28 class INode;
29 class IPort : public NoCopyable {
30 public:
31     virtual ~IPort() = default;
32     virtual std::string GetName() const = 0;
33     virtual RetCode SetFormat(const PortFormat& format) = 0;
34     virtual RetCode GetFormat(PortFormat& format) const = 0;
35     virtual int32_t GetStreamId() const = 0;
36     virtual RetCode Connect(const std::shared_ptr<IPort>& peer) = 0;
37     virtual RetCode DisConnect() = 0;
38     virtual int32_t Direction() const = 0;
39     virtual std::shared_ptr<INode> GetNode() const = 0;
40     virtual std::shared_ptr<IPort> Peer() const = 0;
41     virtual void DeliverBuffer(std::shared_ptr<IBuffer>& buffer) = 0;
42     virtual void DeliverBuffers(std::vector<std::shared_ptr<IBuffer>>& buffers) = 0;
43     virtual void DeliverBuffers(std::shared_ptr<FrameSpec> frameSpec) = 0;
44     virtual void DeliverBuffers(std::vector<std::shared_ptr<FrameSpec>> mergeVec) = 0;
45     PortFormat format_ {};
46 };
47 
48 class INode : public NoCopyable {
49 public:
50     using BufferCb = std::function<void(std::shared_ptr<IBuffer>)>;
51     virtual ~INode() = default;
52     virtual std::string GetName() const = 0;
53     virtual std::string GetType() const = 0;
54     virtual std::shared_ptr<IPort> GetPort(const std::string& name) = 0;
55     virtual RetCode Init(const int32_t streamId) = 0;
56     virtual RetCode Start(const int32_t streamId) = 0;
57     virtual RetCode Flush(const int32_t streamId) = 0;
58     virtual RetCode Stop(const int32_t streamId) = 0;
59     virtual RetCode Config(const int32_t streamId, const CaptureMeta& meta) = 0;
60     virtual RetCode Capture(const int32_t streamId, const int32_t captureId) = 0;
61     virtual RetCode CancelCapture(const int32_t streamId) = 0;
62     virtual int32_t GetNumberOfInPorts() const = 0;
63     virtual int32_t GetNumberOfOutPorts() const = 0;
64     virtual std::vector<std::shared_ptr<IPort>> GetInPorts() const = 0;
65     virtual std::vector<std::shared_ptr<IPort>> GetOutPorts() = 0;
66     virtual std::shared_ptr<IPort> GetOutPortById(const int32_t id) = 0;
67     virtual void DeliverBuffer(std::shared_ptr<IBuffer>& buffer) = 0;
68     virtual void DeliverBuffers(std::vector<std::shared_ptr<IBuffer>>& buffers) = 0;
69     virtual void SetCallBack(BufferCb c) = 0;
70 
71     virtual RetCode ProvideBuffers(std::shared_ptr<FrameSpec> frameSpec) = 0;
72     virtual void DeliverBuffers(std::shared_ptr<FrameSpec> frameSpec) = 0;
73     virtual void DeliverBuffers(std::vector<std::shared_ptr<FrameSpec>> mergeVec) = 0;
74 };
75 
76 
77 using NodeFactory = RegisterFactoty<INode, const std::string&, const std::string&>;
78 
79 #define REGISTERNODE(cls, ...) \
80 namespace { \
81     static std::string g_##cls = NodeFactory::Instance().DoRegister<cls>(__VA_ARGS__, \
82                 [](const std::string& name, const std::string& type) {return std::make_shared<cls>(name, type);}); \
83 }
84 }
85 
86 #endif
87