2009-06-01 19:24:12 +00:00
|
|
|
/* GStreamer
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Sebastian Dröge <sebastian.droege@collabora.co.uk>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <gst/check/gstcheck.h>
|
|
|
|
|
|
|
|
gboolean have_eos = FALSE;
|
|
|
|
|
|
|
|
/* For ease of programming we use globals to keep refs for our floating
|
|
|
|
* src and sink pads we create; otherwise we always have to do get_pad,
|
|
|
|
* get_peer, and then remove references in every test function */
|
|
|
|
GstPad *myvideosrcpad, *mymasksrcpad, *mysinkpad;
|
|
|
|
|
|
|
|
|
|
|
|
#define SHAPEWIPE_VIDEO_CAPS_STRING \
|
2012-01-03 13:16:28 +00:00
|
|
|
"video/x-raw, " \
|
|
|
|
"format = (string)AYUV, " \
|
2009-06-01 19:24:12 +00:00
|
|
|
"width = 400, " \
|
|
|
|
"height = 400, " \
|
|
|
|
"framerate = 0/1"
|
|
|
|
|
|
|
|
#define SHAPEWIPE_MASK_CAPS_STRING \
|
2012-01-03 13:16:28 +00:00
|
|
|
"video/x-raw, " \
|
|
|
|
"format = (string)GRAY8, " \
|
2009-06-01 19:24:12 +00:00
|
|
|
"width = 400, " \
|
|
|
|
"height = 400, " \
|
|
|
|
"framerate = 0/1"
|
|
|
|
|
|
|
|
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS (SHAPEWIPE_VIDEO_CAPS_STRING)
|
|
|
|
);
|
|
|
|
static GstStaticPadTemplate videosrctemplate =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("videosrc",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS (SHAPEWIPE_VIDEO_CAPS_STRING)
|
|
|
|
);
|
|
|
|
static GstStaticPadTemplate masksrctemplate =
|
|
|
|
GST_STATIC_PAD_TEMPLATE ("masksrc",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS (SHAPEWIPE_MASK_CAPS_STRING)
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
static GstBuffer *output = NULL;
|
|
|
|
|
|
|
|
static GstFlowReturn
|
2012-01-03 13:16:28 +00:00
|
|
|
on_chain (GstPad * pad, GstObject * parent, GstBuffer * buffer)
|
2009-06-01 19:24:12 +00:00
|
|
|
{
|
|
|
|
g_return_val_if_fail (output == NULL, GST_FLOW_ERROR);
|
|
|
|
|
|
|
|
output = buffer;
|
|
|
|
return GST_FLOW_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_START_TEST (test_general)
|
|
|
|
{
|
|
|
|
GstElement *shapewipe;
|
|
|
|
GstPad *p;
|
|
|
|
GstCaps *caps;
|
|
|
|
GstBuffer *mask, *input;
|
|
|
|
guint i, j;
|
2012-01-03 13:16:28 +00:00
|
|
|
guint8 *data, *orig;
|
2009-06-01 19:24:12 +00:00
|
|
|
|
|
|
|
myvideosrcpad =
|
|
|
|
gst_pad_new_from_static_template (&videosrctemplate, "videosrc");
|
|
|
|
gst_pad_set_active (myvideosrcpad, TRUE);
|
|
|
|
caps = gst_caps_from_string (SHAPEWIPE_VIDEO_CAPS_STRING);
|
|
|
|
gst_pad_set_caps (myvideosrcpad, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
|
|
|
mymasksrcpad = gst_pad_new_from_static_template (&masksrctemplate, "masksrc");
|
|
|
|
gst_pad_set_active (mymasksrcpad, TRUE);
|
|
|
|
caps = gst_caps_from_string (SHAPEWIPE_MASK_CAPS_STRING);
|
|
|
|
gst_pad_set_caps (mymasksrcpad, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
|
|
|
mysinkpad = gst_pad_new_from_static_template (&sinktemplate, "sink");
|
|
|
|
gst_pad_set_chain_function (mysinkpad, on_chain);
|
|
|
|
gst_pad_set_active (mysinkpad, TRUE);
|
|
|
|
caps = gst_caps_from_string (SHAPEWIPE_VIDEO_CAPS_STRING);
|
|
|
|
gst_pad_set_caps (mysinkpad, caps);
|
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
|
|
|
shapewipe = gst_element_factory_make ("shapewipe", NULL);
|
|
|
|
fail_unless (shapewipe != NULL);
|
|
|
|
|
|
|
|
p = gst_element_get_static_pad (shapewipe, "video_sink");
|
|
|
|
fail_unless (gst_pad_link (myvideosrcpad, p) == GST_PAD_LINK_OK);
|
|
|
|
gst_object_unref (p);
|
|
|
|
p = gst_element_get_static_pad (shapewipe, "mask_sink");
|
|
|
|
fail_unless (gst_pad_link (mymasksrcpad, p) == GST_PAD_LINK_OK);
|
|
|
|
gst_object_unref (p);
|
|
|
|
p = gst_element_get_static_pad (shapewipe, "src");
|
|
|
|
fail_unless (gst_pad_link (p, mysinkpad) == GST_PAD_LINK_OK);
|
|
|
|
gst_object_unref (p);
|
|
|
|
|
|
|
|
fail_unless (gst_element_set_state (shapewipe,
|
|
|
|
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS);
|
|
|
|
|
|
|
|
mask = gst_buffer_new_and_alloc (400 * 400);
|
|
|
|
caps = gst_caps_from_string (SHAPEWIPE_MASK_CAPS_STRING);
|
2012-01-03 13:16:28 +00:00
|
|
|
gst_pad_set_caps (mymasksrcpad, caps);
|
2009-06-01 19:24:12 +00:00
|
|
|
gst_caps_unref (caps);
|
2012-01-03 13:16:28 +00:00
|
|
|
data = orig = gst_buffer_map (mask, NULL, NULL, GST_MAP_WRITE);
|
2009-06-01 19:24:12 +00:00
|
|
|
for (i = 0; i < 400; i++) {
|
|
|
|
for (j = 0; j < 400; j++) {
|
|
|
|
if (i < 100 && j < 100)
|
|
|
|
data[0] = 0;
|
|
|
|
else if (i < 200 && j < 200)
|
|
|
|
data[0] = 85;
|
|
|
|
else if (i < 300 && j < 300)
|
|
|
|
data[0] = 170;
|
|
|
|
else
|
|
|
|
data[0] = 254;
|
|
|
|
data++;
|
|
|
|
}
|
|
|
|
}
|
2012-01-03 13:16:28 +00:00
|
|
|
gst_buffer_unmap (mask, orig, -1);
|
2009-06-01 19:24:12 +00:00
|
|
|
|
|
|
|
fail_unless (gst_pad_push (mymasksrcpad, mask) == GST_FLOW_OK);
|
|
|
|
|
|
|
|
input = gst_buffer_new_and_alloc (400 * 400 * 4);
|
|
|
|
caps = gst_caps_from_string (SHAPEWIPE_VIDEO_CAPS_STRING);
|
2012-01-03 13:16:28 +00:00
|
|
|
gst_pad_set_caps (myvideosrcpad, caps);
|
2009-06-01 19:24:12 +00:00
|
|
|
gst_caps_unref (caps);
|
2012-01-03 13:16:28 +00:00
|
|
|
data = orig = gst_buffer_map (input, NULL, NULL, GST_MAP_WRITE);
|
2009-06-01 19:24:12 +00:00
|
|
|
for (i = 0; i < 400; i++) {
|
|
|
|
for (j = 0; j < 400; j++) {
|
|
|
|
/* This is green */
|
2010-02-14 23:50:27 +00:00
|
|
|
data[0] = 255; /* A */
|
2009-06-01 19:24:12 +00:00
|
|
|
data[1] = 173; /* Y */
|
|
|
|
data[2] = 42; /* U */
|
|
|
|
data[3] = 26; /* V */
|
|
|
|
data += 4;
|
|
|
|
}
|
|
|
|
}
|
2012-01-03 13:16:28 +00:00
|
|
|
gst_buffer_unmap (input, orig, -1);
|
2009-06-01 19:24:12 +00:00
|
|
|
|
|
|
|
g_object_set (G_OBJECT (shapewipe), "position", 0.0, NULL);
|
|
|
|
output = NULL;
|
|
|
|
fail_unless (gst_pad_push (myvideosrcpad,
|
|
|
|
gst_buffer_ref (input)) == GST_FLOW_OK);
|
|
|
|
fail_unless (output != NULL);
|
2012-01-03 13:16:28 +00:00
|
|
|
data = orig = gst_buffer_map (output, NULL, NULL, GST_MAP_WRITE);
|
2009-06-01 19:24:12 +00:00
|
|
|
for (i = 0; i < 400; i++) {
|
|
|
|
for (j = 0; j < 400; j++) {
|
2010-02-14 23:47:08 +00:00
|
|
|
fail_unless_equals_int (data[0], 255); /* A */
|
|
|
|
fail_unless_equals_int (data[1], 173); /* Y */
|
|
|
|
fail_unless_equals_int (data[2], 42); /* U */
|
|
|
|
fail_unless_equals_int (data[3], 26); /* V */
|
2009-06-01 19:24:12 +00:00
|
|
|
data += 4;
|
|
|
|
}
|
|
|
|
}
|
2012-01-03 13:16:28 +00:00
|
|
|
gst_buffer_unmap (output, orig, -1);
|
2009-06-01 19:24:12 +00:00
|
|
|
gst_buffer_unref (output);
|
|
|
|
output = NULL;
|
|
|
|
|
|
|
|
g_object_set (G_OBJECT (shapewipe), "position", 0.1, NULL);
|
|
|
|
output = NULL;
|
|
|
|
fail_unless (gst_pad_push (myvideosrcpad,
|
|
|
|
gst_buffer_ref (input)) == GST_FLOW_OK);
|
|
|
|
fail_unless (output != NULL);
|
2012-01-03 13:16:28 +00:00
|
|
|
data = orig = gst_buffer_map (output, NULL, NULL, GST_MAP_WRITE);
|
2009-06-01 19:24:12 +00:00
|
|
|
for (i = 0; i < 400; i++) {
|
|
|
|
for (j = 0; j < 400; j++) {
|
|
|
|
if (i < 100 && j < 100) {
|
2010-02-14 23:47:08 +00:00
|
|
|
fail_unless_equals_int (data[0], 0); /* A */
|
2010-02-14 23:50:27 +00:00
|
|
|
fail_unless_equals_int (data[1], 173); /* Y */
|
|
|
|
fail_unless_equals_int (data[2], 42); /* U */
|
|
|
|
fail_unless_equals_int (data[3], 26); /* V */
|
2009-06-01 19:24:12 +00:00
|
|
|
} else {
|
2010-02-14 23:47:08 +00:00
|
|
|
fail_unless_equals_int (data[0], 255); /* A */
|
|
|
|
fail_unless_equals_int (data[1], 173); /* Y */
|
|
|
|
fail_unless_equals_int (data[2], 42); /* U */
|
|
|
|
fail_unless_equals_int (data[3], 26); /* V */
|
2009-06-01 19:24:12 +00:00
|
|
|
}
|
|
|
|
data += 4;
|
|
|
|
}
|
|
|
|
}
|
2012-01-03 13:16:28 +00:00
|
|
|
gst_buffer_unmap (output, orig, -1);
|
2009-06-01 19:24:12 +00:00
|
|
|
gst_buffer_unref (output);
|
|
|
|
output = NULL;
|
|
|
|
|
|
|
|
g_object_set (G_OBJECT (shapewipe), "position", 0.34, NULL);
|
|
|
|
output = NULL;
|
|
|
|
fail_unless (gst_pad_push (myvideosrcpad,
|
|
|
|
gst_buffer_ref (input)) == GST_FLOW_OK);
|
|
|
|
fail_unless (output != NULL);
|
2012-01-03 13:16:28 +00:00
|
|
|
data = orig = gst_buffer_map (output, NULL, NULL, GST_MAP_WRITE);
|
2009-06-01 19:24:12 +00:00
|
|
|
for (i = 0; i < 400; i++) {
|
|
|
|
for (j = 0; j < 400; j++) {
|
|
|
|
if (i < 200 && j < 200) {
|
2010-02-14 23:47:08 +00:00
|
|
|
fail_unless_equals_int (data[0], 0); /* A */
|
2010-02-14 23:50:27 +00:00
|
|
|
fail_unless_equals_int (data[1], 173); /* Y */
|
|
|
|
fail_unless_equals_int (data[2], 42); /* U */
|
|
|
|
fail_unless_equals_int (data[3], 26); /* V */
|
2009-06-01 19:24:12 +00:00
|
|
|
} else {
|
2010-02-14 23:47:08 +00:00
|
|
|
fail_unless_equals_int (data[0], 255); /* A */
|
|
|
|
fail_unless_equals_int (data[1], 173); /* Y */
|
|
|
|
fail_unless_equals_int (data[2], 42); /* U */
|
|
|
|
fail_unless_equals_int (data[3], 26); /* V */
|
2009-06-01 19:24:12 +00:00
|
|
|
}
|
|
|
|
data += 4;
|
|
|
|
}
|
|
|
|
}
|
2012-01-03 13:16:28 +00:00
|
|
|
gst_buffer_unmap (output, orig, -1);
|
2009-06-01 19:24:12 +00:00
|
|
|
gst_buffer_unref (output);
|
|
|
|
output = NULL;
|
|
|
|
|
|
|
|
g_object_set (G_OBJECT (shapewipe), "position", 0.67, NULL);
|
|
|
|
output = NULL;
|
|
|
|
fail_unless (gst_pad_push (myvideosrcpad,
|
|
|
|
gst_buffer_ref (input)) == GST_FLOW_OK);
|
|
|
|
fail_unless (output != NULL);
|
2012-01-03 13:16:28 +00:00
|
|
|
data = orig = gst_buffer_map (output, NULL, NULL, GST_MAP_WRITE);
|
2009-06-01 19:24:12 +00:00
|
|
|
for (i = 0; i < 400; i++) {
|
|
|
|
for (j = 0; j < 400; j++) {
|
|
|
|
if (i < 300 && j < 300) {
|
2010-02-14 23:47:08 +00:00
|
|
|
fail_unless_equals_int (data[0], 0); /* A */
|
2010-02-14 23:50:27 +00:00
|
|
|
fail_unless_equals_int (data[1], 173); /* Y */
|
|
|
|
fail_unless_equals_int (data[2], 42); /* U */
|
|
|
|
fail_unless_equals_int (data[3], 26); /* V */
|
2009-06-01 19:24:12 +00:00
|
|
|
} else {
|
2010-02-14 23:47:08 +00:00
|
|
|
fail_unless_equals_int (data[0], 255); /* A */
|
|
|
|
fail_unless_equals_int (data[1], 173); /* Y */
|
|
|
|
fail_unless_equals_int (data[2], 42); /* U */
|
|
|
|
fail_unless_equals_int (data[3], 26); /* V */
|
2009-06-01 19:24:12 +00:00
|
|
|
}
|
|
|
|
data += 4;
|
|
|
|
}
|
|
|
|
}
|
2012-01-03 13:16:28 +00:00
|
|
|
gst_buffer_unmap (output, orig, -1);
|
2009-06-01 19:24:12 +00:00
|
|
|
gst_buffer_unref (output);
|
|
|
|
output = NULL;
|
|
|
|
|
|
|
|
g_object_set (G_OBJECT (shapewipe), "position", 1.0, NULL);
|
|
|
|
output = NULL;
|
|
|
|
fail_unless (gst_pad_push (myvideosrcpad,
|
|
|
|
gst_buffer_ref (input)) == GST_FLOW_OK);
|
|
|
|
fail_unless (output != NULL);
|
2012-01-03 13:16:28 +00:00
|
|
|
data = orig = gst_buffer_map (output, NULL, NULL, GST_MAP_WRITE);
|
2009-06-01 19:24:12 +00:00
|
|
|
for (i = 0; i < 400; i++) {
|
|
|
|
for (j = 0; j < 400; j++) {
|
2010-02-14 23:47:08 +00:00
|
|
|
fail_unless_equals_int (data[0], 0); /* A */
|
2010-02-14 23:50:27 +00:00
|
|
|
fail_unless_equals_int (data[1], 173); /* Y */
|
|
|
|
fail_unless_equals_int (data[2], 42); /* U */
|
|
|
|
fail_unless_equals_int (data[3], 26); /* V */
|
2009-06-01 19:24:12 +00:00
|
|
|
data += 4;
|
|
|
|
}
|
|
|
|
}
|
2012-01-03 13:16:28 +00:00
|
|
|
gst_buffer_unmap (output, orig, -1);
|
2009-06-01 19:24:12 +00:00
|
|
|
gst_buffer_unref (output);
|
|
|
|
output = NULL;
|
|
|
|
|
|
|
|
gst_buffer_unref (input);
|
|
|
|
|
|
|
|
fail_unless (gst_element_set_state (shapewipe,
|
|
|
|
GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS);
|
|
|
|
|
|
|
|
p = gst_element_get_static_pad (shapewipe, "video_sink");
|
|
|
|
fail_unless (gst_pad_unlink (myvideosrcpad, p));
|
|
|
|
gst_object_unref (p);
|
|
|
|
p = gst_element_get_static_pad (shapewipe, "mask_sink");
|
|
|
|
fail_unless (gst_pad_unlink (mymasksrcpad, p));
|
|
|
|
gst_object_unref (p);
|
|
|
|
p = gst_element_get_static_pad (shapewipe, "src");
|
|
|
|
fail_unless (gst_pad_unlink (p, mysinkpad));
|
|
|
|
gst_object_unref (p);
|
|
|
|
|
|
|
|
gst_object_unref (myvideosrcpad);
|
|
|
|
gst_object_unref (mymasksrcpad);
|
|
|
|
gst_object_unref (mysinkpad);
|
|
|
|
gst_object_unref (shapewipe);
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_END_TEST;
|
|
|
|
|
2010-03-17 17:23:00 +00:00
|
|
|
static Suite *
|
2009-06-01 19:24:12 +00:00
|
|
|
shapewipe_suite (void)
|
|
|
|
{
|
|
|
|
Suite *s = suite_create ("shapewipe");
|
|
|
|
TCase *tc_chain = tcase_create ("general");
|
|
|
|
|
|
|
|
suite_add_tcase (s, tc_chain);
|
2009-06-04 06:56:14 +00:00
|
|
|
tcase_set_timeout (tc_chain, 180);
|
2009-06-01 19:24:12 +00:00
|
|
|
tcase_add_test (tc_chain, test_general);
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_CHECK_MAIN (shapewipe);
|