-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.cpp
115 lines (91 loc) · 3.47 KB
/
client.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
#include <msquic.h>
#include <callbacks.hpp>
#include <cstring>
#include <iostream>
#include <memory>
#include <moqt.hpp>
#include <thread>
#include <subscription_builder.hpp>
#include <opencv2/opencv.hpp>
#include <sanitizer/lsan_interface.h>
#include <signal.h>
void handler(int signum)
{
// __lsan_do_leak_check();
}
using namespace rvn;
const char* Target = "127.0.0.1";
const uint16_t UdpPort = 4567;
const uint64_t IdleTimeoutMs = 0;
QUIC_CREDENTIAL_CONFIG* get_cred_config()
{
QUIC_CREDENTIAL_CONFIG* CredConfig =
(QUIC_CREDENTIAL_CONFIG*)malloc(sizeof(QUIC_CREDENTIAL_CONFIG));
memset(CredConfig, 0, sizeof(QUIC_CREDENTIAL_CONFIG));
CredConfig->Type = QUIC_CREDENTIAL_TYPE_NONE;
CredConfig->Flags =
QUIC_CREDENTIAL_FLAG_CLIENT | QUIC_CREDENTIAL_FLAG_NO_CERTIFICATE_VALIDATION;
return CredConfig;
}
int main()
{
// signal(SIGINT, handler);
std::unique_ptr<MOQTClient> moqtClient = std::make_unique<MOQTClient>();
QUIC_REGISTRATION_CONFIG RegConfig = { "quicsample", QUIC_EXECUTION_PROFILE_LOW_LATENCY };
moqtClient->set_regConfig(&RegConfig);
QUIC_SETTINGS Settings;
std::memset(&Settings, 0, sizeof(Settings));
Settings.IdleTimeoutMs = IdleTimeoutMs;
Settings.IsSet.IdleTimeoutMs = TRUE;
Settings.IsSet.StreamMultiReceiveEnabled = TRUE;
Settings.StreamMultiReceiveEnabled = TRUE;
Settings.PeerUnidiStreamCount = (static_cast<uint16_t>(1) << 16) - 1;
Settings.IsSet.PeerUnidiStreamCount = TRUE;
moqtClient->set_Settings(&Settings, sizeof(Settings));
moqtClient->set_CredConfig(get_cred_config());
QUIC_BUFFER AlpnBuffer = { sizeof("sample") - 1, (uint8_t*)"sample" };
moqtClient->set_AlpnBuffers(&AlpnBuffer);
moqtClient->set_AlpnBufferCount(1);
moqtClient->set_connectionCb(rvn::callbacks::client_connection_callback);
moqtClient->set_listenerCb(rvn::callbacks::client_listener_callback);
moqtClient->set_controlStreamCb(rvn::callbacks::client_control_stream_callback);
moqtClient->set_dataStreamCb(rvn::callbacks::client_data_stream_callback);
moqtClient->start_connection(QUIC_ADDRESS_FAMILY_UNSPEC, Target, UdpPort);
std::thread th(
[&]()
{
using namespace std::chrono_literals;
std::this_thread::sleep_for(5000ms);
SubscriptionBuilder subBuilder;
subBuilder.set_data_range<SubscriptionBuilder::Filter::LatestGroup>(std::size_t(0));
subBuilder.set_track_alias(0);
subBuilder.set_track_namespace("default");
subBuilder.set_track_name("default");
subBuilder.set_subscriber_priority(0);
subBuilder.set_group_order(0);
auto subMessage = subBuilder.build();
auto queueIter = moqtClient->subscribe(std::move(subMessage));
while (true)
{
if (!queueIter->empty())
{
std::cout << "Queue Size: " << queueIter->size() << std::endl;
std::cout << queueIter->size() << std::endl;
std::string objectPayloadStr = queueIter->front();
queueIter->pop();
cv::Mat frame;
std::vector<uchar> buffer(objectPayloadStr.begin(),
objectPayloadStr.end());
frame = cv::imdecode(buffer, cv::IMREAD_COLOR);
cv::imshow("Live Video Feed", frame);
if (cv::waitKey(30) == 'q')
break;
}
}
});
{
char c;
while (1)
std::cin >> c;
}
}