diff --git a/examples/custom_timestamps.cc b/examples/custom_timestamps.cc new file mode 100644 index 0000000..7aa077c --- /dev/null +++ b/examples/custom_timestamps.cc @@ -0,0 +1,45 @@ +#include + +#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; +} diff --git a/examples/sending.cc b/examples/sending.cc index 8bf1ea4..51c1bea 100644 --- a/examples/sending.cc +++ b/examples/sending.cc @@ -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 */ diff --git a/include/rtcp.hh b/include/rtcp.hh index 4b0fece..4705490 100644 --- a/include/rtcp.hh +++ b/include/rtcp.hh @@ -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); diff --git a/src/rtcp.cc b/src/rtcp.cc index 98b3187..e8cbc9d 100644 --- a/src/rtcp.cc +++ b/src/rtcp.cc @@ -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; diff --git a/src/srtp.cc b/src/srtp.cc index ad23bd3..5d4a975 100644 --- a/src/srtp.cc +++ b/src/srtp.cc @@ -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;