rtph265pay test: Add unit tests for aggregation

This commit is contained in:
Olivier Crête 2019-06-19 17:16:03 -04:00 committed by Nicolas Dufresne
parent 1b32cb1eae
commit 4810c93222

View file

@ -615,6 +615,296 @@ GST_START_TEST (test_rtph265pay_marker_for_fragmented_au)
GST_END_TEST;
GST_START_TEST (test_rtph265pay_aggregate_two_slices_per_buffer)
{
GstHarness *h = gst_harness_new_parse ("rtph265pay timestamp-offset=123"
" name=p");
GstFlowReturn ret;
GstBuffer *buffer;
GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
GstElement *e = gst_bin_get_by_name (GST_BIN (h->element), "p");
gint i;
gst_harness_set_src_caps_str (h,
"video/x-h265,alignment=nal,stream-format=byte-stream");
/* No aggregation latency mode */
g_object_set (e, "aggregate-mode", 0, NULL);
buffer = wrap_static_buffer_with_pts (h265_idr_slice_1,
sizeof (h265_idr_slice_1), 0);
buffer = gst_buffer_append (buffer,
wrap_static_buffer_with_pts (h265_idr_slice_2, sizeof (h265_idr_slice_2),
0));
ret = gst_harness_push (h, buffer);
fail_unless_equals_int (ret, GST_FLOW_OK);
buffer = wrap_static_buffer_with_pts (h265_idr_slice_1,
sizeof (h265_idr_slice_1), 0);
buffer = gst_buffer_append (buffer,
wrap_static_buffer_with_pts (h265_idr_slice_2, sizeof (h265_idr_slice_2),
0));
ret = gst_harness_push (h, buffer);
fail_unless_equals_int (ret, GST_FLOW_OK);
fail_unless_equals_int (gst_harness_buffers_in_queue (h), 4);
for (i = 0; i < 4; i++) {
buffer = gst_harness_pull (h);
fail_unless (gst_rtp_buffer_map (buffer, GST_MAP_READ, &rtp));
fail_unless_equals_uint64 (GST_BUFFER_PTS (buffer), 0);
fail_unless_equals_uint64 (gst_rtp_buffer_get_timestamp (&rtp), 123);
fail_unless_equals_int (gst_buffer_get_size (buffer), 12 +
((i % 2) ? (sizeof (h265_idr_slice_2) - 3) :
(sizeof (h265_idr_slice_1)) - 4));
gst_rtp_buffer_unmap (&rtp);
gst_buffer_unref (buffer);
}
/* Zero latency mode */
g_object_set (e, "aggregate-mode", 1, NULL);
buffer = wrap_static_buffer_with_pts (h265_idr_slice_1,
sizeof (h265_idr_slice_1), 0);
buffer = gst_buffer_append (buffer,
wrap_static_buffer_with_pts (h265_idr_slice_2, sizeof (h265_idr_slice_2),
0));
ret = gst_harness_push (h, buffer);
fail_unless_equals_int (ret, GST_FLOW_OK);
buffer = wrap_static_buffer_with_pts (h265_idr_slice_1,
sizeof (h265_idr_slice_1), 0);
buffer = gst_buffer_append (buffer,
wrap_static_buffer_with_pts (h265_idr_slice_2, sizeof (h265_idr_slice_2),
0));
ret = gst_harness_push (h, buffer);
fail_unless_equals_int (ret, GST_FLOW_OK);
fail_unless_equals_int (gst_harness_buffers_in_queue (h), 2);
for (i = 0; i < 2; i++) {
buffer = gst_harness_pull (h);
fail_unless (gst_rtp_buffer_map (buffer, GST_MAP_READ, &rtp));
fail_unless_equals_uint64 (GST_BUFFER_PTS (buffer), 0);
fail_unless_equals_uint64 (gst_rtp_buffer_get_timestamp (&rtp), 123);
/* RTP header = 12, AP header = 2, 2 bytes length per NAL */
fail_unless_equals_int (gst_buffer_get_size (buffer), 12 + 2 +
(2 + sizeof (h265_idr_slice_2) - 3) +
(2 + sizeof (h265_idr_slice_1) - 4));
gst_rtp_buffer_unmap (&rtp);
gst_buffer_unref (buffer);
}
/* Max aggregation */
g_object_set (e, "aggregate-mode", 2, NULL);
buffer = wrap_static_buffer_with_pts (h265_idr_slice_1,
sizeof (h265_idr_slice_1), 0);
buffer = gst_buffer_append (buffer,
wrap_static_buffer_with_pts (h265_idr_slice_2, sizeof (h265_idr_slice_2),
0));
ret = gst_harness_push (h, buffer);
fail_unless_equals_int (ret, GST_FLOW_OK);
buffer = wrap_static_buffer_with_pts (h265_idr_slice_1,
sizeof (h265_idr_slice_1), 0);
buffer = gst_buffer_append (buffer,
wrap_static_buffer_with_pts (h265_idr_slice_2, sizeof (h265_idr_slice_2),
0));
ret = gst_harness_push (h, buffer);
fail_unless_equals_int (ret, GST_FLOW_OK);
fail_unless_equals_int (gst_harness_buffers_in_queue (h), 0);
/* Push EOS to send it out */
gst_harness_push_event (h, gst_event_new_eos ());
fail_unless_equals_int (gst_harness_buffers_in_queue (h), 1);
buffer = gst_harness_pull (h);
fail_unless (gst_rtp_buffer_map (buffer, GST_MAP_READ, &rtp));
fail_unless_equals_uint64 (GST_BUFFER_PTS (buffer), 0);
fail_unless_equals_uint64 (gst_rtp_buffer_get_timestamp (&rtp), 123);
fail_unless_equals_int (gst_buffer_get_size (buffer), 12 + 2 +
2 * ((2 + sizeof (h265_idr_slice_2) - 3) +
(2 + sizeof (h265_idr_slice_1) - 4)));
gst_rtp_buffer_unmap (&rtp);
gst_buffer_unref (buffer);
g_object_unref (e);
gst_harness_teardown (h);
}
GST_END_TEST;
/* AUD */
static guint8 h265_aud[] = {
0x00, 0x00, 0x00, 0x01, (35 << 1), 0x00, 0x80
};
GST_START_TEST (test_rtph265pay_aggregate_with_aud)
{
GstHarness *h = gst_harness_new_parse ("rtph265pay timestamp-offset=123");
GstFlowReturn ret;
GstBuffer *buffer;
GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
gst_harness_set_src_caps_str (h,
"video/x-h265,alignment=nal,stream-format=byte-stream");
buffer = wrap_static_buffer_with_pts (h265_idr_slice_1,
sizeof (h265_idr_slice_1), 0);
buffer = gst_buffer_append (buffer,
wrap_static_buffer_with_pts (h265_aud, sizeof (h265_aud), 0));
buffer = gst_buffer_append (buffer,
wrap_static_buffer_with_pts (h265_idr_slice_1, sizeof (h265_idr_slice_1),
0));
ret = gst_harness_push (h, buffer);
fail_unless_equals_int (ret, GST_FLOW_OK);
fail_unless_equals_int (gst_harness_buffers_in_queue (h), 2);
buffer = gst_harness_pull (h);
fail_unless (gst_rtp_buffer_map (buffer, GST_MAP_READ, &rtp));
fail_unless_equals_uint64 (GST_BUFFER_PTS (buffer), 0);
fail_unless_equals_uint64 (gst_rtp_buffer_get_timestamp (&rtp), 123);
fail_unless_equals_int (gst_buffer_get_size (buffer), 12 +
(sizeof (h265_idr_slice_1) - 4));
gst_rtp_buffer_unmap (&rtp);
gst_buffer_unref (buffer);
buffer = gst_harness_pull (h);
fail_unless (gst_rtp_buffer_map (buffer, GST_MAP_READ, &rtp));
fail_unless_equals_uint64 (GST_BUFFER_PTS (buffer), 0);
fail_unless_equals_uint64 (gst_rtp_buffer_get_timestamp (&rtp), 123);
fail_unless_equals_int (gst_buffer_get_size (buffer), 12 + 2 +
(2 + sizeof (h265_aud) - 4) + (2 + sizeof (h265_idr_slice_1) - 4));
gst_rtp_buffer_unmap (&rtp);
gst_buffer_unref (buffer);
gst_harness_teardown (h);
}
GST_END_TEST;
GST_START_TEST (test_rtph265pay_aggregate_with_ts_change)
{
GstHarness *h = gst_harness_new_parse ("rtph265pay timestamp-offset=123 "
"aggregate-mode=max");
GstFlowReturn ret;
GstBuffer *buffer;
GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
gst_harness_set_src_caps_str (h,
"video/x-h265,alignment=nal,stream-format=byte-stream");
buffer = wrap_static_buffer_with_pts (h265_idr_slice_1,
sizeof (h265_idr_slice_1), 0);
buffer = gst_buffer_append (buffer,
wrap_static_buffer_with_pts (h265_idr_slice_2, sizeof (h265_idr_slice_2),
0));
ret = gst_harness_push (h, buffer);
fail_unless_equals_int (ret, GST_FLOW_OK);
buffer = wrap_static_buffer_with_pts (h265_idr_slice_1,
sizeof (h265_idr_slice_1), GST_SECOND);
buffer = gst_buffer_append (buffer,
wrap_static_buffer_with_pts (h265_idr_slice_2, sizeof (h265_idr_slice_2),
GST_SECOND));
ret = gst_harness_push (h, buffer);
fail_unless_equals_int (ret, GST_FLOW_OK);
fail_unless_equals_int (gst_harness_buffers_in_queue (h), 1);
/* Push EOS to send the second one out */
gst_harness_push_event (h, gst_event_new_eos ());
fail_unless_equals_int (gst_harness_buffers_in_queue (h), 2);
buffer = gst_harness_pull (h);
fail_unless (gst_rtp_buffer_map (buffer, GST_MAP_READ, &rtp));
fail_unless_equals_uint64 (GST_BUFFER_PTS (buffer), 0);
fail_unless_equals_uint64 (gst_rtp_buffer_get_timestamp (&rtp), 123);
fail_unless_equals_int (gst_buffer_get_size (buffer), 12 + 2 +
(2 + sizeof (h265_idr_slice_2) - 3) +
(2 + sizeof (h265_idr_slice_1) - 4));
gst_rtp_buffer_unmap (&rtp);
gst_buffer_unref (buffer);
buffer = gst_harness_pull (h);
fail_unless (gst_rtp_buffer_map (buffer, GST_MAP_READ, &rtp));
fail_unless_equals_uint64 (GST_BUFFER_PTS (buffer), GST_SECOND);
fail_unless_equals_uint64 (gst_rtp_buffer_get_timestamp (&rtp), 123 + 90000);
fail_unless_equals_int (gst_buffer_get_size (buffer), 12 + 2 +
(2 + sizeof (h265_idr_slice_2) - 3) +
(2 + sizeof (h265_idr_slice_1) - 4));
gst_rtp_buffer_unmap (&rtp);
gst_buffer_unref (buffer);
gst_harness_teardown (h);
}
GST_END_TEST;
GST_START_TEST (test_rtph265pay_aggregate_with_discont)
{
GstHarness *h = gst_harness_new_parse ("rtph265pay timestamp-offset=123");
GstFlowReturn ret;
GstBuffer *buffer;
GstRTPBuffer rtp = GST_RTP_BUFFER_INIT;
gst_harness_set_src_caps_str (h,
"video/x-h265,alignment=nal,stream-format=byte-stream");
buffer = wrap_static_buffer_with_pts (h265_idr_slice_1,
sizeof (h265_idr_slice_1), 0);
buffer = gst_buffer_append (buffer,
wrap_static_buffer_with_pts (h265_idr_slice_2, sizeof (h265_idr_slice_2),
0));
ret = gst_harness_push (h, buffer);
fail_unless_equals_int (ret, GST_FLOW_OK);
buffer = wrap_static_buffer_with_pts (h265_idr_slice_1,
sizeof (h265_idr_slice_1), 0);
buffer = gst_buffer_append (buffer,
wrap_static_buffer_with_pts (h265_idr_slice_2, sizeof (h265_idr_slice_2),
0));
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DISCONT);
ret = gst_harness_push (h, buffer);
fail_unless_equals_int (ret, GST_FLOW_OK);
fail_unless_equals_int (gst_harness_buffers_in_queue (h), 2);
buffer = gst_harness_pull (h);
fail_unless (gst_rtp_buffer_map (buffer, GST_MAP_READ, &rtp));
fail_unless_equals_uint64 (GST_BUFFER_PTS (buffer), 0);
fail_unless_equals_uint64 (gst_rtp_buffer_get_timestamp (&rtp), 123);
fail_unless_equals_int (gst_buffer_get_size (buffer), 12 + 2 +
(2 + sizeof (h265_idr_slice_2) - 3) +
(2 + sizeof (h265_idr_slice_1) - 4));
gst_rtp_buffer_unmap (&rtp);
gst_buffer_unref (buffer);
buffer = gst_harness_pull (h);
fail_unless (gst_rtp_buffer_map (buffer, GST_MAP_READ, &rtp));
fail_unless_equals_uint64 (GST_BUFFER_PTS (buffer), 0);
fail_unless_equals_uint64 (gst_rtp_buffer_get_timestamp (&rtp), 123 + 0);
fail_unless_equals_int (gst_buffer_get_size (buffer), 12 + 2 +
(2 + sizeof (h265_idr_slice_2) - 3) +
(2 + sizeof (h265_idr_slice_1) - 4));
gst_rtp_buffer_unmap (&rtp);
gst_buffer_unref (buffer);
gst_harness_teardown (h);
}
GST_END_TEST;
static Suite *
rtph265_suite (void)
@ -636,6 +926,10 @@ rtph265_suite (void)
tcase_add_test (tc_chain, test_rtph265pay_marker_for_flag);
tcase_add_test (tc_chain, test_rtph265pay_marker_for_au);
tcase_add_test (tc_chain, test_rtph265pay_marker_for_fragmented_au);
tcase_add_test (tc_chain, test_rtph265pay_aggregate_two_slices_per_buffer);
tcase_add_test (tc_chain, test_rtph265pay_aggregate_with_aud);
tcase_add_test (tc_chain, test_rtph265pay_aggregate_with_ts_change);
tcase_add_test (tc_chain, test_rtph265pay_aggregate_with_discont);
return s;
}