diff --git a/src/formats/h26x.cc b/src/formats/h26x.cc index e82b732..a2eef72 100644 --- a/src/formats/h26x.cc +++ b/src/formats/h26x.cc @@ -393,10 +393,10 @@ rtp_error_t uvgrtp::formats::h26x::push_media_frame(sockaddr_in& addr, sockaddr_ for (auto& nal : nals) // non-aggregatable NAL units { - + //UVG_LOG_DEBUG("NAL size %u", nal.size); if (!nal.aggregate || !should_aggregate) { - if ((ret = fqueue_->init_transaction(data + nal.offset)) != RTP_OK) { + if ((ret = fqueue_->init_transaction(data + nal.offset, true)) != RTP_OK) { UVG_LOG_ERROR("Invalid frame queue or failed to initialize transaction!"); return ret; } diff --git a/src/frame_queue.cc b/src/frame_queue.cc index 9779d37..6a115a3 100644 --- a/src/frame_queue.cc +++ b/src/frame_queue.cc @@ -47,7 +47,7 @@ uvgrtp::frame_queue::~frame_queue() } } -rtp_error_t uvgrtp::frame_queue::init_transaction() +rtp_error_t uvgrtp::frame_queue::init_transaction(bool use_old_rtp_ts) { if (active_) { @@ -99,18 +99,18 @@ rtp_error_t uvgrtp::frame_queue::init_transaction() else active_->rtp_auth_tags = nullptr; - rtp_->fill_header((uint8_t *)&active_->rtp_common); + rtp_->fill_header((uint8_t *)&active_->rtp_common, use_old_rtp_ts); active_->buffers.clear(); return RTP_OK; } -rtp_error_t uvgrtp::frame_queue::init_transaction(uint8_t *data) +rtp_error_t uvgrtp::frame_queue::init_transaction(uint8_t *data, bool old_rtp_ts) { if (!data) return RTP_INVALID_VALUE; - if (init_transaction() != RTP_OK) { + if (init_transaction(old_rtp_ts) != RTP_OK) { UVG_LOG_ERROR("Failed to initialize transaction"); return RTP_GENERIC_ERROR; } @@ -121,12 +121,12 @@ rtp_error_t uvgrtp::frame_queue::init_transaction(uint8_t *data) return RTP_OK; } -rtp_error_t uvgrtp::frame_queue::init_transaction(std::unique_ptr data) +rtp_error_t uvgrtp::frame_queue::init_transaction(std::unique_ptr data, bool old_rtp_ts) { if (!data) return RTP_INVALID_VALUE; - if (init_transaction() != RTP_OK) { + if (init_transaction(old_rtp_ts) != RTP_OK) { UVG_LOG_ERROR("Failed to initialize transaction"); return RTP_GENERIC_ERROR; } diff --git a/src/frame_queue.hh b/src/frame_queue.hh index cec8fca..7290aaf 100644 --- a/src/frame_queue.hh +++ b/src/frame_queue.hh @@ -83,9 +83,9 @@ namespace uvgrtp { frame_queue(std::shared_ptr socket, std::shared_ptr rtp, int rce_flags); ~frame_queue(); - rtp_error_t init_transaction(); - rtp_error_t init_transaction(uint8_t *data); - rtp_error_t init_transaction(std::unique_ptr data); + rtp_error_t init_transaction(bool use_old_rtp_ts); + rtp_error_t init_transaction(uint8_t *data, bool old_rtp_ts = false); + rtp_error_t init_transaction(std::unique_ptr data, bool old_rtp_ts = false); /* Releases all memory associated with transaction * diff --git a/src/rtp.cc b/src/rtp.cc index dc2415f..3ceeefe 100644 --- a/src/rtp.cc +++ b/src/rtp.cc @@ -143,7 +143,7 @@ void uvgrtp::rtp::update_sequence(uint8_t *buffer) *(uint16_t *)&buffer[2] = htons(seq_); } -void uvgrtp::rtp::fill_header(uint8_t *buffer) +void uvgrtp::rtp::fill_header(uint8_t *buffer, bool use_old_ts) { if (!buffer) return; @@ -161,7 +161,10 @@ void uvgrtp::rtp::fill_header(uint8_t *buffer) *(uint16_t *)&buffer[2] = htons(seq_); *(uint32_t *)&buffer[8] = htonl(*ssrc_.get()); - if (timestamp_ == INVALID_TS) { + if (use_old_ts) { + *(uint32_t*)&buffer[4] = htonl((u_long)rtp_ts_); + } + else if (timestamp_ == INVALID_TS) { auto t1 = std::chrono::high_resolution_clock::now(); std::chrono::microseconds time_since_start = diff --git a/src/rtp.hh b/src/rtp.hh index f9708ec..2698c8a 100644 --- a/src/rtp.hh +++ b/src/rtp.hh @@ -40,7 +40,7 @@ namespace uvgrtp { void set_pkt_max_delay(size_t delay); void set_sampling_ntp(uint64_t ntp_ts); - void fill_header(uint8_t *buffer); + void fill_header(uint8_t* buffer, bool use_old_ts = false); void update_sequence(uint8_t *buffer); /* Validates the RTP header pointed to by "packet" */