videoscale: Add unit test for working reverse negotiation

See bug #633147.
This commit is contained in:
Sebastian Dröge 2010-10-28 15:55:12 +02:00
parent e0d683f3ed
commit 0750531378
2 changed files with 242 additions and 0 deletions

View file

@ -346,6 +346,14 @@ elements_vorbistag_CFLAGS = \
$(VORBIS_CFLAGS) \
$(CFLAGS)
elements_videoscale_CFLAGS = \
$(GST_PLUGINS_BASE_CFLAGS) \
$(GST_BASE_CFLAGS) \
$(AM_CFLAGS)
elements_videoscale_LDADD = \
$(top_builddir)/gst-libs/gst/video/libgstvideo-@GST_MAJORMINOR@.la \
$(GST_BASE_LIBS) $(LDADD)
gst_typefindfunctions_CFLAGS = $(GST_BASE_CFLAGS) $(AM_CFLAGS)
gst_typefindfunctions_LDADD = $(GST_BASE_LIBS) $(LDADD)

View file

@ -20,6 +20,9 @@
* Boston, MA 02111-1307, USA.
*/
#include <gst/video/video.h>
#include <gst/base/gstbasesink.h>
#include <gst/check/gstcheck.h>
#include <string.h>
@ -506,6 +509,236 @@ GST_START_TEST (test_negotiation)
GST_END_TEST;
#define GST_TYPE_TEST_REVERSE_NEGOTIATION_SINK \
(gst_test_reverse_negotiation_sink_get_type())
#define GST_TEST_REVERSE_NEGOTIATION_SINK(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_TEST_REVERSE_NEGOTIATION_SINK,GstTestReverseNegotiationSink))
#define GST_TEST_REVERSE_NEGOTIATION_SINK_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_TEST_REVERSE_NEGOTIATION_SINK,GstTestReverseNegotiationSinkClass))
#define GST_IS_TEST_REVERSE_NEGOTIATION_SINK(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_TEST_REVERSE_NEGOTIATION_SINK))
#define GST_IS_TEST_REVERSE_NEGOTIATION_SINK_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_TEST_REVERSE_NEGOTIATION_SINK))
#define GST_TEST_REVERSE_NEGOTIATION_SINK_CAST(obj) ((GstTestReverseNegotiationSink *)obj)
typedef struct _GstTestReverseNegotiationSink GstTestReverseNegotiationSink;
typedef struct _GstTestReverseNegotiationSinkClass
GstTestReverseNegotiationSinkClass;
struct _GstTestReverseNegotiationSink
{
GstBaseSink element;
gint nbuffers;
};
struct _GstTestReverseNegotiationSinkClass
{
GstBaseSinkClass parent_class;
};
GType gst_test_reverse_negotiation_sink_get_type (void);
GST_BOILERPLATE (GstTestReverseNegotiationSink,
gst_test_reverse_negotiation_sink, GstBaseSink, GST_TYPE_BASE_SINK);
static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS (GST_VIDEO_CAPS_xRGB));
static GstFlowReturn
gst_test_reverse_negotiation_sink_buffer_alloc (GstBaseSink * bsink,
guint64 offset, guint size, GstCaps * caps, GstBuffer ** buf)
{
GstTestReverseNegotiationSink *sink =
GST_TEST_REVERSE_NEGOTIATION_SINK (bsink);
GstVideoFormat fmt;
gint width, height;
fail_unless (gst_video_format_parse_caps (caps, &fmt, &width, &height));
if (sink->nbuffers < 2) {
*buf =
gst_buffer_new_and_alloc (gst_video_format_get_size (fmt, width,
height));
gst_buffer_set_caps (*buf, caps);
} else {
gint fps_n, fps_d;
fail_unless (gst_video_parse_caps_framerate (caps, &fps_n, &fps_d));
width = 512;
height = 128;
*buf =
gst_buffer_new_and_alloc (gst_video_format_get_size (fmt, width,
height));
caps = gst_video_format_new_caps (fmt, width, height, fps_n, fps_d, 1, 1);
gst_buffer_set_caps (*buf, caps);
gst_caps_unref (caps);
}
return GST_FLOW_OK;
}
static GstFlowReturn
gst_test_reverse_negotiation_sink_render (GstBaseSink * bsink,
GstBuffer * buffer)
{
GstTestReverseNegotiationSink *sink =
GST_TEST_REVERSE_NEGOTIATION_SINK (bsink);
GstCaps *caps = gst_buffer_get_caps (buffer);
GstVideoFormat fmt;
gint width, height;
fail_unless (caps != NULL);
fail_unless (gst_video_format_parse_caps (caps, &fmt, &width, &height));
sink->nbuffers++;
/* The third buffer is still in the old size
* because the ffmpegcolorspaces can't convert
* the frame sizes
*/
if (sink->nbuffers > 3) {
fail_unless_equals_int (width, 512);
fail_unless_equals_int (height, 128);
}
gst_caps_unref (caps);
return GST_FLOW_OK;
}
static void
gst_test_reverse_negotiation_sink_base_init (gpointer g_class)
{
GstElementClass *gstelement_class = GST_ELEMENT_CLASS (g_class);
gst_element_class_set_details_simple (gstelement_class,
"Test Reverse Negotiation Sink",
"Sink",
"Some test sink", "Sebastian Dröge <sebastian.droege@collabora.co.uk>");
gst_element_class_add_pad_template (gstelement_class,
gst_static_pad_template_get (&sinktemplate));
}
static void
gst_test_reverse_negotiation_sink_class_init (GstTestReverseNegotiationSinkClass
* klass)
{
GObjectClass *gobject_class;
GstElementClass *gstelement_class;
GstBaseSinkClass *gstbase_sink_class;
gobject_class = G_OBJECT_CLASS (klass);
gstelement_class = GST_ELEMENT_CLASS (klass);
gstbase_sink_class = GST_BASE_SINK_CLASS (klass);
gstbase_sink_class->buffer_alloc =
GST_DEBUG_FUNCPTR (gst_test_reverse_negotiation_sink_buffer_alloc);
gstbase_sink_class->render =
GST_DEBUG_FUNCPTR (gst_test_reverse_negotiation_sink_render);
}
static void
gst_test_reverse_negotiation_sink_init (GstTestReverseNegotiationSink * sink,
GstTestReverseNegotiationSinkClass * g_class)
{
sink->nbuffers = 0;
}
static void
_test_reverse_negotiation_message (GstBus * bus, GstMessage * message,
GMainLoop * loop)
{
GError *err = NULL;
gchar *debug;
switch (GST_MESSAGE_TYPE (message)) {
case GST_MESSAGE_ERROR:
gst_message_parse_error (message, &err, &debug);
gst_object_default_error (GST_MESSAGE_SRC (message), err, debug);
g_error_free (err);
g_free (debug);
g_assert_not_reached ();
break;
case GST_MESSAGE_WARNING:
gst_message_parse_warning (message, &err, &debug);
gst_object_default_error (GST_MESSAGE_SRC (message), err, debug);
g_error_free (err);
g_free (debug);
g_assert_not_reached ();
break;
case GST_MESSAGE_EOS:
g_main_loop_quit (loop);
break;
default:
break;
}
}
GST_START_TEST (test_reverse_negotiation)
{
GstElement *pipeline;
GstElement *src, *csp1, *scale, *csp2, *sink;
GstBus *bus;
GMainLoop *loop;
pipeline = gst_element_factory_make ("pipeline", "pipeline");
fail_unless (pipeline != NULL);
src = gst_element_factory_make ("videotestsrc", "src");
fail_unless (src != NULL);
g_object_set (G_OBJECT (src), "num-buffers", 8, NULL);
csp1 = gst_element_factory_make ("ffmpegcolorspace", "csp1");
fail_unless (csp1 != NULL);
scale = gst_element_factory_make ("videoscale", "scale");
fail_unless (scale != NULL);
csp2 = gst_element_factory_make ("ffmpegcolorspace", "csp2");
fail_unless (csp2 != NULL);
sink = g_object_new (GST_TYPE_TEST_REVERSE_NEGOTIATION_SINK, NULL);
fail_unless (sink != NULL);
g_object_set (sink, "async", FALSE, NULL);
gst_bin_add_many (GST_BIN (pipeline), src, csp1, scale, csp2, sink, NULL);
fail_unless (gst_element_link_pads_full (src, "src", csp1, "sink",
LINK_CHECK_FLAGS));
fail_unless (gst_element_link_pads_full (csp1, "src", scale, "sink",
LINK_CHECK_FLAGS));
fail_unless (gst_element_link_pads_full (scale, "src", csp2, "sink",
LINK_CHECK_FLAGS));
fail_unless (gst_element_link_pads_full (csp2, "src", sink, "sink",
LINK_CHECK_FLAGS));
loop = g_main_loop_new (NULL, FALSE);
bus = gst_element_get_bus (pipeline);
fail_unless (bus != NULL);
gst_bus_add_signal_watch (bus);
g_signal_connect (bus, "message",
G_CALLBACK (_test_reverse_negotiation_message), loop);
gst_object_unref (bus);
fail_unless (gst_element_set_state (pipeline,
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS);
g_main_loop_run (loop);
fail_unless (gst_element_set_state (pipeline,
GST_STATE_NULL) == GST_STATE_CHANGE_SUCCESS);
gst_object_unref (pipeline);
g_main_loop_unref (loop);
}
GST_END_TEST;
static Suite *
videoscale_suite (void)
{
@ -552,6 +785,7 @@ videoscale_suite (void)
tcase_add_test (tc_chain, test_upscale_1x240_640x480_method_1);
tcase_add_test (tc_chain, test_upscale_1x240_640x480_method_2);
tcase_add_test (tc_chain, test_negotiation);
tcase_add_test (tc_chain, test_reverse_negotiation);
return s;
}