2020-07-23 09:55:24 +00:00
|
|
|
#include <uvgrtp/lib.hh>
|
|
|
|
#include <climits>
|
|
|
|
#include <cstring>
|
|
|
|
|
|
|
|
void thread_func(void)
|
|
|
|
{
|
|
|
|
/* See sending.cc for more details */
|
2021-02-19 01:13:43 +00:00
|
|
|
uvgrtp::context ctx;
|
|
|
|
uvgrtp::session *sess = ctx.create_session("127.0.0.1");
|
2020-07-23 09:55:24 +00:00
|
|
|
|
|
|
|
/* Enable SRTP and use ZRTP to manage keys */
|
|
|
|
unsigned flags = RCE_SRTP | RCE_SRTP_KMNGMNT_ZRTP;
|
|
|
|
|
|
|
|
/* Keys creates using Diffie-Hellman mode */
|
2021-04-23 05:55:15 +00:00
|
|
|
uvgrtp::media_stream *video = sess->create_stream(8889, 8888, RTP_FORMAT_GENERIC, flags);
|
2020-07-23 09:55:24 +00:00
|
|
|
|
|
|
|
/* Keys created using Multistream mode */
|
2021-04-23 05:55:15 +00:00
|
|
|
uvgrtp::media_stream *audio = sess->create_stream(7778, 7777, RTP_FORMAT_GENERIC, flags);
|
2020-07-23 09:55:24 +00:00
|
|
|
|
|
|
|
for (;;) {
|
2021-04-23 05:55:15 +00:00
|
|
|
auto frame = video->pull_frame();
|
2020-07-23 09:55:24 +00:00
|
|
|
fprintf(stderr, "Message: '%s'\n", frame->payload);
|
2021-02-19 01:13:43 +00:00
|
|
|
(void)uvgrtp::frame::dealloc_frame(frame);
|
2020-07-23 09:55:24 +00:00
|
|
|
|
2021-04-23 05:55:15 +00:00
|
|
|
frame = audio->pull_frame();
|
2020-07-23 09:55:24 +00:00
|
|
|
fprintf(stderr, "Message: '%s'\n", frame->payload);
|
2021-02-19 01:13:43 +00:00
|
|
|
(void)uvgrtp::frame::dealloc_frame(frame);
|
2020-07-23 09:55:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
{
|
|
|
|
/* Create separate thread for the receiver
|
|
|
|
*
|
|
|
|
* Because we're using ZRTP for SRTP key management,
|
|
|
|
* the receiver and sender must communicate with each other
|
|
|
|
* before the actual media communication starts */
|
|
|
|
new std::thread(thread_func);
|
|
|
|
|
|
|
|
/* See sending.cc for more details */
|
2021-02-19 01:13:43 +00:00
|
|
|
uvgrtp::context ctx;
|
|
|
|
uvgrtp::session *sess = ctx.create_session("127.0.0.1");
|
2020-07-23 09:55:24 +00:00
|
|
|
|
|
|
|
/* Enable SRTP and use ZRTP to manage keys */
|
|
|
|
unsigned flags = RCE_SRTP | RCE_SRTP_KMNGMNT_ZRTP;
|
|
|
|
|
|
|
|
/* Initialize ZRTP and negotiate the keys used to encrypt the media */
|
2021-04-23 05:55:15 +00:00
|
|
|
uvgrtp::media_stream *video = sess->create_stream(8888, 8889, RTP_FORMAT_GENERIC, flags);
|
2020-07-23 09:55:24 +00:00
|
|
|
|
|
|
|
/* The first call to create_stream() creates keys for the session using Diffie-Hellman
|
|
|
|
* key exchange and all subsequent calls to create_stream() initialize keys for the
|
|
|
|
* stream using Multistream mode */
|
2021-04-23 05:55:15 +00:00
|
|
|
uvgrtp::media_stream *audio = sess->create_stream(7777, 7778, RTP_FORMAT_GENERIC, flags);
|
2020-07-23 09:55:24 +00:00
|
|
|
|
|
|
|
char *message = (char *)"Hello, world!";
|
|
|
|
size_t msg_len = strlen(message);
|
|
|
|
|
|
|
|
for (;;) {
|
2021-04-23 05:55:15 +00:00
|
|
|
video->push_frame((uint8_t *)message, msg_len, RTP_NO_FLAGS);
|
|
|
|
audio->push_frame((uint8_t *)message, msg_len, RTP_NO_FLAGS);
|
2020-07-23 09:55:24 +00:00
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
|
|
|
}
|
|
|
|
}
|