2002-03-20 21:45:03 +00:00
|
|
|
/* GStreamer
|
2001-12-20 22:10:54 +00:00
|
|
|
* 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:09 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2003-07-25 02:04:01 +00:00
|
|
|
|
2001-12-20 22:10:54 +00:00
|
|
|
#include <string.h>
|
2003-11-24 04:08:47 +00:00
|
|
|
#include "gstmad.h"
|
2002-02-03 20:10:04 +00:00
|
|
|
|
|
|
|
#define GST_TYPE_MAD \
|
|
|
|
(gst_mad_get_type())
|
|
|
|
#define GST_MAD(obj) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_MAD,GstMad))
|
|
|
|
#define GST_MAD_CLASS(klass) \
|
|
|
|
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_MAD,GstMad))
|
|
|
|
#define GST_IS_MAD(obj) \
|
|
|
|
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_MAD))
|
|
|
|
#define GST_IS_MAD_CLASS(obj) \
|
|
|
|
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_MAD))
|
|
|
|
|
|
|
|
typedef struct _GstMad GstMad;
|
|
|
|
typedef struct _GstMadClass GstMadClass;
|
|
|
|
|
|
|
|
struct _GstMad {
|
2003-01-08 16:11:48 +00:00
|
|
|
GstElement element;
|
2002-02-03 20:10:04 +00:00
|
|
|
|
|
|
|
/* pads */
|
2003-01-08 16:11:48 +00:00
|
|
|
GstPad *sinkpad, *srcpad;
|
2002-02-03 20:10:04 +00:00
|
|
|
|
|
|
|
/* state */
|
|
|
|
struct mad_stream stream;
|
|
|
|
struct mad_frame frame;
|
|
|
|
struct mad_synth synth;
|
2003-01-08 16:11:48 +00:00
|
|
|
guchar *tempbuffer;
|
|
|
|
glong tempsize; /* used to keep track of partial buffers */
|
|
|
|
gboolean need_sync;
|
2003-05-30 14:48:29 +00:00
|
|
|
GstClockTime last_ts;
|
2003-01-20 19:38:37 +00:00
|
|
|
guint64 base_byte_offset;
|
|
|
|
guint64 bytes_consumed; /* since the base_byte_offset */
|
2003-01-08 16:11:48 +00:00
|
|
|
guint64 total_samples; /* the number of samples since the sync point */
|
2002-02-03 20:10:04 +00:00
|
|
|
|
2003-01-08 16:11:48 +00:00
|
|
|
gboolean restart;
|
2003-01-20 19:38:37 +00:00
|
|
|
guint64 segment_start;
|
2002-03-30 17:06:26 +00:00
|
|
|
|
2002-02-03 20:10:04 +00:00
|
|
|
/* info */
|
|
|
|
struct mad_header header;
|
2003-01-08 16:11:48 +00:00
|
|
|
gboolean new_header;
|
|
|
|
guint framecount;
|
|
|
|
gint vbr_average; /* average bitrate */
|
|
|
|
guint64 vbr_rate; /* average * framecount */
|
2002-03-03 00:53:24 +00:00
|
|
|
|
2003-01-08 16:11:48 +00:00
|
|
|
gboolean half;
|
|
|
|
gboolean ignore_crc;
|
2002-11-02 17:40:16 +00:00
|
|
|
|
2003-11-24 04:08:47 +00:00
|
|
|
GstTagList * tags;
|
2002-09-17 21:40:37 +00:00
|
|
|
|
2002-11-08 20:39:58 +00:00
|
|
|
/* negotiated format */
|
2003-01-08 16:11:48 +00:00
|
|
|
gint rate;
|
|
|
|
gint channels;
|
2003-01-20 19:38:37 +00:00
|
|
|
|
|
|
|
GstIndex *index;
|
|
|
|
gint index_id;
|
2002-02-03 20:10:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct _GstMadClass {
|
|
|
|
GstElementClass parent_class;
|
|
|
|
};
|
2001-12-20 22:10:54 +00:00
|
|
|
|
|
|
|
/* elementfactory information */
|
2003-10-31 20:03:29 +00:00
|
|
|
static GstElementDetails gst_mad_details = GST_ELEMENT_DETAILS (
|
2001-12-20 22:10:54 +00:00
|
|
|
"mad mp3 decoder",
|
2003-11-16 22:02:04 +00:00
|
|
|
"Codec/Decoder/Audio",
|
2001-12-20 22:10:54 +00:00
|
|
|
"Uses mad code to decode mp3 streams",
|
2003-10-31 20:03:29 +00:00
|
|
|
"Wim Taymans <wim.taymans@chello.be>"
|
|
|
|
);
|
2001-12-20 22:10:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* Mad signals and args */
|
|
|
|
enum {
|
|
|
|
/* FILL ME */
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
ARG_0,
|
2002-11-02 17:40:16 +00:00
|
|
|
ARG_HALF,
|
|
|
|
ARG_IGNORE_CRC,
|
2002-09-17 21:40:37 +00:00
|
|
|
ARG_METADATA,
|
2002-11-11 13:54:52 +00:00
|
|
|
ARG_STREAMINFO
|
2001-12-20 22:10:54 +00:00
|
|
|
/* FILL ME */
|
|
|
|
};
|
|
|
|
|
2002-04-11 20:42:25 +00:00
|
|
|
GST_PAD_TEMPLATE_FACTORY (mad_src_template_factory,
|
2001-12-20 22:10:54 +00:00
|
|
|
"src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_CAPS_NEW (
|
|
|
|
"mad_src",
|
2003-07-06 20:49:50 +00:00
|
|
|
"audio/x-raw-int",
|
2001-12-20 22:10:54 +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_RANGE (11025, 48000),
|
|
|
|
"channels", GST_PROPS_INT_RANGE (1, 2)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2002-04-11 20:42:25 +00:00
|
|
|
GST_PAD_TEMPLATE_FACTORY (mad_sink_template_factory,
|
2001-12-20 22:10:54 +00:00
|
|
|
"sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_CAPS_NEW (
|
|
|
|
"mad_sink",
|
2003-07-06 20:49:50 +00:00
|
|
|
"audio/mpeg",
|
|
|
|
/* we don't need channel/rate ... */
|
2003-10-01 13:14:51 +00:00
|
|
|
"mpegversion", GST_PROPS_INT (1),
|
2003-07-06 20:49:50 +00:00
|
|
|
"layer", GST_PROPS_INT_RANGE (1, 3)
|
2001-12-20 22:10:54 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2003-10-31 20:03:29 +00:00
|
|
|
static void gst_mad_base_init (gpointer g_class);
|
2003-01-08 16:11:48 +00:00
|
|
|
static void gst_mad_class_init (GstMadClass *klass);
|
|
|
|
static void gst_mad_init (GstMad *mad);
|
|
|
|
static void gst_mad_dispose (GObject *object);
|
2001-12-20 22:10:54 +00:00
|
|
|
|
2002-02-06 18:10:35 +00:00
|
|
|
static void gst_mad_set_property (GObject *object, guint prop_id,
|
|
|
|
const GValue *value, GParamSpec *pspec);
|
|
|
|
static void gst_mad_get_property (GObject *object, guint prop_id,
|
|
|
|
GValue *value, GParamSpec *pspec);
|
|
|
|
|
2003-01-08 16:11:48 +00:00
|
|
|
static gboolean gst_mad_src_event (GstPad *pad, GstEvent *event);
|
|
|
|
static const GstFormat*
|
|
|
|
gst_mad_get_formats (GstPad *pad);
|
|
|
|
static const GstEventMask*
|
|
|
|
gst_mad_get_event_masks (GstPad *pad);
|
|
|
|
static const GstQueryType*
|
|
|
|
gst_mad_get_query_types (GstPad *pad);
|
2002-07-24 21:36:39 +00:00
|
|
|
|
2003-01-08 16:11:48 +00:00
|
|
|
static gboolean gst_mad_src_query (GstPad *pad, GstQueryType type,
|
|
|
|
GstFormat *format, gint64 *value);
|
|
|
|
static gboolean gst_mad_convert_sink (GstPad *pad, GstFormat src_format,
|
|
|
|
gint64 src_value, GstFormat
|
|
|
|
*dest_format, gint64 *dest_value);
|
|
|
|
static gboolean gst_mad_convert_src (GstPad *pad, GstFormat src_format,
|
|
|
|
gint64 src_value, GstFormat
|
|
|
|
*dest_format, gint64 *dest_value);
|
2002-03-30 17:06:26 +00:00
|
|
|
|
2003-10-08 16:08:10 +00:00
|
|
|
static void gst_mad_chain (GstPad *pad, GstData *_data);
|
2001-12-20 22:10:54 +00:00
|
|
|
|
2001-12-28 01:59:26 +00:00
|
|
|
static GstElementStateReturn
|
2003-01-08 16:11:48 +00:00
|
|
|
gst_mad_change_state (GstElement *element);
|
2001-12-20 22:10:54 +00:00
|
|
|
|
2003-01-20 19:38:37 +00:00
|
|
|
static void gst_mad_set_index (GstElement *element, GstIndex *index);
|
|
|
|
static GstIndex* gst_mad_get_index (GstElement *element);
|
|
|
|
|
2001-12-20 22:10:54 +00:00
|
|
|
|
|
|
|
static GstElementClass *parent_class = NULL;
|
2002-02-13 08:15:34 +00:00
|
|
|
/* static guint gst_mad_signals[LAST_SIGNAL] = { 0 }; */
|
2001-12-20 22:10:54 +00:00
|
|
|
|
|
|
|
GType
|
|
|
|
gst_mad_get_type (void)
|
|
|
|
{
|
|
|
|
static GType mad_type = 0;
|
|
|
|
|
|
|
|
if (!mad_type) {
|
|
|
|
static const GTypeInfo mad_info = {
|
2003-01-08 16:11:48 +00:00
|
|
|
sizeof (GstMadClass),
|
2003-10-31 20:03:29 +00:00
|
|
|
gst_mad_base_init,
|
2001-12-20 22:10:54 +00:00
|
|
|
NULL,
|
2003-01-08 16:11:48 +00:00
|
|
|
(GClassInitFunc) gst_mad_class_init,
|
2001-12-20 22:10:54 +00:00
|
|
|
NULL,
|
|
|
|
NULL,
|
2003-01-08 16:11:48 +00:00
|
|
|
sizeof (GstMad),
|
2001-12-20 22:10:54 +00:00
|
|
|
0,
|
2003-01-08 16:11:48 +00:00
|
|
|
(GInstanceInitFunc) gst_mad_init,
|
2001-12-20 22:10:54 +00:00
|
|
|
};
|
|
|
|
mad_type = g_type_register_static(GST_TYPE_ELEMENT, "GstMad", &mad_info, 0);
|
|
|
|
}
|
|
|
|
return mad_type;
|
|
|
|
}
|
|
|
|
|
2002-07-24 21:36:39 +00:00
|
|
|
#define GST_TYPE_MAD_LAYER (gst_mad_layer_get_type())
|
2002-11-20 20:59:00 +00:00
|
|
|
G_GNUC_UNUSED static GType
|
2002-07-24 21:36:39 +00:00
|
|
|
gst_mad_layer_get_type(void) {
|
|
|
|
static GType mad_layer_type = 0;
|
|
|
|
static GEnumValue mad_layer[] = {
|
|
|
|
{0, "0", "Unknown"},
|
|
|
|
{MAD_LAYER_I, "1", "I"},
|
|
|
|
{MAD_LAYER_II, "2", "II"},
|
|
|
|
{MAD_LAYER_III, "3", "III"},
|
|
|
|
{0, NULL, NULL},
|
|
|
|
};
|
|
|
|
if (!mad_layer_type) {
|
|
|
|
mad_layer_type = g_enum_register_static("GstMadLayer", mad_layer);
|
|
|
|
}
|
|
|
|
return mad_layer_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GST_TYPE_MAD_MODE (gst_mad_mode_get_type())
|
2002-11-20 20:59:00 +00:00
|
|
|
G_GNUC_UNUSED static GType
|
2002-07-24 21:36:39 +00:00
|
|
|
gst_mad_mode_get_type(void) {
|
|
|
|
static GType mad_mode_type = 0;
|
|
|
|
static GEnumValue mad_mode[] = {
|
|
|
|
{-1, "-1", "Unknown"},
|
|
|
|
{MAD_MODE_SINGLE_CHANNEL, "0", "Single Channel"},
|
|
|
|
{MAD_MODE_DUAL_CHANNEL , "1", "Dual Channel"},
|
|
|
|
{MAD_MODE_JOINT_STEREO , "2", "Joint Stereo"},
|
|
|
|
{MAD_MODE_STEREO , "3", "Stereo"},
|
|
|
|
{ 0, NULL, NULL},
|
|
|
|
};
|
|
|
|
if (!mad_mode_type) {
|
|
|
|
mad_mode_type = g_enum_register_static("GstMadMode", mad_mode);
|
|
|
|
}
|
|
|
|
return mad_mode_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GST_TYPE_MAD_EMPHASIS (gst_mad_emphasis_get_type())
|
2002-11-20 20:59:00 +00:00
|
|
|
G_GNUC_UNUSED static GType
|
2002-07-24 21:36:39 +00:00
|
|
|
gst_mad_emphasis_get_type(void) {
|
|
|
|
static GType mad_emphasis_type = 0;
|
|
|
|
static GEnumValue mad_emphasis[] = {
|
|
|
|
{-1, "-1", "Unknown"},
|
|
|
|
{MAD_EMPHASIS_NONE, "0", "None"},
|
|
|
|
{MAD_EMPHASIS_50_15_US, "1", "50/15 Microseconds"},
|
|
|
|
{MAD_EMPHASIS_CCITT_J_17, "2", "CCITT J.17"},
|
|
|
|
{ 0, NULL, NULL},
|
|
|
|
};
|
|
|
|
if (!mad_emphasis_type) {
|
|
|
|
mad_emphasis_type = g_enum_register_static("GstMadEmphasis", mad_emphasis);
|
|
|
|
}
|
|
|
|
return mad_emphasis_type;
|
|
|
|
}
|
2002-02-06 18:10:35 +00:00
|
|
|
|
2003-10-31 20:03:29 +00:00
|
|
|
static void
|
|
|
|
gst_mad_base_init (gpointer g_class)
|
|
|
|
{
|
|
|
|
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
GST_PAD_TEMPLATE_GET (mad_sink_template_factory));
|
|
|
|
gst_element_class_add_pad_template (element_class,
|
|
|
|
GST_PAD_TEMPLATE_GET (mad_src_template_factory));
|
|
|
|
gst_element_class_set_details (element_class, &gst_mad_details);
|
|
|
|
}
|
2001-12-20 22:10:54 +00:00
|
|
|
static void
|
|
|
|
gst_mad_class_init (GstMadClass *klass)
|
|
|
|
{
|
2001-12-28 01:59:26 +00:00
|
|
|
GObjectClass *gobject_class;
|
2001-12-20 22:10:54 +00:00
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
2001-12-28 01:59:26 +00:00
|
|
|
gobject_class = (GObjectClass*) klass;
|
|
|
|
gstelement_class = (GstElementClass*) klass;
|
2001-12-20 22:10:54 +00:00
|
|
|
|
|
|
|
parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
|
2001-12-28 01:59:26 +00:00
|
|
|
|
2002-02-06 18:10:35 +00:00
|
|
|
gobject_class->set_property = gst_mad_set_property;
|
|
|
|
gobject_class->get_property = gst_mad_get_property;
|
2001-12-28 01:59:26 +00:00
|
|
|
gobject_class->dispose = gst_mad_dispose;
|
|
|
|
|
|
|
|
gstelement_class->change_state = gst_mad_change_state;
|
2003-01-20 19:38:37 +00:00
|
|
|
gstelement_class->set_index = gst_mad_set_index;
|
|
|
|
gstelement_class->get_index = gst_mad_get_index;
|
2003-01-08 16:11:48 +00:00
|
|
|
|
2002-02-06 18:10:35 +00:00
|
|
|
/* init properties */
|
|
|
|
/* currently, string representations are used, we might want to change that */
|
2003-01-08 16:11:48 +00:00
|
|
|
/* FIXME: descriptions need to be more technical,
|
|
|
|
* default values and ranges need to be selected right */
|
2002-11-02 17:40:16 +00:00
|
|
|
g_object_class_install_property (gobject_class, ARG_HALF,
|
|
|
|
g_param_spec_boolean ("half", "Half", "Generate PCM at 1/2 sample rate",
|
|
|
|
FALSE, G_PARAM_READWRITE));
|
|
|
|
g_object_class_install_property (gobject_class, ARG_IGNORE_CRC,
|
|
|
|
g_param_spec_boolean ("ignore_crc", "Ignore CRC", "Ignore CRC errors",
|
|
|
|
FALSE, G_PARAM_READWRITE));
|
2001-12-20 22:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_mad_init (GstMad *mad)
|
|
|
|
{
|
|
|
|
/* create the sink and src pads */
|
|
|
|
mad->sinkpad = gst_pad_new_from_template(
|
2002-04-11 20:42:25 +00:00
|
|
|
GST_PAD_TEMPLATE_GET (mad_sink_template_factory), "sink");
|
2002-05-26 21:59:22 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (mad), mad->sinkpad);
|
|
|
|
gst_pad_set_chain_function (mad->sinkpad, GST_DEBUG_FUNCPTR (gst_mad_chain));
|
|
|
|
gst_pad_set_convert_function (mad->sinkpad, GST_DEBUG_FUNCPTR (gst_mad_convert_sink));
|
2002-07-24 21:36:39 +00:00
|
|
|
gst_pad_set_formats_function (mad->sinkpad, GST_DEBUG_FUNCPTR (gst_mad_get_formats));
|
2001-12-20 22:10:54 +00:00
|
|
|
|
|
|
|
mad->srcpad = gst_pad_new_from_template(
|
2002-04-11 20:42:25 +00:00
|
|
|
GST_PAD_TEMPLATE_GET (mad_src_template_factory), "src");
|
2002-05-26 21:59:22 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (mad), mad->srcpad);
|
|
|
|
gst_pad_set_event_function (mad->srcpad, GST_DEBUG_FUNCPTR (gst_mad_src_event));
|
2002-07-24 21:36:39 +00:00
|
|
|
gst_pad_set_event_mask_function (mad->srcpad, GST_DEBUG_FUNCPTR (gst_mad_get_event_masks));
|
2002-05-26 21:59:22 +00:00
|
|
|
gst_pad_set_query_function (mad->srcpad, GST_DEBUG_FUNCPTR (gst_mad_src_query));
|
2002-07-24 21:36:39 +00:00
|
|
|
gst_pad_set_query_type_function (mad->srcpad, GST_DEBUG_FUNCPTR (gst_mad_get_query_types));
|
2002-05-26 21:59:22 +00:00
|
|
|
gst_pad_set_convert_function (mad->srcpad, GST_DEBUG_FUNCPTR (gst_mad_convert_src));
|
2002-07-24 21:36:39 +00:00
|
|
|
gst_pad_set_formats_function (mad->srcpad, GST_DEBUG_FUNCPTR (gst_mad_get_formats));
|
2001-12-20 22:10:54 +00:00
|
|
|
|
2001-12-28 01:59:26 +00:00
|
|
|
mad->tempbuffer = g_malloc (MAD_BUFFER_MDLEN * 3);
|
2001-12-20 22:10:54 +00:00
|
|
|
mad->tempsize = 0;
|
|
|
|
mad->need_sync = TRUE;
|
2003-01-20 19:38:37 +00:00
|
|
|
mad->base_byte_offset = 0;
|
|
|
|
mad->bytes_consumed = 0;
|
2002-02-03 20:10:04 +00:00
|
|
|
mad->total_samples = 0;
|
2001-12-20 22:27:35 +00:00
|
|
|
mad->new_header = TRUE;
|
2002-02-13 08:15:34 +00:00
|
|
|
mad->framecount = 0;
|
|
|
|
mad->vbr_average = 0;
|
|
|
|
mad->vbr_rate = 0;
|
2002-05-07 21:02:24 +00:00
|
|
|
mad->restart = FALSE;
|
2003-01-20 19:38:37 +00:00
|
|
|
mad->segment_start = 0;
|
2002-07-24 21:36:39 +00:00
|
|
|
mad->header.mode = -1;
|
|
|
|
mad->header.emphasis = -1;
|
2003-11-24 04:08:47 +00:00
|
|
|
mad->tags = NULL;
|
2002-05-26 21:59:22 +00:00
|
|
|
|
2002-11-02 17:40:16 +00:00
|
|
|
mad->half = FALSE;
|
|
|
|
mad->ignore_crc = FALSE;
|
|
|
|
|
2002-05-26 21:59:22 +00:00
|
|
|
GST_FLAG_SET (mad, GST_ELEMENT_EVENT_AWARE);
|
2001-12-20 22:10:54 +00:00
|
|
|
}
|
|
|
|
|
2001-12-28 01:59:26 +00:00
|
|
|
static void
|
|
|
|
gst_mad_dispose (GObject *object)
|
2001-12-20 22:10:54 +00:00
|
|
|
{
|
2001-12-28 01:59:26 +00:00
|
|
|
GstMad *mad = GST_MAD (object);
|
2001-12-20 22:10:54 +00:00
|
|
|
|
2003-01-20 19:38:37 +00:00
|
|
|
gst_mad_set_index (GST_ELEMENT (object), NULL);
|
|
|
|
|
2001-12-28 01:59:26 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
2001-12-20 22:10:54 +00:00
|
|
|
|
2001-12-28 01:59:26 +00:00
|
|
|
g_free (mad->tempbuffer);
|
2001-12-20 22:10:54 +00:00
|
|
|
}
|
|
|
|
|
2003-01-20 19:38:37 +00:00
|
|
|
static void
|
|
|
|
gst_mad_set_index (GstElement *element, GstIndex *index)
|
|
|
|
{
|
|
|
|
GstMad *mad = GST_MAD (element);
|
|
|
|
|
|
|
|
mad->index = index;
|
|
|
|
|
|
|
|
if (index)
|
|
|
|
gst_index_get_writer_id (index, GST_OBJECT (element), &mad->index_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstIndex*
|
|
|
|
gst_mad_get_index (GstElement *element)
|
|
|
|
{
|
|
|
|
GstMad *mad = GST_MAD (element);
|
|
|
|
|
|
|
|
return mad->index;
|
|
|
|
}
|
|
|
|
|
2002-07-24 21:36:39 +00:00
|
|
|
static const GstFormat*
|
|
|
|
gst_mad_get_formats (GstPad *pad)
|
|
|
|
{
|
|
|
|
static const GstFormat src_formats[] = {
|
|
|
|
GST_FORMAT_BYTES,
|
2003-05-24 10:14:39 +00:00
|
|
|
GST_FORMAT_DEFAULT,
|
2002-07-24 21:36:39 +00:00
|
|
|
GST_FORMAT_TIME,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
static const GstFormat sink_formats[] = {
|
|
|
|
GST_FORMAT_BYTES,
|
|
|
|
GST_FORMAT_TIME,
|
|
|
|
0
|
|
|
|
};
|
2003-01-08 16:11:48 +00:00
|
|
|
|
2002-07-24 21:36:39 +00:00
|
|
|
return (GST_PAD_IS_SRC (pad) ? src_formats : sink_formats);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const GstEventMask*
|
|
|
|
gst_mad_get_event_masks (GstPad *pad)
|
|
|
|
{
|
|
|
|
static const GstEventMask gst_mad_src_event_masks[] = {
|
|
|
|
{ GST_EVENT_SEEK, GST_SEEK_METHOD_SET |
|
|
|
|
GST_SEEK_FLAG_FLUSH },
|
|
|
|
{ 0, }
|
|
|
|
};
|
|
|
|
return gst_mad_src_event_masks;
|
|
|
|
}
|
|
|
|
|
2002-05-26 21:59:22 +00:00
|
|
|
static gboolean
|
2003-01-08 16:11:48 +00:00
|
|
|
gst_mad_convert_sink (GstPad *pad, GstFormat src_format, gint64 src_value,
|
2002-05-26 21:59:22 +00:00
|
|
|
GstFormat *dest_format, gint64 *dest_value)
|
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
GstMad *mad;
|
|
|
|
|
|
|
|
mad = GST_MAD (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
if (mad->vbr_average == 0)
|
|
|
|
return FALSE;
|
2003-01-08 16:11:48 +00:00
|
|
|
|
2002-05-26 21:59:22 +00:00
|
|
|
switch (src_format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
switch (*dest_format) {
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
/* multiply by 8 because vbr is in bits/second */
|
|
|
|
*dest_value = src_value * 8 * GST_SECOND / mad->vbr_average;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
switch (*dest_format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
/* multiply by 8 because vbr is in bits/second */
|
|
|
|
*dest_value = src_value * mad->vbr_average / (8 * GST_SECOND);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2003-01-08 16:11:48 +00:00
|
|
|
gst_mad_convert_src (GstPad *pad, GstFormat src_format, gint64 src_value,
|
2002-05-26 21:59:22 +00:00
|
|
|
GstFormat *dest_format, gint64 *dest_value)
|
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
guint scale = 1;
|
|
|
|
gint bytes_per_sample;
|
|
|
|
GstMad *mad;
|
|
|
|
|
|
|
|
mad = GST_MAD (gst_pad_get_parent (pad));
|
2003-01-08 16:11:48 +00:00
|
|
|
|
2002-05-26 21:59:22 +00:00
|
|
|
bytes_per_sample = MAD_NCHANNELS (&mad->frame.header) << 1;
|
2003-01-08 16:11:48 +00:00
|
|
|
|
2002-05-26 21:59:22 +00:00
|
|
|
switch (src_format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
switch (*dest_format) {
|
2003-05-24 10:14:39 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
2002-05-26 21:59:22 +00:00
|
|
|
if (bytes_per_sample == 0)
|
|
|
|
return FALSE;
|
|
|
|
*dest_value = src_value / bytes_per_sample;
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
{
|
|
|
|
gint byterate = bytes_per_sample * mad->frame.header.samplerate;
|
|
|
|
|
|
|
|
if (byterate == 0)
|
|
|
|
return FALSE;
|
|
|
|
*dest_value = src_value * GST_SECOND / byterate;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
2003-05-24 10:14:39 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
2002-05-26 21:59:22 +00:00
|
|
|
switch (*dest_format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
*dest_value = src_value * bytes_per_sample;
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
if (mad->frame.header.samplerate == 0)
|
|
|
|
return FALSE;
|
|
|
|
*dest_value = src_value * GST_SECOND / mad->frame.header.samplerate;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
switch (*dest_format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
scale = bytes_per_sample;
|
|
|
|
/* fallthrough */
|
2003-05-24 10:14:39 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
2002-05-26 21:59:22 +00:00
|
|
|
*dest_value = src_value * scale * mad->frame.header.samplerate / GST_SECOND;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2002-12-30 17:53:18 +00:00
|
|
|
static const GstQueryType*
|
2002-07-24 21:36:39 +00:00
|
|
|
gst_mad_get_query_types (GstPad *pad)
|
|
|
|
{
|
2002-12-30 17:53:18 +00:00
|
|
|
static const GstQueryType gst_mad_src_query_types[] = {
|
|
|
|
GST_QUERY_TOTAL,
|
|
|
|
GST_QUERY_POSITION,
|
2002-07-24 21:36:39 +00:00
|
|
|
0
|
|
|
|
};
|
|
|
|
return gst_mad_src_query_types;
|
|
|
|
}
|
|
|
|
|
2002-05-26 21:59:22 +00:00
|
|
|
static gboolean
|
2002-12-30 17:53:18 +00:00
|
|
|
gst_mad_src_query (GstPad *pad, GstQueryType type,
|
2002-05-26 21:59:22 +00:00
|
|
|
GstFormat *format, gint64 *value)
|
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
GstMad *mad;
|
2003-01-08 16:11:48 +00:00
|
|
|
|
2002-05-26 21:59:22 +00:00
|
|
|
mad = GST_MAD (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
switch (type) {
|
2002-12-30 17:53:18 +00:00
|
|
|
case GST_QUERY_TOTAL:
|
2002-05-26 21:59:22 +00:00
|
|
|
{
|
|
|
|
switch (*format) {
|
|
|
|
case GST_FORMAT_BYTES:
|
2003-05-24 10:14:39 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
2002-05-26 21:59:22 +00:00
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
{
|
2002-07-24 21:36:39 +00:00
|
|
|
gint64 peer_value;
|
|
|
|
const GstFormat *peer_formats;
|
|
|
|
|
2002-05-26 21:59:22 +00:00
|
|
|
res = FALSE;
|
|
|
|
|
2002-07-24 21:36:39 +00:00
|
|
|
peer_formats = gst_pad_get_formats (GST_PAD_PEER (mad->sinkpad));
|
|
|
|
|
|
|
|
while (peer_formats && *peer_formats && !res) {
|
|
|
|
|
|
|
|
GstFormat peer_format = *peer_formats;
|
|
|
|
|
2002-05-26 21:59:22 +00:00
|
|
|
/* do the probe */
|
2002-12-30 17:53:18 +00:00
|
|
|
if (gst_pad_query (GST_PAD_PEER (mad->sinkpad), GST_QUERY_TOTAL,
|
2003-01-08 16:11:48 +00:00
|
|
|
&peer_format, &peer_value))
|
2002-05-26 21:59:22 +00:00
|
|
|
{
|
|
|
|
GstFormat conv_format;
|
|
|
|
/* convert to TIME */
|
|
|
|
conv_format = GST_FORMAT_TIME;
|
2002-06-02 20:13:35 +00:00
|
|
|
res = gst_pad_convert (mad->sinkpad,
|
2002-05-26 21:59:22 +00:00
|
|
|
peer_format, peer_value,
|
|
|
|
&conv_format, value);
|
|
|
|
/* and to final format */
|
2002-06-02 20:13:35 +00:00
|
|
|
res &= gst_pad_convert (pad,
|
2002-05-26 21:59:22 +00:00
|
|
|
GST_FORMAT_TIME, *value,
|
|
|
|
format, value);
|
|
|
|
}
|
2002-07-24 21:36:39 +00:00
|
|
|
peer_formats++;
|
2002-05-26 21:59:22 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2002-12-30 17:53:18 +00:00
|
|
|
case GST_QUERY_POSITION:
|
2002-05-26 21:59:22 +00:00
|
|
|
switch (*format) {
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
/* we only know about our samples, convert to requested format */
|
2002-06-02 20:13:35 +00:00
|
|
|
res &= gst_pad_convert (pad,
|
2003-05-29 09:12:17 +00:00
|
|
|
GST_FORMAT_DEFAULT, mad->total_samples,
|
2002-05-26 21:59:22 +00:00
|
|
|
format, value);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2003-01-20 19:38:37 +00:00
|
|
|
static gboolean
|
|
|
|
index_seek (GstMad *mad, GstPad *pad, GstEvent *event)
|
|
|
|
{
|
|
|
|
/* since we know the exact byteoffset of the frame,
|
|
|
|
make sure to try bytes first */
|
|
|
|
|
|
|
|
const GstFormat try_all_formats[] = {
|
|
|
|
GST_FORMAT_BYTES,
|
|
|
|
GST_FORMAT_TIME,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
const GstFormat *try_formats = try_all_formats;
|
|
|
|
const GstFormat *peer_formats;
|
|
|
|
|
|
|
|
GstIndexEntry *entry =
|
|
|
|
gst_index_get_assoc_entry (mad->index, mad->index_id,
|
|
|
|
GST_INDEX_LOOKUP_BEFORE, 0,
|
|
|
|
GST_EVENT_SEEK_FORMAT (event),
|
|
|
|
GST_EVENT_SEEK_OFFSET (event));
|
|
|
|
if (!entry)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
peer_formats = gst_pad_get_formats (GST_PAD_PEER (mad->sinkpad));
|
|
|
|
|
|
|
|
while (gst_formats_contains (peer_formats, *try_formats)) {
|
|
|
|
gint64 value;
|
2003-08-02 00:56:11 +00:00
|
|
|
GstEvent *seek_event;
|
2003-01-20 19:38:37 +00:00
|
|
|
|
|
|
|
if (gst_index_entry_assoc_map (entry, *try_formats, &value)) {
|
|
|
|
/* lookup succeeded, create the seek */
|
|
|
|
|
2003-11-24 04:08:47 +00:00
|
|
|
GST_DEBUG ("index %s %" G_GINT64_FORMAT
|
2003-07-25 02:04:01 +00:00
|
|
|
" -> %s %" G_GINT64_FORMAT,
|
|
|
|
gst_format_get_details (GST_EVENT_SEEK_FORMAT (event))->nick,
|
|
|
|
GST_EVENT_SEEK_OFFSET (event),
|
|
|
|
gst_format_get_details (*try_formats)->nick,
|
|
|
|
value);
|
|
|
|
|
2003-08-02 00:56:11 +00:00
|
|
|
seek_event = gst_event_new_seek (*try_formats |
|
|
|
|
GST_SEEK_METHOD_SET |
|
|
|
|
GST_SEEK_FLAG_FLUSH, value);
|
2003-01-20 19:38:37 +00:00
|
|
|
|
|
|
|
if (gst_pad_send_event (GST_PAD_PEER (mad->sinkpad), seek_event)) {
|
|
|
|
/* seek worked, we're done, loop will exit */
|
|
|
|
mad->restart = TRUE;
|
|
|
|
g_assert (GST_EVENT_SEEK_FORMAT (event) == GST_FORMAT_TIME);
|
|
|
|
mad->segment_start = GST_EVENT_SEEK_OFFSET (event);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try_formats++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
normal_seek (GstMad *mad, GstPad *pad, GstEvent *event)
|
|
|
|
{
|
|
|
|
gint64 src_offset;
|
|
|
|
gboolean flush;
|
|
|
|
GstFormat format;
|
|
|
|
const GstFormat *peer_formats;
|
|
|
|
gboolean res;
|
|
|
|
|
|
|
|
format = GST_FORMAT_TIME;
|
|
|
|
|
|
|
|
/* first bring the src_format to TIME */
|
|
|
|
if (!gst_pad_convert (pad,
|
|
|
|
GST_EVENT_SEEK_FORMAT (event), GST_EVENT_SEEK_OFFSET (event),
|
|
|
|
&format, &src_offset))
|
2003-05-29 09:12:17 +00:00
|
|
|
{
|
|
|
|
/* didn't work, probably unsupported seek format then */
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-01-20 19:38:37 +00:00
|
|
|
|
|
|
|
/* shave off the flush flag, we'll need it later */
|
|
|
|
flush = GST_EVENT_SEEK_FLAGS (event) & GST_SEEK_FLAG_FLUSH;
|
|
|
|
|
|
|
|
/* assume the worst */
|
|
|
|
res = FALSE;
|
|
|
|
|
|
|
|
peer_formats = gst_pad_get_formats (GST_PAD_PEER (mad->sinkpad));
|
|
|
|
|
|
|
|
/* while we did not exhaust our seek formats without result */
|
|
|
|
while (peer_formats && *peer_formats && !res) {
|
|
|
|
gint64 desired_offset;
|
|
|
|
|
|
|
|
format = *peer_formats;
|
|
|
|
|
|
|
|
/* try to convert requested format to one we can seek with on the sinkpad */
|
|
|
|
if (gst_pad_convert (mad->sinkpad, GST_FORMAT_TIME, src_offset,
|
|
|
|
&format, &desired_offset))
|
|
|
|
{
|
|
|
|
GstEvent *seek_event;
|
|
|
|
|
|
|
|
/* conversion succeeded, create the seek */
|
|
|
|
seek_event = gst_event_new_seek (format | GST_SEEK_METHOD_SET | flush,
|
|
|
|
desired_offset);
|
|
|
|
/* do the seek */
|
|
|
|
if (gst_pad_send_event (GST_PAD_PEER (mad->sinkpad), seek_event)) {
|
|
|
|
/* seek worked, we're done, loop will exit */
|
|
|
|
res = TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* at this point, either the seek worked or res == FALSE */
|
|
|
|
if (res)
|
|
|
|
/* we need to break out of the processing loop on flush */
|
|
|
|
mad->restart = flush;
|
|
|
|
|
|
|
|
peer_formats++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2002-03-30 17:06:26 +00:00
|
|
|
static gboolean
|
|
|
|
gst_mad_src_event (GstPad *pad, GstEvent *event)
|
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
GstMad *mad;
|
2003-01-08 16:11:48 +00:00
|
|
|
|
2002-03-30 17:06:26 +00:00
|
|
|
mad = GST_MAD (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2002-11-02 13:35:45 +00:00
|
|
|
case GST_EVENT_SEEK_SEGMENT:
|
|
|
|
gst_event_ref (event);
|
|
|
|
if (gst_pad_send_event (GST_PAD_PEER (mad->sinkpad), event)) {
|
|
|
|
/* seek worked, we're done, loop will exit */
|
|
|
|
res = TRUE;
|
|
|
|
}
|
|
|
|
break;
|
2002-05-26 21:59:22 +00:00
|
|
|
/* the all-formats seek logic */
|
2002-03-30 17:06:26 +00:00
|
|
|
case GST_EVENT_SEEK:
|
2003-01-20 19:38:37 +00:00
|
|
|
if (mad->index)
|
|
|
|
res = index_seek (mad, pad, event);
|
|
|
|
else
|
|
|
|
res = normal_seek (mad, pad, event);
|
2002-03-30 17:06:26 +00:00
|
|
|
break;
|
2003-01-20 19:38:37 +00:00
|
|
|
|
2002-03-30 17:06:26 +00:00
|
|
|
default:
|
2002-05-26 21:59:22 +00:00
|
|
|
res = FALSE;
|
2002-03-30 17:06:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2002-07-08 19:35:51 +00:00
|
|
|
gst_event_unref (event);
|
2002-03-30 17:06:26 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2003-01-08 16:11:48 +00:00
|
|
|
static inline signed int
|
2001-12-20 22:10:54 +00:00
|
|
|
scale (mad_fixed_t sample)
|
|
|
|
{
|
|
|
|
/* round */
|
|
|
|
sample += (1L << (MAD_F_FRACBITS - 16));
|
|
|
|
|
|
|
|
/* clip */
|
|
|
|
if (sample >= MAD_F_ONE)
|
|
|
|
sample = MAD_F_ONE - 1;
|
|
|
|
else if (sample < -MAD_F_ONE)
|
|
|
|
sample = -MAD_F_ONE;
|
|
|
|
|
|
|
|
/* quantize */
|
|
|
|
return sample >> (MAD_F_FRACBITS + 1 - 16);
|
|
|
|
}
|
|
|
|
|
2002-02-06 18:10:35 +00:00
|
|
|
/* do we need this function? */
|
|
|
|
static void
|
2003-01-08 16:11:48 +00:00
|
|
|
gst_mad_set_property (GObject *object, guint prop_id,
|
|
|
|
const GValue *value, GParamSpec *pspec)
|
2002-02-06 18:10:35 +00:00
|
|
|
{
|
|
|
|
GstMad *mad;
|
2003-01-08 16:11:48 +00:00
|
|
|
|
2002-02-06 18:10:35 +00:00
|
|
|
g_return_if_fail (GST_IS_MAD (object));
|
2003-01-08 16:11:48 +00:00
|
|
|
|
2002-02-06 18:10:35 +00:00
|
|
|
mad = GST_MAD (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2002-11-02 17:40:16 +00:00
|
|
|
case ARG_HALF:
|
|
|
|
mad->half = g_value_get_boolean (value);
|
|
|
|
break;
|
|
|
|
case ARG_IGNORE_CRC:
|
|
|
|
mad->ignore_crc = g_value_get_boolean (value);
|
|
|
|
break;
|
2002-02-06 18:10:35 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
static void
|
2003-01-08 16:11:48 +00:00
|
|
|
gst_mad_get_property (GObject *object, guint prop_id,
|
|
|
|
GValue *value, GParamSpec *pspec)
|
2002-02-06 18:10:35 +00:00
|
|
|
{
|
|
|
|
GstMad *mad;
|
2003-01-08 16:11:48 +00:00
|
|
|
|
2002-02-06 18:10:35 +00:00
|
|
|
g_return_if_fail (GST_IS_MAD (object));
|
2003-01-08 16:11:48 +00:00
|
|
|
|
2002-02-06 18:10:35 +00:00
|
|
|
mad = GST_MAD (object);
|
|
|
|
|
|
|
|
switch (prop_id) {
|
2002-11-02 17:40:16 +00:00
|
|
|
case ARG_HALF:
|
|
|
|
g_value_set_boolean (value, mad->half);
|
|
|
|
break;
|
|
|
|
case ARG_IGNORE_CRC:
|
|
|
|
g_value_set_boolean (value, mad->ignore_crc);
|
|
|
|
break;
|
2002-02-06 18:10:35 +00:00
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-05-26 21:59:22 +00:00
|
|
|
|
2001-12-20 22:27:35 +00:00
|
|
|
static void
|
2002-05-26 21:59:22 +00:00
|
|
|
gst_mad_update_info (GstMad *mad)
|
2001-12-20 22:27:35 +00:00
|
|
|
{
|
2002-02-13 08:15:34 +00:00
|
|
|
gint abr = mad->vbr_average;
|
2002-05-26 21:59:22 +00:00
|
|
|
struct mad_header *header = &mad->frame.header;
|
2002-11-20 20:59:00 +00:00
|
|
|
gboolean changed = FALSE;
|
2002-05-26 21:59:22 +00:00
|
|
|
|
2003-01-08 16:11:48 +00:00
|
|
|
#define CHECK_HEADER(h1,str) \
|
2001-12-20 22:27:35 +00:00
|
|
|
G_STMT_START{ \
|
|
|
|
if (mad->header.h1 != header->h1 || mad->new_header) { \
|
|
|
|
mad->header.h1 = header->h1; \
|
2002-11-20 20:59:00 +00:00
|
|
|
changed = TRUE; \
|
2001-12-20 22:27:35 +00:00
|
|
|
}; \
|
2002-02-06 18:10:35 +00:00
|
|
|
} G_STMT_END
|
2003-01-08 16:11:48 +00:00
|
|
|
|
2002-02-13 08:15:34 +00:00
|
|
|
/* update average bitrate */
|
2002-05-26 21:59:22 +00:00
|
|
|
if (mad->new_header) {
|
2002-02-13 08:15:34 +00:00
|
|
|
mad->framecount = 1;
|
|
|
|
mad->vbr_rate = header->bitrate;
|
|
|
|
abr = 0;
|
|
|
|
} else {
|
|
|
|
mad->framecount++;
|
|
|
|
mad->vbr_rate += header->bitrate;
|
|
|
|
}
|
|
|
|
mad->vbr_average = (gint) (mad->vbr_rate / mad->framecount);
|
|
|
|
|
2003-01-08 16:11:48 +00:00
|
|
|
CHECK_HEADER (layer, "layer");
|
|
|
|
CHECK_HEADER (mode, "mode");
|
2002-02-06 18:10:35 +00:00
|
|
|
CHECK_HEADER (emphasis, "emphasis");
|
2002-11-02 13:35:45 +00:00
|
|
|
|
|
|
|
if (header->bitrate != mad->header.bitrate || mad->new_header) {
|
|
|
|
mad->header.bitrate = header->bitrate;
|
|
|
|
}
|
2001-12-20 22:27:35 +00:00
|
|
|
mad->new_header = FALSE;
|
2002-11-20 20:59:00 +00:00
|
|
|
|
2002-02-06 18:10:35 +00:00
|
|
|
#undef CHECK_HEADER
|
2003-01-08 16:11:48 +00:00
|
|
|
|
2001-12-20 22:27:35 +00:00
|
|
|
}
|
|
|
|
|
2002-12-11 21:57:39 +00:00
|
|
|
static void
|
|
|
|
gst_mad_handle_event (GstPad *pad, GstBuffer *buffer)
|
|
|
|
{
|
|
|
|
GstEvent *event = GST_EVENT (buffer);
|
|
|
|
GstMad *mad = GST_MAD (gst_pad_get_parent (pad));
|
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event))
|
|
|
|
{
|
|
|
|
case GST_EVENT_DISCONTINUOUS:
|
|
|
|
{
|
|
|
|
gint n = GST_EVENT_DISCONT_OFFSET_LEN (event);
|
|
|
|
gint i;
|
|
|
|
|
2003-05-29 09:12:17 +00:00
|
|
|
mad->total_samples = 0;
|
|
|
|
|
2002-12-11 21:57:39 +00:00
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
{
|
2002-12-30 17:53:18 +00:00
|
|
|
const GstFormat *formats;
|
|
|
|
formats = gst_pad_get_formats (pad);
|
|
|
|
|
|
|
|
if (gst_formats_contains (formats, GST_EVENT_DISCONT_OFFSET(event, i).format))
|
2002-12-11 21:57:39 +00:00
|
|
|
{
|
|
|
|
gint64 value = GST_EVENT_DISCONT_OFFSET (event, i).value;
|
|
|
|
gint64 time;
|
|
|
|
GstFormat format;
|
|
|
|
GstEvent *discont;
|
|
|
|
|
|
|
|
/* see how long the input bytes take */
|
|
|
|
format = GST_FORMAT_TIME;
|
|
|
|
if (!gst_pad_convert (pad,
|
|
|
|
GST_EVENT_DISCONT_OFFSET (event, i).format,
|
|
|
|
value, &format, &time))
|
|
|
|
{
|
|
|
|
time = 0;
|
|
|
|
}
|
|
|
|
|
2003-05-29 09:12:17 +00:00
|
|
|
/* for now, this is the best we can do to get the total number
|
|
|
|
* of samples */
|
|
|
|
format = GST_FORMAT_DEFAULT;
|
|
|
|
if (!gst_pad_convert (mad->srcpad,
|
|
|
|
GST_FORMAT_TIME, time, &format, &mad->total_samples))
|
|
|
|
{
|
|
|
|
mad->total_samples = 0;
|
|
|
|
}
|
2002-12-11 21:57:39 +00:00
|
|
|
|
|
|
|
gst_event_unref (event);
|
|
|
|
|
|
|
|
if (GST_PAD_IS_USABLE (mad->srcpad))
|
|
|
|
{
|
|
|
|
discont = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME,
|
|
|
|
time, NULL);
|
2003-10-08 16:08:10 +00:00
|
|
|
gst_pad_push (mad->srcpad, GST_DATA (discont));
|
2002-12-11 21:57:39 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mad->tempsize = 0;
|
|
|
|
/* we don't need to restart when we get here */
|
|
|
|
mad->restart = FALSE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
gst_pad_event_default (pad, event);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-01-20 19:38:37 +00:00
|
|
|
static gboolean
|
|
|
|
gst_mad_check_restart (GstMad *mad)
|
|
|
|
{
|
|
|
|
gboolean yes = mad->restart;
|
|
|
|
if (mad->restart) {
|
|
|
|
mad->restart = FALSE;
|
|
|
|
mad->tempsize = 0;
|
|
|
|
}
|
|
|
|
return yes;
|
|
|
|
}
|
|
|
|
|
2001-12-28 01:59:26 +00:00
|
|
|
static void
|
2003-10-08 16:08:10 +00:00
|
|
|
gst_mad_chain (GstPad *pad, GstData *_data)
|
2001-12-20 22:10:54 +00:00
|
|
|
{
|
2003-10-08 16:08:10 +00:00
|
|
|
GstBuffer *buffer = GST_BUFFER (_data);
|
2001-12-20 22:10:54 +00:00
|
|
|
GstMad *mad;
|
2001-12-28 01:59:26 +00:00
|
|
|
gchar *data;
|
|
|
|
glong size;
|
2002-09-18 22:04:32 +00:00
|
|
|
gboolean new_pts = FALSE;
|
2003-01-20 19:38:37 +00:00
|
|
|
GstClockTime timestamp;
|
2001-12-20 22:10:54 +00:00
|
|
|
|
2001-12-28 01:59:26 +00:00
|
|
|
mad = GST_MAD (gst_pad_get_parent (pad));
|
2002-12-13 10:23:07 +00:00
|
|
|
g_return_if_fail (GST_IS_MAD (mad));
|
2001-12-20 22:10:54 +00:00
|
|
|
|
2002-12-11 21:57:39 +00:00
|
|
|
/* handle events */
|
|
|
|
if (GST_IS_EVENT (buffer))
|
|
|
|
{
|
|
|
|
gst_mad_handle_event (pad, buffer);
|
2002-02-03 20:10:04 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-01-08 16:11:48 +00:00
|
|
|
|
2003-01-20 19:38:37 +00:00
|
|
|
gst_mad_check_restart (mad);
|
|
|
|
|
|
|
|
timestamp = GST_BUFFER_TIMESTAMP (buffer);
|
|
|
|
|
2003-01-08 16:11:48 +00:00
|
|
|
/* handle timestamps */
|
2003-04-13 03:11:06 +00:00
|
|
|
if (GST_CLOCK_TIME_IS_VALID (timestamp)) {
|
2002-09-18 22:04:32 +00:00
|
|
|
/* if there is nothing queued (partial buffer), we prepare to set the
|
|
|
|
* timestamp on the next buffer */
|
|
|
|
if (mad->tempsize == 0) {
|
2003-05-30 14:48:29 +00:00
|
|
|
/* we have to save the result here because we can't yet convert the timestamp
|
|
|
|
* to a sample offset yet, the samplerate might not be known yet */
|
|
|
|
mad->last_ts = timestamp;
|
2003-01-20 19:38:37 +00:00
|
|
|
mad->base_byte_offset = GST_BUFFER_OFFSET (buffer);
|
|
|
|
mad->bytes_consumed = 0;
|
2002-09-18 22:04:32 +00:00
|
|
|
}
|
|
|
|
/* else we need to finish the current partial frame with the old timestamp
|
|
|
|
* and queue this timestamp for the next frame */
|
|
|
|
else {
|
|
|
|
new_pts = TRUE;
|
|
|
|
}
|
2002-03-30 17:06:26 +00:00
|
|
|
}
|
2002-02-03 20:10:04 +00:00
|
|
|
|
2003-01-08 16:11:48 +00:00
|
|
|
/* handle data */
|
2002-05-26 21:59:22 +00:00
|
|
|
data = GST_BUFFER_DATA (buffer);
|
|
|
|
size = GST_BUFFER_SIZE (buffer);
|
|
|
|
|
2003-01-08 16:11:48 +00:00
|
|
|
/* process the incoming buffer in chunks of maximum MAD_BUFFER_MDLEN bytes;
|
|
|
|
* this is the upper limit on processable chunk sizes set by mad */
|
2002-12-11 21:57:39 +00:00
|
|
|
while (size > 0)
|
|
|
|
{
|
2001-12-28 01:59:26 +00:00
|
|
|
gint tocopy;
|
|
|
|
guchar *mad_input_buffer;
|
|
|
|
|
|
|
|
tocopy = MIN (MAD_BUFFER_MDLEN, size);
|
2002-12-11 21:57:39 +00:00
|
|
|
|
2003-01-08 16:11:48 +00:00
|
|
|
/* append the chunk to process to our internal temporary buffer */
|
2001-12-28 01:59:26 +00:00
|
|
|
memcpy (mad->tempbuffer + mad->tempsize, data, tocopy);
|
|
|
|
mad->tempsize += tocopy;
|
|
|
|
|
2003-01-08 16:11:48 +00:00
|
|
|
/* update our incoming buffer's parameters to reflect this */
|
2001-12-28 01:59:26 +00:00
|
|
|
size -= tocopy;
|
|
|
|
data += tocopy;
|
|
|
|
|
|
|
|
mad_input_buffer = mad->tempbuffer;
|
|
|
|
|
2003-01-08 16:11:48 +00:00
|
|
|
/* while we have data we can consume it */
|
2002-02-10 14:13:41 +00:00
|
|
|
while (mad->tempsize >= 0) {
|
2001-12-28 01:59:26 +00:00
|
|
|
gint consumed;
|
2002-11-02 17:40:16 +00:00
|
|
|
guint nchannels;
|
|
|
|
guint nsamples;
|
2002-11-08 20:39:58 +00:00
|
|
|
gint rate;
|
2003-01-20 19:38:37 +00:00
|
|
|
guint64 time_offset;
|
2003-05-24 10:14:39 +00:00
|
|
|
guint64 time_duration;
|
2001-12-28 01:59:26 +00:00
|
|
|
|
|
|
|
mad_stream_buffer (&mad->stream, mad_input_buffer, mad->tempsize);
|
|
|
|
|
|
|
|
if (mad_frame_decode (&mad->frame, &mad->stream) == -1) {
|
2002-02-10 14:13:41 +00:00
|
|
|
/* not enough data, need to wait for next buffer? */
|
|
|
|
if (mad->stream.error == MAD_ERROR_BUFLEN) {
|
|
|
|
break;
|
2002-12-11 21:57:39 +00:00
|
|
|
}
|
2001-12-28 01:59:26 +00:00
|
|
|
if (!MAD_RECOVERABLE (mad->stream.error)) {
|
2003-09-16 10:00:00 +00:00
|
|
|
gst_element_error (GST_ELEMENT (mad), "fatal error decoding stream");
|
2001-12-28 01:59:26 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-09-17 21:40:37 +00:00
|
|
|
else if (mad->stream.error == MAD_ERROR_LOSTSYNC) {
|
2002-12-11 21:57:39 +00:00
|
|
|
/* lost sync, force a resync */
|
2002-09-17 21:40:37 +00:00
|
|
|
signed long tagsize;
|
|
|
|
|
|
|
|
tagsize = id3_tag_query (mad->stream.this_frame,
|
|
|
|
mad->stream.bufend - mad->stream.this_frame);
|
|
|
|
|
|
|
|
if (tagsize > mad->tempsize) {
|
2003-10-01 13:14:51 +00:00
|
|
|
GST_INFO ("mad: got partial id3 tag in buffer, skipping");
|
2002-09-17 21:40:37 +00:00
|
|
|
}
|
|
|
|
else if (tagsize > 0) {
|
|
|
|
struct id3_tag *tag;
|
|
|
|
id3_byte_t const *data;
|
|
|
|
|
2003-10-01 13:14:51 +00:00
|
|
|
GST_INFO ("mad: got ID3 tag size %ld", tagsize);
|
2002-09-17 21:40:37 +00:00
|
|
|
|
|
|
|
data = mad->stream.this_frame;
|
2002-12-11 21:57:39 +00:00
|
|
|
|
2002-11-08 20:39:58 +00:00
|
|
|
/* mad has moved the pointer to the next frame over the start of the
|
2002-12-11 21:57:39 +00:00
|
|
|
* id3 tags, so we need to flush one byte less than the tagsize */
|
|
|
|
mad_stream_skip (&mad->stream, tagsize - 1);
|
2002-09-17 21:40:37 +00:00
|
|
|
|
|
|
|
tag = id3_tag_parse (data, tagsize);
|
|
|
|
if (tag) {
|
2003-11-24 04:08:47 +00:00
|
|
|
GstTagList *list;
|
|
|
|
|
|
|
|
list = gst_mad_id3_to_tag_list (tag);
|
2002-09-17 21:40:37 +00:00
|
|
|
id3_tag_delete (tag);
|
2003-11-24 04:08:47 +00:00
|
|
|
GST_DEBUG_OBJECT (mad, "found tag");
|
|
|
|
gst_element_found_tags (GST_ELEMENT (mad), list);
|
|
|
|
if (mad->tags) {
|
|
|
|
gst_tag_list_insert (mad->tags, list, GST_TAG_MERGE_PREPEND);
|
|
|
|
} else {
|
|
|
|
mad->tags = gst_tag_list_copy (list);
|
|
|
|
}
|
|
|
|
if (GST_PAD_IS_USABLE (mad->srcpad)) {
|
|
|
|
gst_pad_push (mad->srcpad, GST_DATA (gst_event_new_tag (list)));
|
|
|
|
} else {
|
|
|
|
gst_tag_list_free (list);
|
|
|
|
}
|
2002-09-17 21:40:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2002-11-08 20:39:58 +00:00
|
|
|
mad_frame_mute (&mad->frame);
|
|
|
|
mad_synth_mute (&mad->synth);
|
2002-06-09 11:29:14 +00:00
|
|
|
mad_stream_sync (&mad->stream);
|
2002-03-30 17:06:26 +00:00
|
|
|
/* recoverable errors pass */
|
2002-04-13 17:17:59 +00:00
|
|
|
goto next;
|
2001-12-28 01:59:26 +00:00
|
|
|
}
|
2002-03-30 17:06:26 +00:00
|
|
|
|
2001-12-28 01:59:26 +00:00
|
|
|
nchannels = MAD_NCHANNELS (&mad->frame.header);
|
2003-01-08 16:11:48 +00:00
|
|
|
nsamples = MAD_NSBSAMPLES (&mad->frame.header) *
|
|
|
|
(mad->stream.options & MAD_OPTION_HALFSAMPLERATE ? 16 : 32);
|
2001-12-20 22:27:35 +00:00
|
|
|
|
2002-11-08 20:39:58 +00:00
|
|
|
#if MAD_VERSION_MINOR <= 12
|
|
|
|
rate = mad->header.sfreq;
|
|
|
|
#else
|
|
|
|
rate = mad->frame.header.samplerate;
|
|
|
|
#endif
|
|
|
|
|
2002-05-26 21:59:22 +00:00
|
|
|
gst_mad_update_info (mad);
|
2001-12-20 22:10:54 +00:00
|
|
|
|
2002-11-08 20:39:58 +00:00
|
|
|
if (mad->channels != nchannels || mad->rate != rate) {
|
2003-01-08 16:11:48 +00:00
|
|
|
if (mad->stream.options & MAD_OPTION_HALFSAMPLERATE)
|
2002-11-02 17:40:16 +00:00
|
|
|
rate >>=1;
|
|
|
|
|
2002-11-11 13:54:52 +00:00
|
|
|
/* we set the caps even when the pad is not connected so they
|
|
|
|
* can be gotten for streaminfo */
|
2002-11-02 17:40:16 +00:00
|
|
|
if (gst_pad_try_set_caps (mad->srcpad,
|
2003-01-08 16:11:48 +00:00
|
|
|
gst_caps_new (
|
|
|
|
"mad_src",
|
2003-07-06 20:49:50 +00:00
|
|
|
"audio/x-raw-int",
|
2002-11-02 17:40:16 +00:00
|
|
|
gst_props_new (
|
|
|
|
"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 (rate),
|
|
|
|
"channels", GST_PROPS_INT (nchannels),
|
2003-01-08 16:11:48 +00:00
|
|
|
NULL))) <= 0)
|
2002-11-02 17:40:16 +00:00
|
|
|
{
|
2003-05-29 09:12:17 +00:00
|
|
|
if (!gst_pad_recover_caps_error (mad->srcpad, NULL)) {
|
|
|
|
gst_buffer_unref (buffer);
|
|
|
|
return;
|
|
|
|
}
|
2002-11-02 17:40:16 +00:00
|
|
|
}
|
2002-11-08 20:39:58 +00:00
|
|
|
mad->channels = nchannels;
|
|
|
|
mad->rate = rate;
|
2002-11-02 17:40:16 +00:00
|
|
|
}
|
|
|
|
|
2003-01-20 19:38:37 +00:00
|
|
|
if (mad->frame.header.samplerate == 0) {
|
|
|
|
g_warning ("mad->frame.header.samplerate is 0; timestamps cannot be calculated");
|
2003-04-13 03:11:06 +00:00
|
|
|
time_offset = GST_CLOCK_TIME_NONE;
|
2003-05-24 10:14:39 +00:00
|
|
|
time_duration = GST_CLOCK_TIME_NONE;
|
2003-01-20 19:38:37 +00:00
|
|
|
}
|
|
|
|
else {
|
2003-05-30 14:48:29 +00:00
|
|
|
/* if we have a pending timestamp, we can use it now to calculate the sample offset */
|
|
|
|
if (GST_CLOCK_TIME_IS_VALID (mad->last_ts)) {
|
|
|
|
GstFormat format = GST_FORMAT_DEFAULT;
|
|
|
|
gst_pad_convert (mad->srcpad, GST_FORMAT_TIME, mad->last_ts, &format, &mad->total_samples);
|
|
|
|
mad->last_ts = GST_CLOCK_TIME_NONE;
|
|
|
|
}
|
2003-05-29 09:12:17 +00:00
|
|
|
time_offset = mad->total_samples * GST_SECOND
|
|
|
|
/ mad->frame.header.samplerate;
|
2003-06-07 00:28:20 +00:00
|
|
|
time_duration = (nsamples * GST_SECOND
|
|
|
|
/ mad->frame.header.samplerate);
|
2003-01-20 19:38:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mad->index) {
|
|
|
|
guint64 x_bytes = mad->base_byte_offset + mad->bytes_consumed;
|
|
|
|
|
|
|
|
gst_index_add_association (mad->index, mad->index_id, 0,
|
|
|
|
GST_FORMAT_BYTES, x_bytes,
|
|
|
|
GST_FORMAT_TIME, time_offset,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (GST_PAD_IS_USABLE (mad->srcpad) &&
|
2003-05-29 09:12:17 +00:00
|
|
|
mad->segment_start <= (time_offset == GST_CLOCK_TIME_NONE ? 0 : time_offset)) {
|
2003-01-20 19:38:37 +00:00
|
|
|
|
|
|
|
/* for sample accurate seeking, calculate how many samples
|
|
|
|
to skip and send the remaining pcm samples */
|
|
|
|
|
2002-11-02 17:40:16 +00:00
|
|
|
GstBuffer *outbuffer;
|
|
|
|
gint16 *outdata;
|
|
|
|
mad_fixed_t const *left_ch, *right_ch;
|
|
|
|
|
|
|
|
mad_synth_frame (&mad->synth, &mad->frame);
|
|
|
|
left_ch = mad->synth.pcm.samples[0];
|
|
|
|
right_ch = mad->synth.pcm.samples[1];
|
2002-02-03 20:10:04 +00:00
|
|
|
|
2002-09-17 21:40:37 +00:00
|
|
|
outbuffer = gst_buffer_new_and_alloc (nsamples * nchannels * 2);
|
|
|
|
outdata = (gint16 *) GST_BUFFER_DATA (outbuffer);
|
2002-03-30 17:06:26 +00:00
|
|
|
|
2003-01-20 19:38:37 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (outbuffer) = time_offset;
|
2003-05-24 10:14:39 +00:00
|
|
|
GST_BUFFER_DURATION (outbuffer) = time_duration;
|
|
|
|
GST_BUFFER_OFFSET (outbuffer) = mad->total_samples;
|
2002-02-03 20:10:04 +00:00
|
|
|
|
2001-12-28 01:59:26 +00:00
|
|
|
/* output sample(s) in 16-bit signed native-endian PCM */
|
2002-09-17 21:40:37 +00:00
|
|
|
if (nchannels == 1) {
|
2002-11-02 17:40:16 +00:00
|
|
|
gint count = nsamples;
|
|
|
|
while (count--) {
|
2002-09-17 21:40:37 +00:00
|
|
|
*outdata++ = scale(*left_ch++) & 0xffff;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2002-11-02 17:40:16 +00:00
|
|
|
gint count = nsamples;
|
|
|
|
while (count--) {
|
2002-09-17 21:40:37 +00:00
|
|
|
*outdata++ = scale(*left_ch++) & 0xffff;
|
|
|
|
*outdata++ = scale(*right_ch++) & 0xffff;
|
|
|
|
}
|
2001-12-28 01:59:26 +00:00
|
|
|
}
|
2001-12-20 22:10:54 +00:00
|
|
|
|
2003-10-08 16:08:10 +00:00
|
|
|
gst_pad_push (mad->srcpad, GST_DATA (outbuffer));
|
2002-05-26 21:59:22 +00:00
|
|
|
}
|
2002-11-02 17:40:16 +00:00
|
|
|
|
|
|
|
mad->total_samples += nsamples;
|
2002-05-26 21:59:22 +00:00
|
|
|
|
2003-01-08 16:11:48 +00:00
|
|
|
/* we have a queued timestamp on the incoming buffer that we should
|
2002-09-18 22:04:32 +00:00
|
|
|
* use for the next frame */
|
|
|
|
if (new_pts) {
|
2003-05-30 14:48:29 +00:00
|
|
|
mad->last_ts = timestamp;
|
2002-09-18 22:04:32 +00:00
|
|
|
new_pts = FALSE;
|
2003-01-20 19:38:37 +00:00
|
|
|
mad->base_byte_offset = GST_BUFFER_OFFSET (buffer);
|
|
|
|
mad->bytes_consumed = 0;
|
2002-09-18 22:04:32 +00:00
|
|
|
}
|
|
|
|
|
2003-01-20 19:38:37 +00:00
|
|
|
if (gst_mad_check_restart (mad)) {
|
2002-05-07 21:02:24 +00:00
|
|
|
goto end;
|
|
|
|
}
|
2002-06-09 14:30:16 +00:00
|
|
|
|
2002-04-13 17:17:59 +00:00
|
|
|
next:
|
2001-12-28 01:59:26 +00:00
|
|
|
/* figure out how many bytes mad consumed */
|
|
|
|
consumed = mad->stream.next_frame - mad_input_buffer;
|
|
|
|
|
|
|
|
/* move out pointer to where mad want the next data */
|
|
|
|
mad_input_buffer += consumed;
|
|
|
|
mad->tempsize -= consumed;
|
2003-01-20 19:38:37 +00:00
|
|
|
mad->bytes_consumed += consumed;
|
2001-12-28 01:59:26 +00:00
|
|
|
}
|
|
|
|
memmove (mad->tempbuffer, mad_input_buffer, mad->tempsize);
|
2001-12-20 22:10:54 +00:00
|
|
|
}
|
|
|
|
|
2002-05-07 21:02:24 +00:00
|
|
|
end:
|
2001-12-28 01:59:26 +00:00
|
|
|
gst_buffer_unref (buffer);
|
2001-12-20 22:10:54 +00:00
|
|
|
}
|
|
|
|
|
2001-12-28 01:59:26 +00:00
|
|
|
static GstElementStateReturn
|
|
|
|
gst_mad_change_state (GstElement *element)
|
2001-12-20 22:10:54 +00:00
|
|
|
{
|
|
|
|
GstMad *mad;
|
|
|
|
|
|
|
|
mad = GST_MAD (element);
|
|
|
|
|
2001-12-28 01:59:26 +00:00
|
|
|
switch (GST_STATE_TRANSITION (element)) {
|
|
|
|
case GST_STATE_NULL_TO_READY:
|
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_PAUSED:
|
2002-11-02 17:40:16 +00:00
|
|
|
{
|
|
|
|
guint options = 0;
|
|
|
|
|
2001-12-28 01:59:26 +00:00
|
|
|
mad_stream_init (&mad->stream);
|
|
|
|
mad_frame_init (&mad->frame);
|
|
|
|
mad_synth_init (&mad->synth);
|
2002-03-30 17:06:26 +00:00
|
|
|
mad->tempsize = 0;
|
2002-05-07 21:02:24 +00:00
|
|
|
mad->total_samples = 0;
|
2002-11-08 20:39:58 +00:00
|
|
|
mad->rate = 0;
|
|
|
|
mad->channels = 0;
|
2002-09-02 18:13:26 +00:00
|
|
|
mad->vbr_average = 0;
|
2003-01-20 19:38:37 +00:00
|
|
|
mad->segment_start = 0;
|
2002-12-07 14:32:21 +00:00
|
|
|
mad->new_header = TRUE;
|
|
|
|
mad->framecount = 0;
|
|
|
|
mad->vbr_rate = 0;
|
2002-09-02 18:13:26 +00:00
|
|
|
mad->frame.header.samplerate = 0;
|
2003-05-30 14:48:29 +00:00
|
|
|
mad->last_ts = GST_CLOCK_TIME_NONE;
|
2002-11-02 17:40:16 +00:00
|
|
|
if (mad->ignore_crc) options |= MAD_OPTION_IGNORECRC;
|
|
|
|
if (mad->half) options |= MAD_OPTION_HALFSAMPLERATE;
|
|
|
|
mad_stream_options (&mad->stream, options);
|
2001-12-28 01:59:26 +00:00
|
|
|
break;
|
2002-11-02 17:40:16 +00:00
|
|
|
}
|
2001-12-28 01:59:26 +00:00
|
|
|
case GST_STATE_PAUSED_TO_PLAYING:
|
|
|
|
/* do something to get out of the chain function faster */
|
|
|
|
break;
|
|
|
|
case GST_STATE_PLAYING_TO_PAUSED:
|
|
|
|
break;
|
|
|
|
case GST_STATE_PAUSED_TO_READY:
|
|
|
|
mad_synth_finish (&mad->synth);
|
|
|
|
mad_frame_finish (&mad->frame);
|
|
|
|
mad_stream_finish (&mad->stream);
|
2002-09-02 19:07:01 +00:00
|
|
|
mad->restart = TRUE;
|
2003-11-24 04:08:47 +00:00
|
|
|
if (mad->tags) {
|
|
|
|
gst_tag_list_free (mad->tags);
|
|
|
|
mad->tags = NULL;
|
|
|
|
}
|
2001-12-28 01:59:26 +00:00
|
|
|
break;
|
|
|
|
case GST_STATE_READY_TO_NULL:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-05-08 19:58:13 +00:00
|
|
|
return parent_class->change_state (element);
|
2001-12-28 01:59:26 +00:00
|
|
|
}
|
2001-12-20 22:10:54 +00:00
|
|
|
|