feat: add DeckLink input and output nodes
decklink-in: - IDeckLinkInputCallback::VideoInputFrameArrived captures V210 frames - Frame data stored with mutex, copied to MXL grain in process thread - Uses mxlSleepUntil for TAI-time-based grain pacing - Configurable: device_index (int), mode (1080i50/1080p50/etc) - Auto-detect input format via bmdVideoInputEnableFormatDetection - 1 output port: video_out (V210) decklink-out: - Reads V210 grains from MXL, schedules playback via DeckLink output - Creates IDeckLinkMutableVideoFrame, copies grain data, schedules - Uses ScheduledFrameCompleted callback for frame completion - Configurable: device_index (int), mode (1080i50/1080p50/etc) - 1 input port: video_in (V210) Both nodes: - Use DeckLinkAPIDispatch.cpp for CreateDeckLinkIteratorInstance - Access pixel data via IDeckLinkVideoBuffer (latest SDK API) - Graceful device open/close on writer/reader add/remove - Build conditionally via DMF_BUILD_DECKLINK + DECKLINK_SDK_DIR
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
#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_{50, 1};
|
||||
uint64_t write_index_ = 0;
|
||||
uint64_t grains_written_ = 0;
|
||||
|
||||
int device_index_ = 0;
|
||||
BMDDisplayMode display_mode_ = bmdModeHD1080i50;
|
||||
|
||||
IDeckLink* decklink_ = nullptr;
|
||||
IDeckLinkInput* input_ = nullptr;
|
||||
|
||||
std::atomic<bool> capturing_{false};
|
||||
std::mutex frame_mutex_;
|
||||
void* frame_data_ = nullptr;
|
||||
long frame_row_bytes_ = 0;
|
||||
long frame_width_ = 0;
|
||||
long frame_height_ = 0;
|
||||
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
|
||||
Reference in New Issue
Block a user