File: decklink-device.cpp

package info (click to toggle)
obs-studio 0.15.4%2Bdfsg1-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 19,628 kB
  • ctags: 35,365
  • sloc: ansic: 123,403; cpp: 28,026; objc: 1,036; makefile: 908; sh: 375; python: 49
file content (120 lines) | stat: -rw-r--r-- 2,609 bytes parent folder | download
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
#include <sstream>

#include "decklink-device.hpp"

#include <util/threading.h>

DeckLinkDevice::DeckLinkDevice(IDeckLink *device_) : device(device_)
{
}

DeckLinkDevice::~DeckLinkDevice(void)
{
	for (DeckLinkDeviceMode *mode : modes)
		delete mode;
}

ULONG DeckLinkDevice::AddRef()
{
	return os_atomic_inc_long(&refCount);
}

ULONG DeckLinkDevice::Release()
{
	long ret = os_atomic_dec_long(&refCount);
	if (ret == 0)
		delete this;
	return ret;
}

bool DeckLinkDevice::Init()
{
	ComPtr<IDeckLinkInput> input;
	if (device->QueryInterface(IID_IDeckLinkInput, (void**)&input) != S_OK)
		return false;

	IDeckLinkDisplayModeIterator *modeIterator;
	if (input->GetDisplayModeIterator(&modeIterator) == S_OK) {
		IDeckLinkDisplayMode *displayMode;
		long long modeId = 1;

		while (modeIterator->Next(&displayMode) == S_OK) {
			if (displayMode == nullptr)
				continue;

			DeckLinkDeviceMode *mode =
				new DeckLinkDeviceMode(displayMode, modeId);
			modes.push_back(mode);
			modeIdMap[modeId] = mode;
			displayMode->Release();
			++modeId;
		}

		modeIterator->Release();
	}

	decklink_string_t decklinkModelName;
	decklink_string_t decklinkDisplayName;

	if (device->GetModelName(&decklinkModelName) != S_OK)
		return false;
	DeckLinkStringToStdString(decklinkModelName, name);

	if (device->GetDisplayName(&decklinkDisplayName) != S_OK)
		return false;
	DeckLinkStringToStdString(decklinkDisplayName, displayName);

	hash = displayName;

	ComPtr<IDeckLinkAttributes> attributes;
	const HRESULT result = device->QueryInterface(IID_IDeckLinkAttributes,
			(void **)&attributes);
	if (result != S_OK)
		return true;

	/* http://forum.blackmagicdesign.com/viewtopic.php?f=12&t=33967
	 * BMDDeckLinkTopologicalID for older devices
	 * BMDDeckLinkPersistentID for newer ones */

	int64_t value;
	if (attributes->GetInt(BMDDeckLinkPersistentID,  &value) != S_OK &&
	    attributes->GetInt(BMDDeckLinkTopologicalID, &value) != S_OK)
		return true;

	std::ostringstream os;
	os << value << "_" << name;
	hash = os.str();
	return true;
}

bool DeckLinkDevice::GetInput(IDeckLinkInput **input)
{
	if (device->QueryInterface(IID_IDeckLinkInput, (void**)input) != S_OK)
		return false;
	return true;
}

DeckLinkDeviceMode *DeckLinkDevice::FindMode(long long id)
{
	return modeIdMap[id];
}

const std::string& DeckLinkDevice::GetDisplayName(void)
{
	return displayName;
}

const std::string& DeckLinkDevice::GetHash(void) const
{
	return hash;
}

const std::vector<DeckLinkDeviceMode *>& DeckLinkDevice::GetModes(void) const
{
	return modes;
}

const std::string& DeckLinkDevice::GetName(void) const
{
	return name;
}