tests: work on porting the unit tests

This commit is contained in:
Wim Taymans 2011-03-28 14:12:24 +02:00
parent d10602fbde
commit 40dc12da3a
41 changed files with 762 additions and 492 deletions

View file

@ -198,6 +198,8 @@ GST_END_TEST;
static GstBufferList *mylist; static GstBufferList *mylist;
static GstCaps *mycaps; static GstCaps *mycaps;
static gint values[] = { 1, 2, 4 };
static GstBufferList * static GstBufferList *
create_buffer_list (void) create_buffer_list (void)
{ {
@ -216,19 +218,19 @@ create_buffer_list (void)
gst_buffer_list_iterator_add_group (it); gst_buffer_list_iterator_add_group (it);
buffer = gst_buffer_new_and_alloc (sizeof (gint)); buffer = gst_buffer_new_and_alloc (sizeof (gint));
*(gint *) GST_BUFFER_DATA (buffer) = 1; gst_buffer_fill (buffer, 0, &values[0], sizeof (gint));
gst_buffer_set_caps (buffer, mycaps); gst_buffer_set_caps (buffer, mycaps);
gst_buffer_list_iterator_add (it, buffer); gst_buffer_list_iterator_add (it, buffer);
gst_buffer_list_iterator_add_group (it); gst_buffer_list_iterator_add_group (it);
buffer = gst_buffer_new_and_alloc (sizeof (gint)); buffer = gst_buffer_new_and_alloc (sizeof (gint));
*(gint *) GST_BUFFER_DATA (buffer) = 2; gst_buffer_fill (buffer, 0, &values[1], sizeof (gint));
gst_buffer_set_caps (buffer, mycaps); gst_buffer_set_caps (buffer, mycaps);
gst_buffer_list_iterator_add (it, buffer); gst_buffer_list_iterator_add (it, buffer);
buffer = gst_buffer_new_and_alloc (sizeof (gint)); buffer = gst_buffer_new_and_alloc (sizeof (gint));
*(gint *) GST_BUFFER_DATA (buffer) = 4; gst_buffer_fill (buffer, 0, &values[2], sizeof (gint));
gst_buffer_set_caps (buffer, mycaps); gst_buffer_set_caps (buffer, mycaps);
gst_buffer_list_iterator_add (it, buffer); gst_buffer_list_iterator_add (it, buffer);
@ -254,7 +256,7 @@ check_buffer_list (GstBufferList * list)
fail_unless (gst_buffer_list_iterator_n_buffers (it) == 1); fail_unless (gst_buffer_list_iterator_n_buffers (it) == 1);
buf = gst_buffer_list_iterator_next (it); buf = gst_buffer_list_iterator_next (it);
fail_if (buf == NULL); fail_if (buf == NULL);
fail_unless (*(gint *) GST_BUFFER_DATA (buf) == 1); gst_check_buffer_data (buf, &values[0], sizeof (gint));
caps = gst_buffer_get_caps (buf); caps = gst_buffer_get_caps (buf);
fail_unless (caps == mycaps); fail_unless (caps == mycaps);
fail_unless (gst_caps_is_equal (caps, mycaps)); fail_unless (gst_caps_is_equal (caps, mycaps));
@ -264,14 +266,14 @@ check_buffer_list (GstBufferList * list)
fail_unless (gst_buffer_list_iterator_n_buffers (it) == 2); fail_unless (gst_buffer_list_iterator_n_buffers (it) == 2);
buf = gst_buffer_list_iterator_next (it); buf = gst_buffer_list_iterator_next (it);
fail_if (buf == NULL); fail_if (buf == NULL);
fail_unless (*(gint *) GST_BUFFER_DATA (buf) == 2); gst_check_buffer_data (buf, &values[1], sizeof (gint));
caps = gst_buffer_get_caps (buf); caps = gst_buffer_get_caps (buf);
fail_unless (caps == mycaps); fail_unless (caps == mycaps);
gst_caps_unref (caps); gst_caps_unref (caps);
buf = gst_buffer_list_iterator_next (it); buf = gst_buffer_list_iterator_next (it);
fail_if (buf == NULL); fail_if (buf == NULL);
fail_unless (*(gint *) GST_BUFFER_DATA (buf) == 4); gst_check_buffer_data (buf, &values[2], sizeof (gint));
caps = gst_buffer_get_caps (buf); caps = gst_buffer_get_caps (buf);
fail_unless (caps == mycaps); fail_unless (caps == mycaps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -329,13 +331,12 @@ callback_function_buffer (GstAppSink * appsink, gpointer p_counter)
/* buffer list has 3 buffers in two groups */ /* buffer list has 3 buffers in two groups */
switch (*p_int_counter) { switch (*p_int_counter) {
case 0: case 0:
fail_unless_equals_int (GST_BUFFER_SIZE (buf), sizeof (gint)); fail_unless_equals_int (gst_buffer_get_size (buf), sizeof (gint));
fail_unless_equals_int ((((gint *) GST_BUFFER_DATA (buf))[0]), 1); gst_check_buffer_data (buf, &values[0], sizeof (gint));
break; break;
case 1: case 1:
fail_unless_equals_int (GST_BUFFER_SIZE (buf), 2 * sizeof (gint)); fail_unless_equals_int (gst_buffer_get_size (buf), 2 * sizeof (gint));
fail_unless_equals_int ((((gint *) GST_BUFFER_DATA (buf))[0]), 2); gst_check_buffer_data (buf, &values[1], 2 * sizeof (gint));
fail_unless_equals_int ((((gint *) GST_BUFFER_DATA (buf))[1]), 4);
break; break;
default: default:
g_warn_if_reached (); g_warn_if_reached ();

View file

@ -449,7 +449,7 @@ verify_convert (const gchar * which, void *in, int inlength,
GST_DEBUG ("Creating buffer of %d bytes", inlength); GST_DEBUG ("Creating buffer of %d bytes", inlength);
inbuffer = gst_buffer_new_and_alloc (inlength); inbuffer = gst_buffer_new_and_alloc (inlength);
memcpy (GST_BUFFER_DATA (inbuffer), in, inlength); gst_buffer_fill (inbuffer, 0, in, inlength);
gst_buffer_set_caps (inbuffer, incaps); gst_buffer_set_caps (inbuffer, incaps);
ASSERT_CAPS_REFCOUNT (incaps, "incaps", 2); ASSERT_CAPS_REFCOUNT (incaps, "incaps", 2);
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
@ -467,8 +467,10 @@ verify_convert (const gchar * which, void *in, int inlength,
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1); ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1);
fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), outlength); fail_unless_equals_int (gst_buffer_get_size (outbuffer), outlength);
gst_check_buffer_data (outbuffer, out, outlength);
#if 0
if (memcmp (GST_BUFFER_DATA (outbuffer), out, outlength) != 0) { if (memcmp (GST_BUFFER_DATA (outbuffer), out, outlength) != 0) {
g_print ("\nInput data:\n"); g_print ("\nInput data:\n");
gst_util_dump_mem (in, inlength); gst_util_dump_mem (in, inlength);
@ -479,6 +481,7 @@ verify_convert (const gchar * which, void *in, int inlength,
} }
fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, outlength) == 0, fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, outlength) == 0,
"failed converting %s", which); "failed converting %s", which);
#endif
/* make sure that the channel positions are not lost */ /* make sure that the channel positions are not lost */
{ {

View file

@ -277,11 +277,12 @@ do_perfect_stream_test (guint rate, guint width, gdouble drop_probability,
} }
/* check buffer size for sanity */ /* check buffer size for sanity */
fail_unless_equals_int (GST_BUFFER_SIZE (buf) % (width / 8), 0); fail_unless_equals_int (gst_buffer_get_size (buf) % (width / 8), 0);
/* check there is actually as much data as there should be */ /* check there is actually as much data as there should be */
num_samples = GST_BUFFER_OFFSET_END (buf) - GST_BUFFER_OFFSET (buf); num_samples = GST_BUFFER_OFFSET_END (buf) - GST_BUFFER_OFFSET (buf);
fail_unless_equals_int (GST_BUFFER_SIZE (buf), num_samples * (width / 8)); fail_unless_equals_int (gst_buffer_get_size (buf),
num_samples * (width / 8));
next_time = GST_BUFFER_TIMESTAMP (buf) + GST_BUFFER_DURATION (buf); next_time = GST_BUFFER_TIMESTAMP (buf) + GST_BUFFER_DURATION (buf);
next_offset = GST_BUFFER_OFFSET_END (buf); next_offset = GST_BUFFER_OFFSET_END (buf);

View file

@ -175,9 +175,8 @@ test_perfect_stream_instance (int inrate, int outrate, int samples,
GstBuffer *inbuffer, *outbuffer; GstBuffer *inbuffer, *outbuffer;
GstCaps *caps; GstCaps *caps;
guint64 offset = 0; guint64 offset = 0;
int i, j; int i, j;
gint16 *p; gint16 *p, *data;
audioresample = setup_audioresample (2, inrate, outrate, 16, FALSE); audioresample = setup_audioresample (2, inrate, outrate, 16, FALSE);
caps = gst_pad_get_negotiated_caps (mysrcpad); caps = gst_pad_get_negotiated_caps (mysrcpad);
@ -198,7 +197,7 @@ test_perfect_stream_instance (int inrate, int outrate, int samples,
gst_buffer_set_caps (inbuffer, caps); gst_buffer_set_caps (inbuffer, caps);
p = (gint16 *) GST_BUFFER_DATA (inbuffer); p = data = gst_buffer_map (inbuffer, NULL, NULL, GST_MAP_WRITE);
/* create a 16 bit signed ramp */ /* create a 16 bit signed ramp */
for (i = 0; i < samples; ++i) { for (i = 0; i < samples; ++i) {
@ -207,6 +206,7 @@ test_perfect_stream_instance (int inrate, int outrate, int samples,
*p = -32767 + i * (65535 / samples); *p = -32767 + i * (65535 / samples);
++p; ++p;
} }
gst_buffer_unmap (inbuffer, data, samples * 4);
/* pushing gives away my reference ... */ /* pushing gives away my reference ... */
fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
@ -261,7 +261,7 @@ test_discont_stream_instance (int inrate, int outrate, int samples,
GstClockTime ints; GstClockTime ints;
int i, j; int i, j;
gint16 *p; gint16 *p, *data;
GST_DEBUG ("inrate:%d outrate:%d samples:%d numbuffers:%d", GST_DEBUG ("inrate:%d outrate:%d samples:%d numbuffers:%d",
inrate, outrate, samples, numbuffers); inrate, outrate, samples, numbuffers);
@ -286,8 +286,7 @@ test_discont_stream_instance (int inrate, int outrate, int samples,
gst_buffer_set_caps (inbuffer, caps); gst_buffer_set_caps (inbuffer, caps);
p = (gint16 *) GST_BUFFER_DATA (inbuffer); p = data = gst_buffer_map (inbuffer, NULL, NULL, GST_MAP_WRITE);
/* create a 16 bit signed ramp */ /* create a 16 bit signed ramp */
for (i = 0; i < samples; ++i) { for (i = 0; i < samples; ++i) {
*p = -32767 + i * (65535 / samples); *p = -32767 + i * (65535 / samples);
@ -295,6 +294,7 @@ test_discont_stream_instance (int inrate, int outrate, int samples,
*p = -32767 + i * (65535 / samples); *p = -32767 + i * (65535 / samples);
++p; ++p;
} }
gst_buffer_unmap (inbuffer, data, samples * 4);
GST_DEBUG ("Sending Buffer time:%" G_GUINT64_FORMAT " duration:%" GST_DEBUG ("Sending Buffer time:%" G_GUINT64_FORMAT " duration:%"
G_GINT64_FORMAT " discont:%d offset:%" G_GUINT64_FORMAT " offset_end:%" G_GINT64_FORMAT " discont:%d offset:%" G_GUINT64_FORMAT " offset_end:%"
@ -351,6 +351,7 @@ GST_START_TEST (test_reuse)
GstEvent *newseg; GstEvent *newseg;
GstBuffer *inbuffer; GstBuffer *inbuffer;
GstCaps *caps; GstCaps *caps;
guint8 *data;
audioresample = setup_audioresample (1, 9343, 48000, 16, FALSE); audioresample = setup_audioresample (1, 9343, 48000, 16, FALSE);
caps = gst_pad_get_negotiated_caps (mysrcpad); caps = gst_pad_get_negotiated_caps (mysrcpad);
@ -364,7 +365,9 @@ GST_START_TEST (test_reuse)
fail_unless (gst_pad_push_event (mysrcpad, newseg) != FALSE); fail_unless (gst_pad_push_event (mysrcpad, newseg) != FALSE);
inbuffer = gst_buffer_new_and_alloc (9343 * 4); inbuffer = gst_buffer_new_and_alloc (9343 * 4);
memset (GST_BUFFER_DATA (inbuffer), 0, GST_BUFFER_SIZE (inbuffer)); data = gst_buffer_map (inbuffer, NULL, NULL, GST_MAP_WRITE);
memset (data, 0, 9343 * 4);
gst_buffer_unmap (inbuffer, data, 9343 * 4);
GST_BUFFER_DURATION (inbuffer) = GST_SECOND; GST_BUFFER_DURATION (inbuffer) = GST_SECOND;
GST_BUFFER_TIMESTAMP (inbuffer) = 0; GST_BUFFER_TIMESTAMP (inbuffer) = 0;
GST_BUFFER_OFFSET (inbuffer) = 0; GST_BUFFER_OFFSET (inbuffer) = 0;
@ -388,7 +391,9 @@ GST_START_TEST (test_reuse)
fail_unless (gst_pad_push_event (mysrcpad, newseg) != FALSE); fail_unless (gst_pad_push_event (mysrcpad, newseg) != FALSE);
inbuffer = gst_buffer_new_and_alloc (9343 * 4); inbuffer = gst_buffer_new_and_alloc (9343 * 4);
memset (GST_BUFFER_DATA (inbuffer), 0, GST_BUFFER_SIZE (inbuffer)); data = gst_buffer_map (inbuffer, NULL, NULL, GST_MAP_WRITE);
memset (data, 0, 9343 * 4);
gst_buffer_unmap (inbuffer, data, 9343 * 4);
GST_BUFFER_DURATION (inbuffer) = GST_SECOND; GST_BUFFER_DURATION (inbuffer) = GST_SECOND;
GST_BUFFER_TIMESTAMP (inbuffer) = 0; GST_BUFFER_TIMESTAMP (inbuffer) = 0;
GST_BUFFER_OFFSET (inbuffer) = 0; GST_BUFFER_OFFSET (inbuffer) = 0;
@ -500,6 +505,7 @@ live_switch_push (int rate, GstCaps * caps)
GstBuffer *inbuffer; GstBuffer *inbuffer;
GstCaps *desired; GstCaps *desired;
GList *l; GList *l;
guint8 *data;
desired = gst_caps_copy (caps); desired = gst_caps_copy (caps);
gst_caps_set_simple (desired, "rate", G_TYPE_INT, rate, NULL); gst_caps_set_simple (desired, "rate", G_TYPE_INT, rate, NULL);
@ -516,7 +522,10 @@ live_switch_push (int rate, GstCaps * caps)
desired, GST_BUFFER_CAPS (inbuffer)); desired, GST_BUFFER_CAPS (inbuffer));
fail_unless (gst_caps_is_equal (desired, GST_BUFFER_CAPS (inbuffer))); fail_unless (gst_caps_is_equal (desired, GST_BUFFER_CAPS (inbuffer)));
memset (GST_BUFFER_DATA (inbuffer), 0, GST_BUFFER_SIZE (inbuffer)); data = gst_buffer_map (inbuffer, NULL, NULL, GST_MAP_WRITE);
memset (data, 0, rate * 4);
gst_buffer_unmap (inbuffer, data, rate * 4);
GST_BUFFER_DURATION (inbuffer) = GST_SECOND; GST_BUFFER_DURATION (inbuffer) = GST_SECOND;
GST_BUFFER_TIMESTAMP (inbuffer) = 0; GST_BUFFER_TIMESTAMP (inbuffer) = 0;
GST_BUFFER_OFFSET (inbuffer) = 0; GST_BUFFER_OFFSET (inbuffer) = 0;
@ -769,7 +778,7 @@ fakesink_handoff_cb (GstElement * object, GstBuffer * buffer, GstPad * pad,
ctx->out_buffer_count++; ctx->out_buffer_count++;
if (ctx->latency == GST_CLOCK_TIME_NONE) { if (ctx->latency == GST_CLOCK_TIME_NONE) {
ctx->latency = 1000 - GST_BUFFER_SIZE (buffer) / 8; ctx->latency = 1000 - gst_buffer_get_size (buffer) / 8;
} }
/* Check if we have a perfectly timestampped stream */ /* Check if we have a perfectly timestampped stream */
@ -781,10 +790,10 @@ fakesink_handoff_cb (GstElement * object, GstBuffer * buffer, GstPad * pad,
/* Check if we have a perfectly offsetted stream */ /* Check if we have a perfectly offsetted stream */
fail_unless (GST_BUFFER_OFFSET_END (buffer) == fail_unless (GST_BUFFER_OFFSET_END (buffer) ==
GST_BUFFER_OFFSET (buffer) + GST_BUFFER_SIZE (buffer) / 8, GST_BUFFER_OFFSET (buffer) + gst_buffer_get_size (buffer) / 8,
"expected offset end %" G_GUINT64_FORMAT " got offset end %" "expected offset end %" G_GUINT64_FORMAT " got offset end %"
G_GUINT64_FORMAT, G_GUINT64_FORMAT,
GST_BUFFER_OFFSET (buffer) + GST_BUFFER_SIZE (buffer) / 8, GST_BUFFER_OFFSET (buffer) + gst_buffer_get_size (buffer) / 8,
GST_BUFFER_OFFSET_END (buffer)); GST_BUFFER_OFFSET_END (buffer));
if (ctx->next_out_off != GST_BUFFER_OFFSET_NONE) { if (ctx->next_out_off != GST_BUFFER_OFFSET_NONE) {
fail_unless (GST_BUFFER_OFFSET (buffer) == ctx->next_out_off, fail_unless (GST_BUFFER_OFFSET (buffer) == ctx->next_out_off,

View file

@ -44,10 +44,12 @@ static const gchar dummytext[] =
static void static void
src_handoff_cb (GstElement * src, GstBuffer * buf, GstPad * pad, gpointer data) src_handoff_cb (GstElement * src, GstBuffer * buf, GstPad * pad, gpointer data)
{ {
GST_BUFFER_DATA (buf) = (guint8 *) dummytext; gst_buffer_take_memory (buf,
GST_BUFFER_SIZE (buf) = sizeof (dummytext); gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY,
(gpointer) dummytext, NULL, sizeof (dummytext), 0,
sizeof (dummytext)));
GST_BUFFER_OFFSET (buf) = 0; GST_BUFFER_OFFSET (buf) = 0;
GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_READONLY);
} }
static void static void

View file

@ -44,10 +44,12 @@ static const gchar dummytext[] =
static void static void
src_handoff_cb (GstElement * src, GstBuffer * buf, GstPad * pad, gpointer data) src_handoff_cb (GstElement * src, GstBuffer * buf, GstPad * pad, gpointer data)
{ {
GST_BUFFER_DATA (buf) = (guint8 *) dummytext; gst_buffer_take_memory (buf,
GST_BUFFER_SIZE (buf) = sizeof (dummytext); gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY,
(gpointer) dummytext, NULL, sizeof (dummytext), 0,
sizeof (dummytext)));
GST_BUFFER_OFFSET (buf) = 0; GST_BUFFER_OFFSET (buf) = 0;
GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_READONLY);
} }
static void static void

View file

@ -313,6 +313,8 @@ GST_START_TEST (test_rgb_to_rgb)
GstStateChangeReturn state_ret; GstStateChangeReturn state_ret;
RGBFormat *from = &conv->from_fmt; RGBFormat *from = &conv->from_fmt;
RGBFormat *to = &conv->to_fmt; RGBFormat *to = &conv->to_fmt;
guint8 *data;
gsize size;
/* trick compiler into thinking from is used, might throw warning /* trick compiler into thinking from is used, might throw warning
* otherwise if the debugging system is disabled */ * otherwise if the debugging system is disabled */
@ -393,10 +395,12 @@ GST_START_TEST (test_rgb_to_rgb)
} }
/* now check the top-left pixel */ /* now check the top-left pixel */
check_rgb_buf (GST_BUFFER_DATA (buf), to->red_mask, data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
check_rgb_buf (data, to->red_mask,
to->green_mask, to->blue_mask, to->alpha_mask, to->green_mask, to->blue_mask, to->alpha_mask,
test_patterns[p].r_expected, test_patterns[p].g_expected, test_patterns[p].r_expected, test_patterns[p].g_expected,
test_patterns[p].b_expected, to->endianness, to->bpp, to->depth); test_patterns[p].b_expected, to->endianness, to->bpp, to->depth);
gst_buffer_unmap (buf, data, size);
gst_buffer_unref (buf); gst_buffer_unref (buf);
buf = NULL; buf = NULL;

View file

@ -94,14 +94,15 @@ cleanup_gdpdepay (GstElement * gdpdepay)
} }
static void static void
gdpdepay_push_per_byte (const gchar * reason, guint8 * bytes, guint length) gdpdepay_push_per_byte (const gchar * reason, const guint8 * bytes,
guint length)
{ {
int i; int i;
GstBuffer *inbuffer; GstBuffer *inbuffer;
for (i = 0; i < length; ++i) { for (i = 0; i < length; ++i) {
inbuffer = gst_buffer_new_and_alloc (1); inbuffer = gst_buffer_new_and_alloc (1);
GST_BUFFER_DATA (inbuffer)[0] = bytes[i]; gst_buffer_fill (inbuffer, 0, &bytes[i], 1);
fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK, fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK,
"%s: failed pushing byte buffer", reason); "%s: failed pushing byte buffer", reason);
} }
@ -148,13 +149,13 @@ GST_START_TEST (test_audio_per_byte)
g_free (payload); g_free (payload);
buffer = gst_buffer_new_and_alloc (4); buffer = gst_buffer_new_and_alloc (4);
memcpy (GST_BUFFER_DATA (buffer), "f00d", 4); gst_buffer_fill (buffer, 0, "f00d", 4);
GST_BUFFER_TIMESTAMP (buffer) = GST_SECOND; GST_BUFFER_TIMESTAMP (buffer) = GST_SECOND;
GST_BUFFER_DURATION (buffer) = GST_SECOND / 10; GST_BUFFER_DURATION (buffer) = GST_SECOND / 10;
fail_unless (pk->header_from_buffer (buffer, 0, &len, &header)); fail_unless (pk->header_from_buffer (buffer, 0, &len, &header));
gdpdepay_push_per_byte ("buffer header", header, len); gdpdepay_push_per_byte ("buffer header", header, len);
fail_unless_equals_int (g_list_length (buffers), 0); fail_unless_equals_int (g_list_length (buffers), 0);
gdpdepay_push_per_byte ("buffer payload", GST_BUFFER_DATA (buffer), gdpdepay_push_per_byte ("buffer payload", (const guint8 *) "f00d",
gst_dp_header_payload_length (header)); gst_dp_header_payload_length (header));
g_free (header); g_free (header);
gst_buffer_unref (buffer); gst_buffer_unref (buffer);
@ -214,21 +215,20 @@ GST_START_TEST (test_audio_in_one_buffer)
&caps_payload)); &caps_payload));
buffer = gst_buffer_new_and_alloc (4); buffer = gst_buffer_new_and_alloc (4);
memcpy (GST_BUFFER_DATA (buffer), "f00d", 4); gst_buffer_fill (buffer, 0, "f00d", 4);
fail_unless (pk->header_from_buffer (buffer, 0, &header_len, &buf_header)); fail_unless (pk->header_from_buffer (buffer, 0, &header_len, &buf_header));
payload_len = gst_dp_header_payload_length (caps_header); payload_len = gst_dp_header_payload_length (caps_header);
inbuffer = gst_buffer_new_and_alloc (2 * GST_DP_HEADER_LENGTH + inbuffer = gst_buffer_new_and_alloc (2 * GST_DP_HEADER_LENGTH +
payload_len + GST_BUFFER_SIZE (buffer)); payload_len + gst_buffer_get_size (buffer));
memcpy (GST_BUFFER_DATA (inbuffer), caps_header, GST_DP_HEADER_LENGTH); gst_buffer_fill (inbuffer, 0, caps_header, GST_DP_HEADER_LENGTH);
i = GST_DP_HEADER_LENGTH; i = GST_DP_HEADER_LENGTH;
memcpy (GST_BUFFER_DATA (inbuffer) + i, caps_payload, payload_len); gst_buffer_fill (inbuffer, i, caps_payload, payload_len);
i += payload_len; i += payload_len;
memcpy (GST_BUFFER_DATA (inbuffer) + i, buf_header, GST_DP_HEADER_LENGTH); gst_buffer_fill (inbuffer, i, buf_header, GST_DP_HEADER_LENGTH);
i += GST_DP_HEADER_LENGTH; i += GST_DP_HEADER_LENGTH;
memcpy (GST_BUFFER_DATA (inbuffer) + i, GST_BUFFER_DATA (buffer), gst_buffer_fill (inbuffer, i, "f00d", 4);
GST_BUFFER_SIZE (buffer));
gst_caps_unref (caps); gst_caps_unref (caps);
gst_buffer_unref (buffer); gst_buffer_unref (buffer);
@ -287,7 +287,8 @@ GST_START_TEST (test_streamheader)
GstPad *srcpad; GstPad *srcpad;
GstElement *gdpdepay; GstElement *gdpdepay;
GstBuffer *buffer, *inbuffer, *outbuffer, *shbuffer; GstBuffer *buffer, *inbuffer, *outbuffer, *shbuffer;
guint8 *caps_header, *caps_payload, *buf_header; guint8 *caps_header, *caps_payload, *buf_header, *data;
gsize size;
guint header_len, payload_len; guint header_len, payload_len;
guint i; guint i;
GstStructure *structure; GstStructure *structure;
@ -315,7 +316,7 @@ GST_START_TEST (test_streamheader)
caps = gst_caps_from_string ("application/x-gst-test-streamheader"); caps = gst_caps_from_string ("application/x-gst-test-streamheader");
structure = gst_caps_get_structure (caps, 0); structure = gst_caps_get_structure (caps, 0);
buffer = gst_buffer_new_and_alloc (4); buffer = gst_buffer_new_and_alloc (4);
memcpy (GST_BUFFER_DATA (buffer), "f00d", 4); gst_buffer_fill (buffer, 0, "f00d", 4);
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_IN_CAPS); GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_IN_CAPS);
g_value_init (&array, GST_TYPE_ARRAY); g_value_init (&array, GST_TYPE_ARRAY);
g_value_init (&value, GST_TYPE_BUFFER); g_value_init (&value, GST_TYPE_BUFFER);
@ -338,16 +339,17 @@ GST_START_TEST (test_streamheader)
payload_len = gst_dp_header_payload_length (caps_header); payload_len = gst_dp_header_payload_length (caps_header);
data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
inbuffer = gst_buffer_new_and_alloc (2 * GST_DP_HEADER_LENGTH + inbuffer = gst_buffer_new_and_alloc (2 * GST_DP_HEADER_LENGTH +
payload_len + GST_BUFFER_SIZE (buffer)); payload_len + size);
memcpy (GST_BUFFER_DATA (inbuffer), caps_header, GST_DP_HEADER_LENGTH); gst_buffer_fill (inbuffer, 0, caps_header, GST_DP_HEADER_LENGTH);
i = GST_DP_HEADER_LENGTH; i = GST_DP_HEADER_LENGTH;
memcpy (GST_BUFFER_DATA (inbuffer) + i, caps_payload, payload_len); gst_buffer_fill (inbuffer, i, caps_payload, payload_len);
i += payload_len; i += payload_len;
memcpy (GST_BUFFER_DATA (inbuffer) + i, buf_header, GST_DP_HEADER_LENGTH); gst_buffer_fill (inbuffer, i, buf_header, GST_DP_HEADER_LENGTH);
i += GST_DP_HEADER_LENGTH; i += GST_DP_HEADER_LENGTH;
memcpy (GST_BUFFER_DATA (inbuffer) + i, GST_BUFFER_DATA (buffer), gst_buffer_fill (inbuffer, i, data, size);
GST_BUFFER_SIZE (buffer)); gst_buffer_unmap (buffer, data, size);
gst_caps_unref (caps); gst_caps_unref (caps);
gst_buffer_unref (buffer); gst_buffer_unref (buffer);

View file

@ -142,7 +142,7 @@ GST_START_TEST (test_audio)
buffers = g_list_remove (buffers, outbuffer); buffers = g_list_remove (buffers, outbuffer);
ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 2); ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 2);
length = GST_DP_HEADER_LENGTH + (strlen (caps_string) + 1); length = GST_DP_HEADER_LENGTH + (strlen (caps_string) + 1);
fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), length); fail_unless_equals_int (gst_buffer_get_size (outbuffer), length);
gst_buffer_unref (outbuffer); gst_buffer_unref (outbuffer);
/* the third buffer is the GDP buffer for our pushed buffer */ /* the third buffer is the GDP buffer for our pushed buffer */
@ -150,7 +150,7 @@ GST_START_TEST (test_audio)
buffers = g_list_remove (buffers, outbuffer); buffers = g_list_remove (buffers, outbuffer);
ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1); ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1);
length = GST_DP_HEADER_LENGTH + 4; length = GST_DP_HEADER_LENGTH + 4;
fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), length); fail_unless_equals_int (gst_buffer_get_size (outbuffer), length);
gst_buffer_unref (outbuffer); gst_buffer_unref (outbuffer);
/* second buffer */ /* second buffer */
@ -170,7 +170,7 @@ GST_START_TEST (test_audio)
/* the third output buffer is data */ /* the third output buffer is data */
length = GST_DP_HEADER_LENGTH + 4; length = GST_DP_HEADER_LENGTH + 4;
fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), length); fail_unless_equals_int (gst_buffer_get_size (outbuffer), length);
gst_buffer_unref (outbuffer); gst_buffer_unref (outbuffer);
/* a third buffer without caps set explicitly; should work */ /* a third buffer without caps set explicitly; should work */
@ -189,7 +189,7 @@ GST_START_TEST (test_audio)
/* the fourth output buffer is data */ /* the fourth output buffer is data */
length = GST_DP_HEADER_LENGTH + 4; length = GST_DP_HEADER_LENGTH + 4;
fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), length); fail_unless_equals_int (gst_buffer_get_size (outbuffer), length);
gst_buffer_unref (outbuffer); gst_buffer_unref (outbuffer);
@ -263,7 +263,7 @@ GST_START_TEST (test_streamheader)
GST_DEBUG ("first buffer"); GST_DEBUG ("first buffer");
inbuffer = gst_buffer_new_and_alloc (4); inbuffer = gst_buffer_new_and_alloc (4);
memcpy (GST_BUFFER_DATA (inbuffer), "head", 4); gst_buffer_fill (inbuffer, 0, "head", 4);
caps = gst_caps_from_string ("application/x-gst-test-streamheader"); caps = gst_caps_from_string ("application/x-gst-test-streamheader");
structure = gst_caps_get_structure (caps, 0); structure = gst_caps_get_structure (caps, 0);
GST_BUFFER_FLAG_SET (inbuffer, GST_BUFFER_FLAG_IN_CAPS); GST_BUFFER_FLAG_SET (inbuffer, GST_BUFFER_FLAG_IN_CAPS);
@ -316,7 +316,7 @@ GST_START_TEST (test_streamheader)
buffers = g_list_remove (buffers, outbuffer); buffers = g_list_remove (buffers, outbuffer);
ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 2); ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 2);
length = GST_DP_HEADER_LENGTH + (strlen (caps_string) + 1); length = GST_DP_HEADER_LENGTH + (strlen (caps_string) + 1);
fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), length); fail_unless_equals_int (gst_buffer_get_size (outbuffer), length);
gst_buffer_unref (outbuffer); gst_buffer_unref (outbuffer);
/* the third buffer is the GDP buffer for our pushed buffer */ /* the third buffer is the GDP buffer for our pushed buffer */
@ -324,7 +324,7 @@ GST_START_TEST (test_streamheader)
buffers = g_list_remove (buffers, outbuffer); buffers = g_list_remove (buffers, outbuffer);
ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1); ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1);
length = GST_DP_HEADER_LENGTH + 4; length = GST_DP_HEADER_LENGTH + 4;
fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), length); fail_unless_equals_int (gst_buffer_get_size (outbuffer), length);
gst_buffer_unref (outbuffer); gst_buffer_unref (outbuffer);
/* second buffer */ /* second buffer */
@ -344,7 +344,7 @@ GST_START_TEST (test_streamheader)
/* the third output buffer is data */ /* the third output buffer is data */
length = GST_DP_HEADER_LENGTH + 4; length = GST_DP_HEADER_LENGTH + 4;
fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), length); fail_unless_equals_int (gst_buffer_get_size (outbuffer), length);
gst_buffer_unref (outbuffer); gst_buffer_unref (outbuffer);
/* a third buffer without caps set explicitly; should work */ /* a third buffer without caps set explicitly; should work */
@ -363,7 +363,7 @@ GST_START_TEST (test_streamheader)
/* the fourth output buffer is data */ /* the fourth output buffer is data */
length = GST_DP_HEADER_LENGTH + 4; length = GST_DP_HEADER_LENGTH + 4;
fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), length); fail_unless_equals_int (gst_buffer_get_size (outbuffer), length);
gst_buffer_unref (outbuffer); gst_buffer_unref (outbuffer);
@ -464,6 +464,8 @@ GST_START_TEST (test_crc)
GstEvent *event; GstEvent *event;
gchar *caps_string; gchar *caps_string;
gint length; gint length;
guint8 *data;
gsize size;
guint16 crc_calculated, crc_read; guint16 crc_calculated, crc_read;
gdppay = setup_gdppay (); gdppay = setup_gdppay ();
@ -503,16 +505,18 @@ GST_START_TEST (test_crc)
/* verify the header checksum */ /* verify the header checksum */
/* CRC's start at 58 in the header */ /* CRC's start at 58 in the header */
crc_calculated = gst_dp_crc (GST_BUFFER_DATA (outbuffer), 58); data = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READWRITE);
crc_read = GST_READ_UINT16_BE (GST_BUFFER_DATA (outbuffer) + 58); crc_calculated = gst_dp_crc (data, 58);
crc_read = GST_READ_UINT16_BE (data + 58);
fail_unless_equals_int (crc_calculated, crc_read); fail_unless_equals_int (crc_calculated, crc_read);
/* change a byte in the header and verify that the checksum now fails */ /* change a byte in the header and verify that the checksum now fails */
GST_BUFFER_DATA (outbuffer)[0] = 0xff; data[0] = 0xff;
crc_calculated = gst_dp_crc (GST_BUFFER_DATA (outbuffer), 58); crc_calculated = gst_dp_crc (data, 58);
fail_if (crc_calculated == crc_read, fail_if (crc_calculated == crc_read,
"Introducing a byte error in the header should make the checksum fail"); "Introducing a byte error in the header should make the checksum fail");
gst_buffer_unmap (outbuffer, data, size);
gst_buffer_unref (outbuffer); gst_buffer_unref (outbuffer);
/* second buffer is the serialized caps; /* second buffer is the serialized caps;
@ -521,7 +525,7 @@ GST_START_TEST (test_crc)
buffers = g_list_remove (buffers, outbuffer); buffers = g_list_remove (buffers, outbuffer);
ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 2); ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 2);
length = GST_DP_HEADER_LENGTH + (strlen (caps_string) + 1); length = GST_DP_HEADER_LENGTH + (strlen (caps_string) + 1);
fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), length); fail_unless_equals_int (gst_buffer_get_size (outbuffer), length);
gst_buffer_unref (outbuffer); gst_buffer_unref (outbuffer);
/* the third buffer is the GDP buffer for our pushed buffer */ /* the third buffer is the GDP buffer for our pushed buffer */
@ -529,7 +533,7 @@ GST_START_TEST (test_crc)
buffers = g_list_remove (buffers, outbuffer); buffers = g_list_remove (buffers, outbuffer);
ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1); ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1);
length = GST_DP_HEADER_LENGTH + 4; length = GST_DP_HEADER_LENGTH + 4;
fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), length); fail_unless_equals_int (gst_buffer_get_size (outbuffer), length);
gst_buffer_unref (outbuffer); gst_buffer_unref (outbuffer);
fail_unless (gst_element_set_state (gdppay, fail_unless (gst_element_set_state (gdppay,

View file

@ -87,9 +87,12 @@ cleanup_gnomevfssink (GstElement * gnomevfssink)
G_STMT_START { \ G_STMT_START { \
GstBuffer *buf = gst_buffer_new_and_alloc(num_bytes); \ GstBuffer *buf = gst_buffer_new_and_alloc(num_bytes); \
GRand *rand = g_rand_new_with_seed (num_bytes); \ GRand *rand = g_rand_new_with_seed (num_bytes); \
guint i; \ gsize i; \
guint8 *data; \
data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE); \
for (i = 0; i < num_bytes; ++i) \ for (i = 0; i < num_bytes; ++i) \
GST_BUFFER_DATA(buf)[i] = (g_rand_int (rand) >> 24) & 0xff; \ data[i] = (g_rand_int (rand) >> 24) & 0xff; \
gst_buffer_unmap (buf, data, num_bytes); \
fail_unless_equals_int (gst_pad_push (mysrcpad, buf), GST_FLOW_OK); \ fail_unless_equals_int (gst_pad_push (mysrcpad, buf), GST_FLOW_OK); \
g_rand_free (rand); \ g_rand_free (rand); \
} G_STMT_END } G_STMT_END

View file

@ -121,7 +121,7 @@ GST_START_TEST (test_add_client)
buffer = gst_buffer_new_and_alloc (4); buffer = gst_buffer_new_and_alloc (4);
gst_buffer_set_caps (buffer, caps); gst_buffer_set_caps (buffer, caps);
ASSERT_CAPS_REFCOUNT (caps, "caps", 2); ASSERT_CAPS_REFCOUNT (caps, "caps", 2);
memcpy (GST_BUFFER_DATA (buffer), "dead", 4); gst_buffer_fill (buffer, 0, "dead", 4);
fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK); fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK);
GST_DEBUG ("reading"); GST_DEBUG ("reading");
@ -176,10 +176,10 @@ gst_multifdsink_create_streamheader (const gchar * data1,
* buffers */ * buffers */
*hbuf1 = gst_buffer_new_and_alloc (size1); *hbuf1 = gst_buffer_new_and_alloc (size1);
GST_BUFFER_FLAG_SET (*hbuf1, GST_BUFFER_FLAG_IN_CAPS); GST_BUFFER_FLAG_SET (*hbuf1, GST_BUFFER_FLAG_IN_CAPS);
memcpy (GST_BUFFER_DATA (*hbuf1), data1, size1); gst_buffer_fill (*hbuf1, 0, data1, size1);
*hbuf2 = gst_buffer_new_and_alloc (size2); *hbuf2 = gst_buffer_new_and_alloc (size2);
GST_BUFFER_FLAG_SET (*hbuf2, GST_BUFFER_FLAG_IN_CAPS); GST_BUFFER_FLAG_SET (*hbuf2, GST_BUFFER_FLAG_IN_CAPS);
memcpy (GST_BUFFER_DATA (*hbuf2), data2, size2); gst_buffer_fill (*hbuf2, 0, data2, size2);
g_value_init (&array, GST_TYPE_ARRAY); g_value_init (&array, GST_TYPE_ARRAY);
@ -265,7 +265,7 @@ GST_START_TEST (test_streamheader)
/* push a non-IN_CAPS buffer, this should trigger the client receiving the /* push a non-IN_CAPS buffer, this should trigger the client receiving the
* first three buffers */ * first three buffers */
buf = gst_buffer_new_and_alloc (4); buf = gst_buffer_new_and_alloc (4);
memcpy (GST_BUFFER_DATA (buf), "f00d", 4); gst_buffer_fill (buf, 0, "f00d", 4);
gst_pad_push (mysrcpad, buf); gst_pad_push (mysrcpad, buf);
fail_unless_read ("first client", pfd1[0], 4, "babe"); fail_unless_read ("first client", pfd1[0], 4, "babe");
@ -281,7 +281,7 @@ GST_START_TEST (test_streamheader)
/* now push another buffer, which will trigger streamheader for second /* now push another buffer, which will trigger streamheader for second
* client */ * client */
buf = gst_buffer_new_and_alloc (4); buf = gst_buffer_new_and_alloc (4);
memcpy (GST_BUFFER_DATA (buf), "deaf", 4); gst_buffer_fill (buf, 0, "deaf", 4);
gst_pad_push (mysrcpad, buf); gst_pad_push (mysrcpad, buf);
fail_unless_read ("first client", pfd1[0], 4, "deaf"); fail_unless_read ("first client", pfd1[0], 4, "deaf");
@ -360,7 +360,7 @@ GST_START_TEST (test_change_streamheader)
/* now push a buffer and read */ /* now push a buffer and read */
buf = gst_buffer_new_and_alloc (4); buf = gst_buffer_new_and_alloc (4);
memcpy (GST_BUFFER_DATA (buf), "f00d", 4); gst_buffer_fill (buf, 0, "f00d", 4);
gst_pad_push (mysrcpad, buf); gst_pad_push (mysrcpad, buf);
fail_unless_read ("change: first client", pfd1[0], 5, "first"); fail_unless_read ("change: first client", pfd1[0], 5, "first");
@ -400,7 +400,7 @@ GST_START_TEST (test_change_streamheader)
/* now push another buffer, which will trigger streamheader for second /* now push another buffer, which will trigger streamheader for second
* client, but should also send new streamheaders to first client */ * client, but should also send new streamheaders to first client */
buf = gst_buffer_new_and_alloc (8); buf = gst_buffer_new_and_alloc (8);
memcpy (GST_BUFFER_DATA (buf), "deadbabe", 8); gst_buffer_fill (buf, 0, "deadbabe", 8);
gst_pad_push (mysrcpad, buf); gst_pad_push (mysrcpad, buf);
fail_unless_read ("first client", pfd1[0], 6, "second"); fail_unless_read ("first client", pfd1[0], 6, "second");
@ -469,8 +469,9 @@ GST_START_TEST (test_burst_client_bytes)
gst_buffer_set_caps (buffer, caps); gst_buffer_set_caps (buffer, caps);
/* copy some id */ /* copy some id */
data = (gchar *) GST_BUFFER_DATA (buffer); data = gst_buffer_map (buffer, NULL, NULL, GST_MAP_WRITE);
g_snprintf (data, 16, "deadbee%08x", i); g_snprintf (data, 16, "deadbee%08x", i);
gst_buffer_unmap (buffer, data, 16);
fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK); fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK);
} }
@ -494,8 +495,9 @@ GST_START_TEST (test_burst_client_bytes)
gst_buffer_set_caps (buffer, caps); gst_buffer_set_caps (buffer, caps);
/* copy some id */ /* copy some id */
data = (gchar *) GST_BUFFER_DATA (buffer); data = gst_buffer_map (buffer, NULL, NULL, GST_MAP_WRITE);
g_snprintf (data, 16, "deadbee%08x", i); g_snprintf (data, 16, "deadbee%08x", i);
gst_buffer_unmap (buffer, data, 16);
fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK); fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK);
} }
@ -586,8 +588,9 @@ GST_START_TEST (test_burst_client_bytes_keyframe)
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT); GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT);
/* copy some id */ /* copy some id */
data = (gchar *) GST_BUFFER_DATA (buffer); data = gst_buffer_map (buffer, NULL, NULL, GST_MAP_WRITE);
g_snprintf (data, 16, "deadbee%08x", i); g_snprintf (data, 16, "deadbee%08x", i);
gst_buffer_unmap (buffer, data, 16);
fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK); fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK);
} }
@ -612,8 +615,9 @@ GST_START_TEST (test_burst_client_bytes_keyframe)
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT); GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT);
/* copy some id */ /* copy some id */
data = (gchar *) GST_BUFFER_DATA (buffer); data = gst_buffer_map (buffer, NULL, NULL, GST_MAP_WRITE);
g_snprintf (data, 16, "deadbee%08x", i); g_snprintf (data, 16, "deadbee%08x", i);
gst_buffer_unmap (buffer, data, 16);
fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK); fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK);
} }
@ -701,8 +705,9 @@ GST_START_TEST (test_burst_client_bytes_with_keyframe)
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT); GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT);
/* copy some id */ /* copy some id */
data = (gchar *) GST_BUFFER_DATA (buffer); data = gst_buffer_map (buffer, NULL, NULL, GST_MAP_WRITE);
g_snprintf (data, 16, "deadbee%08x", i); g_snprintf (data, 16, "deadbee%08x", i);
gst_buffer_unmap (buffer, data, 16);
fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK); fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK);
} }
@ -727,8 +732,9 @@ GST_START_TEST (test_burst_client_bytes_with_keyframe)
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT); GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT);
/* copy some id */ /* copy some id */
data = (gchar *) GST_BUFFER_DATA (buffer); data = gst_buffer_map (buffer, NULL, NULL, GST_MAP_WRITE);
g_snprintf (data, 16, "deadbee%08x", i); g_snprintf (data, 16, "deadbee%08x", i);
gst_buffer_unmap (buffer, data, 16);
fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK); fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK);
} }
@ -813,8 +819,9 @@ GST_START_TEST (test_client_next_keyframe)
gst_buffer_set_caps (buffer, caps); gst_buffer_set_caps (buffer, caps);
/* copy some id */ /* copy some id */
data = (gchar *) GST_BUFFER_DATA (buffer); data = gst_buffer_map (buffer, NULL, NULL, GST_MAP_WRITE);
g_snprintf (data, 16, "deadbee%08x", i); g_snprintf (data, 16, "deadbee%08x", i);
gst_buffer_unmap (buffer, data, 16);
if (i > 0) if (i > 0)
GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT); GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT);

View file

@ -472,14 +472,15 @@ gst_red_video_src_create (GstPushSrc * src, GstBuffer ** p_buf)
GstCaps *caps; GstCaps *caps;
guint8 *data; guint8 *data;
guint w = 64, h = 64; guint w = 64, h = 64;
guint size; gsize size;
size = w * h * 3 / 2; size = w * h * 3 / 2;
buf = gst_buffer_new_and_alloc (size); buf = gst_buffer_new_and_alloc (size);
data = GST_BUFFER_DATA (buf); data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
memset (data, 76, w * h); memset (data, 76, w * h);
memset (data + (w * h), 85, (w * h) / 4); memset (data + (w * h), 85, (w * h) / 4);
memset (data + (w * h) + ((w * h) / 4), 255, (w * h) / 4); memset (data + (w * h) + ((w * h) / 4), 255, (w * h) / 4);
gst_buffer_unmap (buf, data, size);
caps = gst_caps_new_simple ("video/x-raw-yuv", "format", GST_TYPE_FOURCC, caps = gst_caps_new_simple ("video/x-raw-yuv", "format", GST_TYPE_FOURCC,
GST_MAKE_FOURCC ('I', '4', '2', '0'), "width", G_TYPE_INT, w, "height", GST_MAKE_FOURCC ('I', '4', '2', '0'), "width", G_TYPE_INT, w, "height",
@ -582,9 +583,12 @@ gst_codec_src_create (GstPushSrc * src, GstBuffer ** p_buf)
{ {
GstBuffer *buf; GstBuffer *buf;
GstCaps *caps; GstCaps *caps;
guint8 *data;
buf = gst_buffer_new_and_alloc (20); buf = gst_buffer_new_and_alloc (20);
memset (GST_BUFFER_DATA (buf), 0, GST_BUFFER_SIZE (buf)); data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
memset (data, 0, 20);
gst_buffer_unmap (buf, data, 20);
caps = gst_caps_new_simple ("application/x-codec", NULL); caps = gst_caps_new_simple ("application/x-codec", NULL);
gst_buffer_set_caps (buf, caps); gst_buffer_set_caps (buf, caps);

View file

@ -588,10 +588,11 @@ gst_red_video_src_create (GstPushSrc * src, GstBuffer ** p_buf)
size = w * h * 3 / 2; size = w * h * 3 / 2;
buf = gst_buffer_new_and_alloc (size); buf = gst_buffer_new_and_alloc (size);
data = GST_BUFFER_DATA (buf); data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
memset (data, 76, w * h); memset (data, 76, w * h);
memset (data + (w * h), 85, (w * h) / 4); memset (data + (w * h), 85, (w * h) / 4);
memset (data + (w * h) + ((w * h) / 4), 255, (w * h) / 4); memset (data + (w * h) + ((w * h) / 4), 255, (w * h) / 4);
gst_buffer_unmap (buf, data, size);
caps = gst_caps_new_simple ("video/x-raw-yuv", "format", GST_TYPE_FOURCC, caps = gst_caps_new_simple ("video/x-raw-yuv", "format", GST_TYPE_FOURCC,
GST_MAKE_FOURCC ('I', '4', '2', '0'), "width", G_TYPE_INT, w, "height", GST_MAKE_FOURCC ('I', '4', '2', '0'), "width", G_TYPE_INT, w, "height",
@ -694,9 +695,12 @@ gst_codec_src_create (GstPushSrc * src, GstBuffer ** p_buf)
{ {
GstBuffer *buf; GstBuffer *buf;
GstCaps *caps; GstCaps *caps;
guint8 *data;
buf = gst_buffer_new_and_alloc (20); buf = gst_buffer_new_and_alloc (20);
memset (GST_BUFFER_DATA (buf), 0, GST_BUFFER_SIZE (buf)); data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
memset (data, 0, 20);
gst_buffer_unmap (buf, data, 20);
caps = gst_caps_new_simple ("application/x-codec", NULL); caps = gst_caps_new_simple ("application/x-codec", NULL);
gst_buffer_set_caps (buf, caps); gst_buffer_set_caps (buf, caps);

View file

@ -43,11 +43,14 @@ static GstBuffer *
buffer_from_static_string (const gchar * s) buffer_from_static_string (const gchar * s)
{ {
GstBuffer *buf; GstBuffer *buf;
gsize len;
len = strlen (s);
buf = gst_buffer_new (); buf = gst_buffer_new ();
GST_BUFFER_DATA (buf) = (guint8 *) s; gst_buffer_take_memory (buf,
GST_BUFFER_SIZE (buf) = strlen (s); gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY,
GST_BUFFER_FLAG_SET (buf, GST_BUFFER_FLAG_READONLY); (gpointer) s, NULL, len, 0, len));
return buf; return buf;
} }
@ -209,7 +212,7 @@ test_srt_do_test (SubParseInputChunk * input, guint start_idx, guint num)
const GstStructure *buffer_caps_struct; const GstStructure *buffer_caps_struct;
GstBuffer *buf; GstBuffer *buf;
gchar *out; gchar *out;
guint out_size; gsize out_size;
buf = g_list_nth_data (buffers, n - start_idx); buf = g_list_nth_data (buffers, n - start_idx);
fail_unless (buf != NULL); fail_unless (buf != NULL);
@ -218,8 +221,8 @@ test_srt_do_test (SubParseInputChunk * input, guint start_idx, guint num)
fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (buf), input[n].from_ts); fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (buf), input[n].from_ts);
fail_unless_equals_uint64 (GST_BUFFER_DURATION (buf), fail_unless_equals_uint64 (GST_BUFFER_DURATION (buf),
input[n].to_ts - input[n].from_ts); input[n].to_ts - input[n].from_ts);
out = (gchar *) GST_BUFFER_DATA (buf);
out_size = GST_BUFFER_SIZE (buf); out = gst_buffer_map (buf, &out_size, NULL, GST_MAP_READ);
/* shouldn't have trailing newline characters */ /* shouldn't have trailing newline characters */
fail_if (out_size > 0 && out[out_size - 1] == '\n'); fail_if (out_size > 0 && out[out_size - 1] == '\n');
/* shouldn't include NUL-terminator in data size */ /* shouldn't include NUL-terminator in data size */
@ -228,6 +231,7 @@ test_srt_do_test (SubParseInputChunk * input, guint start_idx, guint num)
fail_unless_equals_int (out[out_size], '\0'); fail_unless_equals_int (out[out_size], '\0');
/* make sure out string matches expected string */ /* make sure out string matches expected string */
fail_unless_equals_string (out, input[n].out); fail_unless_equals_string (out, input[n].out);
gst_buffer_unmap (buf, out, out_size);
/* check caps */ /* check caps */
fail_unless (GST_BUFFER_CAPS (buf) != NULL); fail_unless (GST_BUFFER_CAPS (buf) != NULL);
buffer_caps_struct = gst_caps_get_structure (GST_BUFFER_CAPS (buf), 0); buffer_caps_struct = gst_caps_get_structure (GST_BUFFER_CAPS (buf), 0);
@ -288,7 +292,7 @@ do_test (SubParseInputChunk * input, guint num, const gchar * media_type)
const GstStructure *buffer_caps_struct; const GstStructure *buffer_caps_struct;
GstBuffer *buf; GstBuffer *buf;
gchar *out; gchar *out;
guint out_size; gsize out_size;
buf = g_list_nth_data (buffers, n); buf = g_list_nth_data (buffers, n);
fail_unless (buf != NULL); fail_unless (buf != NULL);
@ -305,8 +309,7 @@ do_test (SubParseInputChunk * input, guint num, const gchar * media_type)
input[n].to_ts - input[n].from_ts); input[n].to_ts - input[n].from_ts);
} }
out = (gchar *) GST_BUFFER_DATA (buf); out = gst_buffer_map (buf, &out_size, NULL, GST_MAP_READ);
out_size = GST_BUFFER_SIZE (buf);
/* shouldn't have trailing newline characters */ /* shouldn't have trailing newline characters */
fail_if (out_size > 0 && out[out_size - 1] == '\n'); fail_if (out_size > 0 && out[out_size - 1] == '\n');
/* shouldn't include NUL-terminator in data size */ /* shouldn't include NUL-terminator in data size */
@ -315,6 +318,7 @@ do_test (SubParseInputChunk * input, guint num, const gchar * media_type)
fail_unless_equals_int (out[out_size], '\0'); fail_unless_equals_int (out[out_size], '\0');
/* make sure out string matches expected string */ /* make sure out string matches expected string */
fail_unless_equals_string (out, input[n].out); fail_unless_equals_string (out, input[n].out);
gst_buffer_unmap (buf, out, out_size);
/* check caps */ /* check caps */
fail_unless (GST_BUFFER_CAPS (buf) != NULL); fail_unless (GST_BUFFER_CAPS (buf) != NULL);
buffer_caps_struct = gst_caps_get_structure (GST_BUFFER_CAPS (buf), 0); buffer_caps_struct = gst_caps_get_structure (GST_BUFFER_CAPS (buf), 0);

View file

@ -164,6 +164,8 @@ buffer_is_all_black (GstBuffer * buf)
{ {
GstStructure *s; GstStructure *s;
gint x, y, w, h; gint x, y, w, h;
guint8 *data;
gsize size;
fail_unless (buf != NULL); fail_unless (buf != NULL);
fail_unless (GST_BUFFER_CAPS (buf) != NULL); fail_unless (GST_BUFFER_CAPS (buf) != NULL);
@ -172,16 +174,18 @@ buffer_is_all_black (GstBuffer * buf)
fail_unless (gst_structure_get_int (s, "width", &w)); fail_unless (gst_structure_get_int (s, "width", &w));
fail_unless (gst_structure_get_int (s, "height", &h)); fail_unless (gst_structure_get_int (s, "height", &h));
data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
for (y = 0; y < h; ++y) { for (y = 0; y < h; ++y) {
guint8 *data = GST_BUFFER_DATA (buf) + (y * GST_ROUND_UP_4 (w)); guint8 *ptr = data + (y * GST_ROUND_UP_4 (w));
for (x = 0; x < w; ++x) { for (x = 0; x < w; ++x) {
if (data[x] != 0x00) { if (ptr[x] != 0x00) {
GST_LOG ("non-black pixel at (x,y) %d,%d", x, y); GST_LOG ("non-black pixel at (x,y) %d,%d", x, y);
return FALSE; return FALSE;
} }
} }
} }
gst_buffer_unmap (buf, data, size);
return TRUE; return TRUE;
} }
@ -193,6 +197,7 @@ create_black_buffer (const gchar * caps_string)
GstBuffer *buffer; GstBuffer *buffer;
GstCaps *caps; GstCaps *caps;
gint w, h, size; gint w, h, size;
guint8 *data;
fail_unless (caps_string != NULL); fail_unless (caps_string != NULL);
@ -207,9 +212,12 @@ create_black_buffer (const gchar * caps_string)
GST_LOG ("creating buffer (%dx%d)", w, h); GST_LOG ("creating buffer (%dx%d)", w, h);
size = I420_SIZE (w, h); size = I420_SIZE (w, h);
buffer = gst_buffer_new_and_alloc (size); buffer = gst_buffer_new_and_alloc (size);
data = gst_buffer_map (buffer, NULL, NULL, GST_MAP_WRITE);
/* we're only checking the Y plane later, so just zero it all out, /* we're only checking the Y plane later, so just zero it all out,
* even if it's not the blackest black there is */ * even if it's not the blackest black there is */
memset (GST_BUFFER_DATA (buffer), 0, size); memset (data, 0, size);
gst_buffer_unmap (buffer, data, size);
gst_buffer_set_caps (buffer, caps); gst_buffer_set_caps (buffer, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -232,7 +240,7 @@ create_text_buffer (const gchar * txt, GstClockTime ts, GstClockTime duration)
txt_len = strlen (txt); txt_len = strlen (txt);
buffer = gst_buffer_new_and_alloc (txt_len); buffer = gst_buffer_new_and_alloc (txt_len);
memcpy (GST_BUFFER_DATA (buffer), txt, txt_len); gst_buffer_fill (buffer, 0, txt, txt_len);
GST_BUFFER_TIMESTAMP (buffer) = ts; GST_BUFFER_TIMESTAMP (buffer) = ts;
GST_BUFFER_DURATION (buffer) = duration; GST_BUFFER_DURATION (buffer) = duration;
@ -525,7 +533,7 @@ GST_START_TEST (test_video_waits_for_text)
fail_unless (buffer_is_all_black (GST_BUFFER_CAST (buffers->data))); fail_unless (buffer_is_all_black (GST_BUFFER_CAST (buffers->data)));
/* now, another video buffer */ /* now, another video buffer */
inbuffer = gst_buffer_make_metadata_writable (inbuffer); inbuffer = gst_buffer_make_writable (inbuffer);
GST_BUFFER_TIMESTAMP (inbuffer) = GST_SECOND; GST_BUFFER_TIMESTAMP (inbuffer) = GST_SECOND;
GST_BUFFER_DURATION (inbuffer) = GST_SECOND / 2; GST_BUFFER_DURATION (inbuffer) = GST_SECOND / 2;
@ -545,7 +553,7 @@ GST_START_TEST (test_video_waits_for_text)
FALSE); FALSE);
/* a third video buffer */ /* a third video buffer */
inbuffer = gst_buffer_make_metadata_writable (inbuffer); inbuffer = gst_buffer_make_writable (inbuffer);
GST_BUFFER_TIMESTAMP (inbuffer) = 30 * GST_SECOND; GST_BUFFER_TIMESTAMP (inbuffer) = 30 * GST_SECOND;
GST_BUFFER_DURATION (inbuffer) = GST_SECOND / 2; GST_BUFFER_DURATION (inbuffer) = GST_SECOND / 2;
@ -573,7 +581,7 @@ GST_START_TEST (test_video_waits_for_text)
next->data))); next->data)));
/* a fourth video buffer */ /* a fourth video buffer */
inbuffer = gst_buffer_make_metadata_writable (inbuffer); inbuffer = gst_buffer_make_writable (inbuffer);
GST_BUFFER_TIMESTAMP (inbuffer) = 35 * GST_SECOND; GST_BUFFER_TIMESTAMP (inbuffer) = 35 * GST_SECOND;
GST_BUFFER_DURATION (inbuffer) = GST_SECOND; GST_BUFFER_DURATION (inbuffer) = GST_SECOND;

View file

@ -142,6 +142,26 @@ cleanup_videorate (GstElement * videorate)
gst_check_teardown_element (videorate); gst_check_teardown_element (videorate);
} }
static void
buffer_memset (GstBuffer * buffer, gint val, gsize size)
{
guint8 *data;
data = gst_buffer_map (buffer, NULL, NULL, GST_MAP_WRITE);
memset (data, val, size);
gst_buffer_unmap (buffer, data, size);
}
static guint8
buffer_get_byte (GstBuffer * buffer, gint offset)
{
guint8 res;
gst_buffer_extract (buffer, offset, &res, 1);
return res;
}
GST_START_TEST (test_one) GST_START_TEST (test_one)
{ {
GstElement *videorate; GstElement *videorate;
@ -154,7 +174,7 @@ GST_START_TEST (test_one)
"could not set to playing"); "could not set to playing");
inbuffer = gst_buffer_new_and_alloc (4); inbuffer = gst_buffer_new_and_alloc (4);
memset (GST_BUFFER_DATA (inbuffer), 0, 4); buffer_memset (inbuffer, 0, 4);
caps = gst_caps_from_string (VIDEO_CAPS_STRING); caps = gst_caps_from_string (VIDEO_CAPS_STRING);
gst_buffer_set_caps (inbuffer, caps); gst_buffer_set_caps (inbuffer, caps);
GST_BUFFER_TIMESTAMP (inbuffer) = 0; GST_BUFFER_TIMESTAMP (inbuffer) = 0;
@ -196,7 +216,7 @@ GST_START_TEST (test_more)
streams */ streams */
GST_BUFFER_OFFSET (first) = g_rand_int (rand); GST_BUFFER_OFFSET (first) = g_rand_int (rand);
GST_BUFFER_OFFSET_END (first) = g_rand_int (rand); GST_BUFFER_OFFSET_END (first) = g_rand_int (rand);
memset (GST_BUFFER_DATA (first), 1, 4); buffer_memset (first, 1, 4);
caps = gst_caps_from_string (VIDEO_CAPS_STRING); caps = gst_caps_from_string (VIDEO_CAPS_STRING);
gst_buffer_set_caps (first, caps); gst_buffer_set_caps (first, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -215,7 +235,7 @@ GST_START_TEST (test_more)
GST_BUFFER_TIMESTAMP (second) = GST_SECOND * 3 / 50; GST_BUFFER_TIMESTAMP (second) = GST_SECOND * 3 / 50;
GST_BUFFER_OFFSET (first) = g_rand_int (rand); GST_BUFFER_OFFSET (first) = g_rand_int (rand);
GST_BUFFER_OFFSET_END (first) = g_rand_int (rand); GST_BUFFER_OFFSET_END (first) = g_rand_int (rand);
memset (GST_BUFFER_DATA (second), 2, 4); buffer_memset (second, 2, 4);
caps = gst_caps_from_string (VIDEO_CAPS_STRING); caps = gst_caps_from_string (VIDEO_CAPS_STRING);
gst_buffer_set_caps (second, caps); gst_buffer_set_caps (second, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -240,7 +260,7 @@ GST_START_TEST (test_more)
GST_BUFFER_TIMESTAMP (third) = GST_SECOND * 12 / 50; GST_BUFFER_TIMESTAMP (third) = GST_SECOND * 12 / 50;
GST_BUFFER_OFFSET (first) = g_rand_int (rand); GST_BUFFER_OFFSET (first) = g_rand_int (rand);
GST_BUFFER_OFFSET_END (first) = g_rand_int (rand); GST_BUFFER_OFFSET_END (first) = g_rand_int (rand);
memset (GST_BUFFER_DATA (third), 3, 4); buffer_memset (third, 3, 4);
caps = gst_caps_from_string (VIDEO_CAPS_STRING); caps = gst_caps_from_string (VIDEO_CAPS_STRING);
gst_buffer_set_caps (third, caps); gst_buffer_set_caps (third, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -258,27 +278,27 @@ GST_START_TEST (test_more)
/* check timestamp and source correctness */ /* check timestamp and source correctness */
l = buffers; l = buffers;
fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (l->data), 0); fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (l->data), 0);
fail_unless_equals_int (GST_BUFFER_DATA (l->data)[0], 1); fail_unless_equals_int (buffer_get_byte (l->data, 0), 1);
fail_unless_equals_uint64 (GST_BUFFER_OFFSET (l->data), 0); fail_unless_equals_uint64 (GST_BUFFER_OFFSET (l->data), 0);
fail_unless_equals_uint64 (GST_BUFFER_OFFSET_END (l->data), 1); fail_unless_equals_uint64 (GST_BUFFER_OFFSET_END (l->data), 1);
l = g_list_next (l); l = g_list_next (l);
fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (l->data), GST_SECOND / 25); fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (l->data), GST_SECOND / 25);
fail_unless_equals_int (GST_BUFFER_DATA (l->data)[0], 2); fail_unless_equals_int (buffer_get_byte (l->data, 0), 2);
fail_unless_equals_uint64 (GST_BUFFER_OFFSET (l->data), 1); fail_unless_equals_uint64 (GST_BUFFER_OFFSET (l->data), 1);
fail_unless_equals_uint64 (GST_BUFFER_OFFSET_END (l->data), 2); fail_unless_equals_uint64 (GST_BUFFER_OFFSET_END (l->data), 2);
l = g_list_next (l); l = g_list_next (l);
fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (l->data), fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (l->data),
GST_SECOND * 2 / 25); GST_SECOND * 2 / 25);
fail_unless_equals_int (GST_BUFFER_DATA (l->data)[0], 2); fail_unless_equals_int (buffer_get_byte (l->data, 0), 2);
fail_unless_equals_uint64 (GST_BUFFER_OFFSET (l->data), 2); fail_unless_equals_uint64 (GST_BUFFER_OFFSET (l->data), 2);
fail_unless_equals_uint64 (GST_BUFFER_OFFSET_END (l->data), 3); fail_unless_equals_uint64 (GST_BUFFER_OFFSET_END (l->data), 3);
l = g_list_next (l); l = g_list_next (l);
fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (l->data), fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (l->data),
GST_SECOND * 3 / 25); GST_SECOND * 3 / 25);
fail_unless_equals_int (GST_BUFFER_DATA (l->data)[0], 2); fail_unless_equals_int (buffer_get_byte (l->data, 0), 2);
fail_unless_equals_uint64 (GST_BUFFER_OFFSET (l->data), 3); fail_unless_equals_uint64 (GST_BUFFER_OFFSET (l->data), 3);
fail_unless_equals_uint64 (GST_BUFFER_OFFSET_END (l->data), 4); fail_unless_equals_uint64 (GST_BUFFER_OFFSET_END (l->data), 4);
@ -320,7 +340,7 @@ GST_START_TEST (test_wrong_order_from_zero)
/* first buffer */ /* first buffer */
first = gst_buffer_new_and_alloc (4); first = gst_buffer_new_and_alloc (4);
GST_BUFFER_TIMESTAMP (first) = GST_SECOND; GST_BUFFER_TIMESTAMP (first) = GST_SECOND;
memset (GST_BUFFER_DATA (first), 0, 4); buffer_memset (first, 0, 4);
caps = gst_caps_from_string (VIDEO_CAPS_STRING); caps = gst_caps_from_string (VIDEO_CAPS_STRING);
gst_buffer_set_caps (first, caps); gst_buffer_set_caps (first, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -338,7 +358,7 @@ GST_START_TEST (test_wrong_order_from_zero)
/* second buffer */ /* second buffer */
second = gst_buffer_new_and_alloc (4); second = gst_buffer_new_and_alloc (4);
GST_BUFFER_TIMESTAMP (second) = 0; GST_BUFFER_TIMESTAMP (second) = 0;
memset (GST_BUFFER_DATA (second), 0, 4); buffer_memset (second, 0, 4);
caps = gst_caps_from_string (VIDEO_CAPS_STRING); caps = gst_caps_from_string (VIDEO_CAPS_STRING);
gst_buffer_set_caps (second, caps); gst_buffer_set_caps (second, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -358,7 +378,7 @@ GST_START_TEST (test_wrong_order_from_zero)
/* third buffer */ /* third buffer */
third = gst_buffer_new_and_alloc (4); third = gst_buffer_new_and_alloc (4);
GST_BUFFER_TIMESTAMP (third) = 2 * GST_SECOND; GST_BUFFER_TIMESTAMP (third) = 2 * GST_SECOND;
memset (GST_BUFFER_DATA (third), 0, 4); buffer_memset (third, 0, 4);
caps = gst_caps_from_string (VIDEO_CAPS_STRING); caps = gst_caps_from_string (VIDEO_CAPS_STRING);
gst_buffer_set_caps (third, caps); gst_buffer_set_caps (third, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -409,7 +429,7 @@ GST_START_TEST (test_wrong_order)
/* first buffer */ /* first buffer */
first = gst_buffer_new_and_alloc (4); first = gst_buffer_new_and_alloc (4);
GST_BUFFER_TIMESTAMP (first) = 0; GST_BUFFER_TIMESTAMP (first) = 0;
memset (GST_BUFFER_DATA (first), 0, 4); buffer_memset (first, 0, 4);
caps = gst_caps_from_string (VIDEO_CAPS_STRING); caps = gst_caps_from_string (VIDEO_CAPS_STRING);
gst_buffer_set_caps (first, caps); gst_buffer_set_caps (first, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -427,7 +447,7 @@ GST_START_TEST (test_wrong_order)
/* second buffer */ /* second buffer */
second = gst_buffer_new_and_alloc (4); second = gst_buffer_new_and_alloc (4);
GST_BUFFER_TIMESTAMP (second) = GST_SECOND; GST_BUFFER_TIMESTAMP (second) = GST_SECOND;
memset (GST_BUFFER_DATA (second), 0, 4); buffer_memset (second, 0, 4);
caps = gst_caps_from_string (VIDEO_CAPS_STRING); caps = gst_caps_from_string (VIDEO_CAPS_STRING);
gst_buffer_set_caps (second, caps); gst_buffer_set_caps (second, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -446,7 +466,7 @@ GST_START_TEST (test_wrong_order)
/* third buffer */ /* third buffer */
third = gst_buffer_new_and_alloc (4); third = gst_buffer_new_and_alloc (4);
GST_BUFFER_TIMESTAMP (third) = 2 * GST_SECOND; GST_BUFFER_TIMESTAMP (third) = 2 * GST_SECOND;
memset (GST_BUFFER_DATA (third), 0, 4); buffer_memset (third, 0, 4);
caps = gst_caps_from_string (VIDEO_CAPS_STRING); caps = gst_caps_from_string (VIDEO_CAPS_STRING);
gst_buffer_set_caps (third, caps); gst_buffer_set_caps (third, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -468,7 +488,7 @@ GST_START_TEST (test_wrong_order)
/* fourth buffer */ /* fourth buffer */
fourth = gst_buffer_new_and_alloc (4); fourth = gst_buffer_new_and_alloc (4);
GST_BUFFER_TIMESTAMP (fourth) = 0; GST_BUFFER_TIMESTAMP (fourth) = 0;
memset (GST_BUFFER_DATA (fourth), 0, 4); buffer_memset (fourth, 0, 4);
caps = gst_caps_from_string (VIDEO_CAPS_STRING); caps = gst_caps_from_string (VIDEO_CAPS_STRING);
gst_buffer_set_caps (fourth, caps); gst_buffer_set_caps (fourth, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -516,7 +536,7 @@ GST_START_TEST (test_no_framerate)
"could not set to playing"); "could not set to playing");
inbuffer = gst_buffer_new_and_alloc (4); inbuffer = gst_buffer_new_and_alloc (4);
memset (GST_BUFFER_DATA (inbuffer), 0, 4); buffer_memset (inbuffer, 0, 4);
caps = gst_caps_from_string (VIDEO_CAPS_NO_FRAMERATE_STRING); caps = gst_caps_from_string (VIDEO_CAPS_NO_FRAMERATE_STRING);
gst_buffer_set_caps (inbuffer, caps); gst_buffer_set_caps (inbuffer, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -564,7 +584,7 @@ GST_START_TEST (test_changing_size)
fail_unless (gst_pad_push_event (mysrcpad, newsegment) == TRUE); fail_unless (gst_pad_push_event (mysrcpad, newsegment) == TRUE);
first = gst_buffer_new_and_alloc (4); first = gst_buffer_new_and_alloc (4);
memset (GST_BUFFER_DATA (first), 0, 4); buffer_memset (first, 0, 4);
caps = gst_caps_from_string (VIDEO_CAPS_STRING); caps = gst_caps_from_string (VIDEO_CAPS_STRING);
GST_BUFFER_TIMESTAMP (first) = 0; GST_BUFFER_TIMESTAMP (first) = 0;
gst_buffer_set_caps (first, caps); gst_buffer_set_caps (first, caps);
@ -575,7 +595,7 @@ GST_START_TEST (test_changing_size)
/* second buffer */ /* second buffer */
second = gst_buffer_new_and_alloc (4); second = gst_buffer_new_and_alloc (4);
GST_BUFFER_TIMESTAMP (second) = GST_SECOND / 25; GST_BUFFER_TIMESTAMP (second) = GST_SECOND / 25;
memset (GST_BUFFER_DATA (second), 0, 4); buffer_memset (second, 0, 4);
gst_buffer_set_caps (second, caps); gst_buffer_set_caps (second, caps);
fail_unless (gst_pad_push (mysrcpad, second) == GST_FLOW_OK); fail_unless (gst_pad_push (mysrcpad, second) == GST_FLOW_OK);
@ -588,7 +608,7 @@ GST_START_TEST (test_changing_size)
/* third buffer with new size */ /* third buffer with new size */
third = gst_buffer_new_and_alloc (4); third = gst_buffer_new_and_alloc (4);
GST_BUFFER_TIMESTAMP (third) = 2 * GST_SECOND / 25; GST_BUFFER_TIMESTAMP (third) = 2 * GST_SECOND / 25;
memset (GST_BUFFER_DATA (third), 0, 4); buffer_memset (third, 0, 4);
caps_newsize = gst_caps_from_string (VIDEO_CAPS_NEWSIZE_STRING); caps_newsize = gst_caps_from_string (VIDEO_CAPS_NEWSIZE_STRING);
gst_buffer_set_caps (third, caps_newsize); gst_buffer_set_caps (third, caps_newsize);
@ -603,7 +623,7 @@ GST_START_TEST (test_changing_size)
/* fourth buffer with original size */ /* fourth buffer with original size */
fourth = gst_buffer_new_and_alloc (4); fourth = gst_buffer_new_and_alloc (4);
GST_BUFFER_TIMESTAMP (fourth) = 3 * GST_SECOND / 25; GST_BUFFER_TIMESTAMP (fourth) = 3 * GST_SECOND / 25;
memset (GST_BUFFER_DATA (fourth), 0, 4); buffer_memset (fourth, 0, 4);
gst_buffer_set_caps (fourth, caps); gst_buffer_set_caps (fourth, caps);
fail_unless (gst_pad_push (mysrcpad, fourth) == GST_FLOW_OK); fail_unless (gst_pad_push (mysrcpad, fourth) == GST_FLOW_OK);
@ -612,7 +632,7 @@ GST_START_TEST (test_changing_size)
/* fifth buffer with original size */ /* fifth buffer with original size */
fifth = gst_buffer_new_and_alloc (4); fifth = gst_buffer_new_and_alloc (4);
GST_BUFFER_TIMESTAMP (fifth) = 4 * GST_SECOND / 25; GST_BUFFER_TIMESTAMP (fifth) = 4 * GST_SECOND / 25;
memset (GST_BUFFER_DATA (fifth), 0, 4); buffer_memset (fifth, 0, 4);
gst_buffer_set_caps (fifth, caps); gst_buffer_set_caps (fifth, caps);
fail_unless (gst_pad_push (mysrcpad, fifth) == GST_FLOW_OK); fail_unless (gst_pad_push (mysrcpad, fifth) == GST_FLOW_OK);
@ -643,7 +663,7 @@ GST_START_TEST (test_non_ok_flow)
"could not set to playing"); "could not set to playing");
buf = gst_buffer_new_and_alloc (4); buf = gst_buffer_new_and_alloc (4);
memset (GST_BUFFER_DATA (buf), 0, 4); buffer_memset (buf, 0, 4);
caps = gst_caps_from_string (VIDEO_CAPS_STRING); caps = gst_caps_from_string (VIDEO_CAPS_STRING);
gst_buffer_set_caps (buf, caps); gst_buffer_set_caps (buf, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -666,7 +686,7 @@ GST_START_TEST (test_non_ok_flow)
gst_pad_set_active (mysinkpad, FALSE); gst_pad_set_active (mysinkpad, FALSE);
/* push buffer on deactivated pad */ /* push buffer on deactivated pad */
fail_unless (gst_buffer_is_metadata_writable (buf)); fail_unless (gst_buffer_is_writable (buf));
GST_BUFFER_TIMESTAMP (buf) = ts; GST_BUFFER_TIMESTAMP (buf) = ts;
/* pushing gives away our reference */ /* pushing gives away our reference */

View file

@ -240,9 +240,15 @@ GST_START_TEST (test_passthrough)
l1 = l1->next, l2 = l2->next) { l1 = l1->next, l2 = l2->next) {
GstBuffer *a = l1->data; GstBuffer *a = l1->data;
GstBuffer *b = l2->data; GstBuffer *b = l2->data;
gsize sa, sb;
guint8 *pa, *pb;
fail_unless_equals_int (GST_BUFFER_SIZE (a), GST_BUFFER_SIZE (b)); pa = gst_buffer_map (a, &sa, NULL, GST_MAP_READ);
fail_unless (GST_BUFFER_DATA (a) == GST_BUFFER_DATA (b)); pb = gst_buffer_map (b, &sb, NULL, GST_MAP_READ);
fail_unless_equals_int (sa, sb);
fail_unless (pa == pb);
gst_buffer_unmap (b, pb, sb);
gst_buffer_unmap (a, pa, sa);
gst_buffer_unref (a); gst_buffer_unref (a);
gst_buffer_unref (b); gst_buffer_unref (b);

View file

@ -322,6 +322,8 @@ GST_START_TEST (test_rgb_formats)
/* caps are supported, let's run some tests then ... */ /* caps are supported, let's run some tests then ... */
for (p = 0; p < G_N_ELEMENTS (test_patterns); ++p) { for (p = 0; p < G_N_ELEMENTS (test_patterns); ++p) {
GstStateChangeReturn state_ret; GstStateChangeReturn state_ret;
guint8 *data;
gsize size;
g_object_set (src, "pattern", test_patterns[p].pattern_enum, NULL); g_object_set (src, "pattern", test_patterns[p].pattern_enum, NULL);
@ -375,11 +377,13 @@ GST_START_TEST (test_rgb_formats)
/* now check the first pixel */ /* now check the first pixel */
check_rgb_buf (GST_BUFFER_DATA (buf), rgb_formats[i].red_mask, data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
check_rgb_buf (data, rgb_formats[i].red_mask,
rgb_formats[i].green_mask, rgb_formats[i].blue_mask, rgb_formats[i].green_mask, rgb_formats[i].blue_mask,
rgb_formats[i].alpha_mask, test_patterns[p].r_expected, rgb_formats[i].alpha_mask, test_patterns[p].r_expected,
test_patterns[p].g_expected, test_patterns[p].b_expected, test_patterns[p].g_expected, test_patterns[p].b_expected,
endianness, rgb_formats[i].bpp, rgb_formats[i].depth); endianness, rgb_formats[i].bpp, rgb_formats[i].depth);
gst_buffer_unmap (buf, data, size);
gst_buffer_unref (buf); gst_buffer_unref (buf);
buf = NULL; buf = NULL;

View file

@ -185,6 +185,7 @@ GST_START_TEST (test_unity_s8)
GstCaps *caps; GstCaps *caps;
gint8 in[2] = { 64, -16 }; gint8 in[2] = { 64, -16 };
gint8 *res; gint8 *res;
gsize size;
volume = setup_volume (); volume = setup_volume ();
fail_unless (gst_element_set_state (volume, fail_unless (gst_element_set_state (volume,
@ -192,7 +193,7 @@ GST_START_TEST (test_unity_s8)
"could not set to playing"); "could not set to playing");
inbuffer = gst_buffer_new_and_alloc (2); inbuffer = gst_buffer_new_and_alloc (2);
memcpy (GST_BUFFER_DATA (inbuffer), in, 2); gst_buffer_fill (inbuffer, 0, in, 2);
caps = gst_caps_from_string (VOLUME_CAPS_STRING_S8); caps = gst_caps_from_string (VOLUME_CAPS_STRING_S8);
gst_buffer_set_caps (inbuffer, caps); gst_buffer_set_caps (inbuffer, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -205,9 +206,10 @@ GST_START_TEST (test_unity_s8)
fail_unless_equals_int (g_list_length (buffers), 1); fail_unless_equals_int (g_list_length (buffers), 1);
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
fail_unless (inbuffer == outbuffer); fail_unless (inbuffer == outbuffer);
res = (gint8 *) GST_BUFFER_DATA (outbuffer); res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
GST_INFO ("expected %+5d %+5d real %+5d %+5d", in[0], in[1], res[0], res[1]); GST_INFO ("expected %+5d %+5d real %+5d %+5d", in[0], in[1], res[0], res[1]);
fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 2) == 0); fail_unless (memcmp (res, in, 2) == 0);
gst_buffer_unmap (outbuffer, res, size);
/* cleanup */ /* cleanup */
cleanup_volume (volume); cleanup_volume (volume);
@ -224,6 +226,7 @@ GST_START_TEST (test_half_s8)
gint8 in[2] = { 64, -16 }; gint8 in[2] = { 64, -16 };
gint8 out[2] = { 32, -8 }; gint8 out[2] = { 32, -8 };
gint8 *res; gint8 *res;
gsize size;
volume = setup_volume (); volume = setup_volume ();
g_object_set (G_OBJECT (volume), "volume", 0.5, NULL); g_object_set (G_OBJECT (volume), "volume", 0.5, NULL);
@ -232,8 +235,7 @@ GST_START_TEST (test_half_s8)
"could not set to playing"); "could not set to playing");
inbuffer = gst_buffer_new_and_alloc (2); inbuffer = gst_buffer_new_and_alloc (2);
memcpy (GST_BUFFER_DATA (inbuffer), in, 2); gst_buffer_fill (inbuffer, 0, in, 2);
fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 2) == 0);
caps = gst_caps_from_string (VOLUME_CAPS_STRING_S8); caps = gst_caps_from_string (VOLUME_CAPS_STRING_S8);
gst_buffer_set_caps (inbuffer, caps); gst_buffer_set_caps (inbuffer, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -251,10 +253,11 @@ GST_START_TEST (test_half_s8)
fail_unless_equals_int (g_list_length (buffers), 1); fail_unless_equals_int (g_list_length (buffers), 1);
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
fail_unless (inbuffer == outbuffer); fail_unless (inbuffer == outbuffer);
res = (gint8 *) GST_BUFFER_DATA (outbuffer); res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0], GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
res[1]); res[1]);
fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 2) == 0); fail_unless (memcmp (res, out, 2) == 0);
gst_buffer_unmap (outbuffer, res, size);
/* cleanup */ /* cleanup */
cleanup_volume (volume); cleanup_volume (volume);
@ -271,6 +274,7 @@ GST_START_TEST (test_double_s8)
gint8 in[2] = { 64, -16 }; gint8 in[2] = { 64, -16 };
gint8 out[2] = { 127, -32 }; /* notice the clamped sample */ gint8 out[2] = { 127, -32 }; /* notice the clamped sample */
gint8 *res; gint8 *res;
gsize size;
volume = setup_volume (); volume = setup_volume ();
g_object_set (G_OBJECT (volume), "volume", 2.0, NULL); g_object_set (G_OBJECT (volume), "volume", 2.0, NULL);
@ -279,8 +283,7 @@ GST_START_TEST (test_double_s8)
"could not set to playing"); "could not set to playing");
inbuffer = gst_buffer_new_and_alloc (2); inbuffer = gst_buffer_new_and_alloc (2);
memcpy (GST_BUFFER_DATA (inbuffer), in, 2); gst_buffer_fill (inbuffer, 0, in, 2);
fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 2) == 0);
caps = gst_caps_from_string (VOLUME_CAPS_STRING_S8); caps = gst_caps_from_string (VOLUME_CAPS_STRING_S8);
gst_buffer_set_caps (inbuffer, caps); gst_buffer_set_caps (inbuffer, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -298,10 +301,11 @@ GST_START_TEST (test_double_s8)
fail_unless_equals_int (g_list_length (buffers), 1); fail_unless_equals_int (g_list_length (buffers), 1);
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
fail_unless (inbuffer == outbuffer); fail_unless (inbuffer == outbuffer);
res = (gint8 *) GST_BUFFER_DATA (outbuffer); res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0], GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
res[1]); res[1]);
fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 2) == 0); fail_unless (memcmp (res, out, 2) == 0);
gst_buffer_unmap (outbuffer, res, size);
/* cleanup */ /* cleanup */
cleanup_volume (volume); cleanup_volume (volume);
@ -318,6 +322,7 @@ GST_START_TEST (test_mute_s8)
gint8 in[2] = { 64, -16 }; gint8 in[2] = { 64, -16 };
gint8 out[2] = { 0, 0 }; gint8 out[2] = { 0, 0 };
gint8 *res; gint8 *res;
gsize size;
volume = setup_volume (); volume = setup_volume ();
g_object_set (G_OBJECT (volume), "mute", TRUE, NULL); g_object_set (G_OBJECT (volume), "mute", TRUE, NULL);
@ -326,8 +331,7 @@ GST_START_TEST (test_mute_s8)
"could not set to playing"); "could not set to playing");
inbuffer = gst_buffer_new_and_alloc (2); inbuffer = gst_buffer_new_and_alloc (2);
memcpy (GST_BUFFER_DATA (inbuffer), in, 2); gst_buffer_fill (inbuffer, 0, in, 2);
fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 2) == 0);
caps = gst_caps_from_string (VOLUME_CAPS_STRING_S8); caps = gst_caps_from_string (VOLUME_CAPS_STRING_S8);
gst_buffer_set_caps (inbuffer, caps); gst_buffer_set_caps (inbuffer, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -345,10 +349,11 @@ GST_START_TEST (test_mute_s8)
fail_unless_equals_int (g_list_length (buffers), 1); fail_unless_equals_int (g_list_length (buffers), 1);
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
fail_unless (inbuffer == outbuffer); fail_unless (inbuffer == outbuffer);
res = (gint8 *) GST_BUFFER_DATA (outbuffer); res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0], GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
res[1]); res[1]);
fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 2) == 0); fail_unless (memcmp (res, out, 2) == 0);
gst_buffer_unmap (outbuffer, res, size);
/* cleanup */ /* cleanup */
cleanup_volume (volume); cleanup_volume (volume);
@ -363,6 +368,7 @@ GST_START_TEST (test_unity_s16)
GstCaps *caps; GstCaps *caps;
gint16 in[2] = { 16384, -256 }; gint16 in[2] = { 16384, -256 };
gint16 *res; gint16 *res;
gsize size;
volume = setup_volume (); volume = setup_volume ();
fail_unless (gst_element_set_state (volume, fail_unless (gst_element_set_state (volume,
@ -370,7 +376,7 @@ GST_START_TEST (test_unity_s16)
"could not set to playing"); "could not set to playing");
inbuffer = gst_buffer_new_and_alloc (4); inbuffer = gst_buffer_new_and_alloc (4);
memcpy (GST_BUFFER_DATA (inbuffer), in, 4); gst_buffer_fill (inbuffer, 0, in, 4);
caps = gst_caps_from_string (VOLUME_CAPS_STRING_S16); caps = gst_caps_from_string (VOLUME_CAPS_STRING_S16);
gst_buffer_set_caps (inbuffer, caps); gst_buffer_set_caps (inbuffer, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -383,9 +389,10 @@ GST_START_TEST (test_unity_s16)
fail_unless_equals_int (g_list_length (buffers), 1); fail_unless_equals_int (g_list_length (buffers), 1);
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
fail_unless (inbuffer == outbuffer); fail_unless (inbuffer == outbuffer);
res = (gint16 *) GST_BUFFER_DATA (outbuffer); res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
GST_INFO ("expected %+5d %+5d real %+5d %+5d", in[0], in[1], res[0], res[1]); GST_INFO ("expected %+5d %+5d real %+5d %+5d", in[0], in[1], res[0], res[1]);
fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 4) == 0); fail_unless (memcmp (res, in, 4) == 0);
gst_buffer_unmap (outbuffer, res, size);
/* cleanup */ /* cleanup */
cleanup_volume (volume); cleanup_volume (volume);
@ -402,6 +409,7 @@ GST_START_TEST (test_half_s16)
gint16 in[2] = { 16384, -256 }; gint16 in[2] = { 16384, -256 };
gint16 out[2] = { 8192, -128 }; gint16 out[2] = { 8192, -128 };
gint16 *res; gint16 *res;
gsize size;
volume = setup_volume (); volume = setup_volume ();
g_object_set (G_OBJECT (volume), "volume", 0.5, NULL); g_object_set (G_OBJECT (volume), "volume", 0.5, NULL);
@ -410,8 +418,7 @@ GST_START_TEST (test_half_s16)
"could not set to playing"); "could not set to playing");
inbuffer = gst_buffer_new_and_alloc (4); inbuffer = gst_buffer_new_and_alloc (4);
memcpy (GST_BUFFER_DATA (inbuffer), in, 4); gst_buffer_fill (inbuffer, 0, in, 4);
fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 4) == 0);
caps = gst_caps_from_string (VOLUME_CAPS_STRING_S16); caps = gst_caps_from_string (VOLUME_CAPS_STRING_S16);
gst_buffer_set_caps (inbuffer, caps); gst_buffer_set_caps (inbuffer, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -429,10 +436,11 @@ GST_START_TEST (test_half_s16)
fail_unless_equals_int (g_list_length (buffers), 1); fail_unless_equals_int (g_list_length (buffers), 1);
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
fail_unless (inbuffer == outbuffer); fail_unless (inbuffer == outbuffer);
res = (gint16 *) GST_BUFFER_DATA (outbuffer); res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0], GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
res[1]); res[1]);
fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 4) == 0); fail_unless (memcmp (res, out, 4) == 0);
gst_buffer_unmap (outbuffer, res, size);
/* cleanup */ /* cleanup */
cleanup_volume (volume); cleanup_volume (volume);
@ -449,6 +457,7 @@ GST_START_TEST (test_double_s16)
gint16 in[2] = { 16384, -256 }; gint16 in[2] = { 16384, -256 };
gint16 out[2] = { 32767, -512 }; /* notice the clamped sample */ gint16 out[2] = { 32767, -512 }; /* notice the clamped sample */
gint16 *res; gint16 *res;
gsize size;
volume = setup_volume (); volume = setup_volume ();
g_object_set (G_OBJECT (volume), "volume", 2.0, NULL); g_object_set (G_OBJECT (volume), "volume", 2.0, NULL);
@ -457,8 +466,7 @@ GST_START_TEST (test_double_s16)
"could not set to playing"); "could not set to playing");
inbuffer = gst_buffer_new_and_alloc (4); inbuffer = gst_buffer_new_and_alloc (4);
memcpy (GST_BUFFER_DATA (inbuffer), in, 4); gst_buffer_fill (inbuffer, 0, in, 4);
fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 4) == 0);
caps = gst_caps_from_string (VOLUME_CAPS_STRING_S16); caps = gst_caps_from_string (VOLUME_CAPS_STRING_S16);
gst_buffer_set_caps (inbuffer, caps); gst_buffer_set_caps (inbuffer, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -476,10 +484,11 @@ GST_START_TEST (test_double_s16)
fail_unless_equals_int (g_list_length (buffers), 1); fail_unless_equals_int (g_list_length (buffers), 1);
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
fail_unless (inbuffer == outbuffer); fail_unless (inbuffer == outbuffer);
res = (gint16 *) GST_BUFFER_DATA (outbuffer); res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0], GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
res[1]); res[1]);
fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 4) == 0); fail_unless (memcmp (res, out, 4) == 0);
gst_buffer_unmap (outbuffer, res, size);
/* cleanup */ /* cleanup */
cleanup_volume (volume); cleanup_volume (volume);
@ -497,6 +506,7 @@ GST_START_TEST (test_mute_s16)
gint16 in[2] = { 16384, -256 }; gint16 in[2] = { 16384, -256 };
gint16 out[2] = { 0, 0 }; gint16 out[2] = { 0, 0 };
gint16 *res; gint16 *res;
gsize size;
volume = setup_volume (); volume = setup_volume ();
g_object_set (G_OBJECT (volume), "mute", TRUE, NULL); g_object_set (G_OBJECT (volume), "mute", TRUE, NULL);
@ -505,8 +515,7 @@ GST_START_TEST (test_mute_s16)
"could not set to playing"); "could not set to playing");
inbuffer = gst_buffer_new_and_alloc (4); inbuffer = gst_buffer_new_and_alloc (4);
memcpy (GST_BUFFER_DATA (inbuffer), in, 4); gst_buffer_fill (inbuffer, 0, in, 4);
fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 4) == 0);
caps = gst_caps_from_string (VOLUME_CAPS_STRING_S16); caps = gst_caps_from_string (VOLUME_CAPS_STRING_S16);
gst_buffer_set_caps (inbuffer, caps); gst_buffer_set_caps (inbuffer, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -524,10 +533,11 @@ GST_START_TEST (test_mute_s16)
fail_unless_equals_int (g_list_length (buffers), 1); fail_unless_equals_int (g_list_length (buffers), 1);
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
fail_unless (inbuffer == outbuffer); fail_unless (inbuffer == outbuffer);
res = (gint16 *) GST_BUFFER_DATA (outbuffer); res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0], GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
res[1]); res[1]);
fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 4) == 0); fail_unless (memcmp (res, out, 4) == 0);
gst_buffer_unmap (outbuffer, res, size);
/* cleanup */ /* cleanup */
cleanup_volume (volume); cleanup_volume (volume);
@ -552,7 +562,7 @@ GST_START_TEST (test_unity_s24)
guint8 in[6]; guint8 in[6];
guint8 *res; guint8 *res;
gint32 res_32[2]; gint32 res_32[2];
gsize size;
write_unaligned_u24 (in, in_32[0]); write_unaligned_u24 (in, in_32[0]);
write_unaligned_u24 (in + 3, in_32[1]); write_unaligned_u24 (in + 3, in_32[1]);
@ -563,7 +573,7 @@ GST_START_TEST (test_unity_s24)
"could not set to playing"); "could not set to playing");
inbuffer = gst_buffer_new_and_alloc (6); inbuffer = gst_buffer_new_and_alloc (6);
memcpy (GST_BUFFER_DATA (inbuffer), in, 6); gst_buffer_fill (inbuffer, 0, in, 6);
caps = gst_caps_from_string (VOLUME_CAPS_STRING_S24); caps = gst_caps_from_string (VOLUME_CAPS_STRING_S24);
gst_buffer_set_caps (inbuffer, caps); gst_buffer_set_caps (inbuffer, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -576,14 +586,15 @@ GST_START_TEST (test_unity_s24)
fail_unless_equals_int (g_list_length (buffers), 1); fail_unless_equals_int (g_list_length (buffers), 1);
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
fail_unless (inbuffer == outbuffer); fail_unless (inbuffer == outbuffer);
res = GST_BUFFER_DATA (outbuffer); res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
res_32[0] = get_unaligned_i24 (res); res_32[0] = get_unaligned_i24 (res);
res_32[1] = get_unaligned_i24 ((res + 3)); res_32[1] = get_unaligned_i24 ((res + 3));
GST_INFO ("expected %+5d %+5d real %+5d %+5d", in_32[0], in_32[1], res_32[0], GST_INFO ("expected %+5d %+5d real %+5d %+5d", in_32[0], in_32[1], res_32[0],
res_32[1]); res_32[1]);
fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 6) == 0); fail_unless (memcmp (res, in, 6) == 0);
gst_buffer_unmap (outbuffer, res, size);
/* cleanup */ /* cleanup */
cleanup_volume (volume); cleanup_volume (volume);
@ -602,6 +613,7 @@ GST_START_TEST (test_half_s24)
guint8 *res; guint8 *res;
gint32 res_32[2]; gint32 res_32[2];
gint32 out_32[2] = { 2097152, -2048 }; gint32 out_32[2] = { 2097152, -2048 };
gsize size;
write_unaligned_u24 (in, in_32[0]); write_unaligned_u24 (in, in_32[0]);
write_unaligned_u24 (in + 3, in_32[1]); write_unaligned_u24 (in + 3, in_32[1]);
@ -613,8 +625,7 @@ GST_START_TEST (test_half_s24)
"could not set to playing"); "could not set to playing");
inbuffer = gst_buffer_new_and_alloc (6); inbuffer = gst_buffer_new_and_alloc (6);
memcpy (GST_BUFFER_DATA (inbuffer), in, 6); gst_buffer_fill (inbuffer, 0, in, 6);
fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 6) == 0);
caps = gst_caps_from_string (VOLUME_CAPS_STRING_S24); caps = gst_caps_from_string (VOLUME_CAPS_STRING_S24);
gst_buffer_set_caps (inbuffer, caps); gst_buffer_set_caps (inbuffer, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -632,7 +643,7 @@ GST_START_TEST (test_half_s24)
fail_unless_equals_int (g_list_length (buffers), 1); fail_unless_equals_int (g_list_length (buffers), 1);
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
fail_unless (inbuffer == outbuffer); fail_unless (inbuffer == outbuffer);
res = GST_BUFFER_DATA (outbuffer); res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
res_32[0] = get_unaligned_i24 (res); res_32[0] = get_unaligned_i24 (res);
res_32[1] = get_unaligned_i24 ((res + 3)); res_32[1] = get_unaligned_i24 ((res + 3));
@ -640,6 +651,7 @@ GST_START_TEST (test_half_s24)
GST_INFO ("expected %+5d %+5d real %+5d %+5d", out_32[0], out_32[1], GST_INFO ("expected %+5d %+5d real %+5d %+5d", out_32[0], out_32[1],
res_32[0], res_32[1]); res_32[0], res_32[1]);
fail_unless (memcmp (res_32, out_32, 8) == 0); fail_unless (memcmp (res_32, out_32, 8) == 0);
gst_buffer_unmap (outbuffer, res, size);
/* cleanup */ /* cleanup */
cleanup_volume (volume); cleanup_volume (volume);
@ -658,6 +670,7 @@ GST_START_TEST (test_double_s24)
guint8 *res; guint8 *res;
gint32 res_32[2]; gint32 res_32[2];
gint32 out_32[2] = { 8388607, -8192 }; /* notice the clamped sample */ gint32 out_32[2] = { 8388607, -8192 }; /* notice the clamped sample */
gsize size;
write_unaligned_u24 (in, in_32[0]); write_unaligned_u24 (in, in_32[0]);
write_unaligned_u24 (in + 3, in_32[1]); write_unaligned_u24 (in + 3, in_32[1]);
@ -669,8 +682,7 @@ GST_START_TEST (test_double_s24)
"could not set to playing"); "could not set to playing");
inbuffer = gst_buffer_new_and_alloc (6); inbuffer = gst_buffer_new_and_alloc (6);
memcpy (GST_BUFFER_DATA (inbuffer), in, 6); gst_buffer_fill (inbuffer, 0, in, 6);
fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 6) == 0);
caps = gst_caps_from_string (VOLUME_CAPS_STRING_S24); caps = gst_caps_from_string (VOLUME_CAPS_STRING_S24);
gst_buffer_set_caps (inbuffer, caps); gst_buffer_set_caps (inbuffer, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -688,7 +700,7 @@ GST_START_TEST (test_double_s24)
fail_unless_equals_int (g_list_length (buffers), 1); fail_unless_equals_int (g_list_length (buffers), 1);
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
fail_unless (inbuffer == outbuffer); fail_unless (inbuffer == outbuffer);
res = GST_BUFFER_DATA (outbuffer); res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
res_32[0] = get_unaligned_i24 (res); res_32[0] = get_unaligned_i24 (res);
res_32[1] = get_unaligned_i24 ((res + 3)); res_32[1] = get_unaligned_i24 ((res + 3));
@ -696,6 +708,7 @@ GST_START_TEST (test_double_s24)
GST_INFO ("expected %+5d %+5d real %+5d %+5d", out_32[0], out_32[1], GST_INFO ("expected %+5d %+5d real %+5d %+5d", out_32[0], out_32[1],
res_32[0], res_32[1]); res_32[0], res_32[1]);
fail_unless (memcmp (res_32, out_32, 8) == 0); fail_unless (memcmp (res_32, out_32, 8) == 0);
gst_buffer_unmap (outbuffer, res, size);
/* cleanup */ /* cleanup */
cleanup_volume (volume); cleanup_volume (volume);
@ -715,6 +728,7 @@ GST_START_TEST (test_mute_s24)
guint8 *res; guint8 *res;
gint32 res_32[2]; gint32 res_32[2];
gint32 out_32[2] = { 0, 0 }; /* notice the clamped sample */ gint32 out_32[2] = { 0, 0 }; /* notice the clamped sample */
gsize size;
write_unaligned_u24 (in, in_32[0]); write_unaligned_u24 (in, in_32[0]);
write_unaligned_u24 (in + 3, in_32[1]); write_unaligned_u24 (in + 3, in_32[1]);
@ -726,8 +740,7 @@ GST_START_TEST (test_mute_s24)
"could not set to playing"); "could not set to playing");
inbuffer = gst_buffer_new_and_alloc (6); inbuffer = gst_buffer_new_and_alloc (6);
memcpy (GST_BUFFER_DATA (inbuffer), in, 6); gst_buffer_fill (inbuffer, 0, in, 6);
fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 6) == 0);
caps = gst_caps_from_string (VOLUME_CAPS_STRING_S24); caps = gst_caps_from_string (VOLUME_CAPS_STRING_S24);
gst_buffer_set_caps (inbuffer, caps); gst_buffer_set_caps (inbuffer, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -746,7 +759,7 @@ GST_START_TEST (test_mute_s24)
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
fail_unless (inbuffer == outbuffer); fail_unless (inbuffer == outbuffer);
res = GST_BUFFER_DATA (outbuffer); res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
res_32[0] = get_unaligned_i24 (res); res_32[0] = get_unaligned_i24 (res);
res_32[1] = get_unaligned_i24 ((res + 3)); res_32[1] = get_unaligned_i24 ((res + 3));
@ -754,6 +767,7 @@ GST_START_TEST (test_mute_s24)
GST_INFO ("expected %+5d %+5d real %+5d %+5d", out_32[0], out_32[1], GST_INFO ("expected %+5d %+5d real %+5d %+5d", out_32[0], out_32[1],
res_32[0], res_32[1]); res_32[0], res_32[1]);
fail_unless (memcmp (res_32, out_32, 8) == 0); fail_unless (memcmp (res_32, out_32, 8) == 0);
gst_buffer_unmap (outbuffer, res, size);
/* cleanup */ /* cleanup */
cleanup_volume (volume); cleanup_volume (volume);
@ -768,6 +782,7 @@ GST_START_TEST (test_unity_s32)
GstCaps *caps; GstCaps *caps;
gint32 in[2] = { 1073741824, -65536 }; gint32 in[2] = { 1073741824, -65536 };
gint32 *res; gint32 *res;
gsize size;
volume = setup_volume (); volume = setup_volume ();
fail_unless (gst_element_set_state (volume, fail_unless (gst_element_set_state (volume,
@ -775,7 +790,7 @@ GST_START_TEST (test_unity_s32)
"could not set to playing"); "could not set to playing");
inbuffer = gst_buffer_new_and_alloc (8); inbuffer = gst_buffer_new_and_alloc (8);
memcpy (GST_BUFFER_DATA (inbuffer), in, 8); gst_buffer_fill (inbuffer, 0, in, 8);
caps = gst_caps_from_string (VOLUME_CAPS_STRING_S32); caps = gst_caps_from_string (VOLUME_CAPS_STRING_S32);
gst_buffer_set_caps (inbuffer, caps); gst_buffer_set_caps (inbuffer, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -788,9 +803,10 @@ GST_START_TEST (test_unity_s32)
fail_unless_equals_int (g_list_length (buffers), 1); fail_unless_equals_int (g_list_length (buffers), 1);
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
fail_unless (inbuffer == outbuffer); fail_unless (inbuffer == outbuffer);
res = (gint32 *) GST_BUFFER_DATA (outbuffer); res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
GST_INFO ("expected %+5d %+5d real %+5d %+5d", in[0], in[1], res[0], res[1]); GST_INFO ("expected %+5d %+5d real %+5d %+5d", in[0], in[1], res[0], res[1]);
fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 8) == 0); fail_unless (memcmp (res, in, 8) == 0);
gst_buffer_unmap (outbuffer, res, size);
/* cleanup */ /* cleanup */
cleanup_volume (volume); cleanup_volume (volume);
@ -807,6 +823,7 @@ GST_START_TEST (test_half_s32)
gint32 in[2] = { 1073741824, -65536 }; gint32 in[2] = { 1073741824, -65536 };
gint32 out[2] = { 536870912, -32768 }; gint32 out[2] = { 536870912, -32768 };
gint32 *res; gint32 *res;
gsize size;
volume = setup_volume (); volume = setup_volume ();
g_object_set (G_OBJECT (volume), "volume", 0.5, NULL); g_object_set (G_OBJECT (volume), "volume", 0.5, NULL);
@ -815,8 +832,7 @@ GST_START_TEST (test_half_s32)
"could not set to playing"); "could not set to playing");
inbuffer = gst_buffer_new_and_alloc (8); inbuffer = gst_buffer_new_and_alloc (8);
memcpy (GST_BUFFER_DATA (inbuffer), in, 8); gst_buffer_fill (inbuffer, 0, in, 8);
fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 8) == 0);
caps = gst_caps_from_string (VOLUME_CAPS_STRING_S32); caps = gst_caps_from_string (VOLUME_CAPS_STRING_S32);
gst_buffer_set_caps (inbuffer, caps); gst_buffer_set_caps (inbuffer, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -834,10 +850,11 @@ GST_START_TEST (test_half_s32)
fail_unless_equals_int (g_list_length (buffers), 1); fail_unless_equals_int (g_list_length (buffers), 1);
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
fail_unless (inbuffer == outbuffer); fail_unless (inbuffer == outbuffer);
res = (gint32 *) GST_BUFFER_DATA (outbuffer); res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0], GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
res[1]); res[1]);
fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 8) == 0); fail_unless (memcmp (res, out, 8) == 0);
gst_buffer_unmap (outbuffer, res, size);
/* cleanup */ /* cleanup */
cleanup_volume (volume); cleanup_volume (volume);
@ -854,6 +871,7 @@ GST_START_TEST (test_double_s32)
gint32 in[2] = { 1073741824, -65536 }; gint32 in[2] = { 1073741824, -65536 };
gint32 out[2] = { 2147483647, -131072 }; /* notice the clamped sample */ gint32 out[2] = { 2147483647, -131072 }; /* notice the clamped sample */
gint32 *res; gint32 *res;
gsize size;
volume = setup_volume (); volume = setup_volume ();
g_object_set (G_OBJECT (volume), "volume", 2.0, NULL); g_object_set (G_OBJECT (volume), "volume", 2.0, NULL);
@ -862,8 +880,7 @@ GST_START_TEST (test_double_s32)
"could not set to playing"); "could not set to playing");
inbuffer = gst_buffer_new_and_alloc (8); inbuffer = gst_buffer_new_and_alloc (8);
memcpy (GST_BUFFER_DATA (inbuffer), in, 8); gst_buffer_fill (inbuffer, 0, in, 8);
fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 8) == 0);
caps = gst_caps_from_string (VOLUME_CAPS_STRING_S32); caps = gst_caps_from_string (VOLUME_CAPS_STRING_S32);
gst_buffer_set_caps (inbuffer, caps); gst_buffer_set_caps (inbuffer, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -881,10 +898,11 @@ GST_START_TEST (test_double_s32)
fail_unless_equals_int (g_list_length (buffers), 1); fail_unless_equals_int (g_list_length (buffers), 1);
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
fail_unless (inbuffer == outbuffer); fail_unless (inbuffer == outbuffer);
res = (gint32 *) GST_BUFFER_DATA (outbuffer); res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0], GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
res[1]); res[1]);
fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 8) == 0); fail_unless (memcmp (res, out, 8) == 0);
gst_buffer_unmap (outbuffer, res, size);
/* cleanup */ /* cleanup */
cleanup_volume (volume); cleanup_volume (volume);
@ -902,6 +920,7 @@ GST_START_TEST (test_mute_s32)
gint32 in[2] = { 1073741824, -65536 }; gint32 in[2] = { 1073741824, -65536 };
gint32 out[2] = { 0, 0 }; gint32 out[2] = { 0, 0 };
gint32 *res; gint32 *res;
gsize size;
volume = setup_volume (); volume = setup_volume ();
g_object_set (G_OBJECT (volume), "mute", TRUE, NULL); g_object_set (G_OBJECT (volume), "mute", TRUE, NULL);
@ -910,8 +929,7 @@ GST_START_TEST (test_mute_s32)
"could not set to playing"); "could not set to playing");
inbuffer = gst_buffer_new_and_alloc (8); inbuffer = gst_buffer_new_and_alloc (8);
memcpy (GST_BUFFER_DATA (inbuffer), in, 8); gst_buffer_fill (inbuffer, 0, in, 8);
fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 8) == 0);
caps = gst_caps_from_string (VOLUME_CAPS_STRING_S32); caps = gst_caps_from_string (VOLUME_CAPS_STRING_S32);
gst_buffer_set_caps (inbuffer, caps); gst_buffer_set_caps (inbuffer, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -929,10 +947,11 @@ GST_START_TEST (test_mute_s32)
fail_unless_equals_int (g_list_length (buffers), 1); fail_unless_equals_int (g_list_length (buffers), 1);
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
fail_unless (inbuffer == outbuffer); fail_unless (inbuffer == outbuffer);
res = (gint32 *) GST_BUFFER_DATA (outbuffer); res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0], GST_INFO ("expected %+5d %+5d real %+5d %+5d", out[0], out[1], res[0],
res[1]); res[1]);
fail_unless (memcmp (GST_BUFFER_DATA (outbuffer), out, 8) == 0); fail_unless (memcmp (res, out, 8) == 0);
gst_buffer_unmap (outbuffer, res, size);
/* cleanup */ /* cleanup */
cleanup_volume (volume); cleanup_volume (volume);
@ -947,6 +966,7 @@ GST_START_TEST (test_unity_f32)
GstCaps *caps; GstCaps *caps;
gfloat in[2] = { 0.75, -0.25 }; gfloat in[2] = { 0.75, -0.25 };
gfloat *res; gfloat *res;
gsize size;
volume = setup_volume (); volume = setup_volume ();
fail_unless (gst_element_set_state (volume, fail_unless (gst_element_set_state (volume,
@ -954,7 +974,7 @@ GST_START_TEST (test_unity_f32)
"could not set to playing"); "could not set to playing");
inbuffer = gst_buffer_new_and_alloc (8); inbuffer = gst_buffer_new_and_alloc (8);
memcpy (GST_BUFFER_DATA (inbuffer), in, 8); gst_buffer_fill (inbuffer, 0, in, 8);
caps = gst_caps_from_string (VOLUME_CAPS_STRING_F32); caps = gst_caps_from_string (VOLUME_CAPS_STRING_F32);
gst_buffer_set_caps (inbuffer, caps); gst_buffer_set_caps (inbuffer, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -967,7 +987,7 @@ GST_START_TEST (test_unity_f32)
fail_unless_equals_int (g_list_length (buffers), 1); fail_unless_equals_int (g_list_length (buffers), 1);
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
fail_unless (inbuffer == outbuffer); fail_unless (inbuffer == outbuffer);
res = (gfloat *) GST_BUFFER_DATA (outbuffer); res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", in[0], in[1], res[0], GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", in[0], in[1], res[0],
res[1]); res[1]);
fail_unless_equals_float (res[0], in[0]); fail_unless_equals_float (res[0], in[0]);
@ -988,6 +1008,7 @@ GST_START_TEST (test_half_f32)
gfloat in[2] = { 0.75, -0.25 }; gfloat in[2] = { 0.75, -0.25 };
gfloat out[2] = { 0.375, -0.125 }; gfloat out[2] = { 0.375, -0.125 };
gfloat *res; gfloat *res;
gsize size;
volume = setup_volume (); volume = setup_volume ();
g_object_set (G_OBJECT (volume), "volume", 0.5, NULL); g_object_set (G_OBJECT (volume), "volume", 0.5, NULL);
@ -996,8 +1017,7 @@ GST_START_TEST (test_half_f32)
"could not set to playing"); "could not set to playing");
inbuffer = gst_buffer_new_and_alloc (8); inbuffer = gst_buffer_new_and_alloc (8);
memcpy (GST_BUFFER_DATA (inbuffer), in, 8); gst_buffer_fill (inbuffer, 0, in, 8);
fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 8) == 0);
caps = gst_caps_from_string (VOLUME_CAPS_STRING_F32); caps = gst_caps_from_string (VOLUME_CAPS_STRING_F32);
gst_buffer_set_caps (inbuffer, caps); gst_buffer_set_caps (inbuffer, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -1015,11 +1035,12 @@ GST_START_TEST (test_half_f32)
fail_unless_equals_int (g_list_length (buffers), 1); fail_unless_equals_int (g_list_length (buffers), 1);
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
fail_unless (inbuffer == outbuffer); fail_unless (inbuffer == outbuffer);
res = (gfloat *) GST_BUFFER_DATA (outbuffer); res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", out[0], out[1], GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", out[0], out[1],
res[0], res[1]); res[0], res[1]);
fail_unless_equals_float (res[0], out[0]); fail_unless_equals_float (res[0], out[0]);
fail_unless_equals_float (res[1], out[1]); fail_unless_equals_float (res[1], out[1]);
gst_buffer_unmap (outbuffer, res, size);
/* cleanup */ /* cleanup */
cleanup_volume (volume); cleanup_volume (volume);
@ -1036,6 +1057,7 @@ GST_START_TEST (test_double_f32)
gfloat in[2] = { 0.75, -0.25 }; gfloat in[2] = { 0.75, -0.25 };
gfloat out[2] = { 1.5, -0.5 }; /* nothing is clamped */ gfloat out[2] = { 1.5, -0.5 }; /* nothing is clamped */
gfloat *res; gfloat *res;
gsize size;
volume = setup_volume (); volume = setup_volume ();
g_object_set (G_OBJECT (volume), "volume", 2.0, NULL); g_object_set (G_OBJECT (volume), "volume", 2.0, NULL);
@ -1044,8 +1066,7 @@ GST_START_TEST (test_double_f32)
"could not set to playing"); "could not set to playing");
inbuffer = gst_buffer_new_and_alloc (8); inbuffer = gst_buffer_new_and_alloc (8);
memcpy (GST_BUFFER_DATA (inbuffer), in, 8); gst_buffer_fill (inbuffer, 0, in, 8);
fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 8) == 0);
caps = gst_caps_from_string (VOLUME_CAPS_STRING_F32); caps = gst_caps_from_string (VOLUME_CAPS_STRING_F32);
gst_buffer_set_caps (inbuffer, caps); gst_buffer_set_caps (inbuffer, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -1063,11 +1084,12 @@ GST_START_TEST (test_double_f32)
fail_unless_equals_int (g_list_length (buffers), 1); fail_unless_equals_int (g_list_length (buffers), 1);
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
fail_unless (inbuffer == outbuffer); fail_unless (inbuffer == outbuffer);
res = (gfloat *) GST_BUFFER_DATA (outbuffer); res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", out[0], out[1], GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", out[0], out[1],
res[0], res[1]); res[0], res[1]);
fail_unless_equals_float (res[0], out[0]); fail_unless_equals_float (res[0], out[0]);
fail_unless_equals_float (res[1], out[1]); fail_unless_equals_float (res[1], out[1]);
gst_buffer_unmap (outbuffer, res, size);
/* cleanup */ /* cleanup */
cleanup_volume (volume); cleanup_volume (volume);
@ -1085,6 +1107,7 @@ GST_START_TEST (test_mute_f32)
gfloat in[2] = { 0.75, -0.25 }; gfloat in[2] = { 0.75, -0.25 };
gfloat out[2] = { 0, 0 }; gfloat out[2] = { 0, 0 };
gfloat *res; gfloat *res;
gsize size;
volume = setup_volume (); volume = setup_volume ();
g_object_set (G_OBJECT (volume), "mute", TRUE, NULL); g_object_set (G_OBJECT (volume), "mute", TRUE, NULL);
@ -1093,8 +1116,7 @@ GST_START_TEST (test_mute_f32)
"could not set to playing"); "could not set to playing");
inbuffer = gst_buffer_new_and_alloc (8); inbuffer = gst_buffer_new_and_alloc (8);
memcpy (GST_BUFFER_DATA (inbuffer), in, 8); gst_buffer_fill (inbuffer, 0, in, 8);
fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 8) == 0);
caps = gst_caps_from_string (VOLUME_CAPS_STRING_F32); caps = gst_caps_from_string (VOLUME_CAPS_STRING_F32);
gst_buffer_set_caps (inbuffer, caps); gst_buffer_set_caps (inbuffer, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -1112,11 +1134,12 @@ GST_START_TEST (test_mute_f32)
fail_unless_equals_int (g_list_length (buffers), 1); fail_unless_equals_int (g_list_length (buffers), 1);
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
fail_unless (inbuffer == outbuffer); fail_unless (inbuffer == outbuffer);
res = (gfloat *) GST_BUFFER_DATA (outbuffer); res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", out[0], out[1], GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", out[0], out[1],
res[0], res[1]); res[0], res[1]);
fail_unless_equals_float (res[0], out[0]); fail_unless_equals_float (res[0], out[0]);
fail_unless_equals_float (res[1], out[1]); fail_unless_equals_float (res[1], out[1]);
gst_buffer_unmap (outbuffer, res, size);
/* cleanup */ /* cleanup */
cleanup_volume (volume); cleanup_volume (volume);
@ -1131,6 +1154,7 @@ GST_START_TEST (test_unity_f64)
GstCaps *caps; GstCaps *caps;
gdouble in[2] = { 0.75, -0.25 }; gdouble in[2] = { 0.75, -0.25 };
gdouble *res; gdouble *res;
gsize size;
volume = setup_volume (); volume = setup_volume ();
fail_unless (gst_element_set_state (volume, fail_unless (gst_element_set_state (volume,
@ -1138,7 +1162,7 @@ GST_START_TEST (test_unity_f64)
"could not set to playing"); "could not set to playing");
inbuffer = gst_buffer_new_and_alloc (16); inbuffer = gst_buffer_new_and_alloc (16);
memcpy (GST_BUFFER_DATA (inbuffer), in, 16); gst_buffer_fill (inbuffer, 0, in, 16);
caps = gst_caps_from_string (VOLUME_CAPS_STRING_F64); caps = gst_caps_from_string (VOLUME_CAPS_STRING_F64);
gst_buffer_set_caps (inbuffer, caps); gst_buffer_set_caps (inbuffer, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -1151,7 +1175,7 @@ GST_START_TEST (test_unity_f64)
fail_unless_equals_int (g_list_length (buffers), 1); fail_unless_equals_int (g_list_length (buffers), 1);
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
fail_unless (inbuffer == outbuffer); fail_unless (inbuffer == outbuffer);
res = (gdouble *) GST_BUFFER_DATA (outbuffer); res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", in[0], in[1], res[0], GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", in[0], in[1], res[0],
res[1]); res[1]);
fail_unless_equals_float (res[0], in[0]); fail_unless_equals_float (res[0], in[0]);
@ -1172,6 +1196,7 @@ GST_START_TEST (test_half_f64)
gdouble in[2] = { 0.75, -0.25 }; gdouble in[2] = { 0.75, -0.25 };
gdouble out[2] = { 0.375, -0.125 }; gdouble out[2] = { 0.375, -0.125 };
gdouble *res; gdouble *res;
gsize size;
volume = setup_volume (); volume = setup_volume ();
g_object_set (G_OBJECT (volume), "volume", 0.5, NULL); g_object_set (G_OBJECT (volume), "volume", 0.5, NULL);
@ -1180,8 +1205,7 @@ GST_START_TEST (test_half_f64)
"could not set to playing"); "could not set to playing");
inbuffer = gst_buffer_new_and_alloc (16); inbuffer = gst_buffer_new_and_alloc (16);
memcpy (GST_BUFFER_DATA (inbuffer), in, 16); gst_buffer_fill (inbuffer, 0, in, 16);
fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 16) == 0);
caps = gst_caps_from_string (VOLUME_CAPS_STRING_F64); caps = gst_caps_from_string (VOLUME_CAPS_STRING_F64);
gst_buffer_set_caps (inbuffer, caps); gst_buffer_set_caps (inbuffer, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -1199,11 +1223,12 @@ GST_START_TEST (test_half_f64)
fail_unless_equals_int (g_list_length (buffers), 1); fail_unless_equals_int (g_list_length (buffers), 1);
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
fail_unless (inbuffer == outbuffer); fail_unless (inbuffer == outbuffer);
res = (gdouble *) GST_BUFFER_DATA (outbuffer); res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", out[0], out[1], GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", out[0], out[1],
res[0], res[1]); res[0], res[1]);
fail_unless_equals_float (res[0], out[0]); fail_unless_equals_float (res[0], out[0]);
fail_unless_equals_float (res[1], out[1]); fail_unless_equals_float (res[1], out[1]);
gst_buffer_unmap (outbuffer, res, size);
/* cleanup */ /* cleanup */
cleanup_volume (volume); cleanup_volume (volume);
@ -1220,6 +1245,7 @@ GST_START_TEST (test_double_f64)
gdouble in[2] = { 0.75, -0.25 }; gdouble in[2] = { 0.75, -0.25 };
gdouble out[2] = { 1.5, -0.5 }; /* nothing is clamped */ gdouble out[2] = { 1.5, -0.5 }; /* nothing is clamped */
gdouble *res; gdouble *res;
gsize size;
volume = setup_volume (); volume = setup_volume ();
g_object_set (G_OBJECT (volume), "volume", 2.0, NULL); g_object_set (G_OBJECT (volume), "volume", 2.0, NULL);
@ -1228,8 +1254,7 @@ GST_START_TEST (test_double_f64)
"could not set to playing"); "could not set to playing");
inbuffer = gst_buffer_new_and_alloc (16); inbuffer = gst_buffer_new_and_alloc (16);
memcpy (GST_BUFFER_DATA (inbuffer), in, 16); gst_buffer_fill (inbuffer, 0, in, 16);
fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 16) == 0);
caps = gst_caps_from_string (VOLUME_CAPS_STRING_F64); caps = gst_caps_from_string (VOLUME_CAPS_STRING_F64);
gst_buffer_set_caps (inbuffer, caps); gst_buffer_set_caps (inbuffer, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -1247,11 +1272,12 @@ GST_START_TEST (test_double_f64)
fail_unless_equals_int (g_list_length (buffers), 1); fail_unless_equals_int (g_list_length (buffers), 1);
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
fail_unless (inbuffer == outbuffer); fail_unless (inbuffer == outbuffer);
res = (gdouble *) GST_BUFFER_DATA (outbuffer); res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", out[0], out[1], GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", out[0], out[1],
res[0], res[1]); res[0], res[1]);
fail_unless_equals_float (res[0], out[0]); fail_unless_equals_float (res[0], out[0]);
fail_unless_equals_float (res[1], out[1]); fail_unless_equals_float (res[1], out[1]);
gst_buffer_unmap (outbuffer, res, size);
/* cleanup */ /* cleanup */
cleanup_volume (volume); cleanup_volume (volume);
@ -1269,6 +1295,7 @@ GST_START_TEST (test_mute_f64)
gdouble in[2] = { 0.75, -0.25 }; gdouble in[2] = { 0.75, -0.25 };
gdouble out[2] = { 0, 0 }; gdouble out[2] = { 0, 0 };
gdouble *res; gdouble *res;
gsize size;
volume = setup_volume (); volume = setup_volume ();
g_object_set (G_OBJECT (volume), "mute", TRUE, NULL); g_object_set (G_OBJECT (volume), "mute", TRUE, NULL);
@ -1277,8 +1304,7 @@ GST_START_TEST (test_mute_f64)
"could not set to playing"); "could not set to playing");
inbuffer = gst_buffer_new_and_alloc (16); inbuffer = gst_buffer_new_and_alloc (16);
memcpy (GST_BUFFER_DATA (inbuffer), in, 16); gst_buffer_fill (inbuffer, 0, in, 16);
fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 16) == 0);
caps = gst_caps_from_string (VOLUME_CAPS_STRING_F64); caps = gst_caps_from_string (VOLUME_CAPS_STRING_F64);
gst_buffer_set_caps (inbuffer, caps); gst_buffer_set_caps (inbuffer, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -1296,11 +1322,12 @@ GST_START_TEST (test_mute_f64)
fail_unless_equals_int (g_list_length (buffers), 1); fail_unless_equals_int (g_list_length (buffers), 1);
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
fail_unless (inbuffer == outbuffer); fail_unless (inbuffer == outbuffer);
res = (gdouble *) GST_BUFFER_DATA (outbuffer); res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", out[0], out[1], GST_INFO ("expected %+1.4f %+1.4f real %+1.4f %+1.4f", out[0], out[1],
res[0], res[1]); res[0], res[1]);
fail_unless_equals_float (res[0], out[0]); fail_unless_equals_float (res[0], out[0]);
fail_unless_equals_float (res[1], out[1]); fail_unless_equals_float (res[1], out[1]);
gst_buffer_unmap (outbuffer, res, size);
/* cleanup */ /* cleanup */
cleanup_volume (volume); cleanup_volume (volume);
@ -1325,7 +1352,7 @@ GST_START_TEST (test_wrong_caps)
"could not set to playing"); "could not set to playing");
inbuffer = gst_buffer_new_and_alloc (4); inbuffer = gst_buffer_new_and_alloc (4);
memcpy (GST_BUFFER_DATA (inbuffer), in, 4); gst_buffer_fill (inbuffer, 0, in, 4);
caps = gst_caps_from_string (VOLUME_WRONG_CAPS_STRING); caps = gst_caps_from_string (VOLUME_WRONG_CAPS_STRING);
gst_buffer_set_caps (inbuffer, caps); gst_buffer_set_caps (inbuffer, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -1362,6 +1389,7 @@ GST_START_TEST (test_passthrough)
GstCaps *caps; GstCaps *caps;
gint16 in[2] = { 16384, -256 }; gint16 in[2] = { 16384, -256 };
gint16 *res; gint16 *res;
gsize size;
volume = setup_volume (); volume = setup_volume ();
g_object_set (G_OBJECT (volume), "volume", 1.0, NULL); g_object_set (G_OBJECT (volume), "volume", 1.0, NULL);
@ -1370,7 +1398,7 @@ GST_START_TEST (test_passthrough)
"could not set to playing"); "could not set to playing");
inbuffer = gst_buffer_new_and_alloc (4); inbuffer = gst_buffer_new_and_alloc (4);
memcpy (GST_BUFFER_DATA (inbuffer), in, 4); gst_buffer_fill (inbuffer, 0, in, 4);
caps = gst_caps_from_string (VOLUME_CAPS_STRING_S16); caps = gst_caps_from_string (VOLUME_CAPS_STRING_S16);
gst_buffer_set_caps (inbuffer, caps); gst_buffer_set_caps (inbuffer, caps);
gst_caps_unref (caps); gst_caps_unref (caps);
@ -1383,9 +1411,10 @@ GST_START_TEST (test_passthrough)
fail_unless_equals_int (g_list_length (buffers), 1); fail_unless_equals_int (g_list_length (buffers), 1);
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
fail_unless (inbuffer == outbuffer); fail_unless (inbuffer == outbuffer);
res = (gint16 *) GST_BUFFER_DATA (outbuffer); res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
GST_INFO ("expected %+5d %+5d real %+5d %+5d", in[0], in[1], res[0], res[1]); GST_INFO ("expected %+5d %+5d real %+5d %+5d", in[0], in[1], res[0], res[1]);
fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 4) == 0); fail_unless (memcmp (res, in, 4) == 0);
gst_buffer_unmap (outbuffer, res, size);
/* cleanup */ /* cleanup */
cleanup_volume (volume); cleanup_volume (volume);
@ -1439,6 +1468,7 @@ GST_START_TEST (test_controller_processing)
GstCaps *caps; GstCaps *caps;
gint16 in[2] = { 16384, -256 }; gint16 in[2] = { 16384, -256 };
gint16 *res; gint16 *res;
gsize size;
volume = setup_volume (); volume = setup_volume ();
@ -1457,7 +1487,7 @@ GST_START_TEST (test_controller_processing)
"could not set to playing"); "could not set to playing");
inbuffer = gst_buffer_new_and_alloc (4); inbuffer = gst_buffer_new_and_alloc (4);
memcpy (GST_BUFFER_DATA (inbuffer), in, 4); gst_buffer_fill (inbuffer, 0, in, 4);
caps = gst_caps_from_string (VOLUME_CAPS_STRING_S16); caps = gst_caps_from_string (VOLUME_CAPS_STRING_S16);
gst_buffer_set_caps (inbuffer, caps); gst_buffer_set_caps (inbuffer, caps);
GST_BUFFER_TIMESTAMP (inbuffer) = 0; GST_BUFFER_TIMESTAMP (inbuffer) = 0;
@ -1471,9 +1501,10 @@ GST_START_TEST (test_controller_processing)
fail_unless_equals_int (g_list_length (buffers), 1); fail_unless_equals_int (g_list_length (buffers), 1);
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL); fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
fail_unless (inbuffer == outbuffer); fail_unless (inbuffer == outbuffer);
res = (gint16 *) GST_BUFFER_DATA (outbuffer); res = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
GST_INFO ("expected %+5d %+5d real %+5d %+5d", in[0], in[1], res[0], res[1]); GST_INFO ("expected %+5d %+5d real %+5d %+5d", in[0], in[1], res[0], res[1]);
fail_unless (memcmp (GST_BUFFER_DATA (inbuffer), in, 4) == 0); fail_unless (memcmp (res, in, 4) == 0);
gst_buffer_unmap (outbuffer, res, size);
g_object_unref (c); g_object_unref (c);

View file

@ -147,7 +147,7 @@ GST_START_TEST (test_identification_header)
bus = gst_bus_new (); bus = gst_bus_new ();
inbuffer = gst_buffer_new_and_alloc (30); inbuffer = gst_buffer_new_and_alloc (30);
memcpy (GST_BUFFER_DATA (inbuffer), identification_header, 30); gst_buffer_fill (inbuffer, 0, identification_header, 30);
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
gst_buffer_ref (inbuffer); gst_buffer_ref (inbuffer);
@ -161,7 +161,7 @@ GST_START_TEST (test_identification_header)
fail_if ((message = gst_bus_pop (bus)) != NULL); fail_if ((message = gst_bus_pop (bus)) != NULL);
inbuffer = gst_buffer_new_and_alloc (sizeof (comment_header)); inbuffer = gst_buffer_new_and_alloc (sizeof (comment_header));
memcpy (GST_BUFFER_DATA (inbuffer), comment_header, sizeof (comment_header)); gst_buffer_fill (inbuffer, 0, comment_header, sizeof (comment_header));
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
gst_buffer_ref (inbuffer); gst_buffer_ref (inbuffer);
@ -214,7 +214,7 @@ _create_codebook_header_buffer (void)
vorbis_analysis_headerout (&vd, &vc, &header, &header_comm, &header_code); vorbis_analysis_headerout (&vd, &vc, &header, &header_comm, &header_code);
buffer = gst_buffer_new_and_alloc (header_code.bytes); buffer = gst_buffer_new_and_alloc (header_code.bytes);
memcpy (GST_BUFFER_DATA (buffer), header_code.packet, header_code.bytes); gst_buffer_fill (buffer, 0, header_code.packet, header_code.bytes);
return buffer; return buffer;
} }
@ -236,7 +236,7 @@ _create_audio_buffer (void)
vorbis_bitrate_addblock (&vb); vorbis_bitrate_addblock (&vb);
vorbis_bitrate_flushpacket (&vd, &packet); vorbis_bitrate_flushpacket (&vd, &packet);
buffer = gst_buffer_new_and_alloc (packet.bytes); buffer = gst_buffer_new_and_alloc (packet.bytes);
memcpy (GST_BUFFER_DATA (buffer), packet.packet, packet.bytes); gst_buffer_fill (buffer, 0, packet.packet, packet.bytes);
vorbis_comment_clear (&vc); vorbis_comment_clear (&vc);
vorbis_block_clear (&vb); vorbis_block_clear (&vb);
@ -260,7 +260,7 @@ GST_START_TEST (test_empty_vorbis_packet)
bus = gst_bus_new (); bus = gst_bus_new ();
inbuffer = gst_buffer_new_and_alloc (30); inbuffer = gst_buffer_new_and_alloc (30);
memcpy (GST_BUFFER_DATA (inbuffer), identification_header, 30); gst_buffer_fill (inbuffer, 0, identification_header, 30);
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
gst_buffer_ref (inbuffer); gst_buffer_ref (inbuffer);
@ -275,7 +275,7 @@ GST_START_TEST (test_empty_vorbis_packet)
fail_if ((message = gst_bus_pop (bus)) != NULL); fail_if ((message = gst_bus_pop (bus)) != NULL);
inbuffer = gst_buffer_new_and_alloc (sizeof (comment_header)); inbuffer = gst_buffer_new_and_alloc (sizeof (comment_header));
memcpy (GST_BUFFER_DATA (inbuffer), comment_header, sizeof (comment_header)); gst_buffer_fill (inbuffer, 0, comment_header, sizeof (comment_header));
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
gst_buffer_ref (inbuffer); gst_buffer_ref (inbuffer);

View file

@ -160,6 +160,19 @@ stop_pipeline (GstElement * element)
pending_buffers = NULL; pending_buffers = NULL;
} }
static void
compare_buffer (GstBuffer * buf, const guint8 * data, gsize size)
{
guint8 *bdata;
gsize bsize;
bdata = gst_buffer_map (buf, &bsize, NULL, GST_MAP_READ);
fail_unless_equals_int (bsize, size);
fail_unless_equals_int (memcmp (bdata,
title_comment_header, sizeof (title_comment_header)), 0);
gst_buffer_unmap (buf, bdata, bsize);
}
static vorbis_comment vc; static vorbis_comment vc;
static vorbis_dsp_state vd; static vorbis_dsp_state vd;
static vorbis_info vi; static vorbis_info vi;
@ -182,7 +195,7 @@ _create_codebook_header_buffer (void)
vorbis_analysis_headerout (&vd, &vc, &header, &header_comm, &header_code); vorbis_analysis_headerout (&vd, &vc, &header, &header_comm, &header_code);
buffer = gst_buffer_new_and_alloc (header_code.bytes); buffer = gst_buffer_new_and_alloc (header_code.bytes);
memcpy (GST_BUFFER_DATA (buffer), header_code.packet, header_code.bytes); gst_buffer_fill (buffer, 0, header_code.packet, header_code.bytes);
return buffer; return buffer;
} }
@ -201,7 +214,7 @@ _create_audio_buffer (void)
vorbis_bitrate_addblock (&vb); vorbis_bitrate_addblock (&vb);
vorbis_bitrate_flushpacket (&vd, &packet); vorbis_bitrate_flushpacket (&vd, &packet);
buffer = gst_buffer_new_and_alloc (packet.bytes); buffer = gst_buffer_new_and_alloc (packet.bytes);
memcpy (GST_BUFFER_DATA (buffer), packet.packet, packet.bytes); gst_buffer_fill (buffer, 0, packet.packet, packet.bytes);
vorbis_comment_clear (&vc); vorbis_comment_clear (&vc);
vorbis_block_clear (&vb); vorbis_block_clear (&vb);
@ -232,13 +245,13 @@ GST_START_TEST (test_empty_tags_set)
/* send identification header */ /* send identification header */
inbuffer = gst_buffer_new_and_alloc (sizeof (identification_header)); inbuffer = gst_buffer_new_and_alloc (sizeof (identification_header));
memcpy (GST_BUFFER_DATA (inbuffer), identification_header, gst_buffer_fill (inbuffer, 0, identification_header,
sizeof (identification_header)); sizeof (identification_header));
fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK); fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK);
/* send empty comment buffer */ /* send empty comment buffer */
inbuffer = gst_buffer_new_and_alloc (sizeof (empty_comment_header)); inbuffer = gst_buffer_new_and_alloc (sizeof (empty_comment_header));
memcpy (GST_BUFFER_DATA (inbuffer), empty_comment_header, gst_buffer_fill (inbuffer, 0, empty_comment_header,
sizeof (empty_comment_header)); sizeof (empty_comment_header));
fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK); fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK);
@ -251,18 +264,14 @@ GST_START_TEST (test_empty_tags_set)
/* check identification header is unchanged */ /* check identification header is unchanged */
outbuffer = get_buffer (); outbuffer = get_buffer ();
fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), compare_buffer (outbuffer, identification_header,
sizeof (identification_header)); sizeof (identification_header));
fail_unless_equals_int (memcmp (GST_BUFFER_DATA (outbuffer),
identification_header, sizeof (identification_header)), 0);
gst_buffer_unref (outbuffer); gst_buffer_unref (outbuffer);
/* check comment header is correct */ /* check comment header is correct */
outbuffer = get_buffer (); outbuffer = get_buffer ();
fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), compare_buffer (outbuffer, title_comment_header,
sizeof (title_comment_header)); sizeof (title_comment_header));
fail_unless_equals_int (memcmp (GST_BUFFER_DATA (outbuffer),
title_comment_header, sizeof (title_comment_header)), 0);
gst_buffer_unref (outbuffer); gst_buffer_unref (outbuffer);
stop_pipeline (vorbistag); stop_pipeline (vorbistag);
@ -291,13 +300,13 @@ GST_START_TEST (test_filled_tags_unset)
/* send identification header */ /* send identification header */
inbuffer = gst_buffer_new_and_alloc (sizeof (identification_header)); inbuffer = gst_buffer_new_and_alloc (sizeof (identification_header));
memcpy (GST_BUFFER_DATA (inbuffer), identification_header, gst_buffer_fill (inbuffer, 0, identification_header,
sizeof (identification_header)); sizeof (identification_header));
fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK); fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK);
/* send empty comment buffer */ /* send empty comment buffer */
inbuffer = gst_buffer_new_and_alloc (sizeof (title_comment_header)); inbuffer = gst_buffer_new_and_alloc (sizeof (title_comment_header));
memcpy (GST_BUFFER_DATA (inbuffer), title_comment_header, gst_buffer_fill (inbuffer, 0, title_comment_header,
sizeof (title_comment_header)); sizeof (title_comment_header));
fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK); fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK);
@ -310,18 +319,14 @@ GST_START_TEST (test_filled_tags_unset)
/* check identification header is unchanged */ /* check identification header is unchanged */
outbuffer = get_buffer (); outbuffer = get_buffer ();
fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), compare_buffer (outbuffer, identification_header,
sizeof (identification_header)); sizeof (identification_header));
fail_unless_equals_int (memcmp (GST_BUFFER_DATA (outbuffer),
identification_header, sizeof (identification_header)), 0);
gst_buffer_unref (outbuffer); gst_buffer_unref (outbuffer);
/* check comment header is correct */ /* check comment header is correct */
outbuffer = get_buffer (); outbuffer = get_buffer ();
fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), compare_buffer (outbuffer, empty_comment_header,
sizeof (empty_comment_header)); sizeof (empty_comment_header));
fail_unless_equals_int (memcmp (GST_BUFFER_DATA (outbuffer),
empty_comment_header, sizeof (empty_comment_header)), 0);
gst_buffer_unref (outbuffer); gst_buffer_unref (outbuffer);
stop_pipeline (vorbistag); stop_pipeline (vorbistag);
@ -351,13 +356,13 @@ GST_START_TEST (test_filled_tags_change)
/* send identification header */ /* send identification header */
inbuffer = gst_buffer_new_and_alloc (sizeof (identification_header)); inbuffer = gst_buffer_new_and_alloc (sizeof (identification_header));
memcpy (GST_BUFFER_DATA (inbuffer), identification_header, gst_buffer_fill (inbuffer, 0, identification_header,
sizeof (identification_header)); sizeof (identification_header));
fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK); fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK);
/* send empty comment buffer */ /* send empty comment buffer */
inbuffer = gst_buffer_new_and_alloc (sizeof (artist_comment_header)); inbuffer = gst_buffer_new_and_alloc (sizeof (artist_comment_header));
memcpy (GST_BUFFER_DATA (inbuffer), artist_comment_header, gst_buffer_fill (inbuffer, 0, artist_comment_header,
sizeof (artist_comment_header)); sizeof (artist_comment_header));
fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK); fail_unless_equals_int (gst_pad_push (mysrcpad, inbuffer), GST_FLOW_OK);
@ -370,18 +375,14 @@ GST_START_TEST (test_filled_tags_change)
/* check identification header is unchanged */ /* check identification header is unchanged */
outbuffer = get_buffer (); outbuffer = get_buffer ();
fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), compare_buffer (outbuffer, identification_header,
sizeof (identification_header)); sizeof (identification_header));
fail_unless_equals_int (memcmp (GST_BUFFER_DATA (outbuffer),
identification_header, sizeof (identification_header)), 0);
gst_buffer_unref (outbuffer); gst_buffer_unref (outbuffer);
/* check comment header is correct */ /* check comment header is correct */
outbuffer = get_buffer (); outbuffer = get_buffer ();
fail_unless_equals_int (GST_BUFFER_SIZE (outbuffer), compare_buffer (outbuffer, title_comment_header,
sizeof (title_comment_header)); sizeof (title_comment_header));
fail_unless_equals_int (memcmp (GST_BUFFER_DATA (outbuffer),
title_comment_header, sizeof (title_comment_header)), 0);
gst_buffer_unref (outbuffer); gst_buffer_unref (outbuffer);
stop_pipeline (vorbistag); stop_pipeline (vorbistag);

View file

@ -62,8 +62,11 @@ GST_START_TEST (test_quicktime_mpeg4video)
GstCaps *caps = NULL; GstCaps *caps = NULL;
buf = gst_buffer_new (); buf = gst_buffer_new ();
GST_BUFFER_DATA (buf) = (guint8 *) qt_redirect_396042; gst_buffer_take_memory (buf,
GST_BUFFER_SIZE (buf) = sizeof (qt_redirect_396042); gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY,
(gpointer) qt_redirect_396042, NULL,
sizeof (qt_redirect_396042), 0, sizeof (qt_redirect_396042)));
GST_BUFFER_OFFSET (buf) = 0; GST_BUFFER_OFFSET (buf) = 0;
caps = gst_type_find_helper_for_buffer (NULL, buf, &prob); caps = gst_type_find_helper_for_buffer (NULL, buf, &prob);
@ -89,8 +92,11 @@ GST_START_TEST (test_broken_flac_in_ogg)
GstCaps *caps = NULL; GstCaps *caps = NULL;
buf = gst_buffer_new (); buf = gst_buffer_new ();
GST_BUFFER_DATA (buf) = (guint8 *) flac_id_packet; gst_buffer_take_memory (buf,
GST_BUFFER_SIZE (buf) = sizeof (flac_id_packet); gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY,
(gpointer) flac_id_packet, NULL,
sizeof (flac_id_packet), 0, sizeof (flac_id_packet)));
GST_BUFFER_OFFSET (buf) = 0; GST_BUFFER_OFFSET (buf) = 0;
caps = gst_type_find_helper_for_buffer (NULL, buf, &prob); caps = gst_type_find_helper_for_buffer (NULL, buf, &prob);
@ -123,8 +129,10 @@ typefind_test_file (const gchar * filename)
} }
buf = gst_buffer_new (); buf = gst_buffer_new ();
GST_BUFFER_DATA (buf) = (guint8 *) data; gst_buffer_take_memory (buf,
GST_BUFFER_SIZE (buf) = data_len; gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY,
(gpointer) data, NULL, data_len, 0, data_len));
GST_BUFFER_OFFSET (buf) = 0; GST_BUFFER_OFFSET (buf) = 0;
caps = gst_type_find_helper_for_buffer (NULL, buf, NULL); caps = gst_type_find_helper_for_buffer (NULL, buf, NULL);
@ -222,11 +230,14 @@ GST_START_TEST (test_ac3)
GstBuffer *buf; GstBuffer *buf;
GstCaps *caps = NULL; GstCaps *caps = NULL;
guint bsid; guint bsid;
guint8 *data;
for (bsid = 0; bsid < 32; bsid++) { for (bsid = 0; bsid < 32; bsid++) {
buf = gst_buffer_new_and_alloc ((256 + 640) * 2); buf = gst_buffer_new_and_alloc ((256 + 640) * 2);
make_ac3_packet (GST_BUFFER_DATA (buf), 256 * 2, bsid); data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
make_ac3_packet (GST_BUFFER_DATA (buf) + 256 * 2, 640 * 2, bsid); make_ac3_packet (data, 256 * 2, bsid);
make_ac3_packet (data + 256 * 2, 640 * 2, bsid);
gst_buffer_unmap (buf, data, (256 + 640) * 2);
caps = gst_type_find_helper_for_buffer (NULL, buf, &prob); caps = gst_type_find_helper_for_buffer (NULL, buf, &prob);
if (bsid <= 8) { if (bsid <= 8) {
@ -281,11 +292,14 @@ GST_START_TEST (test_eac3)
GstBuffer *buf; GstBuffer *buf;
GstCaps *caps = NULL; GstCaps *caps = NULL;
guint bsid; guint bsid;
guint8 *data;
for (bsid = 0; bsid <= 32; bsid++) { for (bsid = 0; bsid <= 32; bsid++) {
buf = gst_buffer_new_and_alloc (558 + 384); buf = gst_buffer_new_and_alloc (558 + 384);
make_eac3_packet (GST_BUFFER_DATA (buf), 558, bsid); data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
make_eac3_packet (GST_BUFFER_DATA (buf) + 558, 384, bsid); make_eac3_packet (data, 558, bsid);
make_eac3_packet (data + 558, 384, bsid);
gst_buffer_unmap (buf, data, 558 + 384);
caps = gst_type_find_helper_for_buffer (NULL, buf, &prob); caps = gst_type_find_helper_for_buffer (NULL, buf, &prob);
if (bsid > 10 && bsid <= 16) { if (bsid > 10 && bsid <= 16) {
@ -335,8 +349,10 @@ GST_START_TEST (test_random_data)
data[i] = g_random_int () & 0xff; data[i] = g_random_int () & 0xff;
buf = gst_buffer_new (); buf = gst_buffer_new ();
GST_BUFFER_DATA (buf) = (guint8 *) data; gst_buffer_take_memory (buf,
GST_BUFFER_SIZE (buf) = TEST_RANDOM_DATA_SIZE; gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY,
data, NULL, TEST_RANDOM_DATA_SIZE, 0, TEST_RANDOM_DATA_SIZE));
GST_BUFFER_OFFSET (buf) = 0; GST_BUFFER_OFFSET (buf) = 0;
caps = gst_type_find_helper_for_buffer (NULL, buf, &prob); caps = gst_type_find_helper_for_buffer (NULL, buf, &prob);

View file

@ -127,18 +127,16 @@ GST_END_TEST;
GST_START_TEST (test_buffer_clipping_time) GST_START_TEST (test_buffer_clipping_time)
{ {
GstSegment s; GstSegment s;
GstBuffer *buf; GstBuffer *buf;
GstBuffer *ret; GstBuffer *ret;
guint8 *data, *sdata;
guint8 *data; gsize ssize;
/* Clip start and end */ /* Clip start and end */
buf = gst_buffer_new (); buf = gst_buffer_new ();
data = (guint8 *) g_malloc (1000); data = (guint8 *) g_malloc (1000);
GST_BUFFER_SIZE (buf) = 1000; gst_buffer_take_memory (buf,
GST_BUFFER_DATA (buf) = GST_BUFFER_MALLOCDATA (buf) = data; gst_memory_new_wrapped (0, data, g_free, 1000, 0, 1000));
gst_segment_init (&s, GST_FORMAT_TIME); gst_segment_init (&s, GST_FORMAT_TIME);
gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_TIME, 4 * GST_SECOND, gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_TIME, 4 * GST_SECOND,
@ -156,16 +154,18 @@ GST_START_TEST (test_buffer_clipping_time)
fail_unless (GST_BUFFER_DURATION (ret) == 4 * GST_SECOND); fail_unless (GST_BUFFER_DURATION (ret) == 4 * GST_SECOND);
fail_unless (GST_BUFFER_OFFSET (ret) == 400); fail_unless (GST_BUFFER_OFFSET (ret) == 400);
fail_unless (GST_BUFFER_OFFSET_END (ret) == 800); fail_unless (GST_BUFFER_OFFSET_END (ret) == 800);
fail_unless (GST_BUFFER_DATA (ret) == data + 200); sdata = gst_buffer_map (ret, &ssize, NULL, GST_MAP_READ);
fail_unless (GST_BUFFER_SIZE (ret) == 400); fail_unless (sdata == data + 200);
fail_unless (ssize == 400);
gst_buffer_unmap (ret, sdata, ssize);
gst_buffer_unref (ret); gst_buffer_unref (ret);
/* Clip only start */ /* Clip only start */
buf = gst_buffer_new (); buf = gst_buffer_new ();
data = (guint8 *) g_malloc (1000); data = (guint8 *) g_malloc (1000);
GST_BUFFER_SIZE (buf) = 1000; gst_buffer_take_memory (buf,
GST_BUFFER_DATA (buf) = GST_BUFFER_MALLOCDATA (buf) = data; gst_memory_new_wrapped (0, data, g_free, 1000, 0, 1000));
gst_segment_init (&s, GST_FORMAT_TIME); gst_segment_init (&s, GST_FORMAT_TIME);
gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_TIME, 4 * GST_SECOND, gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_TIME, 4 * GST_SECOND,
@ -183,16 +183,18 @@ GST_START_TEST (test_buffer_clipping_time)
fail_unless (GST_BUFFER_DURATION (ret) == 8 * GST_SECOND); fail_unless (GST_BUFFER_DURATION (ret) == 8 * GST_SECOND);
fail_unless (GST_BUFFER_OFFSET (ret) == 400); fail_unless (GST_BUFFER_OFFSET (ret) == 400);
fail_unless (GST_BUFFER_OFFSET_END (ret) == 1200); fail_unless (GST_BUFFER_OFFSET_END (ret) == 1200);
fail_unless (GST_BUFFER_DATA (ret) == data + 200); sdata = gst_buffer_map (ret, &ssize, NULL, GST_MAP_READ);
fail_unless (GST_BUFFER_SIZE (ret) == 800); fail_unless (sdata == data + 200);
fail_unless (ssize == 800);
gst_buffer_unmap (ret, sdata, ssize);
gst_buffer_unref (ret); gst_buffer_unref (ret);
/* Clip only stop */ /* Clip only stop */
buf = gst_buffer_new (); buf = gst_buffer_new ();
data = (guint8 *) g_malloc (1000); data = (guint8 *) g_malloc (1000);
GST_BUFFER_SIZE (buf) = 1000; gst_buffer_take_memory (buf,
GST_BUFFER_DATA (buf) = GST_BUFFER_MALLOCDATA (buf) = data; gst_memory_new_wrapped (0, data, g_free, 1000, 0, 1000));
gst_segment_init (&s, GST_FORMAT_TIME); gst_segment_init (&s, GST_FORMAT_TIME);
gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_TIME, 2 * GST_SECOND, gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_TIME, 2 * GST_SECOND,
@ -210,16 +212,18 @@ GST_START_TEST (test_buffer_clipping_time)
fail_unless (GST_BUFFER_DURATION (ret) == 8 * GST_SECOND); fail_unless (GST_BUFFER_DURATION (ret) == 8 * GST_SECOND);
fail_unless (GST_BUFFER_OFFSET (ret) == 200); fail_unless (GST_BUFFER_OFFSET (ret) == 200);
fail_unless (GST_BUFFER_OFFSET_END (ret) == 1000); fail_unless (GST_BUFFER_OFFSET_END (ret) == 1000);
fail_unless (GST_BUFFER_DATA (ret) == data); sdata = gst_buffer_map (ret, &ssize, NULL, GST_MAP_READ);
fail_unless (GST_BUFFER_SIZE (ret) == 800); fail_unless (sdata == data);
fail_unless (ssize == 800);
gst_buffer_unmap (ret, sdata, ssize);
gst_buffer_unref (ret); gst_buffer_unref (ret);
/* Buffer outside segment */ /* Buffer outside segment */
buf = gst_buffer_new (); buf = gst_buffer_new ();
data = (guint8 *) g_malloc (1000); data = (guint8 *) g_malloc (1000);
GST_BUFFER_SIZE (buf) = 1000; gst_buffer_take_memory (buf,
GST_BUFFER_DATA (buf) = GST_BUFFER_MALLOCDATA (buf) = data; gst_memory_new_wrapped (0, data, g_free, 1000, 0, 1000));
gst_segment_init (&s, GST_FORMAT_TIME); gst_segment_init (&s, GST_FORMAT_TIME);
gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_TIME, 12 * GST_SECOND, gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_TIME, 12 * GST_SECOND,
@ -236,8 +240,8 @@ GST_START_TEST (test_buffer_clipping_time)
/* Clip start and end but don't touch duration and offset_end */ /* Clip start and end but don't touch duration and offset_end */
buf = gst_buffer_new (); buf = gst_buffer_new ();
data = (guint8 *) g_malloc (1000); data = (guint8 *) g_malloc (1000);
GST_BUFFER_SIZE (buf) = 1000; gst_buffer_take_memory (buf,
GST_BUFFER_DATA (buf) = GST_BUFFER_MALLOCDATA (buf) = data; gst_memory_new_wrapped (0, data, g_free, 1000, 0, 1000));
gst_segment_init (&s, GST_FORMAT_TIME); gst_segment_init (&s, GST_FORMAT_TIME);
gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_TIME, 4 * GST_SECOND, gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_TIME, 4 * GST_SECOND,
@ -255,8 +259,10 @@ GST_START_TEST (test_buffer_clipping_time)
fail_unless (GST_BUFFER_DURATION (ret) == GST_CLOCK_TIME_NONE); fail_unless (GST_BUFFER_DURATION (ret) == GST_CLOCK_TIME_NONE);
fail_unless (GST_BUFFER_OFFSET (ret) == 400); fail_unless (GST_BUFFER_OFFSET (ret) == 400);
fail_unless (GST_BUFFER_OFFSET_END (ret) == GST_BUFFER_OFFSET_NONE); fail_unless (GST_BUFFER_OFFSET_END (ret) == GST_BUFFER_OFFSET_NONE);
fail_unless (GST_BUFFER_DATA (ret) == data + 200); sdata = gst_buffer_map (ret, &ssize, NULL, GST_MAP_READ);
fail_unless (GST_BUFFER_SIZE (ret) == 400); fail_unless (sdata == data + 200);
fail_unless (ssize == 400);
gst_buffer_unmap (ret, sdata, ssize);
gst_buffer_unref (ret); gst_buffer_unref (ret);
@ -266,8 +272,8 @@ GST_START_TEST (test_buffer_clipping_time)
*/ */
buf = gst_buffer_new (); buf = gst_buffer_new ();
data = (guint8 *) g_malloc (1000); data = (guint8 *) g_malloc (1000);
GST_BUFFER_SIZE (buf) = 1000; gst_buffer_take_memory (buf,
GST_BUFFER_DATA (buf) = GST_BUFFER_MALLOCDATA (buf) = data; gst_memory_new_wrapped (0, data, g_free, 1000, 0, 1000));
gst_segment_init (&s, GST_FORMAT_TIME); gst_segment_init (&s, GST_FORMAT_TIME);
gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_TIME, 0 * GST_SECOND, gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_TIME, 0 * GST_SECOND,
@ -289,8 +295,8 @@ GST_START_TEST (test_buffer_clipping_time)
*/ */
buf = gst_buffer_new (); buf = gst_buffer_new ();
data = (guint8 *) g_malloc (1000); data = (guint8 *) g_malloc (1000);
GST_BUFFER_SIZE (buf) = 1000; gst_buffer_take_memory (buf,
GST_BUFFER_DATA (buf) = GST_BUFFER_MALLOCDATA (buf) = data; gst_memory_new_wrapped (0, data, g_free, 1000, 0, 1000));
gst_segment_init (&s, GST_FORMAT_PERCENT); gst_segment_init (&s, GST_FORMAT_PERCENT);
gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_PERCENT, 0, 10, 0); gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_PERCENT, 0, 10, 0);
@ -311,18 +317,16 @@ GST_END_TEST;
GST_START_TEST (test_buffer_clipping_samples) GST_START_TEST (test_buffer_clipping_samples)
{ {
GstSegment s; GstSegment s;
GstBuffer *buf; GstBuffer *buf;
GstBuffer *ret; GstBuffer *ret;
guint8 *data, *sdata;
guint8 *data; gsize ssize;
/* Clip start and end */ /* Clip start and end */
buf = gst_buffer_new (); buf = gst_buffer_new ();
data = (guint8 *) g_malloc (1000); data = (guint8 *) g_malloc (1000);
GST_BUFFER_SIZE (buf) = 1000; gst_buffer_take_memory (buf,
GST_BUFFER_DATA (buf) = GST_BUFFER_MALLOCDATA (buf) = data; gst_memory_new_wrapped (0, data, g_free, 1000, 0, 1000));
gst_segment_init (&s, GST_FORMAT_DEFAULT); gst_segment_init (&s, GST_FORMAT_DEFAULT);
gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_DEFAULT, 400, gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_DEFAULT, 400,
@ -340,16 +344,18 @@ GST_START_TEST (test_buffer_clipping_samples)
fail_unless (GST_BUFFER_DURATION (ret) == 4 * GST_SECOND); fail_unless (GST_BUFFER_DURATION (ret) == 4 * GST_SECOND);
fail_unless (GST_BUFFER_OFFSET (ret) == 400); fail_unless (GST_BUFFER_OFFSET (ret) == 400);
fail_unless (GST_BUFFER_OFFSET_END (ret) == 800); fail_unless (GST_BUFFER_OFFSET_END (ret) == 800);
fail_unless (GST_BUFFER_DATA (ret) == data + 200); sdata = gst_buffer_map (ret, &ssize, NULL, GST_MAP_READ);
fail_unless (GST_BUFFER_SIZE (ret) == 400); fail_unless (sdata == data + 200);
fail_unless (ssize == 400);
gst_buffer_unmap (ret, sdata, ssize);
gst_buffer_unref (ret); gst_buffer_unref (ret);
/* Clip only start */ /* Clip only start */
buf = gst_buffer_new (); buf = gst_buffer_new ();
data = (guint8 *) g_malloc (1000); data = (guint8 *) g_malloc (1000);
GST_BUFFER_SIZE (buf) = 1000; gst_buffer_take_memory (buf,
GST_BUFFER_DATA (buf) = GST_BUFFER_MALLOCDATA (buf) = data; gst_memory_new_wrapped (0, data, g_free, 1000, 0, 1000));
gst_segment_init (&s, GST_FORMAT_DEFAULT); gst_segment_init (&s, GST_FORMAT_DEFAULT);
gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_DEFAULT, 400, gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_DEFAULT, 400,
@ -367,16 +373,18 @@ GST_START_TEST (test_buffer_clipping_samples)
fail_unless (GST_BUFFER_DURATION (ret) == 8 * GST_SECOND); fail_unless (GST_BUFFER_DURATION (ret) == 8 * GST_SECOND);
fail_unless (GST_BUFFER_OFFSET (ret) == 400); fail_unless (GST_BUFFER_OFFSET (ret) == 400);
fail_unless (GST_BUFFER_OFFSET_END (ret) == 1200); fail_unless (GST_BUFFER_OFFSET_END (ret) == 1200);
fail_unless (GST_BUFFER_DATA (ret) == data + 200); sdata = gst_buffer_map (ret, &ssize, NULL, GST_MAP_READ);
fail_unless (GST_BUFFER_SIZE (ret) == 800); fail_unless (sdata == data + 200);
fail_unless (ssize == 800);
gst_buffer_unmap (ret, sdata, ssize);
gst_buffer_unref (ret); gst_buffer_unref (ret);
/* Clip only stop */ /* Clip only stop */
buf = gst_buffer_new (); buf = gst_buffer_new ();
data = (guint8 *) g_malloc (1000); data = (guint8 *) g_malloc (1000);
GST_BUFFER_SIZE (buf) = 1000; gst_buffer_take_memory (buf,
GST_BUFFER_DATA (buf) = GST_BUFFER_MALLOCDATA (buf) = data; gst_memory_new_wrapped (0, data, g_free, 1000, 0, 1000));
gst_segment_init (&s, GST_FORMAT_DEFAULT); gst_segment_init (&s, GST_FORMAT_DEFAULT);
gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_DEFAULT, 200, gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_DEFAULT, 200,
@ -394,16 +402,18 @@ GST_START_TEST (test_buffer_clipping_samples)
fail_unless (GST_BUFFER_DURATION (ret) == 8 * GST_SECOND); fail_unless (GST_BUFFER_DURATION (ret) == 8 * GST_SECOND);
fail_unless (GST_BUFFER_OFFSET (ret) == 200); fail_unless (GST_BUFFER_OFFSET (ret) == 200);
fail_unless (GST_BUFFER_OFFSET_END (ret) == 1000); fail_unless (GST_BUFFER_OFFSET_END (ret) == 1000);
fail_unless (GST_BUFFER_DATA (ret) == data); sdata = gst_buffer_map (ret, &ssize, NULL, GST_MAP_READ);
fail_unless (GST_BUFFER_SIZE (ret) == 800); fail_unless (sdata == data);
fail_unless (ssize == 800);
gst_buffer_unmap (ret, sdata, ssize);
gst_buffer_unref (ret); gst_buffer_unref (ret);
/* Buffer outside segment */ /* Buffer outside segment */
buf = gst_buffer_new (); buf = gst_buffer_new ();
data = (guint8 *) g_malloc (1000); data = (guint8 *) g_malloc (1000);
GST_BUFFER_SIZE (buf) = 1000; gst_buffer_take_memory (buf,
GST_BUFFER_DATA (buf) = GST_BUFFER_MALLOCDATA (buf) = data; gst_memory_new_wrapped (0, data, g_free, 1000, 0, 1000));
gst_segment_init (&s, GST_FORMAT_DEFAULT); gst_segment_init (&s, GST_FORMAT_DEFAULT);
gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_DEFAULT, 1200, gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_DEFAULT, 1200,
@ -420,8 +430,8 @@ GST_START_TEST (test_buffer_clipping_samples)
/* Clip start and end but don't touch duration and offset_end */ /* Clip start and end but don't touch duration and offset_end */
buf = gst_buffer_new (); buf = gst_buffer_new ();
data = (guint8 *) g_malloc (1000); data = (guint8 *) g_malloc (1000);
GST_BUFFER_SIZE (buf) = 1000; gst_buffer_take_memory (buf,
GST_BUFFER_DATA (buf) = GST_BUFFER_MALLOCDATA (buf) = data; gst_memory_new_wrapped (0, data, g_free, 1000, 0, 1000));
gst_segment_init (&s, GST_FORMAT_DEFAULT); gst_segment_init (&s, GST_FORMAT_DEFAULT);
gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_DEFAULT, 400, gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_DEFAULT, 400,
@ -439,8 +449,10 @@ GST_START_TEST (test_buffer_clipping_samples)
fail_unless (GST_BUFFER_DURATION (ret) == GST_CLOCK_TIME_NONE); fail_unless (GST_BUFFER_DURATION (ret) == GST_CLOCK_TIME_NONE);
fail_unless (GST_BUFFER_OFFSET (ret) == 400); fail_unless (GST_BUFFER_OFFSET (ret) == 400);
fail_unless (GST_BUFFER_OFFSET_END (ret) == GST_BUFFER_OFFSET_NONE); fail_unless (GST_BUFFER_OFFSET_END (ret) == GST_BUFFER_OFFSET_NONE);
fail_unless (GST_BUFFER_DATA (ret) == data + 200); sdata = gst_buffer_map (ret, &ssize, NULL, GST_MAP_READ);
fail_unless (GST_BUFFER_SIZE (ret) == 400); fail_unless (sdata == data + 200);
fail_unless (ssize == 400);
gst_buffer_unmap (ret, sdata, ssize);
gst_buffer_unref (ret); gst_buffer_unref (ret);
@ -450,8 +462,8 @@ GST_START_TEST (test_buffer_clipping_samples)
*/ */
buf = gst_buffer_new (); buf = gst_buffer_new ();
data = (guint8 *) g_malloc (1000); data = (guint8 *) g_malloc (1000);
GST_BUFFER_SIZE (buf) = 1000; gst_buffer_take_memory (buf,
GST_BUFFER_DATA (buf) = GST_BUFFER_MALLOCDATA (buf) = data; gst_memory_new_wrapped (0, data, g_free, 1000, 0, 1000));
gst_segment_init (&s, GST_FORMAT_DEFAULT); gst_segment_init (&s, GST_FORMAT_DEFAULT);
gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_DEFAULT, 0, 10, 0); gst_segment_set_newsegment (&s, FALSE, 1.0, GST_FORMAT_DEFAULT, 0, 10, 0);

View file

@ -260,9 +260,12 @@ static GstBuffer *
gst_cd_foo_src_read_sector (GstCddaBaseSrc * cddabasesrc, gint sector) gst_cd_foo_src_read_sector (GstCddaBaseSrc * cddabasesrc, gint sector)
{ {
GstBuffer *buf; GstBuffer *buf;
guint8 *data;
buf = gst_buffer_new_and_alloc (CD_FRAMESIZE_RAW); buf = gst_buffer_new_and_alloc (CD_FRAMESIZE_RAW);
memset (GST_BUFFER_DATA (buf), 0, CD_FRAMESIZE_RAW); data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
memset (data, 0, CD_FRAMESIZE_RAW);
gst_buffer_unmap (buf, data, CD_FRAMESIZE_RAW);
return buf; return buf;
} }

View file

@ -23,7 +23,6 @@
#include <config.h> #include <config.h>
#include <gst/check/gstcheck.h> #include <gst/check/gstcheck.h>
#include <gst/app/gstappbuffer.h>
#include <gst/app/gstappsrc.h> #include <gst/app/gstappsrc.h>
#include <gst/app/gstappsink.h> #include <gst/app/gstappsink.h>
#include <gst/audio/audio.h> #include <gst/audio/audio.h>

View file

@ -29,7 +29,7 @@
GST_START_TEST (test_netbuffer_copy) GST_START_TEST (test_netbuffer_copy)
{ {
GstNetBuffer *netbuf, *copy; GstBuffer *netbuf, *copy;
guint8 ipv6_addr[16] = { 0xff, 0x11, 0xee, 0x22, 0xdd, 0x33, 0xcc, guint8 ipv6_addr[16] = { 0xff, 0x11, 0xee, 0x22, 0xdd, 0x33, 0xcc,
0x44, 0xbb, 0x55, 0xaa, 0x66, 0x00, 0x77, 0x99, 0x88 0x44, 0xbb, 0x55, 0xaa, 0x66, 0x00, 0x77, 0x99, 0x88
}; };
@ -38,44 +38,88 @@ GST_START_TEST (test_netbuffer_copy)
guint16 ipv6_port = 3490; guint16 ipv6_port = 3490;
guint16 ipv4_port = 5678; guint16 ipv4_port = 5678;
guint16 port; guint16 port;
GstMetaNetAddress *meta, *cmeta;
gsize len;
guint8 *data1, *data2;
gsize size1, size2;
netbuf = gst_netbuffer_new (); netbuf = gst_buffer_new ();
fail_unless (netbuf != NULL, "failed to create net buffer"); fail_unless (netbuf != NULL, "failed to create net buffer");
meta = gst_buffer_add_meta_net_address (netbuf);
gst_netaddress_set_ip4_address (&netbuf->from, ipv4_addr, ipv4_port); gst_netaddress_set_ip4_address (&meta->naddr, ipv4_addr, ipv4_port);
gst_netaddress_set_ip6_address (&netbuf->to, ipv6_addr, ipv6_port);
len = strlen (DATA_STRING);
gst_buffer_take_memory (netbuf,
gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY,
(gpointer) DATA_STRING, NULL, len, 0, len));
GST_BUFFER_DATA (netbuf) = (guint8 *) DATA_STRING;
GST_BUFFER_SIZE (netbuf) = strlen (DATA_STRING);
GST_BUFFER_FLAG_SET (netbuf, GST_BUFFER_FLAG_DISCONT); GST_BUFFER_FLAG_SET (netbuf, GST_BUFFER_FLAG_DISCONT);
GST_BUFFER_FLAG_SET (netbuf, GST_BUFFER_FLAG_READONLY);
copy = (GstNetBuffer *) gst_buffer_copy (GST_BUFFER_CAST (netbuf)); copy = gst_buffer_copy (netbuf);
fail_unless (copy != NULL, "failed to copy net buffer"); fail_unless (copy != NULL, "failed to copy net buffer");
fail_unless (GST_IS_NETBUFFER (copy), "copied buffer is not a GstNetBuffer!");
cmeta = gst_buffer_get_meta_net_address (copy);
fail_unless (cmeta != NULL, "copied buffer is not a GstNetBuffer!");
fail_unless_equals_int (GST_MINI_OBJECT_REFCOUNT_VALUE (copy), 1); fail_unless_equals_int (GST_MINI_OBJECT_REFCOUNT_VALUE (copy), 1);
fail_unless_equals_int (GST_BUFFER_SIZE (copy), GST_BUFFER_SIZE (netbuf)); data1 = gst_buffer_map (netbuf, &size1, NULL, GST_MAP_READ);
fail_unless (memcmp (GST_BUFFER_DATA (copy), GST_BUFFER_DATA (netbuf), data2 = gst_buffer_map (copy, &size2, NULL, GST_MAP_READ);
GST_BUFFER_SIZE (copy)) == 0); fail_unless_equals_int (size1, size2);
fail_unless (memcmp (data1, data2, size1) == 0);
gst_buffer_unmap (copy, data2, size2);
gst_buffer_unmap (netbuf, data1, size1);
fail_if (GST_BUFFER_FLAG_IS_SET (copy, GST_BUFFER_FLAG_READONLY));
fail_unless (GST_BUFFER_FLAG_IS_SET (copy, GST_BUFFER_FLAG_DISCONT)); fail_unless (GST_BUFFER_FLAG_IS_SET (copy, GST_BUFFER_FLAG_DISCONT));
fail_unless (gst_netaddress_get_ip4_address (&copy->from, &ipv4_copy, &port)); fail_unless (gst_netaddress_get_ip4_address (&cmeta->naddr, &ipv4_copy,
&port));
fail_unless (ipv4_copy == ipv4_addr, fail_unless (ipv4_copy == ipv4_addr,
"Copied buffer has wrong IPV4 from address"); "Copied buffer has wrong IPV4 from address");
fail_unless (port == ipv4_port, "Copied buffer has wrong IPV4 from port"); fail_unless (port == ipv4_port, "Copied buffer has wrong IPV4 from port");
gst_buffer_unref (netbuf);
gst_buffer_unref (copy);
fail_unless (gst_netaddress_get_ip6_address (&copy->to, ipv6_copy, &port)); netbuf = gst_buffer_new ();
fail_unless (netbuf != NULL, "failed to create net buffer");
meta = gst_buffer_add_meta_net_address (netbuf);
gst_netaddress_set_ip6_address (&meta->naddr, ipv6_addr, ipv6_port);
len = strlen (DATA_STRING);
gst_buffer_take_memory (netbuf,
gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY,
(gpointer) DATA_STRING, NULL, len, 0, len));
GST_BUFFER_FLAG_SET (netbuf, GST_BUFFER_FLAG_DISCONT);
copy = gst_buffer_copy (netbuf);
fail_unless (copy != NULL, "failed to copy net buffer");
cmeta = gst_buffer_get_meta_net_address (copy);
fail_unless (cmeta != NULL, "copied buffer is not a GstNetBuffer!");
fail_unless_equals_int (GST_MINI_OBJECT_REFCOUNT_VALUE (copy), 1);
data1 = gst_buffer_map (netbuf, &size1, NULL, GST_MAP_READ);
data2 = gst_buffer_map (copy, &size2, NULL, GST_MAP_READ);
fail_unless_equals_int (size1, size2);
fail_unless (memcmp (data1, data2, size1) == 0);
gst_buffer_unmap (copy, data2, size2);
gst_buffer_unmap (netbuf, data1, size1);
fail_unless (GST_BUFFER_FLAG_IS_SET (copy, GST_BUFFER_FLAG_DISCONT));
fail_unless (gst_netaddress_get_ip6_address (&cmeta->naddr, ipv6_copy,
&port));
fail_unless (memcmp (ipv6_copy, ipv6_addr, 16) == 0, fail_unless (memcmp (ipv6_copy, ipv6_addr, 16) == 0,
"Copied buffer has wrong IPv6 destination address"); "Copied buffer has wrong IPv6 destination address");
fail_unless (port == ipv6_port, fail_unless (port == ipv6_port,
"Copied buffer has wrong IPv6 destination port"); "Copied buffer has wrong IPv6 destination port");
gst_buffer_unref (netbuf);
gst_buffer_unref (copy);
gst_buffer_unref (GST_BUFFER_CAST (netbuf));
gst_buffer_unref (GST_BUFFER_CAST (copy));
} }
GST_END_TEST; GST_END_TEST;

View file

@ -396,7 +396,7 @@ GST_START_TEST (test_loading_profile)
GstEncodingProfile *profile; GstEncodingProfile *profile;
GstCaps *tmpcaps; GstCaps *tmpcaps;
GValue strvalue = { 0, }; GValue strvalue = { 0, };
GValue miniobjectvalue = { 0, }; GValue objectvalue = { 0, };
/* Test loading using short method and all arguments */ /* Test loading using short method and all arguments */
target = gst_encoding_target_load ("myponytarget", "herding", NULL); target = gst_encoding_target_load ("myponytarget", "herding", NULL);
@ -442,13 +442,13 @@ GST_START_TEST (test_loading_profile)
/* For my next trick, I will need the assistance of a GValue */ /* For my next trick, I will need the assistance of a GValue */
g_value_init (&strvalue, G_TYPE_STRING); g_value_init (&strvalue, G_TYPE_STRING);
g_value_init (&miniobjectvalue, GST_TYPE_ENCODING_PROFILE); g_value_init (&objectvalue, GST_TYPE_ENCODING_PROFILE);
g_value_set_static_string (&strvalue, "myponytarget/pony"); g_value_set_static_string (&strvalue, "myponytarget/pony");
fail_unless (g_value_transform (&strvalue, &miniobjectvalue)); fail_unless (g_value_transform (&strvalue, &objectvalue));
profile = (GstEncodingProfile *) gst_value_dup_mini_object (&miniobjectvalue); profile = (GstEncodingProfile *) g_value_dup_object (&objectvalue);
fail_if (profile == NULL); fail_if (profile == NULL);
g_value_unset (&strvalue); g_value_unset (&strvalue);
g_value_unset (&miniobjectvalue); g_value_unset (&objectvalue);
tmpcaps = gst_caps_from_string ("animal/x-pony"); tmpcaps = gst_caps_from_string ("animal/x-pony");
CHECK_PROFILE (profile, "pony", "I don't want a description !", tmpcaps, NULL, CHECK_PROFILE (profile, "pony", "I don't want a description !", tmpcaps, NULL,
0, 0); 0, 0);

View file

@ -34,99 +34,109 @@ GST_START_TEST (test_rtp_buffer)
{ {
GstBuffer *buf; GstBuffer *buf;
guint8 *data; guint8 *data;
gsize size;
GstRTPBuffer rtp;
/* check GstRTPHeader structure alignment and packing */ /* check GstRTPHeader structure alignment and packing */
buf = gst_rtp_buffer_new_allocate (16, 4, 0); buf = gst_rtp_buffer_new_allocate (16, 4, 0);
fail_unless (buf != NULL); fail_unless (buf != NULL);
fail_unless_equals_int (GST_BUFFER_SIZE (buf), RTP_HEADER_LEN + 16 + 4); data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
data = GST_BUFFER_DATA (buf); fail_unless_equals_int (size, RTP_HEADER_LEN + 16 + 4);
gst_rtp_buffer_map (buf, GST_MAP_READWRITE, &rtp);
/* check defaults */ /* check defaults */
fail_unless_equals_int (gst_rtp_buffer_get_version (buf), 2); fail_unless_equals_int (gst_rtp_buffer_get_version (&rtp), 2);
fail_unless (gst_rtp_buffer_get_padding (buf) == FALSE); fail_unless (gst_rtp_buffer_get_padding (&rtp) == FALSE);
fail_unless (gst_rtp_buffer_get_extension (buf) == FALSE); fail_unless (gst_rtp_buffer_get_extension (&rtp) == FALSE);
fail_unless_equals_int (gst_rtp_buffer_get_csrc_count (buf), 0); fail_unless_equals_int (gst_rtp_buffer_get_csrc_count (&rtp), 0);
fail_unless (gst_rtp_buffer_get_marker (buf) == FALSE); fail_unless (gst_rtp_buffer_get_marker (&rtp) == FALSE);
fail_unless (gst_rtp_buffer_get_payload_type (buf) == 0); fail_unless (gst_rtp_buffer_get_payload_type (&rtp) == 0);
fail_unless_equals_int (GST_READ_UINT16_BE (data), 0x8000); fail_unless_equals_int (GST_READ_UINT16_BE (data), 0x8000);
/* check version in bitfield */ /* check version in bitfield */
gst_rtp_buffer_set_version (buf, 3); gst_rtp_buffer_set_version (&rtp, 3);
fail_unless_equals_int (gst_rtp_buffer_get_version (buf), 3); fail_unless_equals_int (gst_rtp_buffer_get_version (&rtp), 3);
fail_unless_equals_int ((data[0] & 0xC0) >> 6, 3); fail_unless_equals_int ((data[0] & 0xC0) >> 6, 3);
gst_rtp_buffer_set_version (buf, 2); gst_rtp_buffer_set_version (&rtp, 2);
fail_unless_equals_int (gst_rtp_buffer_get_version (buf), 2); fail_unless_equals_int (gst_rtp_buffer_get_version (&rtp), 2);
fail_unless_equals_int ((data[0] & 0xC0) >> 6, 2); fail_unless_equals_int ((data[0] & 0xC0) >> 6, 2);
/* check padding bit */ /* check padding bit */
gst_rtp_buffer_set_padding (buf, TRUE); gst_rtp_buffer_set_padding (&rtp, TRUE);
fail_unless (gst_rtp_buffer_get_padding (buf) == TRUE); fail_unless (gst_rtp_buffer_get_padding (&rtp) == TRUE);
fail_unless_equals_int ((data[0] & 0x20) >> 5, 1); fail_unless_equals_int ((data[0] & 0x20) >> 5, 1);
gst_rtp_buffer_set_padding (buf, FALSE); gst_rtp_buffer_set_padding (&rtp, FALSE);
fail_unless (gst_rtp_buffer_get_padding (buf) == FALSE); fail_unless (gst_rtp_buffer_get_padding (&rtp) == FALSE);
fail_unless_equals_int ((data[0] & 0x20) >> 5, 0); fail_unless_equals_int ((data[0] & 0x20) >> 5, 0);
/* check marker bit */ /* check marker bit */
gst_rtp_buffer_set_marker (buf, TRUE); gst_rtp_buffer_set_marker (&rtp, TRUE);
fail_unless (gst_rtp_buffer_get_marker (buf) == TRUE); fail_unless (gst_rtp_buffer_get_marker (&rtp) == TRUE);
fail_unless_equals_int ((data[1] & 0x80) >> 7, 1); fail_unless_equals_int ((data[1] & 0x80) >> 7, 1);
gst_rtp_buffer_set_marker (buf, FALSE); gst_rtp_buffer_set_marker (&rtp, FALSE);
fail_unless (gst_rtp_buffer_get_marker (buf) == FALSE); fail_unless (gst_rtp_buffer_get_marker (&rtp) == FALSE);
fail_unless_equals_int ((data[1] & 0x80) >> 7, 0); fail_unless_equals_int ((data[1] & 0x80) >> 7, 0);
/* check sequence offset */ /* check sequence offset */
gst_rtp_buffer_set_seq (buf, 0xF2C9); gst_rtp_buffer_set_seq (&rtp, 0xF2C9);
fail_unless_equals_int (gst_rtp_buffer_get_seq (buf), 0xF2C9); fail_unless_equals_int (gst_rtp_buffer_get_seq (&rtp), 0xF2C9);
fail_unless_equals_int (GST_READ_UINT16_BE (data + 2), 0xF2C9); fail_unless_equals_int (GST_READ_UINT16_BE (data + 2), 0xF2C9);
gst_rtp_buffer_set_seq (buf, 0); gst_rtp_buffer_set_seq (&rtp, 0);
fail_unless_equals_int (gst_rtp_buffer_get_seq (buf), 0); fail_unless_equals_int (gst_rtp_buffer_get_seq (&rtp), 0);
fail_unless_equals_int (GST_READ_UINT16_BE (data + 2), 0); fail_unless_equals_int (GST_READ_UINT16_BE (data + 2), 0);
/* check timestamp offset */ /* check timestamp offset */
gst_rtp_buffer_set_timestamp (buf, 432191); gst_rtp_buffer_set_timestamp (&rtp, 432191);
fail_unless_equals_int (GST_READ_UINT32_BE (data + 4), 432191); fail_unless_equals_int (GST_READ_UINT32_BE (data + 4), 432191);
fail_unless_equals_int (gst_rtp_buffer_get_timestamp (buf), 432191); fail_unless_equals_int (gst_rtp_buffer_get_timestamp (&rtp), 432191);
gst_rtp_buffer_set_timestamp (buf, 0); gst_rtp_buffer_set_timestamp (&rtp, 0);
fail_unless_equals_int (gst_rtp_buffer_get_timestamp (buf), 0); fail_unless_equals_int (gst_rtp_buffer_get_timestamp (&rtp), 0);
fail_unless_equals_int (GST_READ_UINT32_BE (data + 4), 0); fail_unless_equals_int (GST_READ_UINT32_BE (data + 4), 0);
/* check ssrc offset */ /* check ssrc offset */
gst_rtp_buffer_set_ssrc (buf, 0xf04043C2); gst_rtp_buffer_set_ssrc (&rtp, 0xf04043C2);
fail_unless_equals_int (gst_rtp_buffer_get_ssrc (buf), (gint) 0xf04043c2); fail_unless_equals_int (gst_rtp_buffer_get_ssrc (&rtp), (gint) 0xf04043c2);
fail_unless_equals_int (GST_READ_UINT32_BE (data + 4 + 4), (gint) 0xf04043c2); fail_unless_equals_int (GST_READ_UINT32_BE (data + 4 + 4), (gint) 0xf04043c2);
gst_rtp_buffer_set_ssrc (buf, 0); gst_rtp_buffer_set_ssrc (&rtp, 0);
fail_unless_equals_int (gst_rtp_buffer_get_ssrc (buf), 0); fail_unless_equals_int (gst_rtp_buffer_get_ssrc (&rtp), 0);
fail_unless_equals_int (GST_READ_UINT32_BE (data + 4 + 4), 0); fail_unless_equals_int (GST_READ_UINT32_BE (data + 4 + 4), 0);
/* check csrc bits */ /* check csrc bits */
fail_unless_equals_int (gst_rtp_buffer_get_csrc_count (buf), 0); fail_unless_equals_int (gst_rtp_buffer_get_csrc_count (&rtp), 0);
ASSERT_CRITICAL (gst_rtp_buffer_get_csrc (buf, 0)); ASSERT_CRITICAL (gst_rtp_buffer_get_csrc (&rtp, 0));
fail_unless_equals_int (data[0] & 0xf, 0); fail_unless_equals_int (data[0] & 0xf, 0);
gst_rtp_buffer_unmap (&rtp);
gst_buffer_unmap (buf, data, size);
gst_buffer_unref (buf); gst_buffer_unref (buf);
/* and again, this time with CSRCs */ /* and again, this time with CSRCs */
buf = gst_rtp_buffer_new_allocate (16, 4, 3); buf = gst_rtp_buffer_new_allocate (16, 4, 3);
fail_unless (buf != NULL); fail_unless (buf != NULL);
fail_unless_equals_int (GST_BUFFER_SIZE (buf), data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
RTP_HEADER_LEN + 16 + 4 + 4 * 3); fail_unless_equals_int (size, RTP_HEADER_LEN + 16 + 4 + 4 * 3);
data = GST_BUFFER_DATA (buf); gst_rtp_buffer_map (buf, GST_MAP_READWRITE, &rtp);
fail_unless_equals_int (gst_rtp_buffer_get_csrc_count (buf), 3); fail_unless_equals_int (gst_rtp_buffer_get_csrc_count (&rtp), 3);
ASSERT_CRITICAL (gst_rtp_buffer_get_csrc (buf, 3)); ASSERT_CRITICAL (gst_rtp_buffer_get_csrc (&rtp, 3));
fail_unless_equals_int (data[0] & 0xf, 3); fail_unless_equals_int (data[0] & 0xf, 3);
fail_unless_equals_int (gst_rtp_buffer_get_csrc (buf, 0), 0); fail_unless_equals_int (gst_rtp_buffer_get_csrc (&rtp, 0), 0);
fail_unless_equals_int (gst_rtp_buffer_get_csrc (buf, 1), 0); fail_unless_equals_int (gst_rtp_buffer_get_csrc (&rtp, 1), 0);
fail_unless_equals_int (gst_rtp_buffer_get_csrc (buf, 2), 0); fail_unless_equals_int (gst_rtp_buffer_get_csrc (&rtp, 2), 0);
data += RTP_HEADER_LEN; /* skip the other header stuff */ data += RTP_HEADER_LEN; /* skip the other header stuff */
gst_rtp_buffer_set_csrc (buf, 0, 0xf7c0); gst_rtp_buffer_set_csrc (&rtp, 0, 0xf7c0);
fail_unless_equals_int (GST_READ_UINT32_BE (data + 0 * 4), 0xf7c0); fail_unless_equals_int (GST_READ_UINT32_BE (data + 0 * 4), 0xf7c0);
gst_rtp_buffer_set_csrc (buf, 1, 0xf7c1); gst_rtp_buffer_set_csrc (&rtp, 1, 0xf7c1);
fail_unless_equals_int (GST_READ_UINT32_BE (data + 1 * 4), 0xf7c1); fail_unless_equals_int (GST_READ_UINT32_BE (data + 1 * 4), 0xf7c1);
gst_rtp_buffer_set_csrc (buf, 2, 0xf7c2); gst_rtp_buffer_set_csrc (&rtp, 2, 0xf7c2);
fail_unless_equals_int (GST_READ_UINT32_BE (data + 2 * 4), 0xf7c2); fail_unless_equals_int (GST_READ_UINT32_BE (data + 2 * 4), 0xf7c2);
ASSERT_CRITICAL (gst_rtp_buffer_set_csrc (buf, 3, 0xf123)); ASSERT_CRITICAL (gst_rtp_buffer_set_csrc (&rtp, 3, 0xf123));
gst_rtp_buffer_unmap (&rtp);
gst_buffer_unmap (buf, data, size);
gst_buffer_unref (buf); gst_buffer_unref (buf);
} }
@ -143,15 +153,15 @@ GST_START_TEST (test_rtp_buffer_validate_corrupt)
0xb0, 0x97, 0x63, 0x08, 0x10, 0x4b, 0x43, 0x85, 0x37, 0x2c 0xb0, 0x97, 0x63, 0x08, 0x10, 0x4b, 0x43, 0x85, 0x37, 0x2c
}; };
buf = gst_buffer_new (); buf = gst_buffer_new_and_alloc (sizeof (corrupt_rtp_packet));
GST_BUFFER_DATA (buf) = corrupt_rtp_packet; gst_buffer_fill (buf, 0, corrupt_rtp_packet, sizeof (corrupt_rtp_packet));
GST_BUFFER_SIZE (buf) = sizeof (corrupt_rtp_packet);
fail_if (gst_rtp_buffer_validate (buf)); fail_if (gst_rtp_buffer_validate (buf));
gst_buffer_unref (buf); gst_buffer_unref (buf);
} }
GST_END_TEST; GST_END_TEST;
#if 0
GST_START_TEST (test_rtp_buffer_list) GST_START_TEST (test_rtp_buffer_list)
{ {
GstBuffer *rtp_header; GstBuffer *rtp_header;
@ -203,6 +213,7 @@ GST_START_TEST (test_rtp_buffer_list)
} }
GST_END_TEST; GST_END_TEST;
#endif
GST_START_TEST (test_rtp_buffer_set_extension_data) GST_START_TEST (test_rtp_buffer_set_extension_data)
{ {
@ -213,158 +224,185 @@ GST_START_TEST (test_rtp_buffer_set_extension_data)
guint8 misc_data[4] = { 1, 2, 3, 4 }; guint8 misc_data[4] = { 1, 2, 3, 4 };
gpointer pointer; gpointer pointer;
guint8 appbits; guint8 appbits;
gsize bsize;
GstRTPBuffer rtp;
/* check GstRTPHeader structure alignment and packing */ /* check GstRTPHeader structure alignment and packing */
buf = gst_rtp_buffer_new_allocate (4, 0, 0); buf = gst_rtp_buffer_new_allocate (4, 0, 0);
data = GST_BUFFER_DATA (buf); data = gst_buffer_map (buf, &bsize, NULL, GST_MAP_READ);
gst_rtp_buffer_map (buf, GST_MAP_READWRITE, &rtp);
/* should be impossible to set the extension data */ /* should be impossible to set the extension data */
ASSERT_WARNING (fail_unless (gst_rtp_buffer_set_extension_data (buf, 0, ASSERT_WARNING (fail_unless (gst_rtp_buffer_set_extension_data (&rtp, 0,
4) == FALSE)); 4) == FALSE));
fail_unless (gst_rtp_buffer_get_extension (buf) == FALSE); fail_unless (gst_rtp_buffer_get_extension (&rtp) == FALSE);
/* should be possible to set the extension data */ /* should be possible to set the extension data */
fail_unless (gst_rtp_buffer_set_extension_data (buf, 270, 0) == TRUE); fail_unless (gst_rtp_buffer_set_extension_data (&rtp, 270, 0) == TRUE);
fail_unless (gst_rtp_buffer_get_extension (buf) == TRUE); fail_unless (gst_rtp_buffer_get_extension (&rtp) == TRUE);
gst_rtp_buffer_get_extension_data (buf, &bits, &pointer, &size); gst_rtp_buffer_get_extension_data (&rtp, &bits, &pointer, &size);
fail_unless (bits == 270); fail_unless (bits == 270);
fail_unless (size == 0); fail_unless (size == 0);
fail_unless (pointer == GST_BUFFER_DATA (buf) + 16); fail_unless (pointer == data + 16);
pointer = gst_rtp_buffer_get_payload (buf); pointer = gst_rtp_buffer_get_payload (&rtp);
fail_unless (pointer == GST_BUFFER_DATA (buf) + 16); fail_unless (pointer == data + 16);
gst_buffer_unmap (buf, data, bsize);
gst_rtp_buffer_unmap (&rtp);
gst_buffer_unref (buf); gst_buffer_unref (buf);
buf = gst_rtp_buffer_new_allocate (20, 0, 0); buf = gst_rtp_buffer_new_allocate (20, 0, 0);
data = GST_BUFFER_DATA (buf); data = gst_buffer_map (buf, &bsize, NULL, GST_MAP_READ);
fail_unless (gst_rtp_buffer_get_extension (buf) == FALSE); gst_rtp_buffer_map (buf, GST_MAP_READWRITE, &rtp);
fail_unless (gst_rtp_buffer_set_extension_data (buf, 333, 2) == TRUE);
fail_unless (gst_rtp_buffer_get_extension (buf) == TRUE); fail_unless (gst_rtp_buffer_get_extension (&rtp) == FALSE);
gst_rtp_buffer_get_extension_data (buf, &bits, &pointer, &size); fail_unless (gst_rtp_buffer_set_extension_data (&rtp, 333, 2) == TRUE);
fail_unless (gst_rtp_buffer_get_extension (&rtp) == TRUE);
gst_rtp_buffer_get_extension_data (&rtp, &bits, &pointer, &size);
fail_unless (bits == 333); fail_unless (bits == 333);
fail_unless (size == 2); fail_unless (size == 2);
fail_unless (pointer == GST_BUFFER_DATA (buf) + 16); fail_unless (pointer == data + 16);
pointer = gst_rtp_buffer_get_payload (buf); pointer = gst_rtp_buffer_get_payload (&rtp);
fail_unless (pointer == GST_BUFFER_DATA (buf) + 24); fail_unless (pointer == data + 24);
gst_buffer_unmap (buf, data, bsize);
gst_rtp_buffer_unmap (&rtp);
gst_buffer_unref (buf); gst_buffer_unref (buf);
/* Test header extensions with a one byte header */ /* Test header extensions with a one byte header */
buf = gst_rtp_buffer_new_allocate (20, 0, 0); buf = gst_rtp_buffer_new_allocate (20, 0, 0);
fail_unless (gst_rtp_buffer_get_extension (buf) == FALSE); data = gst_buffer_map (buf, &bsize, NULL, GST_MAP_READ);
gst_rtp_buffer_map (buf, GST_MAP_READWRITE, &rtp);
fail_unless (gst_rtp_buffer_add_extension_onebyte_header (buf, 5, fail_unless (gst_rtp_buffer_get_extension (&rtp) == FALSE);
fail_unless (gst_rtp_buffer_add_extension_onebyte_header (&rtp, 5,
misc_data, 2) == TRUE); misc_data, 2) == TRUE);
fail_unless (gst_rtp_buffer_get_extension_data (buf, &bits, &pointer, &size)); fail_unless (gst_rtp_buffer_get_extension_data (&rtp, &bits, &pointer,
&size));
fail_unless (bits == 0xBEDE); fail_unless (bits == 0xBEDE);
fail_unless (size == 1); fail_unless (size == 1);
data = (guint8 *) pointer; data = (guint8 *) pointer;
fail_unless (data[0] == ((5 << 4) | 1)); fail_unless (data[0] == ((5 << 4) | 1));
fail_unless (gst_rtp_buffer_get_extension_onebyte_header (buf, 2, fail_unless (gst_rtp_buffer_get_extension_onebyte_header (&rtp, 2,
1, &pointer, &size) == FALSE); 1, &pointer, &size) == FALSE);
fail_unless (gst_rtp_buffer_get_extension_onebyte_header (buf, 5, fail_unless (gst_rtp_buffer_get_extension_onebyte_header (&rtp, 5,
1, &pointer, &size) == FALSE); 1, &pointer, &size) == FALSE);
fail_unless (gst_rtp_buffer_get_extension_onebyte_header (buf, 5, fail_unless (gst_rtp_buffer_get_extension_onebyte_header (&rtp, 5,
0, &pointer, &size) == TRUE); 0, &pointer, &size) == TRUE);
fail_unless (size == 2); fail_unless (size == 2);
fail_unless (memcmp (pointer, misc_data, 2) == 0); fail_unless (memcmp (pointer, misc_data, 2) == 0);
fail_unless (gst_rtp_buffer_add_extension_onebyte_header (buf, 5, fail_unless (gst_rtp_buffer_add_extension_onebyte_header (&rtp, 5,
misc_data, 4) == TRUE); misc_data, 4) == TRUE);
fail_unless (gst_rtp_buffer_get_extension_onebyte_header (buf, 5, fail_unless (gst_rtp_buffer_get_extension_onebyte_header (&rtp, 5,
0, &pointer, &size) == TRUE); 0, &pointer, &size) == TRUE);
fail_unless (size == 2); fail_unless (size == 2);
fail_unless (memcmp (pointer, misc_data, 2) == 0); fail_unless (memcmp (pointer, misc_data, 2) == 0);
fail_unless (gst_rtp_buffer_get_extension_onebyte_header (buf, 5, fail_unless (gst_rtp_buffer_get_extension_onebyte_header (&rtp, 5,
1, &pointer, &size) == TRUE); 1, &pointer, &size) == TRUE);
fail_unless (size == 4); fail_unless (size == 4);
fail_unless (memcmp (pointer, misc_data, 4) == 0); fail_unless (memcmp (pointer, misc_data, 4) == 0);
fail_unless (gst_rtp_buffer_get_extension_onebyte_header (buf, 5, fail_unless (gst_rtp_buffer_get_extension_onebyte_header (&rtp, 5,
2, &pointer, &size) == FALSE); 2, &pointer, &size) == FALSE);
fail_unless (gst_rtp_buffer_get_extension_onebyte_header (buf, 2, fail_unless (gst_rtp_buffer_get_extension_onebyte_header (&rtp, 2,
1, &pointer, &size) == FALSE); 1, &pointer, &size) == FALSE);
fail_unless (gst_rtp_buffer_add_extension_onebyte_header (buf, 6, fail_unless (gst_rtp_buffer_add_extension_onebyte_header (&rtp, 6,
misc_data, 2) == TRUE); misc_data, 2) == TRUE);
fail_unless (gst_rtp_buffer_get_extension_onebyte_header (buf, 5, fail_unless (gst_rtp_buffer_get_extension_onebyte_header (&rtp, 5,
0, &pointer, &size) == TRUE); 0, &pointer, &size) == TRUE);
fail_unless (size == 2); fail_unless (size == 2);
fail_unless (memcmp (pointer, misc_data, 2) == 0); fail_unless (memcmp (pointer, misc_data, 2) == 0);
fail_unless (gst_rtp_buffer_get_extension_onebyte_header (buf, 5, fail_unless (gst_rtp_buffer_get_extension_onebyte_header (&rtp, 5,
1, &pointer, &size) == TRUE); 1, &pointer, &size) == TRUE);
fail_unless (size == 4); fail_unless (size == 4);
fail_unless (memcmp (pointer, misc_data, 4) == 0); fail_unless (memcmp (pointer, misc_data, 4) == 0);
fail_unless (gst_rtp_buffer_get_extension_onebyte_header (buf, 5, fail_unless (gst_rtp_buffer_get_extension_onebyte_header (&rtp, 5,
3, &pointer, &size) == FALSE); 3, &pointer, &size) == FALSE);
fail_unless (gst_rtp_buffer_get_extension_onebyte_header (buf, 2, fail_unless (gst_rtp_buffer_get_extension_onebyte_header (&rtp, 2,
1, &pointer, &size) == FALSE); 1, &pointer, &size) == FALSE);
fail_unless (gst_rtp_buffer_get_extension_onebyte_header (buf, 6, fail_unless (gst_rtp_buffer_get_extension_onebyte_header (&rtp, 6,
2, &pointer, &size) == FALSE); 2, &pointer, &size) == FALSE);
fail_unless (gst_rtp_buffer_get_extension_onebyte_header (buf, 5, fail_unless (gst_rtp_buffer_get_extension_onebyte_header (&rtp, 5,
0, &pointer, &size) == TRUE); 0, &pointer, &size) == TRUE);
fail_unless (size == 2); fail_unless (size == 2);
fail_unless (memcmp (pointer, misc_data, 2) == 0); fail_unless (memcmp (pointer, misc_data, 2) == 0);
gst_buffer_unmap (buf, data, bsize);
gst_rtp_buffer_unmap (&rtp);
gst_buffer_unref (buf); gst_buffer_unref (buf);
/* Test header extensions with a two bytes header */ /* Test header extensions with a two bytes header */
buf = gst_rtp_buffer_new_allocate (20, 0, 0); buf = gst_rtp_buffer_new_allocate (20, 0, 0);
fail_unless (gst_rtp_buffer_get_extension (buf) == FALSE); data = gst_buffer_map (buf, &bsize, NULL, GST_MAP_READ);
gst_rtp_buffer_map (buf, GST_MAP_READWRITE, &rtp);
fail_unless (gst_rtp_buffer_add_extension_twobytes_header (buf, 0, 5, fail_unless (gst_rtp_buffer_get_extension (&rtp) == FALSE);
fail_unless (gst_rtp_buffer_add_extension_twobytes_header (&rtp, 0, 5,
misc_data, 2) == TRUE); misc_data, 2) == TRUE);
fail_unless (gst_rtp_buffer_get_extension_data (buf, &bits, &pointer, &size)); fail_unless (gst_rtp_buffer_get_extension_data (&rtp, &bits, &pointer,
&size));
fail_unless (bits == 0x100 << 4); fail_unless (bits == 0x100 << 4);
fail_unless (size == 1); fail_unless (size == 1);
data = (guint8 *) pointer; data = (guint8 *) pointer;
fail_unless (data[0] == 5); fail_unless (data[0] == 5);
fail_unless (data[1] == 2); fail_unless (data[1] == 2);
fail_unless (gst_rtp_buffer_get_extension_twobytes_header (buf, &appbits, 2, fail_unless (gst_rtp_buffer_get_extension_twobytes_header (&rtp, &appbits, 2,
0, &pointer, &size) == FALSE); 0, &pointer, &size) == FALSE);
fail_unless (gst_rtp_buffer_get_extension_twobytes_header (buf, &appbits, 5, fail_unless (gst_rtp_buffer_get_extension_twobytes_header (&rtp, &appbits, 5,
1, &pointer, &size) == FALSE); 1, &pointer, &size) == FALSE);
fail_unless (gst_rtp_buffer_get_extension_twobytes_header (buf, &appbits, 5, fail_unless (gst_rtp_buffer_get_extension_twobytes_header (&rtp, &appbits, 5,
0, &pointer, &size) == TRUE); 0, &pointer, &size) == TRUE);
fail_unless (size == 2); fail_unless (size == 2);
fail_unless (memcmp (pointer, misc_data, 2) == 0); fail_unless (memcmp (pointer, misc_data, 2) == 0);
fail_unless (gst_rtp_buffer_add_extension_twobytes_header (buf, 0, 5, fail_unless (gst_rtp_buffer_add_extension_twobytes_header (&rtp, 0, 5,
misc_data, 4) == TRUE); misc_data, 4) == TRUE);
fail_unless (gst_rtp_buffer_get_extension_twobytes_header (buf, &appbits, 5, fail_unless (gst_rtp_buffer_get_extension_twobytes_header (&rtp, &appbits, 5,
0, &pointer, &size) == TRUE); 0, &pointer, &size) == TRUE);
fail_unless (size == 2); fail_unless (size == 2);
fail_unless (memcmp (pointer, misc_data, 2) == 0); fail_unless (memcmp (pointer, misc_data, 2) == 0);
fail_unless (gst_rtp_buffer_get_extension_twobytes_header (buf, &appbits, 5, fail_unless (gst_rtp_buffer_get_extension_twobytes_header (&rtp, &appbits, 5,
1, &pointer, &size) == TRUE); 1, &pointer, &size) == TRUE);
fail_unless (size == 4); fail_unless (size == 4);
fail_unless (memcmp (pointer, misc_data, 4) == 0); fail_unless (memcmp (pointer, misc_data, 4) == 0);
fail_unless (gst_rtp_buffer_get_extension_twobytes_header (buf, &appbits, 5, fail_unless (gst_rtp_buffer_get_extension_twobytes_header (&rtp, &appbits, 5,
2, &pointer, &size) == FALSE); 2, &pointer, &size) == FALSE);
fail_unless (gst_rtp_buffer_get_extension_twobytes_header (buf, &appbits, 2, fail_unless (gst_rtp_buffer_get_extension_twobytes_header (&rtp, &appbits, 2,
0, &pointer, &size) == FALSE); 0, &pointer, &size) == FALSE);
fail_unless (gst_rtp_buffer_add_extension_twobytes_header (buf, 0, 6, fail_unless (gst_rtp_buffer_add_extension_twobytes_header (&rtp, 0, 6,
misc_data, 2) == TRUE); misc_data, 2) == TRUE);
fail_unless (gst_rtp_buffer_get_extension_twobytes_header (buf, &appbits, 5, fail_unless (gst_rtp_buffer_get_extension_twobytes_header (&rtp, &appbits, 5,
0, &pointer, &size) == TRUE); 0, &pointer, &size) == TRUE);
fail_unless (size == 2); fail_unless (size == 2);
fail_unless (memcmp (pointer, misc_data, 2) == 0); fail_unless (memcmp (pointer, misc_data, 2) == 0);
fail_unless (gst_rtp_buffer_get_extension_twobytes_header (buf, &appbits, 5, fail_unless (gst_rtp_buffer_get_extension_twobytes_header (&rtp, &appbits, 5,
1, &pointer, &size) == TRUE); 1, &pointer, &size) == TRUE);
fail_unless (size == 4); fail_unless (size == 4);
fail_unless (memcmp (pointer, misc_data, 4) == 0); fail_unless (memcmp (pointer, misc_data, 4) == 0);
fail_unless (gst_rtp_buffer_get_extension_twobytes_header (buf, &appbits, 5, fail_unless (gst_rtp_buffer_get_extension_twobytes_header (&rtp, &appbits, 5,
2, &pointer, &size) == FALSE); 2, &pointer, &size) == FALSE);
fail_unless (gst_rtp_buffer_get_extension_twobytes_header (buf, &appbits, 2, fail_unless (gst_rtp_buffer_get_extension_twobytes_header (&rtp, &appbits, 2,
0, &pointer, &size) == FALSE); 0, &pointer, &size) == FALSE);
fail_unless (gst_rtp_buffer_get_extension_twobytes_header (buf, &appbits, 6, fail_unless (gst_rtp_buffer_get_extension_twobytes_header (&rtp, &appbits, 6,
1, &pointer, &size) == FALSE); 1, &pointer, &size) == FALSE);
fail_unless (gst_rtp_buffer_get_extension_twobytes_header (buf, &appbits, 5, fail_unless (gst_rtp_buffer_get_extension_twobytes_header (&rtp, &appbits, 5,
0, &pointer, &size) == TRUE); 0, &pointer, &size) == TRUE);
fail_unless (size == 2); fail_unless (size == 2);
fail_unless (memcmp (pointer, misc_data, 2) == 0); fail_unless (memcmp (pointer, misc_data, 2) == 0);
gst_buffer_unmap (buf, data, bsize);
gst_rtp_buffer_unmap (&rtp);
gst_buffer_unref (buf); gst_buffer_unref (buf);
} }
GST_END_TEST; GST_END_TEST;
#if 0
GST_START_TEST (test_rtp_buffer_list_set_extension) GST_START_TEST (test_rtp_buffer_list_set_extension)
{ {
GstBufferList *list; GstBufferList *list;
@ -544,6 +582,7 @@ GST_START_TEST (test_rtp_buffer_list_set_extension)
} }
GST_END_TEST; GST_END_TEST;
#endif
GST_START_TEST (test_rtp_seqnum_compare) GST_START_TEST (test_rtp_seqnum_compare)
{ {
@ -636,18 +675,22 @@ GST_START_TEST (test_rtcp_buffer)
GstBuffer *buf; GstBuffer *buf;
GstRTCPPacket packet; GstRTCPPacket packet;
guint8 *data; guint8 *data;
gsize size;
GstRTCPBuffer rtcp;
buf = gst_rtcp_buffer_new (1400); buf = gst_rtcp_buffer_new (1400);
fail_unless (buf != NULL); fail_unless (buf != NULL);
fail_unless_equals_int (GST_BUFFER_SIZE (buf), 1400); data = gst_buffer_map (buf, &size, NULL, GST_MAP_READ);
data = GST_BUFFER_DATA (buf); fail_unless_equals_int (size, 1400);
gst_rtcp_buffer_map (buf, GST_MAP_READWRITE, &rtcp);
fail_unless (gst_rtcp_buffer_get_first_packet (buf, &packet) == FALSE);
fail_unless (gst_rtcp_buffer_get_packet_count (buf) == 0);
fail_unless (gst_rtcp_buffer_validate (buf) == FALSE); fail_unless (gst_rtcp_buffer_validate (buf) == FALSE);
fail_unless (gst_rtcp_buffer_get_first_packet (&rtcp, &packet) == FALSE);
fail_unless (gst_rtcp_buffer_get_packet_count (&rtcp) == 0);
/* add an SR packet */ /* add an SR packet */
fail_unless (gst_rtcp_buffer_add_packet (buf, GST_RTCP_TYPE_SR, fail_unless (gst_rtcp_buffer_add_packet (&rtcp, GST_RTCP_TYPE_SR,
&packet) == TRUE); &packet) == TRUE);
fail_unless (gst_rtcp_packet_get_padding (&packet) == 0); fail_unless (gst_rtcp_packet_get_padding (&packet) == 0);
@ -675,7 +718,7 @@ GST_START_TEST (test_rtcp_buffer)
} }
/* go to first packet, this should be the packet we just added */ /* go to first packet, this should be the packet we just added */
fail_unless (gst_rtcp_buffer_get_first_packet (buf, &packet) == TRUE); fail_unless (gst_rtcp_buffer_get_first_packet (&rtcp, &packet) == TRUE);
fail_unless (gst_rtcp_packet_get_padding (&packet) == 0); fail_unless (gst_rtcp_packet_get_padding (&packet) == 0);
fail_unless (gst_rtcp_packet_get_count (&packet) == 0); fail_unless (gst_rtcp_packet_get_count (&packet) == 0);
@ -685,14 +728,14 @@ GST_START_TEST (test_rtcp_buffer)
fail_unless (gst_rtcp_packet_move_to_next (&packet) == FALSE); fail_unless (gst_rtcp_packet_move_to_next (&packet) == FALSE);
/* add some SDES */ /* add some SDES */
fail_unless (gst_rtcp_buffer_add_packet (buf, GST_RTCP_TYPE_SDES, fail_unless (gst_rtcp_buffer_add_packet (&rtcp, GST_RTCP_TYPE_SDES,
&packet) == TRUE); &packet) == TRUE);
fail_unless (gst_rtcp_packet_sdes_add_item (&packet, 0xff658743) == TRUE); fail_unless (gst_rtcp_packet_sdes_add_item (&packet, 0xff658743) == TRUE);
fail_unless (gst_rtcp_packet_sdes_add_entry (&packet, GST_RTCP_SDES_CNAME, fail_unless (gst_rtcp_packet_sdes_add_entry (&packet, GST_RTCP_SDES_CNAME,
sizeof ("test@foo.bar"), (guint8 *) "test@foo.bar") == TRUE); sizeof ("test@foo.bar"), (guint8 *) "test@foo.bar") == TRUE);
/* add some BYE */ /* add some BYE */
fail_unless (gst_rtcp_buffer_add_packet (buf, GST_RTCP_TYPE_BYE, fail_unless (gst_rtcp_buffer_add_packet (&rtcp, GST_RTCP_TYPE_BYE,
&packet) == TRUE); &packet) == TRUE);
fail_unless (gst_rtcp_packet_bye_add_ssrc (&packet, 0x5613212f) == TRUE); fail_unless (gst_rtcp_packet_bye_add_ssrc (&packet, 0x5613212f) == TRUE);
fail_unless (gst_rtcp_packet_bye_add_ssrc (&packet, 0x00112233) == TRUE); fail_unless (gst_rtcp_packet_bye_add_ssrc (&packet, 0x00112233) == TRUE);
@ -704,7 +747,7 @@ GST_START_TEST (test_rtcp_buffer)
fail_unless (gst_rtcp_packet_get_length (&packet) == 2); fail_unless (gst_rtcp_packet_get_length (&packet) == 2);
/* move to SDES */ /* move to SDES */
fail_unless (gst_rtcp_buffer_get_first_packet (buf, &packet) == TRUE); fail_unless (gst_rtcp_buffer_get_first_packet (&rtcp, &packet) == TRUE);
fail_unless (gst_rtcp_packet_move_to_next (&packet) == TRUE); fail_unless (gst_rtcp_packet_move_to_next (&packet) == TRUE);
fail_unless (gst_rtcp_packet_get_padding (&packet) == 0); fail_unless (gst_rtcp_packet_get_padding (&packet) == 0);
@ -722,7 +765,7 @@ GST_START_TEST (test_rtcp_buffer)
fail_unless (gst_rtcp_packet_get_length (&packet) == 2); fail_unless (gst_rtcp_packet_get_length (&packet) == 2);
/* close and validate */ /* close and validate */
gst_rtcp_buffer_end (buf); gst_rtcp_buffer_unmap (&rtcp);
fail_unless (gst_rtcp_buffer_validate (buf) == TRUE); fail_unless (gst_rtcp_buffer_validate (buf) == TRUE);
gst_buffer_unref (buf); gst_buffer_unref (buf);
} }
@ -739,12 +782,12 @@ rtp_suite (void)
tcase_add_test (tc_chain, test_rtp_buffer); tcase_add_test (tc_chain, test_rtp_buffer);
tcase_add_test (tc_chain, test_rtp_buffer_validate_corrupt); tcase_add_test (tc_chain, test_rtp_buffer_validate_corrupt);
tcase_add_test (tc_chain, test_rtp_buffer_set_extension_data); tcase_add_test (tc_chain, test_rtp_buffer_set_extension_data);
tcase_add_test (tc_chain, test_rtp_buffer_list_set_extension); //tcase_add_test (tc_chain, test_rtp_buffer_list_set_extension);
tcase_add_test (tc_chain, test_rtp_seqnum_compare); tcase_add_test (tc_chain, test_rtp_seqnum_compare);
tcase_add_test (tc_chain, test_rtcp_buffer); tcase_add_test (tc_chain, test_rtcp_buffer);
tcase_add_test (tc_chain, test_rtp_buffer_list); //tcase_add_test (tc_chain, test_rtp_buffer_list);
return s; return s;
} }

View file

@ -1,7 +1,5 @@
GstCheckABIStruct list[] = { GstCheckABIStruct list[] = {
{"GstAppBufferClass", sizeof (GstAppBufferClass), 16},
{"GstAppBuffer", sizeof (GstAppBuffer), 88},
{"GstAppSinkCallbacks", sizeof (GstAppSinkCallbacks), 28}, {"GstAppSinkCallbacks", sizeof (GstAppSinkCallbacks), 28},
{"GstAppSinkClass", sizeof (GstAppSinkClass), 404}, {"GstAppSinkClass", sizeof (GstAppSinkClass), 404},
{"GstAppSink", sizeof (GstAppSink), 404}, {"GstAppSink", sizeof (GstAppSink), 404},
@ -49,8 +47,6 @@ GstCheckABIStruct list[] = {
{"GstMixerTrack", sizeof (GstMixerTrack), 32}, {"GstMixerTrack", sizeof (GstMixerTrack), 32},
{"GstNavigationInterface", sizeof (GstNavigationInterface), 28}, {"GstNavigationInterface", sizeof (GstNavigationInterface), 28},
{"GstNetAddress", sizeof (GstNetAddress), 40}, {"GstNetAddress", sizeof (GstNetAddress), 40},
{"GstNetBufferClass", sizeof (GstNetBufferClass), 32},
{"GstNetBuffer", sizeof (GstNetBuffer), 176},
{"GstPropertyProbeInterface", sizeof (GstPropertyProbeInterface), 44}, {"GstPropertyProbeInterface", sizeof (GstPropertyProbeInterface), 44},
{"gst_riff_acid", sizeof (gst_riff_acid), 24}, {"gst_riff_acid", sizeof (gst_riff_acid), 24},
{"gst_riff_dmlh", sizeof (gst_riff_dmlh), 4}, {"gst_riff_dmlh", sizeof (gst_riff_dmlh), 4},

View file

@ -407,6 +407,8 @@ GST_START_TEST (test_vorbis_tags)
/* now, while we still have a taglist, test _to_vorbiscomment_buffer() */ /* now, while we still have a taglist, test _to_vorbiscomment_buffer() */
{ {
GstBuffer *buf1, *buf2; GstBuffer *buf1, *buf2;
guint8 *data1, *data2;
gsize size1, size2;
ASSERT_CRITICAL (gst_tag_list_to_vorbiscomment_buffer (NULL, ASSERT_CRITICAL (gst_tag_list_to_vorbiscomment_buffer (NULL,
(const guint8 *) "x", 1, "x")); (const guint8 *) "x", 1, "x"));
@ -418,8 +420,13 @@ GST_START_TEST (test_vorbis_tags)
(const guint8 *) "foo", 3, NULL); (const guint8 *) "foo", 3, NULL);
fail_unless (buf2 != NULL); fail_unless (buf2 != NULL);
fail_unless (memcmp (GST_BUFFER_DATA (buf1), GST_BUFFER_DATA (buf2) + 3, data1 = gst_buffer_map (buf1, &size1, NULL, GST_MAP_READ);
GST_BUFFER_SIZE (buf1)) == 0); data2 = gst_buffer_map (buf2, &size2, NULL, GST_MAP_READ);
fail_unless (memcmp (data1, data2 + 3, size1) == 0);
gst_buffer_unmap (buf2, data2, size2);
gst_buffer_unmap (buf1, data1, size1);
gst_buffer_unref (buf1); gst_buffer_unref (buf1);
gst_buffer_unref (buf2); gst_buffer_unref (buf2);
@ -437,8 +444,10 @@ GST_START_TEST (test_vorbis_tags)
gchar *vendor = NULL; gchar *vendor = NULL;
buf = gst_buffer_new (); buf = gst_buffer_new ();
GST_BUFFER_DATA (buf) = (guint8 *) speex_comments_buf1; gst_buffer_take_memory (buf,
GST_BUFFER_SIZE (buf) = sizeof (speex_comments_buf1); gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY,
(gpointer) speex_comments_buf1, NULL,
sizeof (speex_comments_buf1), 0, sizeof (speex_comments_buf1)));
/* make sure it doesn't memcmp over the end of the buffer */ /* make sure it doesn't memcmp over the end of the buffer */
fail_unless (gst_tag_list_from_vorbiscomment_buffer (buf, fail_unless (gst_tag_list_from_vorbiscomment_buffer (buf,
@ -480,8 +489,10 @@ GST_START_TEST (test_vorbis_tags)
gchar *vendor = NULL; gchar *vendor = NULL;
buf = gst_buffer_new (); buf = gst_buffer_new ();
GST_BUFFER_DATA (buf) = (guint8 *) vorbis_comments_buf; gst_buffer_take_memory (buf,
GST_BUFFER_SIZE (buf) = sizeof (vorbis_comments_buf); gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY,
(gpointer) vorbis_comments_buf, NULL,
sizeof (vorbis_comments_buf), 0, sizeof (vorbis_comments_buf)));
/* make sure it doesn't memcmp over the end of the buffer */ /* make sure it doesn't memcmp over the end of the buffer */
fail_unless (gst_tag_list_from_vorbiscomment_buffer (buf, fail_unless (gst_tag_list_from_vorbiscomment_buffer (buf,
@ -755,7 +766,7 @@ GST_START_TEST (test_xmp_formatting)
GstTagList *list; GstTagList *list;
GstBuffer *buf; GstBuffer *buf;
const gchar *text; const gchar *text;
guint len; gsize len;
/* test data */ /* test data */
list = gst_tag_list_new_full (GST_TAG_TITLE, "test title", list = gst_tag_list_new_full (GST_TAG_TITLE, "test title",
@ -765,8 +776,7 @@ GST_START_TEST (test_xmp_formatting)
buf = gst_tag_list_to_xmp_buffer (list, FALSE); buf = gst_tag_list_to_xmp_buffer (list, FALSE);
fail_unless (buf != NULL); fail_unless (buf != NULL);
text = (const gchar *) GST_BUFFER_DATA (buf); text = gst_buffer_map (buf, &len, NULL, GST_MAP_READ);
len = GST_BUFFER_SIZE (buf);
/* check the content */ /* check the content */
fail_unless (g_strrstr_len (text, len, "<?xpacket begin") == text); fail_unless (g_strrstr_len (text, len, "<?xpacket begin") == text);
@ -775,6 +785,7 @@ GST_START_TEST (test_xmp_formatting)
fail_unless (g_strrstr_len (text, len, ">keyword1<") != NULL); fail_unless (g_strrstr_len (text, len, ">keyword1<") != NULL);
fail_unless (g_strrstr_len (text, len, ">keyword2<") != NULL); fail_unless (g_strrstr_len (text, len, ">keyword2<") != NULL);
fail_unless (g_strrstr_len (text, len, "<?xpacket end") != NULL); fail_unless (g_strrstr_len (text, len, "<?xpacket end") != NULL);
gst_buffer_unmap (buf, (gpointer) text, len);
gst_buffer_unref (buf); gst_buffer_unref (buf);
gst_tag_list_free (list); gst_tag_list_free (list);
@ -814,16 +825,18 @@ GST_START_TEST (test_xmp_parsing)
}; };
/* test data */ /* test data */
buf = gst_buffer_new ();
i = 0; i = 0;
while (test_data[i].xmp_data) { while (test_data[i].xmp_data) {
gsize len;
GST_DEBUG ("trying test-data %u", i); GST_DEBUG ("trying test-data %u", i);
text = g_strconcat (xmp_header, test_data[i].xmp_data, xmp_footer, NULL); text = g_strconcat (xmp_header, test_data[i].xmp_data, xmp_footer, NULL);
GST_BUFFER_DATA (buf) = (guint8 *) text;
GST_BUFFER_SIZE (buf) = strlen (text) + 1;
buf = gst_buffer_new ();
len = strlen (text) + 1;
gst_buffer_take_memory (buf,
gst_memory_new_wrapped (0, text, NULL, len, 0, len));
list = gst_tag_list_from_xmp_buffer (buf); list = gst_tag_list_from_xmp_buffer (buf);
if (test_data[i].result_size >= 0) { if (test_data[i].result_size >= 0) {
@ -844,6 +857,7 @@ GST_START_TEST (test_xmp_parsing)
if (list) if (list)
gst_tag_list_free (list); gst_tag_list_free (list);
gst_buffer_unref (buf);
g_free (text); g_free (text);
i++; i++;
} }
@ -1251,6 +1265,7 @@ GST_START_TEST (test_exif_tags_serialization_deserialization)
GstBuffer *buf = NULL; GstBuffer *buf = NULL;
gint i; gint i;
GstTagList *taglist; GstTagList *taglist;
guint8 *data;
gst_tag_register_musicbrainz_tags (); gst_tag_register_musicbrainz_tags ();
@ -1545,8 +1560,10 @@ GST_START_TEST (test_exif_tags_serialization_deserialization)
g_value_init (&value, GST_TYPE_BUFFER); g_value_init (&value, GST_TYPE_BUFFER);
buf = gst_buffer_new_and_alloc (1024); buf = gst_buffer_new_and_alloc (1024);
data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
for (i = 0; i < 1024; i++) for (i = 0; i < 1024; i++)
GST_BUFFER_DATA (buf)[i] = i % 255; data[i] = i % 255;
gst_buffer_unmap (buf, data, 1024);
gst_value_set_buffer (&value, buf); gst_value_set_buffer (&value, buf);
gst_buffer_unref (buf); gst_buffer_unref (buf);
do_simple_exif_tag_serialization_deserialization (GST_TAG_APPLICATION_DATA, do_simple_exif_tag_serialization_deserialization (GST_TAG_APPLICATION_DATA,

View file

@ -162,16 +162,14 @@ eos_buffer_probe (GstPad * pad, GstBuffer * buffer, gpointer unused)
{ {
gint ret; gint ret;
gint size; gint size;
guint8 *data;
gchar *oggbuffer; gchar *oggbuffer;
ChainState *state = NULL; ChainState *state = NULL;
gboolean has_video = FALSE; gboolean has_video = FALSE;
size = GST_BUFFER_SIZE (buffer); size = gst_buffer_get_size (buffer);
data = GST_BUFFER_DATA (buffer);
oggbuffer = ogg_sync_buffer (&oggsync, size); oggbuffer = ogg_sync_buffer (&oggsync, size);
memcpy (oggbuffer, data, size); gst_buffer_extract (buffer, 0, oggbuffer, size);
ogg_sync_wrote (&oggsync, size); ogg_sync_wrote (&oggsync, size);
do { do {

View file

@ -22,7 +22,6 @@ static void
on_new_buffer_from_source (GstElement * elt, ProgramData * data) on_new_buffer_from_source (GstElement * elt, ProgramData * data)
{ {
guint size; guint size;
gpointer raw_buffer;
GstBuffer *app_buffer, *buffer; GstBuffer *app_buffer, *buffer;
GstElement *source; GstElement *source;
@ -31,11 +30,11 @@ on_new_buffer_from_source (GstElement * elt, ProgramData * data)
/* turn it into an app buffer, it's not really needed, we could simply push /* turn it into an app buffer, it's not really needed, we could simply push
* the retrieved buffer from appsink into appsrc just fine. */ * the retrieved buffer from appsink into appsrc just fine. */
size = GST_BUFFER_SIZE (buffer); size = gst_buffer_get_size (buffer);
g_print ("Pushing a buffer of size %d\n", size); g_print ("Pushing a buffer of size %d\n", size);
app_buffer = gst_buffer_new_and_alloc (size); app_buffer = gst_buffer_new_and_alloc (size);
raw_buffer = GST_BUFFER_DATA (app_buffer);
memcpy (raw_buffer, GST_BUFFER_DATA (buffer), size); gst_buffer_copy_into (app_buffer, buffer, GST_BUFFER_COPY_MEMORY, 0, size);
/* newer basesrc will set caps for use automatically but it does not really /* newer basesrc will set caps for use automatically but it does not really
* hurt to set it on the buffer again */ * hurt to set it on the buffer again */

View file

@ -83,8 +83,10 @@ feed_data (GstElement * appsrc, guint size, App * app)
if (app->offset + size > app->length) if (app->offset + size > app->length)
size = app->length - app->offset; size = app->length - app->offset;
GST_BUFFER_DATA (buffer) = app->data + app->offset; gst_buffer_take_memory (buffer,
GST_BUFFER_SIZE (buffer) = size; gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY,
app->data, NULL, app->length, app->offset, size));
/* we need to set an offset for random access */ /* we need to set an offset for random access */
GST_BUFFER_OFFSET (buffer) = app->offset; GST_BUFFER_OFFSET (buffer) = app->offset;
GST_BUFFER_OFFSET_END (buffer) = app->offset + size; GST_BUFFER_OFFSET_END (buffer) = app->offset + size;

View file

@ -89,8 +89,9 @@ feed_data (GstElement * appsrc, guint size, App * app)
if (app->offset + len > app->length) if (app->offset + len > app->length)
len = app->length - app->offset; len = app->length - app->offset;
GST_BUFFER_DATA (buffer) = app->data + app->offset; gst_buffer_take_memory (buffer,
GST_BUFFER_SIZE (buffer) = len; gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY,
app->data, NULL, app->length, app->offset, len));
GST_DEBUG ("feed buffer %p, offset %" G_GUINT64_FORMAT "-%u", buffer, GST_DEBUG ("feed buffer %p, offset %" G_GUINT64_FORMAT "-%u", buffer,
app->offset, len); app->offset, len);

View file

@ -96,8 +96,9 @@ read_data (App * app)
if (app->offset + len > app->length) if (app->offset + len > app->length)
len = app->length - app->offset; len = app->length - app->offset;
GST_BUFFER_DATA (buffer) = app->data + app->offset; gst_buffer_take_memory (buffer,
GST_BUFFER_SIZE (buffer) = len; gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY,
app->data, NULL, app->length, app->offset, len));
GST_DEBUG ("feed buffer %p, offset %" G_GUINT64_FORMAT "-%u", buffer, GST_DEBUG ("feed buffer %p, offset %" G_GUINT64_FORMAT "-%u", buffer,
app->offset, len); app->offset, len);

View file

@ -96,8 +96,9 @@ feed_data (GstElement * appsrc, guint size, App * app)
if (app->offset + len > app->length) if (app->offset + len > app->length)
len = app->length - app->offset; len = app->length - app->offset;
GST_BUFFER_DATA (buffer) = app->data + app->offset; gst_buffer_take_memory (buffer,
GST_BUFFER_SIZE (buffer) = len; gst_memory_new_wrapped (GST_MEMORY_FLAG_READONLY,
app->data, NULL, app->length, app->offset, len));
GST_DEBUG ("feed buffer %p, offset %" G_GUINT64_FORMAT "-%u", buffer, GST_DEBUG ("feed buffer %p, offset %" G_GUINT64_FORMAT "-%u", buffer,
app->offset, len); app->offset, len);

View file

@ -57,8 +57,9 @@ main (int argc, char *argv[])
void *data; void *data;
buf = gst_buffer_new_and_alloc (100); buf = gst_buffer_new_and_alloc (100);
data = GST_BUFFER_DATA (buf); data = gst_buffer_map (buf, NULL, NULL, GST_MAP_WRITE);
memset (data, i, 100); memset (data, i, 100);
gst_buffer_unmap (buf, data, 100);
printf ("%d: pushing buffer for pointer %p, %p\n", i, data, buf); printf ("%d: pushing buffer for pointer %p, %p\n", i, data, buf);
gst_app_src_push_buffer (GST_APP_SRC (app->src), buf); gst_app_src_push_buffer (GST_APP_SRC (app->src), buf);

View file

@ -2044,6 +2044,8 @@ shot_cb (GtkButton * button, gpointer data)
gint width, height; gint width, height;
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;
GError *error = NULL; GError *error = NULL;
gsize size;
guint8 *data;
/* get the snapshot buffer format now. We set the caps on the appsink so /* get the snapshot buffer format now. We set the caps on the appsink so
* that it can only be an rgb buffer. The only thing we have not specified * that it can only be an rgb buffer. The only thing we have not specified
@ -2066,12 +2068,17 @@ shot_cb (GtkButton * button, gpointer data)
/* create pixmap from buffer and save, gstreamer video buffers have a stride /* create pixmap from buffer and save, gstreamer video buffers have a stride
* that is rounded up to the nearest multiple of 4 */ * that is rounded up to the nearest multiple of 4 */
pixbuf = gdk_pixbuf_new_from_data (GST_BUFFER_DATA (buffer), data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
pixbuf = gdk_pixbuf_new_from_data (data,
GDK_COLORSPACE_RGB, FALSE, 8, width, height, GDK_COLORSPACE_RGB, FALSE, 8, width, height,
GST_ROUND_UP_4 (width * 3), NULL, NULL); GST_ROUND_UP_4 (width * 3), NULL, NULL);
/* save the pixbuf */ /* save the pixbuf */
gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL); gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL);
gst_buffer_unmap (buffer, data, size);
/* save the pixbuf */
gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL);
done: done:
gst_buffer_unref (buffer); gst_buffer_unref (buffer);

View file

@ -2034,6 +2034,8 @@ shot_cb (GtkButton * button, gpointer data)
gint width, height; gint width, height;
GdkPixbuf *pixbuf; GdkPixbuf *pixbuf;
GError *error = NULL; GError *error = NULL;
guint8 *data;
gsize size;
/* get the snapshot buffer format now. We set the caps on the appsink so /* get the snapshot buffer format now. We set the caps on the appsink so
* that it can only be an rgb buffer. The only thing we have not specified * that it can only be an rgb buffer. The only thing we have not specified
@ -2056,12 +2058,14 @@ shot_cb (GtkButton * button, gpointer data)
/* create pixmap from buffer and save, gstreamer video buffers have a stride /* create pixmap from buffer and save, gstreamer video buffers have a stride
* that is rounded up to the nearest multiple of 4 */ * that is rounded up to the nearest multiple of 4 */
pixbuf = gdk_pixbuf_new_from_data (GST_BUFFER_DATA (buffer), data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
pixbuf = gdk_pixbuf_new_from_data (data,
GDK_COLORSPACE_RGB, FALSE, 8, width, height, GDK_COLORSPACE_RGB, FALSE, 8, width, height,
GST_ROUND_UP_4 (width * 3), NULL, NULL); GST_ROUND_UP_4 (width * 3), NULL, NULL);
/* save the pixbuf */ /* save the pixbuf */
gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL); gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL);
gst_buffer_unmap (buffer, data, size);
done: done:
gst_buffer_unref (buffer); gst_buffer_unref (buffer);

View file

@ -37,6 +37,8 @@ main (int argc, char *argv[])
GstFormat format; GstFormat format;
GstStateChangeReturn ret; GstStateChangeReturn ret;
gboolean res; gboolean res;
guint8 *data;
gsize size;
gst_init (&argc, &argv); gst_init (&argc, &argv);
@ -133,10 +135,15 @@ main (int argc, char *argv[])
/* create pixmap from buffer and save, gstreamer video buffers have a stride /* create pixmap from buffer and save, gstreamer video buffers have a stride
* that is rounded up to the nearest multiple of 4 */ * that is rounded up to the nearest multiple of 4 */
pixbuf = gdk_pixbuf_new_from_data (GST_BUFFER_DATA (buffer), data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
pixbuf = gdk_pixbuf_new_from_data (data,
GDK_COLORSPACE_RGB, FALSE, 8, width, height, GDK_COLORSPACE_RGB, FALSE, 8, width, height,
GST_ROUND_UP_4 (width * 3), NULL, NULL); GST_ROUND_UP_4 (width * 3), NULL, NULL);
/* save the pixbuf */
gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL);
gst_buffer_unmap (buffer, data, size);
/* save the pixbuf */ /* save the pixbuf */
gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL); gdk_pixbuf_save (pixbuf, "snapshot.png", "png", &error, NULL);
} else { } else {

View file

@ -94,7 +94,7 @@ have_subtitle (GstElement * appsink, App * app)
if (buffer) { if (buffer) {
guint8 *data; guint8 *data;
guint size; gsize size;
GstFormat format; GstFormat format;
gint64 position; gint64 position;
GstClock *clock; GstClock *clock;
@ -114,10 +114,9 @@ have_subtitle (GstElement * appsink, App * app)
", running_time %" GST_TIME_FORMAT, GST_TIME_ARGS (position), ", running_time %" GST_TIME_FORMAT, GST_TIME_ARGS (position),
GST_TIME_ARGS (running_time)); GST_TIME_ARGS (running_time));
data = GST_BUFFER_DATA (buffer); data = gst_buffer_map (buffer, &size, NULL, GST_MAP_READ);
size = GST_BUFFER_SIZE (buffer);
gst_util_dump_mem (data, size); gst_util_dump_mem (data, size);
gst_buffer_unmap (buffer, data, size);
} }
} }