2020-04-27 11:07:24 +00:00
|
|
|
#include <uvgrtp/lib.hh>
|
2019-08-21 05:04:45 +00:00
|
|
|
|
|
|
|
#define PAYLOAD_MAXLEN 100
|
|
|
|
|
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
|
|
|
|
2021-04-23 05:55:15 +00:00
|
|
|
/* Each new IP address requires a separate RTP session */
|
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
|
2021-04-23 05:55:15 +00:00
|
|
|
* specify the media format for the stream and any configuration flags if needed.
|
2020-01-07 08:20:20 +00:00
|
|
|
*
|
2021-04-23 05:55:15 +00:00
|
|
|
* See configuration.cc for more details about configuration.
|
2020-01-07 08:20:20 +00:00
|
|
|
*
|
2020-02-14 06:12:50 +00:00
|
|
|
* First port is source port aka the port that we listen to and second port is the port
|
|
|
|
* that remote listens to
|
2019-08-21 05:04:45 +00:00
|
|
|
*
|
2020-02-14 06:12:50 +00:00
|
|
|
* This same object is used for both sending and receiving media
|
|
|
|
*
|
2021-04-23 05:55:15 +00:00
|
|
|
* In this example, we have one media stream with the remote participant: H265 */
|
|
|
|
uvgrtp::media_stream *hevc = sess->create_stream(8888, 8889, RTP_FORMAT_H265, RTP_NO_FLAGS);
|
2019-08-21 05:04:45 +00:00
|
|
|
|
2021-04-23 05:55:15 +00:00
|
|
|
uint8_t *buffer = new uint8_t[PAYLOAD_MAXLEN];
|
2019-08-21 05:04:45 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
2020-05-28 06:50:26 +00:00
|
|
|
if (hevc->push_frame(buffer, PAYLOAD_MAXLEN, RTP_NO_FLAGS) != RTP_OK)
|
2019-08-21 05:04:45 +00:00
|
|
|
fprintf(stderr, "Failed to send RTP frame!");
|
|
|
|
}
|
|
|
|
|
2020-02-14 06:12:50 +00:00
|
|
|
/* Session must be destroyed manually */
|
2019-08-21 05:04:45 +00:00
|
|
|
delete[] buffer;
|
2020-02-14 06:12:50 +00:00
|
|
|
ctx.destroy_session(sess);
|
2019-08-21 05:04:45 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|