31 #include "../include/DecklinkReader.h"
36 : device(device), is_open(false), g_videoModeIndex(video_mode), g_audioChannels(channels), g_audioSampleDepth(sample_depth)
40 selectedDisplayMode = bmdModeNTSC;
41 pixelFormat = bmdFormat8BitYUV;
44 foundDisplayMode =
false;
45 pthread_mutex_init(&sleepMutex, NULL);
46 pthread_cond_init(&sleepCond, NULL);
50 case 0: pixelFormat = bmdFormat8BitYUV;
break;
51 case 1: pixelFormat = bmdFormat10BitYUV;
break;
52 case 2: pixelFormat = bmdFormat10BitRGB;
break;
54 throw DecklinkError(
"Pixel format is not valid (must be 0,1,2).");
59 deckLinkIterator = CreateDeckLinkIteratorInstance();
61 if (!deckLinkIterator)
62 throw DecklinkError(
"This application requires the DeckLink drivers installed.");
65 for (
int device_count = 0; device_count <= device; device_count++)
68 result = deckLinkIterator->Next(&deckLink);
72 if (device_count == device)
76 if (deckLink->QueryInterface(IID_IDeckLinkInput, (
void**)&deckLinkInput) != S_OK)
80 result = deckLinkInput->GetDisplayModeIterator(&displayModeIterator);
82 throw DecklinkError(
"Could not obtain the video output display mode iterator.");
85 if (deckLink->QueryInterface(IID_IDeckLinkOutput, (
void**)&m_deckLinkOutput) != S_OK)
86 throw DecklinkError(
"Failed to create a deckLinkOutput(), used to convert YUV to RGB.");
89 if(!(m_deckLinkConverter = CreateVideoConversionInstance()))
90 throw DecklinkError(
"Failed to create a VideoConversionInstance(), used to convert YUV to RGB.");
94 deckLinkInput->SetCallback(delegate);
98 if (g_videoModeIndex < 0)
102 while (displayModeIterator->Next(&displayMode) == S_OK)
104 if (g_videoModeIndex == displayModeCount)
106 BMDDisplayModeSupport result;
108 foundDisplayMode =
true;
109 displayMode->GetName(&displayModeName);
110 selectedDisplayMode = displayMode->GetDisplayMode();
111 deckLinkInput->DoesSupportVideoMode(selectedDisplayMode, pixelFormat, bmdVideoInputFlagDefault, &result, NULL);
114 displayMode->GetFrameRate(&frameRateDuration, &frameRateScale);
116 if (result == bmdDisplayModeNotSupported)
117 throw DecklinkError(
"The display mode does not support the selected pixel format.");
119 if (inputFlags & bmdVideoInputDualStream3D)
121 if (!(displayMode->GetFlags() & bmdDisplayModeSupports3D))
122 throw DecklinkError(
"The display mode does not support 3D.");
128 displayMode->Release();
131 if (!foundDisplayMode)
132 throw DecklinkError(
"Invalid video mode. No matching ones found.");
135 result = deckLinkInput->EnableVideoInput(selectedDisplayMode, pixelFormat, inputFlags);
137 throw DecklinkError(
"Failed to enable video input. Is another application using the card?");
140 result = deckLinkInput->EnableAudioInput(bmdAudioSampleRate48kHz, g_audioSampleDepth, g_audioChannels);
142 throw DecklinkError(
"Failed to enable audio input. Is another application using the card?");
149 if (displayModeIterator != NULL)
151 displayModeIterator->Release();
152 displayModeIterator = NULL;
155 if (deckLinkInput != NULL)
157 deckLinkInput->Release();
158 deckLinkInput = NULL;
161 if (deckLink != NULL)
167 if (deckLinkIterator != NULL)
168 deckLinkIterator->Release();
178 result = deckLinkInput->StartStreams();
180 throw DecklinkError(
"Failed to start the video and audio streams.");
221 result = deckLinkInput->StopStreams();
224 throw DecklinkError(
"Failed to stop the video and audio streams.");
240 std::shared_ptr<Frame> f = delegate->
GetFrame(requested_frame);
260 root[
"type"] =
"DecklinkReader";
276 catch (
const std::exception& e)
279 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");