-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvpcc_receiver.cc
141 lines (112 loc) · 4.44 KB
/
vpcc_receiver.cc
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include "uvgrtp_util.hh"
#include "v3c_util.hh"
#include "../util/util.hh"
#include <uvgrtp/lib.hh>
#include <uvgrtp/clock.hh>
#include <cstring>
#include <algorithm>
#include <string>
#include <iostream>
#include <vector>
#include <atomic>
#include <chrono>
int TIMEOUT = 1000;
bool srtp_enabled = false;
// encryption parameters
enum Key_length{SRTP_128 = 128, SRTP_196 = 196, SRTP_256 = 256};
constexpr Key_length KEY_S = SRTP_256;
constexpr int KEY_SIZE_BYTES = KEY_S/8;
constexpr int SALT_S = 112;
constexpr int SALT_SIZE_BYTES = SALT_S/8;
struct stream_results { // Save stats of each stream
size_t packets_received = 0;
size_t bytes_received = 0;
long long start = 0;
long long last = 0;
};
bool frame_received = true;
void hook(void* arg, uvg_rtp::frame::rtp_frame* frame);
int main(int argc, char** argv)
{
if (argc != 9) {
fprintf(stderr, "usage: ./%s <result file> <local address> <local port> <remote address> <remote port> \
<number of threads> <format> <srtp>\n", __FILE__);
return EXIT_FAILURE;
}
std::string result_filename = argv[1];
std::string local_address = argv[2];
int local_port = atoi(argv[3]);
std::string remote_address = argv[4];
int remote_port = atoi(argv[5]);
//int nthreads = atoi(argv[6]);
//bool vvc_enabled = get_vvc_state(argv[7]);
//bool atlas_enabled = get_atlas_state(argv[7]);
srtp_enabled = get_srtp_state(argv[8]);
std::cout << "Starting uvgRTP V-PCC receiver tests. " << local_address << ":" << local_port
<< "<-" << remote_address << ":" << remote_port << std::endl;
uvgrtp::context rtp_ctx;
uvgrtp::session* sess = rtp_ctx.create_session(remote_address, local_address);
int flags = 0;
if (srtp_enabled) {
flags = RCE_SRTP | RCE_SRTP_KMNGMNT_USER | RCE_SRTP_KEYSIZE_256;
}
v3c_streams streams = init_v3c_streams(sess, local_port, remote_port, flags, true);
if (srtp_enabled) {
std::cout << "SRTP enabled" << std::endl;
uint8_t key[KEY_SIZE_BYTES] = { 0 };
uint8_t salt[SALT_SIZE_BYTES] = { 0 };
// initialize SRTP key and salt with dummy values
for (int i = 0; i < KEY_SIZE_BYTES; ++i)
key[i] = i;
for (int i = 0; i < SALT_SIZE_BYTES; ++i)
salt[i] = i * 2;
streams.ad->add_srtp_ctx(key, salt);
streams.ovd->add_srtp_ctx(key, salt);
streams.gvd->add_srtp_ctx(key, salt);
streams.avd->add_srtp_ctx(key, salt);
}
stream_results ad_r;
stream_results ovd_r;
stream_results gvd_r;
stream_results avd_r;
streams.ad->install_receive_hook(&ad_r, hook);
streams.ovd->install_receive_hook(&ovd_r, hook);
streams.gvd->install_receive_hook(&gvd_r, hook);
streams.avd->install_receive_hook(&avd_r, hook);
while (frame_received)
{
frame_received = false;
std::this_thread::sleep_for(std::chrono::milliseconds(TIMEOUT));
}
std::cout << "No more frames received for " << TIMEOUT << " ms, end round" << std::endl;
sess->destroy_stream(streams.ad);
sess->destroy_stream(streams.ovd);
sess->destroy_stream(streams.gvd);
sess->destroy_stream(streams.avd);
rtp_ctx.destroy_session(sess);
// Calculate results
long long start = find_earliest_time_point(ad_r.start, ovd_r.start, gvd_r.start, avd_r.start);
long long end = find_latest_time_point(ad_r.last, ovd_r.last, gvd_r.last, avd_r.last);
long long diff = end - start;
size_t total_packets_received = ad_r.packets_received + ovd_r.packets_received + gvd_r.packets_received + avd_r.packets_received;
size_t total_bytes_received = ad_r.bytes_received + ovd_r.bytes_received + gvd_r.bytes_received + avd_r.bytes_received;
write_receive_results_to_file(result_filename, total_bytes_received, total_packets_received, diff);
return EXIT_SUCCESS;
}
void hook(void* arg, uvgrtp::frame::rtp_frame* frame)
{
stream_results* results = (stream_results*)arg;
if (results->packets_received == 0) {
results->start = get_current_time();
}
if (!frame) {
std::cerr << "Receiver test failed!" << std::endl;
std::this_thread::sleep_for(std::chrono::milliseconds(5000));
return;
}
results->last = get_current_time();
results->bytes_received += frame->payload_len;
results->packets_received++;
(void)uvg_rtp::frame::dealloc_frame(frame);
frame_received = true;
}