~ubuntu-branches/ubuntu/utopic/rhythmbox/utopic-proposed

« back to all changes in this revision

Viewing changes to metadata/monkey-media/monkey-media.c

Tags: upstream-0.9.2
ImportĀ upstreamĀ versionĀ 0.9.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*  monkey-sound
2
 
 *
3
 
 *  arch-tag: Implementation of main MonkeyMedia interface
4
 
 *
5
 
 *  Copyright (C) 2002 Jorn Baayen <jorn@nl.linux.org>
6
 
 *                     Marco Pesenti Gritti <marco@it.gnome.org>
7
 
 *                     Bastien Nocera <hadess@hadess.net>
8
 
 *                     Seth Nickell <snickell@stanford.edu>
9
 
 *
10
 
 *  This program is free software; you can redistribute it and/or modify
11
 
 *  it under the terms of the GNU General Public License as published by
12
 
 *  the Free Software Foundation; either version 2 of the License, or
13
 
 *  (at your option) any later version.
14
 
 *
15
 
 *  This program is distributed in the hope that it will be useful,
16
 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 
 *  GNU General Public License for more details.
19
 
 *
20
 
 *  You should have received a copy of the GNU General Public License
21
 
 *  along with this program; if not, write to the Free Software
22
 
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
 
 *
24
 
 */
25
 
 
26
 
#include <popt.h>
27
 
#include <glib.h>
28
 
#include <gconf/gconf.h>
29
 
#include <gconf/gconf-client.h>
30
 
#include <libgnomevfs/gnome-vfs-init.h>
31
 
#include <libgnomevfs/gnome-vfs-utils.h>
32
 
#include <libgnomevfs/gnome-vfs-mime-utils.h>
33
 
#include <libgnomevfs/gnome-vfs-mime-info.h>
34
 
#include <libgnomevfs/gnome-vfs-mime-handlers.h>
35
 
#include <libgnomevfs/gnome-vfs-application-registry.h>
36
 
#include <string.h>
37
 
#include <sys/stat.h>
38
 
 
39
 
#include "config.h"
40
 
 
41
 
#ifdef HAVE_GSTREAMER
42
 
#include <gst/gst.h>
43
 
#include <gst/control/control.h>
44
 
#endif
45
 
 
46
 
#include "monkey-media.h"
47
 
#include "monkey-media-stream-info.h"
48
 
#include "monkey-media-private.h"
49
 
 
50
 
#include "vorbis-stream-info-impl.h"
51
 
#include "mp3-stream-info-impl.h"
52
 
#include "audiocd-stream-info-impl.h"
53
 
#ifdef HAVE_FLAC
54
 
#include "flac-stream-info-impl.h"
55
 
#endif
56
 
#ifdef HAVE_MP4
57
 
#include "mp4-stream-info-impl.h"
58
 
#endif
59
 
 
60
 
static void monkey_media_init_internal (void);
61
 
 
62
 
typedef struct
63
 
{
64
 
        char *mime_type;
65
 
        GType stream_info_impl_type;
66
 
} Impl;
67
 
 
68
 
static GPtrArray *impl_array;
69
 
 
70
 
#define CONF_DIR                  "/system/monkey_media"
71
 
#define CONF_KEY_AUDIO_DRIVER     "/system/monkey_media/audio_driver"
72
 
#define CONF_KEY_CD_DRIVE         "/system/monkey_media/cd_drive"
73
 
#define CONF_KEY_CD_PLAYBACK_MODE "/system/monkey_media/cd_playback_mode"
74
 
 
75
 
void
76
 
monkey_media_init (int *argc, char ***argv)
77
 
{
78
 
        monkey_media_init_internal ();
79
 
}
80
 
 
81
 
static void
82
 
register_type (const char *mime_type,
83
 
               GType stream_info_impl_type)
84
 
{
85
 
        Impl *impl;
86
 
 
87
 
        impl = g_new0 (Impl, 1);
88
 
 
89
 
        impl->mime_type             = g_strdup (mime_type);
90
 
        impl->stream_info_impl_type = stream_info_impl_type;
91
 
 
92
 
        g_ptr_array_add (impl_array, impl);
93
 
}
94
 
 
95
 
static void
96
 
monkey_media_init_internal (void)
97
 
{
98
 
        /* register mimetypes */
99
 
        impl_array = g_ptr_array_new ();
100
 
#ifdef HAVE_VORBIS
101
 
        register_type ("application/ogg",
102
 
                       TYPE_VORBIS_STREAM_INFO_IMPL);
103
 
        register_type ("application/x-ogg",
104
 
                       TYPE_VORBIS_STREAM_INFO_IMPL);
105
 
#endif
106
 
#ifdef HAVE_FLAC
107
 
        register_type ("application/x-flac",
108
 
                       TYPE_FLAC_STREAM_INFO_IMPL);
109
 
        register_type ("audio/x-flac",
110
 
                       TYPE_FLAC_STREAM_INFO_IMPL);
111
 
#endif
112
 
#ifdef HAVE_MP3
113
 
        register_type ("audio/x-mp3",
114
 
                       TYPE_MP3_STREAM_INFO_IMPL);
115
 
        register_type ("audio/mpeg",
116
 
                       TYPE_MP3_STREAM_INFO_IMPL);
117
 
        register_type ("audio/x-wav",
118
 
                       TYPE_MP3_STREAM_INFO_IMPL);
119
 
#endif
120
 
#ifdef HAVE_MP4
121
 
        register_type ("audio/x-m4a",
122
 
                       TYPE_MP4_STREAM_INFO_IMPL);
123
 
#endif
124
 
#ifdef HAVE_AUDIOCD
125
 
        register_type ("audiocd",
126
 
                       TYPE_AUDIOCD_STREAM_INFO_IMPL);
127
 
#endif
128
 
 
129
 
}
130
 
 
131
 
GList *
132
 
monkey_media_get_supported_filename_extensions (void)
133
 
{
134
 
        GList *ret = NULL;
135
 
        int i;
136
 
 
137
 
        for (i = 0; i < impl_array->len; i++) {
138
 
                Impl *impl = g_ptr_array_index (impl_array, i);
139
 
                GList *types = gnome_vfs_mime_get_extensions_list (impl->mime_type);
140
 
                GList *tem;
141
 
 
142
 
                for (tem = types; tem != NULL; tem = g_list_next (tem))
143
 
                        ret = g_list_append (ret, tem->data);
144
 
 
145
 
                g_list_free (types);
146
 
        }
147
 
 
148
 
        return ret;
149
 
}
150
 
 
151
 
void
152
 
monkey_media_shutdown (void)
153
 
{
154
 
        int i;
155
 
        for (i = 0; i < impl_array->len; i++)
156
 
        {
157
 
                Impl *impl;
158
 
 
159
 
                impl = g_ptr_array_index (impl_array, i);
160
 
 
161
 
                g_free (impl->mime_type);
162
 
                g_free (impl);
163
 
        }
164
 
        g_ptr_array_free (impl_array, FALSE);
165
 
}
166
 
 
167
 
static Impl *
168
 
monkey_media_get_impl_for (const char *uri, char **mimetype)
169
 
{
170
 
        Impl *ret = NULL;
171
 
        int i;
172
 
 
173
 
        if (strncmp (uri, "audiocd://", 10) == 0)
174
 
                *mimetype = g_strdup ("audiocd");
175
 
        else
176
 
                *mimetype = gnome_vfs_get_mime_type (uri);
177
 
 
178
 
        if (*mimetype == NULL)
179
 
                return FALSE;
180
 
 
181
 
        for (i = 0; i < impl_array->len; i++)
182
 
        {
183
 
                Impl *impl;
184
 
 
185
 
                impl = g_ptr_array_index (impl_array, i);
186
 
 
187
 
                if (strcmp (impl->mime_type, *mimetype) == 0)
188
 
                {
189
 
                        ret = impl;
190
 
                        break;
191
 
                }
192
 
        }
193
 
 
194
 
        return ret;
195
 
}
196
 
 
197
 
GType
198
 
monkey_media_get_stream_info_impl_for (const char *uri, char **mimetype)
199
 
{
200
 
        Impl *impl;
201
 
 
202
 
        impl = monkey_media_get_impl_for (uri, mimetype);
203
 
 
204
 
        if (impl == NULL)
205
 
                return -1;
206
 
 
207
 
        return impl->stream_info_impl_type;
208
 
}