51 lines
1.6 KiB
C++
51 lines
1.6 KiB
C++
#pragma once
|
|
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "frame/frame.h"
|
|
#include "utils/simple_json.h"
|
|
#include "utils/spsc_queue.h"
|
|
|
|
namespace rk3588 {
|
|
|
|
using FramePtr = std::shared_ptr<Frame>;
|
|
|
|
struct NodeContext {
|
|
// For nodes with upstream input.
|
|
std::shared_ptr<SpscQueue<FramePtr>> input_queue;
|
|
// For nodes that produce downstream outputs (one queue per outgoing edge).
|
|
std::vector<std::shared_ptr<SpscQueue<FramePtr>>> output_queues;
|
|
};
|
|
|
|
class INode {
|
|
public:
|
|
virtual ~INode() = default;
|
|
virtual std::string Id() const = 0;
|
|
virtual std::string Type() const = 0;
|
|
virtual bool Init(const SimpleJson& config, const NodeContext& ctx) = 0;
|
|
virtual bool Start() = 0;
|
|
virtual void Stop() = 0;
|
|
};
|
|
|
|
constexpr int kNodeAbiVersion = 1;
|
|
|
|
using CreateNodeFn = INode* (*)();
|
|
using DestroyNodeFn = void (*)(INode*);
|
|
using GetTypeFn = const char* (*)();
|
|
using GetAbiFn = int (*)();
|
|
|
|
#define REGISTER_NODE(NodeClass, NodeTypeStr) \
|
|
extern "C" rk3588::INode* CreateNode() { \
|
|
return new NodeClass(); \
|
|
} \
|
|
extern "C" const char* GetNodeType() { \
|
|
return NodeTypeStr; \
|
|
} \
|
|
extern "C" int GetAbiVersion() { \
|
|
return rk3588::kNodeAbiVersion; \
|
|
}
|
|
|
|
} // namespace rk3588
|