Skip to content

Commit

Permalink
formats: Develop solution to H26x aggregation when there are multiple…
Browse files Browse the repository at this point in the history
… non-consecutive small NAL units
  • Loading branch information
tampsa committed Feb 20, 2024
1 parent 516df57 commit c919103
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/formats/h26x.cc
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ rtp_error_t uvgrtp::formats::h26x::push_media_frame(sockaddr_in& addr, sockaddr_
nal.prefix_len = 0;
nal.size = data_len;
nal.aggregate = false;
nal.was_aggregated = false;

nals.push_back(nal);
}
Expand All @@ -381,13 +382,17 @@ rtp_error_t uvgrtp::formats::h26x::push_media_frame(sockaddr_in& addr, sockaddr_
{
if (nal.aggregate)
{
nal.was_aggregated = true;
if ((ret = add_aggregate_packet(data + nal.offset, nal.size)) != RTP_OK)
{
clear_aggregation_info();
fqueue_->deinit_transaction();
return ret;
}
}
else {
break;
}
}

(void)finalize_aggregation_pkt();
Expand All @@ -398,8 +403,7 @@ 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 (do_not_aggr || !nal.aggregate || !should_aggregate)
if (do_not_aggr || !nal.was_aggregated || !should_aggregate)
{
if ((ret = fqueue_->init_transaction(data + nal.offset, true)) != RTP_OK) {
UVG_LOG_ERROR("Invalid frame queue or failed to initialize transaction!");
Expand Down Expand Up @@ -816,7 +820,7 @@ rtp_error_t uvgrtp::formats::h26x::packet_handler(void* args, int rce_flags, uin
if (e && continuous) {
size_t nal_size = 0; // Find size of the complete reconstructed NAL unit
for (auto p : reconstructed_fragments.at(start).seqs) {
nal_size += fragments_[p]->payload_len;
nal_size += (fragments_[p]->payload_len - sizeof_fu_headers);
au.fragments_info[p].reconstructed = true;
}
/* Work in progress feature: here we discard inter frames if their references were not received correctly */
Expand Down
1 change: 1 addition & 0 deletions src/formats/h26x.hh
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ namespace uvgrtp {
size_t prefix_len = 0;
size_t size = 0;
bool aggregate = false;
bool was_aggregated = false;
};

class h26x : public media {
Expand Down
7 changes: 4 additions & 3 deletions test/test_4_formats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ TEST(FormatTests, h265_aggregation)
uvgrtp::media_stream* receiver = nullptr;

aggr_received = 0;
int expected = 3;
int expected = 5;

if (sess)
{
Expand All @@ -721,10 +721,10 @@ TEST(FormatTests, h265_aggregation)
rtp_format_t format = RTP_FORMAT_H265;
int test_runs = 1;

std::vector<size_t> test_sizes = { 100, 200, 300 };
std::vector<size_t> test_sizes = { 100, 200, 1700, 300, 400};

size_t total_size = 0;
std::unique_ptr<uint8_t[]> test_frame = std::unique_ptr<uint8_t[]>(new uint8_t[700]);
std::unique_ptr<uint8_t[]> test_frame = std::unique_ptr<uint8_t[]>(new uint8_t[2700]);

for (auto& size : test_sizes)
{
Expand Down Expand Up @@ -841,6 +841,7 @@ TEST(FormatTests, h265_disable_aggr)

inline void aggr_receive_hook(void* arg, uvgrtp::frame::rtp_frame* frame)
{
std::cout << "Rec frame size " << frame->payload_len << std::endl;
aggr_received++;
(void)uvgrtp::frame::dealloc_frame(frame);
}

0 comments on commit c919103

Please sign in to comment.