Commit 86d70e89 authored by George Kiagiadakis's avatar George Kiagiadakis

tests/check/libs/audio: add unit tests for planar audio support in gst_audio_buffer_clip()

parent 202eb1ea
......@@ -215,6 +215,45 @@ GST_START_TEST (test_buffer_clip_time_start_and_stop)
GST_END_TEST;
GST_START_TEST (test_buffer_clip_time_start_and_stop_planar)
{
GstSegment s;
GstBuffer *buf;
GstBuffer *ret;
GstAudioMapInfo map;
guint8 *data;
/* Clip start and end */
buf = make_buffer (&data);
gst_buffer_add_audio_meta (buf, GST_AUDIO_FORMAT_S8,
GST_AUDIO_LAYOUT_NON_INTERLEAVED, 1, 1000, NULL);
setup_segment (&s, GST_FORMAT_TIME, 4 * GST_SECOND, 8 * GST_SECOND,
4 * GST_SECOND);
GST_BUFFER_TIMESTAMP (buf) = 2 * GST_SECOND;
GST_BUFFER_DURATION (buf) = 10 * GST_SECOND;
GST_BUFFER_OFFSET (buf) = 200;
GST_BUFFER_OFFSET_END (buf) = 1200;
ret = gst_audio_buffer_clip (buf, &s, 100, 1);
fail_unless (ret != NULL);
fail_unless_equals_int64 (GST_BUFFER_TIMESTAMP (ret), 4 * GST_SECOND);
fail_unless_equals_int64 (GST_BUFFER_DURATION (ret), 4 * GST_SECOND);
fail_unless_equals_int64 (GST_BUFFER_OFFSET (ret), 400);
fail_unless_equals_int64 (GST_BUFFER_OFFSET_END (ret), 800);
gst_audio_buffer_map (ret, &map, GST_MAP_READ);
fail_unless_equals_int (map.n_planes, 1);
fail_unless_equals_int (map.plane_size, 400);
fail_unless_equals_pointer (map.planes[0], data + 200);
gst_audio_buffer_unmap (ret, &map);
gst_buffer_unref (ret);
}
GST_END_TEST;
GST_START_TEST (test_buffer_clip_time_start)
{
GstSegment s;
......@@ -250,6 +289,53 @@ GST_START_TEST (test_buffer_clip_time_start)
GST_END_TEST;
GST_START_TEST (test_buffer_clip_time_start_planar)
{
GstSegment s;
GstBuffer *buf;
GstBuffer *ret;
GstAudioMeta *meta;
GstAudioMapInfo map;
guint8 *data;
/* Clip only start */
buf = make_buffer (&data);
gst_buffer_add_audio_meta (buf, GST_AUDIO_FORMAT_S8,
GST_AUDIO_LAYOUT_NON_INTERLEAVED, 2, 500, NULL);
setup_segment (&s, GST_FORMAT_TIME, 4 * GST_SECOND, 12 * GST_SECOND,
4 * GST_SECOND);
GST_BUFFER_TIMESTAMP (buf) = 2 * GST_SECOND;
GST_BUFFER_DURATION (buf) = 5 * GST_SECOND;
GST_BUFFER_OFFSET (buf) = 200;
GST_BUFFER_OFFSET_END (buf) = 700;
ret = gst_audio_buffer_clip (buf, &s, 100, 2);
fail_unless (ret != NULL);
fail_unless_equals_int64 (GST_BUFFER_TIMESTAMP (ret), 4 * GST_SECOND);
fail_unless_equals_int64 (GST_BUFFER_DURATION (ret), 3 * GST_SECOND);
fail_unless_equals_int64 (GST_BUFFER_OFFSET (ret), 400);
fail_unless_equals_int64 (GST_BUFFER_OFFSET_END (ret), 700);
meta = gst_buffer_get_audio_meta (ret);
fail_unless (meta);
fail_unless_equals_int (meta->channels, 2);
fail_unless_equals_int (meta->samples, 300);
gst_audio_buffer_map (ret, &map, GST_MAP_READ);
fail_unless_equals_int (map.n_planes, 2);
fail_unless_equals_int (map.plane_size, 300);
fail_unless_equals_pointer (map.planes[0], data + 200);
fail_unless_equals_pointer (map.planes[1], data + 700);
gst_audio_buffer_unmap (ret, &map);
gst_buffer_unref (ret);
}
GST_END_TEST;
GST_START_TEST (test_buffer_clip_time_stop)
{
GstSegment s;
......@@ -285,6 +371,53 @@ GST_START_TEST (test_buffer_clip_time_stop)
GST_END_TEST;
GST_START_TEST (test_buffer_clip_time_stop_planar)
{
GstSegment s;
GstBuffer *buf;
GstBuffer *ret;
GstAudioMeta *meta;
GstAudioMapInfo map;
guint8 *data;
/* Clip only stop */
buf = make_buffer (&data);
gst_buffer_add_audio_meta (buf, GST_AUDIO_FORMAT_S8,
GST_AUDIO_LAYOUT_NON_INTERLEAVED, 2, 500, NULL);
setup_segment (&s, GST_FORMAT_TIME, 2 * GST_SECOND, 6 * GST_SECOND,
2 * GST_SECOND);
GST_BUFFER_TIMESTAMP (buf) = 2 * GST_SECOND;
GST_BUFFER_DURATION (buf) = 5 * GST_SECOND;
GST_BUFFER_OFFSET (buf) = 200;
GST_BUFFER_OFFSET_END (buf) = 700;
ret = gst_audio_buffer_clip (buf, &s, 100, 2);
fail_unless (ret != NULL);
fail_unless_equals_int64 (GST_BUFFER_TIMESTAMP (ret), 2 * GST_SECOND);
fail_unless_equals_int64 (GST_BUFFER_DURATION (ret), 4 * GST_SECOND);
fail_unless_equals_int64 (GST_BUFFER_OFFSET (ret), 200);
fail_unless_equals_int64 (GST_BUFFER_OFFSET_END (ret), 600);
meta = gst_buffer_get_audio_meta (ret);
fail_unless (meta);
fail_unless_equals_int (meta->channels, 2);
fail_unless_equals_int (meta->samples, 400);
gst_audio_buffer_map (ret, &map, GST_MAP_READ);
fail_unless_equals_int (map.n_planes, 2);
fail_unless_equals_int (map.plane_size, 400);
fail_unless_equals_pointer (map.planes[0], data);
fail_unless_equals_pointer (map.planes[1], data + 500);
gst_audio_buffer_unmap (ret, &map);
gst_buffer_unref (ret);
}
GST_END_TEST;
GST_START_TEST (test_buffer_clip_time_outside)
{
GstSegment s;
......@@ -441,6 +574,52 @@ GST_START_TEST (test_buffer_clip_samples_start_and_stop)
GST_END_TEST;
GST_START_TEST (test_buffer_clip_samples_start_and_stop_planar)
{
GstSegment s;
GstBuffer *buf;
GstBuffer *ret;
GstAudioMeta *meta;
GstAudioMapInfo map;
guint8 *data;
/* Clip start and end */
buf = make_buffer (&data);
gst_buffer_add_audio_meta (buf, GST_AUDIO_FORMAT_S8,
GST_AUDIO_LAYOUT_NON_INTERLEAVED, 2, 500, NULL);
setup_segment (&s, GST_FORMAT_DEFAULT, 400, 600, 400);
GST_BUFFER_TIMESTAMP (buf) = 2 * GST_SECOND;
GST_BUFFER_DURATION (buf) = 5 * GST_SECOND;
GST_BUFFER_OFFSET (buf) = 200;
GST_BUFFER_OFFSET_END (buf) = 700;
ret = gst_audio_buffer_clip (buf, &s, 100, 2);
fail_unless (ret != NULL);
fail_unless_equals_int64 (GST_BUFFER_TIMESTAMP (ret), 4 * GST_SECOND);
fail_unless_equals_int64 (GST_BUFFER_DURATION (ret), 2 * GST_SECOND);
fail_unless_equals_int64 (GST_BUFFER_OFFSET (ret), 400);
fail_unless_equals_int64 (GST_BUFFER_OFFSET_END (ret), 600);
meta = gst_buffer_get_audio_meta (ret);
fail_unless (meta);
fail_unless_equals_int (meta->channels, 2);
fail_unless_equals_int (meta->samples, 200);
gst_audio_buffer_map (ret, &map, GST_MAP_READ);
fail_unless_equals_int (map.n_planes, 2);
fail_unless_equals_int (map.plane_size, 200);
fail_unless_equals_pointer (map.planes[0], data + 200);
fail_unless_equals_pointer (map.planes[1], data + 700);
gst_audio_buffer_unmap (ret, &map);
gst_buffer_unref (ret);
}
GST_END_TEST;
GST_START_TEST (test_buffer_clip_samples_start)
{
GstSegment s;
......@@ -1180,13 +1359,17 @@ audio_suite (void)
tcase_add_test (tc_chain, test_audio_meta_interleaved);
tcase_add_test (tc_chain, test_buffer_clip_unsupported_format);
tcase_add_test (tc_chain, test_buffer_clip_time_start_and_stop);
tcase_add_test (tc_chain, test_buffer_clip_time_start_and_stop_planar);
tcase_add_test (tc_chain, test_buffer_clip_time_start);
tcase_add_test (tc_chain, test_buffer_clip_time_start_planar);
tcase_add_test (tc_chain, test_buffer_clip_time_stop);
tcase_add_test (tc_chain, test_buffer_clip_time_stop_planar);
tcase_add_test (tc_chain, test_buffer_clip_time_outside);
tcase_add_test (tc_chain, test_buffer_clip_time_start_and_stop_no_meta);
tcase_add_test (tc_chain, test_buffer_clip_time_no_timestamp);
tcase_add_test (tc_chain, test_buffer_clip_time_handles_rounding);
tcase_add_test (tc_chain, test_buffer_clip_samples_start_and_stop);
tcase_add_test (tc_chain, test_buffer_clip_samples_start_and_stop_planar);
tcase_add_test (tc_chain, test_buffer_clip_samples_start);
tcase_add_test (tc_chain, test_buffer_clip_samples_stop);
tcase_add_test (tc_chain, test_buffer_clip_samples_outside);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment