5 #define TEST_RUNTIME 120.0 /* how long to run the test, in seconds */
8 play_file (const gchar * bin, const gint delay, const gchar * uri)
10 GstStateChangeReturn sret;
15 play = gst_element_factory_make (bin, "playbin");
17 g_object_set (play, "uri", uri, NULL);
18 g_printerr ("Playing %s\n", uri);
19 sret = gst_element_set_state (play, GST_STATE_PLAYING);
20 if (sret != GST_STATE_CHANGE_ASYNC && sret != GST_STATE_CHANGE_SUCCESS) {
21 g_printerr ("ERROR: state change failed, sret=%d\n", sret);
25 wait_nanosecs = g_random_int_range (0, GST_MSECOND * delay);
26 msg = gst_bus_poll (GST_ELEMENT_BUS (play),
27 GST_MESSAGE_ERROR | GST_MESSAGE_EOS, wait_nanosecs);
29 switch (GST_MESSAGE_TYPE (msg)) {
30 case GST_MESSAGE_ERROR:
35 gst_message_parse_error (msg, &gerror, &debug);
36 gst_object_default_error (GST_MESSAGE_SRC (msg), gerror, debug);
37 g_error_free (gerror);
42 g_printerr ("Got EOS\n");
45 g_printerr ("Got unexpected %s messge\n", GST_MESSAGE_TYPE_NAME (msg));
48 gst_message_unref (msg);
52 /* on to the next one */
56 gst_element_set_state (play, GST_STATE_NULL);
57 gst_object_unref (play);
61 check_arg (GPtrArray * files, const gchar * arg)
65 if ((dir = g_dir_open (arg, 0, NULL))) {
68 while ((entry = g_dir_read_name (dir))) {
71 path = g_strconcat (arg, G_DIR_SEPARATOR_S, entry, NULL);
72 check_arg (files, path);
78 } else if (g_file_test (arg, G_FILE_TEST_EXISTS)) {
79 /* hack: technically an URI is not just file:// + path, but it'll do here */
80 g_ptr_array_add (files, g_strdup_printf ("file://%s", arg));
85 main (int argc, char **argv)
94 GOptionEntry options[] = {
95 {"bin", '\000', 0, G_OPTION_ARG_STRING, &bin, "playbin factory name", NULL},
96 {"runtime", '\000', 0, G_OPTION_ARG_INT, &run, "maximum play time (ms)",
98 {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &args, NULL},
103 #if !GLIB_CHECK_VERSION (2, 31, 0)
104 if (!g_thread_supported ())
105 g_thread_init (NULL);
108 ctx = g_option_context_new ("FILES OR DIRECTORIES WITH AUDIO FILES");
109 g_option_context_add_main_entries (ctx, options, NULL);
110 g_option_context_add_group (ctx, gst_init_get_option_group ());
111 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
112 g_print ("Error initializing: %s\n", GST_STR_NULL (err->message));
115 g_option_context_free (ctx);
118 bin = g_strdup ("playbin");
120 if (strcmp (bin, "playbin") && strcmp (bin, "playbin2")) {
121 g_print ("Please provide a valid playbin argument; playbin | playbin2");
124 if (args == NULL || *args == NULL) {
125 g_print ("Please provide one or more directories with audio files\n\n");
129 files = g_ptr_array_new ();
131 num = g_strv_length (args);
132 for (i = 0; i < num; ++i) {
133 if (g_path_is_absolute (args[i])) {
134 check_arg (files, args[i]);
136 g_warning ("Argument '%s' is not an absolute file path", args[i]);
140 if (files->len == 0) {
141 g_print ("Did not find any files\n\n");
145 timer = g_timer_new ();
147 while (g_timer_elapsed (timer, NULL) < TEST_RUNTIME) {
150 idx = g_random_int_range (0, files->len);
151 play_file (bin, run, (const gchar *) g_ptr_array_index (files, idx));
156 g_timer_destroy (timer);