refactor: DeckLinkReceiver readability and error handling

DeckLinkReceiver:
- Group private members with section comments (SDK objects / sync / frame state)
- Change wait_for_format timeout param from uint64_t to int (matches
  std::chrono::milliseconds and all call sites)

decklinkin main.cpp:
- Wrap start_capture in try/catch — logs error and returns cleanly on
  device init failure (consistent with NDIInNode pattern)
- Remove redundant zero-init on frame_buf (vector<uint8_t> zero-inits anyway)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
JohannesItten
2026-07-06 01:38:13 +03:00
parent 640271384e
commit e335461aac
2 changed files with 19 additions and 12 deletions
+6 -3
View File
@@ -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;