X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=decklink_output.cpp;fp=decklink_output.cpp;h=55d29c5aad38c8d5be43f30ef677a2c9bb9ef032;hb=9aabf53d2ee424e66e3d51039a7a8ecce25f3516;hp=38f44ee96c4d614e2d9ed2729ad2cc42e185eec8;hpb=8b8a5da881d4580e8b7e53837f660f05611796a0;p=nageru diff --git a/decklink_output.cpp b/decklink_output.cpp index 38f44ee..55d29c5 100644 --- a/decklink_output.cpp +++ b/decklink_output.cpp @@ -302,6 +302,33 @@ void DeckLinkOutput::wait_for_frame(int64_t pts, int *dropped_frames, int64_t *f 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 &desired : vector>{ { 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(completedFrame);