fd66e51e1da5eb152af42d624a7db1aee529ec42
[platform/upstream/gstreamer.git] / tests / check / pipelines / vorbisdec.c
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., 59 Temple Place - Suite 330,
20  * Boston, MA 02111-1307, USA.
21  */
22
23 #include <gst/check/gstcheck.h>
24 #include <gst/check/gstbufferstraw.h>
25
26 #ifndef GST_DISABLE_PARSE
27
28 static GMainLoop *loop;
29 static gint messages = 0;
30
31 static void
32 element_message_cb (GstBus * bus, GstMessage * message, gpointer user_data)
33 {
34   gchar *s;
35
36   s = gst_structure_to_string (gst_message_get_structure (message));
37   GST_DEBUG ("Received message: %s", s);
38   g_free (s);
39
40   messages++;
41 }
42
43 static void
44 eos_message_cb (GstBus * bus, GstMessage * message, gpointer user_data)
45 {
46   GST_DEBUG ("Received eos");
47   g_main_loop_quit (loop);
48 }
49
50 GST_START_TEST (test_timestamps)
51 {
52   GstElement *pipeline;
53   gchar *pipe_str;
54   GstBus *bus;
55   GError *error = NULL;
56
57   /* allowing some tolerance permits audiodecoder to come up with
58    * perfect timestamps rather than sticking to upstream ts */
59   pipe_str = g_strdup_printf ("audiotestsrc num-buffers=100"
60       " ! audio/x-raw,rate=44100 ! audioconvert ! vorbisenc "
61       " ! vorbisdec tolerance=10000000 "
62       " ! identity check-imperfect-timestamp=TRUE ! fakesink");
63
64   pipeline = gst_parse_launch (pipe_str, &error);
65   fail_unless (pipeline != NULL, "Error parsing pipeline: %s",
66       error ? error->message : "(invalid error)");
67   g_free (pipe_str);
68
69   bus = gst_element_get_bus (pipeline);
70   fail_if (bus == NULL);
71   gst_bus_add_signal_watch (bus);
72   g_signal_connect (bus, "message::element", (GCallback) element_message_cb,
73       NULL);
74   g_signal_connect (bus, "message::eos", (GCallback) eos_message_cb, NULL);
75
76   gst_element_set_state (pipeline, GST_STATE_PLAYING);
77
78   /* run until we receive EOS */
79   loop = g_main_loop_new (NULL, FALSE);
80
81   g_main_loop_run (loop);
82
83   gst_element_set_state (pipeline, GST_STATE_NULL);
84
85   fail_if (messages > 0, "Received imperfect timestamp messages");
86   gst_object_unref (pipeline);
87 }
88
89 GST_END_TEST;
90 #endif /* #ifndef GST_DISABLE_PARSE */
91
92 static Suite *
93 vorbisenc_suite (void)
94 {
95   Suite *s = suite_create ("vorbisenc");
96   TCase *tc_chain = tcase_create ("general");
97
98   suite_add_tcase (s, tc_chain);
99 #ifndef GST_DISABLE_PARSE
100   tcase_add_test (tc_chain, test_timestamps);
101 #endif
102
103   return s;
104 }
105
106 int
107 main (int argc, char **argv)
108 {
109   int nf;
110
111   Suite *s = vorbisenc_suite ();
112   SRunner *sr = srunner_create (s);
113
114   gst_check_init (&argc, &argv);
115
116   srunner_run_all (sr, CK_NORMAL);
117   nf = srunner_ntests_failed (sr);
118   srunner_free (sr);
119
120   return nf;
121 }