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;
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();
141 if(modelist != NULL && devicelist->count() > 0) {
142 QStringList modes = devicelist->itemData(devicelist->currentIndex()).toStringList();
143 modelist->insertItems(0, modes);
149 bool BMInterface::getBlackMagicOutputDeviceList(KComboBox *devicelist)
151 IDeckLinkIterator* deckLinkIterator;
157 // Create an IDeckLinkIterator object to enumerate all DeckLink cards in the system
158 deckLinkIterator = CreateDeckLinkIteratorInstance();
159 if(deckLinkIterator == NULL) {
160 kDebug() << "A DeckLink iterator could not be created. The DeckLink drivers may not be installed.";
164 // Enumerate all cards in this system
165 while(deckLinkIterator->Next(&deckLink) == S_OK) {
166 char * deviceNameString = NULL;
168 kDebug() << "// FOUND a BM device\n\n+++++++++++++++++++++++++++++++++++++";
170 // *** Print the model name of the DeckLink card
171 result = deckLink->GetModelName((const char **) &deviceNameString);
173 QString deviceName(deviceNameString);
174 free(deviceNameString);
176 IDeckLinkOutput* deckLinkOutput = NULL;
177 IDeckLinkDisplayModeIterator* displayModeIterator = NULL;
178 //IDeckLinkDisplayMode* displayMode = NULL;
181 // Query the DeckLink for its configuration interface
182 result = deckLink->QueryInterface(IID_IDeckLinkInput, (void**)&deckLinkOutput);
184 kDebug() << "Could not obtain the IDeckLinkInput interface - result = " << result;
188 // Obtain an IDeckLinkDisplayModeIterator to enumerate the display modes supported on output
189 result = deckLinkOutput->GetDisplayModeIterator(&displayModeIterator);
191 kDebug() << "Could not obtain the video input display mode iterator - result = " << result;
194 /*QStringList availableModes;
195 // List all supported output display modes
196 while(displayModeIterator->Next(&displayMode) == S_OK) {
197 char * displayModeString = NULL;
199 result = displayMode->GetName((const char **) &displayModeString);
204 BMDTimeValue frameRateDuration;
205 BMDTimeScale frameRateScale;
206 //int pixelFormatIndex = 0; // index into the gKnownPixelFormats / gKnownFormatNames arrays
207 //BMDDisplayModeSupport displayModeSupport;
210 // Obtain the display mode's properties
211 modeWidth = displayMode->GetWidth();
212 modeHeight = displayMode->GetHeight();
213 displayMode->GetFrameRate(&frameRateDuration, &frameRateScale);
214 QString description = QString(displayModeString) + " (" + QString::number(modeWidth) + "x" + QString::number(modeHeight) + " - " + QString::number((double)frameRateScale / (double)frameRateDuration) + i18n("fps") + ")";
215 description.append(" " + QString::number(modeWidth) + ":" + QString::number(modeHeight) + ":" + QString::number(frameRateScale) + ":" + QString::number(frameRateDuration) + ":" + QString::number(displayMode->GetFieldDominance() == bmdProgressiveFrame));
216 availableModes << description;
217 free(displayModeString);
220 // Release the IDeckLinkDisplayMode object to prevent a leak
221 displayMode->Release();
223 devicelist->addItem(deviceName, numDevices++);
227 // Release the IDeckLink instance when we've finished with it to prevent leaks
231 deckLinkIterator->Release();
236 bool BMInterface::isSupportedProfile(int card, QMap< QString, QString > properties)
238 IDeckLinkIterator* deckLinkIterator;
243 // Create an IDeckLinkIterator object to enumerate all DeckLink cards in the system
244 deckLinkIterator = CreateDeckLinkIteratorInstance();
245 if(deckLinkIterator == NULL) {
246 kDebug() << "A DeckLink iterator could not be created. The DeckLink drivers may not be installed.";
250 while(card >= 0 && deckLinkIterator->Next(&deckLink) == S_OK) {
254 IDeckLinkOutput* deckLinkOutput = NULL;
255 IDeckLinkDisplayModeIterator* displayModeIterator = NULL;
256 IDeckLinkDisplayMode* displayMode = NULL;
258 // Query the DeckLink for its configuration interface
259 result = deckLink->QueryInterface(IID_IDeckLinkInput, (void**)&deckLinkOutput);
261 kDebug() << "Could not obtain the IDeckLinkInput interface - result = " << result;
265 // Obtain an IDeckLinkDisplayModeIterator to enumerate the display modes supported on output
266 result = deckLinkOutput->GetDisplayModeIterator(&displayModeIterator);
268 kDebug() << "Could not obtain the video input display mode iterator - result = " << result;
271 // List all supported output display modes
272 BMDTimeValue frameRateDuration;
273 BMDTimeScale frameRateScale;
275 while(displayModeIterator->Next(&displayMode) == S_OK) {
276 if (displayMode->GetWidth() == properties.value("width").toInt() && displayMode->GetHeight() == properties.value("height").toInt()) {
277 int progressive = displayMode->GetFieldDominance() == bmdProgressiveFrame;
278 if (progressive == properties.value("progressive").toInt()) {
279 displayMode->GetFrameRate(&frameRateDuration, &frameRateScale);
280 if (frameRateScale / properties.value("frame_rate_num").toDouble() * properties.value("frame_rate_den").toDouble() == frameRateDuration) {
286 displayMode->Release();
290 deckLinkIterator->Release();
296 QStringList BMInterface::supportedModes(int card)
298 IDeckLinkIterator* deckLinkIterator;
303 // Create an IDeckLinkIterator object to enumerate all DeckLink cards in the system
304 deckLinkIterator = CreateDeckLinkIteratorInstance();
305 if(deckLinkIterator == NULL) {
306 kDebug() << "A DeckLink iterator could not be created. The DeckLink drivers may not be installed.";
310 while(card >= 0 && deckLinkIterator->Next(&deckLink) == S_OK) {
314 IDeckLinkOutput* deckLinkOutput = NULL;
315 IDeckLinkDisplayModeIterator* displayModeIterator = NULL;
316 IDeckLinkDisplayMode* displayMode = NULL;
318 // Query the DeckLink for its configuration interface
319 result = deckLink->QueryInterface(IID_IDeckLinkInput, (void**)&deckLinkOutput);
321 kDebug() << "Could not obtain the IDeckLinkInput interface - result = " << result;
325 // Obtain an IDeckLinkDisplayModeIterator to enumerate the display modes supported on output
326 result = deckLinkOutput->GetDisplayModeIterator(&displayModeIterator);
328 kDebug() << "Could not obtain the video input display mode iterator - result = " << result;
332 while(displayModeIterator->Next(&displayMode) == S_OK) {
333 char * displayModeString = NULL;
334 result = displayMode->GetName((const char **) &displayModeString);
336 QString description = QString(displayModeString);
337 modes.append(description);
338 free(displayModeString);
340 // Release the IDeckLinkDisplayMode object to prevent a leak
341 displayMode->Release();
345 deckLinkIterator->Release();