2020-04-27 11:07:24 +00:00
|
|
|
#include <uvgrtp/lib.hh>
|
2019-08-21 05:04:45 +00:00
|
|
|
#include <thread>
|
|
|
|
|
2021-02-19 01:13:43 +00:00
|
|
|
void receive_hook(void *arg, uvgrtp::frame::rtp_frame *frame)
|
2019-08-21 05:04:45 +00:00
|
|
|
{
|
|
|
|
if (!frame) {
|
|
|
|
fprintf(stderr, "invalid frame received!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-14 06:12:50 +00:00
|
|
|
/* Now we own the frame. Here you could give the frame to the application
|
2020-10-06 03:45:04 +00:00
|
|
|
* if f.ex "arg" was some application-specific pointer
|
2019-08-21 05:04:45 +00:00
|
|
|
*
|
2020-10-06 03:45:04 +00:00
|
|
|
* arg->copy_frame(frame) or whatever
|
2019-08-21 05:04:45 +00:00
|
|
|
*
|
2020-10-06 03:45:04 +00:00
|
|
|
* When we're done with the frame, it must be deallocated manually */
|
2021-02-19 01:13:43 +00:00
|
|
|
(void)uvgrtp::frame::dealloc_frame(frame);
|
2019-08-21 05:04:45 +00:00
|
|
|
}
|
|
|
|
|
2020-02-14 06:12:50 +00:00
|
|
|
int main(void)
|
2019-08-21 05:04:45 +00:00
|
|
|
{
|
2020-02-14 06:12:50 +00:00
|
|
|
/* To use the library, one must create a global RTP context object */
|
2021-02-19 01:13:43 +00:00
|
|
|
uvgrtp::context ctx;
|
2019-08-21 05:04:45 +00:00
|
|
|
|
2020-02-14 06:12:50 +00:00
|
|
|
/* Each new IP address requires a separate RTP session.
|
2020-10-06 03:45:04 +00:00
|
|
|
* This session object contains all media streams and an RTCP object (if enabled) */
|
2021-02-19 01:13:43 +00:00
|
|
|
uvgrtp::session *sess = ctx.create_session("127.0.0.1");
|
2020-02-14 06:12:50 +00:00
|
|
|
|
|
|
|
/* Each RTP session has one or more media streams. These media streams are bidirectional
|
|
|
|
* and they require both source and destination ports for the connection. One must also
|
|
|
|
* specify the media format for the stream and any configuration flags if needed
|
|
|
|
*
|
2020-10-06 03:45:04 +00:00
|
|
|
* If ZRTP is enabled, the first media stream instance does a Diffie-Hellman key exchange
|
2020-02-14 06:12:50 +00:00
|
|
|
* with remote and rest of the media streams use Multistream mode. ZRTP requires that both
|
|
|
|
* source and destination ports are known so it can perform the key exchange
|
|
|
|
*
|
|
|
|
* First port is source port aka the port that we listen to and second port is the port
|
|
|
|
* that remote listens to
|
|
|
|
*
|
|
|
|
* This same object is used for both sending and receiving media
|
|
|
|
*
|
2020-10-06 03:45:04 +00:00
|
|
|
* In this example, we have one media stream with remote participant: HEVC */
|
2021-02-19 01:13:43 +00:00
|
|
|
uvgrtp::media_stream *hevc = sess->create_stream(8888, 8889, RTP_FORMAT_H265, 0);
|
2019-08-21 05:04:45 +00:00
|
|
|
|
2020-02-14 06:12:50 +00:00
|
|
|
/* Receive hook can be installed and the receiver will call this hook when an RTP frame is received
|
2019-08-21 05:04:45 +00:00
|
|
|
*
|
|
|
|
* This is a non-blocking operation
|
|
|
|
*
|
|
|
|
* If necessary, receive hook can be given an argument and this argument is supplied to
|
|
|
|
* receive hook every time the hook is called. This argument could a pointer to application-
|
|
|
|
* specfic object if the application needs to be called inside the hook
|
|
|
|
*
|
2020-02-14 06:12:50 +00:00
|
|
|
* If it's not needed, it should be set to nullptr */
|
|
|
|
hevc->install_receive_hook(nullptr, receive_hook);
|
2019-08-21 05:04:45 +00:00
|
|
|
|
2020-02-14 06:12:50 +00:00
|
|
|
/* Session must be destroyed manually */
|
|
|
|
ctx.destroy_session(sess);
|
2019-08-21 05:04:45 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|