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 "device_manager_adapter.h" 26 #include <functional> 27 28 namespace OHOS::Camera { 29 class INode; 30 class IPort : public NoCopyable { 31 public: 32 virtual ~IPort() = default; 33 virtual std::string GetName() const = 0; 34 virtual RetCode SetFormat(const PortFormat& format) = 0; 35 virtual RetCode GetFormat(PortFormat& format) const = 0; 36 virtual int32_t GetStreamId() const = 0; 37 virtual RetCode Connect(const std::shared_ptr<IPort>& peer) = 0; 38 virtual RetCode DisConnect() = 0; 39 virtual int32_t Direction() const = 0; 40 virtual std::shared_ptr<INode> GetNode() const = 0; 41 virtual std::shared_ptr<IPort> Peer() const = 0; 42 virtual void DeliverBuffer(std::shared_ptr<IBuffer>& buffer) = 0; 43 virtual void DeliverBuffers(std::vector<std::shared_ptr<IBuffer>>& buffers) = 0; 44 virtual void DeliverBuffers(std::shared_ptr<FrameSpec> frameSpec) = 0; 45 virtual void DeliverBuffers(std::vector<std::shared_ptr<FrameSpec>> mergeVec) = 0; 46 PortFormat format_ {}; 47 }; 48 49 class INode : public NoCopyable { 50 public: 51 using BufferCb = std::function<void(std::shared_ptr<IBuffer>)>; 52 virtual ~INode() = default; 53 virtual std::string GetName() const = 0; 54 virtual std::string GetType() const = 0; 55 virtual std::shared_ptr<IPort> GetPort(const std::string& name) = 0; 56 virtual RetCode Init(const int32_t streamId) = 0; 57 virtual RetCode Start(const int32_t streamId) = 0; 58 virtual RetCode Flush(const int32_t streamId) = 0; 59 virtual RetCode SetCallback() = 0; 60 virtual RetCode Stop(const int32_t streamId) = 0; 61 virtual RetCode Config(const int32_t streamId, const CaptureMeta& meta) = 0; 62 virtual RetCode Capture(const int32_t streamId, const int32_t captureId) = 0; 63 virtual RetCode CancelCapture(const int32_t streamId) = 0; 64 virtual int32_t GetNumberOfInPorts() const = 0; 65 virtual int32_t GetNumberOfOutPorts() const = 0; 66 virtual std::vector<std::shared_ptr<IPort>> GetInPorts() const = 0; 67 virtual std::vector<std::shared_ptr<IPort>> GetOutPorts() = 0; 68 virtual std::shared_ptr<IPort> GetOutPortById(const int32_t id) = 0; 69 virtual void DeliverBuffer(std::shared_ptr<IBuffer>& buffer) = 0; 70 virtual void DeliverBuffers(std::vector<std::shared_ptr<IBuffer>>& buffers) = 0; 71 virtual void SetCallBack(BufferCb c) = 0; 72 73 virtual RetCode ProvideBuffers(std::shared_ptr<FrameSpec> frameSpec) = 0; 74 virtual void DeliverBuffers(std::shared_ptr<FrameSpec> frameSpec) = 0; 75 virtual void DeliverBuffers(std::vector<std::shared_ptr<FrameSpec>> mergeVec) = 0; 76 77 public: 78 int32_t wide_; 79 int32_t high_; 80 }; 81 82 83 using NodeFactory = RegisterFactoty<INode, const std::string&, const std::string&, const std::string&>; 84 85 #define REGISTERNODE(cls, ...) \ 86 namespace { \ 87 static std::string g_##cls = NodeFactory::Instance().DoRegister<cls>(__VA_ARGS__, \ 88 [](const std::string& name, const std::string& type, const std::string &cameraId) \ 89 {return std::make_shared<cls>(name, type, cameraId);}); \ 90 } 91 } 92 #endif 93