1 /***************************************************************************
2 * Copyright (C) 2007 by Jean-Baptiste Mardelle (jb@kdenlive.org) *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
27 BMInterface::BMInterface()
32 bool BMInterface::getBlackMagicDeviceList(KComboBox *devicelist, KComboBox *modelist)
34 IDeckLinkIterator* deckLinkIterator;
40 // Create an IDeckLinkIterator object to enumerate all DeckLink cards in the system
41 deckLinkIterator = CreateDeckLinkIteratorInstance();
42 if(deckLinkIterator == NULL) {
43 kDebug() << "A DeckLink iterator could not be created. The DeckLink drivers may not be installed.";
47 // Enumerate all cards in this system
48 while(deckLinkIterator->Next(&deckLink) == S_OK) {
49 char * deviceNameString = NULL;
51 // Increment the total number of DeckLink cards found
54 kDebug() << "// FOUND a BM device\n\n+++++++++++++++++++++++++++++++++++++";
56 // *** Print the model name of the DeckLink card
57 result = deckLink->GetModelName((const char **) &deviceNameString);
59 QString deviceName(deviceNameString);
60 free(deviceNameString);
62 IDeckLinkInput* deckLinkInput = NULL;
63 IDeckLinkDisplayModeIterator* displayModeIterator = NULL;
64 IDeckLinkDisplayMode* displayMode = NULL;
67 // Query the DeckLink for its configuration interface
68 result = deckLink->QueryInterface(IID_IDeckLinkInput, (void**)&deckLinkInput);
70 kDebug() << "Could not obtain the IDeckLinkInput interface - result = " << result;
74 // Obtain an IDeckLinkDisplayModeIterator to enumerate the display modes supported on output
75 result = deckLinkInput->GetDisplayModeIterator(&displayModeIterator);
77 kDebug() << "Could not obtain the video input display mode iterator - result = " << result;
80 QStringList availableModes;
81 // List all supported output display modes
82 while(displayModeIterator->Next(&displayMode) == S_OK) {
83 char * displayModeString = NULL;
85 result = displayMode->GetName((const char **) &displayModeString);
90 BMDTimeValue frameRateDuration;
91 BMDTimeScale frameRateScale;
92 //int pixelFormatIndex = 0; // index into the gKnownPixelFormats / gKnownFormatNames arrays
93 //BMDDisplayModeSupport displayModeSupport;
96 // Obtain the display mode's properties
97 modeWidth = displayMode->GetWidth();
98 modeHeight = displayMode->GetHeight();
99 displayMode->GetFrameRate(&frameRateDuration, &frameRateScale);
100 QString description = QString(displayModeString) + " (" + QString::number(modeWidth) + "x" + QString::number(modeHeight) + " - " + QString::number((double)frameRateScale / (double)frameRateDuration) + i18n("fps") + ")";
101 availableModes << description;
102 //modelist->addItem(description);
103 //printf(" %-20s \t %d x %d \t %7g FPS\t", displayModeString, modeWidth, modeHeight, (double)frameRateScale / (double)frameRateDuration);
105 // Print the supported pixel formats for this display mode
106 /*while ((gKnownPixelFormats[pixelFormatIndex] != 0) && (gKnownPixelFormatNames[pixelFormatIndex] != NULL))
108 if ((deckLinkOutput->DoesSupportVideoMode(displayMode->GetDisplayMode(), gKnownPixelFormats[pixelFormatIndex], bmdVideoOutputFlagDefault, &displayModeSupport, NULL) == S_OK)
109 && (displayModeSupport != bmdDisplayModeNotSupported))
111 printf("%s\t", gKnownPixelFormatNames[pixelFormatIndex]);
115 free(displayModeString);
118 // Release the IDeckLinkDisplayMode object to prevent a leak
119 displayMode->Release();
121 devicelist->addItem(deviceName, availableModes);
126 //print_attributes(deckLink);
128 // ** List the video output display modes supported by the card
129 //print_output_modes(deckLink);
131 // ** List the input and output capabilities of the card
132 //print_capabilities(deckLink);
134 // Release the IDeckLink instance when we've finished with it to prevent leaks
138 deckLinkIterator->Release();
139 if(modelist != NULL && devicelist->count() > 0) {
140 QStringList modes = devicelist->itemData(devicelist->currentIndex()).toStringList();
141 modelist->insertItems(0, modes);
147 bool BMInterface::getBlackMagicOutputDeviceList(KComboBox *devicelist)
149 IDeckLinkIterator* deckLinkIterator;
155 // Create an IDeckLinkIterator object to enumerate all DeckLink cards in the system
156 deckLinkIterator = CreateDeckLinkIteratorInstance();
157 if(deckLinkIterator == NULL) {
158 kDebug() << "A DeckLink iterator could not be created. The DeckLink drivers may not be installed.";
162 // Enumerate all cards in this system
163 while(deckLinkIterator->Next(&deckLink) == S_OK) {
164 char * deviceNameString = NULL;
166 // Increment the total number of DeckLink cards found
168 //if (numDevices > 1)
169 kDebug() << "// FOUND a BM device\n\n+++++++++++++++++++++++++++++++++++++";
171 // *** Print the model name of the DeckLink card
172 result = deckLink->GetModelName((const char **) &deviceNameString);
174 QString deviceName(deviceNameString);
175 free(deviceNameString);
177 IDeckLinkOutput* deckLinkOutput = NULL;
178 IDeckLinkDisplayModeIterator* displayModeIterator = NULL;
179 IDeckLinkDisplayMode* displayMode = NULL;
182 // Query the DeckLink for its configuration interface
183 result = deckLink->QueryInterface(IID_IDeckLinkInput, (void**)&deckLinkOutput);
185 kDebug() << "Could not obtain the IDeckLinkInput interface - result = " << result;
189 // Obtain an IDeckLinkDisplayModeIterator to enumerate the display modes supported on output
190 result = deckLinkOutput->GetDisplayModeIterator(&displayModeIterator);
192 kDebug() << "Could not obtain the video input display mode iterator - result = " << result;
195 /*QStringList availableModes;
196 // List all supported output display modes
197 while(displayModeIterator->Next(&displayMode) == S_OK) {
198 char * displayModeString = NULL;
200 result = displayMode->GetName((const char **) &displayModeString);
205 BMDTimeValue frameRateDuration;
206 BMDTimeScale frameRateScale;
207 //int pixelFormatIndex = 0; // index into the gKnownPixelFormats / gKnownFormatNames arrays
208 //BMDDisplayModeSupport displayModeSupport;
211 // Obtain the display mode's properties
212 modeWidth = displayMode->GetWidth();
213 modeHeight = displayMode->GetHeight();
214 displayMode->GetFrameRate(&frameRateDuration, &frameRateScale);
215 QString description = QString(displayModeString) + " (" + QString::number(modeWidth) + "x" + QString::number(modeHeight) + " - " + QString::number((double)frameRateScale / (double)frameRateDuration) + i18n("fps") + ")";
216 description.append(" " + QString::number(modeWidth) + ":" + QString::number(modeHeight) + ":" + QString::number(frameRateScale) + ":" + QString::number(frameRateDuration) + ":" + QString::number(displayMode->GetFieldDominance() == bmdProgressiveFrame));
217 availableModes << description;
218 free(displayModeString);
221 // Release the IDeckLinkDisplayMode object to prevent a leak
222 displayMode->Release();
224 devicelist->addItem(deviceName);
228 // Release the IDeckLink instance when we've finished with it to prevent leaks
232 deckLinkIterator->Release();
237 bool BMInterface::isSupportedProfile(int card, QMap< QString, QString > properties)
239 IDeckLinkIterator* deckLinkIterator;
244 // Create an IDeckLinkIterator object to enumerate all DeckLink cards in the system
245 deckLinkIterator = CreateDeckLinkIteratorInstance();
246 if(deckLinkIterator == NULL) {
247 kDebug() << "A DeckLink iterator could not be created. The DeckLink drivers may not be installed.";
251 while(card >= 0 && deckLinkIterator->Next(&deckLink) == S_OK) {
255 IDeckLinkOutput* deckLinkOutput = NULL;
256 IDeckLinkDisplayModeIterator* displayModeIterator = NULL;
257 IDeckLinkDisplayMode* displayMode = NULL;
259 // Query the DeckLink for its configuration interface
260 result = deckLink->QueryInterface(IID_IDeckLinkInput, (void**)&deckLinkOutput);
262 kDebug() << "Could not obtain the IDeckLinkInput interface - result = " << result;
266 // Obtain an IDeckLinkDisplayModeIterator to enumerate the display modes supported on output
267 result = deckLinkOutput->GetDisplayModeIterator(&displayModeIterator);
269 kDebug() << "Could not obtain the video input display mode iterator - result = " << result;
272 // List all supported output display modes
273 BMDTimeValue frameRateDuration;
274 BMDTimeScale frameRateScale;
276 while(displayModeIterator->Next(&displayMode) == S_OK) {
277 if (displayMode->GetWidth() == properties.value("width").toInt() && displayMode->GetHeight() == properties.value("height").toInt()) {
278 int progressive = displayMode->GetFieldDominance() == bmdProgressiveFrame;
279 if (progressive == properties.value("progressive").toInt()) {
280 displayMode->GetFrameRate(&frameRateDuration, &frameRateScale);
281 if (frameRateScale / properties.value("frame_rate_num").toDouble() * properties.value("frame_rate_den").toDouble() == frameRateDuration) {
287 displayMode->Release();
291 deckLinkIterator->Release();
297 QStringList BMInterface::supportedModes(int card)
299 IDeckLinkIterator* deckLinkIterator;
304 // Create an IDeckLinkIterator object to enumerate all DeckLink cards in the system
305 deckLinkIterator = CreateDeckLinkIteratorInstance();
306 if(deckLinkIterator == NULL) {
307 kDebug() << "A DeckLink iterator could not be created. The DeckLink drivers may not be installed.";
311 while(card >= 0 && deckLinkIterator->Next(&deckLink) == S_OK) {
315 IDeckLinkOutput* deckLinkOutput = NULL;
316 IDeckLinkDisplayModeIterator* displayModeIterator = NULL;
317 IDeckLinkDisplayMode* displayMode = NULL;
319 // Query the DeckLink for its configuration interface
320 result = deckLink->QueryInterface(IID_IDeckLinkInput, (void**)&deckLinkOutput);
322 kDebug() << "Could not obtain the IDeckLinkInput interface - result = " << result;
326 // Obtain an IDeckLinkDisplayModeIterator to enumerate the display modes supported on output
327 result = deckLinkOutput->GetDisplayModeIterator(&displayModeIterator);
329 kDebug() << "Could not obtain the video input display mode iterator - result = " << result;
333 while(displayModeIterator->Next(&displayMode) == S_OK) {
334 char * displayModeString = NULL;
335 result = displayMode->GetName((const char **) &displayModeString);
337 QString description = QString(displayModeString);
338 modes.append(description);
339 free(displayModeString);
341 // Release the IDeckLinkDisplayMode object to prevent a leak
342 displayMode->Release();
346 deckLinkIterator->Release();