28 #include "../include/DecklinkReader.h"
33 : device(device), is_open(false), g_videoModeIndex(video_mode), g_audioChannels(channels), g_audioSampleDepth(sample_depth)
37 selectedDisplayMode = bmdModeNTSC;
38 pixelFormat = bmdFormat8BitYUV;
41 foundDisplayMode =
false;
42 pthread_mutex_init(&sleepMutex, NULL);
43 pthread_cond_init(&sleepCond, NULL);
47 case 0: pixelFormat = bmdFormat8BitYUV;
break;
48 case 1: pixelFormat = bmdFormat10BitYUV;
break;
49 case 2: pixelFormat = bmdFormat10BitRGB;
break;
51 throw DecklinkError(
"Pixel format is not valid (must be 0,1,2).");
56 deckLinkIterator = CreateDeckLinkIteratorInstance();
58 if (!deckLinkIterator)
59 throw DecklinkError(
"This application requires the DeckLink drivers installed.");
62 for (
int device_count = 0; device_count <= device; device_count++)
65 result = deckLinkIterator->Next(&deckLink);
69 if (device_count == device)
73 if (deckLink->QueryInterface(IID_IDeckLinkInput, (
void**)&deckLinkInput) != S_OK)
77 result = deckLinkInput->GetDisplayModeIterator(&displayModeIterator);
79 throw DecklinkError(
"Could not obtain the video output display mode iterator.");
82 if (deckLink->QueryInterface(IID_IDeckLinkOutput, (
void**)&m_deckLinkOutput) != S_OK)
83 throw DecklinkError(
"Failed to create a deckLinkOutput(), used to convert YUV to RGB.");
86 if(!(m_deckLinkConverter = CreateVideoConversionInstance()))
87 throw DecklinkError(
"Failed to create a VideoConversionInstance(), used to convert YUV to RGB.");
91 deckLinkInput->SetCallback(delegate);
95 if (g_videoModeIndex < 0)
99 while (displayModeIterator->Next(&displayMode) == S_OK)
101 if (g_videoModeIndex == displayModeCount)
103 BMDDisplayModeSupport result;
105 foundDisplayMode =
true;
106 displayMode->GetName(&displayModeName);
107 selectedDisplayMode = displayMode->GetDisplayMode();
108 deckLinkInput->DoesSupportVideoMode(selectedDisplayMode, pixelFormat, bmdVideoInputFlagDefault, &result, NULL);
111 displayMode->GetFrameRate(&frameRateDuration, &frameRateScale);
113 if (result == bmdDisplayModeNotSupported)
114 throw DecklinkError(
"The display mode does not support the selected pixel format.");
116 if (inputFlags & bmdVideoInputDualStream3D)
118 if (!(displayMode->GetFlags() & bmdDisplayModeSupports3D))
119 throw DecklinkError(
"The display mode does not support 3D.");
125 displayMode->Release();
128 if (!foundDisplayMode)
129 throw DecklinkError(
"Invalid video mode. No matching ones found.");
132 result = deckLinkInput->EnableVideoInput(selectedDisplayMode, pixelFormat, inputFlags);
134 throw DecklinkError(
"Failed to enable video input. Is another application using the card?");
137 result = deckLinkInput->EnableAudioInput(bmdAudioSampleRate48kHz, g_audioSampleDepth, g_audioChannels);
139 throw DecklinkError(
"Failed to enable audio input. Is another application using the card?");
146 if (displayModeIterator != NULL)
148 displayModeIterator->Release();
149 displayModeIterator = NULL;
152 if (deckLinkInput != NULL)
154 deckLinkInput->Release();
155 deckLinkInput = NULL;
158 if (deckLink != NULL)
164 if (deckLinkIterator != NULL)
165 deckLinkIterator->Release();
175 result = deckLinkInput->StartStreams();
177 throw DecklinkError(
"Failed to start the video and audio streams.");
218 result = deckLinkInput->StopStreams();
221 throw DecklinkError(
"Failed to stop the video and audio streams.");
237 std::shared_ptr<Frame> f = delegate->
GetFrame(requested_frame);
257 root[
"type"] =
"DecklinkReader";
269 bool success = reader.parse( value, root );
272 throw InvalidJSON(
"JSON could not be parsed (or is invalid)",
"");
282 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)",
"");