initial import
[gst-scaletempo-demo-rj.git] / src / main.c
blob5ad0df08d8dc0c283f0ee888c9eae3507e003020
1 /* Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
2 *
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom the
8 * Software is furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice shall be included in
11 * all copies or substantial portions of the Software.
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19 * DEALINGS IN THE SOFTWARE.
21 * Alternatively, the contents of this file may be used under the
22 * GNU Lesser General Public License Version 2.1 (the "LGPL"), in
23 * which case the following provisions apply instead of the ones
24 * mentioned above:
26 * This library is free software; you can redistribute it and/or
27 * modify it under the terms of the GNU Library General Public
28 * License as published by the Free Software Foundation; either
29 * version 2 of the License, or (at your option) any later version.
31 * This library is distributed in the hope that it will be useful,
32 * but WITHOUT ANY WARRANTY; without even the implied warranty of
33 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
34 * Library General Public License for more details.
36 * You should have received a copy of the GNU Library General Public
37 * License along with this library; if not, write to the
38 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
39 * Boston, MA 02111-1307, USA.
42 #ifdef HAVE_CONFIG_H
43 #include "config.h"
44 #endif
46 #include "gst-app.h"
48 static void
49 handle_file_or_directory (const gchar * filename)
51 GError *err = NULL;
52 GDir *dir;
53 gchar *uri;
55 if ((dir = g_dir_open (filename, 0, NULL))) {
56 const gchar *entry;
58 while ((entry = g_dir_read_name (dir))) {
59 gchar *path;
61 path = g_strconcat (filename, G_DIR_SEPARATOR_S, entry, NULL);
62 handle_file_or_directory (path);
63 g_free (path);
66 g_dir_close (dir);
67 return;
70 if (g_path_is_absolute (filename)) {
71 uri = g_filename_to_uri (filename, NULL, &err);
72 } else {
73 gchar *curdir, *absolute_path;
75 curdir = g_get_current_dir ();
76 absolute_path = g_strconcat ( curdir, G_DIR_SEPARATOR_S, filename, NULL);
77 uri = g_filename_to_uri (absolute_path, NULL, &err);
78 g_free (absolute_path);
79 g_free (curdir);
82 if (uri) {
83 /* great, we have a proper file:// URI, let's play it! */
84 play_uri (uri);
85 } else {
86 g_warning ("Failed to convert filename '%s' to URI: %s", filename,
87 err->message);
88 g_error_free (err);
91 g_free (uri);
94 int
95 main (int argc, char *argv[])
97 gchar **filenames = NULL;
98 const GOptionEntry entries[] = {
99 /* you can add your won command line options here */
100 { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames,
101 "Special option that collects any remaining arguments for us" },
102 { NULL, }
104 GOptionContext *ctx;
105 GError *err = NULL;
106 gint i, num;
108 /* Before calling any GLib or GStreamer function, we must initialise
109 * the GLib threading system */
110 if (!g_thread_supported())
111 g_thread_init (NULL);
113 ctx = g_option_context_new ("[FILE1] [FILE2] ...");
114 g_option_context_add_group (ctx, gst_init_get_option_group ());
115 g_option_context_add_main_entries (ctx, entries, NULL);
117 if (!g_option_context_parse (ctx, &argc, &argv, &err)) {
118 g_print ("Error initializing: %s\n", GST_STR_NULL (err->message));
119 return -1;
121 g_option_context_free (ctx);
123 if (filenames == NULL || *filenames == NULL) {
124 g_print ("Please specify a file to play\n\n");
125 return -1;
130 num = g_strv_length (filenames);
132 for (i = 0; i < num; ++i) {
133 handle_file_or_directory (filenames[i]);
136 g_strfreev (filenames);
138 return 0;