Decklink in #4

Merged
itten merged 5 commits from decklink-in into main 2026-07-06 02:08:30 +03:00
2 changed files with 19 additions and 12 deletions
Showing only changes of commit e335461aac - Show all commits
+13 -9
View File
@@ -8,15 +8,19 @@
class DeckLinkInNode : public dmf::NodeBase { class DeckLinkInNode : public dmf::NodeBase {
void run() override { void run() override {
dmf::DeckLinkReceiver receiver;
log("Available DeckLink devices:");
for (const auto& d : receiver.devices)
log(" %u) %s", d.index, d.name.c_str());
const uint32_t device_index = config().value("device_index", 0u); const uint32_t device_index = config().value("device_index", 0u);
receiver.start_capture(device_index);
log("Capturing from: %s", receiver.devices[device_index].name.c_str()); dmf::DeckLinkReceiver receiver;
try {
log("Available DeckLink devices:");
for (const auto& d : receiver.devices)
log(" %u) %s", d.index, d.name.c_str());
receiver.start_capture(device_index);
log("Capturing from: %s", receiver.devices[device_index].name.c_str());
} catch (const std::runtime_error& e) {
log("DeckLink init error: %s", e.what());
return;
}
if (!receiver.wait_for_format(5000)) { if (!receiver.wait_for_format(5000)) {
log("Timeout waiting for format detection"); log("Timeout waiting for format detection");
@@ -55,7 +59,7 @@ class DeckLinkInNode : public dmf::NodeBase {
uint64_t video_index = mxlGetCurrentIndex(&video_rate); uint64_t video_index = mxlGetCurrentIndex(&video_rate);
log("start video_index=%llu", video_index); log("start video_index=%llu", video_index);
std::vector<uint8_t> frame_buf(static_cast<size_t>(video_stride) * static_cast<size_t>(height), 0); std::vector<uint8_t> frame_buf(static_cast<size_t>(video_stride) * static_cast<size_t>(height));
while (dmf::g_running.load(std::memory_order_relaxed)) { while (dmf::g_running.load(std::memory_order_relaxed)) {
if (!receiver.wait_for_frame(frame_buf.data(), video_stride, width, height)) break; if (!receiver.wait_for_frame(frame_buf.data(), video_stride, width, height)) break;
+6 -3
View File
@@ -68,7 +68,7 @@ public:
if (r != S_OK) throw std::runtime_error("Could not start streams"); if (r != S_OK) throw std::runtime_error("Could not start streams");
} }
bool wait_for_format(uint64_t timeout_ms = 5000) { bool wait_for_format(int timeout_ms = 5000) {
std::unique_lock<std::mutex> lk(mutex); std::unique_lock<std::mutex> lk(mutex);
return format_cv.wait_for(lk, std::chrono::milliseconds(timeout_ms), return format_cv.wait_for(lk, std::chrono::milliseconds(timeout_ms),
[this] { return format_detected; }); [this] { return format_detected; });
@@ -173,16 +173,19 @@ private:
std::atomic<int32_t> ref_count{1}; std::atomic<int32_t> ref_count{1};
}; };
// DeckLink SDK objects
std::vector<IDeckLink*> raw_devices; std::vector<IDeckLink*> raw_devices;
IDeckLink* selected_device = nullptr; IDeckLink* selected_device = nullptr;
IDeckLinkInput* decklink_input = nullptr; IDeckLinkInput* decklink_input = nullptr;
InputCallback* input_callback = nullptr; InputCallback* input_callback = nullptr;
// Synchronisation — one mutex guards all shared state below
std::mutex mutex; std::mutex mutex;
std::condition_variable format_cv; std::condition_variable format_cv; // signalled when format is detected
std::condition_variable frame_cv; std::condition_variable frame_cv; // signalled when a frame arrives
bool format_detected = false; bool format_detected = false;
// Frame state — written by InputCallback, read by wait_for_frame (both under mutex)
std::vector<uint8_t> frame_buffer; std::vector<uint8_t> frame_buffer;
uint32_t frame_row_bytes = 0; uint32_t frame_row_bytes = 0;
int frame_width = 0; int frame_width = 0;