2003-02-23 17:35:35 +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:13 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2003-02-23 17:35:35 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <gst/gst.h>
|
|
|
|
#include <tremor/ivorbiscodec.h>
|
|
|
|
#include <tremor/ivorbisfile.h>
|
2003-10-29 03:15:55 +00:00
|
|
|
#include <gst/bytestream/bytestream.h>
|
2003-02-23 17:35:35 +00:00
|
|
|
|
2003-12-27 13:07:06 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (ivorbisfile_debug);
|
|
|
|
#define GST_CAT_DEFAULT ivorbisfile_debug
|
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
#define GST_TYPE_IVORBISFILE \
|
|
|
|
(ivorbisfile_get_type())
|
|
|
|
#define GST_IVORBISFILE(obj) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_IVORBISFILE,Ivorbisfile))
|
|
|
|
#define GST_IVORBISFILE_CLASS(klass) \
|
|
|
|
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_IVORBISFILE,IvorbisfileClass))
|
|
|
|
#define GST_IS_IVORBISFILE(obj) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_IVORBISFILE))
|
|
|
|
#define GST_IS_IVORBISFILE_CLASS(obj) \
|
|
|
|
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_IVORBISFILE))
|
|
|
|
|
|
|
|
typedef struct _Ivorbisfile Ivorbisfile;
|
|
|
|
typedef struct _IvorbisfileClass IvorbisfileClass;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
struct _Ivorbisfile
|
|
|
|
{
|
|
|
|
GstElement element;
|
2003-02-23 17:35:35 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GstPad *sinkpad, *srcpad;
|
2003-02-23 17:35:35 +00:00
|
|
|
GstByteStream *bs;
|
|
|
|
|
|
|
|
OggVorbis_File vf;
|
2004-03-14 22:34:33 +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;
|
|
|
|
|
|
|
|
GstCaps *metadata;
|
|
|
|
GstCaps *streaminfo;
|
2003-02-23 17:35:35 +00:00
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
struct _IvorbisfileClass
|
|
|
|
{
|
2003-02-23 17:35:35 +00:00
|
|
|
GstElementClass parent_class;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
GType ivorbisfile_get_type (void);
|
2003-02-23 17:35:35 +00:00
|
|
|
|
2003-11-01 23:26:42 +00:00
|
|
|
static GstPadTemplate *gst_vorbisdec_src_template, *gst_vorbisdec_sink_template;
|
2003-02-23 17:35:35 +00:00
|
|
|
|
|
|
|
/* elementfactory information */
|
2004-03-14 22:34:33 +00:00
|
|
|
GstElementDetails ivorbisfile_details = {
|
2003-02-23 17:35:35 +00:00
|
|
|
"Ogg Vorbis decoder",
|
2004-05-09 14:37:16 +00:00
|
|
|
"Codec/Decoder/Audio",
|
2003-03-01 14:48:00 +00:00
|
|
|
"Decodes OGG Vorbis audio using the Tremor vorbisfile API",
|
2004-03-14 22:34:33 +00:00
|
|
|
"Monty <monty@xiph.org>\n"
|
|
|
|
"Wim Taymans <wim.taymans@chello.be>\n"
|
|
|
|
"Amaury Jacquot <sxpert@esitcom.org>",
|
2003-02-23 17:35:35 +00:00
|
|
|
};
|
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
/* Ivorbisfile signals and args */
|
2003-02-23 17:35:35 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
ARG_0,
|
|
|
|
ARG_METADATA,
|
|
|
|
ARG_STREAMINFO
|
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_ivorbisfile_base_init (gpointer g_class);
|
|
|
|
static void gst_ivorbisfile_class_init (IvorbisfileClass * klass);
|
|
|
|
static void gst_ivorbisfile_init (Ivorbisfile * ivorbisfile);
|
2003-02-23 17:35:35 +00:00
|
|
|
|
|
|
|
static GstElementStateReturn
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_ivorbisfile_change_state (GstElement * element);
|
|
|
|
|
|
|
|
static const GstFormat *gst_ivorbisfile_get_formats (GstPad * pad);
|
|
|
|
static gboolean gst_ivorbisfile_src_convert (GstPad * pad,
|
|
|
|
GstFormat src_format,
|
|
|
|
gint64 src_value, GstFormat * dest_format, gint64 * dest_value);
|
|
|
|
static gboolean gst_ivorbisfile_sink_convert (GstPad * pad,
|
|
|
|
GstFormat src_format,
|
|
|
|
gint64 src_value, GstFormat * dest_format, gint64 * dest_value);
|
|
|
|
static const GstQueryType *gst_ivorbisfile_get_query_types (GstPad * pad);
|
|
|
|
|
|
|
|
static gboolean gst_ivorbisfile_src_query (GstPad * pad,
|
|
|
|
GstQueryType type, GstFormat * format, gint64 * value);
|
|
|
|
static const GstEventMask *gst_ivorbisfile_get_event_masks (GstPad * pad);
|
|
|
|
static gboolean gst_ivorbisfile_src_event (GstPad * pad, GstEvent * event);
|
|
|
|
|
|
|
|
static void gst_ivorbisfile_get_property (GObject * object,
|
|
|
|
guint prop_id, GValue * value, GParamSpec * pspec);
|
|
|
|
static void gst_ivorbisfile_set_property (GObject * object,
|
|
|
|
guint prop_id, const GValue * value, GParamSpec * pspec);
|
|
|
|
|
|
|
|
static void gst_ivorbisfile_loop (GstElement * element);
|
2003-02-23 17:35:35 +00:00
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
//static guint gst_ivorbisfile_signals[LAST_SIGNAL] = { 0 };
|
2003-02-23 17:35:35 +00:00
|
|
|
|
|
|
|
static GstFormat logical_stream_format;
|
|
|
|
|
|
|
|
GType
|
2003-03-01 14:48:00 +00:00
|
|
|
ivorbisfile_get_type (void)
|
2003-02-23 17:35:35 +00:00
|
|
|
{
|
2003-03-01 14:48:00 +00:00
|
|
|
static GType ivorbisfile_type = 0;
|
|
|
|
|
|
|
|
if (!ivorbisfile_type) {
|
|
|
|
static const GTypeInfo ivorbisfile_info = {
|
2003-11-01 23:26:42 +00:00
|
|
|
sizeof (IvorbisfileClass),
|
|
|
|
gst_ivorbisfile_base_init,
|
|
|
|
NULL,
|
2003-03-01 14:48:00 +00:00
|
|
|
(GClassInitFunc) gst_ivorbisfile_class_init, NULL, NULL,
|
|
|
|
sizeof (Ivorbisfile), 0,
|
|
|
|
(GInstanceInitFunc) gst_ivorbisfile_init,
|
2003-02-23 17:35:35 +00:00
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
ivorbisfile_type = g_type_register_static (GST_TYPE_ELEMENT, "Ivorbisfile",
|
2004-03-15 19:32:27 +00:00
|
|
|
&ivorbisfile_info, 0);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
|
|
|
logical_stream_format =
|
2004-03-15 19:32:27 +00:00
|
|
|
gst_format_register ("logical_stream", "The logical stream");
|
2003-02-23 17:35:35 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (ivorbisfile_debug, "ivorbisfile", 0,
|
2004-03-15 19:32:27 +00:00
|
|
|
"vorbis in ogg decoding element (integer arithmetic)");
|
2003-02-23 17:35:35 +00:00
|
|
|
}
|
2003-03-01 14:48:00 +00:00
|
|
|
return ivorbisfile_type;
|
2003-02-23 17:35:35 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstCaps *
|
2003-12-27 13:07:06 +00:00
|
|
|
vorbis_caps_factory (void)
|
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
return gst_caps_new_simple ("application/ogg", NULL);
|
2003-12-27 13:07:06 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstCaps *
|
2003-12-27 13:07:06 +00:00
|
|
|
raw_caps_factory (void)
|
|
|
|
{
|
|
|
|
return
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_caps_new_simple ("audio/x-raw-int",
|
|
|
|
"endianness", G_TYPE_INT, G_BYTE_ORDER,
|
|
|
|
"signed", G_TYPE_BOOLEAN, TRUE,
|
|
|
|
"width", G_TYPE_INT, 16,
|
|
|
|
"depth", G_TYPE_INT, 16,
|
|
|
|
"rate", GST_TYPE_INT_RANGE, 11025, 48000,
|
|
|
|
"channels", GST_TYPE_INT_RANGE, 1, 2, NULL);
|
2003-12-27 13:07:06 +00:00
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static GstCaps *
|
2003-12-27 13:07:06 +00:00
|
|
|
raw_caps2_factory (void)
|
|
|
|
{
|
|
|
|
return
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_caps_new_simple ("audio/x-raw-float",
|
|
|
|
"depth", G_TYPE_INT, 32,
|
|
|
|
"endianness", G_TYPE_INT, G_BYTE_ORDER,
|
|
|
|
"rate", GST_TYPE_INT_RANGE, 11025, 48000,
|
|
|
|
"channels", G_TYPE_INT, 2, NULL);
|
2003-12-27 13:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-11-01 23:26:42 +00:00
|
|
|
static void
|
|
|
|
gst_ivorbisfile_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
GstCaps *raw_caps, *vorbis_caps, *raw_caps2;
|
|
|
|
|
|
|
|
raw_caps = raw_caps_factory ();
|
|
|
|
raw_caps2 = raw_caps2_factory ();
|
|
|
|
vorbis_caps = vorbis_caps_factory ();
|
|
|
|
|
|
|
|
/* register sink pads */
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_vorbisdec_sink_template = gst_pad_template_new ("sink", GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS, vorbis_caps);
|
2003-12-27 13:07:06 +00:00
|
|
|
gst_caps_append (raw_caps2, raw_caps);
|
2003-11-01 23:26:42 +00:00
|
|
|
/* register src pads */
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_vorbisdec_src_template = gst_pad_template_new ("src", GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS, raw_caps2);
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_vorbisdec_sink_template);
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
gst_vorbisdec_src_template);
|
2003-11-01 23:26:42 +00:00
|
|
|
gst_element_class_set_details (element_class, &ivorbisfile_details);
|
|
|
|
}
|
|
|
|
|
2003-02-23 17:35:35 +00:00
|
|
|
static void
|
2003-03-01 14:48:00 +00:00
|
|
|
gst_ivorbisfile_class_init (IvorbisfileClass * klass)
|
2003-02-23 17:35:35 +00:00
|
|
|
{
|
|
|
|
GObjectClass *gobject_class;
|
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
2003-02-23 17:35:35 +00:00
|
|
|
gstelement_class = (GstElementClass *) klass;
|
|
|
|
|
|
|
|
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
|
|
|
|
|
|
|
|
g_object_class_install_property (gobject_class, ARG_METADATA,
|
2004-03-14 22:34:33 +00:00
|
|
|
g_param_spec_boxed ("metadata", "Metadata", "(logical) Stream metadata",
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_TYPE_CAPS, G_PARAM_READABLE));
|
2003-02-23 17:35:35 +00:00
|
|
|
g_object_class_install_property (gobject_class, ARG_STREAMINFO,
|
2004-03-14 22:34:33 +00:00
|
|
|
g_param_spec_boxed ("streaminfo", "stream",
|
2004-03-15 19:32:27 +00:00
|
|
|
"(logical) Stream information", GST_TYPE_CAPS, G_PARAM_READABLE));
|
2003-02-23 17:35:35 +00:00
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
gobject_class->get_property = gst_ivorbisfile_get_property;
|
|
|
|
gobject_class->set_property = gst_ivorbisfile_set_property;
|
2003-02-23 17:35:35 +00:00
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
gstelement_class->change_state = gst_ivorbisfile_change_state;
|
2003-02-23 17:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2003-03-01 14:48:00 +00:00
|
|
|
gst_ivorbisfile_init (Ivorbisfile * ivorbisfile)
|
2003-02-23 17:35:35 +00:00
|
|
|
{
|
2003-03-01 14:48:00 +00:00
|
|
|
ivorbisfile->sinkpad = gst_pad_new_from_template (gst_vorbisdec_sink_template,
|
2004-03-14 22:34:33 +00:00
|
|
|
"sink");
|
2003-03-01 14:48:00 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (ivorbisfile), ivorbisfile->sinkpad);
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_pad_set_formats_function (ivorbisfile->sinkpad,
|
|
|
|
gst_ivorbisfile_get_formats);
|
|
|
|
gst_pad_set_convert_function (ivorbisfile->sinkpad,
|
|
|
|
gst_ivorbisfile_sink_convert);
|
|
|
|
|
|
|
|
gst_element_set_loop_function (GST_ELEMENT (ivorbisfile),
|
|
|
|
gst_ivorbisfile_loop);
|
|
|
|
ivorbisfile->srcpad =
|
|
|
|
gst_pad_new_from_template (gst_vorbisdec_src_template, "src");
|
2003-03-01 14:48:00 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (ivorbisfile), ivorbisfile->srcpad);
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_pad_set_formats_function (ivorbisfile->srcpad,
|
|
|
|
gst_ivorbisfile_get_formats);
|
|
|
|
gst_pad_set_query_type_function (ivorbisfile->srcpad,
|
|
|
|
gst_ivorbisfile_get_query_types);
|
2003-03-01 14:48:00 +00:00
|
|
|
gst_pad_set_query_function (ivorbisfile->srcpad, gst_ivorbisfile_src_query);
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_pad_set_event_mask_function (ivorbisfile->srcpad,
|
|
|
|
gst_ivorbisfile_get_event_masks);
|
2003-03-01 14:48:00 +00:00
|
|
|
gst_pad_set_event_function (ivorbisfile->srcpad, gst_ivorbisfile_src_event);
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_pad_set_convert_function (ivorbisfile->srcpad,
|
|
|
|
gst_ivorbisfile_src_convert);
|
2003-03-01 14:48:00 +00:00
|
|
|
|
|
|
|
ivorbisfile->total_bytes = 0;
|
|
|
|
ivorbisfile->offset = 0;
|
|
|
|
ivorbisfile->seek_pending = 0;
|
|
|
|
ivorbisfile->need_discont = FALSE;
|
|
|
|
ivorbisfile->metadata = NULL;
|
|
|
|
ivorbisfile->streaminfo = NULL;
|
|
|
|
ivorbisfile->current_link = -1;
|
2003-02-23 17:35:35 +00:00
|
|
|
}
|
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
/* the next four functions are the ov callbacks we provide to ivorbisfile
|
2003-02-23 17:35:35 +00:00
|
|
|
* which interface between GStreamer's handling of the data flow and
|
|
|
|
* vorbis's needs */
|
|
|
|
static size_t
|
2003-03-01 14:48:00 +00:00
|
|
|
gst_ivorbisfile_read (void *ptr, size_t size, size_t nmemb, void *datasource)
|
2003-02-23 17:35:35 +00:00
|
|
|
{
|
|
|
|
guint32 got_bytes = 0;
|
|
|
|
guint8 *data;
|
|
|
|
size_t read_size = size * nmemb;
|
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
Ivorbisfile *ivorbisfile = GST_IVORBISFILE (datasource);
|
2003-02-23 17:35:35 +00:00
|
|
|
|
2003-06-29 19:46:13 +00:00
|
|
|
GST_DEBUG ("read %d", read_size);
|
2003-02-23 17:35:35 +00:00
|
|
|
|
|
|
|
/* make sure we don't go to EOS */
|
2004-03-14 22:34:33 +00:00
|
|
|
if (!ivorbisfile->may_eos && ivorbisfile->total_bytes &&
|
|
|
|
ivorbisfile->offset + read_size > ivorbisfile->total_bytes) {
|
2003-03-01 14:48:00 +00:00
|
|
|
read_size = ivorbisfile->total_bytes - ivorbisfile->offset;
|
2003-02-23 17:35:35 +00:00
|
|
|
}
|
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
if (read_size == 0 || ivorbisfile->eos)
|
2003-02-23 17:35:35 +00:00
|
|
|
return 0;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-02-23 17:35:35 +00:00
|
|
|
while (got_bytes == 0) {
|
2003-03-01 14:48:00 +00:00
|
|
|
got_bytes = gst_bytestream_peek_bytes (ivorbisfile->bs, &data, read_size);
|
2003-02-23 17:35:35 +00:00
|
|
|
if (got_bytes < read_size) {
|
|
|
|
GstEvent *event;
|
|
|
|
guint32 avail;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
|
|
|
gst_bytestream_get_status (ivorbisfile->bs, &avail, &event);
|
2003-02-23 17:35:35 +00:00
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2004-03-15 19:32:27 +00:00
|
|
|
case GST_EVENT_EOS:
|
|
|
|
GST_DEBUG ("eos");
|
|
|
|
ivorbisfile->eos = TRUE;
|
|
|
|
if (avail == 0) {
|
|
|
|
gst_event_unref (event);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_EVENT_DISCONTINUOUS:
|
|
|
|
GST_DEBUG ("discont");
|
|
|
|
ivorbisfile->need_discont = TRUE;
|
|
|
|
default:
|
|
|
|
break;
|
2003-02-23 17:35:35 +00:00
|
|
|
}
|
|
|
|
gst_event_unref (event);
|
2004-03-14 22:34:33 +00:00
|
|
|
if (avail > 0)
|
2004-03-15 19:32:27 +00:00
|
|
|
got_bytes = gst_bytestream_peek_bytes (ivorbisfile->bs, &data, avail);
|
2003-02-23 17:35:35 +00:00
|
|
|
else
|
2004-03-15 19:32:27 +00:00
|
|
|
got_bytes = 0;
|
2003-02-23 17:35:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy (ptr, data, got_bytes);
|
2003-03-01 14:48:00 +00:00
|
|
|
gst_bytestream_flush_fast (ivorbisfile->bs, got_bytes);
|
2003-02-23 17:35:35 +00:00
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
ivorbisfile->offset += got_bytes;
|
2003-02-23 17:35:35 +00:00
|
|
|
|
|
|
|
return got_bytes / size;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2003-03-01 14:48:00 +00:00
|
|
|
gst_ivorbisfile_seek (void *datasource, int64_t offset, int whence)
|
2003-02-23 17:35:35 +00:00
|
|
|
{
|
2003-03-01 14:48:00 +00:00
|
|
|
Ivorbisfile *ivorbisfile = GST_IVORBISFILE (datasource);
|
2003-02-23 17:35:35 +00:00
|
|
|
GstSeekType method;
|
2003-03-01 14:48:00 +00:00
|
|
|
guint64 pending_offset = ivorbisfile->offset;
|
2003-02-23 17:35:35 +00:00
|
|
|
gboolean need_total = FALSE;
|
|
|
|
|
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
if (!ivorbisfile->vf.seekable) {
|
2003-02-23 17:35:35 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-06-29 19:46:13 +00:00
|
|
|
GST_DEBUG ("seek %lld %d", offset, whence);
|
2003-02-23 17:35:35 +00:00
|
|
|
|
|
|
|
if (whence == SEEK_SET) {
|
|
|
|
method = GST_SEEK_METHOD_SET;
|
|
|
|
pending_offset = offset;
|
2004-03-14 22:34:33 +00:00
|
|
|
} else if (whence == SEEK_CUR) {
|
2003-02-23 17:35:35 +00:00
|
|
|
method = GST_SEEK_METHOD_CUR;
|
|
|
|
pending_offset += offset;
|
2004-03-14 22:34:33 +00:00
|
|
|
} else if (whence == SEEK_END) {
|
2003-02-23 17:35:35 +00:00
|
|
|
method = GST_SEEK_METHOD_END;
|
|
|
|
need_total = TRUE;
|
2003-03-01 14:48:00 +00:00
|
|
|
pending_offset = ivorbisfile->total_bytes - offset;
|
2004-03-14 22:34:33 +00:00
|
|
|
} else
|
2003-02-23 17:35:35 +00:00
|
|
|
return -1;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
if (!gst_bytestream_seek (ivorbisfile->bs, offset, method))
|
2003-02-23 17:35:35 +00:00
|
|
|
return -1;
|
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
ivorbisfile->offset = pending_offset;
|
2003-02-23 17:35:35 +00:00
|
|
|
if (need_total)
|
2003-03-01 14:48:00 +00:00
|
|
|
ivorbisfile->total_bytes = gst_bytestream_tell (ivorbisfile->bs) + offset;
|
2003-02-23 17:35:35 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2003-03-01 14:48:00 +00:00
|
|
|
gst_ivorbisfile_close (void *datasource)
|
2003-02-23 17:35:35 +00:00
|
|
|
{
|
2003-06-29 19:46:13 +00:00
|
|
|
GST_DEBUG ("close");
|
2003-02-23 17:35:35 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static long
|
2003-03-01 14:48:00 +00:00
|
|
|
gst_ivorbisfile_tell (void *datasource)
|
2003-02-23 17:35:35 +00:00
|
|
|
{
|
2003-03-01 14:48:00 +00:00
|
|
|
Ivorbisfile *ivorbisfile = GST_IVORBISFILE (datasource);
|
2003-02-23 17:35:35 +00:00
|
|
|
long result;
|
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
result = gst_bytestream_tell (ivorbisfile->bs);
|
2003-02-23 17:35:35 +00:00
|
|
|
|
2003-06-29 19:46:13 +00:00
|
|
|
GST_DEBUG ("tell %ld", result);
|
2003-02-23 17:35:35 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
ov_callbacks ivorbisfile_ov_callbacks = {
|
2003-03-01 14:48:00 +00:00
|
|
|
gst_ivorbisfile_read,
|
|
|
|
gst_ivorbisfile_seek,
|
|
|
|
gst_ivorbisfile_close,
|
|
|
|
gst_ivorbisfile_tell,
|
2003-02-23 17:35:35 +00:00
|
|
|
};
|
|
|
|
|
2003-12-27 13:07:06 +00:00
|
|
|
#if 0
|
2003-02-23 17:35:35 +00:00
|
|
|
/* retrieve the comment field (or tags) and put in metadata GstCaps
|
|
|
|
* returns TRUE if caps could be set,
|
|
|
|
* FALSE if they couldn't be read somehow */
|
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_ivorbisfile_update_metadata (Ivorbisfile * ivorbisfile, gint link)
|
2003-02-23 17:35:35 +00:00
|
|
|
{
|
2003-03-01 14:48:00 +00:00
|
|
|
OggVorbis_File *vf = &ivorbisfile->vf;
|
2003-02-23 17:35:35 +00:00
|
|
|
gchar **ptr;
|
|
|
|
vorbis_comment *vc;
|
|
|
|
GstProps *props = NULL;
|
|
|
|
GstPropsEntry *entry;
|
|
|
|
gchar *name, *value;
|
|
|
|
|
|
|
|
/* clear old one */
|
2003-03-01 14:48:00 +00:00
|
|
|
if (ivorbisfile->metadata) {
|
|
|
|
gst_caps_unref (ivorbisfile->metadata);
|
|
|
|
ivorbisfile->metadata = NULL;
|
2003-02-23 17:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* create props to hold the key/value pairs */
|
|
|
|
props = gst_props_empty_new ();
|
|
|
|
|
|
|
|
vc = ov_comment (vf, link);
|
|
|
|
ptr = vc->user_comments;
|
|
|
|
while (*ptr) {
|
|
|
|
value = strstr (*ptr, "=");
|
|
|
|
if (value) {
|
2004-03-14 22:34:33 +00:00
|
|
|
name = g_strndup (*ptr, value - *ptr);
|
|
|
|
entry = gst_props_entry_new (name, GST_PROPS_STRING_TYPE, value + 1);
|
2003-02-23 17:35:35 +00:00
|
|
|
gst_props_add_entry (props, (GstPropsEntry *) entry);
|
|
|
|
}
|
|
|
|
ptr++;
|
|
|
|
}
|
2003-03-01 14:48:00 +00:00
|
|
|
ivorbisfile->metadata = gst_caps_new ("ivorbisfile_metadata",
|
2004-03-14 22:34:33 +00:00
|
|
|
"application/x-gst-metadata", props);
|
2003-02-23 17:35:35 +00:00
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
g_object_notify (G_OBJECT (ivorbisfile), "metadata");
|
2003-02-23 17:35:35 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* retrieve logical stream properties and put them in streaminfo GstCaps
|
|
|
|
* returns TRUE if caps could be set,
|
|
|
|
* FALSE if they couldn't be read somehow */
|
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_ivorbisfile_update_streaminfo (Ivorbisfile * ivorbisfile, gint link)
|
2003-02-23 17:35:35 +00:00
|
|
|
{
|
2003-03-01 14:48:00 +00:00
|
|
|
OggVorbis_File *vf = &ivorbisfile->vf;
|
2003-02-23 17:35:35 +00:00
|
|
|
vorbis_info *vi;
|
|
|
|
GstProps *props = NULL;
|
|
|
|
GstPropsEntry *entry;
|
|
|
|
|
|
|
|
/* clear old one */
|
2003-03-01 14:48:00 +00:00
|
|
|
if (ivorbisfile->streaminfo) {
|
|
|
|
gst_caps_unref (ivorbisfile->streaminfo);
|
|
|
|
ivorbisfile->streaminfo = NULL;
|
2003-02-23 17:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* create props to hold the key/value pairs */
|
|
|
|
props = gst_props_empty_new ();
|
|
|
|
|
|
|
|
vi = ov_info (vf, link);
|
|
|
|
entry = gst_props_entry_new ("version", GST_PROPS_INT_TYPE, vi->version);
|
|
|
|
gst_props_add_entry (props, (GstPropsEntry *) entry);
|
2004-03-14 22:34:33 +00:00
|
|
|
entry = gst_props_entry_new ("bitrate_upper", GST_PROPS_INT_TYPE,
|
|
|
|
vi->bitrate_upper);
|
2003-02-23 17:35:35 +00:00
|
|
|
gst_props_add_entry (props, (GstPropsEntry *) entry);
|
2004-03-14 22:34:33 +00:00
|
|
|
entry = gst_props_entry_new ("bitrate_nominal", GST_PROPS_INT_TYPE,
|
|
|
|
vi->bitrate_nominal);
|
2003-02-23 17:35:35 +00:00
|
|
|
gst_props_add_entry (props, (GstPropsEntry *) entry);
|
2004-03-14 22:34:33 +00:00
|
|
|
entry = gst_props_entry_new ("bitrate_lower", GST_PROPS_INT_TYPE,
|
|
|
|
vi->bitrate_lower);
|
2003-02-23 17:35:35 +00:00
|
|
|
gst_props_add_entry (props, (GstPropsEntry *) entry);
|
2004-03-14 22:34:33 +00:00
|
|
|
entry = gst_props_entry_new ("serial", GST_PROPS_INT_TYPE,
|
|
|
|
ov_serialnumber (vf, link));
|
2003-02-23 17:35:35 +00:00
|
|
|
gst_props_add_entry (props, (GstPropsEntry *) entry);
|
2004-03-14 22:34:33 +00:00
|
|
|
entry = gst_props_entry_new ("bitrate", GST_PROPS_INT_TYPE,
|
|
|
|
ov_bitrate (vf, link));
|
2003-02-23 17:35:35 +00:00
|
|
|
gst_props_add_entry (props, (GstPropsEntry *) entry);
|
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
ivorbisfile->streaminfo = gst_caps_new ("ivorbisfile_streaminfo",
|
2004-03-14 22:34:33 +00:00
|
|
|
"application/x-gst-streaminfo", props);
|
2003-02-23 17:35:35 +00:00
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
g_object_notify (G_OBJECT (ivorbisfile), "streaminfo");
|
2003-02-23 17:35:35 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2003-12-27 13:07:06 +00:00
|
|
|
#endif
|
2003-02-23 17:35:35 +00:00
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_ivorbisfile_new_link (Ivorbisfile * ivorbisfile, gint link)
|
2003-02-23 17:35:35 +00:00
|
|
|
{
|
2003-03-01 14:48:00 +00:00
|
|
|
vorbis_info *vi = ov_info (&ivorbisfile->vf, link);
|
2003-12-27 13:07:06 +00:00
|
|
|
GstCaps *caps;
|
|
|
|
gboolean res = TRUE;
|
2003-02-23 17:35:35 +00:00
|
|
|
|
|
|
|
/* new logical bitstream */
|
2003-03-01 14:48:00 +00:00
|
|
|
ivorbisfile->current_link = link;
|
2003-02-23 17:35:35 +00:00
|
|
|
|
2003-12-27 13:07:06 +00:00
|
|
|
caps = gst_caps_new_simple ("audio/x-raw-int",
|
2004-03-14 22:34:33 +00:00
|
|
|
"endianness", G_TYPE_INT, G_BYTE_ORDER,
|
|
|
|
"signed", G_TYPE_BOOLEAN, TRUE,
|
|
|
|
"width", G_TYPE_INT, 16,
|
|
|
|
"depth", G_TYPE_INT, 16,
|
|
|
|
"rate", G_TYPE_INT, vi->rate, "channels", G_TYPE_INT, vi->channels, NULL);
|
2003-12-27 13:07:06 +00:00
|
|
|
|
|
|
|
if (gst_pad_try_set_caps (ivorbisfile->srcpad, caps) <= 0) {
|
2004-03-14 22:34:33 +00:00
|
|
|
res = FALSE;
|
2003-02-23 17:35:35 +00:00
|
|
|
}
|
|
|
|
|
2003-12-27 13:07:06 +00:00
|
|
|
gst_caps_free (caps);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-02-23 17:35:35 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_ivorbisfile_loop (GstElement * element)
|
2003-02-23 17:35:35 +00:00
|
|
|
{
|
2003-03-01 14:48:00 +00:00
|
|
|
Ivorbisfile *ivorbisfile = GST_IVORBISFILE (element);
|
2003-02-23 17:35:35 +00:00
|
|
|
GstBuffer *outbuf;
|
|
|
|
long ret;
|
|
|
|
GstClockTime time;
|
|
|
|
gint64 samples;
|
|
|
|
gint link;
|
|
|
|
|
|
|
|
/* this function needs to go first since you don't want to be messing
|
|
|
|
* with an unset vf ;) */
|
2003-03-01 14:48:00 +00:00
|
|
|
if (ivorbisfile->restart) {
|
|
|
|
ivorbisfile->offset = 0;
|
|
|
|
ivorbisfile->total_bytes = 0;
|
|
|
|
ivorbisfile->may_eos = FALSE;
|
2004-01-18 21:46:58 +00:00
|
|
|
ivorbisfile->vf.seekable = gst_bytestream_seek (ivorbisfile->bs, 0,
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_SEEK_METHOD_SET);
|
2003-06-29 19:46:13 +00:00
|
|
|
GST_DEBUG ("ivorbisfile: seekable: %s\n",
|
2004-03-15 19:32:27 +00:00
|
|
|
ivorbisfile->vf.seekable ? "yes" : "no");
|
2003-02-23 17:35:35 +00:00
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
/* open our custom ivorbisfile data object with the callbacks we provide */
|
2004-01-18 21:46:58 +00:00
|
|
|
if (ov_open_callbacks (ivorbisfile, &ivorbisfile->vf, NULL, 0,
|
2004-03-15 19:32:27 +00:00
|
|
|
ivorbisfile_ov_callbacks) < 0) {
|
2004-02-02 17:23:33 +00:00
|
|
|
GST_ELEMENT_ERROR (element, STREAM, DECODE, (NULL), (NULL));
|
2003-02-23 17:35:35 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-03-01 14:48:00 +00:00
|
|
|
ivorbisfile->need_discont = TRUE;
|
|
|
|
ivorbisfile->restart = FALSE;
|
|
|
|
ivorbisfile->current_link = -1;
|
2003-02-23 17:35:35 +00:00
|
|
|
}
|
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
if (ivorbisfile->seek_pending) {
|
2003-02-23 17:35:35 +00:00
|
|
|
/* get time to seek to in seconds */
|
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
switch (ivorbisfile->seek_format) {
|
2003-02-23 17:35:35 +00:00
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
{
|
2004-03-15 19:32:27 +00:00
|
|
|
gdouble seek_to = (gdouble) ivorbisfile->seek_value / GST_SECOND;
|
|
|
|
|
|
|
|
if (ivorbisfile->seek_accurate) {
|
|
|
|
if (ov_time_seek (&ivorbisfile->vf, seek_to) == 0) {
|
|
|
|
ivorbisfile->need_discont = TRUE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (ov_time_seek_page (&ivorbisfile->vf, seek_to) == 0) {
|
|
|
|
ivorbisfile->need_discont = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2003-02-23 17:35:35 +00:00
|
|
|
}
|
2003-05-24 10:41:58 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
2004-03-15 19:32:27 +00:00
|
|
|
if (ivorbisfile->seek_accurate) {
|
|
|
|
if (ov_pcm_seek (&ivorbisfile->vf, ivorbisfile->seek_value) == 0) {
|
|
|
|
ivorbisfile->need_discont = TRUE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (ov_pcm_seek_page (&ivorbisfile->vf, ivorbisfile->seek_value) == 0) {
|
|
|
|
ivorbisfile->need_discont = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2003-02-23 17:35:35 +00:00
|
|
|
default:
|
2004-03-15 19:32:27 +00:00
|
|
|
if (ivorbisfile->seek_format == logical_stream_format) {
|
|
|
|
gint64 seek_to;
|
|
|
|
|
|
|
|
seek_to = ivorbisfile->vf.offsets[ivorbisfile->seek_value];
|
|
|
|
|
|
|
|
if (ov_raw_seek (&ivorbisfile->vf, seek_to) == 0) {
|
|
|
|
ivorbisfile->need_discont = TRUE;
|
|
|
|
ivorbisfile->current_link = -1;
|
|
|
|
} else {
|
|
|
|
g_warning ("raw seek failed");
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
g_warning ("unknown seek method, implement me !");
|
|
|
|
break;
|
2003-02-23 17:35:35 +00:00
|
|
|
}
|
2003-03-01 14:48:00 +00:00
|
|
|
ivorbisfile->seek_pending = FALSE;
|
2003-02-23 17:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* we update the caps for each logical stream */
|
2003-03-01 14:48:00 +00:00
|
|
|
if (ivorbisfile->vf.current_link != ivorbisfile->current_link) {
|
|
|
|
if (!gst_ivorbisfile_new_link (ivorbisfile, ivorbisfile->vf.current_link)) {
|
2004-02-02 17:23:33 +00:00
|
|
|
GST_ELEMENT_ERROR (ivorbisfile, CORE, NEGOTIATION, (NULL), (NULL));
|
2003-02-23 17:35:35 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
outbuf = gst_buffer_new ();
|
|
|
|
GST_BUFFER_DATA (outbuf) = g_malloc (4096);
|
|
|
|
GST_BUFFER_SIZE (outbuf) = 4096;
|
|
|
|
|
|
|
|
/* get current time for discont and buffer timestamp */
|
2003-03-01 14:48:00 +00:00
|
|
|
time = (GstClockTime) (ov_time_tell (&ivorbisfile->vf) * GST_SECOND);
|
2003-02-23 17:35:35 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
ret = ov_read (&ivorbisfile->vf,
|
|
|
|
GST_BUFFER_DATA (outbuf), GST_BUFFER_SIZE (outbuf), &link);
|
2003-02-23 17:35:35 +00:00
|
|
|
|
|
|
|
if (ret == 0) {
|
2003-06-29 19:46:13 +00:00
|
|
|
GST_DEBUG ("eos");
|
2003-02-23 17:35:35 +00:00
|
|
|
/* send EOS event */
|
2004-03-14 22:34:33 +00:00
|
|
|
/*ov_clear (&ivorbisfile->vf); */
|
2003-03-01 14:48:00 +00:00
|
|
|
ivorbisfile->restart = TRUE;
|
2003-02-23 17:35:35 +00:00
|
|
|
gst_buffer_unref (outbuf);
|
|
|
|
/* if the pad is not usable, don't push it out */
|
2003-03-01 14:48:00 +00:00
|
|
|
if (GST_PAD_IS_USABLE (ivorbisfile->srcpad)) {
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_pad_push (ivorbisfile->srcpad,
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_DATA (gst_event_new (GST_EVENT_EOS)));
|
2003-02-23 17:35:35 +00:00
|
|
|
}
|
|
|
|
gst_element_set_eos (element);
|
|
|
|
return;
|
2004-03-14 22:34:33 +00:00
|
|
|
} else if (ret < 0) {
|
2003-03-01 14:48:00 +00:00
|
|
|
g_warning ("ivorbisfile: decoding error");
|
2003-02-23 17:35:35 +00:00
|
|
|
gst_buffer_unref (outbuf);
|
|
|
|
return;
|
2004-03-14 22:34:33 +00:00
|
|
|
} else {
|
2003-03-01 14:48:00 +00:00
|
|
|
if (ivorbisfile->need_discont) {
|
2003-02-23 17:35:35 +00:00
|
|
|
GstEvent *discont;
|
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
ivorbisfile->need_discont = FALSE;
|
2003-02-23 17:35:35 +00:00
|
|
|
|
|
|
|
/* if the pad is not usable, don't push it out */
|
2003-03-01 14:48:00 +00:00
|
|
|
if (GST_PAD_IS_USABLE (ivorbisfile->srcpad)) {
|
2004-03-15 19:32:27 +00:00
|
|
|
/* get stream stats */
|
|
|
|
samples = (gint64) (ov_pcm_tell (&ivorbisfile->vf));
|
2003-02-23 17:35:35 +00:00
|
|
|
|
2004-03-15 19:32:27 +00:00
|
|
|
discont = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME, time,
|
|
|
|
GST_FORMAT_DEFAULT, samples, NULL);
|
2003-02-23 17:35:35 +00:00
|
|
|
|
2004-03-15 19:32:27 +00:00
|
|
|
gst_pad_push (ivorbisfile->srcpad, GST_DATA (discont));
|
2003-02-23 17:35:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_BUFFER_SIZE (outbuf) = ret;
|
|
|
|
GST_BUFFER_TIMESTAMP (outbuf) = time;
|
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
ivorbisfile->may_eos = TRUE;
|
2003-02-23 17:35:35 +00:00
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
if (!ivorbisfile->vf.seekable) {
|
|
|
|
ivorbisfile->total_bytes += GST_BUFFER_SIZE (outbuf);
|
2003-02-23 17:35:35 +00:00
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
|
|
|
|
if (GST_PAD_IS_USABLE (ivorbisfile->srcpad))
|
2003-10-08 16:08:19 +00:00
|
|
|
gst_pad_push (ivorbisfile->srcpad, GST_DATA (outbuf));
|
2003-02-23 17:35:35 +00:00
|
|
|
else
|
|
|
|
gst_buffer_unref (outbuf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static const GstFormat *
|
|
|
|
gst_ivorbisfile_get_formats (GstPad * pad)
|
2003-02-23 17:35:35 +00:00
|
|
|
{
|
|
|
|
static GstFormat src_formats[] = {
|
|
|
|
GST_FORMAT_TIME,
|
|
|
|
GST_FORMAT_BYTES,
|
2003-05-24 10:41:58 +00:00
|
|
|
GST_FORMAT_DEFAULT,
|
2003-02-23 17:35:35 +00:00
|
|
|
0,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
static GstFormat sink_formats[] = {
|
|
|
|
GST_FORMAT_TIME,
|
|
|
|
GST_FORMAT_BYTES,
|
|
|
|
0,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
|
|
|
|
src_formats[3] = logical_stream_format;
|
|
|
|
sink_formats[2] = logical_stream_format;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-02-23 17:35:35 +00:00
|
|
|
return (GST_PAD_IS_SRC (pad) ? src_formats : sink_formats);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_ivorbisfile_src_convert (GstPad * pad,
|
|
|
|
GstFormat src_format, gint64 src_value,
|
|
|
|
GstFormat * dest_format, gint64 * dest_value)
|
2003-02-23 17:35:35 +00:00
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
guint scale = 1;
|
|
|
|
gint bytes_per_sample;
|
2004-03-14 22:34:33 +00:00
|
|
|
Ivorbisfile *ivorbisfile;
|
2003-02-23 17:35:35 +00:00
|
|
|
vorbis_info *vi;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
ivorbisfile = GST_IVORBISFILE (gst_pad_get_parent (pad));
|
2003-02-23 17:35:35 +00:00
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
vi = ov_info (&ivorbisfile->vf, -1);
|
2003-02-23 17:35:35 +00:00
|
|
|
bytes_per_sample = vi->channels * 2;
|
|
|
|
|
|
|
|
switch (src_format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
switch (*dest_format) {
|
2004-03-15 19:32:27 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
|
|
|
*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-02-23 17:35:35 +00:00
|
|
|
}
|
2003-05-24 10:41:58 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
2003-02-23 17:35:35 +00:00
|
|
|
switch (*dest_format) {
|
2004-03-15 19:32:27 +00:00
|
|
|
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;
|
2003-02-23 17:35:35 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
switch (*dest_format) {
|
2004-03-15 19:32:27 +00:00
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
scale = bytes_per_sample;
|
|
|
|
case GST_FORMAT_DEFAULT:
|
|
|
|
*dest_value = src_value * scale * vi->rate / GST_SECOND;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
2003-02-23 17:35:35 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (src_format == logical_stream_format) {
|
2004-03-15 19:32:27 +00:00
|
|
|
/* 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:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_DEFAULT:
|
|
|
|
if (src_value > ivorbisfile->vf.links) {
|
|
|
|
src_value = ivorbisfile->vf.links;
|
|
|
|
}
|
|
|
|
for (i = 0; i < src_value; i++) {
|
|
|
|
vi = ov_info (&ivorbisfile->vf, i);
|
|
|
|
|
|
|
|
count += ov_pcm_total (&ivorbisfile->vf, i);
|
|
|
|
}
|
|
|
|
*dest_value = count;
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
{
|
|
|
|
if (src_value > ivorbisfile->vf.links) {
|
|
|
|
src_value = ivorbisfile->vf.links;
|
|
|
|
}
|
|
|
|
for (i = 0; i < src_value; i++) {
|
|
|
|
vi = ov_info (&ivorbisfile->vf, i);
|
|
|
|
if (vi->rate)
|
|
|
|
count +=
|
|
|
|
ov_pcm_total (&ivorbisfile->vf, i) * GST_SECOND / vi->rate;
|
|
|
|
else
|
|
|
|
count += ov_time_total (&ivorbisfile->vf, i) * GST_SECOND;
|
|
|
|
}
|
|
|
|
/* we use the pcm totals to get the total time, it's more accurate */
|
|
|
|
*dest_value = count;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
} else
|
2004-03-15 19:32:27 +00:00
|
|
|
res = FALSE;
|
2003-02-23 17:35:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_ivorbisfile_sink_convert (GstPad * pad,
|
|
|
|
GstFormat src_format, gint64 src_value,
|
|
|
|
GstFormat * dest_format, gint64 * dest_value)
|
2003-02-23 17:35:35 +00:00
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
2004-03-14 22:34:33 +00:00
|
|
|
Ivorbisfile *ivorbisfile;
|
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
ivorbisfile = GST_IVORBISFILE (gst_pad_get_parent (pad));
|
2003-02-23 17:35:35 +00:00
|
|
|
|
|
|
|
switch (src_format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
switch (*dest_format) {
|
2004-03-15 19:32:27 +00:00
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (*dest_format == logical_stream_format) {
|
|
|
|
} else
|
|
|
|
res = FALSE;
|
2003-02-23 17:35:35 +00:00
|
|
|
}
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
switch (*dest_format) {
|
2004-03-15 19:32:27 +00:00
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (*dest_format == logical_stream_format) {
|
|
|
|
} else
|
|
|
|
res = FALSE;
|
2003-02-23 17:35:35 +00:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
if (src_format == logical_stream_format) {
|
2004-03-15 19:32:27 +00:00
|
|
|
switch (*dest_format) {
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
} else
|
2004-03-15 19:32:27 +00:00
|
|
|
res = FALSE;
|
2003-02-23 17:35:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static const GstQueryType *
|
|
|
|
gst_ivorbisfile_get_query_types (GstPad * pad)
|
2003-02-23 17:35:35 +00:00
|
|
|
{
|
2003-03-01 14:48:00 +00:00
|
|
|
static const GstQueryType types[] = {
|
|
|
|
GST_QUERY_TOTAL,
|
|
|
|
GST_QUERY_POSITION,
|
2003-02-23 17:35:35 +00:00
|
|
|
0
|
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2003-02-23 17:35:35 +00:00
|
|
|
return types;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handles queries for location in the stream in the requested format */
|
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_ivorbisfile_src_query (GstPad * pad, GstQueryType type,
|
|
|
|
GstFormat * format, gint64 * value)
|
2003-02-23 17:35:35 +00:00
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
2004-03-14 22:34:33 +00:00
|
|
|
Ivorbisfile *ivorbisfile;
|
2003-02-23 17:35:35 +00:00
|
|
|
vorbis_info *vi;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
ivorbisfile = GST_IVORBISFILE (gst_pad_get_parent (pad));
|
2003-02-23 17:35:35 +00:00
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
vi = ov_info (&ivorbisfile->vf, -1);
|
2003-02-23 17:35:35 +00:00
|
|
|
|
|
|
|
switch (type) {
|
2003-03-01 14:48:00 +00:00
|
|
|
case GST_QUERY_TOTAL:
|
2003-02-23 17:35:35 +00:00
|
|
|
{
|
|
|
|
switch (*format) {
|
2004-03-15 19:32:27 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
|
|
|
if (ivorbisfile->vf.seekable)
|
|
|
|
*value = ov_pcm_total (&ivorbisfile->vf, -1);
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
if (ivorbisfile->vf.seekable)
|
|
|
|
*value = ov_pcm_total (&ivorbisfile->vf, -1) * vi->channels * 2;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
if (ivorbisfile->vf.seekable)
|
|
|
|
*value =
|
|
|
|
(gint64) (ov_time_total (&ivorbisfile->vf, -1) * GST_SECOND);
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (*format == logical_stream_format) {
|
|
|
|
if (ivorbisfile->vf.seekable)
|
|
|
|
*value = ivorbisfile->vf.links;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
} else
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
2003-02-23 17:35:35 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2003-03-01 14:48:00 +00:00
|
|
|
case GST_QUERY_POSITION:
|
2003-02-23 17:35:35 +00:00
|
|
|
switch (*format) {
|
2004-03-15 19:32:27 +00:00
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
if (ivorbisfile->vf.seekable)
|
|
|
|
*value = (gint64) (ov_time_tell (&ivorbisfile->vf) * GST_SECOND);
|
|
|
|
else
|
|
|
|
*value = ivorbisfile->total_bytes * GST_SECOND
|
|
|
|
/ (vi->rate * vi->channels * 2);
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
if (ivorbisfile->vf.seekable)
|
|
|
|
*value = ov_pcm_tell (&ivorbisfile->vf) * vi->channels * 2;
|
|
|
|
else
|
|
|
|
*value = ivorbisfile->total_bytes;
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_DEFAULT:
|
|
|
|
if (ivorbisfile->vf.seekable)
|
|
|
|
*value = ov_pcm_tell (&ivorbisfile->vf);
|
|
|
|
else
|
|
|
|
*value = ivorbisfile->total_bytes / (vi->channels * 2);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (*format == logical_stream_format) {
|
|
|
|
if (ivorbisfile->vf.seekable)
|
|
|
|
*value = ivorbisfile->current_link;
|
|
|
|
else
|
|
|
|
return FALSE;
|
|
|
|
} else
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
2003-02-23 17:35:35 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static const GstEventMask *
|
|
|
|
gst_ivorbisfile_get_event_masks (GstPad * pad)
|
2003-02-23 17:35:35 +00:00
|
|
|
{
|
|
|
|
static const GstEventMask masks[] = {
|
2004-03-14 22:34:33 +00:00
|
|
|
{GST_EVENT_SEEK, GST_SEEK_METHOD_SET | GST_SEEK_FLAG_ACCURATE},
|
|
|
|
{0,}
|
2003-02-23 17:35:35 +00:00
|
|
|
};
|
2004-03-15 19:32:27 +00:00
|
|
|
|
2003-02-23 17:35:35 +00:00
|
|
|
return masks;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* handle events on src pad */
|
|
|
|
static gboolean
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_ivorbisfile_src_event (GstPad * pad, GstEvent * event)
|
2003-02-23 17:35:35 +00:00
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
2004-03-14 22:34:33 +00:00
|
|
|
Ivorbisfile *ivorbisfile;
|
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
ivorbisfile = GST_IVORBISFILE (gst_pad_get_parent (pad));
|
2003-02-23 17:35:35 +00:00
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_SEEK:
|
|
|
|
{
|
|
|
|
gint64 offset;
|
|
|
|
vorbis_info *vi;
|
|
|
|
GstFormat format;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-06-29 19:46:13 +00:00
|
|
|
GST_DEBUG ("ivorbisfile: handling seek event on pad %s:%s",
|
2004-03-15 19:32:27 +00:00
|
|
|
GST_DEBUG_PAD_NAME (pad));
|
2003-03-01 14:48:00 +00:00
|
|
|
if (!ivorbisfile->vf.seekable) {
|
2004-03-15 19:32:27 +00:00
|
|
|
gst_event_unref (event);
|
|
|
|
GST_DEBUG ("vorbis stream is not seekable");
|
|
|
|
return FALSE;
|
2003-02-23 17:35:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
offset = GST_EVENT_SEEK_OFFSET (event);
|
|
|
|
format = GST_EVENT_SEEK_FORMAT (event);
|
|
|
|
|
|
|
|
switch (format) {
|
2004-03-15 19:32:27 +00:00
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
ivorbisfile->seek_pending = TRUE;
|
|
|
|
ivorbisfile->seek_value = offset;
|
|
|
|
ivorbisfile->seek_format = format;
|
|
|
|
ivorbisfile->seek_accurate = GST_EVENT_SEEK_FLAGS (event)
|
|
|
|
& GST_SEEK_FLAG_ACCURATE;
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
vi = ov_info (&ivorbisfile->vf, -1);
|
|
|
|
if (vi->channels == 0) {
|
|
|
|
GST_DEBUG ("vorbis stream has 0 channels ?");
|
|
|
|
res = FALSE;
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
offset /= vi->channels * 2;
|
|
|
|
/* fallthrough */
|
|
|
|
case GST_FORMAT_DEFAULT:
|
|
|
|
ivorbisfile->seek_pending = TRUE;
|
|
|
|
ivorbisfile->seek_value = offset;
|
|
|
|
ivorbisfile->seek_format = format;
|
|
|
|
ivorbisfile->seek_accurate = GST_EVENT_SEEK_FLAGS (event)
|
|
|
|
& GST_SEEK_FLAG_ACCURATE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (format == logical_stream_format) {
|
|
|
|
ivorbisfile->seek_pending = TRUE;
|
|
|
|
ivorbisfile->seek_value = offset;
|
|
|
|
ivorbisfile->seek_format = format;
|
|
|
|
ivorbisfile->seek_accurate = GST_EVENT_SEEK_FLAGS (event)
|
|
|
|
& GST_SEEK_FLAG_ACCURATE;
|
|
|
|
} else {
|
|
|
|
GST_DEBUG ("unhandled seek format");
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
2003-02-23 17:35:35 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
done:
|
|
|
|
gst_event_unref (event);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstElementStateReturn
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_ivorbisfile_change_state (GstElement * element)
|
2003-02-23 17:35:35 +00:00
|
|
|
{
|
2003-03-01 14:48:00 +00:00
|
|
|
Ivorbisfile *ivorbisfile = GST_IVORBISFILE (element);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-02-23 17:35:35 +00:00
|
|
|
switch (GST_STATE_TRANSITION (element)) {
|
|
|
|
case GST_STATE_NULL_TO_READY:
|
|
|
|
case GST_STATE_READY_TO_PAUSED:
|
2003-03-01 14:48:00 +00:00
|
|
|
ivorbisfile->restart = TRUE;
|
|
|
|
ivorbisfile->bs = gst_bytestream_new (ivorbisfile->sinkpad);
|
2003-02-23 17:35:35 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_PLAYING:
|
2003-03-01 14:48:00 +00:00
|
|
|
ivorbisfile->eos = FALSE;
|
2003-02-23 17:35:35 +00:00
|
|
|
case GST_STATE_PLAYING_TO_PAUSED:
|
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
2003-03-01 14:48:00 +00:00
|
|
|
ov_clear (&ivorbisfile->vf);
|
|
|
|
gst_bytestream_destroy (ivorbisfile->bs);
|
2003-02-23 17:35:35 +00:00
|
|
|
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);
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-02-23 17:35:35 +00:00
|
|
|
return GST_STATE_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_ivorbisfile_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
2003-02-23 17:35:35 +00:00
|
|
|
{
|
2003-03-01 14:48:00 +00:00
|
|
|
Ivorbisfile *ivorbisfile;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
g_return_if_fail (GST_IS_IVORBISFILE (object));
|
2003-02-23 17:35:35 +00:00
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
ivorbisfile = GST_IVORBISFILE (object);
|
2003-02-23 17:35:35 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
default:
|
|
|
|
g_warning ("Unknown property id\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void
|
|
|
|
gst_ivorbisfile_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
2003-02-23 17:35:35 +00:00
|
|
|
{
|
2003-03-01 14:48:00 +00:00
|
|
|
Ivorbisfile *ivorbisfile;
|
2004-03-14 22:34:33 +00:00
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
g_return_if_fail (GST_IS_IVORBISFILE (object));
|
2003-02-23 17:35:35 +00:00
|
|
|
|
2003-03-01 14:48:00 +00:00
|
|
|
ivorbisfile = GST_IVORBISFILE (object);
|
2003-02-23 17:35:35 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_METADATA:
|
2003-03-01 14:48:00 +00:00
|
|
|
g_value_set_boxed (value, ivorbisfile->metadata);
|
2003-02-23 17:35:35 +00:00
|
|
|
break;
|
|
|
|
case ARG_STREAMINFO:
|
2003-03-01 14:48:00 +00:00
|
|
|
g_value_set_boxed (value, ivorbisfile->streaminfo);
|
2003-02-23 17:35:35 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_warning ("Unknown property id\n");
|
|
|
|
}
|
|
|
|
}
|