tests: port x264enc unit test to 0.11

Well, it compiles now at least.
This commit is contained in:
Tim-Philipp Müller 2011-11-12 20:33:03 +00:00
parent 115e7cbd7f
commit 4f3345531f

View file

@ -29,8 +29,8 @@
* get_peer, and then remove references in every test function */ * get_peer, and then remove references in every test function */
static GstPad *mysrcpad, *mysinkpad; static GstPad *mysrcpad, *mysinkpad;
#define VIDEO_CAPS_STRING "video/x-raw-yuv, " \ #define VIDEO_CAPS_STRING "video/x-raw, " \
"format = (fourcc) I420, " \ "format = (string) I420, " \
"width = (int) 384, " \ "width = (int) 384, " \
"height = (int) 288, " \ "height = (int) 288, " \
"framerate = (fraction) 25/1" "framerate = (fraction) 25/1"
@ -106,10 +106,11 @@ check_caps (GstCaps * caps)
fail_unless (GST_VALUE_HOLDS_BUFFER (avcc)); fail_unless (GST_VALUE_HOLDS_BUFFER (avcc));
buf = gst_value_get_buffer (avcc); buf = gst_value_get_buffer (avcc);
fail_unless (buf != NULL); fail_unless (buf != NULL);
data = GST_BUFFER_DATA (buf); data = gst_buffer_map (buf, NULL, NULL, GST_MAP_READ);
fail_unless_equals_int (data[0], 1); fail_unless_equals_int (data[0], 1);
/* should be either baseline, main profile or extended profile */ /* should be either baseline, main profile or extended profile */
fail_unless (data[1] == 0x42 || data[1] == 0x4D || data[1] == 0x58); fail_unless (data[1] == 0x42 || data[1] == 0x4D || data[1] == 0x58);
gst_buffer_unmap (buf, (gpointer) data, -1);
} else if (strcmp (stream_format, "byte-stream") == 0) { } else if (strcmp (stream_format, "byte-stream") == 0) {
fail_if (gst_structure_get_value (s, "codec_data") != NULL); fail_if (gst_structure_get_value (s, "codec_data") != NULL);
} else { } else {
@ -122,6 +123,8 @@ GST_START_TEST (test_video_pad)
GstElement *x264enc; GstElement *x264enc;
GstBuffer *inbuffer, *outbuffer; GstBuffer *inbuffer, *outbuffer;
GstCaps *caps; GstCaps *caps;
guint8 *data;
gsize size;
int i, num_buffers; int i, num_buffers;
x264enc = setup_x264enc (); x264enc = setup_x264enc ();
@ -129,13 +132,16 @@ GST_START_TEST (test_video_pad)
GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS, GST_STATE_PLAYING) == GST_STATE_CHANGE_SUCCESS,
"could not set to playing"); "could not set to playing");
caps = gst_caps_from_string (VIDEO_CAPS_STRING);
fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_caps (caps)));
gst_caps_unref (caps);
/* corresponds to I420 buffer for the size mentioned in the caps */ /* corresponds to I420 buffer for the size mentioned in the caps */
inbuffer = gst_buffer_new_and_alloc (384 * 288 * 3 / 2); inbuffer = gst_buffer_new_and_alloc (384 * 288 * 3 / 2);
/* makes valgrind's memcheck happier */ /* makes valgrind's memcheck happier */
memset (GST_BUFFER_DATA (inbuffer), 0, GST_BUFFER_SIZE (inbuffer)); data = gst_buffer_map (inbuffer, &size, NULL, GST_MAP_WRITE);
caps = gst_caps_from_string (VIDEO_CAPS_STRING); memset (data, 0, size);
gst_buffer_set_caps (inbuffer, caps); gst_buffer_unmap (inbuffer, data, size);
gst_caps_unref (caps);
GST_BUFFER_TIMESTAMP (inbuffer) = 0; GST_BUFFER_TIMESTAMP (inbuffer) = 0;
ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1); ASSERT_BUFFER_REFCOUNT (inbuffer, "inbuffer", 1);
fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
@ -146,6 +152,15 @@ GST_START_TEST (test_video_pad)
num_buffers = g_list_length (buffers); num_buffers = g_list_length (buffers);
fail_unless (num_buffers == 1); fail_unless (num_buffers == 1);
/* check output caps */
{
GstCaps *outcaps;
outcaps = gst_pad_get_current_caps (mysinkpad);
check_caps (outcaps);
gst_caps_unref (outcaps);
}
/* clean up buffers */ /* clean up buffers */
for (i = 0; i < num_buffers; ++i) { for (i = 0; i < num_buffers; ++i) {
outbuffer = GST_BUFFER (buffers->data); outbuffer = GST_BUFFER (buffers->data);
@ -155,10 +170,10 @@ GST_START_TEST (test_video_pad)
case 0: case 0:
{ {
gint nsize, npos, j, type, next_type; gint nsize, npos, j, type, next_type;
guint8 *data = GST_BUFFER_DATA (outbuffer); const guint8 *data;
gint size = GST_BUFFER_SIZE (outbuffer); gsize size;
check_caps (GST_BUFFER_CAPS (outbuffer)); data = gst_buffer_map (outbuffer, &size, NULL, GST_MAP_READ);
npos = 0; npos = 0;
j = 0; j = 0;
@ -197,6 +212,9 @@ GST_START_TEST (test_video_pad)
default: default:
break; break;
} }
gst_buffer_unmap (outbuffer, (gpointer) data, size);
buffers = g_list_remove (buffers, outbuffer); buffers = g_list_remove (buffers, outbuffer);
ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1); ASSERT_BUFFER_REFCOUNT (outbuffer, "outbuffer", 1);
@ -214,9 +232,12 @@ GST_END_TEST;
GstCaps *pad_caps; GstCaps *pad_caps;
GstCaps * GstCaps *
getcaps_test (GstPad * pad) getcaps_test (GstPad * pad, GstCaps * filter)
{ {
return gst_caps_ref (pad_caps); if (filter == NULL)
return gst_caps_ref (pad_caps);
else
return gst_caps_intersect (pad_caps, filter);
} }
GST_START_TEST (test_profile_in_caps) GST_START_TEST (test_profile_in_caps)
@ -225,6 +246,7 @@ GST_START_TEST (test_profile_in_caps)
GstPad *srcpad; GstPad *srcpad;
GstPad *sinkpad; GstPad *sinkpad;
GstStructure *s; GstStructure *s;
GstCaps *caps;
pad_caps = gst_caps_from_string (MPEG_CAPS_STRING); pad_caps = gst_caps_from_string (MPEG_CAPS_STRING);
@ -238,8 +260,10 @@ GST_START_TEST (test_profile_in_caps)
fail_unless (gst_pad_set_caps (sinkpad, fail_unless (gst_pad_set_caps (sinkpad,
(GstCaps *) gst_pad_get_pad_template_caps (mysrcpad))); (GstCaps *) gst_pad_get_pad_template_caps (mysrcpad)));
s = gst_caps_get_structure (GST_PAD_CAPS (srcpad), 0); caps = gst_pad_get_current_caps (srcpad);
s = gst_caps_get_structure (caps, 0);
fail_unless (!g_strcmp0 (gst_structure_get_string (s, "profile"), "main")); fail_unless (!g_strcmp0 (gst_structure_get_string (s, "profile"), "main"));
gst_caps_unref (caps);
fail_unless (gst_element_set_state (x264enc, fail_unless (gst_element_set_state (x264enc,
GST_STATE_READY) == GST_STATE_CHANGE_SUCCESS, GST_STATE_READY) == GST_STATE_CHANGE_SUCCESS,
@ -250,9 +274,12 @@ GST_START_TEST (test_profile_in_caps)
"could not set to playing"); "could not set to playing");
fail_unless (gst_pad_set_caps (sinkpad, fail_unless (gst_pad_set_caps (sinkpad,
(GstCaps *) gst_pad_get_pad_template_caps (mysrcpad))); (GstCaps *) gst_pad_get_pad_template_caps (mysrcpad)));
s = gst_caps_get_structure (GST_PAD_CAPS (srcpad), 0);
caps = gst_pad_get_current_caps (srcpad);
s = gst_caps_get_structure (caps, 0);
fail_unless (!g_strcmp0 (gst_structure_get_string (s, "profile"), fail_unless (!g_strcmp0 (gst_structure_get_string (s, "profile"),
"constrained-baseline")); "constrained-baseline"));
gst_caps_unref (caps);
fail_unless (gst_element_set_state (x264enc, fail_unless (gst_element_set_state (x264enc,
GST_STATE_READY) == GST_STATE_CHANGE_SUCCESS, GST_STATE_READY) == GST_STATE_CHANGE_SUCCESS,
@ -263,8 +290,11 @@ GST_START_TEST (test_profile_in_caps)
"could not set to playing"); "could not set to playing");
fail_unless (gst_pad_set_caps (sinkpad, fail_unless (gst_pad_set_caps (sinkpad,
(GstCaps *) gst_pad_get_pad_template_caps (mysrcpad))); (GstCaps *) gst_pad_get_pad_template_caps (mysrcpad)));
s = gst_caps_get_structure (GST_PAD_CAPS (srcpad), 0);
caps = gst_pad_get_current_caps (srcpad);
s = gst_caps_get_structure (caps, 0);
fail_unless (!g_strcmp0 (gst_structure_get_string (s, "profile"), "high")); fail_unless (!g_strcmp0 (gst_structure_get_string (s, "profile"), "high"));
gst_caps_unref (caps);
fail_unless (gst_element_set_state (x264enc, fail_unless (gst_element_set_state (x264enc,
GST_STATE_READY) == GST_STATE_CHANGE_SUCCESS, GST_STATE_READY) == GST_STATE_CHANGE_SUCCESS,
@ -275,8 +305,11 @@ GST_START_TEST (test_profile_in_caps)
"could not set to playing"); "could not set to playing");
fail_unless (gst_pad_set_caps (sinkpad, fail_unless (gst_pad_set_caps (sinkpad,
(GstCaps *) gst_pad_get_pad_template_caps (mysrcpad))); (GstCaps *) gst_pad_get_pad_template_caps (mysrcpad)));
s = gst_caps_get_structure (GST_PAD_CAPS (srcpad), 0);
caps = gst_pad_get_current_caps (srcpad);
s = gst_caps_get_structure (caps, 0);
fail_unless (!g_strcmp0 (gst_structure_get_string (s, "profile"), "main")); fail_unless (!g_strcmp0 (gst_structure_get_string (s, "profile"), "main"));
gst_caps_unref (caps);
s = gst_caps_get_structure (pad_caps, 0); s = gst_caps_get_structure (pad_caps, 0);
gst_structure_set (s, "profile", G_TYPE_STRING, "constrained-baseline", NULL); gst_structure_set (s, "profile", G_TYPE_STRING, "constrained-baseline", NULL);
@ -288,9 +321,12 @@ GST_START_TEST (test_profile_in_caps)
"could not set to playing"); "could not set to playing");
fail_unless (gst_pad_set_caps (sinkpad, fail_unless (gst_pad_set_caps (sinkpad,
(GstCaps *) gst_pad_get_pad_template_caps (mysrcpad))); (GstCaps *) gst_pad_get_pad_template_caps (mysrcpad)));
s = gst_caps_get_structure (GST_PAD_CAPS (srcpad), 0);
caps = gst_pad_get_current_caps (srcpad);
s = gst_caps_get_structure (caps, 0);
fail_unless (!g_strcmp0 (gst_structure_get_string (s, "profile"), fail_unless (!g_strcmp0 (gst_structure_get_string (s, "profile"),
"constrained-baseline")); "constrained-baseline"));
gst_caps_unref (caps);
s = gst_caps_get_structure (pad_caps, 0); s = gst_caps_get_structure (pad_caps, 0);
gst_structure_set (s, "profile", G_TYPE_STRING, "high", NULL); gst_structure_set (s, "profile", G_TYPE_STRING, "high", NULL);
@ -302,8 +338,11 @@ GST_START_TEST (test_profile_in_caps)
"could not set to playing"); "could not set to playing");
fail_unless (gst_pad_set_caps (sinkpad, fail_unless (gst_pad_set_caps (sinkpad,
(GstCaps *) gst_pad_get_pad_template_caps (mysrcpad))); (GstCaps *) gst_pad_get_pad_template_caps (mysrcpad)));
s = gst_caps_get_structure (GST_PAD_CAPS (srcpad), 0);
caps = gst_pad_get_current_caps (srcpad);
s = gst_caps_get_structure (caps, 0);
fail_unless (!g_strcmp0 (gst_structure_get_string (s, "profile"), "high")); fail_unless (!g_strcmp0 (gst_structure_get_string (s, "profile"), "high"));
gst_caps_unref (caps);
gst_object_unref (srcpad); gst_object_unref (srcpad);
gst_object_unref (sinkpad); gst_object_unref (sinkpad);