]> git.sesse.net Git - nageru/commitdiff
Split DeckLink mode summarization into a separate shared file.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 11 Jan 2017 21:06:51 +0000 (22:06 +0100)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 15 Jan 2017 23:24:07 +0000 (00:24 +0100)
Useful when we want output.

Makefile
decklink_capture.cpp
decklink_util.cpp [new file with mode: 0644]
decklink_util.h [new file with mode: 0644]

index b2f0906019d8391748f01911a97a678ae0b3ed5e..2d2d60950dca9d5768fe36416a597bd66425e3f0 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -28,7 +28,7 @@ OBJS += chroma_subsampler.o mixer.o pbo_frame_allocator.o context.o ref_counted_
 OBJS += quicksync_encoder.o x264_encoder.o x264_speed_control.o video_encoder.o metacube2.o mux.o audio_encoder.o ffmpeg_raii.o
 
 # DeckLink
-OBJS += decklink_capture.o decklink/DeckLinkAPIDispatch.o
+OBJS += decklink_capture.o decklink_util.o decklink/DeckLinkAPIDispatch.o
 
 # bmusb
 ifeq ($(EMBEDDED_BMUSB),yes)
index 1093ab11aa0f64f388a6e348520ac8cb57f023a6..2c255207c0bd5009fe85c362ff7be2d985fdeed9 100644 (file)
@@ -18,6 +18,7 @@
 #include <vector>
 
 #include "bmusb/bmusb.h"
+#include "decklink_util.h"
 
 #define FRAME_SIZE (8 << 20)  // 8 MB.
 
@@ -221,36 +222,8 @@ DeckLinkCapture::DeckLinkCapture(IDeckLink *card, int card_index)
                exit(1);
        }
 
-       for (IDeckLinkDisplayMode *mode_ptr; mode_it->Next(&mode_ptr) == S_OK; mode_ptr->Release()) {
-               VideoMode mode;
-
-               const char *mode_name;
-               if (mode_ptr->GetName(&mode_name) != S_OK) {
-                       mode.name = "Unknown mode";
-               } else {
-                       mode.name = mode_name;
-               }
-
-               mode.autodetect = false;
-
-               mode.width = mode_ptr->GetWidth();
-               mode.height = mode_ptr->GetHeight();
-
-               BMDTimeScale frame_rate_num;
-               BMDTimeValue frame_rate_den;
-               if (mode_ptr->GetFrameRate(&frame_rate_den, &frame_rate_num) != S_OK) {
-                       fprintf(stderr, "Could not get frame rate for mode '%s' on card %d\n", mode.name.c_str(), card_index);
-                       exit(1);
-               }
-               mode.frame_rate_num = frame_rate_num;
-               mode.frame_rate_den = frame_rate_den;
-
-               // TODO: Respect the TFF/BFF flag.
-               mode.interlaced = (mode_ptr->GetFieldDominance() == bmdLowerFieldFirst || mode_ptr->GetFieldDominance() == bmdUpperFieldFirst);
-
-               uint32_t id = mode_ptr->GetDisplayMode();
-               video_modes.insert(make_pair(id, mode));
-       }
+       video_modes = summarize_video_modes(mode_it, card_index);
+       mode_it->Release();
 
        set_video_mode_no_restart(bmdModeHD720p5994);
 
diff --git a/decklink_util.cpp b/decklink_util.cpp
new file mode 100644 (file)
index 0000000..0e775de
--- /dev/null
@@ -0,0 +1,45 @@
+#include <DeckLinkAPI.h>
+#include <DeckLinkAPIModes.h>
+
+#include "decklink_util.h"
+
+using namespace bmusb;
+using namespace std;
+
+map<uint32_t, VideoMode> summarize_video_modes(IDeckLinkDisplayModeIterator *mode_it, unsigned card_index)
+{
+       map<uint32_t, VideoMode> video_modes;
+
+       for (IDeckLinkDisplayMode *mode_ptr; mode_it->Next(&mode_ptr) == S_OK; mode_ptr->Release()) {
+               VideoMode mode;
+
+               const char *mode_name;
+               if (mode_ptr->GetName(&mode_name) != S_OK) {
+                       mode.name = "Unknown mode";
+               } else {
+                       mode.name = mode_name;
+               }
+
+               mode.autodetect = false;
+
+               mode.width = mode_ptr->GetWidth();
+               mode.height = mode_ptr->GetHeight();
+
+               BMDTimeScale frame_rate_num;
+               BMDTimeValue frame_rate_den;
+               if (mode_ptr->GetFrameRate(&frame_rate_den, &frame_rate_num) != S_OK) {
+                       fprintf(stderr, "Could not get frame rate for mode '%s' on card %d\n", mode.name.c_str(), card_index);
+                       exit(1);
+               }
+               mode.frame_rate_num = frame_rate_num;
+               mode.frame_rate_den = frame_rate_den;
+
+               // TODO: Respect the TFF/BFF flag.
+               mode.interlaced = (mode_ptr->GetFieldDominance() == bmdLowerFieldFirst || mode_ptr->GetFieldDominance() == bmdUpperFieldFirst);
+
+               uint32_t id = mode_ptr->GetDisplayMode();
+               video_modes.insert(make_pair(id, mode));
+       }
+
+       return video_modes;
+}
diff --git a/decklink_util.h b/decklink_util.h
new file mode 100644 (file)
index 0000000..2bef415
--- /dev/null
@@ -0,0 +1,14 @@
+#ifndef _DECKLINK_UTIL
+#define _DECKLINK_UTIL 1
+
+#include <stdint.h>
+
+#include <map>
+
+#include "bmusb/bmusb.h"
+
+class IDeckLinkDisplayModeIterator;
+
+std::map<uint32_t, bmusb::VideoMode> summarize_video_modes(IDeckLinkDisplayModeIterator *mode_it, unsigned card_index);
+
+#endif  // !defined(_DECKLINK_UTIL)