Decklink in #4
@@ -8,15 +8,19 @@
|
||||
|
||||
class DeckLinkInNode : public dmf::NodeBase {
|
||||
void run() override {
|
||||
dmf::DeckLinkReceiver receiver;
|
||||
const uint32_t device_index = config().value("device_index", 0u);
|
||||
|
||||
dmf::DeckLinkReceiver receiver;
|
||||
try {
|
||||
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);
|
||||
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)) {
|
||||
log("Timeout waiting for format detection");
|
||||
@@ -55,7 +59,7 @@ class DeckLinkInNode : public dmf::NodeBase {
|
||||
uint64_t video_index = mxlGetCurrentIndex(&video_rate);
|
||||
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)) {
|
||||
if (!receiver.wait_for_frame(frame_buf.data(), video_stride, width, height)) break;
|
||||
|
||||
@@ -68,7 +68,7 @@ public:
|
||||
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);
|
||||
return format_cv.wait_for(lk, std::chrono::milliseconds(timeout_ms),
|
||||
[this] { return format_detected; });
|
||||
@@ -173,16 +173,19 @@ private:
|
||||
std::atomic<int32_t> ref_count{1};
|
||||
};
|
||||
|
||||
// DeckLink SDK objects
|
||||
std::vector<IDeckLink*> raw_devices;
|
||||
IDeckLink* selected_device = nullptr;
|
||||
IDeckLinkInput* decklink_input = nullptr;
|
||||
InputCallback* input_callback = nullptr;
|
||||
|
||||
// Synchronisation — one mutex guards all shared state below
|
||||
std::mutex mutex;
|
||||
std::condition_variable format_cv;
|
||||
std::condition_variable frame_cv;
|
||||
std::condition_variable format_cv; // signalled when format is detected
|
||||
std::condition_variable frame_cv; // signalled when a frame arrives
|
||||
bool format_detected = false;
|
||||
|
||||
// Frame state — written by InputCallback, read by wait_for_frame (both under mutex)
|
||||
std::vector<uint8_t> frame_buffer;
|
||||
uint32_t frame_row_bytes = 0;
|
||||
int frame_width = 0;
|
||||
|
||||
Reference in New Issue
Block a user