tests: Add tests for small NAL units
Add tests for very small NAL units (4+ bytes for h264 and 6+ for h265/h266).
This commit is contained in:
parent
d7f0af7c4c
commit
e2234029d0
|
@ -69,15 +69,14 @@ TEST(FormatTests, h264_single_nal_unit)
|
|||
receiver = sess->create_stream(RECEIVE_PORT, SEND_PORT, RTP_FORMAT_H264, RCE_NO_FLAGS);
|
||||
}
|
||||
|
||||
// the default packet limit for RTP is 1458 where 12 bytes are dedicated to RTP header
|
||||
int rtp_flags = RTP_NO_FLAGS;
|
||||
rtp_format_t format = RTP_FORMAT_H264;
|
||||
int test_runs = 5;
|
||||
int size = 8;
|
||||
|
||||
std::cout << "Testing small NAL unit" << std::endl;
|
||||
std::vector<size_t> test_sizes = std::vector<size_t>(10);
|
||||
std::iota(test_sizes.begin(), test_sizes.end(), 8);
|
||||
std::vector<size_t> test_sizes = std::vector<size_t>(16);
|
||||
std::iota(test_sizes.begin(), test_sizes.end(), 4);
|
||||
|
||||
for (auto& size : test_sizes)
|
||||
{
|
||||
|
@ -86,10 +85,9 @@ TEST(FormatTests, h264_single_nal_unit)
|
|||
test_packet_size(std::move(intra_frame), test_runs, size, sess, sender, receiver, rtp_flags);
|
||||
}
|
||||
|
||||
|
||||
size = 35;
|
||||
|
||||
for (unsigned int nal_type = 1; nal_type <= 21; ++nal_type)
|
||||
for (unsigned int nal_type = 1; nal_type <= 23; ++nal_type)
|
||||
{
|
||||
std::cout << "Testing H264 NAL type " << nal_type << std::endl;
|
||||
std::unique_ptr<uint8_t[]> intra_frame = create_test_packet(format, nal_type, true, size, rtp_flags);
|
||||
|
@ -142,6 +140,51 @@ TEST(FormatTests, h264_fragmentation)
|
|||
cleanup_sess(ctx, sess);
|
||||
}
|
||||
|
||||
TEST(FormatTests, h265_single_nal_unit)
|
||||
{
|
||||
std::cout << "Starting H265 Single NAL unit test" << std::endl;
|
||||
uvgrtp::context ctx;
|
||||
uvgrtp::session* sess = ctx.create_session(LOCAL_ADDRESS);
|
||||
|
||||
uvgrtp::media_stream* sender = nullptr;
|
||||
uvgrtp::media_stream* receiver = nullptr;
|
||||
|
||||
if (sess)
|
||||
{
|
||||
sender = sess->create_stream(SEND_PORT, RECEIVE_PORT, RTP_FORMAT_H265, RCE_NO_FLAGS);
|
||||
receiver = sess->create_stream(RECEIVE_PORT, SEND_PORT, RTP_FORMAT_H265, RCE_NO_FLAGS);
|
||||
}
|
||||
|
||||
int rtp_flags = RTP_NO_FLAGS;
|
||||
rtp_format_t format = RTP_FORMAT_H265;
|
||||
int test_runs = 5;
|
||||
int size = 8;
|
||||
|
||||
std::cout << "Testing small NAL unit" << std::endl;
|
||||
std::vector<size_t> test_sizes = std::vector<size_t>(16);
|
||||
std::iota(test_sizes.begin(), test_sizes.end(), 6);
|
||||
|
||||
for (auto& size : test_sizes)
|
||||
{
|
||||
int nal_type = 8;
|
||||
std::unique_ptr<uint8_t[]> intra_frame = create_test_packet(format, nal_type, true, size, rtp_flags);
|
||||
test_packet_size(std::move(intra_frame), test_runs, size, sess, sender, receiver, rtp_flags);
|
||||
}
|
||||
|
||||
size = 35;
|
||||
|
||||
for (unsigned int nal_type = 0; nal_type <= 47; ++nal_type)
|
||||
{
|
||||
std::cout << "Testing H264 NAL type " << nal_type << std::endl;
|
||||
std::unique_ptr<uint8_t[]> intra_frame = create_test_packet(format, nal_type, true, size, rtp_flags);
|
||||
test_packet_size(std::move(intra_frame), test_runs, size, sess, sender, receiver, rtp_flags);
|
||||
}
|
||||
|
||||
cleanup_ms(sess, sender);
|
||||
cleanup_ms(sess, receiver);
|
||||
cleanup_sess(ctx, sess);
|
||||
}
|
||||
|
||||
TEST(FormatTests, h265_fragmentation)
|
||||
{
|
||||
std::cout << "Starting h265 fragmentation test" << std::endl;
|
||||
|
@ -269,6 +312,51 @@ TEST(FormatTests, h265_small_fragment_pacing_fps)
|
|||
cleanup_sess(ctx, sess);
|
||||
}
|
||||
|
||||
TEST(FormatTests, h266_single_nal_unit)
|
||||
{
|
||||
std::cout << "Starting H266 Single NAL unit test" << std::endl;
|
||||
uvgrtp::context ctx;
|
||||
uvgrtp::session* sess = ctx.create_session(LOCAL_ADDRESS);
|
||||
|
||||
uvgrtp::media_stream* sender = nullptr;
|
||||
uvgrtp::media_stream* receiver = nullptr;
|
||||
|
||||
if (sess)
|
||||
{
|
||||
sender = sess->create_stream(SEND_PORT, RECEIVE_PORT, RTP_FORMAT_H266, RCE_NO_FLAGS);
|
||||
receiver = sess->create_stream(RECEIVE_PORT, SEND_PORT, RTP_FORMAT_H266, RCE_NO_FLAGS);
|
||||
}
|
||||
|
||||
int rtp_flags = RTP_NO_FLAGS;
|
||||
rtp_format_t format = RTP_FORMAT_H266;
|
||||
int test_runs = 5;
|
||||
int size = 8;
|
||||
|
||||
std::cout << "Testing small NAL unit" << std::endl;
|
||||
std::vector<size_t> test_sizes = std::vector<size_t>(16);
|
||||
std::iota(test_sizes.begin(), test_sizes.end(), 6);
|
||||
|
||||
for (auto& size : test_sizes)
|
||||
{
|
||||
int nal_type = 8;
|
||||
std::unique_ptr<uint8_t[]> intra_frame = create_test_packet(format, nal_type, true, size, rtp_flags);
|
||||
test_packet_size(std::move(intra_frame), test_runs, size, sess, sender, receiver, rtp_flags);
|
||||
}
|
||||
|
||||
size = 35;
|
||||
|
||||
for (unsigned int nal_type = 0; nal_type <= 27; ++nal_type)
|
||||
{
|
||||
std::cout << "Testing H264 NAL type " << nal_type << std::endl;
|
||||
std::unique_ptr<uint8_t[]> intra_frame = create_test_packet(format, nal_type, true, size, rtp_flags);
|
||||
test_packet_size(std::move(intra_frame), test_runs, size, sess, sender, receiver, rtp_flags);
|
||||
}
|
||||
|
||||
cleanup_ms(sess, sender);
|
||||
cleanup_ms(sess, receiver);
|
||||
cleanup_sess(ctx, sess);
|
||||
}
|
||||
|
||||
TEST(FormatTests, h265_large_fragment_pacing)
|
||||
{
|
||||
std::cout << "Starting h265 test" << std::endl;
|
||||
|
|
|
@ -29,6 +29,8 @@ inline void rtp_receive_hook(void* arg, uvgrtp::frame::rtp_frame* frame);
|
|||
|
||||
inline void set_nal_unit(uint8_t* frame, size_t& pos, bool zero_prefix, uint8_t zeros,
|
||||
uint8_t first_byte, uint8_t second_byte);
|
||||
inline void set_nal_unit(uint8_t* frame, size_t& pos, bool zero_prefix, uint8_t zeros,
|
||||
uint8_t first_byte);
|
||||
|
||||
class Test_receiver
|
||||
{
|
||||
|
@ -60,7 +62,7 @@ inline std::unique_ptr<uint8_t[]> create_test_packet(rtp_format_t format, uint8_
|
|||
std::unique_ptr<uint8_t[]> test_frame = std::unique_ptr<uint8_t[]>(new uint8_t[size]);
|
||||
memset(test_frame.get(), 'b', size);
|
||||
|
||||
if (add_start_code && size >= 6)
|
||||
if (add_start_code && (size >= 6 || (size >= 4 && format == RTP_FORMAT_H264)))
|
||||
{
|
||||
size_t pos = 0;
|
||||
bool zero_prefix = !(rtp_flags & RTP_NO_H26X_SCL);
|
||||
|
@ -68,7 +70,7 @@ inline std::unique_ptr<uint8_t[]> create_test_packet(rtp_format_t format, uint8_
|
|||
if (format == RTP_FORMAT_H264)
|
||||
{
|
||||
// https://datatracker.ietf.org/doc/html/rfc6184#section-1.3
|
||||
set_nal_unit(test_frame.get(), pos, zero_prefix, 2, nal_type, 0);
|
||||
set_nal_unit(test_frame.get(), pos, zero_prefix, 2, nal_type);
|
||||
}
|
||||
else if (format == RTP_FORMAT_H265)
|
||||
{
|
||||
|
@ -237,7 +239,6 @@ inline void process_rtp_frame(uvgrtp::frame::rtp_frame* frame)
|
|||
inline void set_nal_unit(uint8_t* frame, size_t& pos, bool start_code, uint8_t zeros,
|
||||
uint8_t first_byte, uint8_t second_byte)
|
||||
{
|
||||
// see https://datatracker.ietf.org/doc/html/draft-ietf-avtcore-rtp-vvc#section-1.1.4
|
||||
if (start_code)
|
||||
{
|
||||
memset(frame + pos, 0, zeros);
|
||||
|
@ -248,6 +249,21 @@ inline void set_nal_unit(uint8_t* frame, size_t& pos, bool start_code, uint8_t z
|
|||
|
||||
memset(frame + pos, first_byte, 1);
|
||||
pos += 1;
|
||||
memset(frame + pos, second_byte, 1); // Intra frame (type)
|
||||
memset(frame + pos, second_byte, 1);
|
||||
pos += 1;
|
||||
}
|
||||
|
||||
inline void set_nal_unit(uint8_t* frame, size_t& pos, bool start_code, uint8_t zeros,
|
||||
uint8_t first_byte)
|
||||
{
|
||||
if (start_code)
|
||||
{
|
||||
memset(frame + pos, 0, zeros);
|
||||
pos += zeros;
|
||||
memset(frame + pos, 1, 1);
|
||||
pos += 1;
|
||||
}
|
||||
|
||||
memset(frame + pos, first_byte, 1);
|
||||
pos += 1;
|
||||
}
|
Loading…
Reference in New Issue