|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #include <gst/gst.h> |
|
18 #include <stdlib.h> |
|
19 |
|
20 #define TEST_RUNTIME 120.0 /* how long to run the test, in seconds */ |
|
21 |
|
22 static void |
|
23 play_file (const gchar * uri) |
|
24 { |
|
25 GstStateChangeReturn sret; |
|
26 GstMessage *msg; |
|
27 GstElement *play; |
|
28 guint wait_nanosecs; |
|
29 |
|
30 play = gst_element_factory_make ("playbin", "playbin"); |
|
31 |
|
32 g_object_set (play, "uri", uri, NULL); |
|
33 sret = gst_element_set_state (play, GST_STATE_PLAYING); |
|
34 if (sret != GST_STATE_CHANGE_ASYNC) { |
|
35 g_printerr ("ERROR: state change failed, sret=%d\n", sret); |
|
36 goto next; |
|
37 } |
|
38 |
|
39 wait_nanosecs = g_random_int_range (0, GST_SECOND / 10); |
|
40 msg = gst_bus_poll (GST_ELEMENT_BUS (play), |
|
41 GST_MESSAGE_ERROR | GST_MESSAGE_EOS, wait_nanosecs); |
|
42 if (msg) { |
|
43 g_printerr ("Got %s messge\n", GST_MESSAGE_TYPE_NAME (msg)); |
|
44 gst_message_unref (msg); |
|
45 goto next; |
|
46 } |
|
47 |
|
48 /* on to the next one */ |
|
49 g_print ("."); |
|
50 |
|
51 next: |
|
52 gst_element_set_state (play, GST_STATE_NULL); |
|
53 } |
|
54 |
|
55 static void |
|
56 check_arg (GPtrArray * files, const gchar * arg) |
|
57 { |
|
58 GDir *dir; |
|
59 |
|
60 if ((dir = g_dir_open (arg, 0, NULL))) { |
|
61 const gchar *entry; |
|
62 |
|
63 while ((entry = g_dir_read_name (dir))) { |
|
64 gchar *path; |
|
65 |
|
66 path = g_strconcat (arg, G_DIR_SEPARATOR_S, entry, NULL); |
|
67 check_arg (files, path); |
|
68 g_free (path); |
|
69 } |
|
70 |
|
71 g_dir_close (dir); |
|
72 return; |
|
73 } else if (g_file_test (arg, G_FILE_TEST_EXISTS)) { |
|
74 /* hack: technically an URI is not just file:// + path, but it'll do here */ |
|
75 g_ptr_array_add (files, g_strdup_printf ("file://%s", arg)); |
|
76 } |
|
77 } |
|
78 |
|
79 int |
|
80 main (int argc, char **argv) |
|
81 { |
|
82 GPtrArray *files; |
|
83 gchar **args = NULL; |
|
84 guint num, i; |
|
85 GError *err = NULL; |
|
86 GOptionContext *ctx; |
|
87 GOptionEntry options[] = { |
|
88 {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &args, NULL}, |
|
89 {NULL} |
|
90 }; |
|
91 GTimer *timer; |
|
92 |
|
93 if (!g_thread_supported ()) |
|
94 g_thread_init (NULL); |
|
95 |
|
96 ctx = g_option_context_new ("FILES OR DIRECTORIES WITH AUDIO FILES"); |
|
97 g_option_context_add_main_entries (ctx, options, NULL); |
|
98 g_option_context_add_group (ctx, gst_init_get_option_group ()); |
|
99 if (!g_option_context_parse (ctx, &argc, &argv, &err)) { |
|
100 g_print ("Error initializing: %s\n", GST_STR_NULL (err->message)); |
|
101 exit (1); |
|
102 } |
|
103 g_option_context_free (ctx); |
|
104 |
|
105 if (args == NULL || *args == NULL) { |
|
106 g_print ("Please provide one or more directories with audio files\n\n"); |
|
107 return 1; |
|
108 } |
|
109 |
|
110 files = g_ptr_array_new (); |
|
111 |
|
112 num = g_strv_length (args); |
|
113 for (i = 0; i < num; ++i) { |
|
114 if (g_path_is_absolute (args[i])) { |
|
115 check_arg (files, args[i]); |
|
116 } else { |
|
117 g_warning ("Argument '%s' is not an absolute file path", args[i]); |
|
118 } |
|
119 } |
|
120 |
|
121 if (files->len == 0) { |
|
122 g_print ("Did not find any files\n\n"); |
|
123 return 1; |
|
124 } |
|
125 |
|
126 timer = g_timer_new (); |
|
127 |
|
128 while (g_timer_elapsed (timer, NULL) < TEST_RUNTIME) { |
|
129 gint32 idx; |
|
130 |
|
131 idx = g_random_int_range (0, files->len); |
|
132 play_file ((const gchar *) g_ptr_array_index (files, idx)); |
|
133 } |
|
134 |
|
135 g_strfreev (args); |
|
136 g_timer_destroy (timer); |
|
137 |
|
138 return 0; |
|
139 } |