forked from ultravideo/uvgRTP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtcp_hook.cc
55 lines (46 loc) · 2.14 KB
/
rtcp_hook.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
#include <uvgrtp/lib.hh>
#include <cstring>
/* uvgRTP calls this hook when it receives an RTCP Receiver Report
*
* NOTE: If application uses hook, it must also free the frame when it's done with i
* Frame must deallocated using uvgrtp::frame::dealloc_frame() function */
void receiver_hook(uvgrtp::frame::rtcp_receiver_report *frame)
{
LOG_INFO("Received an RTCP Receiver Report");
for (auto& block : frame->report_blocks) {
fprintf(stderr, "ssrc: %x\n", block.ssrc);
fprintf(stderr, "fraction: %u\n", block.fraction);
fprintf(stderr, "lost: %d\n", block.lost);
fprintf(stderr, "last_seq: %u\n", block.last_seq);
fprintf(stderr, "jitter: %u\n", block.jitter);
fprintf(stderr, "lsr: %u\n", block.lsr);
fprintf(stderr, "dlsr (ms): %u\n", uvgrtp::clock::jiffies_to_ms(block.dlsr));
}
/* RTCP frames can be deallocated using delete */
delete frame;
}
int main(void)
{
/* See sending.cc for more details */
uvgrtp::context ctx;
/* See sending.cc for more details */
uvgrtp::session *sess = ctx.create_session("127.0.0.1");
/* For s1, RTCP runner is using port 7778 and for s2 port 8889 */
uvgrtp::media_stream *s1 = sess->create_stream(7777, 8888, RTP_FORMAT_GENERIC, RCE_RTCP);
uvgrtp::media_stream *s2 = sess->create_stream(8888, 7777, RTP_FORMAT_GENERIC, RCE_RTCP);
/* In this example code, s1 acts as the sender and because it is the only sender,
* it does not send any RTCP frames but only receives RTCP Receiver reports from s2.
*
* Because s1 only sends and s2 only receives, we only need to install receive hook for s1
*
* By default, all media_stream that have RTCP enabled start as receivers and only if/when they
* call push_frame() are they converted into senders. */
(void)s1->get_rtcp()->install_receiver_hook(receiver_hook);
/* Send dummy data so there's some RTCP data to send */
uint8_t buffer[50] = { 0 };
memset(buffer, 'a', 50);
while (true) {
s1->push_frame((uint8_t *)buffer, 50, RTP_NO_FLAGS);
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
}
}