From 915f418cc4fed2fd5cc08a725874f06ce98b01dc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Olivier=20Cr=C3=AAte?= Date: Tue, 16 Jul 2013 15:35:08 -0400 Subject: [PATCH] adapter: Take account of the skip in gst_adapter_take_buffer_fast() Include regression test --- libs/gst/base/gstadapter.c | 4 ++-- tests/check/libs/adapter.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/libs/gst/base/gstadapter.c b/libs/gst/base/gstadapter.c index a5e7b48..4c3e730 100644 --- a/libs/gst/base/gstadapter.c +++ b/libs/gst/base/gstadapter.c @@ -776,12 +776,12 @@ gst_adapter_take_buffer_fast (GstAdapter * adapter, gsize nbytes) gsize size; cur = item->data; - size = MIN (gst_buffer_get_size (cur), left); + size = MIN (gst_buffer_get_size (cur) - skip, left); GST_LOG_OBJECT (adapter, "appending %" G_GSIZE_FORMAT " bytes" " via region copy", size); if (buffer) - gst_buffer_copy_into (buffer, cur, GST_BUFFER_COPY_MEMORY, 0, size); + gst_buffer_copy_into (buffer, cur, GST_BUFFER_COPY_MEMORY, skip, size); else buffer = gst_buffer_copy_region (cur, GST_BUFFER_COPY_ALL, skip, size); skip = 0; diff --git a/tests/check/libs/adapter.c b/tests/check/libs/adapter.c index dc48385..a99c8e0 100644 --- a/tests/check/libs/adapter.c +++ b/tests/check/libs/adapter.c @@ -858,13 +858,41 @@ GST_START_TEST (test_take_buffer_fast) buffer = gst_adapter_take_buffer_fast (adapter, 30); fail_unless (gst_adapter_available (adapter) == 0); - fail_unless (gst_buffer_n_memory (buffer) == 3); fail_unless (gst_buffer_get_sizes_range (buffer, 0, 1, NULL, NULL) == 5); fail_unless (gst_buffer_get_sizes_range (buffer, 1, 1, NULL, NULL) == 10); fail_unless (gst_buffer_get_sizes_range (buffer, 2, 1, NULL, NULL) == 15); + gst_buffer_unref (buffer); + + fail_unless (gst_adapter_available (adapter) == 0); + + buffer = gst_buffer_new_and_alloc (10); + fail_if (buffer == NULL); + gst_adapter_push (adapter, buffer); + buffer = gst_buffer_new_and_alloc (20); + fail_if (buffer == NULL); + gst_adapter_push (adapter, buffer); + + gst_adapter_flush (adapter, 2); + fail_unless (gst_adapter_available (adapter) == 28); + + buffer = gst_adapter_take_buffer_fast (adapter, 10); + fail_unless (gst_buffer_n_memory (buffer) == 2); + fail_unless (gst_buffer_get_sizes_range (buffer, 0, 1, NULL, NULL) == 8); + fail_unless (gst_buffer_get_sizes_range (buffer, 1, 1, NULL, NULL) == 2); + fail_unless (gst_adapter_available (adapter) == 18); + gst_buffer_unref (buffer); + + buffer = gst_adapter_take_buffer_fast (adapter, 8); + fail_unless (gst_buffer_n_memory (buffer) == 1); + fail_unless (gst_buffer_get_size (buffer) == 8); + fail_unless (gst_adapter_available (adapter) == 10); gst_buffer_unref (buffer); + + gst_adapter_clear (adapter); + fail_unless (gst_adapter_available (adapter) == 0); + g_object_unref (adapter); } -- 2.7.4