fprintf(stderr, "Failed to set PsF flag for card\n");
exit(1);
}
+ if (config->SetFlag(bmdDeckLinkConfigSMPTELevelAOutput, true) != S_OK) {
+ // This affects at least some no-name SDI->HDMI converters.
+ // Warn, but don't die.
+ fprintf(stderr, "WARNING: Failed to enable SMTPE Level A; resolutions like 1080p60 might have issues.\n");
+ }
BMDDisplayModeSupport support;
IDeckLinkDisplayMode *display_mode;
}
}
-void DeckLinkOutput::wait_for_frame(int64_t pts, int *dropped_frames, int64_t *frame_duration, bool *is_preroll)
+void DeckLinkOutput::wait_for_frame(int64_t pts, int *dropped_frames, int64_t *frame_duration, bool *is_preroll, steady_clock::time_point *frame_timestamp)
{
assert(!should_quit);
double playback_speed;
output->GetScheduledStreamTime(TIMEBASE, &stream_frame_time, &playback_speed);
+ *frame_timestamp = steady_clock::now() +
+ nanoseconds((target_time - stream_frame_time) * 1000000000 / TIMEBASE);
+
// If we're ahead of time, wait for the frame to (approximately) start.
if (stream_frame_time < target_time) {
- steady_clock::time_point t = steady_clock::now() +
- nanoseconds((target_time - stream_frame_time) * 1000000000 / TIMEBASE);
- this_thread::sleep_until(t);
+ this_thread::sleep_until(*frame_timestamp);
return;
}
// Oops, we missed by more than one frame. Return immediately,
// but drop so that we catch up.
*dropped_frames = (stream_frame_time - target_time + *frame_duration - 1) / *frame_duration;
+ const int64_t ns_per_frame = this->frame_duration * 1000000000 / TIMEBASE;
+ *frame_timestamp += nanoseconds(*dropped_frames * ns_per_frame);
fprintf(stderr, "Dropped %d output frames; skipping.\n", *dropped_frames);
}
+uint32_t DeckLinkOutput::pick_video_mode(uint32_t mode) const
+{
+ if (video_modes.count(mode)) {
+ return mode;
+ }
+
+ // Prioritize 59.94 > 60 > 29.97. If none of those are found, then pick the highest one.
+ for (const pair<int, int> &desired : vector<pair<int, int>>{ { 60000, 1001 }, { 60, 0 }, { 30000, 1001 } }) {
+ for (const auto &it : video_modes) {
+ if (it.second.frame_rate_num * desired.second == desired.first * it.second.frame_rate_den) {
+ return it.first;
+ }
+ }
+ }
+
+ uint32_t best_mode = 0;
+ double best_fps = 0.0;
+ for (const auto &it : video_modes) {
+ double fps = double(it.second.frame_rate_num) / it.second.frame_rate_den;
+ if (fps > best_fps) {
+ best_mode = it.first;
+ best_fps = fps;
+ }
+ }
+ return best_mode;
+}
+
HRESULT DeckLinkOutput::ScheduledFrameCompleted(/* in */ IDeckLinkVideoFrame *completedFrame, /* in */ BMDOutputFrameCompletionResult result)
{
Frame *frame = static_cast<Frame *>(completedFrame);
break;
}
- static int hei = 0;
- print_latency("DeckLink output latency (frame received → output on HDMI):", frame->received_ts, false, &hei);
+ static int frameno = 0;
+ print_latency("DeckLink output latency (frame received → output on HDMI):", frame->received_ts, false, &frameno);
{
lock_guard<mutex> lock(frame_queue_mutex);