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)",
"");
int num
Numerator for the fraction.
void SetJsonValue(Json::Value root)
Load Json::JsonValue into this object.
int width
The width of the video (in pixesl)
std::shared_ptr< Frame > GetFrame(int64_t requested_frame)
float duration
Length of time (in seconds)
void Open()
Open device and video stream - which is called by the constructor automatically.
unsigned long GetCurrentFrameNumber()
bool has_video
Determines if this file has a video stream.
Fraction display_ratio
The ratio of width to height of the video stream (i.e. 640x480 has a ratio of 4/3) ...
int64_t file_size
Size of file (in bytes)
string Json()
Get and Set JSON methods.
bool has_audio
Determines if this file has an audio stream.
Exception when accessing a blackmagic decklink card.
int64_t video_length
The number of frames in the video stream.
int height
The height of the video (in pixels)
This class represents a fraction.
virtual Json::Value JsonValue()=0
Generate Json::JsonValue for this object.
virtual void SetJsonValue(Json::Value root)=0
Load Json::JsonValue into this object.
ReaderInfo info
Information about the current media file.
DecklinkReader(int device, int video_mode, int pixel_format, int channels, int sample_depth)
Json::Value JsonValue()
Generate Json::JsonValue for this object.
Fraction fps
Frames per second, as a fraction (i.e. 24/1 = 24 fps)
Fraction video_timebase
The video timebase determines how long each frame stays on the screen.
Fraction pixel_ratio
The pixel ratio of the video stream as a fraction (i.e. some pixels are not square) ...
void SetJson(string value)
Load JSON string into this object.
This namespace is the default namespace for all code in the openshot library.
Exception for invalid JSON.
string vcodec
The name of the video codec used to encode / decode the video stream.
int den
Denominator for the fraction.
double ToDouble()
Return this fraction as a double (i.e. 1/2 = 0.5)