37 : device(device), is_open(false), g_videoModeIndex(video_mode), g_audioChannels(channels), g_audioSampleDepth(sample_depth)
41 selectedDisplayMode = bmdModeNTSC;
42 pixelFormat = bmdFormat8BitYUV;
45 foundDisplayMode =
false;
46 pthread_mutex_init(&sleepMutex, NULL);
47 pthread_cond_init(&sleepCond, NULL);
51 case 0: pixelFormat = bmdFormat8BitYUV;
break;
52 case 1: pixelFormat = bmdFormat10BitYUV;
break;
53 case 2: pixelFormat = bmdFormat10BitRGB;
break;
55 throw DecklinkError(
"Pixel format is not valid (must be 0,1,2).");
60 deckLinkIterator = CreateDeckLinkIteratorInstance();
62 if (!deckLinkIterator)
63 throw DecklinkError(
"This application requires the DeckLink drivers installed.");
66 for (
int device_count = 0; device_count <= device; device_count++)
69 result = deckLinkIterator->Next(&deckLink);
73 if (device_count == device)
77 if (deckLink->QueryInterface(IID_IDeckLinkInput, (
void**)&deckLinkInput) != S_OK)
81 result = deckLinkInput->GetDisplayModeIterator(&displayModeIterator);
83 throw DecklinkError(
"Could not obtain the video output display mode iterator.");
86 if (deckLink->QueryInterface(IID_IDeckLinkOutput, (
void**)&m_deckLinkOutput) != S_OK)
87 throw DecklinkError(
"Failed to create a deckLinkOutput(), used to convert YUV to RGB.");
90 if(!(m_deckLinkConverter = CreateVideoConversionInstance()))
91 throw DecklinkError(
"Failed to create a VideoConversionInstance(), used to convert YUV to RGB.");
95 deckLinkInput->SetCallback(delegate);
99 if (g_videoModeIndex < 0)
103 while (displayModeIterator->Next(&displayMode) == S_OK)
105 if (g_videoModeIndex == displayModeCount)
107 BMDDisplayModeSupport result;
109 foundDisplayMode =
true;
110 displayMode->GetName(&displayModeName);
111 selectedDisplayMode = displayMode->GetDisplayMode();
112 deckLinkInput->DoesSupportVideoMode(selectedDisplayMode, pixelFormat, bmdVideoInputFlagDefault, &result, NULL);
115 displayMode->GetFrameRate(&frameRateDuration, &frameRateScale);
117 if (result == bmdDisplayModeNotSupported)
118 throw DecklinkError(
"The display mode does not support the selected pixel format.");
120 if (inputFlags & bmdVideoInputDualStream3D)
122 if (!(displayMode->GetFlags() & bmdDisplayModeSupports3D))
123 throw DecklinkError(
"The display mode does not support 3D.");
129 displayMode->Release();
132 if (!foundDisplayMode)
133 throw DecklinkError(
"Invalid video mode. No matching ones found.");
136 result = deckLinkInput->EnableVideoInput(selectedDisplayMode, pixelFormat, inputFlags);
138 throw DecklinkError(
"Failed to enable video input. Is another application using the card?");
141 result = deckLinkInput->EnableAudioInput(bmdAudioSampleRate48kHz, g_audioSampleDepth, g_audioChannels);
143 throw DecklinkError(
"Failed to enable audio input. Is another application using the card?");
150 if (displayModeIterator != NULL)
152 displayModeIterator->Release();
153 displayModeIterator = NULL;
156 if (deckLinkInput != NULL)
158 deckLinkInput->Release();
159 deckLinkInput = NULL;
162 if (deckLink != NULL)
168 if (deckLinkIterator != NULL)
169 deckLinkIterator->Release();
179 result = deckLinkInput->StartStreams();
181 throw DecklinkError(
"Failed to start the video and audio streams.");
222 result = deckLinkInput->StopStreams();
225 throw DecklinkError(
"Failed to stop the video and audio streams.");
241 std::shared_ptr<Frame> f = delegate->
GetFrame(requested_frame);
261 root[
"type"] =
"DecklinkReader";
277 catch (
const std::exception& e)
280 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
Header file for DecklinkReader class.
Header file for all Exception classes.
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
Generate JSON string of this object.
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() const
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)