1 /* GStreamer
2 *
3 * unit test for vorbisdec
4 *
5 * Copyright (C) 2007 Thomas Vander Stichele <thomas at apestaart dot org>
6 *
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.
11 *
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.
16 *
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.
21 */
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include <gst/check/gstcheck.h>
27 #include <gst/check/gstbufferstraw.h>
28
29 #ifndef GST_DISABLE_PARSE
30
31 static GMainLoop *loop;
32 static gint messages = 0;
33
34 static void
element_message_cb(GstBus * bus,GstMessage * message,gpointer user_data)35 element_message_cb (GstBus * bus, GstMessage * message, gpointer user_data)
36 {
37 gchar *s;
38
39 s = gst_structure_to_string (gst_message_get_structure (message));
40 GST_DEBUG ("Received message: %s", s);
41 g_free (s);
42
43 messages++;
44 }
45
46 static void
eos_message_cb(GstBus * bus,GstMessage * message,gpointer user_data)47 eos_message_cb (GstBus * bus, GstMessage * message, gpointer user_data)
48 {
49 GST_DEBUG ("Received eos");
50 g_main_loop_quit (loop);
51 }
52
GST_START_TEST(test_timestamps)53 GST_START_TEST (test_timestamps)
54 {
55 GstElement *pipeline;
56 gchar *pipe_str;
57 GstBus *bus;
58 GError *error = NULL;
59
60 /* allowing some tolerance permits audiodecoder to come up with
61 * perfect timestamps rather than sticking to upstream ts */
62 pipe_str = g_strdup_printf ("audiotestsrc num-buffers=100"
63 " ! audio/x-raw,rate=44100 ! audioconvert ! vorbisenc "
64 " ! vorbisdec tolerance=10000000 "
65 " ! identity check-imperfect-timestamp=TRUE ! fakesink");
66
67 pipeline = gst_parse_launch (pipe_str, &error);
68 fail_unless (pipeline != NULL, "Error parsing pipeline: %s",
69 error ? error->message : "(invalid error)");
70 g_free (pipe_str);
71
72 bus = gst_element_get_bus (pipeline);
73 fail_if (bus == NULL);
74 gst_bus_add_signal_watch (bus);
75 g_signal_connect (bus, "message::element", (GCallback) element_message_cb,
76 NULL);
77 g_signal_connect (bus, "message::eos", (GCallback) eos_message_cb, NULL);
78
79 gst_element_set_state (pipeline, GST_STATE_PLAYING);
80
81 /* run until we receive EOS */
82 loop = g_main_loop_new (NULL, FALSE);
83
84 g_main_loop_run (loop);
85 g_main_loop_unref (loop);
86
87 gst_element_set_state (pipeline, GST_STATE_NULL);
88
89 gst_bus_remove_signal_watch (bus);
90 gst_object_unref (bus);
91
92 fail_if (messages > 0, "Received imperfect timestamp messages");
93 gst_object_unref (pipeline);
94 }
95
96 GST_END_TEST;
97 #endif /* #ifndef GST_DISABLE_PARSE */
98
99 static Suite *
vorbisdec_suite(void)100 vorbisdec_suite (void)
101 {
102 Suite *s = suite_create ("vorbisdec");
103 TCase *tc_chain = tcase_create ("general");
104
105 suite_add_tcase (s, tc_chain);
106 #ifndef GST_DISABLE_PARSE
107 tcase_add_test (tc_chain, test_timestamps);
108 #endif
109
110 return s;
111 }
112
113 GST_CHECK_MAIN (vorbisdec);
114