gstreamer/subprojects/gst-plugins-good/tests/check/elements/aspectratiocrop.c

176 lines
6.2 KiB
C
Raw Normal View History

/* GStreamer unit test for the aspectratiocrop element
* Copyright (C) 2009 Thijs Vermeir <thijsvermeir@gmail.com>
*
* 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., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <gst/gst.h>
#include <gst/video/video.h>
#include <gst/check/gstcheck.h>
2011-10-12 20:43:47 +00:00
#define ASPECT_RATIO_CROP_CAPS \
GST_VIDEO_CAPS_MAKE ("{ RGBx, xRGB, BGRx, xBGR, " \
"RGBA, ARGB, BGRA, ABGR, RGB, BGR, AYUV, " \
2012-06-06 11:00:58 +00:00
"YUY2, YVYU, UYVY, GRAY8, I420, YV12, RGB16, " \
2011-10-12 20:43:47 +00:00
"RGB15 }")
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (ASPECT_RATIO_CROP_CAPS)
);
static void
check_aspectratiocrop (const gchar * in_string, const gchar * out_string,
gint in_size, gint out_size, gint ar_n, gint ar_d)
{
GstElement *element;
GstPad *pad_peer;
GstPad *sink_pad = NULL;
GstPad *src_pad;
GstBuffer *new;
GstBuffer *buffer;
GstBuffer *buffer_out;
2011-10-12 20:43:47 +00:00
GstCaps *incaps;
GstCaps *outcaps;
2011-10-12 20:43:47 +00:00
incaps = gst_caps_from_string (in_string);
buffer = gst_buffer_new_and_alloc (in_size);
outcaps = gst_caps_from_string (out_string);
buffer_out = gst_buffer_new_and_alloc (out_size);
/* check that there are no buffers waiting */
gst_check_drop_buffers ();
/* create the element */
element = gst_check_setup_element ("aspectratiocrop");
/* set the requested aspect ratio */
g_object_set (G_OBJECT (element), "aspect-ratio", ar_n, ar_d, NULL);
/* create the src pad */
src_pad = gst_pad_new (NULL, GST_PAD_SRC);
2012-02-06 08:49:38 +00:00
gst_pad_set_active (src_pad, TRUE);
GST_DEBUG ("setting caps %s %" GST_PTR_FORMAT, in_string, incaps);
2013-05-10 11:34:16 +00:00
gst_check_setup_events (src_pad, element, incaps, GST_FORMAT_TIME);
2012-02-06 08:49:38 +00:00
pad_peer = gst_element_get_static_pad (element, "sink");
fail_if (pad_peer == NULL);
fail_unless (gst_pad_link (src_pad, pad_peer) == GST_PAD_LINK_OK,
"Could not link source and %s sink pads", GST_ELEMENT_NAME (element));
gst_object_unref (pad_peer);
/* create the sink pad */
pad_peer = gst_element_get_static_pad (element, "src");
2011-10-12 20:43:47 +00:00
sink_pad = gst_pad_new_from_static_template (&sinktemplate, "sink");
fail_unless (gst_pad_link (pad_peer, sink_pad) == GST_PAD_LINK_OK,
"Could not link sink and %s source pads", GST_ELEMENT_NAME (element));
gst_object_unref (pad_peer);
gst_pad_set_chain_function (sink_pad, gst_check_chain_func);
gst_pad_set_active (sink_pad, TRUE);
/* configure the sink pad */
fail_unless (gst_element_set_state (element,
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
"could not set to playing");
2011-10-12 20:43:47 +00:00
fail_unless (gst_pad_push (src_pad, buffer) == GST_FLOW_OK,
"Failed to push buffer");
fail_unless (gst_element_set_state (element,
GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS, "could not set to null");
/* check the result */
fail_unless (g_list_length (buffers) == 1);
new = GST_BUFFER (buffers->data);
buffers = g_list_remove (buffers, new);
2011-10-12 20:43:47 +00:00
fail_unless (gst_buffer_get_size (buffer_out) == gst_buffer_get_size (new),
"size of the buffers are not the same");
2011-10-12 20:43:47 +00:00
{
GstCaps *sinkpad_caps;
sinkpad_caps = gst_pad_get_current_caps (sink_pad);
gst_check_caps_equal (sinkpad_caps, outcaps);
gst_caps_unref (sinkpad_caps);
}
gst_buffer_unref (new);
gst_buffer_unref (buffer_out);
2011-10-12 20:43:47 +00:00
gst_caps_unref (outcaps);
gst_caps_unref (incaps);
/* teardown the element and pads */
gst_pad_set_active (src_pad, FALSE);
gst_check_teardown_src_pad (element);
gst_pad_set_active (sink_pad, FALSE);
gst_check_teardown_sink_pad (element);
gst_check_teardown_element (element);
}
GST_START_TEST (test_no_cropping)
{
check_aspectratiocrop
2012-02-06 08:49:38 +00:00
("video/x-raw, format=(string)YUY2, width=(int)320, height=(int)240, framerate=(fraction)30/1",
"video/x-raw, format=(string)YUY2, width=(int)320, height=(int)240, framerate=(fraction)30/1",
153600, 153600, 4, 3);
check_aspectratiocrop
2012-02-06 08:49:38 +00:00
("video/x-raw, format=(string)YUY2, width=(int)320, height=(int)320, framerate=(fraction)30/1, pixel-aspect-ratio=(fraction)4/3",
"video/x-raw, format=(string)YUY2, width=(int)320, height=(int)320, framerate=(fraction)30/1, pixel-aspect-ratio=(fraction)4/3",
204800, 204800, 4, 3);
}
GST_END_TEST;
GST_START_TEST (test_autocropping)
{
check_aspectratiocrop
2012-02-06 08:49:38 +00:00
("video/x-raw, format=(string)YUY2, width=(int)320, height=(int)240, framerate=(fraction)30/1, pixel-aspect-ratio=(fraction)4/3",
"video/x-raw, format=(string)YUY2, width=(int)240, height=(int)240, framerate=(fraction)30/1, pixel-aspect-ratio=(fraction)4/3",
153600, 115200, 4, 3);
check_aspectratiocrop
2012-02-06 08:49:38 +00:00
("video/x-raw, format=(string)YUY2, width=(int)320, height=(int)240, framerate=(fraction)30/1, pixel-aspect-ratio=(fraction)16/9",
"video/x-raw, format=(string)YUY2, width=(int)180, height=(int)240, framerate=(fraction)30/1, pixel-aspect-ratio=(fraction)16/9",
153600, 86400, 4, 3);
check_aspectratiocrop
2012-02-06 08:49:38 +00:00
("video/x-raw, format=(string)YUY2, width=(int)320, height=(int)240, framerate=(fraction)30/1, pixel-aspect-ratio=(fraction)16/15",
"video/x-raw, format=(string)YUY2, width=(int)320, height=(int)192, framerate=(fraction)30/1, pixel-aspect-ratio=(fraction)16/15",
153600, 122880, 16, 9);
}
GST_END_TEST;
static Suite *
aspectratiocrop_suite (void)
{
Suite *s = suite_create ("aspectratiocrop");
TCase *tc_chain = tcase_create ("general");
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_no_cropping);
tcase_add_test (tc_chain, test_autocropping);
return s;
}
GST_CHECK_MAIN (aspectratiocrop);