formats: Use the same RTP timestamp for all NAL units that belong to the same access unit

This commit is contained in:
Heikki Tampio 2024-02-13 13:17:25 +02:00
parent 5bd486fbab
commit 2a3c12cff5
5 changed files with 17 additions and 14 deletions

View File

@ -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;
}

View File

@ -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<uint8_t[]> data)
rtp_error_t uvgrtp::frame_queue::init_transaction(std::unique_ptr<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;
}

View File

@ -83,9 +83,9 @@ namespace uvgrtp {
frame_queue(std::shared_ptr<uvgrtp::socket> socket, std::shared_ptr<uvgrtp::rtp> 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<uint8_t[]> 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<uint8_t[]> data, bool old_rtp_ts = false);
/* Releases all memory associated with transaction
*

View File

@ -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 =

View File

@ -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" */