3 #define TEST_RUNTIME 120.0 /* how long to run the test, in seconds */
6 play_file (const gchar * uri)
8 GstStateChangeReturn sret;
13 play = gst_element_factory_make ("playbin", "playbin");
15 g_object_set (play, "uri", uri, NULL);
16 sret = gst_element_set_state (play, GST_STATE_PLAYING);
17 if (sret != GST_STATE_CHANGE_ASYNC) {
18 g_printerr ("ERROR: state change failed, sret=%d\n", sret);
22 wait_nanosecs = g_random_int_range (0, GST_SECOND / 10);
23 msg = gst_bus_poll (GST_ELEMENT_BUS (play),
24 GST_MESSAGE_ERROR | GST_MESSAGE_EOS, wait_nanosecs);
26 g_printerr ("Got %s messge\n", GST_MESSAGE_TYPE_NAME (msg));
27 gst_message_unref (msg);
31 /* on to the next one */
35 gst_element_set_state (play, GST_STATE_NULL);
39 check_arg (GPtrArray * files, const gchar * arg)
43 if ((dir = g_dir_open (arg, 0, NULL))) {
46 while ((entry = g_dir_read_name (dir))) {
49 path = g_strconcat (arg, G_DIR_SEPARATOR_S, entry, NULL);
50 check_arg (files, path);
56 } else if (g_file_test (arg, G_FILE_TEST_EXISTS)) {
57 /* hack: technically an URI is not just file:// + path, but it'll do here */
58 g_ptr_array_add (files, g_strdup_printf ("file://%s", arg));
63 main (int argc, char **argv)
70 GOptionEntry options[] = {
71 {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &args, NULL},
76 if (!g_thread_supported ())
79 ctx = g_option_context_new ("FILES OR DIRECTORIES WITH AUDIO FILES");
80 g_option_context_add_main_entries (ctx, options, NULL);
81 g_option_context_add_group (ctx, gst_init_get_option_group ());
82 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
83 g_print ("Error initializing: %s\n", GST_STR_NULL (err->message));
86 g_option_context_free (ctx);
88 if (args == NULL || *args == NULL) {
89 g_print ("Please provide one or more directories with audio files\n\n");
93 files = g_ptr_array_new ();
95 num = g_strv_length (args);
96 for (i = 0; i < num; ++i) {
97 if (g_path_is_absolute (args[i])) {
98 check_arg (files, args[i]);
100 g_warning ("Argument '%s' is not an absolute file path", args[i]);
104 if (files->len == 0) {
105 g_print ("Did not find any files\n\n");
109 timer = g_timer_new ();
111 while (g_timer_elapsed (timer, NULL) < TEST_RUNTIME) {
114 idx = g_random_int_range (0, files->len);
115 play_file ((const gchar *) g_ptr_array_index (files, idx));
119 g_timer_destroy (timer);