upload tizen1.0 source
[framework/multimedia/gstreamer0.10-ffmpeg.git] / tests / check / elements / ffdec_adpcm.c
1 /* GStreamer unit tests for ffdec_adpcm
2  *
3  * Copyright (C) 2009 Tim-Philipp Müller  <tim centricular net>
4  *
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.
9  *
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.
14  *
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.
19  */
20
21 #include <gst/check/gstcheck.h>
22
23 #include <gst/gst.h>
24
25 static void
26 pad_added_cb (GstElement * decodebin, GstPad * pad, GstBin * pipeline)
27 {
28   GstElement *sink;
29
30   GST_INFO_OBJECT (pad, "got pad");
31
32   sink = gst_bin_get_by_name (pipeline, "fakesink");
33   fail_unless (gst_element_link (decodebin, sink));
34   gst_object_unref (sink);
35
36   gst_element_set_state (sink, GST_STATE_PAUSED);
37 }
38
39 static GstBusSyncReply
40 error_cb (GstBus * bus, GstMessage * msg, gpointer user_data)
41 {
42   if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR) {
43     const gchar *file = (const gchar *) user_data;
44     GError *err = NULL;
45     gchar *dbg = NULL;
46
47     gst_message_parse_error (msg, &err, &dbg);
48     g_error ("ERROR for %s: %s\n%s\n", file, err->message, dbg);
49   }
50
51   return GST_BUS_PASS;
52 }
53
54 static gboolean
55 pad_check_get_range (GstPad * pad)
56 {
57   return FALSE;
58 }
59
60 static gboolean
61 decode_file (const gchar * file, gboolean push_mode)
62 {
63   GstStateChangeReturn state_ret;
64   GstElement *sink, *src, *dec, *pipeline;
65   GstMessage *msg;
66   GstBus *bus;
67   gchar *path;
68
69   pipeline = gst_pipeline_new ("pipeline");
70   fail_unless (pipeline != NULL, "Failed to create pipeline!");
71
72   src = gst_element_factory_make ("filesrc", "filesrc");
73   fail_unless (src != NULL, "Failed to create filesrc!");
74
75   if (push_mode) {
76     GstPad *pad = gst_element_get_static_pad (src, "src");
77
78     /* KIDS: don't do this at home! */
79     gst_pad_set_checkgetrange_function (pad, pad_check_get_range);
80     gst_object_unref (pad);
81   }
82
83   dec = gst_element_factory_make ("decodebin2", "decodebin2");
84   fail_unless (dec != NULL, "Failed to create decodebin2!");
85
86   sink = gst_element_factory_make ("fakesink", "fakesink");
87   fail_unless (sink != NULL, "Failed to create fakesink!");
88
89   bus = gst_element_get_bus (pipeline);
90
91   /* kids, don't use a sync handler for this at home, really; we do because
92    * we just want to abort and nothing else */
93   gst_bus_set_sync_handler (bus, error_cb, (gpointer) file);
94
95   gst_bin_add_many (GST_BIN (pipeline), src, dec, sink, NULL);
96   gst_element_link_many (src, dec, NULL);
97
98   path = g_build_filename (GST_TEST_FILES_PATH, file, NULL);
99   GST_LOG ("reading file '%s'", path);
100   g_object_set (src, "location", path, NULL);
101
102   /* can't link uridecodebin and sink yet, do that later */
103   g_signal_connect (dec, "pad-added", G_CALLBACK (pad_added_cb), pipeline);
104
105   state_ret = gst_element_set_state (pipeline, GST_STATE_PAUSED);
106   fail_unless (state_ret != GST_STATE_CHANGE_FAILURE);
107
108   if (state_ret == GST_STATE_CHANGE_ASYNC) {
109     GST_LOG ("waiting for pipeline to reach PAUSED state");
110     state_ret = gst_element_get_state (pipeline, NULL, NULL, -1);
111     fail_unless_equals_int (state_ret, GST_STATE_CHANGE_SUCCESS);
112   }
113
114   state_ret = gst_element_set_state (pipeline, GST_STATE_PLAYING);
115   fail_unless (state_ret != GST_STATE_CHANGE_FAILURE);
116
117   GST_LOG ("PAUSED, let's decode");
118   msg = gst_bus_timed_pop_filtered (bus, 10 * GST_SECOND, GST_MESSAGE_EOS);
119   GST_LOG ("Done, got EOS message");
120   fail_unless (msg != NULL);
121   gst_message_unref (msg);
122   gst_object_unref (bus);
123
124   fail_unless_equals_int (gst_element_set_state (pipeline, GST_STATE_NULL),
125       GST_STATE_CHANGE_SUCCESS);
126   gst_object_unref (pipeline);
127
128   g_free (path);
129
130   return TRUE;
131 }
132
133 static void
134 run_check_for_file (const gchar * filename)
135 {
136   gboolean ret;
137
138   /* first, pull-based */
139   ret = decode_file (filename, FALSE);
140   fail_unless (ret == TRUE, "Failed to decode '%s' (pull mode)", filename);
141
142   /* first, pull-based */
143   ret = decode_file (filename, TRUE);
144   fail_unless (ret == TRUE, "Failed to decode '%s' (push mode)", filename);
145 }
146
147 GST_START_TEST (test_low_sample_rate_adpcm)
148 {
149   if (!gst_default_registry_check_feature_version ("wavparse", 0, 10, 0) ||
150       !gst_default_registry_check_feature_version ("decodebin2", 0, 10, 0)) {
151     g_printerr ("skipping test_low_sample_rate_adpcm: required element "
152         "wavparse or element decodebin2 not found\n");
153     return;
154   }
155
156   run_check_for_file ("591809.wav");
157 }
158
159 GST_END_TEST;
160
161 static Suite *
162 ffdec_adpcm_suite (void)
163 {
164   Suite *s = suite_create ("ffdec_adpcm");
165   TCase *tc_chain = tcase_create ("general");
166
167   suite_add_tcase (s, tc_chain);
168   tcase_add_test (tc_chain, test_low_sample_rate_adpcm);
169
170   return s;
171 }
172
173 GST_CHECK_MAIN (ffdec_adpcm)