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"
|
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>
|
|
|
|
#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
|
|
|
|
2004-03-09 22:42:08 +01:00
|
|
|
#ifdef WORDS_BIGENDIAN
|
|
|
|
#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-10-26 19:54:57 +01:00
|
|
|
struct input_stream *inStream;
|
2008-08-26 08:27:07 +02:00
|
|
|
struct decoder *decoder;
|
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;
|
|
|
|
|
2008-08-26 08:27:14 +02:00
|
|
|
ret = decoder_read(data->decoder, data->inStream, ptr, size * nmemb);
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
errno = 0;
|
2008-10-26 19:54:57 +01:00
|
|
|
/*if(ret<0) errno = ((struct input_stream *)inStream)->error; */
|
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;
|
2008-10-26 20:56:46 +01:00
|
|
|
return input_stream_seek(data->inStream, 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
|
|
|
|
|
|
|
return (long)(data->inStream->offset);
|
2004-05-04 21:49:29 +02:00
|
|
|
}
|
|
|
|
|
2008-02-05 11:17:33 +01:00
|
|
|
static const char *ogg_parseComment(const char *comment, const char *needle)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
|
|
|
int len = strlen(needle);
|
2004-05-08 14:00:30 +02:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (strncasecmp(comment, needle, len) == 0 && *(comment + len) == '=') {
|
|
|
|
return comment + len + 1;
|
2004-05-31 04:21:06 +02:00
|
|
|
}
|
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 *
|
|
|
|
ogg_getReplayGainInfo(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 =
|
|
|
|
ogg_parseComment(*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;
|
2006-07-20 18:02:40 +02:00
|
|
|
} else if ((temp = ogg_parseComment(*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;
|
2006-07-20 18:02:40 +02:00
|
|
|
} else if ((temp = ogg_parseComment(*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;
|
2006-07-20 18:02:40 +02:00
|
|
|
} else if ((temp = ogg_parseComment(*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
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
static unsigned int ogg_parseCommentAddToTag(char *comment,
|
|
|
|
unsigned int itemType,
|
2008-08-29 09:38:11 +02:00
|
|
|
struct tag ** tag)
|
2006-03-16 07:52:46 +01:00
|
|
|
{
|
2006-07-20 18:02:40 +02:00
|
|
|
const char *needle;
|
2006-06-04 13:36:02 +02:00
|
|
|
unsigned int len;
|
2006-04-30 21:55:56 +02:00
|
|
|
switch (itemType) {
|
2006-07-20 18:02:40 +02:00
|
|
|
case TAG_ITEM_TRACK:
|
|
|
|
needle = VORBIS_COMMENT_TRACK_KEY;
|
|
|
|
break;
|
|
|
|
case TAG_ITEM_DISC:
|
|
|
|
needle = VORBIS_COMMENT_DISC_KEY;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
needle = mpdTagItemKeys[itemType];
|
2006-04-30 21:55:56 +02:00
|
|
|
}
|
2006-06-04 13:36:02 +02:00
|
|
|
len = strlen(needle);
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (strncasecmp(comment, needle, len) == 0 && *(comment + len) == '=') {
|
2006-03-16 07:52:46 +01:00
|
|
|
if (!*tag)
|
2008-08-29 09:38:21 +02:00
|
|
|
*tag = tag_new();
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2008-08-29 09:38:21 +02:00
|
|
|
tag_add_item(*tag, itemType, comment + len + 1);
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2006-03-16 07:52:46 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2006-03-16 07:52:46 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2004-06-01 13:18:25 +02:00
|
|
|
|
2008-08-29 09:38:11 +02:00
|
|
|
static struct tag *oggCommentsParse(char **comments)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2008-08-29 09:38:11 +02:00
|
|
|
struct tag *tag = NULL;
|
2006-07-20 18:02:40 +02:00
|
|
|
|
|
|
|
while (*comments) {
|
2006-04-18 08:17:48 +02:00
|
|
|
int j;
|
2006-07-20 18:02:40 +02:00
|
|
|
for (j = TAG_NUM_OF_ITEM_TYPES; --j >= 0;) {
|
2006-03-16 07:52:46 +01:00
|
|
|
if (ogg_parseCommentAddToTag(*comments, j, &tag))
|
|
|
|
break;
|
2005-03-05 23:24:10 +01:00
|
|
|
}
|
2004-06-01 13:18:25 +02:00
|
|
|
comments++;
|
|
|
|
}
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2006-03-16 07:52:46 +01:00
|
|
|
return tag;
|
2004-06-01 13:18:25 +02:00
|
|
|
}
|
|
|
|
|
2008-11-02 17:02:28 +01:00
|
|
|
static void putOggCommentsIntoOutputBuffer(struct decoder *decoder,
|
|
|
|
struct input_stream *is,
|
2006-07-20 18:02:40 +02:00
|
|
|
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
|
|
|
|
|
|
|
tag = oggCommentsParse(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
|
2008-10-26 19:54:57 +01:00
|
|
|
oggvorbis_decode(struct decoder *decoder, struct input_stream *inStream)
|
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;
|
2008-11-11 15:55:34 +01:00
|
|
|
struct replay_gain_info *replayGainInfo = 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
|
|
|
|
2008-11-10 15:07:01 +01:00
|
|
|
if (ogg_stream_type_detect(inStream) != 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 */
|
|
|
|
input_stream_seek(inStream, 0, SEEK_SET);
|
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
data.inStream = inStream;
|
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) {
|
2008-11-20 20:11:00 +01:00
|
|
|
const char *errorStr;
|
|
|
|
|
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:
|
|
|
|
errorStr = "read error";
|
|
|
|
break;
|
|
|
|
case OV_ENOTVORBIS:
|
|
|
|
errorStr = "not vorbis stream";
|
|
|
|
break;
|
|
|
|
case OV_EVERSION:
|
|
|
|
errorStr = "vorbis version mismatch";
|
|
|
|
break;
|
|
|
|
case OV_EBADHEADER:
|
|
|
|
errorStr = "invalid vorbis header";
|
|
|
|
break;
|
|
|
|
case OV_EFAULT:
|
|
|
|
errorStr = "internal logic error";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
errorStr = "unknown error";
|
|
|
|
break;
|
2006-07-20 18:02:40 +02:00
|
|
|
}
|
2008-11-11 21:33:01 +01:00
|
|
|
|
|
|
|
g_warning("Error decoding Ogg Vorbis stream: %s\n",
|
|
|
|
errorStr);
|
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,
|
2008-11-02 17:01:51 +01:00
|
|
|
inStream->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;
|
2008-11-02 17:02:28 +01:00
|
|
|
putOggCommentsIntoOutputBuffer(decoder, inStream,
|
2006-07-20 18:02:40 +02:00
|
|
|
comments);
|
2008-11-11 16:19:00 +01:00
|
|
|
new_rgi = ogg_getReplayGainInfo(comments);
|
|
|
|
if (new_rgi != NULL) {
|
|
|
|
if (replayGainInfo != NULL)
|
|
|
|
replay_gain_info_free(replayGainInfo);
|
|
|
|
replayGainInfo = new_rgi;
|
|
|
|
}
|
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
|
|
|
|
2008-11-11 21:21:54 +01:00
|
|
|
cmd = decoder_data(decoder, inStream,
|
|
|
|
chunk, ret,
|
|
|
|
ov_pcm_tell(&vf) / audio_format.sample_rate,
|
|
|
|
bitRate, replayGainInfo);
|
|
|
|
} while (cmd != DECODE_COMMAND_STOP);
|
2004-02-24 00:41:20 +01:00
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
if (replayGainInfo)
|
2008-11-11 15:55:34 +01:00
|
|
|
replay_gain_info_free(replayGainInfo);
|
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
|
|
|
}
|
|
|
|
|
2008-10-31 15:56:43 +01:00
|
|
|
static struct tag *oggvorbis_TagDup(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
|
|
|
|
2006-07-20 18:02:40 +02:00
|
|
|
ret = oggCommentsParse(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
|
|
|
}
|
|
|
|
|
2008-11-01 14:55:23 +01:00
|
|
|
static const char *const oggvorbis_Suffixes[] = { "ogg","oga", NULL };
|
|
|
|
static const char *const oggvorbis_MimeTypes[] = {
|
|
|
|
"application/ogg",
|
|
|
|
"audio/x-vorbis+ogg",
|
|
|
|
"application/x-ogg",
|
|
|
|
NULL
|
|
|
|
};
|
2004-05-31 03:21:17 +02:00
|
|
|
|
2008-11-01 14:54:09 +01:00
|
|
|
const struct decoder_plugin oggvorbisPlugin = {
|
2008-09-29 15:55:17 +02:00
|
|
|
.name = "oggvorbis",
|
|
|
|
.stream_decode = oggvorbis_decode,
|
|
|
|
.tag_dup = oggvorbis_TagDup,
|
|
|
|
.suffixes = oggvorbis_Suffixes,
|
|
|
|
.mime_types = oggvorbis_MimeTypes
|
2004-05-31 03:21:17 +02:00
|
|
|
};
|