19 : device(device), is_open(false), g_videoModeIndex(video_mode), g_audioChannels(channels), g_audioSampleDepth(sample_depth)
23 selectedDisplayMode = bmdModeNTSC;
24 pixelFormat = bmdFormat8BitYUV;
27 foundDisplayMode =
false;
28 pthread_mutex_init(&sleepMutex, NULL);
29 pthread_cond_init(&sleepCond, NULL);
33 case 0: pixelFormat = bmdFormat8BitYUV;
break;
34 case 1: pixelFormat = bmdFormat10BitYUV;
break;
35 case 2: pixelFormat = bmdFormat10BitRGB;
break;
37 throw DecklinkError(
"Pixel format is not valid (must be 0,1,2).");
42 deckLinkIterator = CreateDeckLinkIteratorInstance();
44 if (!deckLinkIterator)
45 throw DecklinkError(
"This application requires the DeckLink drivers installed.");
48 for (
int device_count = 0; device_count <= device; device_count++)
51 result = deckLinkIterator->Next(&deckLink);
55 if (device_count == device)
59 if (deckLink->QueryInterface(IID_IDeckLinkInput, (
void**)&deckLinkInput) != S_OK)
63 result = deckLinkInput->GetDisplayModeIterator(&displayModeIterator);
65 throw DecklinkError(
"Could not obtain the video output display mode iterator.");
68 if (deckLink->QueryInterface(IID_IDeckLinkOutput, (
void**)&m_deckLinkOutput) != S_OK)
69 throw DecklinkError(
"Failed to create a deckLinkOutput(), used to convert YUV to RGB.");
72 if(!(m_deckLinkConverter = CreateVideoConversionInstance()))
73 throw DecklinkError(
"Failed to create a VideoConversionInstance(), used to convert YUV to RGB.");
77 deckLinkInput->SetCallback(delegate);
81 if (g_videoModeIndex < 0)
85 while (displayModeIterator->Next(&displayMode) == S_OK)
87 if (g_videoModeIndex == displayModeCount)
89 BMDDisplayModeSupport result;
91 foundDisplayMode =
true;
92 displayMode->GetName(&displayModeName);
93 selectedDisplayMode = displayMode->GetDisplayMode();
94 deckLinkInput->DoesSupportVideoMode(selectedDisplayMode, pixelFormat, bmdVideoInputFlagDefault, &result, NULL);
97 displayMode->GetFrameRate(&frameRateDuration, &frameRateScale);
99 if (result == bmdDisplayModeNotSupported)
100 throw DecklinkError(
"The display mode does not support the selected pixel format.");
102 if (inputFlags & bmdVideoInputDualStream3D)
104 if (!(displayMode->GetFlags() & bmdDisplayModeSupports3D))
105 throw DecklinkError(
"The display mode does not support 3D.");
111 displayMode->Release();
114 if (!foundDisplayMode)
115 throw DecklinkError(
"Invalid video mode. No matching ones found.");
118 result = deckLinkInput->EnableVideoInput(selectedDisplayMode, pixelFormat, inputFlags);
120 throw DecklinkError(
"Failed to enable video input. Is another application using the card?");
123 result = deckLinkInput->EnableAudioInput(bmdAudioSampleRate48kHz, g_audioSampleDepth, g_audioChannels);
125 throw DecklinkError(
"Failed to enable audio input. Is another application using the card?");
132 if (displayModeIterator != NULL)
134 displayModeIterator->Release();
135 displayModeIterator = NULL;
138 if (deckLinkInput != NULL)
140 deckLinkInput->Release();
141 deckLinkInput = NULL;
144 if (deckLink != NULL)
150 if (deckLinkIterator != NULL)
151 deckLinkIterator->Release();
161 result = deckLinkInput->StartStreams();
163 throw DecklinkError(
"Failed to start the video and audio streams.");
204 result = deckLinkInput->StopStreams();
207 throw DecklinkError(
"Failed to stop the video and audio streams.");
223 std::shared_ptr<Frame> f = delegate->
GetFrame(requested_frame);
243 root[
"type"] =
"DecklinkReader";
259 catch (
const std::exception& e)
262 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
int num
Numerator for the fraction.
void SetJsonValue(const Json::Value root)
Load Json::Value 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()
double ToDouble() const
Return this fraction as a double (i.e. 1/2 = 0.5)
const Json::Value stringToJson(const std::string value)
bool has_video
Determines if this file has a video stream.
std::string Json() const override
Generate JSON string of this object.
int64_t file_size
Size of file (in bytes)
Header file for all Exception classes.
bool has_audio
Determines if this file has an audio stream.
virtual Json::Value JsonValue() const =0
Generate Json::Value for this object.
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)
void SetJson(const std::string value)
Load JSON string into this object.
openshot::Fraction video_timebase
The video timebase determines how long each frame stays on the screen.
This class represents a fraction.
DecklinkReader(int device, int video_mode, int pixel_format, int channels, int sample_depth)
virtual void SetJsonValue(const Json::Value root)=0
Load Json::Value into this object.
Header file for DecklinkReader class.
Json::Value JsonValue() const
Generate Json::Value for this object.
openshot::ReaderInfo info
Information about the current media file.
std::string vcodec
The name of the video codec used to encode / decode the video stream.
This namespace is the default namespace for all code in the openshot library.
Exception for invalid JSON.
openshot::Fraction display_ratio
The ratio of width to height of the video stream (i.e. 640x480 has a ratio of 4/3) ...
openshot::Fraction pixel_ratio
The pixel ratio of the video stream as a fraction (i.e. some pixels are not square) ...
int den
Denominator for the fraction.
openshot::Fraction fps
Frames per second, as a fraction (i.e. 24/1 = 24 fps)