2009-03-13 18:43:16 +01:00
|
|
|
/*
|
2010-01-01 05:55:13 +01:00
|
|
|
* Copyright (C) 2003-2010 The Music Player Daemon Project
|
2009-03-13 18:43:16 +01:00
|
|
|
* http://www.musicpd.org
|
2004-02-24 00:41:20 +01:00
|
|
|
*
|
|
|
|
* 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.
|
2009-03-13 18:43:16 +01:00
|
|
|
*
|
|
|
|
* 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.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2004-02-24 00:41:20 +01:00
|
|
|
*/
|
|
|
|
|
2009-01-08 21:37:02 +01:00
|
|
|
#include "config.h"
|
2009-11-12 09:12:38 +01:00
|
|
|
#include "_ogg_common.h"
|
2009-11-10 19:01:38 +01:00
|
|
|
#include "audio_check.h"
|
2009-02-25 16:44:06 +01:00
|
|
|
#include "uri.h"
|
2005-08-25 10:07:28 +02:00
|
|
|
|
|
|
|
#ifndef HAVE_TREMOR
|
2009-10-18 17:09:32 +02:00
|
|
|
#define OV_EXCLUDE_STATIC_CALLBACKS
|
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-02-17 08:51:34 +01:00
|
|
|
#undef G_LOG_DOMAIN
|
|
|
|
#define G_LOG_DOMAIN "vorbis"
|
2009-04-03 01:07:52 +02:00
|
|
|
#define OGG_CHUNK_SIZE 4096
|
2009-02-17 08:51:34 +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
|
|
|
|
|
2010-05-30 23:57:58 +02:00
|
|
|
struct vorbis_input_stream {
|
2008-08-26 08:27:07 +02:00
|
|
|
struct decoder *decoder;
|
2009-01-17 11:43:13 +01:00
|
|
|
|
2009-01-14 23:09:02 +01:00
|
|
|
struct input_stream *input_stream;
|
2009-01-17 11:43:13 +01:00
|
|
|
bool seekable;
|
2009-11-11 21:04:32 +01:00
|
|
|
};
|
2004-05-20 05:44:33 +02:00
|
|
|
|
2010-05-30 23:57:58 +02:00
|
|
|
static size_t ogg_read_cb(void *ptr, size_t size, size_t nmemb, void *data)
|
2004-05-04 21:49:29 +02:00
|
|
|
{
|
2010-05-30 23:57:58 +02:00
|
|
|
struct vorbis_input_stream *vis = data;
|
2008-03-26 11:37:36 +01:00
|
|
|
size_t ret;
|
2006-07-20 18:02:40 +02:00
|
|
|
|
2010-05-30 23:57:58 +02:00
|
|
|
ret = decoder_read(vis->decoder, vis->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
|
|
|
}
|
|
|
|
|
2010-05-30 23:57:58 +02:00
|
|
|
static int ogg_seek_cb(void *data, ogg_int64_t offset, int whence)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2010-05-30 23:57:58 +02:00
|
|
|
struct vorbis_input_stream *vis = data;
|
2009-01-17 11:43:13 +01:00
|
|
|
|
2010-05-30 23:57:58 +02:00
|
|
|
return vis->seekable &&
|
|
|
|
decoder_get_command(vis->decoder) != DECODE_COMMAND_STOP &&
|
|
|
|
input_stream_seek(vis->input_stream, offset, whence, NULL)
|
2009-01-17 11:43:13 +01:00
|
|
|
? 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 */
|
2010-05-30 23:57:58 +02:00
|
|
|
static int ogg_close_cb(G_GNUC_UNUSED void *data)
|
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
|
|
|
}
|
|
|
|
|
2010-05-30 23:57:58 +02:00
|
|
|
static long ogg_tell_cb(void *data)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2010-05-30 23:57:58 +02:00
|
|
|
const struct vorbis_input_stream *vis = data;
|
2004-05-20 05:44:33 +02:00
|
|
|
|
2010-05-30 23:57:58 +02:00
|
|
|
return (long)vis->input_stream->offset;
|
2004-05-04 21:49:29 +02:00
|
|
|
}
|
|
|
|
|
2010-05-30 23:52:05 +02:00
|
|
|
static const ov_callbacks vorbis_is_callbacks = {
|
|
|
|
.read_func = ogg_read_cb,
|
|
|
|
.seek_func = ogg_seek_cb,
|
|
|
|
.close_func = ogg_close_cb,
|
|
|
|
.tell_func = ogg_tell_cb,
|
|
|
|
};
|
|
|
|
|
2009-11-11 21:12:10 +01:00
|
|
|
static const char *
|
|
|
|
vorbis_strerror(int code)
|
|
|
|
{
|
|
|
|
switch (code) {
|
|
|
|
case OV_EREAD:
|
|
|
|
return "read error";
|
|
|
|
|
|
|
|
case OV_ENOTVORBIS:
|
|
|
|
return "not vorbis stream";
|
|
|
|
|
|
|
|
case OV_EVERSION:
|
|
|
|
return "vorbis version mismatch";
|
|
|
|
|
|
|
|
case OV_EBADHEADER:
|
|
|
|
return "invalid vorbis header";
|
|
|
|
|
|
|
|
case OV_EFAULT:
|
|
|
|
return "internal logic error";
|
|
|
|
|
|
|
|
default:
|
|
|
|
return "unknown error";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-30 23:50:17 +02:00
|
|
|
static bool
|
|
|
|
vorbis_is_open(struct vorbis_input_stream *vis, OggVorbis_File *vf,
|
|
|
|
struct decoder *decoder, struct input_stream *input_stream)
|
|
|
|
{
|
|
|
|
vis->decoder = decoder;
|
|
|
|
vis->input_stream = input_stream;
|
|
|
|
vis->seekable = input_stream->seekable &&
|
|
|
|
(input_stream->uri == NULL ||
|
|
|
|
!uri_has_scheme(input_stream->uri));
|
|
|
|
|
|
|
|
int ret = ov_open_callbacks(vis, vf, NULL, 0, vorbis_is_callbacks);
|
|
|
|
if (ret < 0) {
|
|
|
|
if (decoder == NULL ||
|
|
|
|
decoder_get_command(decoder) == DECODE_COMMAND_NONE)
|
|
|
|
g_warning("Failed to open Ogg Vorbis stream: %s",
|
|
|
|
vorbis_strerror(ret));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-02-14 20:36:31 +01:00
|
|
|
static bool
|
|
|
|
vorbis_comments_to_replay_gain(struct replay_gain_info *rgi, char **comments)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
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
|
|
|
|
2010-02-14 20:36:31 +01:00
|
|
|
replay_gain_info_init(rgi);
|
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
|
|
|
|
2010-02-14 20:36:31 +01:00
|
|
|
return found;
|
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,
|
2009-10-13 16:12:45 +02:00
|
|
|
TAG_TRACK) ||
|
2009-01-14 23:21:45 +01:00
|
|
|
vorbis_copy_comment(tag, comment, VORBIS_COMMENT_DISC_KEY,
|
2009-10-13 16:12:45 +02:00
|
|
|
TAG_DISC) ||
|
2009-01-15 00:42:35 +01:00
|
|
|
vorbis_copy_comment(tag, comment, "album artist",
|
2009-10-13 16:12:45 +02:00
|
|
|
TAG_ALBUM_ARTIST))
|
2009-01-14 23:21:45 +01:00
|
|
|
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,
|
2009-02-27 09:01:55 +01:00
|
|
|
tag_item_names[i], i))
|
2009-01-14 23:21:45 +01:00
|
|
|
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
|
|
|
{
|
2009-11-10 19:01:38 +01:00
|
|
|
GError *error = NULL;
|
2004-02-24 00:41:20 +01:00
|
|
|
OggVorbis_File vf;
|
2010-05-30 23:57:58 +02:00
|
|
|
struct vorbis_input_stream vis;
|
2008-09-07 19:19:55 +02:00
|
|
|
struct audio_format audio_format;
|
2009-11-11 21:34:55 +01:00
|
|
|
float total_time;
|
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;
|
|
|
|
char chunk[OGG_CHUNK_SIZE];
|
|
|
|
long bitRate = 0;
|
|
|
|
long test;
|
2009-11-11 21:34:55 +01:00
|
|
|
const vorbis_info *vi;
|
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-11-14 23:53:04 +01:00
|
|
|
input_stream_seek(input_stream, 0, SEEK_SET, NULL);
|
2008-11-10 15:07:01 +01:00
|
|
|
|
2010-05-30 23:50:17 +02:00
|
|
|
if (!vorbis_is_open(&vis, &vf, decoder, input_stream))
|
2008-11-11 17:13:44 +01:00
|
|
|
return;
|
2004-06-01 12:37:13 +02:00
|
|
|
|
2009-11-11 21:34:55 +01:00
|
|
|
vi = ov_info(&vf, -1);
|
|
|
|
if (vi == NULL) {
|
|
|
|
g_warning("ov_info() has failed");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-11-10 17:11:34 +01:00
|
|
|
if (!audio_format_init_checked(&audio_format, vi->rate,
|
|
|
|
SAMPLE_FORMAT_S16,
|
2009-11-10 19:01:38 +01:00
|
|
|
vi->channels, &error)) {
|
|
|
|
g_warning("%s", error->message);
|
|
|
|
g_error_free(error);
|
2009-11-11 21:34:55 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
total_time = ov_time_total(&vf, -1);
|
|
|
|
if (total_time < 0)
|
|
|
|
total_time = 0;
|
|
|
|
|
2010-05-30 23:57:58 +02:00
|
|
|
decoder_initialized(decoder, &audio_format, vis.seekable, total_time);
|
2009-11-11 21:34:55 +01: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) {
|
2009-11-11 21:34:55 +01:00
|
|
|
char **comments;
|
2008-11-11 16:19:00 +01:00
|
|
|
|
2009-11-11 21:34:55 +01:00
|
|
|
vi = ov_info(&vf, -1);
|
|
|
|
if (vi == NULL) {
|
|
|
|
g_warning("ov_info() has failed");
|
2008-11-21 20:27:30 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-11-12 09:16:34 +01:00
|
|
|
if (vi->rate != (long)audio_format.sample_rate ||
|
|
|
|
vi->channels != (int)audio_format.channels) {
|
2009-11-11 21:34:55 +01:00
|
|
|
/* we don't support audio format
|
|
|
|
change yet */
|
|
|
|
g_warning("audio format change, stopping here");
|
|
|
|
break;
|
2004-06-06 18:42:14 +02:00
|
|
|
}
|
2009-11-11 21:34:55 +01: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);
|
2010-02-14 20:36:31 +01:00
|
|
|
|
|
|
|
struct replay_gain_info rgi;
|
|
|
|
if (vorbis_comments_to_replay_gain(&rgi, comments))
|
|
|
|
decoder_replay_gain(decoder, &rgi);
|
2004-06-05 07:03:00 +02:00
|
|
|
|
2009-11-11 21:34:55 +01:00
|
|
|
prev_section = current_section;
|
|
|
|
}
|
2004-06-05 07:03:00 +02:00
|
|
|
|
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,
|
2010-01-03 22:44:23 +01:00
|
|
|
bitRate);
|
2008-11-11 21:21:54 +01:00
|
|
|
} while (cmd != DECODE_COMMAND_STOP);
|
2004-02-24 00:41:20 +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 *
|
2010-05-31 00:02:57 +02:00
|
|
|
vorbis_stream_tag(struct input_stream *is)
|
2006-07-20 18:02:40 +02:00
|
|
|
{
|
2010-05-31 00:02:57 +02:00
|
|
|
struct vorbis_input_stream vis;
|
2004-05-31 03:21:17 +02:00
|
|
|
OggVorbis_File vf;
|
|
|
|
|
2010-05-31 00:02:57 +02:00
|
|
|
if (!vorbis_is_open(&vis, &vf, NULL, is))
|
2004-05-31 03:21:17 +02:00
|
|
|
return NULL;
|
|
|
|
|
2010-05-31 00:06:37 +02:00
|
|
|
struct tag *tag = vorbis_comments_to_tag(ov_comment(&vf, -1)->user_comments);
|
2004-05-31 05:02:17 +02:00
|
|
|
|
2010-05-31 00:06:37 +02:00
|
|
|
if (tag == NULL)
|
|
|
|
tag = tag_new();
|
|
|
|
tag->time = (int)(ov_time_total(&vf, -1) + 0.5);
|
2004-05-31 03:21:17 +02:00
|
|
|
|
|
|
|
ov_clear(&vf);
|
|
|
|
|
2010-05-31 00:06:37 +02:00
|
|
|
return tag;
|
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",
|
|
|
|
"application/x-ogg",
|
2009-12-29 22:33:46 +01:00
|
|
|
"audio/ogg",
|
|
|
|
"audio/vorbis",
|
|
|
|
"audio/vorbis+ogg",
|
|
|
|
"audio/x-ogg",
|
|
|
|
"audio/x-vorbis",
|
|
|
|
"audio/x-vorbis+ogg",
|
2008-11-01 14:55:23 +01:00
|
|
|
NULL
|
|
|
|
};
|
2004-05-31 03:21:17 +02:00
|
|
|
|
2009-01-14 23:09:02 +01:00
|
|
|
const struct decoder_plugin vorbis_decoder_plugin = {
|
2009-02-16 19:31:06 +01:00
|
|
|
.name = "vorbis",
|
2009-01-14 23:09:02 +01:00
|
|
|
.stream_decode = vorbis_stream_decode,
|
2010-05-31 00:02:57 +02:00
|
|
|
.stream_tag = vorbis_stream_tag,
|
2009-01-14 23:09:02 +01:00
|
|
|
.suffixes = vorbis_suffixes,
|
|
|
|
.mime_types = vorbis_mime_types
|
2004-05-31 03:21:17 +02:00
|
|
|
};
|