jpegenc: Adds another test case

Adds a test for jpegenc to check that is possible to negotiate and
push buffers with different resolution one after another.

https://bugzilla.gnome.org/show_bug.cgi?id=637686
This commit is contained in:
Thiago Santos 2010-12-20 14:49:02 -03:00
parent dcbba0932d
commit dde7af4b9d
2 changed files with 91 additions and 0 deletions

View file

@ -202,6 +202,9 @@ elements_interleave_LDADD = $(GST_PLUGINS_BASE_LIBS) -lgstaudio-$(GST_MAJORMINOR
elements_imagefreeze_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(AM_CFLAGS)
elements_imagefreeze_LDADD = $(GST_BASE_LIBS) $(LDADD) -lgstvideo-$(GST_MAJORMINOR)
elements_jpegenc_CFLAGS = $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(AM_CFLAGS)
elements_jpegenc_LDADD = $(GST_BASE_LIBS) $(LDADD) -lgstapp-0.10
elements_level_LDADD = $(LDADD) $(LIBM)
elements_matroskamux_LDADD = $(GST_BASE_LIBS) $(LDADD) $(LIBM)

View file

@ -23,11 +23,13 @@
#include <unistd.h>
#include <gst/check/gstcheck.h>
#include <gst/app/gstappsink.h>
/* For ease of programming we use globals to keep refs for our floating
* sink pads we create; otherwise we always have to do get_pad,
* get_peer, and then remove references in every test function */
static GstPad *mysinkpad;
static GstPad *mysrcpad;
#define JPEG_CAPS_STRING "image/jpeg"
@ -52,6 +54,12 @@ GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_ALWAYS,
GST_STATIC_CAPS (JPEG_CAPS_RESTRICTIVE));
static GstStaticPadTemplate any_srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS_ANY);
static GstElement *
setup_jpegenc (GstStaticPadTemplate * sinktemplate)
{
@ -60,6 +68,8 @@ setup_jpegenc (GstStaticPadTemplate * sinktemplate)
GST_DEBUG ("setup_jpegenc");
jpegenc = gst_check_setup_element ("jpegenc");
mysinkpad = gst_check_setup_sink_pad (jpegenc, sinktemplate, NULL);
mysrcpad = gst_check_setup_src_pad (jpegenc, &any_srctemplate, NULL);
gst_pad_set_active (mysrcpad, TRUE);
gst_pad_set_active (mysinkpad, TRUE);
return jpegenc;
@ -71,11 +81,44 @@ cleanup_jpegenc (GstElement * jpegenc)
GST_DEBUG ("cleanup_jpegenc");
gst_element_set_state (jpegenc, GST_STATE_NULL);
gst_pad_set_active (mysrcpad, FALSE);
gst_pad_set_active (mysinkpad, FALSE);
gst_check_teardown_sink_pad (jpegenc);
gst_check_teardown_src_pad (jpegenc);
gst_check_teardown_element (jpegenc);
}
static GstBuffer *
create_video_buffer (GstCaps * caps)
{
GstElement *pipeline;
GstElement *cf;
GstElement *sink;
GstBuffer *buffer;
pipeline =
gst_parse_launch
("videotestsrc num-buffers=1 ! capsfilter name=cf ! appsink name=sink",
NULL);
g_assert (pipeline != NULL);
cf = gst_bin_get_by_name (GST_BIN (pipeline), "cf");
sink = gst_bin_get_by_name (GST_BIN (pipeline), "sink");
g_object_set (G_OBJECT (cf), "caps", caps, NULL);
gst_element_set_state (pipeline, GST_STATE_PLAYING);
buffer = gst_app_sink_pull_buffer (GST_APP_SINK (sink));
gst_element_set_state (pipeline, GST_STATE_NULL);
gst_object_unref (pipeline);
gst_object_unref (sink);
gst_object_unref (cf);
return buffer;
}
GST_START_TEST (test_jpegenc_getcaps)
{
GstElement *jpegenc;
@ -129,6 +172,50 @@ GST_START_TEST (test_jpegenc_getcaps)
GST_END_TEST;
GST_START_TEST (test_jpegenc_different_caps)
{
GstElement *jpegenc;
GstBuffer *buffer;
GstCaps *caps;
GstCaps *allowed_caps;
/* now use a more restricted one and check the resulting caps */
jpegenc = setup_jpegenc (&any_sinktemplate);
gst_element_set_state (jpegenc, GST_STATE_PLAYING);
/* push first buffer with 800x600 resolution */
caps = gst_caps_new_simple ("video/x-raw-yuv", "width", G_TYPE_INT,
800, "height", G_TYPE_INT, 600, "framerate",
GST_TYPE_FRACTION, 1, 1, "format", GST_TYPE_FOURCC,
GST_MAKE_FOURCC ('I', '4', '2', '0'), NULL);
buffer = create_video_buffer (caps);
gst_caps_unref (caps);
fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK);
/* check the allowed caps to see if a second buffer with a different
* caps could be negotiated */
allowed_caps = gst_pad_get_allowed_caps (mysrcpad);
/* the caps we want to negotiate to */
caps = gst_caps_new_simple ("video/x-raw-yuv", "width", G_TYPE_INT,
640, "height", G_TYPE_INT, 480, "framerate",
GST_TYPE_FRACTION, 1, 1, "format", GST_TYPE_FOURCC,
GST_MAKE_FOURCC ('I', '4', '2', '0'), NULL);
fail_unless (gst_caps_can_intersect (allowed_caps, caps));
/* push second buffer with 640x480 resolution */
buffer = create_video_buffer (caps);
gst_caps_unref (caps);
fail_unless (gst_pad_push (mysrcpad, buffer) == GST_FLOW_OK);
gst_caps_unref (allowed_caps);
gst_element_set_state (jpegenc, GST_STATE_NULL);
cleanup_jpegenc (jpegenc);
}
GST_END_TEST;
static Suite *
jpegenc_suite (void)
{
@ -137,6 +224,7 @@ jpegenc_suite (void)
suite_add_tcase (s, tc_chain);
tcase_add_test (tc_chain, test_jpegenc_getcaps);
tcase_add_test (tc_chain, test_jpegenc_different_caps);
return s;
}