3 * Copyright (c) 2010 Sebastian Dröge <sebastian.droege@collabora.co.uk>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 #include <gst/check/gstcheck.h>
23 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
26 GST_STATIC_CAPS ("video/x-vp8, "
27 "width = (int) [1, MAX], "
28 "height = (int) [1, MAX], " "framerate = (fraction) [0, MAX]"));
30 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
33 GST_STATIC_CAPS ("video/x-raw-yuv, "
34 "format = (fourcc) I420, "
35 "width = (int) [1, MAX], "
36 "height = (int) [1, MAX], " "framerate = (fraction) [0, MAX]"));
38 static GstPad *sinkpad, *srcpad;
41 setup_vp8enc (const gchar * src_caps_str)
44 GstCaps *srccaps = NULL;
48 srccaps = gst_caps_from_string (src_caps_str);
49 fail_unless (srccaps != NULL);
52 vp8enc = gst_check_setup_element ("vp8enc");
53 fail_unless (vp8enc != NULL);
54 srcpad = gst_check_setup_src_pad (vp8enc, &srctemplate, srccaps);
55 sinkpad = gst_check_setup_sink_pad (vp8enc, &sinktemplate, NULL);
56 gst_pad_set_active (srcpad, TRUE);
57 gst_pad_set_active (sinkpad, TRUE);
60 gst_element_set_bus (vp8enc, bus);
62 fail_unless (gst_element_set_state (vp8enc,
63 GST_STATE_PLAYING) != GST_STATE_CHANGE_FAILURE,
64 "could not set to playing");
67 gst_caps_unref (srccaps);
74 cleanup_vp8enc (GstElement * vp8enc)
78 /* Free parsed buffers */
79 gst_check_drop_buffers ();
81 bus = GST_ELEMENT_BUS (vp8enc);
82 gst_bus_set_flushing (bus, TRUE);
83 gst_object_unref (bus);
85 gst_pad_set_active (srcpad, FALSE);
86 gst_pad_set_active (sinkpad, FALSE);
87 gst_check_teardown_src_pad (vp8enc);
88 gst_check_teardown_sink_pad (vp8enc);
89 gst_check_teardown_element (vp8enc);
92 GST_START_TEST (test_encode_simple)
102 ("video/x-raw-yuv,format=(fourcc)I420,width=(int)320,height=(int)240,framerate=(fraction)25/1");
104 g_object_set (vp8enc, "max-latency", 5, NULL);
106 fail_unless (gst_pad_push_event (srcpad, gst_event_new_new_segment (FALSE,
107 1.0, GST_FORMAT_TIME, 0, gst_util_uint64_scale (20, GST_SECOND,
110 buffer = gst_buffer_new_and_alloc (320 * 240 + 2 * 160 * 120);
111 memset (GST_BUFFER_DATA (buffer), 0, GST_BUFFER_SIZE (buffer));
112 gst_buffer_set_caps (buffer, GST_PAD_CAPS (srcpad));
114 for (i = 0; i < 20; i++) {
115 GST_BUFFER_TIMESTAMP (buffer) = gst_util_uint64_scale (i, GST_SECOND, 25);
116 GST_BUFFER_DURATION (buffer) = gst_util_uint64_scale (1, GST_SECOND, 25);
117 fail_unless (gst_pad_push (srcpad, gst_buffer_ref (buffer)) == GST_FLOW_OK);
120 gst_buffer_unref (buffer);
122 /* Only 5 buffers are allowed to be queued now */
123 fail_unless (g_list_length (buffers) > 15);
125 fail_unless (gst_pad_push_event (srcpad, gst_event_new_eos ()));
128 /* All buffers must be there now */
129 fail_unless_equals_int (g_list_length (buffers), 20);
133 ("video/x-vp8,width=(int)320,height=(int)240,framerate=(fraction)25/1");
135 for (l = buffers, i = 0; l; l = l->next, i++) {
139 fail_if (GST_BUFFER_FLAG_IS_SET (buffer, GST_BUFFER_FLAG_DELTA_UNIT));
141 fail_unless_equals_uint64 (GST_BUFFER_TIMESTAMP (buffer),
142 gst_util_uint64_scale (i, GST_SECOND, 25));
143 fail_unless_equals_uint64 (GST_BUFFER_DURATION (buffer),
144 gst_util_uint64_scale (1, GST_SECOND, 25));
146 fail_unless (gst_caps_can_intersect (GST_BUFFER_CAPS (buffer), outcaps));
149 gst_caps_unref (outcaps);
151 cleanup_vp8enc (vp8enc);
159 Suite *s = suite_create ("vp8enc");
160 TCase *tc_chain = tcase_create ("general");
162 suite_add_tcase (s, tc_chain);
164 tcase_add_test (tc_chain, test_encode_simple);
169 GST_CHECK_MAIN (vp8enc);