2004-02-24 00:41:20 +01:00
|
|
|
/* the Music Player Daemon (MPD)
|
2007-04-05 05:22:33 +02:00
|
|
|
* Copyright (C) 2003-2007 by Warren Dukes (warren.dukes@gmail.com)
|
2004-02-24 00:41:20 +01:00
|
|
|
* This project's homepage is: http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
2006-03-16 07:52:46 +01:00
|
|
|
/* TODO 'ogg' should probably be replaced with 'oggvorbis' in all instances */
|
|
|
|
|
|
|
|
#include "_ogg_common.h"
|
2009-01-08 21:37:02 +01:00
|
|
|
#include "config.h"
|
2005-08-25 10:07:28 +02:00
|
|
|
|
|
|
|
#ifndef HAVE_TREMOR
|
2004-02-24 00:41:20 +01:00
|
|
|
#include <vorbis/vorbisfile.h>
|
2005-08-25 10:07:28 +02:00
|
|
|
#else
|
|
|
|
#include <tremor/ivorbisfile.h>
|
|
|
|
/* Macros to make Tremor's API look like libogg. Tremor always
|
|
|
|
returns host-byte-order 16-bit signed data, and uses integer
|
|
|
|
milliseconds where libogg uses double seconds.
|
|
|
|
*/
|
|
|
|
#define ov_read(VF, BUFFER, LENGTH, BIGENDIANP, WORD, SGNED, BITSTREAM) \
|
|
|
|
ov_read(VF, BUFFER, LENGTH, BITSTREAM)
|
|
|
|
#define ov_time_total(VF, I) ((double)ov_time_total(VF, I)/1000)
|
|
|
|
#define ov_time_tell(VF) ((double)ov_time_tell(VF)/1000)
|
|
|
|
#define ov_time_seek_page(VF, S) (ov_time_seek_page(VF, (S)*1000))
|
2006-07-20 20:53:56 +02:00
|
|
|
#endif /* HAVE_TREMOR */
|
2005-08-25 10:07:28 +02:00
|
|
|
|
2008-11-11 21:33:01 +01:00
|
|
|
#include <glib.h>
|
2009-01-14 23:09:31 +01:00
|
|
|
|
|
|
|
#include <assert.h>
|
2008-11-11 21:33:01 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdlib.h>
|
2008-11-24 10:33:08 +01:00
|
|
|
#include <unistd.h>
|
2008-11-11 21:33:01 +01:00
|
|
|
|
2009-01-05 12:40:57 +01:00
|
|
|
#if G_BYTE_ORDER == G_BIG_ENDIAN
|
2004-03-09 22:42:08 +01:00
|
|
|
#define OGG_DECODE_USE_BIGENDIAN 1
|
|
|
|
#else
|
|
|
|
#define OGG_DECODE_USE_BIGENDIAN 0
|
|
|
|
#endif
|
|
|
|
|
2004-05-20 05:44:33 +02:00
|
|
|
typedef struct _OggCallbackData {
|
2008-08-26 08:27:07 +02:00
|
|
|
struct decoder *decoder;
|
2009-01-14 23:09:02 +01:00
|
|
|
struct input_stream *input_stream;
|
2004-05-20 05:44:33 +02:00
|
|
|
} OggCallbackData;
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static size_t ogg_read_cb(void *ptr, size_t size, size_t nmemb, void *vdata)
|
2004-05-04 21:49:29 +02:00
|
|
|
{
|
2008-03-26 11:37:36 +01:00
|
|
|
size_t ret;
|
2006-07-20 18:02:40 +02:00
|
|
|
OggCallbackData *data = (OggCallbackData *) vdata;
|
|
|
|
|
2009-01-14 23:09:02 +01:00
|
|
|
ret = decoder_read(data->decoder, data->input_stream, ptr, size * nmemb);
|
2008-08-26 08:27:14 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
errno = 0;
|
2004-05-04 21:49:29 +02:00
|
|
|
|
2008-08-26 08:27:14 +02:00
|
|
|
return ret / size;
|
2004-05-04 21:49:29 +02:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static int ogg_seek_cb(void *vdata, ogg_int64_t offset, int whence)
|
|
|
|
{
|
2008-02-05 11:17:33 +01:00
|
|
|
const OggCallbackData *data = (const OggCallbackData *) vdata;
|
2008-08-26 08:27:07 +02:00
|
|
|
if(decoder_get_command(data->decoder) == DECODE_COMMAND_STOP)
|
2007-11-28 15:06:03 +01:00
|
|
|
return -1;
|
2009-01-14 23:09:02 +01:00
|
|
|
return input_stream_seek(data->input_stream, offset, whence) ? 0 : -1;
|
2004-05-04 21:49:29 +02:00
|
|
|
}
|
|
|
|
|
2008-01-01 11:09:56 +01:00
|
|
|
/* TODO: check Ogg libraries API and see if we can just not have this func */
|
2009-01-01 18:09:24 +01:00
|
|
|
static int ogg_close_cb(G_GNUC_UNUSED void *vdata)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-01-01 11:09:56 +01:00
|
|
|
return 0;
|
2004-05-04 21:49:29 +02:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static long ogg_tell_cb(void *vdata)
|
|
|
|
{
|
2008-02-05 11:17:33 +01:00
|
|
|
const OggCallbackData *data = (const OggCallbackData *) vdata;
|
2004-05-20 05:44:33 +02:00
|
|
|
|
2009-01-14 23:09:02 +01:00
|
|
|
return (long)data->input_stream->offset;
|
2004-05-04 21:49:29 +02:00
|
|
|
}
|
|
|
|
|
2009-01-14 23:09:02 +01:00
|
|
|
static const char *
|
|
|
|
vorbis_comment_value(const char *comment, const char *needle)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2009-01-14 23:23:05 +01:00
|
|
|
size_t len = strlen(needle);
|
2004-05-08 14:00:30 +02:00
|
|
|
|
2009-01-14 23:23:05 +01:00
|
|
|
if (g_ascii_strncasecmp(comment, needle, len) == 0 &&
|
|
|
|
comment[len] == '=')
|
2006-07-20 18:02:40 +02:00
|
|
|
return comment + len + 1;
|
2004-05-08 14:00:30 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
return NULL;
|
2004-05-08 14:00:30 +02:00
|
|
|
}
|
|
|
|
|
2008-11-11 16:19:00 +01:00
|
|
|
static struct replay_gain_info *
|
2009-01-14 23:09:02 +01:00
|
|
|
vorbis_comments_to_replay_gain(char **comments)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-11-11 16:19:00 +01:00
|
|
|
struct replay_gain_info *rgi;
|
2008-02-05 11:17:33 +01:00
|
|
|
const char *temp;
|
2008-10-30 08:38:54 +01:00
|
|
|
bool found = false;
|
2004-05-08 14:00:30 +02:00
|
|
|
|
2008-11-11 16:19:00 +01:00
|
|
|
rgi = replay_gain_info_new();
|
2004-05-08 14:00:30 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
while (*comments) {
|
|
|
|
if ((temp =
|
2009-01-14 23:09:02 +01:00
|
|
|
vorbis_comment_value(*comments, "replaygain_track_gain"))) {
|
2008-11-11 16:24:27 +01:00
|
|
|
rgi->tuples[REPLAY_GAIN_TRACK].gain = atof(temp);
|
2008-10-30 08:38:54 +01:00
|
|
|
found = true;
|
2009-01-14 23:09:02 +01:00
|
|
|
} else if ((temp = vorbis_comment_value(*comments,
|
|
|
|
"replaygain_album_gain"))) {
|
2008-11-11 16:24:27 +01:00
|
|
|
rgi->tuples[REPLAY_GAIN_ALBUM].gain = atof(temp);
|
2008-10-30 08:38:54 +01:00
|
|
|
found = true;
|
2009-01-14 23:09:02 +01:00
|
|
|
} else if ((temp = vorbis_comment_value(*comments,
|
|
|
|
"replaygain_track_peak"))) {
|
2008-11-11 16:24:27 +01:00
|
|
|
rgi->tuples[REPLAY_GAIN_TRACK].peak = atof(temp);
|
2008-10-30 08:38:54 +01:00
|
|
|
found = true;
|
2009-01-14 23:09:02 +01:00
|
|
|
} else if ((temp = vorbis_comment_value(*comments,
|
|
|
|
"replaygain_album_peak"))) {
|
2008-11-11 16:24:27 +01:00
|
|
|
rgi->tuples[REPLAY_GAIN_ALBUM].peak = atof(temp);
|
2008-10-30 08:38:54 +01:00
|
|
|
found = true;
|
2006-07-20 18:02:40 +02:00
|
|
|
}
|
2004-05-08 14:00:30 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
comments++;
|
|
|
|
}
|
2004-05-08 14:00:30 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (!found) {
|
2008-11-11 16:19:00 +01:00
|
|
|
replay_gain_info_free(rgi);
|
|
|
|
rgi = NULL;
|
2004-11-02 20:56:59 +01:00
|
|
|
}
|
2008-11-11 16:19:00 +01:00
|
|
|
|
|
|
|
return rgi;
|
2004-05-08 14:00:30 +02:00
|
|
|
}
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static const char *VORBIS_COMMENT_TRACK_KEY = "tracknumber";
|
|
|
|
static const char *VORBIS_COMMENT_DISC_KEY = "discnumber";
|
2006-03-16 07:52:46 +01:00
|
|
|
|
2009-01-14 23:15:14 +01:00
|
|
|
/**
|
|
|
|
* Check if the comment's name equals the passed name, and if so, copy
|
|
|
|
* the comment value into the tag.
|
|
|
|
*/
|
|
|
|
static bool
|
|
|
|
vorbis_copy_comment(struct tag *tag, const char *comment,
|
|
|
|
const char *name, enum tag_type tag_type)
|
|
|
|
{
|
|
|
|
const char *value;
|
|
|
|
|
|
|
|
value = vorbis_comment_value(comment, name);
|
|
|
|
if (value != NULL) {
|
|
|
|
tag_add_item(tag, tag_type, value);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2009-01-14 23:21:45 +01:00
|
|
|
static void
|
|
|
|
vorbis_parse_comment(struct tag *tag, const char *comment)
|
2006-03-16 07:52:46 +01:00
|
|
|
{
|
2009-01-14 23:09:31 +01:00
|
|
|
assert(tag != NULL);
|
|
|
|
|
2009-01-14 23:21:45 +01:00
|
|
|
if (vorbis_copy_comment(tag, comment, VORBIS_COMMENT_TRACK_KEY,
|
|
|
|
TAG_ITEM_TRACK) ||
|
|
|
|
vorbis_copy_comment(tag, comment, VORBIS_COMMENT_DISC_KEY,
|
|
|
|
TAG_ITEM_DISC))
|
|
|
|
return;
|
2006-06-04 13:36:02 +02:00
|
|
|
|
2009-01-14 23:21:45 +01:00
|
|
|
for (unsigned i = 0; i < TAG_NUM_OF_ITEM_TYPES; ++i)
|
|
|
|
if (vorbis_copy_comment(tag, comment,
|
|
|
|
mpdTagItemKeys[i], i))
|
|
|
|
return;
|
2006-03-16 07:52:46 +01:00
|
|
|
}
|
2004-06-01 13:18:25 +02:00
|
|
|
|
2009-01-14 23:09:02 +01:00
|
|
|
static struct tag *
|
|
|
|
vorbis_comments_to_tag(char **comments)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2009-01-14 23:09:31 +01:00
|
|
|
struct tag *tag = tag_new();
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2009-01-14 23:21:45 +01:00
|
|
|
while (*comments)
|
|
|
|
vorbis_parse_comment(tag, *comments++);
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2009-01-14 23:09:31 +01:00
|
|
|
if (tag_is_empty(tag)) {
|
|
|
|
tag_free(tag);
|
|
|
|
tag = NULL;
|
|
|
|
}
|
|
|
|
|
2006-03-16 07:52:46 +01:00
|
|
|
return tag;
|
2004-06-01 13:18:25 +02:00
|
|
|
}
|
|
|
|
|
2009-01-14 23:09:02 +01:00
|
|
|
static void
|
|
|
|
vorbis_send_comments(struct decoder *decoder, struct input_stream *is,
|
|
|
|
char **comments)
|
2004-06-01 13:18:25 +02:00
|
|
|
{
|
2008-08-29 09:38:11 +02:00
|
|
|
struct tag *tag;
|
2004-06-01 13:18:25 +02:00
|
|
|
|
2009-01-14 23:09:02 +01:00
|
|
|
tag = vorbis_comments_to_tag(comments);
|
2006-07-20 18:02:40 +02:00
|
|
|
if (!tag)
|
|
|
|
return;
|
2004-06-01 13:18:25 +02:00
|
|
|
|
2008-11-02 17:02:28 +01:00
|
|
|
decoder_tag(decoder, is, tag);
|
2008-08-29 09:38:21 +02:00
|
|
|
tag_free(tag);
|
2004-06-01 13:18:25 +02:00
|
|
|
}
|
|
|
|
|
2006-03-16 07:52:46 +01:00
|
|
|
/* public */
|
2008-11-11 17:13:44 +01:00
|
|
|
static void
|
2009-01-14 23:09:02 +01:00
|
|
|
vorbis_stream_decode(struct decoder *decoder,
|
|
|
|
struct input_stream *input_stream)
|
2004-02-24 00:41:20 +01:00
|
|
|
{
|
|
|
|
OggVorbis_File vf;
|
2004-05-04 21:49:29 +02:00
|
|
|
ov_callbacks callbacks;
|
2006-07-20 18:02:40 +02:00
|
|
|
OggCallbackData data;
|
2008-09-07 19:19:55 +02:00
|
|
|
struct audio_format audio_format;
|
2004-06-01 12:37:13 +02:00
|
|
|
int current_section;
|
2004-06-05 07:03:00 +02:00
|
|
|
int prev_section = -1;
|
2004-06-01 12:37:13 +02:00
|
|
|
long ret;
|
|
|
|
#define OGG_CHUNK_SIZE 4096
|
|
|
|
char chunk[OGG_CHUNK_SIZE];
|
|
|
|
long bitRate = 0;
|
|
|
|
long test;
|
2009-01-14 23:09:02 +01:00
|
|
|
struct replay_gain_info *replay_gain_info = NULL;
|
2006-07-20 18:02:40 +02:00
|
|
|
char **comments;
|
2008-10-30 08:38:54 +01:00
|
|
|
bool initialized = false;
|
2008-11-11 21:21:54 +01:00
|
|
|
enum decoder_command cmd = DECODE_COMMAND_NONE;
|
2004-05-20 05:44:33 +02:00
|
|
|
|
2009-01-14 23:09:02 +01:00
|
|
|
if (ogg_stream_type_detect(input_stream) != VORBIS)
|
2008-11-11 17:13:44 +01:00
|
|
|
return;
|
2008-11-10 15:07:01 +01:00
|
|
|
|
|
|
|
/* rewind the stream, because ogg_stream_type_detect() has
|
|
|
|
moved it */
|
2009-01-14 23:09:02 +01:00
|
|
|
input_stream_seek(input_stream, 0, SEEK_SET);
|
2008-11-10 15:07:01 +01:00
|
|
|
|
2009-01-14 23:09:02 +01:00
|
|
|
data.input_stream = input_stream;
|
2008-08-26 08:27:07 +02:00
|
|
|
data.decoder = decoder;
|
2004-05-04 21:49:29 +02:00
|
|
|
|
|
|
|
callbacks.read_func = ogg_read_cb;
|
|
|
|
callbacks.seek_func = ogg_seek_cb;
|
|
|
|
callbacks.close_func = ogg_close_cb;
|
|
|
|
callbacks.tell_func = ogg_tell_cb;
|
2006-07-20 18:02:40 +02:00
|
|
|
if ((ret = ov_open_callbacks(&data, &vf, NULL, 0, callbacks)) < 0) {
|
2009-01-14 23:09:02 +01:00
|
|
|
const char *error;
|
2008-11-20 20:11:00 +01:00
|
|
|
|
2008-08-26 08:27:14 +02:00
|
|
|
if (decoder_get_command(decoder) != DECODE_COMMAND_NONE)
|
2008-11-11 17:13:44 +01:00
|
|
|
return;
|
2008-08-26 08:27:14 +02:00
|
|
|
|
|
|
|
switch (ret) {
|
|
|
|
case OV_EREAD:
|
2009-01-14 23:09:02 +01:00
|
|
|
error = "read error";
|
2008-08-26 08:27:14 +02:00
|
|
|
break;
|
|
|
|
case OV_ENOTVORBIS:
|
2009-01-14 23:09:02 +01:00
|
|
|
error = "not vorbis stream";
|
2008-08-26 08:27:14 +02:00
|
|
|
break;
|
|
|
|
case OV_EVERSION:
|
2009-01-14 23:09:02 +01:00
|
|
|
error = "vorbis version mismatch";
|
2008-08-26 08:27:14 +02:00
|
|
|
break;
|
|
|
|
case OV_EBADHEADER:
|
2009-01-14 23:09:02 +01:00
|
|
|
error = "invalid vorbis header";
|
2008-08-26 08:27:14 +02:00
|
|
|
break;
|
|
|
|
case OV_EFAULT:
|
2009-01-14 23:09:02 +01:00
|
|
|
error = "internal logic error";
|
2008-08-26 08:27:14 +02:00
|
|
|
break;
|
|
|
|
default:
|
2009-01-14 23:09:02 +01:00
|
|
|
error = "unknown error";
|
2008-08-26 08:27:14 +02:00
|
|
|
break;
|
2006-07-20 18:02:40 +02:00
|
|
|
}
|
2008-11-11 21:33:01 +01:00
|
|
|
|
2009-01-14 23:09:02 +01:00
|
|
|
g_warning("Error decoding Ogg Vorbis stream: %s", error);
|
2008-11-11 17:13:44 +01:00
|
|
|
return;
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
2008-08-26 08:27:05 +02:00
|
|
|
audio_format.bits = 16;
|
2004-06-01 12:37:13 +02:00
|
|
|
|
2008-11-11 21:21:54 +01:00
|
|
|
do {
|
|
|
|
if (cmd == DECODE_COMMAND_SEEK) {
|
2008-08-26 08:27:07 +02:00
|
|
|
double seek_where = decoder_seek_where(decoder);
|
|
|
|
if (0 == ov_time_seek_page(&vf, seek_where)) {
|
|
|
|
decoder_command_finished(decoder);
|
2006-07-20 18:02:40 +02:00
|
|
|
} else
|
2008-08-26 08:27:07 +02:00
|
|
|
decoder_seek_error(decoder);
|
2004-06-01 12:37:13 +02:00
|
|
|
}
|
2008-11-11 21:15:01 +01:00
|
|
|
|
|
|
|
ret = ov_read(&vf, chunk, sizeof(chunk),
|
2006-07-20 18:02:40 +02:00
|
|
|
OGG_DECODE_USE_BIGENDIAN, 2, 1, ¤t_section);
|
2008-11-20 12:45:17 +01:00
|
|
|
if (ret == OV_HOLE) /* bad packet */
|
|
|
|
ret = 0;
|
|
|
|
else if (ret <= 0)
|
|
|
|
/* break on EOF or other error */
|
|
|
|
break;
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (current_section != prev_section) {
|
|
|
|
/*printf("new song!\n"); */
|
|
|
|
vorbis_info *vi = ov_info(&vf, -1);
|
2008-11-11 16:19:00 +01:00
|
|
|
struct replay_gain_info *new_rgi;
|
|
|
|
|
2008-08-26 08:27:05 +02:00
|
|
|
audio_format.channels = vi->channels;
|
2008-10-10 14:40:54 +02:00
|
|
|
audio_format.sample_rate = vi->rate;
|
2008-11-21 20:27:30 +01:00
|
|
|
|
|
|
|
if (!audio_format_valid(&audio_format)) {
|
|
|
|
g_warning("Invalid audio format: %u:%u:%u\n",
|
|
|
|
audio_format.sample_rate,
|
|
|
|
audio_format.bits,
|
|
|
|
audio_format.channels);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-08-26 08:27:07 +02:00
|
|
|
if (!initialized) {
|
2008-08-26 08:27:05 +02:00
|
|
|
float total_time = ov_time_total(&vf, -1);
|
|
|
|
if (total_time < 0)
|
|
|
|
total_time = 0;
|
|
|
|
decoder_initialized(decoder, &audio_format,
|
2009-01-14 23:09:02 +01:00
|
|
|
input_stream->seekable,
|
2008-08-26 08:27:05 +02:00
|
|
|
total_time);
|
2008-10-30 08:38:54 +01:00
|
|
|
initialized = true;
|
2004-06-06 18:42:14 +02:00
|
|
|
}
|
2004-06-05 18:01:44 +02:00
|
|
|
comments = ov_comment(&vf, -1)->user_comments;
|
2009-01-14 23:09:02 +01:00
|
|
|
vorbis_send_comments(decoder, input_stream, comments);
|
|
|
|
new_rgi = vorbis_comments_to_replay_gain(comments);
|
2008-11-11 16:19:00 +01:00
|
|
|
if (new_rgi != NULL) {
|
2009-01-14 23:09:02 +01:00
|
|
|
if (replay_gain_info != NULL)
|
|
|
|
replay_gain_info_free(replay_gain_info);
|
|
|
|
replay_gain_info = new_rgi;
|
2008-11-11 16:19:00 +01:00
|
|
|
}
|
2004-06-05 18:01:44 +02:00
|
|
|
}
|
2004-06-05 07:03:00 +02:00
|
|
|
|
|
|
|
prev_section = current_section;
|
|
|
|
|
2008-11-11 21:15:01 +01:00
|
|
|
if ((test = ov_bitrate_instant(&vf)) > 0)
|
|
|
|
bitRate = test / 1000;
|
2004-06-01 12:37:13 +02:00
|
|
|
|
2009-01-14 23:09:02 +01:00
|
|
|
cmd = decoder_data(decoder, input_stream,
|
2008-11-11 21:21:54 +01:00
|
|
|
chunk, ret,
|
|
|
|
ov_pcm_tell(&vf) / audio_format.sample_rate,
|
2009-01-14 23:09:02 +01:00
|
|
|
bitRate, replay_gain_info);
|
2008-11-11 21:21:54 +01:00
|
|
|
} while (cmd != DECODE_COMMAND_STOP);
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2009-01-14 23:09:02 +01:00
|
|
|
if (replay_gain_info)
|
|
|
|
replay_gain_info_free(replay_gain_info);
|
2004-11-02 20:56:59 +01:00
|
|
|
|
2004-06-01 12:37:13 +02:00
|
|
|
ov_clear(&vf);
|
2004-02-24 00:41:20 +01:00
|
|
|
}
|
|
|
|
|
2009-01-14 23:09:02 +01:00
|
|
|
static struct tag *
|
|
|
|
vorbis_tag_dup(const char *file)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-08-29 09:38:11 +02:00
|
|
|
struct tag *ret;
|
2008-11-12 08:38:04 +01:00
|
|
|
FILE *fp;
|
2004-05-31 03:21:17 +02:00
|
|
|
OggVorbis_File vf;
|
|
|
|
|
2008-11-12 08:38:04 +01:00
|
|
|
fp = fopen(file, "r");
|
|
|
|
if (!fp) {
|
2004-05-31 03:21:17 +02:00
|
|
|
return NULL;
|
2008-11-12 08:38:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ov_open(fp, &vf, NULL, 0) < 0) {
|
|
|
|
fclose(fp);
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-05-31 03:21:17 +02:00
|
|
|
|
2009-01-14 23:09:02 +01:00
|
|
|
ret = vorbis_comments_to_tag(ov_comment(&vf, -1)->user_comments);
|
2004-05-31 05:02:17 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (!ret)
|
2008-08-29 09:38:21 +02:00
|
|
|
ret = tag_new();
|
2006-07-20 18:02:40 +02:00
|
|
|
ret->time = (int)(ov_time_total(&vf, -1) + 0.5);
|
2004-05-31 03:21:17 +02:00
|
|
|
|
|
|
|
ov_clear(&vf);
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
return ret;
|
2004-05-31 03:21:17 +02:00
|
|
|
}
|
|
|
|
|
2009-01-14 23:09:02 +01:00
|
|
|
static const char *const vorbis_suffixes[] = {
|
|
|
|
"ogg", "oga", NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char *const vorbis_mime_types[] = {
|
2008-11-01 14:55:23 +01:00
|
|
|
"application/ogg",
|
|
|
|
"audio/x-vorbis+ogg",
|
|
|
|
"application/x-ogg",
|
|
|
|
NULL
|
|
|
|
};
|
2004-05-31 03:21:17 +02:00
|
|
|
|
2009-01-14 23:09:02 +01:00
|
|
|
const struct decoder_plugin vorbis_decoder_plugin = {
|
2008-09-29 15:55:17 +02:00
|
|
|
.name = "oggvorbis",
|
2009-01-14 23:09:02 +01:00
|
|
|
.stream_decode = vorbis_stream_decode,
|
|
|
|
.tag_dup = vorbis_tag_dup,
|
|
|
|
.suffixes = vorbis_suffixes,
|
|
|
|
.mime_types = vorbis_mime_types
|
2004-05-31 03:21:17 +02:00
|
|
|
};
|