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

« back to all changes in this revision

Viewing changes to metadata/monkey-media/stream-info-impl/vorbis-stream-info-impl.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 Ogg Vorbis metadata retrieval
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 <libgnomevfs/gnome-vfs.h>
27
 
#include <libgnomevfs/gnome-vfs-mime-utils.h>
28
 
#include <libgnomevfs/gnome-vfs-utils.h>
29
 
#include <stdlib.h>
30
 
 
31
 
#include <ogg/ogg.h>
32
 
#include <vorbis/codec.h>
33
 
#include <vorbis/vorbisfile.h>
34
 
 
35
 
#include "ogg-helper.h"
36
 
 
37
 
#include "monkey-media-stream-info.h"
38
 
#include "monkey-media-private.h"
39
 
 
40
 
#include "vorbis-stream-info-impl.h"
41
 
 
42
 
static ov_callbacks file_info_callbacks =
43
 
{
44
 
        ogg_helper_read,
45
 
        ogg_helper_seek,
46
 
        ogg_helper_close_dummy,
47
 
        ogg_helper_tell
48
 
};
49
 
 
50
 
static void vorbis_stream_info_impl_class_init (VorbisStreamInfoImplClass *klass);
51
 
static void vorbis_stream_info_impl_init (VorbisStreamInfoImpl *ma);
52
 
static void vorbis_stream_info_impl_finalize (GObject *object);
53
 
static void vorbis_stream_info_impl_open_stream (MonkeyMediaStreamInfo *info);
54
 
static gboolean vorbis_stream_info_impl_get_value (MonkeyMediaStreamInfo *info,
55
 
                                                   MonkeyMediaStreamInfoField field,
56
 
                                                   int index,
57
 
                                                   GValue *value);
58
 
static gboolean vorbis_stream_info_impl_set_value (MonkeyMediaStreamInfo *info,
59
 
                                                   MonkeyMediaStreamInfoField field,
60
 
                                                   int index,
61
 
                                                   const GValue *value);
62
 
static int vorbis_stream_info_impl_get_n_values (MonkeyMediaStreamInfo *info,
63
 
                                                 MonkeyMediaStreamInfoField field);
64
 
 
65
 
struct VorbisStreamInfoImplPrivate
66
 
{
67
 
        vorbis_comment *comment;
68
 
        vorbis_info *info;
69
 
        OggVorbis_File vf;
70
 
        GnomeVFSHandle *handle;
71
 
};
72
 
 
73
 
static GObjectClass *parent_class = NULL;
74
 
 
75
 
GType
76
 
vorbis_stream_info_impl_get_type (void)
77
 
{
78
 
        static GType vorbis_stream_info_impl_type = 0;
79
 
 
80
 
        if (vorbis_stream_info_impl_type == 0)
81
 
        {
82
 
                static const GTypeInfo our_info =
83
 
                {
84
 
                        sizeof (VorbisStreamInfoImplClass),
85
 
                        NULL,
86
 
                        NULL,
87
 
                        (GClassInitFunc) vorbis_stream_info_impl_class_init,
88
 
                        NULL,
89
 
                        NULL,
90
 
                        sizeof (VorbisStreamInfoImpl),
91
 
                        0,
92
 
                        (GInstanceInitFunc) vorbis_stream_info_impl_init
93
 
                };
94
 
 
95
 
                vorbis_stream_info_impl_type = g_type_register_static (MONKEY_MEDIA_TYPE_STREAM_INFO,
96
 
                                                                       "VorbisStreamInfoImpl",
97
 
                                                                       &our_info, 0);
98
 
        }
99
 
 
100
 
        return vorbis_stream_info_impl_type;
101
 
}
102
 
 
103
 
static void
104
 
vorbis_stream_info_impl_class_init (VorbisStreamInfoImplClass *klass)
105
 
{
106
 
        GObjectClass *object_class = G_OBJECT_CLASS (klass);
107
 
        MonkeyMediaStreamInfoClass *info_class = MONKEY_MEDIA_STREAM_INFO_CLASS (klass);
108
 
 
109
 
        parent_class = g_type_class_peek_parent (klass);
110
 
 
111
 
        object_class->finalize = vorbis_stream_info_impl_finalize;
112
 
 
113
 
        info_class->open_stream  = vorbis_stream_info_impl_open_stream;
114
 
        info_class->get_n_values = vorbis_stream_info_impl_get_n_values;
115
 
        info_class->get_value    = vorbis_stream_info_impl_get_value;
116
 
        info_class->set_value    = vorbis_stream_info_impl_set_value;
117
 
}
118
 
 
119
 
static void
120
 
vorbis_stream_info_impl_init (VorbisStreamInfoImpl *impl)
121
 
{
122
 
        impl->priv = g_new0 (VorbisStreamInfoImplPrivate, 1);
123
 
}
124
 
 
125
 
static void
126
 
vorbis_stream_info_impl_finalize (GObject *object)
127
 
{
128
 
        VorbisStreamInfoImpl *impl;
129
 
 
130
 
        g_return_if_fail (object != NULL);
131
 
        g_return_if_fail (IS_VORBIS_STREAM_INFO_IMPL (object));
132
 
 
133
 
        impl = VORBIS_STREAM_INFO_IMPL (object);
134
 
 
135
 
        g_return_if_fail (impl->priv != NULL);
136
 
 
137
 
        if (&impl->priv->vf != NULL)
138
 
                ov_clear (&impl->priv->vf);
139
 
        if (impl->priv->handle != NULL)
140
 
                ogg_helper_close (impl->priv->handle);
141
 
 
142
 
        g_free (impl->priv);
143
 
 
144
 
        G_OBJECT_CLASS (parent_class)->finalize (object);
145
 
}
146
 
 
147
 
static void
148
 
vorbis_stream_info_impl_open_stream (MonkeyMediaStreamInfo *info)
149
 
{
150
 
        VorbisStreamInfoImpl *impl = VORBIS_STREAM_INFO_IMPL (info);
151
 
        GnomeVFSResult res;
152
 
        GError *error;
153
 
        char *uri;
154
 
        int rc;
155
 
 
156
 
        g_object_get (G_OBJECT (info),
157
 
                      "error", &error,
158
 
                      "location", &uri,
159
 
                      NULL);
160
 
 
161
 
        res = gnome_vfs_open (&impl->priv->handle, uri, GNOME_VFS_OPEN_READ);
162
 
        g_free (uri);
163
 
        if (res != GNOME_VFS_OK)
164
 
        {
165
 
                error = g_error_new (MONKEY_MEDIA_STREAM_INFO_ERROR,
166
 
                                     MONKEY_MEDIA_STREAM_INFO_ERROR_OPEN_FAILED,
167
 
                                     _("Failed to open file for reading"));
168
 
                g_object_set (G_OBJECT (info), "error", error, NULL);
169
 
                return;
170
 
        }
171
 
 
172
 
        /* Try the different SEEK types that might fail */
173
 
        if ((gnome_vfs_seek (impl->priv->handle, GNOME_VFS_SEEK_END, 0) != GNOME_VFS_OK) ||
174
 
            (gnome_vfs_seek (impl->priv->handle, GNOME_VFS_SEEK_START, 0) != GNOME_VFS_OK))
175
 
        {
176
 
                gnome_vfs_close (impl->priv->handle);
177
 
                impl->priv->handle = NULL;
178
 
                error = g_error_new (MONKEY_MEDIA_STREAM_INFO_ERROR,
179
 
                                     MONKEY_MEDIA_STREAM_INFO_ERROR_SEEK_FAILED,
180
 
                                     _("Failed to seek file"));
181
 
                g_object_set (G_OBJECT (info), "error", error, NULL);
182
 
                return;
183
 
        }
184
 
 
185
 
        rc = ov_open_callbacks (impl->priv->handle, &impl->priv->vf, NULL, 0,
186
 
                                file_info_callbacks);
187
 
        if (rc < 0)
188
 
        {
189
 
                /* see ogg-helper.c for details */
190
 
                ogg_helper_close (impl->priv->handle);
191
 
                impl->priv->handle = NULL;
192
 
                error = g_error_new (MONKEY_MEDIA_STREAM_INFO_ERROR,
193
 
                                     MONKEY_MEDIA_STREAM_INFO_ERROR_OPEN_FAILED,
194
 
                                     _("Failed to open file as Ogg Vorbis"));
195
 
                g_object_set (G_OBJECT (info), "error", error, NULL);
196
 
                return;
197
 
        }
198
 
 
199
 
        impl->priv->comment = ov_comment (&impl->priv->vf, -1);
200
 
        impl->priv->info = ov_info (&impl->priv->vf, -1);
201
 
}
202
 
 
203
 
static int
204
 
vorbis_stream_info_impl_get_n_values (MonkeyMediaStreamInfo *info,
205
 
                                      MonkeyMediaStreamInfoField field)
206
 
{
207
 
        VorbisStreamInfoImpl *impl;
208
 
        
209
 
        g_return_val_if_fail (IS_VORBIS_STREAM_INFO_IMPL (info), 0);
210
 
 
211
 
        impl = VORBIS_STREAM_INFO_IMPL (info);
212
 
 
213
 
        switch (field)
214
 
        {
215
 
        /* tags */
216
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_TITLE:
217
 
                return vorbis_comment_query_count (impl->priv->comment, "title");
218
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_ARTIST:
219
 
                return vorbis_comment_query_count (impl->priv->comment, "artist");
220
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_ALBUM:
221
 
                return vorbis_comment_query_count (impl->priv->comment, "album");
222
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_DATE:
223
 
                return vorbis_comment_query_count (impl->priv->comment, "date");
224
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_GENRE:
225
 
                return vorbis_comment_query_count (impl->priv->comment, "genre");
226
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_COMMENT:
227
 
                return vorbis_comment_query_count (impl->priv->comment, "comment") + 
228
 
                       vorbis_comment_query_count (impl->priv->comment, "");
229
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_TRACK_NUMBER:
230
 
                {
231
 
                        char *tmp, **parts;
232
 
                        gboolean ret = FALSE;
233
 
 
234
 
                        tmp = vorbis_comment_query (impl->priv->comment, "tracknumber", 0);
235
 
                        if (tmp == NULL)
236
 
                                return 0;
237
 
 
238
 
                        parts = g_strsplit (tmp, "/", -1);
239
 
                        
240
 
                        if (parts[0] != NULL)
241
 
                                ret = TRUE;
242
 
 
243
 
                        g_strfreev (parts);
244
 
 
245
 
                        return ret;
246
 
                }
247
 
                break;
248
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_MAX_TRACK_NUMBER:
249
 
                {
250
 
                        char *tmp, **parts;
251
 
                        gboolean ret = FALSE;
252
 
 
253
 
                        tmp = vorbis_comment_query (impl->priv->comment, "tracktotal", 0);
254
 
                        if (tmp != NULL)
255
 
                                return TRUE;
256
 
 
257
 
                        tmp = vorbis_comment_query (impl->priv->comment, "tracknumber", 0);
258
 
                        if (tmp == NULL)
259
 
                                return FALSE;
260
 
 
261
 
                        parts = g_strsplit (tmp, "/", -1);
262
 
                        
263
 
                        if (parts[0] != NULL && parts[1] != NULL)
264
 
                                ret = TRUE;
265
 
 
266
 
                        g_strfreev (parts);
267
 
 
268
 
                        return ret;
269
 
                }
270
 
                break;
271
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_LOCATION:
272
 
                return vorbis_comment_query_count (impl->priv->comment, "location");
273
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_DESCRIPTION:
274
 
                return vorbis_comment_query_count (impl->priv->comment, "description");
275
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_VERSION:
276
 
                return vorbis_comment_query_count (impl->priv->comment, "version");
277
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_ISRC:
278
 
                return vorbis_comment_query_count (impl->priv->comment, "isrc");
279
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_ORGANIZATION:
280
 
                return vorbis_comment_query_count (impl->priv->comment, "organization");
281
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_COPYRIGHT:
282
 
                return vorbis_comment_query_count (impl->priv->comment, "copyright");
283
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_CONTACT:
284
 
                return vorbis_comment_query_count (impl->priv->comment, "contact");
285
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_LICENSE:
286
 
                return vorbis_comment_query_count (impl->priv->comment, "license");
287
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_PERFORMER:
288
 
                return vorbis_comment_query_count (impl->priv->comment, "performer");
289
 
 
290
 
        /* generic bits */
291
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_FILE_SIZE:
292
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_DURATION:
293
 
                return 1;
294
 
 
295
 
        /* audio bits */
296
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_HAS_AUDIO:
297
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_AUDIO_CODEC_INFO:
298
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_AUDIO_BIT_RATE:
299
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_AUDIO_AVERAGE_BIT_RATE:
300
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_AUDIO_VARIABLE_BIT_RATE:
301
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_AUDIO_QUALITY:
302
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_AUDIO_SAMPLE_RATE:
303
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_AUDIO_CHANNELS:
304
 
                return 1;
305
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_AUDIO_TRM_ID:
306
 
                return 0;
307
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_AUDIO_SERIAL_NUMBER:
308
 
                return (ov_serialnumber (&impl->priv->vf, -1) > 0);
309
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_AUDIO_VENDOR:
310
 
                return (impl->priv->comment->vendor != NULL);
311
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_AUDIO_ALBUM_GAIN:
312
 
                {
313
 
                        char *tmp;
314
 
 
315
 
                        tmp = vorbis_comment_query (impl->priv->comment, "replaygain_album_gain", 0);
316
 
                        if (tmp == NULL)
317
 
                                tmp = vorbis_comment_query (impl->priv->comment, "rg_audiophile", 0);
318
 
                        
319
 
                        return (tmp != NULL);
320
 
                }
321
 
                break;
322
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_AUDIO_TRACK_GAIN:
323
 
                {
324
 
                        char *tmp;
325
 
 
326
 
                        tmp = vorbis_comment_query (impl->priv->comment, "replaygain_track_gain", 0);
327
 
                        if (tmp == NULL)
328
 
                                tmp = vorbis_comment_query (impl->priv->comment, "rg_radio", 0);
329
 
                        
330
 
                        return (tmp != NULL);
331
 
                }
332
 
                break;
333
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_AUDIO_ALBUM_PEAK:
334
 
                {
335
 
                        char *tmp;
336
 
 
337
 
                        tmp = vorbis_comment_query (impl->priv->comment, "replaygain_album_peak", 0);
338
 
                        if (tmp == NULL)
339
 
                                tmp = vorbis_comment_query (impl->priv->comment, "rg_peak", 0);
340
 
 
341
 
                        return (tmp != NULL);
342
 
                }
343
 
                break;
344
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_AUDIO_TRACK_PEAK:
345
 
                {
346
 
                        char *tmp;
347
 
 
348
 
                        tmp = vorbis_comment_query (impl->priv->comment, "replaygain_track_peak", 0);
349
 
                        if (tmp == NULL)
350
 
                                tmp = vorbis_comment_query (impl->priv->comment, "rg_peak", 0);
351
 
 
352
 
                        return (tmp != NULL);
353
 
                }
354
 
                break;
355
 
 
356
 
        /* video bits */
357
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_HAS_VIDEO:
358
 
                return 1;
359
 
 
360
 
        /* default */
361
 
        default:
362
 
                return 0;
363
 
        }
364
 
}
365
 
 
366
 
static gboolean
367
 
vorbis_stream_info_impl_get_strvalue_utf8 (VorbisStreamInfoImpl *impl,
368
 
                                           int index, char *entry, GValue *value)
369
 
{
370
 
        gsize read, written;
371
 
        char *strval;
372
 
 
373
 
        strval = g_strdup (vorbis_comment_query (impl->priv->comment, entry, index));
374
 
 
375
 
        if (!g_utf8_validate (strval, -1, NULL))
376
 
        {
377
 
                char *tem;
378
 
 
379
 
                g_warning ("Invalid UTF-8 in %s field in vorbis file\n", entry);
380
 
 
381
 
                tem = g_locale_to_utf8 (strval, -1, &read, &written, NULL);
382
 
                g_free (strval);
383
 
 
384
 
                if (!tem)
385
 
                        return FALSE;
386
 
 
387
 
                strval = tem;
388
 
        }
389
 
 
390
 
        g_value_init (value, G_TYPE_STRING);
391
 
        g_value_set_string_take_ownership (value, strval);
392
 
 
393
 
        return TRUE;
394
 
}
395
 
 
396
 
static gboolean
397
 
vorbis_stream_info_impl_get_value (MonkeyMediaStreamInfo *info,
398
 
                                   MonkeyMediaStreamInfoField field,
399
 
                                   int index,
400
 
                                   GValue *value)
401
 
{
402
 
        VorbisStreamInfoImpl *impl;
403
 
        
404
 
        g_return_val_if_fail (IS_VORBIS_STREAM_INFO_IMPL (info), FALSE);
405
 
        g_return_val_if_fail (value != NULL, FALSE);
406
 
 
407
 
        impl = VORBIS_STREAM_INFO_IMPL (info);
408
 
 
409
 
        if (vorbis_stream_info_impl_get_n_values (info, field) <= 0)
410
 
                return FALSE;
411
 
 
412
 
        switch (field)
413
 
        {
414
 
        /* tags */
415
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_TITLE:
416
 
                return vorbis_stream_info_impl_get_strvalue_utf8 (impl, index, "title", value);
417
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_ARTIST:
418
 
                return vorbis_stream_info_impl_get_strvalue_utf8 (impl, index, "artist", value);
419
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_ALBUM:
420
 
                return vorbis_stream_info_impl_get_strvalue_utf8 (impl, index, "album", value);
421
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_DATE:
422
 
                return vorbis_stream_info_impl_get_strvalue_utf8 (impl, index, "date", value);
423
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_GENRE:
424
 
                return vorbis_stream_info_impl_get_strvalue_utf8 (impl, index, "genre", value);
425
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_COMMENT:
426
 
                {
427
 
                        int count;
428
 
                        
429
 
                        g_value_init (value, G_TYPE_STRING);
430
 
 
431
 
                        count = vorbis_comment_query_count (impl->priv->comment, "comment");
432
 
                        if (index < count)
433
 
                                g_value_set_string (value, vorbis_comment_query (impl->priv->comment, "comment", index));
434
 
                        else
435
 
                                g_value_set_string (value, vorbis_comment_query (impl->priv->comment, "", index - count));
436
 
                        if (!g_utf8_validate (g_value_get_string (value), -1, NULL))
437
 
                        {
438
 
                                g_warning ("Invalid UTF-8 in comment field in vorbis file\n");
439
 
                                g_value_unset (value);
440
 
                                return FALSE;
441
 
                        }
442
 
                }
443
 
                break;
444
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_TRACK_NUMBER:
445
 
                {
446
 
                        char *tmp, **parts;
447
 
                        int num = -1;
448
 
 
449
 
                        g_value_init (value, G_TYPE_INT);
450
 
 
451
 
                        tmp = vorbis_comment_query (impl->priv->comment, "tracknumber", 0);
452
 
                        if (tmp == NULL)
453
 
                        {
454
 
                                g_value_set_int (value, -1);
455
 
                                break;
456
 
                        }
457
 
                        
458
 
                        parts = g_strsplit (tmp, "/", -1);
459
 
                        
460
 
                        if (parts[0] != NULL)
461
 
                                num = atoi (parts[0]);
462
 
 
463
 
                        g_value_set_int (value, num);
464
 
 
465
 
                        g_strfreev (parts);
466
 
                }
467
 
                break;
468
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_MAX_TRACK_NUMBER:
469
 
                {
470
 
                        char *tmp;
471
 
                        int num = -1;
472
 
 
473
 
                        g_value_init (value, G_TYPE_INT);
474
 
 
475
 
                        tmp = vorbis_comment_query (impl->priv->comment, "tracktotal", 0);
476
 
                        if (tmp != NULL) {
477
 
                                g_value_set_int (value, atoi (tmp));
478
 
                                break;
479
 
                        }
480
 
 
481
 
                        tmp = vorbis_comment_query (impl->priv->comment, "tracknumber", 0);
482
 
                        if (tmp != NULL) {
483
 
                                char **parts = g_strsplit (tmp, "/", -1);
484
 
                                
485
 
                                if (parts[0] != NULL && parts[1] != NULL) {
486
 
                                        num = atoi (parts[1]);
487
 
                                        g_value_set_int (value, num);
488
 
                                } else 
489
 
                                        g_value_set_int (value, -1);
490
 
                                
491
 
                                g_strfreev (parts);
492
 
                        }
493
 
                }
494
 
                break;
495
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_LOCATION:
496
 
                return vorbis_stream_info_impl_get_strvalue_utf8 (impl, index, "location", value);
497
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_DESCRIPTION:
498
 
                return vorbis_stream_info_impl_get_strvalue_utf8 (impl, index, "description", value);
499
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_VERSION:
500
 
                return vorbis_stream_info_impl_get_strvalue_utf8 (impl, index, "version", value);
501
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_ISRC:
502
 
                return vorbis_stream_info_impl_get_strvalue_utf8 (impl, index, "isrc", value);
503
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_ORGANIZATION:
504
 
                return vorbis_stream_info_impl_get_strvalue_utf8 (impl, index, "organization", value);
505
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_COPYRIGHT:
506
 
                return vorbis_stream_info_impl_get_strvalue_utf8 (impl, index, "copyright", value);
507
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_CONTACT:
508
 
                return vorbis_stream_info_impl_get_strvalue_utf8 (impl, index, "contact", value);
509
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_LICENSE:
510
 
                return vorbis_stream_info_impl_get_strvalue_utf8 (impl, index, "license", value);
511
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_PERFORMER:
512
 
                return vorbis_stream_info_impl_get_strvalue_utf8 (impl, index, "performer", value);
513
 
 
514
 
        /* generic bits */
515
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_FILE_SIZE:
516
 
                {
517
 
                        GnomeVFSFileInfo *i;
518
 
                        GnomeVFSResult res;
519
 
 
520
 
                        g_value_init (value, G_TYPE_LONG);
521
 
 
522
 
                        i = gnome_vfs_file_info_new ();
523
 
                        res = gnome_vfs_get_file_info_from_handle
524
 
                                (impl->priv->handle, i,
525
 
                                 GNOME_VFS_FILE_INFO_FOLLOW_LINKS);
526
 
                        if (res == GNOME_VFS_OK)
527
 
                                g_value_set_long (value, i->size);
528
 
                        else
529
 
                                g_value_set_long (value, 0);
530
 
 
531
 
                        gnome_vfs_file_info_unref (i);
532
 
                }
533
 
                break;
534
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_DURATION:
535
 
                g_value_init (value, G_TYPE_LONG);
536
 
                g_value_set_long (value, ov_time_total (&impl->priv->vf, -1));
537
 
                break;
538
 
 
539
 
        /* audio bits */
540
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_HAS_AUDIO:
541
 
                g_value_init (value, G_TYPE_BOOLEAN);
542
 
                g_value_set_boolean (value, TRUE);
543
 
                break;
544
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_AUDIO_CODEC_INFO:
545
 
                g_value_init (value, G_TYPE_STRING);
546
 
                g_value_set_string (value, _("Ogg Vorbis"));
547
 
                break;
548
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_AUDIO_BIT_RATE:
549
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_AUDIO_AVERAGE_BIT_RATE:
550
 
                g_value_init (value, G_TYPE_INT);
551
 
                g_value_set_int (value, (int) (impl->priv->info->bitrate_nominal / 1000));
552
 
                break;
553
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_AUDIO_VARIABLE_BIT_RATE:
554
 
                g_value_init (value, G_TYPE_BOOLEAN);
555
 
                g_value_set_boolean (value, TRUE);
556
 
                break;
557
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_AUDIO_TRM_ID:
558
 
                /* FIXME */
559
 
                g_value_init (value, G_TYPE_STRING);
560
 
                g_value_set_string (value, NULL);
561
 
                break;
562
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_AUDIO_SAMPLE_RATE:
563
 
                g_value_init (value, G_TYPE_LONG);
564
 
                g_value_set_long (value, impl->priv->info->rate);
565
 
                break;
566
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_AUDIO_CHANNELS:
567
 
                g_value_init (value, G_TYPE_INT);
568
 
                g_value_set_int (value, impl->priv->info->channels);
569
 
                break;
570
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_AUDIO_SERIAL_NUMBER:
571
 
                g_value_init (value, G_TYPE_LONG);
572
 
                g_value_set_long (value, ov_serialnumber (&impl->priv->vf, -1));
573
 
                break;
574
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_AUDIO_VENDOR:
575
 
                g_value_init (value, G_TYPE_STRING);
576
 
                g_value_set_string (value, impl->priv->comment->vendor);
577
 
                if (!g_utf8_validate (g_value_get_string (value), -1, NULL))
578
 
                {
579
 
                        g_warning ("Invalid UTF-8 in audio vendor field in vorbis file\n");
580
 
                        g_value_unset (value);
581
 
                        return FALSE;
582
 
                }
583
 
                break;
584
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_AUDIO_ALBUM_GAIN:
585
 
                {
586
 
                        char *tmp;
587
 
 
588
 
                        tmp = vorbis_comment_query (impl->priv->comment, "replaygain_album_gain", 0);
589
 
                        if (tmp == NULL)
590
 
                                tmp = vorbis_comment_query (impl->priv->comment, "rg_audiophile", 0);
591
 
                        
592
 
                        g_value_init (value, G_TYPE_DOUBLE);
593
 
                        g_value_set_double (value, tmp != NULL ? atof (tmp) : 0.0);
594
 
                }
595
 
                break;
596
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_AUDIO_TRACK_GAIN:
597
 
                {
598
 
                        char *tmp;
599
 
 
600
 
                        tmp = vorbis_comment_query (impl->priv->comment, "replaygain_track_gain", 0);
601
 
                        if (tmp == NULL)
602
 
                                tmp = vorbis_comment_query (impl->priv->comment, "rg_radio", 0);
603
 
                        
604
 
                        g_value_init (value, G_TYPE_DOUBLE);
605
 
                        g_value_set_double (value, tmp != NULL ? atof (tmp) : 0.0);
606
 
                }
607
 
                break;
608
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_AUDIO_ALBUM_PEAK:
609
 
                {
610
 
                        char *tmp;
611
 
 
612
 
                        tmp = vorbis_comment_query (impl->priv->comment, "replaygain_album_peak", 0);
613
 
                        if (tmp == NULL)
614
 
                                tmp = vorbis_comment_query (impl->priv->comment, "rg_peak", 0);
615
 
                        
616
 
                        g_value_init (value, G_TYPE_DOUBLE);
617
 
                        g_value_set_double (value, tmp != NULL ? atof (tmp) : 0.0);
618
 
                }
619
 
                break;
620
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_AUDIO_TRACK_PEAK:
621
 
                {
622
 
                        char *tmp;
623
 
 
624
 
                        tmp = vorbis_comment_query (impl->priv->comment, "replaygain_track_peak", 0);
625
 
                        if (tmp == NULL)
626
 
                                tmp = vorbis_comment_query (impl->priv->comment, "rg_peak", 0);
627
 
                        
628
 
                        g_value_init (value, G_TYPE_DOUBLE);
629
 
                        g_value_set_double (value, tmp != NULL ? atof (tmp) : 0.0);
630
 
                }
631
 
                break;
632
 
 
633
 
        /* video bits */
634
 
        case MONKEY_MEDIA_STREAM_INFO_FIELD_HAS_VIDEO:
635
 
                g_value_init (value, G_TYPE_BOOLEAN);
636
 
                g_value_set_boolean (value, FALSE);
637
 
                break;
638
 
 
639
 
        /* default */
640
 
        default:
641
 
                g_value_init (value, G_TYPE_NONE);
642
 
                break;
643
 
        }
644
 
        
645
 
        return TRUE;
646
 
}
647
 
 
648
 
static gboolean
649
 
vorbis_stream_info_impl_set_value (MonkeyMediaStreamInfo *info,
650
 
                                   MonkeyMediaStreamInfoField field,
651
 
                                   int index,
652
 
                                   const GValue *value)
653
 
{
654
 
        /* FIXME */
655
 
        return FALSE;
656
 
}