summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Huet <nicolas.huet@parrot.com>2016-05-09 15:32:43 +0200
committerTim-Philipp Müller <tim@centricular.com>2016-11-11 18:18:23 +0000
commit9ae9a01fe2d454b954bd53918b53103c3972db02 (patch)
tree6e4c620f5f2b65bbc6afa07feaf5a86854a95136
parent9cd2677791bc25c9ad1885c86b40ac0b3328dd31 (diff)
tests: add unit test for gst_adapter_prev_pts_at_offset()
https://bugzilla.gnome.org/show_bug.cgi?id=765662
-rw-r--r--tests/check/libs/adapter.c129
1 files changed, 129 insertions, 0 deletions
diff --git a/tests/check/libs/adapter.c b/tests/check/libs/adapter.c
index f503245de..9bae8e975 100644
--- a/tests/check/libs/adapter.c
+++ b/tests/check/libs/adapter.c
@@ -641,6 +641,135 @@ GST_START_TEST (test_timestamp)
fail_unless (timestamp == 5 * GST_SECOND);
fail_unless (dist == 50);
+ /* clearing to start a new test */
+ gst_adapter_clear (adapter);
+
+ buffer = gst_buffer_new_and_alloc (100);
+
+ /* push the buffer without timestamp in the adapter */
+ gst_adapter_push (adapter, buffer);
+ avail = gst_adapter_available (adapter);
+ fail_unless_equals_int (avail, 100);
+
+ /* timestamp is now undefined */
+ timestamp = gst_adapter_prev_pts_at_offset (adapter, 0, &dist);
+ fail_unless (timestamp == GST_CLOCK_TIME_NONE);
+ fail_unless_equals_int (dist, 0);
+
+ gst_adapter_flush (adapter, 50);
+ avail = gst_adapter_available (adapter);
+ fail_unless_equals_int (avail, 50);
+
+ /* still undefined, dist changed, though */
+ timestamp = gst_adapter_prev_pts_at_offset (adapter, 0, &dist);
+ fail_unless (timestamp == GST_CLOCK_TIME_NONE);
+ fail_unless_equals_int (dist, 50);
+
+ /* alloc first buffer with timestamp */
+ buffer = gst_buffer_new_and_alloc (100);
+ GST_BUFFER_TIMESTAMP (buffer) = 1 * GST_SECOND;
+
+ /* push in the adapter */
+ gst_adapter_push (adapter, buffer);
+ avail = gst_adapter_available (adapter);
+ fail_unless_equals_int (avail, 150);
+
+ /* timestamp is still undefined at offset 0 */
+ timestamp = gst_adapter_prev_pts_at_offset (adapter, 0, &dist);
+ fail_unless (timestamp == GST_CLOCK_TIME_NONE);
+ fail_unless_equals_int (dist, 50);
+
+ /* timestamp is still undefined at offset 50 */
+ timestamp = gst_adapter_prev_pts_at_offset (adapter, 50, &dist);
+ fail_unless (timestamp == GST_CLOCK_TIME_NONE);
+ fail_unless_equals_int (dist, 100);
+
+ /* timestamp is 1 second at offset 51 */
+ timestamp = gst_adapter_prev_pts_at_offset (adapter, 51, &dist);
+ fail_unless (timestamp == 1 * GST_SECOND);
+ fail_unless_equals_int (dist, 1);
+
+ /* timestamp is still 1 second at offset 100 */
+ timestamp = gst_adapter_prev_pts_at_offset (adapter, 100, &dist);
+ fail_unless (timestamp == 1 * GST_SECOND);
+ fail_unless_equals_int (dist, 50);
+
+ /* flush out the last 50 bytes of the buffer with undefined timestamp */
+ gst_adapter_flush (adapter, 50);
+ avail = gst_adapter_available (adapter);
+ fail_unless_equals_int (avail, 100);
+
+ /* alloc second buffer with timestamp */
+ buffer = gst_buffer_new_and_alloc (100);
+ GST_BUFFER_TIMESTAMP (buffer) = 2 * GST_SECOND;
+
+ /* push in the adapter */
+ gst_adapter_push (adapter, buffer);
+ avail = gst_adapter_available (adapter);
+ fail_unless_equals_int (avail, 200);
+
+ /* alloc third buffer with timestamp */
+ buffer = gst_buffer_new_and_alloc (100);
+ GST_BUFFER_TIMESTAMP (buffer) = 3 * GST_SECOND;
+
+ /* push in the adapter */
+ gst_adapter_push (adapter, buffer);
+ avail = gst_adapter_available (adapter);
+ fail_unless_equals_int (avail, 300);
+
+ /* alloc fourth buffer with timestamp */
+ buffer = gst_buffer_new_and_alloc (100);
+ GST_BUFFER_TIMESTAMP (buffer) = 4 * GST_SECOND;
+
+ /* push in the adapter */
+ gst_adapter_push (adapter, buffer);
+ avail = gst_adapter_available (adapter);
+ fail_unless_equals_int (avail, 400);
+
+ timestamp = gst_adapter_prev_pts_at_offset (adapter, 0, &dist);
+ fail_unless (timestamp == 1 * GST_SECOND);
+ fail_unless_equals_int (dist, 0);
+
+ timestamp = gst_adapter_prev_pts_at_offset (adapter, 100, &dist);
+ fail_unless (timestamp == 1 * GST_SECOND);
+ fail_unless_equals_int (dist, 100);
+
+ timestamp = gst_adapter_prev_pts_at_offset (adapter, 200, &dist);
+ fail_unless (timestamp == 2 * GST_SECOND);
+ fail_unless_equals_int (dist, 100);
+
+ timestamp = gst_adapter_prev_pts_at_offset (adapter, 300, &dist);
+ fail_unless (timestamp == 3 * GST_SECOND);
+ fail_unless_equals_int (dist, 100);
+
+ timestamp = gst_adapter_prev_pts_at_offset (adapter, 400, &dist);
+ fail_unless (timestamp == 4 * GST_SECOND);
+ fail_unless_equals_int (dist, 100);
+
+ gst_adapter_flush (adapter, 50);
+ avail = gst_adapter_available (adapter);
+ fail_unless_equals_int (avail, 350);
+
+ /* We flushed 50 bytes, we are still on the first buffer */
+ timestamp = gst_adapter_prev_pts_at_offset (adapter, 0, &dist);
+ fail_unless (timestamp == 1 * GST_SECOND);
+ fail_unless_equals_int (dist, 50);
+
+ /* As we flushed 50 bytes, offset 100 is on the second buffer */
+ timestamp = gst_adapter_prev_pts_at_offset (adapter, 100, &dist);
+ fail_unless (timestamp == 2 * GST_SECOND);
+ fail_unless_equals_int (dist, 50);
+
+ /* Third buffer */
+ timestamp = gst_adapter_prev_pts_at_offset (adapter, 200, &dist);
+ fail_unless (timestamp == 3 * GST_SECOND);
+ fail_unless_equals_int (dist, 50);
+
+ /* Fourth buffer */
+ timestamp = gst_adapter_prev_pts_at_offset (adapter, 300, &dist);
+ fail_unless (timestamp == 4 * GST_SECOND);
+ fail_unless_equals_int (dist, 50);
+
g_object_unref (adapter);
}