-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.cpp
239 lines (202 loc) · 7.42 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/* ex:set ai shiftwidth=4 inputtab=spaces noautotab: */
/*
Command line preference setting for DeckLink cards (Blackmagic Design).
Copyright (C) 2015 Christoph Willing Brisbane, Australia
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <QCoreApplication>
#include <cstdio>
#include <unistd.h>
#include "DeckLinkAPI.h"
void showHelp(char* appName);
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
char *appName = argv[0];
int ch;
int64_t ports = -1;
int deviceNumber = -1;
int inputPort = -1;
bool displayHelp = false;
bool listAttributes = false;
bool saveConfig = false;
HRESULT result;
IDeckLinkIterator *deckLinkIterator;
IDeckLink *deckLink;
IDeckLinkInput *deckLinkInput = NULL;
IDeckLinkAttributes *deckLinkAttributes = NULL;
IDeckLinkConfiguration *deckLinkConfiguration = NULL;
if ( argc == 1 )
displayHelp = true;
while ((ch = getopt(argc, argv, "?hd:lp:s")) != -1)
{
switch (ch)
{
case 'l':
printf("List Attributes\n");
listAttributes = true;
break;
case 'd':
deviceNumber = atoi(optarg);
printf("Configuring device (board) number %d\n", deviceNumber);
break;
case 'p':
inputPort = atoi(optarg);
printf("Configure Input port to %d\n", inputPort);
break;
case 's':
saveConfig = true;
break;
case '?':
case 'h':
default:
displayHelp = true;
}
}
if (displayHelp )
{
showHelp(appName);
exit(0);
}
// Create an IDeckLinkIterator object to enumerate all DeckLink cards in the system
deckLinkIterator = CreateDeckLinkIteratorInstance();
if (deckLinkIterator == NULL)
{
fprintf(stderr, "A DeckLink iterator could not be created (DeckLink drivers may not be installed).\n");
exit(1);
}
int dnum = 0;
deckLink = NULL;
while (deckLinkIterator->Next(&deckLink) == S_OK)
{
if (0 != dnum)
{
dnum++;
// Release the IDeckLink instance when we've finished with it to prevent leaks
deckLink->Release();
continue;
}
dnum++;
// Query the DeckLink for its configuration interface
result = deckLink->QueryInterface(IID_IDeckLinkInput, (void**)&deckLinkInput);
if (result != S_OK)
{
fprintf(stderr, "Could not obtain the IDeckLinkInput interface - result = %08x\n", result);
exit(result);
}
// Query the DeckLink for its configuration interface
result = deckLinkInput->QueryInterface(IID_IDeckLinkConfiguration, (void**)&deckLinkConfiguration);
if (result != S_OK)
{
fprintf(stderr, "Could not obtain the IDeckLinkConfiguration interface: %08x\n", result);
exit(result);
}
if ( listAttributes )
{
// Query the DeckLink for its attributes interface
result = deckLink->QueryInterface(IID_IDeckLinkAttributes, (void**)&deckLinkAttributes);
if (result != S_OK)
{
fprintf(stderr, "Could not obtain the IDeckLinkAttributes interface - result = %08x\n", result);
exit(result);
}
int itemCount = 0;
result = deckLinkAttributes->GetInt(BMDDeckLinkVideoInputConnections, &ports);
if (result == S_OK)
{
printf("Available Input Port Id's:\n");
if (ports & bmdVideoConnectionSDI)
{
itemCount++;
printf("(%d) SDI", bmdVideoConnectionSDI);
}
if (ports & bmdVideoConnectionHDMI)
{
if (itemCount++ > 0)
printf(", ");
printf("(%d) HDMI", bmdVideoConnectionHDMI);
}
if (ports & bmdVideoConnectionOpticalSDI)
{
if (itemCount++ > 0)
printf(", ");
printf("(%d) Optical SDI", bmdVideoConnectionOpticalSDI);
}
if (ports & bmdVideoConnectionComponent)
{
if (itemCount++ > 0)
printf(", ");
printf("(%d) Component", bmdVideoConnectionComponent);
}
if (ports & bmdVideoConnectionComposite)
{
if (itemCount++ > 0)
printf(", ");
printf("(%d) Composite", bmdVideoConnectionComposite);
}
if (ports & bmdVideoConnectionSVideo)
{
if (itemCount++ > 0)
printf(", ");
printf("(%d) S-Video", bmdVideoConnectionSVideo);
}
}
else
{
fprintf(stderr, "Could not obtain the list of input ports - result = %08x\n", result);
exit(result);
}
printf("\n");
}
/* Current port setting */
result = deckLinkConfiguration->GetInt(bmdDeckLinkConfigVideoInputConnection, &ports);
if (result != S_OK)
{
fprintf(stderr, "Couldn't GetVideoInput \n");
exit(result);
}
result = deckLinkConfiguration->GetInt(bmdDeckLinkConfigVideoInputConnection, &ports);
printf("Current port: %ld\n", ports);
if (inputPort >= 0 )
{
printf("Setting input port to %d\n", inputPort);
if ( (result=deckLinkConfiguration->SetInt(bmdDeckLinkConfigVideoInputConnection, inputPort)) != S_OK )
{
printf("Couldn't set input port to %d\n\n", inputPort);
showHelp(appName);
}
if ( saveConfig )
{
printf("Saving configuration ...\n");
if ( (result=deckLinkConfiguration->WriteConfigurationToPreferences()) == S_OK )
{
printf("New configuration saved\n");
}
else
{
printf("Couldn't save configuration\n");
exit(result);
}
}
}
exit(result);
}
return a.exec();
}
void showHelp(char *appName)
{
printf("Usage:\n");
printf("%s [-l] [-p portId] [-s]\n", appName);
printf("\t-l List current configuration\n");
printf("\t-p portId Set input port to one of those listed by the -l option\n");
printf("\t-s Save configuration across reboots\n");
}