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