-
Notifications
You must be signed in to change notification settings - Fork 10
/
SubDeviceUtil.cpp
125 lines (98 loc) · 4.17 KB
/
SubDeviceUtil.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
#include "SubDeviceUtil.h"
#include "RefReleaser.hpp"
#include "util.h"
#define LLOG(x) LOG(x) << "SubDeviceUtil: "
bool SubDeviceUtil::IsSubDevice(IDeckLink *deckLink)
{
LLOG(INFO) << __PRETTY_FUNCTION__;
IDeckLink *parentDevice = QueryParentDevice(deckLink);
RefReleaser<IDeckLink> parentDeviceReleaser(&parentDevice);
bool isSubDevice = parentDevice != nullptr;
LOG(DEBUG1) << "isSubDevice = " << isSubDevice;
return isSubDevice;
}
bool SubDeviceUtil::SupportsDuplexMode(IDeckLink *deckLink)
{
LLOG(INFO) << __PRETTY_FUNCTION__;
HRESULT result;
IDeckLinkAttributes* deckLinkAttributes = nullptr;
RefReleaser<IDeckLinkAttributes> deckLinkAttributesReleaser(&deckLinkAttributes);
LLOG(DEBUG1) << "querying IID_IDeckLinkAttributes Interface";
result = deckLink->QueryInterface(IID_IDeckLinkAttributes, (void **)&deckLinkAttributes);
throwIfNotOk(result, "Could not obtain the IDeckLinkAttributes interface");
LLOG(DEBUG1) << "querying BMDDeckLinkSupportsDuplexModeConfiguration flag";
bool supportsDuplexModeConfiguration;
result = deckLinkAttributes->GetFlag(BMDDeckLinkSupportsDuplexModeConfiguration, &supportsDuplexModeConfiguration);
if(result != S_OK) {
LLOG(DEBUG1) << "failed to query BMDDeckLinkSupportsDuplexModeConfiguration flag";
return false;
}
return supportsDuplexModeConfiguration;
}
IDeckLink *SubDeviceUtil::QueryParentDevice(IDeckLink *deckLink)
{
LLOG(INFO) << __PRETTY_FUNCTION__;
HRESULT result;
IDeckLinkAttributes* deckLinkAttributes = nullptr;
RefReleaser<IDeckLinkAttributes> deckLinkAttributesReleaser(&deckLinkAttributes);
LLOG(DEBUG1) << "querying IID_IDeckLinkAttributes Interface";
result = deckLink->QueryInterface(IID_IDeckLinkAttributes, (void **)&deckLinkAttributes);
throwIfNotOk(result, "Could not obtain the IDeckLinkAttributes interface");
LLOG(DEBUG1) << "querying BMDDeckLinkPairedDevicePersistentID attribute";
int64_t pairedDeviceId;
result = deckLinkAttributes->GetInt(BMDDeckLinkPairedDevicePersistentID, &pairedDeviceId);
if(result != S_OK)
{
LLOG(DEBUG1) << "failed to query BMDDeckLinkPairedDevicePersistentID attribute, this is no SubDevice";
return nullptr;
}
LLOG(DEBUG1) << "found paired device-id 0x" << std::hex << pairedDeviceId << ", looking device up";
IDeckLink *pairedDevice = findDeckLinkInterfaceByPersistentId(pairedDeviceId);
RefReleaser<IDeckLink> pairedDeviceReleaser(&pairedDevice);
throwIfNull(pairedDevice, "did not find device for pairedDeviceId reported by Decklink-Device");
if(!SupportsDuplexMode(pairedDevice))
{
LLOG(DEBUG) << "paired Device does not support Duplex-Mode and is this no Parent-Device";
return nullptr;
}
LLOG(DEBUG) << "found matching Parent-Device";
pairedDevice->AddRef();
return pairedDevice;
}
IDeckLink *SubDeviceUtil::findDeckLinkInterfaceByPersistentId(int64_t pairedDeviceId)
{
LLOG(INFO) << __PRETTY_FUNCTION__;
HRESULT result;
IDeckLinkIterator *deckLinkIterator = CreateDeckLinkIteratorInstance();
RefReleaser<IDeckLinkIterator> iterReleaser(&deckLinkIterator);
throwIfNull(deckLinkIterator,
"A DeckLink iterator could not be created.");
unsigned int i = 0;
IDeckLink *deckLink = nullptr;
while (deckLinkIterator->Next(&deckLink) == S_OK) {
i++;
LLOG(DEBUG) << "probing Device " << i;
RefReleaser<IDeckLink> deckLinkReleaser(&deckLink);
IDeckLinkAttributes* deckLinkAttributes = nullptr;
RefReleaser<IDeckLinkAttributes> deckLinkAttributesReleaser(&deckLinkAttributes);
LLOG(DEBUG1) << "querying IID_IDeckLinkAttributes Interface";
result = deckLink->QueryInterface(IID_IDeckLinkAttributes, (void **)&deckLinkAttributes);
throwIfNotOk(result, "Could not obtain the IDeckLinkAttributes interface");
LLOG(DEBUG1) << "querying BMDDeckLinkPersistentID attribute";
int64_t persistent_id;
result = deckLinkAttributes->GetInt(BMDDeckLinkPersistentID, &persistent_id);
if(result != S_OK) {
LLOG(DEBUG1) << "could not query the BMDDeckLinkPersistentID attribute, continuing with next device";
continue;
}
if(pairedDeviceId == persistent_id)
{
LLOG(DEBUG) << "found matching device";
deckLink->AddRef();
return deckLink;
}
LLOG(DEBUG) << "not the device we are looking for";
}
LLOG(DEBUG) << "found no matching device";
return NULL;
}