File: DecklinkOutput.cpp

package info (click to toggle)
obs-studio 29.0.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 35,920 kB
  • sloc: ansic: 182,921; cpp: 98,959; sh: 1,591; python: 945; makefile: 858; javascript: 19
file content (109 lines) | stat: -rw-r--r-- 2,349 bytes parent folder | download | duplicates (2)
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
#include "DecklinkOutput.hpp"

#include <util/threading.h>

DeckLinkOutput::DeckLinkOutput(obs_output_t *output,
			       DeckLinkDeviceDiscovery *discovery_)
	: DecklinkBase(discovery_), output(output)
{
	discovery->AddCallback(DeckLinkOutput::DevicesChanged, this);
}

DeckLinkOutput::~DeckLinkOutput(void)
{
	discovery->RemoveCallback(DeckLinkOutput::DevicesChanged, this);
	Deactivate();
}

void DeckLinkOutput::DevicesChanged(void *param, DeckLinkDevice *device, bool)
{
	auto *decklink = reinterpret_cast<DeckLinkOutput *>(param);
	std::lock_guard<std::recursive_mutex> lock(decklink->deviceMutex);

	blog(LOG_DEBUG, "%s", device->GetHash().c_str());
}

bool DeckLinkOutput::Activate(DeckLinkDevice *device, long long modeId)
{
	std::lock_guard<std::recursive_mutex> lock(deviceMutex);
	DeckLinkDevice *curDevice = GetDevice();
	const bool same = device == curDevice;
	const bool isActive = instance != nullptr;

	if (same) {
		if (!isActive)
			return false;

		if (instance->GetActiveModeId() == modeId &&
		    instance->GetActivePixelFormat() == pixelFormat &&
		    instance->GetActiveColorSpace() == colorSpace &&
		    instance->GetActiveColorRange() == colorRange &&
		    instance->GetActiveChannelFormat() == channelFormat)
			return false;
	}

	if (isActive)
		instance->StopOutput();

	if (!same)
		instance.Set(new DeckLinkDeviceInstance(this, device));

	if (instance == nullptr)
		return false;

	DeckLinkDeviceMode *mode = GetDevice()->FindOutputMode(modeId);
	if (mode == nullptr) {
		instance = nullptr;
		return false;
	}

	if (!instance->StartOutput(mode)) {
		instance = nullptr;
		return false;
	}

	os_atomic_inc_long(&activateRefs);
	return true;
}

void DeckLinkOutput::Deactivate(void)
{
	std::lock_guard<std::recursive_mutex> lock(deviceMutex);
	if (instance)
		instance->StopOutput();

	instance = nullptr;

	os_atomic_dec_long(&activateRefs);
}

obs_output_t *DeckLinkOutput::GetOutput(void) const
{
	return output;
}

void DeckLinkOutput::DisplayVideoFrame(video_data *frame)
{
	instance->DisplayVideoFrame(frame);
}

void DeckLinkOutput::WriteAudio(audio_data *frames)
{
	instance->WriteAudio(frames);
}

void DeckLinkOutput::SetSize(int width, int height)
{
	this->width = width;
	this->height = height;
}

int DeckLinkOutput::GetWidth()
{
	return width;
}

int DeckLinkOutput::GetHeight()
{
	return height;
}