uvgrtp-base/docs/examples/rtcp_hook.cc

45 lines
1.7 KiB
C++
Raw Normal View History

2020-04-27 11:07:24 +00:00
#include <uvgrtp/lib.hh>
2019-06-24 04:44:29 +00:00
#include <cstring>
2020-04-27 11:07:24 +00:00
/* 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
2020-04-27 11:07:24 +00:00
* Frame must deallocated using uvg_rtp::frame::dealloc_frame() function */
2020-10-06 03:45:04 +00:00
void receiver_hook(uvg_rtp::frame::rtcp_receiver_report *frame)
{
2020-08-11 08:47:33 +00:00
LOG_INFO("Received an RTCP Receiver Report");
2020-10-06 03:45:04 +00:00
/* RTCP frames can be deallocated using delete */
delete frame;
}
2019-06-24 04:44:29 +00:00
int main(void)
{
/* See rtp/sending.cc for more information about session initialization */
2020-06-18 06:58:48 +00:00
uvg_rtp::context ctx;
2019-06-24 04:44:29 +00:00
2020-06-18 06:58:48 +00:00
uvg_rtp::session *sess = ctx.create_session("127.0.0.1");
2020-08-11 08:47:33 +00:00
/* For s1, RTCP runner is using port 7778 and for s2 port 8889 */
uvg_rtp::media_stream *s1 = sess->create_stream(7777, 8888, RTP_FORMAT_GENERIC, RCE_RTCP);
uvg_rtp::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. */
2020-06-18 06:58:48 +00:00
(void)s1->get_rtcp()->install_receiver_hook(receiver_hook);
2019-06-24 04:44:29 +00:00
/* Send dummy data so there's some RTCP data to send */
2019-06-24 04:44:29 +00:00
uint8_t buffer[50] = { 0 };
memset(buffer, 'a', 50);
while (true) {
2020-06-18 06:58:48 +00:00
s1->push_frame((uint8_t *)buffer, 50, RTP_NO_FLAGS);
2019-06-24 04:44:29 +00:00
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
}
}