-
-
Notifications
You must be signed in to change notification settings - Fork 492
/
Copy pathVoipScreenCapture.cpp
117 lines (102 loc) · 2.94 KB
/
VoipScreenCapture.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
#include "pch.h"
#include "VoipScreenCapture.h"
#if __has_include("VoipScreenCapture.g.cpp")
#include "VoipScreenCapture.g.cpp"
#endif
#include "VoipVideoOutputSink.h"
#include "StaticThreads.h"
#include "platform/uwp/UwpContext.h"
namespace winrt::Telegram::Native::Calls::implementation
{
VoipScreenCapture::VoipScreenCapture(GraphicsCaptureItem item)
{
m_impl = tgcalls::VideoCaptureInterface::Create(
tgcalls::StaticThreads::getThreads(),
"GraphicsCaptureItem", true,
std::make_shared<tgcalls::UwpContext>(item));
m_impl->setOnFatalError([this] {
m_failed = true;
m_fatalErrorOccurred(*this, nullptr);
});
m_impl->setOnPause([this](bool paused) {
m_paused(*this, paused);
});
}
void VoipScreenCapture::Stop()
{
m_impl.reset();
m_impl = nullptr;
}
void VoipScreenCapture::SwitchToDevice(hstring deviceId)
{
if (m_impl)
{
m_impl->switchToDevice(winrt::to_string(deviceId), false);
}
}
void VoipScreenCapture::SetState(VoipVideoState state)
{
if (m_impl)
{
m_impl->setState((tgcalls::VideoState)state);
}
}
void VoipScreenCapture::SetPreferredAspectRatio(float aspectRatio)
{
if (m_impl)
{
m_impl->setPreferredAspectRatio(aspectRatio);
}
}
void VoipScreenCapture::SetOutput(winrt::Telegram::Native::Calls::VoipVideoOutputSink sink)
{
if (m_impl)
{
if (sink != nullptr)
{
auto implementation = winrt::get_self<VoipVideoOutputSink>(sink);
m_impl->setOutput(implementation->Sink());
}
else
{
m_impl->setOutput(nullptr);
}
}
}
winrt::event_token VoipScreenCapture::FatalErrorOccurred(Windows::Foundation::TypedEventHandler<
winrt::Telegram::Native::Calls::VoipCaptureBase,
winrt::Windows::Foundation::IInspectable> const& value)
{
auto token = m_fatalErrorOccurred.add(value);
if (m_failed)
{
m_fatalErrorOccurred(*this, nullptr);
}
return token;
}
void VoipScreenCapture::FatalErrorOccurred(winrt::event_token const& token)
{
m_fatalErrorOccurred.remove(token);
}
winrt::event_token VoipScreenCapture::Paused(Windows::Foundation::TypedEventHandler<
winrt::Telegram::Native::Calls::VoipScreenCapture,
bool> const& value)
{
return m_paused.add(value);
}
void VoipScreenCapture::Paused(winrt::event_token const& token)
{
m_paused.remove(token);
}
bool VoipScreenCapture::IsSupported()
{
try
{
return GraphicsCaptureSession::IsSupported();
}
catch (winrt::hresult_error const& ex)
{
return false;
}
}
}