2002-05-31 23:37:28 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2002-05-31 23:37:28 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <gst/gst.h>
|
|
|
|
#include <vorbis/codec.h>
|
|
|
|
#include <vorbis/vorbisfile.h>
|
2002-06-02 22:16:51 +00:00
|
|
|
#include <gst/bytestream/bytestream.h>
|
2002-05-31 23:37:28 +00:00
|
|
|
|
|
|
|
#define GST_TYPE_VORBISFILE \
|
|
|
|
(vorbisfile_get_type())
|
|
|
|
#define GST_VORBISFILE(obj) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_VORBISFILE,VorbisFile))
|
|
|
|
#define GST_VORBISFILE_CLASS(klass) \
|
|
|
|
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_VORBISFILE,VorbisFileClass))
|
|
|
|
#define GST_IS_VORBISFILE(obj) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_VORBISFILE))
|
|
|
|
#define GST_IS_VORBISFILE_CLASS(obj) \
|
|
|
|
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_VORBISFILE))
|
|
|
|
|
|
|
|
typedef struct _VorbisFile VorbisFile;
|
|
|
|
typedef struct _VorbisFileClass VorbisFileClass;
|
|
|
|
|
|
|
|
struct _VorbisFile {
|
2003-05-29 13:02:16 +00:00
|
|
|
GstElement element;
|
2002-05-31 23:37:28 +00:00
|
|
|
|
2003-05-29 13:02:16 +00:00
|
|
|
GstPad *sinkpad,
|
|
|
|
*srcpad;
|
2002-05-31 23:37:28 +00:00
|
|
|
GstByteStream *bs;
|
|
|
|
|
|
|
|
OggVorbis_File vf;
|
2003-05-29 13:02:16 +00:00
|
|
|
gint current_link;
|
|
|
|
|
|
|
|
gboolean restart;
|
|
|
|
gboolean need_discont;
|
|
|
|
gboolean eos;
|
|
|
|
gboolean seek_pending;
|
|
|
|
gint64 seek_value;
|
|
|
|
GstFormat seek_format;
|
|
|
|
gboolean seek_accurate;
|
|
|
|
|
|
|
|
gboolean may_eos;
|
|
|
|
guint64 total_bytes;
|
|
|
|
guint64 offset;
|
|
|
|
gulong blocksize;
|
|
|
|
|
|
|
|
GstCaps *metadata;
|
|
|
|
GstCaps *streaminfo;
|
2002-05-31 23:37:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _VorbisFileClass {
|
|
|
|
GstElementClass parent_class;
|
2002-10-29 02:05:37 +00:00
|
|
|
|
2002-05-31 23:37:28 +00:00
|
|
|
};
|
|
|
|
|
2002-10-29 02:05:37 +00:00
|
|
|
GType vorbisfile_get_type (void);
|
2002-05-31 23:37:28 +00:00
|
|
|
|
2002-07-28 19:51:29 +00:00
|
|
|
extern GstPadTemplate *gst_vorbisdec_src_template, *gst_vorbisdec_sink_template;
|
2002-05-31 23:37:28 +00:00
|
|
|
|
|
|
|
/* elementfactory information */
|
|
|
|
GstElementDetails vorbisfile_details =
|
|
|
|
{
|
|
|
|
"Ogg Vorbis decoder",
|
|
|
|
"Codec/Audio/Decoder",
|
2003-07-09 02:07:14 +00:00
|
|
|
"LGPL",
|
2002-05-31 23:37:28 +00:00
|
|
|
"Decodes OGG Vorbis audio using the vorbisfile API",
|
|
|
|
VERSION,
|
|
|
|
"Monty <monty@xiph.org>, "
|
|
|
|
"Wim Taymans <wim.taymans@chello.be>",
|
|
|
|
"(C) 2000",
|
|
|
|
};
|
|
|
|
|
|
|
|
/* VorbisFile signals and args */
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
2003-05-29 13:02:16 +00:00
|
|
|
#define DEFAULT_BLOCKSIZE 4096
|
|
|
|
|
2002-05-31 23:37:28 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
ARG_0,
|
2003-05-29 13:02:16 +00:00
|
|
|
ARG_BLOCKSIZE,
|
2002-10-29 02:05:37 +00:00
|
|
|
ARG_METADATA,
|
2002-11-10 00:38:57 +00:00
|
|
|
ARG_STREAMINFO
|
2002-05-31 23:37:28 +00:00
|
|
|
};
|
|
|
|
|
2002-10-29 02:05:37 +00:00
|
|
|
static void
|
|
|
|
gst_vorbisfile_class_init (VorbisFileClass *klass);
|
|
|
|
static void gst_vorbisfile_init (VorbisFile *vorbisfile);
|
2002-05-31 23:37:28 +00:00
|
|
|
|
|
|
|
static GstElementStateReturn
|
2002-10-29 02:05:37 +00:00
|
|
|
gst_vorbisfile_change_state (GstElement *element);
|
|
|
|
|
|
|
|
static const
|
|
|
|
GstFormat* gst_vorbisfile_get_formats (GstPad *pad);
|
|
|
|
static gboolean gst_vorbisfile_src_convert (GstPad *pad,
|
|
|
|
GstFormat src_format,
|
|
|
|
gint64 src_value,
|
|
|
|
GstFormat *dest_format,
|
|
|
|
gint64 *dest_value);
|
2002-11-02 13:48:08 +00:00
|
|
|
static gboolean gst_vorbisfile_sink_convert (GstPad *pad,
|
|
|
|
GstFormat src_format,
|
|
|
|
gint64 src_value,
|
|
|
|
GstFormat *dest_format,
|
|
|
|
gint64 *dest_value);
|
2002-12-30 17:53:18 +00:00
|
|
|
static const GstQueryType*
|
2002-10-29 02:05:37 +00:00
|
|
|
gst_vorbisfile_get_query_types (GstPad *pad);
|
|
|
|
|
|
|
|
static gboolean gst_vorbisfile_src_query (GstPad *pad,
|
2002-12-30 17:53:18 +00:00
|
|
|
GstQueryType type,
|
2002-10-29 02:05:37 +00:00
|
|
|
GstFormat *format,
|
|
|
|
gint64 *value);
|
|
|
|
static const
|
|
|
|
GstEventMask* gst_vorbisfile_get_event_masks (GstPad *pad);
|
|
|
|
static gboolean gst_vorbisfile_src_event (GstPad *pad, GstEvent *event);
|
|
|
|
|
|
|
|
static void gst_vorbisfile_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
static void gst_vorbisfile_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec);
|
|
|
|
|
|
|
|
static void gst_vorbisfile_loop (GstElement *element);
|
2002-05-31 23:37:28 +00:00
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
2002-11-02 13:48:08 +00:00
|
|
|
//static guint gst_vorbisfile_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
|
|
|
static GstFormat logical_stream_format;
|
2002-05-31 23:37:28 +00:00
|
|
|
|
|
|
|
GType
|
|
|
|
vorbisfile_get_type (void)
|
|
|
|
{
|
|
|
|
static GType vorbisfile_type = 0;
|
|
|
|
|
|
|
|
if (!vorbisfile_type) {
|
|
|
|
static const GTypeInfo vorbisfile_info = {
|
2002-10-29 02:05:37 +00:00
|
|
|
sizeof (VorbisFileClass), NULL, NULL,
|
|
|
|
(GClassInitFunc) gst_vorbisfile_class_init, NULL, NULL,
|
|
|
|
sizeof (VorbisFile), 0,
|
2002-05-31 23:37:28 +00:00
|
|
|
(GInstanceInitFunc) gst_vorbisfile_init,
|
|
|
|
};
|
|
|
|
|
2002-10-29 02:05:37 +00:00
|
|
|
vorbisfile_type = g_type_register_static (GST_TYPE_ELEMENT, "VorbisFile",
|
|
|
|
&vorbisfile_info, 0);
|
2002-11-02 13:48:08 +00:00
|
|
|
|
|
|
|
logical_stream_format = gst_format_register ("logical_stream", "The logical stream");
|
2002-05-31 23:37:28 +00:00
|
|
|
}
|
|
|
|
return vorbisfile_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vorbisfile_class_init (VorbisFileClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
|
|
|
gobject_class = (GObjectClass*) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
|
|
|
|
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
|
|
|
|
2003-05-29 13:02:16 +00:00
|
|
|
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_BLOCKSIZE,
|
|
|
|
g_param_spec_ulong ("blocksize", "Block size", "Size in bytes to read per buffer",
|
|
|
|
1, G_MAXULONG, DEFAULT_BLOCKSIZE, G_PARAM_READWRITE));
|
2002-10-29 02:05:37 +00:00
|
|
|
g_object_class_install_property (gobject_class, ARG_METADATA,
|
2002-11-02 13:48:08 +00:00
|
|
|
g_param_spec_boxed ("metadata", "Metadata", "(logical) Stream metadata",
|
2002-10-29 02:05:37 +00:00
|
|
|
GST_TYPE_CAPS, G_PARAM_READABLE));
|
2002-11-10 00:38:57 +00:00
|
|
|
g_object_class_install_property (gobject_class, ARG_STREAMINFO,
|
|
|
|
g_param_spec_boxed ("streaminfo", "stream", "(logical) Stream information",
|
|
|
|
GST_TYPE_CAPS, G_PARAM_READABLE));
|
2002-05-31 23:37:28 +00:00
|
|
|
|
|
|
|
gobject_class->get_property = gst_vorbisfile_get_property;
|
2002-10-29 02:05:37 +00:00
|
|
|
gobject_class->set_property = gst_vorbisfile_set_property;
|
|
|
|
|
2002-05-31 23:37:28 +00:00
|
|
|
gstelement_class->change_state = gst_vorbisfile_change_state;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_vorbisfile_init (VorbisFile * vorbisfile)
|
|
|
|
{
|
2002-10-29 02:05:37 +00:00
|
|
|
vorbisfile->sinkpad = gst_pad_new_from_template (gst_vorbisdec_sink_template,
|
|
|
|
"sink");
|
2002-05-31 23:37:28 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (vorbisfile), vorbisfile->sinkpad);
|
2002-11-02 13:48:08 +00:00
|
|
|
gst_pad_set_formats_function (vorbisfile->sinkpad, gst_vorbisfile_get_formats);
|
|
|
|
gst_pad_set_convert_function (vorbisfile->sinkpad, gst_vorbisfile_sink_convert);
|
2002-05-31 23:37:28 +00:00
|
|
|
|
|
|
|
gst_element_set_loop_function (GST_ELEMENT (vorbisfile), gst_vorbisfile_loop);
|
2002-10-29 02:05:37 +00:00
|
|
|
vorbisfile->srcpad = gst_pad_new_from_template (gst_vorbisdec_src_template,
|
|
|
|
"src");
|
2002-05-31 23:37:28 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (vorbisfile), vorbisfile->srcpad);
|
2002-07-24 21:40:16 +00:00
|
|
|
gst_pad_set_formats_function (vorbisfile->srcpad, gst_vorbisfile_get_formats);
|
2002-10-29 02:05:37 +00:00
|
|
|
gst_pad_set_query_type_function (vorbisfile->srcpad,
|
|
|
|
gst_vorbisfile_get_query_types);
|
2002-05-31 23:37:28 +00:00
|
|
|
gst_pad_set_query_function (vorbisfile->srcpad, gst_vorbisfile_src_query);
|
2002-10-29 02:05:37 +00:00
|
|
|
gst_pad_set_event_mask_function (vorbisfile->srcpad,
|
|
|
|
gst_vorbisfile_get_event_masks);
|
2002-05-31 23:37:28 +00:00
|
|
|
gst_pad_set_event_function (vorbisfile->srcpad, gst_vorbisfile_src_event);
|
2002-07-24 21:40:16 +00:00
|
|
|
gst_pad_set_convert_function (vorbisfile->srcpad, gst_vorbisfile_src_convert);
|
2002-05-31 23:37:28 +00:00
|
|
|
|
|
|
|
vorbisfile->total_bytes = 0;
|
|
|
|
vorbisfile->offset = 0;
|
|
|
|
vorbisfile->seek_pending = 0;
|
|
|
|
vorbisfile->need_discont = FALSE;
|
2002-10-29 02:05:37 +00:00
|
|
|
vorbisfile->metadata = NULL;
|
2002-11-10 00:38:57 +00:00
|
|
|
vorbisfile->streaminfo = NULL;
|
2002-11-02 13:48:08 +00:00
|
|
|
vorbisfile->current_link = -1;
|
2003-05-29 13:02:16 +00:00
|
|
|
vorbisfile->blocksize = DEFAULT_BLOCKSIZE;
|
2002-05-31 23:37:28 +00:00
|
|
|
}
|
|
|
|
|
2002-10-29 02:05:37 +00:00
|
|
|
/* the next four functions are the ov callbacks we provide to vorbisfile
|
|
|
|
* which interface between GStreamer's handling of the data flow and
|
|
|
|
* vorbis's needs */
|
2002-05-31 23:37:28 +00:00
|
|
|
static size_t
|
|
|
|
gst_vorbisfile_read (void *ptr, size_t size, size_t nmemb, void *datasource)
|
|
|
|
{
|
2003-01-19 20:11:13 +00:00
|
|
|
guint32 got_bytes;
|
2002-05-31 23:37:28 +00:00
|
|
|
guint8 *data;
|
2003-02-02 22:05:53 +00:00
|
|
|
guint32 read_size = size * nmemb;
|
2002-05-31 23:37:28 +00:00
|
|
|
|
|
|
|
VorbisFile *vorbisfile = GST_VORBISFILE (datasource);
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("read %d", read_size);
|
2002-05-31 23:37:28 +00:00
|
|
|
|
|
|
|
/* make sure we don't go to EOS */
|
|
|
|
if (!vorbisfile->may_eos && vorbisfile->total_bytes &&
|
|
|
|
vorbisfile->offset + read_size > vorbisfile->total_bytes)
|
|
|
|
{
|
|
|
|
read_size = vorbisfile->total_bytes - vorbisfile->offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (read_size == 0 || vorbisfile->eos)
|
|
|
|
return 0;
|
|
|
|
|
2003-01-19 20:11:13 +00:00
|
|
|
do {
|
2002-05-31 23:37:28 +00:00
|
|
|
got_bytes = gst_bytestream_peek_bytes (vorbisfile->bs, &data, read_size);
|
2003-01-19 20:11:13 +00:00
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("peek returned %d", got_bytes);
|
2003-02-02 22:05:53 +00:00
|
|
|
|
2003-01-19 20:11:13 +00:00
|
|
|
if (got_bytes == 0) {
|
2002-05-31 23:37:28 +00:00
|
|
|
GstEvent *event;
|
|
|
|
guint32 avail;
|
|
|
|
|
|
|
|
gst_bytestream_get_status (vorbisfile->bs, &avail, &event);
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_EOS:
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("eos");
|
2002-05-31 23:37:28 +00:00
|
|
|
vorbisfile->eos = TRUE;
|
2003-01-19 20:11:13 +00:00
|
|
|
gst_event_unref (event);
|
|
|
|
goto done;
|
2002-05-31 23:37:28 +00:00
|
|
|
case GST_EVENT_DISCONTINUOUS:
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("discont");
|
2002-05-31 23:37:28 +00:00
|
|
|
vorbisfile->need_discont = TRUE;
|
|
|
|
default:
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("unknown event %d", GST_EVENT_TYPE (event));
|
2002-05-31 23:37:28 +00:00
|
|
|
break;
|
|
|
|
}
|
2002-07-08 19:38:27 +00:00
|
|
|
gst_event_unref (event);
|
2002-05-31 23:37:28 +00:00
|
|
|
}
|
2003-01-19 20:11:13 +00:00
|
|
|
} while (got_bytes == 0);
|
2002-05-31 23:37:28 +00:00
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("read %d got %d bytes", read_size, got_bytes);
|
2003-02-02 22:05:53 +00:00
|
|
|
|
2002-05-31 23:37:28 +00:00
|
|
|
memcpy (ptr, data, got_bytes);
|
|
|
|
gst_bytestream_flush_fast (vorbisfile->bs, got_bytes);
|
|
|
|
|
|
|
|
vorbisfile->offset += got_bytes;
|
|
|
|
|
2003-01-19 20:11:13 +00:00
|
|
|
done:
|
2002-05-31 23:37:28 +00:00
|
|
|
return got_bytes / size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gst_vorbisfile_seek (void *datasource, int64_t offset, int whence)
|
|
|
|
{
|
|
|
|
VorbisFile *vorbisfile = GST_VORBISFILE (datasource);
|
|
|
|
GstSeekType method;
|
|
|
|
guint64 pending_offset = vorbisfile->offset;
|
|
|
|
gboolean need_total = FALSE;
|
|
|
|
|
|
|
|
if (!vorbisfile->vf.seekable) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("seek %" G_GINT64_FORMAT " %d", offset, whence);
|
2002-05-31 23:37:28 +00:00
|
|
|
|
|
|
|
if (whence == SEEK_SET) {
|
|
|
|
method = GST_SEEK_METHOD_SET;
|
|
|
|
pending_offset = offset;
|
|
|
|
}
|
|
|
|
else if (whence == SEEK_CUR) {
|
|
|
|
method = GST_SEEK_METHOD_CUR;
|
|
|
|
pending_offset += offset;
|
|
|
|
}
|
|
|
|
else if (whence == SEEK_END) {
|
|
|
|
method = GST_SEEK_METHOD_END;
|
|
|
|
need_total = TRUE;
|
|
|
|
pending_offset = vorbisfile->total_bytes - offset;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (!gst_bytestream_seek (vorbisfile->bs, offset, method))
|
|
|
|
return -1;
|
|
|
|
|
2003-04-24 18:56:47 +00:00
|
|
|
vorbisfile->eos = FALSE;
|
2002-05-31 23:37:28 +00:00
|
|
|
vorbisfile->offset = pending_offset;
|
|
|
|
if (need_total)
|
|
|
|
vorbisfile->total_bytes = gst_bytestream_tell (vorbisfile->bs) + offset;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
gst_vorbisfile_close (void *datasource)
|
|
|
|
{
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("close");
|
2002-05-31 23:37:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static long
|
|
|
|
gst_vorbisfile_tell (void *datasource)
|
|
|
|
{
|
|
|
|
VorbisFile *vorbisfile = GST_VORBISFILE (datasource);
|
|
|
|
long result;
|
|
|
|
|
|
|
|
result = gst_bytestream_tell (vorbisfile->bs);
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("tell %ld", result);
|
2002-05-31 23:37:28 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
ov_callbacks vorbisfile_ov_callbacks =
|
|
|
|
{
|
|
|
|
gst_vorbisfile_read,
|
|
|
|
gst_vorbisfile_seek,
|
|
|
|
gst_vorbisfile_close,
|
|
|
|
gst_vorbisfile_tell,
|
|
|
|
};
|
|
|
|
|
2002-11-10 00:38:57 +00:00
|
|
|
/* retrieve the comment field (or tags) and put in metadata GstCaps
|
2002-11-09 18:34:48 +00:00
|
|
|
* returns TRUE if caps could be set,
|
2002-10-29 02:05:37 +00:00
|
|
|
* FALSE if they couldn't be read somehow */
|
|
|
|
static gboolean
|
2002-11-10 00:38:57 +00:00
|
|
|
gst_vorbisfile_update_metadata (VorbisFile *vorbisfile, gint link)
|
2002-10-29 02:05:37 +00:00
|
|
|
{
|
|
|
|
OggVorbis_File *vf = &vorbisfile->vf;
|
2002-11-02 13:48:08 +00:00
|
|
|
gchar **ptr;
|
|
|
|
vorbis_comment *vc;
|
2002-10-29 02:05:37 +00:00
|
|
|
GstProps *props = NULL;
|
|
|
|
GstPropsEntry *entry;
|
|
|
|
gchar *name, *value;
|
|
|
|
|
|
|
|
/* clear old one */
|
2002-11-10 00:38:57 +00:00
|
|
|
if (vorbisfile->metadata) {
|
|
|
|
gst_caps_unref (vorbisfile->metadata);
|
|
|
|
vorbisfile->metadata = NULL;
|
2002-10-29 02:05:37 +00:00
|
|
|
}
|
|
|
|
|
2002-11-02 13:48:08 +00:00
|
|
|
/* create props to hold the key/value pairs */
|
2002-10-29 02:05:37 +00:00
|
|
|
props = gst_props_empty_new ();
|
|
|
|
|
2002-11-02 13:48:08 +00:00
|
|
|
vc = ov_comment (vf, link);
|
|
|
|
ptr = vc->user_comments;
|
2002-10-29 02:05:37 +00:00
|
|
|
while (*ptr) {
|
|
|
|
value = strstr (*ptr, "=");
|
|
|
|
if (value) {
|
2002-11-02 13:48:08 +00:00
|
|
|
name = g_strndup (*ptr, value-*ptr);
|
|
|
|
entry = gst_props_entry_new (name, GST_PROPS_STRING_TYPE, value+1);
|
2002-10-29 02:05:37 +00:00
|
|
|
gst_props_add_entry (props, (GstPropsEntry *) entry);
|
|
|
|
}
|
2002-11-02 13:48:08 +00:00
|
|
|
ptr++;
|
2002-10-29 02:05:37 +00:00
|
|
|
}
|
2002-11-10 00:38:57 +00:00
|
|
|
vorbisfile->metadata = gst_caps_new ("vorbisfile_metadata",
|
|
|
|
"application/x-gst-metadata",
|
|
|
|
props);
|
2002-11-09 18:34:48 +00:00
|
|
|
|
2002-11-10 00:38:57 +00:00
|
|
|
g_object_notify (G_OBJECT (vorbisfile), "metadata");
|
2002-11-09 18:34:48 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2002-11-10 00:38:57 +00:00
|
|
|
/* retrieve logical stream properties and put them in streaminfo GstCaps
|
2002-11-09 18:34:48 +00:00
|
|
|
* returns TRUE if caps could be set,
|
|
|
|
* FALSE if they couldn't be read somehow */
|
|
|
|
static gboolean
|
2002-11-10 00:38:57 +00:00
|
|
|
gst_vorbisfile_update_streaminfo (VorbisFile *vorbisfile, gint link)
|
2002-11-09 18:34:48 +00:00
|
|
|
{
|
|
|
|
OggVorbis_File *vf = &vorbisfile->vf;
|
|
|
|
vorbis_info *vi;
|
|
|
|
GstProps *props = NULL;
|
|
|
|
GstPropsEntry *entry;
|
|
|
|
|
|
|
|
/* clear old one */
|
2002-11-10 00:38:57 +00:00
|
|
|
if (vorbisfile->streaminfo) {
|
|
|
|
gst_caps_unref (vorbisfile->streaminfo);
|
|
|
|
vorbisfile->streaminfo = NULL;
|
2002-11-09 18:34:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* create props to hold the key/value pairs */
|
|
|
|
props = gst_props_empty_new ();
|
2002-11-02 13:48:08 +00:00
|
|
|
|
|
|
|
vi = ov_info (vf, link);
|
|
|
|
entry = gst_props_entry_new ("version", GST_PROPS_INT_TYPE, vi->version);
|
|
|
|
gst_props_add_entry (props, (GstPropsEntry *) entry);
|
2002-11-09 18:34:48 +00:00
|
|
|
entry = gst_props_entry_new ("bitrate_upper", GST_PROPS_INT_TYPE,
|
|
|
|
vi->bitrate_upper);
|
2002-11-02 13:48:08 +00:00
|
|
|
gst_props_add_entry (props, (GstPropsEntry *) entry);
|
2002-11-09 18:34:48 +00:00
|
|
|
entry = gst_props_entry_new ("bitrate_nominal", GST_PROPS_INT_TYPE,
|
|
|
|
vi->bitrate_nominal);
|
2002-11-02 13:48:08 +00:00
|
|
|
gst_props_add_entry (props, (GstPropsEntry *) entry);
|
2002-11-09 18:34:48 +00:00
|
|
|
entry = gst_props_entry_new ("bitrate_lower", GST_PROPS_INT_TYPE,
|
|
|
|
vi->bitrate_lower);
|
2002-11-02 13:48:08 +00:00
|
|
|
gst_props_add_entry (props, (GstPropsEntry *) entry);
|
2002-11-09 18:34:48 +00:00
|
|
|
entry = gst_props_entry_new ("serial", GST_PROPS_INT_TYPE,
|
|
|
|
ov_serialnumber (vf, link));
|
2002-11-02 13:48:08 +00:00
|
|
|
gst_props_add_entry (props, (GstPropsEntry *) entry);
|
2002-11-09 18:34:48 +00:00
|
|
|
entry = gst_props_entry_new ("bitrate", GST_PROPS_INT_TYPE,
|
|
|
|
ov_bitrate (vf, link));
|
2002-11-02 13:48:08 +00:00
|
|
|
gst_props_add_entry (props, (GstPropsEntry *) entry);
|
2002-10-29 02:05:37 +00:00
|
|
|
|
2002-11-10 00:38:57 +00:00
|
|
|
vorbisfile->streaminfo = gst_caps_new ("vorbisfile_streaminfo",
|
|
|
|
"application/x-gst-streaminfo",
|
|
|
|
props);
|
2002-11-02 13:48:08 +00:00
|
|
|
|
2002-11-10 00:38:57 +00:00
|
|
|
g_object_notify (G_OBJECT (vorbisfile), "streaminfo");
|
2002-11-02 13:48:08 +00:00
|
|
|
|
2002-10-29 02:05:37 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2002-11-02 13:48:08 +00:00
|
|
|
static gboolean
|
|
|
|
gst_vorbisfile_new_link (VorbisFile *vorbisfile, gint link)
|
2002-10-29 02:05:37 +00:00
|
|
|
{
|
2002-11-02 13:48:08 +00:00
|
|
|
vorbis_info *vi = ov_info (&vorbisfile->vf, link);
|
2003-06-01 08:34:23 +00:00
|
|
|
GstCaps *caps;
|
|
|
|
gboolean res = TRUE;
|
2002-10-29 02:05:37 +00:00
|
|
|
|
2002-11-02 13:48:08 +00:00
|
|
|
/* new logical bitstream */
|
|
|
|
vorbisfile->current_link = link;
|
2002-10-29 02:05:37 +00:00
|
|
|
|
2002-11-02 13:48:08 +00:00
|
|
|
gst_vorbisfile_update_metadata (vorbisfile, link);
|
2002-11-10 00:38:57 +00:00
|
|
|
gst_vorbisfile_update_streaminfo (vorbisfile, link);
|
2002-11-02 13:48:08 +00:00
|
|
|
|
2003-06-01 08:34:23 +00:00
|
|
|
caps = GST_CAPS_NEW ("vorbisdec_src",
|
2003-07-06 20:49:52 +00:00
|
|
|
"audio/x-raw-int",
|
2003-06-01 08:34:23 +00:00
|
|
|
"endianness", GST_PROPS_INT (G_BYTE_ORDER),
|
|
|
|
"signed", GST_PROPS_BOOLEAN (TRUE),
|
|
|
|
"width", GST_PROPS_INT (16),
|
|
|
|
"depth", GST_PROPS_INT (16),
|
|
|
|
"rate", GST_PROPS_INT (vi->rate),
|
|
|
|
"channels", GST_PROPS_INT (vi->channels));
|
|
|
|
gst_caps_ref (caps);
|
|
|
|
|
|
|
|
if (gst_pad_try_set_caps (vorbisfile->srcpad, caps) <= 0) {
|
|
|
|
if (!gst_pad_recover_caps_error (vorbisfile->srcpad, caps))
|
|
|
|
res = FALSE;
|
2002-11-02 13:48:08 +00:00
|
|
|
}
|
2002-10-29 02:05:37 +00:00
|
|
|
|
2003-06-01 08:34:23 +00:00
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
|
|
|
return res;
|
2002-10-29 02:05:37 +00:00
|
|
|
}
|
2002-11-02 13:48:08 +00:00
|
|
|
|
2002-05-31 23:37:28 +00:00
|
|
|
static void
|
|
|
|
gst_vorbisfile_loop (GstElement *element)
|
|
|
|
{
|
|
|
|
VorbisFile *vorbisfile = GST_VORBISFILE (element);
|
|
|
|
GstBuffer *outbuf;
|
|
|
|
long ret;
|
2002-11-02 13:48:08 +00:00
|
|
|
gint link;
|
2002-05-31 23:37:28 +00:00
|
|
|
|
2002-10-29 02:05:37 +00:00
|
|
|
/* this function needs to go first since you don't want to be messing
|
|
|
|
* with an unset vf ;) */
|
2002-05-31 23:37:28 +00:00
|
|
|
if (vorbisfile->restart) {
|
|
|
|
vorbisfile->offset = 0;
|
|
|
|
vorbisfile->total_bytes = 0;
|
|
|
|
vorbisfile->may_eos = FALSE;
|
2002-10-29 02:05:37 +00:00
|
|
|
vorbisfile->vf.seekable = gst_bytestream_seek (vorbisfile->bs, 0,
|
|
|
|
GST_SEEK_METHOD_SET);
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("vorbisfile: seekable: %s",
|
2002-11-11 14:06:31 +00:00
|
|
|
vorbisfile->vf.seekable ? "yes" : "no");
|
2002-05-31 23:37:28 +00:00
|
|
|
|
2002-10-29 02:05:37 +00:00
|
|
|
/* open our custom vorbisfile data object with the callbacks we provide */
|
|
|
|
if (ov_open_callbacks (vorbisfile, &vorbisfile->vf, NULL, 0,
|
|
|
|
vorbisfile_ov_callbacks) < 0) {
|
2003-09-16 10:00:02 +00:00
|
|
|
gst_element_error (element, "this is not a vorbis file");
|
2002-05-31 23:37:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
vorbisfile->need_discont = TRUE;
|
|
|
|
vorbisfile->restart = FALSE;
|
2002-11-02 13:48:08 +00:00
|
|
|
vorbisfile->current_link = -1;
|
2002-10-29 02:05:37 +00:00
|
|
|
}
|
2002-11-02 13:48:08 +00:00
|
|
|
|
2002-05-31 23:37:28 +00:00
|
|
|
if (vorbisfile->seek_pending) {
|
2002-10-29 02:05:37 +00:00
|
|
|
/* get time to seek to in seconds */
|
2002-05-31 23:37:28 +00:00
|
|
|
switch (vorbisfile->seek_format) {
|
|
|
|
case GST_FORMAT_TIME:
|
2002-11-02 13:48:08 +00:00
|
|
|
{
|
|
|
|
gdouble seek_to = (gdouble) vorbisfile->seek_value / GST_SECOND;
|
|
|
|
|
2002-05-31 23:37:28 +00:00
|
|
|
if (vorbisfile->seek_accurate) {
|
2002-10-29 02:05:37 +00:00
|
|
|
if (ov_time_seek (&vorbisfile->vf, seek_to) == 0) {
|
2002-05-31 23:37:28 +00:00
|
|
|
vorbisfile->need_discont = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2002-10-29 02:05:37 +00:00
|
|
|
if (ov_time_seek_page (&vorbisfile->vf, seek_to) == 0) {
|
2002-05-31 23:37:28 +00:00
|
|
|
vorbisfile->need_discont = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2002-11-02 13:48:08 +00:00
|
|
|
}
|
2003-05-24 10:41:58 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
2002-05-31 23:37:28 +00:00
|
|
|
if (vorbisfile->seek_accurate) {
|
2002-11-02 13:48:08 +00:00
|
|
|
if (ov_pcm_seek (&vorbisfile->vf, vorbisfile->seek_value) == 0) {
|
2002-05-31 23:37:28 +00:00
|
|
|
vorbisfile->need_discont = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2002-11-02 13:48:08 +00:00
|
|
|
if (ov_pcm_seek_page (&vorbisfile->vf, vorbisfile->seek_value) == 0) {
|
2002-05-31 23:37:28 +00:00
|
|
|
vorbisfile->need_discont = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2002-11-02 13:48:08 +00:00
|
|
|
if (vorbisfile->seek_format == logical_stream_format) {
|
|
|
|
gint64 seek_to;
|
|
|
|
|
|
|
|
seek_to = vorbisfile->vf.offsets[vorbisfile->seek_value];
|
|
|
|
|
|
|
|
if (ov_raw_seek (&vorbisfile->vf, seek_to) == 0) {
|
|
|
|
vorbisfile->need_discont = TRUE;
|
|
|
|
vorbisfile->current_link = -1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
g_warning ("raw seek failed");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
g_warning ("unknown seek method, implement me !");
|
2002-05-31 23:37:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
vorbisfile->seek_pending = FALSE;
|
|
|
|
}
|
|
|
|
|
2002-11-02 13:48:08 +00:00
|
|
|
/* we update the caps for each logical stream */
|
|
|
|
if (vorbisfile->vf.current_link != vorbisfile->current_link) {
|
|
|
|
if (!gst_vorbisfile_new_link (vorbisfile, vorbisfile->vf.current_link)) {
|
2003-06-01 08:34:23 +00:00
|
|
|
return;
|
2002-11-02 13:48:08 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-05-29 13:02:16 +00:00
|
|
|
outbuf = gst_buffer_new_and_alloc (vorbisfile->blocksize);
|
2002-07-28 18:16:59 +00:00
|
|
|
|
2002-10-29 02:05:37 +00:00
|
|
|
ret = ov_read (&vorbisfile->vf,
|
|
|
|
GST_BUFFER_DATA (outbuf), GST_BUFFER_SIZE (outbuf),
|
|
|
|
(G_BYTE_ORDER == G_LITTLE_ENDIAN ? 0 : 1),
|
2002-11-02 13:48:08 +00:00
|
|
|
sizeof (gint16), 1, &link);
|
2002-05-31 23:37:28 +00:00
|
|
|
|
|
|
|
if (ret == 0) {
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("eos");
|
2002-10-29 02:05:37 +00:00
|
|
|
/* send EOS event */
|
2002-11-02 13:48:08 +00:00
|
|
|
/*ov_clear (&vorbisfile->vf);*/
|
2002-05-31 23:37:28 +00:00
|
|
|
vorbisfile->restart = TRUE;
|
2002-07-08 19:38:27 +00:00
|
|
|
gst_buffer_unref (outbuf);
|
2002-10-29 02:05:37 +00:00
|
|
|
/* if the pad is not usable, don't push it out */
|
2002-11-02 13:48:08 +00:00
|
|
|
if (GST_PAD_IS_USABLE (vorbisfile->srcpad)) {
|
2002-10-29 02:05:37 +00:00
|
|
|
gst_pad_push (vorbisfile->srcpad,
|
|
|
|
GST_BUFFER (gst_event_new (GST_EVENT_EOS)));
|
2002-11-02 13:48:08 +00:00
|
|
|
}
|
2002-05-31 23:37:28 +00:00
|
|
|
gst_element_set_eos (element);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if (ret < 0) {
|
|
|
|
g_warning ("vorbisfile: decoding error");
|
|
|
|
gst_buffer_unref (outbuf);
|
2002-11-02 13:48:08 +00:00
|
|
|
return;
|
2002-05-31 23:37:28 +00:00
|
|
|
}
|
|
|
|
else {
|
2003-05-29 13:17:17 +00:00
|
|
|
GstClockTime time;
|
|
|
|
gint64 samples;
|
|
|
|
|
|
|
|
/* get stream stats */
|
|
|
|
samples = (gint64) (ov_pcm_tell (&vorbisfile->vf));
|
|
|
|
time = (GstClockTime) (ov_time_tell (&vorbisfile->vf) * GST_SECOND);
|
|
|
|
|
2002-11-02 13:48:08 +00:00
|
|
|
if (vorbisfile->need_discont) {
|
|
|
|
GstEvent *discont;
|
2002-05-31 23:37:28 +00:00
|
|
|
|
2002-11-02 13:48:08 +00:00
|
|
|
vorbisfile->need_discont = FALSE;
|
|
|
|
|
|
|
|
/* if the pad is not usable, don't push it out */
|
|
|
|
if (GST_PAD_IS_USABLE (vorbisfile->srcpad)) {
|
|
|
|
|
|
|
|
discont = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME, time,
|
2003-05-24 10:41:58 +00:00
|
|
|
GST_FORMAT_DEFAULT, samples, NULL);
|
2002-11-02 13:48:08 +00:00
|
|
|
|
|
|
|
gst_pad_push (vorbisfile->srcpad, GST_BUFFER (discont));
|
2002-10-20 17:11:10 +00:00
|
|
|
}
|
2002-05-31 23:37:28 +00:00
|
|
|
}
|
|
|
|
|
2002-11-02 13:48:08 +00:00
|
|
|
GST_BUFFER_SIZE (outbuf) = ret;
|
2002-07-28 18:16:59 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (outbuf) = time;
|
2003-05-29 13:17:17 +00:00
|
|
|
GST_BUFFER_OFFSET (outbuf) = samples;
|
|
|
|
{
|
|
|
|
GstClockTime duration;
|
|
|
|
GstFormat format;
|
|
|
|
|
|
|
|
format = GST_FORMAT_TIME;
|
|
|
|
gst_pad_convert (vorbisfile->srcpad,
|
|
|
|
GST_FORMAT_BYTES, ret,
|
|
|
|
&format, &duration);
|
|
|
|
GST_BUFFER_DURATION (outbuf) = duration;
|
|
|
|
}
|
2002-06-02 18:12:08 +00:00
|
|
|
|
2002-11-02 13:48:08 +00:00
|
|
|
vorbisfile->may_eos = TRUE;
|
|
|
|
|
2002-06-02 18:12:08 +00:00
|
|
|
if (!vorbisfile->vf.seekable) {
|
2003-05-29 13:17:17 +00:00
|
|
|
vorbisfile->total_bytes += ret;
|
2002-06-02 15:48:25 +00:00
|
|
|
}
|
2002-05-31 23:37:28 +00:00
|
|
|
|
2002-10-19 16:58:25 +00:00
|
|
|
if (GST_PAD_IS_USABLE (vorbisfile->srcpad))
|
2002-07-08 19:38:27 +00:00
|
|
|
gst_pad_push (vorbisfile->srcpad, outbuf);
|
2002-10-19 16:58:25 +00:00
|
|
|
else
|
2002-07-08 19:38:27 +00:00
|
|
|
gst_buffer_unref (outbuf);
|
2002-05-31 23:37:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-07-24 21:40:16 +00:00
|
|
|
static const GstFormat*
|
|
|
|
gst_vorbisfile_get_formats (GstPad *pad)
|
|
|
|
{
|
2002-11-02 13:48:08 +00:00
|
|
|
static GstFormat src_formats[] = {
|
2002-07-24 21:40:16 +00:00
|
|
|
GST_FORMAT_TIME,
|
|
|
|
GST_FORMAT_BYTES,
|
2003-05-24 10:41:58 +00:00
|
|
|
GST_FORMAT_DEFAULT,
|
2002-11-02 13:48:08 +00:00
|
|
|
0,
|
2002-07-24 21:40:16 +00:00
|
|
|
0
|
|
|
|
};
|
2002-11-02 13:48:08 +00:00
|
|
|
static GstFormat sink_formats[] = {
|
|
|
|
GST_FORMAT_TIME,
|
|
|
|
GST_FORMAT_BYTES,
|
|
|
|
0,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
src_formats[3] = logical_stream_format;
|
|
|
|
sink_formats[2] = logical_stream_format;
|
|
|
|
|
|
|
|
return (GST_PAD_IS_SRC (pad) ? src_formats : sink_formats);
|
2002-07-24 21:40:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2002-10-29 02:05:37 +00:00
|
|
|
gst_vorbisfile_src_convert (GstPad *pad,
|
|
|
|
GstFormat src_format, gint64 src_value,
|
2002-07-24 21:40:16 +00:00
|
|
|
GstFormat *dest_format, gint64 *dest_value)
|
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
guint scale = 1;
|
|
|
|
gint bytes_per_sample;
|
|
|
|
VorbisFile *vorbisfile;
|
|
|
|
vorbis_info *vi;
|
|
|
|
|
|
|
|
vorbisfile = GST_VORBISFILE (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
vi = ov_info (&vorbisfile->vf, -1);
|
|
|
|
bytes_per_sample = vi->channels * 2;
|
|
|
|
|
|
|
|
switch (src_format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
switch (*dest_format) {
|
2003-05-24 10:41:58 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
2002-07-24 21:40:16 +00:00
|
|
|
*dest_value = src_value / (vi->channels * 2);
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
{
|
|
|
|
gint byterate = bytes_per_sample * vi->rate;
|
|
|
|
|
|
|
|
if (byterate == 0)
|
|
|
|
return FALSE;
|
|
|
|
*dest_value = src_value * GST_SECOND / byterate;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
2003-05-24 10:41:58 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
2002-07-24 21:40:16 +00:00
|
|
|
switch (*dest_format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
*dest_value = src_value * bytes_per_sample;
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
if (vi->rate == 0)
|
|
|
|
return FALSE;
|
|
|
|
*dest_value = src_value * GST_SECOND / vi->rate;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
switch (*dest_format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
scale = bytes_per_sample;
|
2003-05-24 10:41:58 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
2002-07-24 21:40:16 +00:00
|
|
|
*dest_value = src_value * scale * vi->rate / GST_SECOND;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
2002-11-02 13:48:08 +00:00
|
|
|
if (src_format == logical_stream_format) {
|
|
|
|
/* because we need to convert relative from 0, we have to add
|
|
|
|
* all pcm totals */
|
|
|
|
gint i;
|
|
|
|
gint64 count = 0;
|
|
|
|
|
|
|
|
switch (*dest_format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
2002-11-12 20:56:13 +00:00
|
|
|
res = FALSE;
|
|
|
|
break;
|
2003-05-24 10:41:58 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
2002-11-12 20:56:13 +00:00
|
|
|
if (src_value > vorbisfile->vf.links) {
|
|
|
|
src_value = vorbisfile->vf.links;
|
|
|
|
}
|
|
|
|
for (i = 0; i < src_value; i++) {
|
|
|
|
vi = ov_info (&vorbisfile->vf, i);
|
|
|
|
|
|
|
|
count += ov_pcm_total (&vorbisfile->vf, i);
|
|
|
|
}
|
|
|
|
*dest_value = count;
|
2002-11-02 13:48:08 +00:00
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
2002-11-12 20:56:13 +00:00
|
|
|
{
|
|
|
|
if (src_value > vorbisfile->vf.links) {
|
|
|
|
src_value = vorbisfile->vf.links;
|
|
|
|
}
|
|
|
|
for (i = 0; i < src_value; i++) {
|
|
|
|
vi = ov_info (&vorbisfile->vf, i);
|
|
|
|
if (vi->rate)
|
|
|
|
count += ov_pcm_total (&vorbisfile->vf, i) * GST_SECOND / vi->rate;
|
|
|
|
else
|
|
|
|
count += ov_time_total (&vorbisfile->vf, i) * GST_SECOND;
|
|
|
|
}
|
2002-11-02 13:48:08 +00:00
|
|
|
/* we use the pcm totals to get the total time, it's more accurate */
|
2002-11-12 20:56:13 +00:00
|
|
|
*dest_value = count;
|
2002-11-02 13:48:08 +00:00
|
|
|
break;
|
2002-11-12 20:56:13 +00:00
|
|
|
}
|
2002-11-02 13:48:08 +00:00
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_vorbisfile_sink_convert (GstPad *pad,
|
|
|
|
GstFormat src_format, gint64 src_value,
|
|
|
|
GstFormat *dest_format, gint64 *dest_value)
|
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
VorbisFile *vorbisfile;
|
|
|
|
|
|
|
|
vorbisfile = GST_VORBISFILE (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
switch (src_format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
switch (*dest_format) {
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (*dest_format == logical_stream_format) {
|
|
|
|
}
|
|
|
|
else
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
switch (*dest_format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (*dest_format == logical_stream_format) {
|
|
|
|
}
|
|
|
|
else
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
if (src_format == logical_stream_format) {
|
|
|
|
switch (*dest_format) {
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
res = FALSE;
|
2002-07-24 21:40:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2002-12-30 17:53:18 +00:00
|
|
|
static const GstQueryType*
|
2002-07-24 21:40:16 +00:00
|
|
|
gst_vorbisfile_get_query_types (GstPad *pad)
|
|
|
|
{
|
2002-12-30 17:53:18 +00:00
|
|
|
static const GstQueryType types[] = {
|
|
|
|
GST_QUERY_TOTAL,
|
|
|
|
GST_QUERY_POSITION,
|
2002-07-24 21:40:16 +00:00
|
|
|
0
|
|
|
|
};
|
|
|
|
return types;
|
|
|
|
}
|
2002-10-29 02:05:37 +00:00
|
|
|
|
|
|
|
/* handles queries for location in the stream in the requested format */
|
2002-05-31 23:37:28 +00:00
|
|
|
static gboolean
|
2002-12-30 17:53:18 +00:00
|
|
|
gst_vorbisfile_src_query (GstPad *pad, GstQueryType type,
|
2002-05-31 23:37:28 +00:00
|
|
|
GstFormat *format, gint64 *value)
|
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
VorbisFile *vorbisfile;
|
2002-06-02 18:12:08 +00:00
|
|
|
vorbis_info *vi;
|
|
|
|
|
2002-05-31 23:37:28 +00:00
|
|
|
vorbisfile = GST_VORBISFILE (gst_pad_get_parent (pad));
|
|
|
|
|
2002-06-02 18:12:08 +00:00
|
|
|
vi = ov_info (&vorbisfile->vf, -1);
|
|
|
|
|
2002-05-31 23:37:28 +00:00
|
|
|
switch (type) {
|
2002-12-30 17:53:18 +00:00
|
|
|
case GST_QUERY_TOTAL:
|
2002-05-31 23:37:28 +00:00
|
|
|
{
|
|
|
|
switch (*format) {
|
2003-05-24 10:41:58 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
2002-06-02 18:12:08 +00:00
|
|
|
if (vorbisfile->vf.seekable)
|
|
|
|
*value = ov_pcm_total (&vorbisfile->vf, -1);
|
|
|
|
else
|
|
|
|
return FALSE;
|
2002-05-31 23:37:28 +00:00
|
|
|
break;
|
|
|
|
case GST_FORMAT_BYTES:
|
2002-06-02 18:12:08 +00:00
|
|
|
if (vorbisfile->vf.seekable)
|
|
|
|
*value = ov_pcm_total (&vorbisfile->vf, -1) * vi->channels * 2;
|
|
|
|
else
|
|
|
|
return FALSE;
|
2002-05-31 23:37:28 +00:00
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
2002-06-02 18:12:08 +00:00
|
|
|
if (vorbisfile->vf.seekable)
|
|
|
|
*value = (gint64) (ov_time_total (&vorbisfile->vf, -1) * GST_SECOND);
|
|
|
|
else
|
|
|
|
return FALSE;
|
2002-05-31 23:37:28 +00:00
|
|
|
break;
|
|
|
|
default:
|
2002-11-02 13:48:08 +00:00
|
|
|
if (*format == logical_stream_format) {
|
|
|
|
if (vorbisfile->vf.seekable)
|
|
|
|
*value = vorbisfile->vf.links;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
res = FALSE;
|
2002-05-31 23:37:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2002-12-30 17:53:18 +00:00
|
|
|
case GST_QUERY_POSITION:
|
2002-05-31 23:37:28 +00:00
|
|
|
switch (*format) {
|
|
|
|
case GST_FORMAT_TIME:
|
2002-06-02 18:12:08 +00:00
|
|
|
if (vorbisfile->vf.seekable)
|
|
|
|
*value = (gint64) (ov_time_tell (&vorbisfile->vf) * GST_SECOND);
|
|
|
|
else
|
2002-10-29 02:05:37 +00:00
|
|
|
*value = vorbisfile->total_bytes * GST_SECOND
|
|
|
|
/ (vi->rate * vi->channels * 2);
|
2002-06-02 18:12:08 +00:00
|
|
|
break;
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
if (vorbisfile->vf.seekable)
|
|
|
|
*value = ov_pcm_tell (&vorbisfile->vf) * vi->channels * 2;
|
|
|
|
else
|
|
|
|
*value = vorbisfile->total_bytes;
|
2002-05-31 23:37:28 +00:00
|
|
|
break;
|
2003-05-24 10:41:58 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
2002-06-02 18:12:08 +00:00
|
|
|
if (vorbisfile->vf.seekable)
|
|
|
|
*value = ov_pcm_tell (&vorbisfile->vf);
|
|
|
|
else
|
|
|
|
*value = vorbisfile->total_bytes / (vi->channels * 2);
|
2002-05-31 23:37:28 +00:00
|
|
|
break;
|
|
|
|
default:
|
2002-11-02 13:48:08 +00:00
|
|
|
if (*format == logical_stream_format) {
|
|
|
|
if (vorbisfile->vf.seekable)
|
|
|
|
*value = vorbisfile->current_link;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
res = FALSE;
|
2002-05-31 23:37:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2002-07-24 21:40:16 +00:00
|
|
|
|
|
|
|
static const GstEventMask*
|
|
|
|
gst_vorbisfile_get_event_masks (GstPad *pad)
|
|
|
|
{
|
|
|
|
static const GstEventMask masks[] = {
|
|
|
|
{ GST_EVENT_SEEK, GST_SEEK_METHOD_SET | GST_SEEK_FLAG_ACCURATE },
|
|
|
|
{ 0, }
|
|
|
|
};
|
|
|
|
return masks;
|
|
|
|
}
|
2002-10-29 02:05:37 +00:00
|
|
|
|
|
|
|
/* handle events on src pad */
|
2002-05-31 23:37:28 +00:00
|
|
|
static gboolean
|
|
|
|
gst_vorbisfile_src_event (GstPad *pad, GstEvent *event)
|
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
VorbisFile *vorbisfile;
|
|
|
|
|
|
|
|
vorbisfile = GST_VORBISFILE (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_SEEK:
|
2002-07-24 21:40:16 +00:00
|
|
|
{
|
|
|
|
gint64 offset;
|
|
|
|
vorbis_info *vi;
|
2002-11-02 13:48:08 +00:00
|
|
|
GstFormat format;
|
2002-07-24 21:40:16 +00:00
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("vorbisfile: handling seek event on pad %s:%s",
|
2002-11-11 14:06:31 +00:00
|
|
|
GST_DEBUG_PAD_NAME (pad));
|
2002-07-08 19:38:27 +00:00
|
|
|
if (!vorbisfile->vf.seekable) {
|
|
|
|
gst_event_unref (event);
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("vorbis stream is not seekable");
|
2002-06-02 15:48:25 +00:00
|
|
|
return FALSE;
|
2002-07-08 19:38:27 +00:00
|
|
|
}
|
2002-06-02 15:48:25 +00:00
|
|
|
|
2002-07-24 21:40:16 +00:00
|
|
|
offset = GST_EVENT_SEEK_OFFSET (event);
|
2002-11-02 13:48:08 +00:00
|
|
|
format = GST_EVENT_SEEK_FORMAT (event);
|
2002-07-24 21:40:16 +00:00
|
|
|
|
2002-11-02 13:48:08 +00:00
|
|
|
switch (format) {
|
2002-05-31 23:37:28 +00:00
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
vorbisfile->seek_pending = TRUE;
|
2002-07-24 21:40:16 +00:00
|
|
|
vorbisfile->seek_value = offset;
|
2002-11-02 13:48:08 +00:00
|
|
|
vorbisfile->seek_format = format;
|
2002-10-29 02:05:37 +00:00
|
|
|
vorbisfile->seek_accurate = GST_EVENT_SEEK_FLAGS (event)
|
|
|
|
& GST_SEEK_FLAG_ACCURATE;
|
2002-05-31 23:37:28 +00:00
|
|
|
break;
|
2002-07-24 21:40:16 +00:00
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
vi = ov_info (&vorbisfile->vf, -1);
|
2002-11-10 14:37:29 +00:00
|
|
|
if (vi->channels == 0) {
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("vorbis stream has 0 channels ?");
|
2002-07-24 21:40:16 +00:00
|
|
|
res = FALSE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
offset /= vi->channels * 2;
|
|
|
|
/* fallthrough */
|
2003-05-24 10:41:58 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
2002-05-31 23:37:28 +00:00
|
|
|
vorbisfile->seek_pending = TRUE;
|
2002-07-24 21:40:16 +00:00
|
|
|
vorbisfile->seek_value = offset;
|
2002-11-02 13:48:08 +00:00
|
|
|
vorbisfile->seek_format = format;
|
2002-10-29 02:05:37 +00:00
|
|
|
vorbisfile->seek_accurate = GST_EVENT_SEEK_FLAGS (event)
|
|
|
|
& GST_SEEK_FLAG_ACCURATE;
|
2002-05-31 23:37:28 +00:00
|
|
|
break;
|
|
|
|
default:
|
2002-11-02 13:48:08 +00:00
|
|
|
if (format == logical_stream_format) {
|
|
|
|
vorbisfile->seek_pending = TRUE;
|
|
|
|
vorbisfile->seek_value = offset;
|
|
|
|
vorbisfile->seek_format = format;
|
|
|
|
vorbisfile->seek_accurate = GST_EVENT_SEEK_FLAGS (event)
|
|
|
|
& GST_SEEK_FLAG_ACCURATE;
|
|
|
|
}
|
|
|
|
else
|
2002-11-10 14:37:29 +00:00
|
|
|
{
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("unhandled seek format");
|
2002-11-02 13:48:08 +00:00
|
|
|
res = FALSE;
|
2002-11-10 14:37:29 +00:00
|
|
|
}
|
2002-05-31 23:37:28 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2002-07-24 21:40:16 +00:00
|
|
|
}
|
2002-05-31 23:37:28 +00:00
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
2002-07-24 21:40:16 +00:00
|
|
|
|
|
|
|
done:
|
2002-07-08 19:38:27 +00:00
|
|
|
gst_event_unref (event);
|
2002-05-31 23:37:28 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstElementStateReturn
|
|
|
|
gst_vorbisfile_change_state (GstElement *element)
|
|
|
|
{
|
|
|
|
VorbisFile *vorbisfile = GST_VORBISFILE (element);
|
|
|
|
|
|
|
|
switch (GST_STATE_TRANSITION (element)) {
|
|
|
|
case GST_STATE_NULL_TO_READY:
|
|
|
|
case GST_STATE_READY_TO_PAUSED:
|
|
|
|
vorbisfile->restart = TRUE;
|
|
|
|
vorbisfile->bs = gst_bytestream_new (vorbisfile->sinkpad);
|
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_PLAYING:
|
|
|
|
vorbisfile->eos = FALSE;
|
|
|
|
case GST_STATE_PLAYING_TO_PAUSED:
|
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
|
|
|
ov_clear (&vorbisfile->vf);
|
|
|
|
gst_bytestream_destroy (vorbisfile->bs);
|
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_NULL:
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_ELEMENT_CLASS (parent_class)->change_state)
|
|
|
|
return GST_ELEMENT_CLASS (parent_class)->change_state (element);
|
|
|
|
|
|
|
|
return GST_STATE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2002-10-29 02:05:37 +00:00
|
|
|
static void
|
|
|
|
gst_vorbisfile_set_property (GObject *object, guint prop_id,
|
|
|
|
const GValue *value, GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
VorbisFile *vorbisfile;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_VORBISFILE (object));
|
|
|
|
|
|
|
|
vorbisfile = GST_VORBISFILE (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2003-05-29 13:02:16 +00:00
|
|
|
case ARG_BLOCKSIZE:
|
|
|
|
vorbisfile->blocksize = g_value_get_ulong (value);
|
|
|
|
break;
|
2002-10-29 02:05:37 +00:00
|
|
|
default:
|
|
|
|
g_warning ("Unknown property id\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-05-31 23:37:28 +00:00
|
|
|
static void
|
2002-10-29 02:05:37 +00:00
|
|
|
gst_vorbisfile_get_property (GObject *object, guint prop_id,
|
|
|
|
GValue *value, GParamSpec *pspec)
|
2002-05-31 23:37:28 +00:00
|
|
|
{
|
|
|
|
VorbisFile *vorbisfile;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_VORBISFILE (object));
|
|
|
|
|
|
|
|
vorbisfile = GST_VORBISFILE (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2003-05-29 13:02:16 +00:00
|
|
|
case ARG_BLOCKSIZE:
|
|
|
|
g_value_set_ulong (value, vorbisfile->blocksize);
|
|
|
|
break;
|
2002-10-29 02:05:37 +00:00
|
|
|
case ARG_METADATA:
|
|
|
|
g_value_set_boxed (value, vorbisfile->metadata);
|
2002-05-31 23:37:28 +00:00
|
|
|
break;
|
2002-11-10 00:38:57 +00:00
|
|
|
case ARG_STREAMINFO:
|
|
|
|
g_value_set_boxed (value, vorbisfile->streaminfo);
|
2002-11-09 18:34:48 +00:00
|
|
|
break;
|
2002-10-29 02:05:37 +00:00
|
|
|
default:
|
|
|
|
g_warning ("Unknown property id\n");
|
2002-05-31 23:37:28 +00:00
|
|
|
}
|
|
|
|
}
|