Files
DMF-Studio/nodes/decklink-in/src/decklink_in_node.hpp
T
2026-05-30 22:12:47 +03:00

85 lines
2.5 KiB
C++

#pragma once
#include <dmf-node/node.hpp>
#include <mxl/flow.h>
#include <mxl/time.h>
#include <DeckLinkAPI.h>
#include <atomic>
#include <mutex>
#include <optional>
#include <thread>
namespace dmf_node {
class DeckLinkInNode : public Node {
public:
DeckLinkInNode() = default;
~DeckLinkInNode();
std::string type() const override { return "decklink-in"; }
std::vector<PortDef> input_ports() const override { return {}; }
std::vector<PortDef> output_ports() const override {
return {{"video_out", PortDirection::Output, MediaType::VideoV210}};
}
void configure(const nlohmann::json& params) override;
void on_add_writer(const std::string& port_id, mxlFlowWriter writer) override;
void on_add_reader(const std::string& port_id, mxlFlowReader reader) override {}
void on_remove_writer(const std::string& port_id) override;
void on_remove_reader(const std::string& port_id) override {}
void process() override;
nlohmann::json status() const override;
private:
bool open_device();
void close_device();
std::optional<mxlFlowWriter> writer_;
mxlRational grain_rate_{25, 1};
uint64_t write_index_ = 0;
uint64_t grains_written_ = 0;
int device_index_ = 0;
BMDDisplayMode display_mode_ = bmdModeHD1080i50;
BMDVideoConnection input_connection_ = bmdVideoConnectionUnspecified;
IDeckLink* decklink_ = nullptr;
IDeckLinkInput* input_ = nullptr;
std::atomic<bool> capturing_{false};
bool is_interlaced_ = false;
std::mutex frame_mutex_;
void* frame_data_ = nullptr;
long frame_row_bytes_ = 0;
long frame_width_ = 1920;
long frame_height_ = 1080;
bool frame_ready_ = false;
class CaptureCallback : public IDeckLinkInputCallback {
public:
CaptureCallback(DeckLinkInNode& owner) : owner_(owner) {}
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID, void**) override { return E_NOINTERFACE; }
ULONG STDMETHODCALLTYPE AddRef() override { return 1; }
ULONG STDMETHODCALLTYPE Release() override { return 1; }
HRESULT STDMETHODCALLTYPE VideoInputFormatChanged(
BMDVideoInputFormatChangedEvents, IDeckLinkDisplayMode*, BMDDetectedVideoInputFormatFlags) override;
HRESULT STDMETHODCALLTYPE VideoInputFrameArrived(
IDeckLinkVideoInputFrame* videoFrame, IDeckLinkAudioInputPacket*) override;
private:
DeckLinkInNode& owner_;
};
std::unique_ptr<CaptureCallback> callback_;
};
} // namespace dmf_node