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)
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;
52 kDebug() << "// FOUND a BM device\n\n+++++++++++++++++++++++++++++++++++++";
54 // *** Print the model name of the DeckLink card
55 result = deckLink->GetModelName((const char **) &deviceNameString);
57 QString deviceName(deviceNameString);
58 free(deviceNameString);
60 IDeckLinkInput* deckLinkInput = NULL;
61 IDeckLinkDisplayModeIterator* displayModeIterator = NULL;
62 IDeckLinkDisplayMode* displayMode = NULL;
65 // Query the DeckLink for its configuration interface
66 result = deckLink->QueryInterface(IID_IDeckLinkInput, (void**)&deckLinkInput);
68 kDebug() << "Could not obtain the IDeckLinkInput interface - result = " << result;
72 // Obtain an IDeckLinkDisplayModeIterator to enumerate the display modes supported on output
73 result = deckLinkInput->GetDisplayModeIterator(&displayModeIterator);
75 kDebug() << "Could not obtain the video input display mode iterator - result = " << result;
78 QStringList availableModes;
79 // List all supported output display modes
80 while(displayModeIterator->Next(&displayMode) == S_OK) {
81 char * displayModeString = NULL;
83 result = displayMode->GetName((const char **) &displayModeString);
88 BMDTimeValue frameRateDuration;
89 BMDTimeScale frameRateScale;
90 //int pixelFormatIndex = 0; // index into the gKnownPixelFormats / gKnownFormatNames arrays
91 //BMDDisplayModeSupport displayModeSupport;
94 // Obtain the display mode's properties
95 modeWidth = displayMode->GetWidth();
96 modeHeight = displayMode->GetHeight();
97 displayMode->GetFrameRate(&frameRateDuration, &frameRateScale);
98 QString description = QString(displayModeString) + " (" + QString::number(modeWidth) + "x" + QString::number(modeHeight) + " - " + QString::number((double)frameRateScale / (double)frameRateDuration) + i18n("fps") + ")";
99 availableModes << description;
100 //modelist->addItem(description);
101 //printf(" %-20s \t %d x %d \t %7g FPS\t", displayModeString, modeWidth, modeHeight, (double)frameRateScale / (double)frameRateDuration);
103 // Print the supported pixel formats for this display mode
104 /*while ((gKnownPixelFormats[pixelFormatIndex] != 0) && (gKnownPixelFormatNames[pixelFormatIndex] != NULL))
106 if ((deckLinkOutput->DoesSupportVideoMode(displayMode->GetDisplayMode(), gKnownPixelFormats[pixelFormatIndex], bmdVideoOutputFlagDefault, &displayModeSupport, NULL) == S_OK)
107 && (displayModeSupport != bmdDisplayModeNotSupported))
109 printf("%s\t", gKnownPixelFormatNames[pixelFormatIndex]);
113 free(displayModeString);
116 // Release the IDeckLinkDisplayMode object to prevent a leak
117 displayMode->Release();
119 devicelist->addItem(deviceName, availableModes);
120 devicelist->setItemData(devicelist->count() - 1, numDevices, Qt::UserRole + 1);
125 //print_attributes(deckLink);
127 // ** List the video output display modes supported by the card
128 //print_output_modes(deckLink);
130 // ** List the input and output capabilities of the card
131 //print_capabilities(deckLink);
133 // Release the IDeckLink instance when we've finished with it to prevent leaks
136 // Increment the total number of DeckLink cards found
140 deckLinkIterator->Release();
145 bool BMInterface::getBlackMagicOutputDeviceList(KComboBox *devicelist)
147 IDeckLinkIterator* deckLinkIterator;
153 // Create an IDeckLinkIterator object to enumerate all DeckLink cards in the system
154 deckLinkIterator = CreateDeckLinkIteratorInstance();
155 if(deckLinkIterator == NULL) {
156 kDebug() << "A DeckLink iterator could not be created. The DeckLink drivers may not be installed.";
160 // Enumerate all cards in this system
161 while(deckLinkIterator->Next(&deckLink) == S_OK) {
162 char * deviceNameString = NULL;
164 kDebug() << "// FOUND a BM device\n\n+++++++++++++++++++++++++++++++++++++";
166 // *** Print the model name of the DeckLink card
167 result = deckLink->GetModelName((const char **) &deviceNameString);
169 QString deviceName(deviceNameString);
170 free(deviceNameString);
172 IDeckLinkOutput* deckLinkOutput = NULL;
173 IDeckLinkDisplayModeIterator* displayModeIterator = NULL;
174 //IDeckLinkDisplayMode* displayMode = NULL;
177 // Query the DeckLink for its configuration interface
178 result = deckLink->QueryInterface(IID_IDeckLinkInput, (void**)&deckLinkOutput);
180 kDebug() << "Could not obtain the IDeckLinkInput interface - result = " << result;
184 // Obtain an IDeckLinkDisplayModeIterator to enumerate the display modes supported on output
185 result = deckLinkOutput->GetDisplayModeIterator(&displayModeIterator);
187 kDebug() << "Could not obtain the video input display mode iterator - result = " << result;
190 /*QStringList availableModes;
191 // List all supported output display modes
192 while(displayModeIterator->Next(&displayMode) == S_OK) {
193 char * displayModeString = NULL;
195 result = displayMode->GetName((const char **) &displayModeString);
200 BMDTimeValue frameRateDuration;
201 BMDTimeScale frameRateScale;
202 //int pixelFormatIndex = 0; // index into the gKnownPixelFormats / gKnownFormatNames arrays
203 //BMDDisplayModeSupport displayModeSupport;
206 // Obtain the display mode's properties
207 modeWidth = displayMode->GetWidth();
208 modeHeight = displayMode->GetHeight();
209 displayMode->GetFrameRate(&frameRateDuration, &frameRateScale);
210 QString description = QString(displayModeString) + " (" + QString::number(modeWidth) + "x" + QString::number(modeHeight) + " - " + QString::number((double)frameRateScale / (double)frameRateDuration) + i18n("fps") + ")";
211 description.append(" " + QString::number(modeWidth) + ":" + QString::number(modeHeight) + ":" + QString::number(frameRateScale) + ":" + QString::number(frameRateDuration) + ":" + QString::number(displayMode->GetFieldDominance() == bmdProgressiveFrame));
212 availableModes << description;
213 free(displayModeString);
216 // Release the IDeckLinkDisplayMode object to prevent a leak
217 displayMode->Release();
219 devicelist->addItem(deviceName, numDevices++);
223 // Release the IDeckLink instance when we've finished with it to prevent leaks
227 deckLinkIterator->Release();
232 bool BMInterface::isSupportedProfile(int card, QMap< QString, QString > properties)
234 IDeckLinkIterator* deckLinkIterator;
239 // Create an IDeckLinkIterator object to enumerate all DeckLink cards in the system
240 deckLinkIterator = CreateDeckLinkIteratorInstance();
241 if(deckLinkIterator == NULL) {
242 kDebug() << "A DeckLink iterator could not be created. The DeckLink drivers may not be installed.";
246 while(card >= 0 && deckLinkIterator->Next(&deckLink) == S_OK) {
250 IDeckLinkOutput* deckLinkOutput = NULL;
251 IDeckLinkDisplayModeIterator* displayModeIterator = NULL;
252 IDeckLinkDisplayMode* displayMode = NULL;
254 // Query the DeckLink for its configuration interface
255 result = deckLink->QueryInterface(IID_IDeckLinkInput, (void**)&deckLinkOutput);
257 kDebug() << "Could not obtain the IDeckLinkInput interface - result = " << result;
261 // Obtain an IDeckLinkDisplayModeIterator to enumerate the display modes supported on output
262 result = deckLinkOutput->GetDisplayModeIterator(&displayModeIterator);
264 kDebug() << "Could not obtain the video input display mode iterator - result = " << result;
267 // List all supported output display modes
268 BMDTimeValue frameRateDuration;
269 BMDTimeScale frameRateScale;
271 while(displayModeIterator->Next(&displayMode) == S_OK) {
272 if (displayMode->GetWidth() == properties.value("width").toInt() && displayMode->GetHeight() == properties.value("height").toInt()) {
273 int progressive = displayMode->GetFieldDominance() == bmdProgressiveFrame;
274 if (progressive == properties.value("progressive").toInt()) {
275 displayMode->GetFrameRate(&frameRateDuration, &frameRateScale);
276 if (frameRateScale / properties.value("frame_rate_num").toDouble() * properties.value("frame_rate_den").toDouble() == frameRateDuration) {
282 displayMode->Release();
286 deckLinkIterator->Release();
292 QStringList BMInterface::supportedModes(int card)
294 IDeckLinkIterator* deckLinkIterator;
299 // Create an IDeckLinkIterator object to enumerate all DeckLink cards in the system
300 deckLinkIterator = CreateDeckLinkIteratorInstance();
301 if(deckLinkIterator == NULL) {
302 kDebug() << "A DeckLink iterator could not be created. The DeckLink drivers may not be installed.";
306 while(card >= 0 && deckLinkIterator->Next(&deckLink) == S_OK) {
310 IDeckLinkOutput* deckLinkOutput = NULL;
311 IDeckLinkDisplayModeIterator* displayModeIterator = NULL;
312 IDeckLinkDisplayMode* displayMode = NULL;
314 // Query the DeckLink for its configuration interface
315 result = deckLink->QueryInterface(IID_IDeckLinkInput, (void**)&deckLinkOutput);
317 kDebug() << "Could not obtain the IDeckLinkInput interface - result = " << result;
321 // Obtain an IDeckLinkDisplayModeIterator to enumerate the display modes supported on output
322 result = deckLinkOutput->GetDisplayModeIterator(&displayModeIterator);
324 kDebug() << "Could not obtain the video input display mode iterator - result = " << result;
328 while(displayModeIterator->Next(&displayMode) == S_OK) {
329 char * displayModeString = NULL;
330 result = displayMode->GetName((const char **) &displayModeString);
332 QString description = QString(displayModeString);
333 modes.append(description);
334 free(displayModeString);
336 // Release the IDeckLinkDisplayMode object to prevent a leak
337 displayMode->Release();
341 deckLinkIterator->Release();