3 * Copyright (c) 2010 Sebastian Dröge <sebastian.droege@collabora.co.uk>
4 * Copyright (c) 2010 David Schleef <ds@schleef.org>
5 * Copyright (c) 2014 Thijs Vermeir <thijs.vermeir@barco.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
23 #include <gst/check/gstcheck.h>
25 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
28 GST_STATIC_CAPS ("video/x-h265, "
29 "width = (int) [1, MAX], "
30 "height = (int) [1, MAX], " "framerate = (fraction) [0, MAX]"));
32 static GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src",
35 GST_STATIC_CAPS ("video/x-raw, "
36 "format = (string) I420, "
37 "width = (int) [1, MAX], "
38 "height = (int) [1, MAX], " "framerate = (fraction) [0, MAX]"));
40 static GstPad *sinkpad, *srcpad;
43 setup_x265enc (const gchar * src_caps_str)
46 GstCaps *srccaps = NULL;
50 srccaps = gst_caps_from_string (src_caps_str);
51 fail_unless (srccaps != NULL);
54 x265enc = gst_check_setup_element ("x265enc");
55 fail_unless (x265enc != NULL);
56 srcpad = gst_check_setup_src_pad (x265enc, &srctemplate);
57 sinkpad = gst_check_setup_sink_pad (x265enc, &sinktemplate);
58 gst_pad_set_active (srcpad, TRUE);
59 gst_pad_set_active (sinkpad, TRUE);
61 gst_check_setup_events (srcpad, x265enc, srccaps, GST_FORMAT_TIME);
64 gst_element_set_bus (x265enc, bus);
66 fail_unless (gst_element_set_state (x265enc,
67 GST_STATE_PLAYING) != GST_STATE_CHANGE_FAILURE,
68 "could not set to playing");
71 gst_caps_unref (srccaps);
78 cleanup_x265enc (GstElement * x265enc)
82 /* Free parsed buffers */
83 gst_check_drop_buffers ();
85 bus = GST_ELEMENT_BUS (x265enc);
86 gst_bus_set_flushing (bus, TRUE);
87 gst_object_unref (bus);
89 gst_pad_set_active (srcpad, FALSE);
90 gst_pad_set_active (sinkpad, FALSE);
91 gst_check_teardown_src_pad (x265enc);
92 gst_check_teardown_sink_pad (x265enc);
93 gst_check_teardown_element (x265enc);
96 GST_START_TEST (test_encode_simple)
102 GstCaps *outcaps, *sinkcaps;
107 ("video/x-raw,format=(string)I420,width=(int)320,height=(int)240,framerate=(fraction)25/1");
109 gst_segment_init (&seg, GST_FORMAT_TIME);
110 seg.stop = gst_util_uint64_scale (10, GST_SECOND, 25);
112 fail_unless (gst_pad_push_event (srcpad, gst_event_new_segment (&seg)));
114 buffer = gst_buffer_new_allocate (NULL, 320 * 240 + 2 * 160 * 120, NULL);
115 gst_buffer_memset (buffer, 0, 0, -1);
117 for (i = 0; i < 10; i++) {
118 GST_BUFFER_TIMESTAMP (buffer) = gst_util_uint64_scale (i, GST_SECOND, 25);
119 GST_BUFFER_DURATION (buffer) = gst_util_uint64_scale (1, GST_SECOND, 25);
120 fail_unless (gst_pad_push (srcpad, gst_buffer_ref (buffer)) == GST_FLOW_OK);
123 gst_buffer_unref (buffer);
125 fail_unless (gst_pad_push_event (srcpad, gst_event_new_eos ()));
127 /* All buffers must be there now */
128 fail_unless_equals_int (g_list_length (buffers), 10);
132 ("video/x-h265,width=(int)320,height=(int)240,framerate=(fraction)25/1");
134 for (l = buffers, i = 0; l; l = l->next, i++) {
137 fail_unless_equals_uint64 (GST_BUFFER_DURATION (buffer),
138 gst_util_uint64_scale (1, GST_SECOND, 25));
140 sinkcaps = gst_pad_get_current_caps (sinkpad);
141 fail_unless (gst_caps_can_intersect (sinkcaps, outcaps));
142 gst_caps_unref (sinkcaps);
145 gst_caps_unref (outcaps);
147 cleanup_x265enc (x265enc);
155 Suite *s = suite_create ("x265enc");
156 TCase *tc_chain = tcase_create ("general");
158 suite_add_tcase (s, tc_chain);
160 tcase_add_test (tc_chain, test_encode_simple);
165 GST_CHECK_MAIN (x265enc);