Add example code for custom timestamping

This commit is contained in:
Aaro Altonen 2020-08-20 11:32:31 +03:00
parent b51fef61ee
commit 5d680d454b
5 changed files with 47 additions and 14 deletions

View File

@ -0,0 +1,45 @@
#include <uvgrtp/lib.hh>
#define PAYLOAD_MAXLEN 100
int main(void)
{
/* To use the library, one must create a global RTP context object */
uvg_rtp::context ctx;
/* Each new IP address requires a separate RTP session.
* This session objects contains all media streams and an RTCP object (if enabled) */
uvg_rtp::session *sess = ctx.create_session("127.0.0.1");
/* Create MediaStream and RTCP for the session */
uvg_rtp::media_stream *hevc = sess->create_stream(8888, 8889, RTP_FORMAT_HEVC, RCE_RTCP);
uint8_t *buffer = new uint8_t[PAYLOAD_MAXLEN];
uint32_t clock_rate = 90000 / 30;
uint32_t timestamp = 0;
/* If you don't want uvgRTP to handle timestamping but wish to do that yourself
* AND you want to use RTCP, timestamping info must be provided for the RTCP so
* it is able calculate sensible values for synchronization info
*
* The first parameter is NTP time associated with the corresponding RTP timestamp,
* second parameter is clock rate and the third parameter is RTP timestamp for t = 0
* (it can be zero or some random number, does not matter)
*
* NOTE: dummy data passed as NTP timestamp */
hevc->get_rtcp()->set_ts_info(1337, clock_rate, timestamp);
for (int i = 0; i < 10; ++i) {
/* If needed, custom timestamps can be given to push_frame().
*
* This overrides uvgRTP's own calculations and uses the given timestamp for all RTP packets of "buffer" */
if (hevc->push_frame(buffer, PAYLOAD_MAXLEN, clock_rate * timestamp++, RTP_NO_FLAGS) != RTP_OK)
fprintf(stderr, "Failed to send RTP frame!");
}
/* Session must be destroyed manually */
delete[] buffer;
ctx.destroy_session(sess);
return 0;
}

View File

@ -31,19 +31,8 @@ int main(void)
uint32_t timestamp = 0;
for (int i = 0; i < 10; ++i) {
#ifndef CUSTOM_TIMESTAMPS
/* Sending data is as simple as calling push_frame().
*
* push_frame() will fragment the input buffer into payloads of 1500 bytes and send them to remote */
if (hevc->push_frame(buffer, PAYLOAD_MAXLEN, RTP_NO_FLAGS) != RTP_OK)
fprintf(stderr, "Failed to send RTP frame!");
#else
/* If needed, custom timestamps can be given to push_frame().
*
* This overrides uvgRTP's own calculations and uses the given timestamp for all RTP packets of "buffer" */
if (hevc->push_frame(buffer, PAYLOAD_MAXLEN, (90000 / 30) * timestamp++, RTP_NO_FLAGS) != RTP_OK)
fprintf(stderr, "Failed to send RTP frame!");
#endif
}
/* Session must be destroyed manually */

View File

@ -177,7 +177,7 @@ namespace uvg_rtp {
/* Set wallclock reading for t = 0 and random RTP timestamp from where the counting is started
* + clock rate for calculating the correct increment */
void set_sender_ts_info(uint64_t clock_start, uint32_t clock_rate, uint32_t rtp_ts_start);
void set_ts_info(uint64_t clock_start, uint32_t clock_rate, uint32_t rtp_ts_start);
/* Update various session statistics */
void update_session_statistics(uvg_rtp::frame::rtp_frame *frame);

View File

@ -208,7 +208,7 @@ bool uvg_rtp::rtcp::is_participant(uint32_t ssrc)
return participants_.find(ssrc) != participants_.end();
}
void uvg_rtp::rtcp::set_sender_ts_info(uint64_t clock_start, uint32_t clock_rate, uint32_t rtp_ts_start)
void uvg_rtp::rtcp::set_ts_info(uint64_t clock_start, uint32_t clock_rate, uint32_t rtp_ts_start)
{
clock_start_ = clock_start;
clock_rate_ = clock_rate;

View File

@ -93,7 +93,6 @@ uvg_rtp::srtp_ctx_t& uvg_rtp::srtp::get_ctx()
return srtp_ctx_;
}
>>>>>>> security-fixes
rtp_error_t uvg_rtp::srtp::__init(int type, int flags)
{
srtp_ctx_.roc = 0;