28 #include "../include/DecklinkWriter.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;
50 case 3: pixelFormat = bmdFormat8BitARGB;
break;
52 throw DecklinkError(
"Pixel format is not valid (must be 0,1,2,3).");
63 deckLinkIterator = CreateDeckLinkIteratorInstance();
65 if (!deckLinkIterator)
66 throw DecklinkError(
"This application requires the DeckLink drivers installed.");
69 for (
int device_count = 0; device_count <= device; device_count++)
72 result = deckLinkIterator->Next(&deckLink);
76 if (device_count == device)
80 if (deckLink->QueryInterface(IID_IDeckLinkOutput, (
void**)&deckLinkOutput) != S_OK)
84 result = deckLinkOutput->GetDisplayModeIterator(&displayModeIterator);
86 throw DecklinkError(
"Could not obtain the video output display mode iterator.");
88 if (g_videoModeIndex < 0)
92 const char *displayModeName;
93 BMDTimeValue frameRateDuration, frameRateScale;
95 while (displayModeIterator->Next(&displayMode) == S_OK)
97 if (g_videoModeIndex == displayModeCount)
99 BMDDisplayModeSupport result;
101 foundDisplayMode =
true;
102 displayMode->GetName(&displayModeName);
103 selectedDisplayMode = displayMode->GetDisplayMode();
107 displayMode->GetFrameRate(&frameRateDuration, &frameRateScale);
120 if (!foundDisplayMode)
121 throw DecklinkError(
"Invalid video mode. No matching ones found.");
124 unsigned long m_framesPerSecond = (
unsigned long)((frameRateScale + (frameRateDuration-1)) / frameRateDuration);
130 deckLinkOutput->SetScheduledFrameCompletionCallback(delegate);
134 if (deckLinkOutput->EnableVideoOutput(displayMode->GetDisplayMode(), bmdVideoOutputFlagDefault) != S_OK)
135 throw DecklinkError(
"Failed to enable video output. Is another application using the card?");
196 deckLinkOutput->StopScheduledPlayback(0, NULL, 0);
197 deckLinkOutput->DisableAudioOutput();
198 deckLinkOutput->DisableVideoOutput();
201 displayMode->Release();
203 if (displayModeIterator != NULL)
205 displayModeIterator->Release();
206 displayModeIterator = NULL;
209 if (deckLinkOutput != NULL)
211 deckLinkOutput->Release();
212 deckLinkOutput = NULL;
215 if (deckLink != NULL)
221 if (deckLinkIterator != NULL)
222 deckLinkIterator->Release();
234 throw WriterClosed(
"The DecklinkWriter is closed. Call Open() before calling this method.",
"");
243 for (
int number = start; number <= length; number++)
246 std::shared_ptr<Frame> f = reader->
GetFrame(number);