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.
|
|
|
|
*/
|
|
|
|
|
2008-06-13 06:57:21 +00:00
|
|
|
/**
|
|
|
|
* SECTION:element-mad
|
|
|
|
* @see_also: lame
|
|
|
|
*
|
|
|
|
* MP3 audio decoder.
|
|
|
|
*
|
|
|
|
* <refsect2>
|
|
|
|
* <title>Example pipelines</title>
|
|
|
|
* |[
|
|
|
|
* gst-launch filesrc location=music.mp3 ! mad ! audioconvert ! audioresample ! autoaudiosink
|
|
|
|
* ]| Decode the mp3 file and play
|
|
|
|
* </refsect2>
|
|
|
|
*/
|
|
|
|
|
2003-06-29 19:46:09 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2003-07-25 02:04:01 +00:00
|
|
|
|
2009-10-02 15:27:11 +00:00
|
|
|
#include <stdlib.h>
|
2001-12-20 22:10:54 +00:00
|
|
|
#include <string.h>
|
2003-11-24 04:08:47 +00:00
|
|
|
#include "gstmad.h"
|
2007-07-13 15:46:13 +00:00
|
|
|
#include <gst/audio/audio.h>
|
2002-02-03 20:10:04 +00:00
|
|
|
|
2011-03-11 17:45:37 +00:00
|
|
|
#ifdef HAVE_ID3TAG
|
|
|
|
#include <id3tag.h>
|
|
|
|
#endif
|
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
enum
|
|
|
|
{
|
2001-12-20 22:10:54 +00:00
|
|
|
ARG_0,
|
2002-11-02 17:40:16 +00:00
|
|
|
ARG_HALF,
|
2006-06-17 19:35:41 +00:00
|
|
|
ARG_IGNORE_CRC
|
2001-12-20 22:10:54 +00:00
|
|
|
};
|
|
|
|
|
2004-04-05 11:38:04 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (mad_debug);
|
|
|
|
#define GST_CAT_DEFAULT mad_debug
|
|
|
|
|
2003-12-22 01:47:08 +00:00
|
|
|
static GstStaticPadTemplate mad_src_template_factory =
|
2004-03-14 22:34:30 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("src",
|
|
|
|
GST_PAD_SRC,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("audio/x-raw-int, "
|
2004-03-15 19:32:25 +00:00
|
|
|
"endianness = (int) " G_STRINGIFY (G_BYTE_ORDER) ", "
|
|
|
|
"signed = (boolean) true, "
|
2006-01-31 22:03:30 +00:00
|
|
|
"width = (int) 32, "
|
|
|
|
"depth = (int) 32, "
|
2004-06-14 10:58:27 +00:00
|
|
|
"rate = (int) { 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000 }, "
|
|
|
|
"channels = (int) [ 1, 2 ]")
|
2004-03-14 22:34:30 +00:00
|
|
|
);
|
2001-12-20 22:10:54 +00:00
|
|
|
|
2004-06-14 10:58:27 +00:00
|
|
|
/* FIXME: make three caps, for mpegversion 1, 2 and 2.5 */
|
2003-12-22 01:47:08 +00:00
|
|
|
static GstStaticPadTemplate mad_sink_template_factory =
|
2004-03-14 22:34:30 +00:00
|
|
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
|
|
|
GST_PAD_SINK,
|
|
|
|
GST_PAD_ALWAYS,
|
|
|
|
GST_STATIC_CAPS ("audio/mpeg, "
|
2004-06-14 10:58:27 +00:00
|
|
|
"mpegversion = (int) 1, "
|
|
|
|
"layer = (int) [ 1, 3 ], "
|
|
|
|
"rate = (int) { 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000 }, "
|
|
|
|
"channels = (int) [ 1, 2 ]")
|
2004-03-14 22:34:30 +00:00
|
|
|
);
|
2001-12-20 22:10:54 +00:00
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
static void gst_mad_dispose (GObject * object);
|
2010-09-29 19:24:23 +00:00
|
|
|
static void gst_mad_clear_queues (GstMad * mad);
|
2004-03-14 22:34:30 +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);
|
2001-12-20 22:10:54 +00:00
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
static gboolean gst_mad_src_event (GstPad * pad, GstEvent * event);
|
2005-05-11 22:42:47 +00:00
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
static const GstQueryType *gst_mad_get_query_types (GstPad * pad);
|
|
|
|
|
2005-05-11 22:42:47 +00:00
|
|
|
static gboolean gst_mad_src_query (GstPad * pad, GstQuery * query);
|
2004-03-14 22:34:30 +00:00
|
|
|
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);
|
|
|
|
|
2005-05-06 11:04:30 +00:00
|
|
|
static gboolean gst_mad_sink_event (GstPad * pad, GstEvent * event);
|
|
|
|
static GstFlowReturn gst_mad_chain (GstPad * pad, GstBuffer * buffer);
|
2010-09-29 19:24:23 +00:00
|
|
|
static GstFlowReturn gst_mad_chain_reverse (GstMad * mad, GstBuffer * buf);
|
2004-03-14 22:34:30 +00:00
|
|
|
|
2005-09-02 15:43:54 +00:00
|
|
|
static GstStateChangeReturn gst_mad_change_state (GstElement * element,
|
|
|
|
GstStateChange transition);
|
2004-03-14 22:34:30 +00:00
|
|
|
|
|
|
|
static void gst_mad_set_index (GstElement * element, GstIndex * index);
|
|
|
|
static GstIndex *gst_mad_get_index (GstElement * element);
|
2003-01-20 19:38:37 +00:00
|
|
|
|
2011-03-11 17:45:37 +00:00
|
|
|
#ifdef HAVE_ID3TAG
|
2009-06-05 19:53:57 +00:00
|
|
|
static GstTagList *gst_mad_id3_to_tag_list (const struct id3_tag *tag);
|
2011-03-11 17:45:37 +00:00
|
|
|
#endif
|
2001-12-20 22:10:54 +00:00
|
|
|
|
2011-04-19 17:24:23 +00:00
|
|
|
#define gst_mad_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE (GstMad, gst_mad, GST_TYPE_ELEMENT);
|
2007-07-13 15:46:13 +00:00
|
|
|
|
2008-01-10 17:24:09 +00:00
|
|
|
/*
|
2002-07-24 21:36:39 +00:00
|
|
|
#define GST_TYPE_MAD_LAYER (gst_mad_layer_get_type())
|
2008-01-10 17:24:09 +00:00
|
|
|
static GType
|
2004-03-14 22:34:30 +00:00
|
|
|
gst_mad_layer_get_type (void)
|
|
|
|
{
|
2002-07-24 21:36:39 +00:00
|
|
|
static GType mad_layer_type = 0;
|
|
|
|
static GEnumValue mad_layer[] = {
|
2005-11-22 17:04:38 +00:00
|
|
|
{0, "Unknown", "unknown"},
|
|
|
|
{MAD_LAYER_I, "Layer I", "1"},
|
|
|
|
{MAD_LAYER_II, "Layer II", "2"},
|
|
|
|
{MAD_LAYER_III, "Layer III", "3"},
|
2002-07-24 21:36:39 +00:00
|
|
|
{0, NULL, NULL},
|
|
|
|
};
|
2004-03-15 19:32:25 +00:00
|
|
|
|
2002-07-24 21:36:39 +00:00
|
|
|
if (!mad_layer_type) {
|
2004-03-14 22:34:30 +00:00
|
|
|
mad_layer_type = g_enum_register_static ("GstMadLayer", mad_layer);
|
2002-07-24 21:36:39 +00:00
|
|
|
}
|
|
|
|
return mad_layer_type;
|
|
|
|
}
|
2008-01-10 17:24:09 +00:00
|
|
|
*/
|
2002-07-24 21:36:39 +00:00
|
|
|
|
|
|
|
#define GST_TYPE_MAD_MODE (gst_mad_mode_get_type())
|
2008-01-10 17:24:09 +00:00
|
|
|
static GType
|
2004-03-14 22:34:30 +00:00
|
|
|
gst_mad_mode_get_type (void)
|
|
|
|
{
|
2002-07-24 21:36:39 +00:00
|
|
|
static GType mad_mode_type = 0;
|
|
|
|
static GEnumValue mad_mode[] = {
|
2005-11-22 17:04:38 +00:00
|
|
|
{-1, "Unknown", "unknown"},
|
2005-11-22 17:39:36 +00:00
|
|
|
{MAD_MODE_SINGLE_CHANNEL, "Mono", "mono"},
|
2005-11-22 17:04:38 +00:00
|
|
|
{MAD_MODE_DUAL_CHANNEL, "Dual Channel", "dual"},
|
|
|
|
{MAD_MODE_JOINT_STEREO, "Joint Stereo", "joint"},
|
|
|
|
{MAD_MODE_STEREO, "Stereo", "stereo"},
|
2004-03-14 22:34:30 +00:00
|
|
|
{0, NULL, NULL},
|
2002-07-24 21:36:39 +00:00
|
|
|
};
|
2004-03-15 19:32:25 +00:00
|
|
|
|
2002-07-24 21:36:39 +00:00
|
|
|
if (!mad_mode_type) {
|
2004-03-14 22:34:30 +00:00
|
|
|
mad_mode_type = g_enum_register_static ("GstMadMode", mad_mode);
|
2002-07-24 21:36:39 +00:00
|
|
|
}
|
|
|
|
return mad_mode_type;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GST_TYPE_MAD_EMPHASIS (gst_mad_emphasis_get_type())
|
2008-01-10 17:24:09 +00:00
|
|
|
static GType
|
2004-03-14 22:34:30 +00:00
|
|
|
gst_mad_emphasis_get_type (void)
|
|
|
|
{
|
2002-07-24 21:36:39 +00:00
|
|
|
static GType mad_emphasis_type = 0;
|
|
|
|
static GEnumValue mad_emphasis[] = {
|
2005-11-22 17:04:38 +00:00
|
|
|
{-1, "Unknown", "unknown"},
|
|
|
|
{MAD_EMPHASIS_NONE, "None", "none"},
|
|
|
|
{MAD_EMPHASIS_50_15_US, "50/15 Microseconds", "50-15"},
|
|
|
|
{MAD_EMPHASIS_CCITT_J_17, "CCITT J.17", "j-17"},
|
|
|
|
{MAD_EMPHASIS_RESERVED, "Reserved", "reserved"},
|
2004-03-14 22:34:30 +00:00
|
|
|
{0, NULL, NULL},
|
2002-07-24 21:36:39 +00:00
|
|
|
};
|
2004-03-15 19:32:25 +00:00
|
|
|
|
2002-07-24 21:36:39 +00:00
|
|
|
if (!mad_emphasis_type) {
|
2004-03-14 22:34:30 +00:00
|
|
|
mad_emphasis_type = g_enum_register_static ("GstMadEmphasis", mad_emphasis);
|
2002-07-24 21:36:39 +00:00
|
|
|
}
|
|
|
|
return mad_emphasis_type;
|
|
|
|
}
|
2002-02-06 18:10:35 +00:00
|
|
|
|
2001-12-20 22:10:54 +00:00
|
|
|
static void
|
2004-03-14 22:34:30 +00:00
|
|
|
gst_mad_class_init (GstMadClass * klass)
|
2001-12-20 22:10:54 +00:00
|
|
|
{
|
2001-12-28 01:59:26 +00:00
|
|
|
GObjectClass *gobject_class;
|
2001-12-20 22:10:54 +00:00
|
|
|
GstElementClass *gstelement_class;
|
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
gobject_class = (GObjectClass *) klass;
|
|
|
|
gstelement_class = (GstElementClass *) klass;
|
2001-12-20 22:10:54 +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;
|
|
|
|
|
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,
|
2004-03-14 22:34:30 +00:00
|
|
|
g_param_spec_boolean ("half", "Half", "Generate PCM at 1/2 sample rate",
|
2010-10-19 07:06:33 +00:00
|
|
|
FALSE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2002-11-02 17:40:16 +00:00
|
|
|
g_object_class_install_property (gobject_class, ARG_IGNORE_CRC,
|
2010-10-19 09:20:40 +00:00
|
|
|
g_param_spec_boolean ("ignore-crc", "Ignore CRC", "Ignore CRC errors",
|
2010-10-19 07:06:33 +00:00
|
|
|
TRUE, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2004-03-06 18:39:39 +00:00
|
|
|
|
2011-04-19 17:24:23 +00:00
|
|
|
gstelement_class->change_state = gst_mad_change_state;
|
|
|
|
gstelement_class->set_index = gst_mad_set_index;
|
|
|
|
gstelement_class->get_index = gst_mad_get_index;
|
|
|
|
|
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
|
|
|
gst_static_pad_template_get (&mad_sink_template_factory));
|
|
|
|
gst_element_class_add_pad_template (gstelement_class,
|
|
|
|
gst_static_pad_template_get (&mad_src_template_factory));
|
|
|
|
|
|
|
|
gst_element_class_set_details_simple (gstelement_class, "mad mp3 decoder",
|
|
|
|
"Codec/Decoder/Audio",
|
|
|
|
"Uses mad code to decode mp3 streams", "Wim Taymans <wim@fluendo.com>");
|
|
|
|
|
2004-03-06 18:39:39 +00:00
|
|
|
/* register tags */
|
|
|
|
#define GST_TAG_LAYER "layer"
|
|
|
|
#define GST_TAG_MODE "mode"
|
|
|
|
#define GST_TAG_EMPHASIS "emphasis"
|
|
|
|
|
2008-01-10 17:24:09 +00:00
|
|
|
/* FIXME 0.11: strings!? why? */
|
2004-03-06 18:39:39 +00:00
|
|
|
gst_tag_register (GST_TAG_LAYER, GST_TAG_FLAG_ENCODED, G_TYPE_UINT,
|
2004-03-14 22:34:30 +00:00
|
|
|
"layer", "MPEG audio layer", NULL);
|
2004-03-06 18:39:39 +00:00
|
|
|
gst_tag_register (GST_TAG_MODE, GST_TAG_FLAG_ENCODED, G_TYPE_STRING,
|
2004-03-14 22:34:30 +00:00
|
|
|
"mode", "MPEG audio channel mode", NULL);
|
2004-03-06 18:39:39 +00:00
|
|
|
gst_tag_register (GST_TAG_EMPHASIS, GST_TAG_FLAG_ENCODED, G_TYPE_STRING,
|
2004-03-14 22:34:30 +00:00
|
|
|
"emphasis", "MPEG audio emphasis", NULL);
|
2008-01-10 17:24:09 +00:00
|
|
|
|
|
|
|
/* ref these here from a thread-safe context (ie. not the streaming thread) */
|
|
|
|
g_type_class_ref (GST_TYPE_MAD_MODE);
|
|
|
|
g_type_class_ref (GST_TYPE_MAD_EMPHASIS);
|
2001-12-20 22:10:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-04-19 17:24:23 +00:00
|
|
|
gst_mad_init (GstMad * mad)
|
2001-12-20 22:10:54 +00:00
|
|
|
{
|
2005-11-15 20:30:53 +00:00
|
|
|
GstPadTemplate *template;
|
|
|
|
|
2001-12-20 22:10:54 +00:00
|
|
|
/* create the sink and src pads */
|
2005-11-15 20:30:53 +00:00
|
|
|
template = gst_static_pad_template_get (&mad_sink_template_factory);
|
|
|
|
mad->sinkpad = gst_pad_new_from_template (template, "sink");
|
|
|
|
gst_object_unref (template);
|
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));
|
2005-05-06 11:04:30 +00:00
|
|
|
gst_pad_set_event_function (mad->sinkpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_mad_sink_event));
|
2008-01-21 12:43:37 +00:00
|
|
|
|
2005-11-15 20:30:53 +00:00
|
|
|
template = gst_static_pad_template_get (&mad_src_template_factory);
|
|
|
|
mad->srcpad = gst_pad_new_from_template (template, "src");
|
|
|
|
gst_object_unref (template);
|
2002-05-26 21:59:22 +00:00
|
|
|
gst_element_add_pad (GST_ELEMENT (mad), mad->srcpad);
|
2004-03-14 22:34:30 +00:00
|
|
|
gst_pad_set_event_function (mad->srcpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_mad_src_event));
|
|
|
|
gst_pad_set_query_function (mad->srcpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_mad_src_query));
|
|
|
|
gst_pad_set_query_type_function (mad->srcpad,
|
|
|
|
GST_DEBUG_FUNCPTR (gst_mad_get_query_types));
|
2005-10-06 13:14:38 +00:00
|
|
|
gst_pad_use_fixed_caps (mad->srcpad);
|
2008-01-21 12:43:37 +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;
|
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;
|
2005-08-09 13:02:54 +00:00
|
|
|
mad->restart = TRUE;
|
2003-01-20 19:38:37 +00:00
|
|
|
mad->segment_start = 0;
|
2007-07-13 15:46:13 +00:00
|
|
|
gst_segment_init (&mad->segment, GST_FORMAT_TIME);
|
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;
|
2004-05-16 20:50:13 +00:00
|
|
|
mad->ignore_crc = TRUE;
|
2004-03-05 23:32:36 +00:00
|
|
|
mad->check_for_xing = TRUE;
|
ext/mad/gstmad.c: Port fixes for bugs 314771, 308772, 140237, and 302625
Original commit message from CVS:
* ext/mad/gstmad.c: (gst_mad_init), (scale), (gst_mad_update_info),
(gst_mad_sink_event), (gst_mad_check_caps_reset), (gst_mad_chain),
(gst_mad_change_state):
Port fixes for bugs 314771, 308772, 140237, and 302625
from 0.8 (Patch by Jonathan Matthew, Fixes #329575)
Use GST_EVENT_FLUSH_STOP to clear data from the current input
buffer, to avoid using it for any future decoding.
2006-02-16 09:50:43 +00:00
|
|
|
mad->xing_found = FALSE;
|
2001-12-20 22:10:54 +00:00
|
|
|
}
|
|
|
|
|
2001-12-28 01:59:26 +00:00
|
|
|
static void
|
2004-03-14 22:34:30 +00:00
|
|
|
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_free (mad->tempbuffer);
|
2005-12-18 15:08:15 +00:00
|
|
|
mad->tempbuffer = NULL;
|
2008-01-21 12:43:37 +00:00
|
|
|
|
2008-02-27 13:18:57 +00:00
|
|
|
g_list_foreach (mad->pending_events, (GFunc) gst_mini_object_unref, NULL);
|
|
|
|
g_list_free (mad->pending_events);
|
|
|
|
mad->pending_events = NULL;
|
|
|
|
|
2008-01-21 12:43:37 +00:00
|
|
|
G_OBJECT_CLASS (parent_class)->dispose (object);
|
2001-12-20 22:10:54 +00:00
|
|
|
}
|
|
|
|
|
2003-01-20 19:38:37 +00:00
|
|
|
static void
|
2004-03-14 22:34:30 +00:00
|
|
|
gst_mad_set_index (GstElement * element, GstIndex * index)
|
2003-01-20 19:38:37 +00:00
|
|
|
{
|
|
|
|
GstMad *mad = GST_MAD (element);
|
2004-03-14 22:34:30 +00:00
|
|
|
|
2003-01-20 19:38:37 +00:00
|
|
|
mad->index = index;
|
|
|
|
|
|
|
|
if (index)
|
|
|
|
gst_index_get_writer_id (index, GST_OBJECT (element), &mad->index_id);
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
static GstIndex *
|
|
|
|
gst_mad_get_index (GstElement * element)
|
2003-01-20 19:38:37 +00:00
|
|
|
{
|
|
|
|
GstMad *mad = GST_MAD (element);
|
|
|
|
|
|
|
|
return mad->index;
|
|
|
|
}
|
|
|
|
|
2002-05-26 21:59:22 +00:00
|
|
|
static gboolean
|
2004-03-14 22:34:30 +00:00
|
|
|
gst_mad_convert_sink (GstPad * pad, GstFormat src_format, gint64 src_value,
|
|
|
|
GstFormat * dest_format, gint64 * dest_value)
|
2002-05-26 21:59:22 +00:00
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
GstMad *mad;
|
|
|
|
|
2006-04-21 20:37:43 +00:00
|
|
|
if (src_format == *dest_format) {
|
|
|
|
*dest_value = src_value;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-03-12 17:26:13 +00:00
|
|
|
/* -1 always maps to -1, and 0 to 0, we don't need any more info for that */
|
|
|
|
if (src_value == -1 || src_value == 0) {
|
|
|
|
*dest_value = src_value;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-05-06 11:04:30 +00:00
|
|
|
mad = GST_MAD (GST_PAD_PARENT (pad));
|
2002-05-26 21:59:22 +00:00
|
|
|
|
|
|
|
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) {
|
2004-03-15 19:32:25 +00:00
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
/* multiply by 8 because vbr is in bits/second */
|
2006-03-14 19:41:17 +00:00
|
|
|
*dest_value = gst_util_uint64_scale (src_value, 8 * GST_SECOND,
|
|
|
|
mad->vbr_average);
|
2004-03-15 19:32:25 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
2002-05-26 21:59:22 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
switch (*dest_format) {
|
2004-03-15 19:32:25 +00:00
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
/* multiply by 8 because vbr is in bits/second */
|
2006-03-14 19:41:17 +00:00
|
|
|
*dest_value = gst_util_uint64_scale (src_value, mad->vbr_average,
|
|
|
|
8 * GST_SECOND);
|
2004-03-15 19:32:25 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
2002-05-26 21:59:22 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:30 +00:00
|
|
|
gst_mad_convert_src (GstPad * pad, GstFormat src_format, gint64 src_value,
|
|
|
|
GstFormat * dest_format, gint64 * dest_value)
|
2002-05-26 21:59:22 +00:00
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
guint scale = 1;
|
|
|
|
gint bytes_per_sample;
|
|
|
|
GstMad *mad;
|
|
|
|
|
2006-04-21 20:37:43 +00:00
|
|
|
if (src_format == *dest_format) {
|
|
|
|
*dest_value = src_value;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2007-03-12 17:26:13 +00:00
|
|
|
/* -1 always maps to -1, and 0 to 0, we don't need any more info for that */
|
|
|
|
if (src_value == -1 || src_value == 0) {
|
|
|
|
*dest_value = src_value;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2005-05-06 11:04:30 +00:00
|
|
|
mad = GST_MAD (GST_PAD_PARENT (pad));
|
2003-01-08 16:11:48 +00:00
|
|
|
|
2008-05-19 15:07:07 +00:00
|
|
|
bytes_per_sample = mad->channels * 4;
|
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) {
|
2004-03-15 19:32:25 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
|
|
|
if (bytes_per_sample == 0)
|
|
|
|
return FALSE;
|
|
|
|
*dest_value = src_value / bytes_per_sample;
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
{
|
2008-05-19 15:07:07 +00:00
|
|
|
gint byterate = bytes_per_sample * mad->rate;
|
2004-03-15 19:32:25 +00:00
|
|
|
|
|
|
|
if (byterate == 0)
|
|
|
|
return FALSE;
|
2006-04-21 20:37:43 +00:00
|
|
|
*dest_value =
|
|
|
|
gst_util_uint64_scale_int (src_value, GST_SECOND, byterate);
|
2004-03-15 19:32:25 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
2002-05-26 21:59:22 +00:00
|
|
|
}
|
|
|
|
break;
|
2003-05-24 10:14:39 +00:00
|
|
|
case GST_FORMAT_DEFAULT:
|
2002-05-26 21:59:22 +00:00
|
|
|
switch (*dest_format) {
|
2004-03-15 19:32:25 +00:00
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
*dest_value = src_value * bytes_per_sample;
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
2008-05-19 15:07:07 +00:00
|
|
|
if (mad->rate == 0)
|
2004-03-15 19:32:25 +00:00
|
|
|
return FALSE;
|
2006-04-21 20:37:43 +00:00
|
|
|
*dest_value = gst_util_uint64_scale_int (src_value, GST_SECOND,
|
2008-05-19 15:07:07 +00:00
|
|
|
mad->rate);
|
2004-03-15 19:32:25 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
2002-05-26 21:59:22 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_FORMAT_TIME:
|
|
|
|
switch (*dest_format) {
|
2004-03-15 19:32:25 +00:00
|
|
|
case GST_FORMAT_BYTES:
|
|
|
|
scale = bytes_per_sample;
|
|
|
|
/* fallthrough */
|
|
|
|
case GST_FORMAT_DEFAULT:
|
2006-04-21 20:37:43 +00:00
|
|
|
*dest_value = gst_util_uint64_scale_int (src_value,
|
2008-05-19 15:07:07 +00:00
|
|
|
scale * mad->rate, GST_SECOND);
|
2004-03-15 19:32:25 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
2002-05-26 21:59:22 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
res = FALSE;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
static const GstQueryType *
|
|
|
|
gst_mad_get_query_types (GstPad * pad)
|
2002-07-24 21:36:39 +00:00
|
|
|
{
|
2002-12-30 17:53:18 +00:00
|
|
|
static const GstQueryType gst_mad_src_query_types[] = {
|
|
|
|
GST_QUERY_POSITION,
|
2005-10-19 16:01:35 +00:00
|
|
|
GST_QUERY_DURATION,
|
|
|
|
GST_QUERY_CONVERT,
|
2002-07-24 21:36:39 +00:00
|
|
|
0
|
|
|
|
};
|
2004-03-15 19:32:25 +00:00
|
|
|
|
2002-07-24 21:36:39 +00:00
|
|
|
return gst_mad_src_query_types;
|
|
|
|
}
|
|
|
|
|
2002-05-26 21:59:22 +00:00
|
|
|
static gboolean
|
2005-05-11 22:42:47 +00:00
|
|
|
gst_mad_src_query (GstPad * pad, GstQuery * query)
|
2002-05-26 21:59:22 +00:00
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
2005-12-09 18:38:53 +00:00
|
|
|
GstPad *peer;
|
2002-05-26 21:59:22 +00:00
|
|
|
GstMad *mad;
|
2003-01-08 16:11:48 +00:00
|
|
|
|
2005-05-06 11:04:30 +00:00
|
|
|
mad = GST_MAD (GST_PAD_PARENT (pad));
|
2002-05-26 21:59:22 +00:00
|
|
|
|
2005-12-09 18:38:53 +00:00
|
|
|
peer = gst_pad_get_peer (mad->sinkpad);
|
|
|
|
|
2005-05-11 22:42:47 +00:00
|
|
|
switch (GST_QUERY_TYPE (query)) {
|
2006-05-04 08:24:52 +00:00
|
|
|
case GST_QUERY_FORMATS:
|
|
|
|
gst_query_set_formats (query, 3, GST_FORMAT_DEFAULT, GST_FORMAT_TIME,
|
|
|
|
GST_FORMAT_BYTES);
|
|
|
|
break;
|
2005-05-11 22:42:47 +00:00
|
|
|
case GST_QUERY_POSITION:
|
2005-10-19 16:01:35 +00:00
|
|
|
{
|
|
|
|
GstFormat format;
|
|
|
|
gint64 cur;
|
|
|
|
|
|
|
|
/* save requested format */
|
|
|
|
gst_query_parse_position (query, &format, NULL);
|
|
|
|
|
2005-12-09 18:38:53 +00:00
|
|
|
/* try any demuxer before us first */
|
|
|
|
if (format == GST_FORMAT_TIME && peer && gst_pad_query (peer, query)) {
|
|
|
|
gst_query_parse_position (query, NULL, &cur);
|
|
|
|
GST_LOG_OBJECT (mad, "peer returned position %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (cur));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-10-19 16:01:35 +00:00
|
|
|
/* and convert to the requested format */
|
|
|
|
if (format != GST_FORMAT_DEFAULT) {
|
|
|
|
if (!gst_mad_convert_src (pad, GST_FORMAT_DEFAULT, mad->total_samples,
|
|
|
|
&format, &cur))
|
|
|
|
goto error;
|
|
|
|
} else {
|
|
|
|
cur = mad->total_samples;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_query_set_position (query, format, cur);
|
|
|
|
|
2005-11-22 17:39:36 +00:00
|
|
|
if (format == GST_FORMAT_TIME) {
|
|
|
|
GST_LOG ("position=%" GST_TIME_FORMAT, GST_TIME_ARGS (cur));
|
|
|
|
} else {
|
|
|
|
GST_LOG ("position=%" G_GINT64_FORMAT ", format=%u", cur, format);
|
|
|
|
}
|
2005-10-19 16:01:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case GST_QUERY_DURATION:
|
2005-05-11 22:42:47 +00:00
|
|
|
{
|
2006-04-21 19:31:47 +00:00
|
|
|
GstFormat bytes_format = GST_FORMAT_BYTES;
|
2006-04-21 20:37:43 +00:00
|
|
|
GstFormat time_format = GST_FORMAT_TIME;
|
2006-04-21 19:31:47 +00:00
|
|
|
GstFormat req_format;
|
2005-10-19 16:01:35 +00:00
|
|
|
gint64 total, total_bytes;
|
2005-05-11 22:42:47 +00:00
|
|
|
|
2005-05-12 14:15:37 +00:00
|
|
|
/* save requested format */
|
2006-04-21 19:31:47 +00:00
|
|
|
gst_query_parse_duration (query, &req_format, NULL);
|
2005-05-12 14:15:37 +00:00
|
|
|
|
2005-12-09 18:38:53 +00:00
|
|
|
if (peer == NULL)
|
|
|
|
goto error;
|
|
|
|
|
|
|
|
/* try any demuxer before us first */
|
2006-04-21 19:31:47 +00:00
|
|
|
if (req_format == GST_FORMAT_TIME && gst_pad_query (peer, query)) {
|
2005-12-09 18:38:53 +00:00
|
|
|
gst_query_parse_duration (query, NULL, &total);
|
|
|
|
GST_LOG_OBJECT (mad, "peer returned duration %" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (total));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-05-12 14:15:37 +00:00
|
|
|
/* query peer for total length in bytes */
|
2006-04-21 19:31:47 +00:00
|
|
|
if (!gst_pad_query_peer_duration (mad->sinkpad, &bytes_format,
|
|
|
|
&total_bytes) || total_bytes <= 0) {
|
|
|
|
GST_LOG_OBJECT (mad, "duration query on peer pad failed");
|
2005-05-11 22:42:47 +00:00
|
|
|
goto error;
|
2005-05-12 14:15:37 +00:00
|
|
|
}
|
2005-07-01 08:10:55 +00:00
|
|
|
|
2006-04-21 20:37:43 +00:00
|
|
|
GST_LOG_OBJECT (mad, "peer pad returned total=%" G_GINT64_FORMAT
|
|
|
|
" bytes", total_bytes);
|
2005-06-30 16:29:39 +00:00
|
|
|
|
2006-04-21 20:37:43 +00:00
|
|
|
if (!gst_mad_convert_sink (pad, GST_FORMAT_BYTES, total_bytes,
|
|
|
|
&time_format, &total)) {
|
|
|
|
GST_DEBUG_OBJECT (mad, "conversion BYTE => TIME failed");
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
if (!gst_mad_convert_src (pad, GST_FORMAT_TIME, total,
|
|
|
|
&req_format, &total)) {
|
|
|
|
GST_DEBUG_OBJECT (mad, "conversion TIME => %s failed",
|
|
|
|
gst_format_get_name (req_format));
|
|
|
|
goto error;
|
2005-05-12 14:15:37 +00:00
|
|
|
}
|
|
|
|
|
2006-04-21 19:31:47 +00:00
|
|
|
gst_query_set_duration (query, req_format, total);
|
|
|
|
|
|
|
|
if (req_format == GST_FORMAT_TIME) {
|
|
|
|
GST_LOG_OBJECT (mad, "duration=%" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (total));
|
2005-11-22 17:39:36 +00:00
|
|
|
} else {
|
2006-04-21 19:31:47 +00:00
|
|
|
GST_LOG_OBJECT (mad, "duration=%" G_GINT64_FORMAT " (%s)",
|
2006-10-05 17:07:52 +00:00
|
|
|
total, gst_format_get_name (req_format));
|
2005-11-22 17:39:36 +00:00
|
|
|
}
|
2005-05-11 22:42:47 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-07-16 16:43:53 +00:00
|
|
|
case GST_QUERY_CONVERT:
|
|
|
|
{
|
|
|
|
GstFormat src_fmt, dest_fmt;
|
|
|
|
gint64 src_val, dest_val;
|
|
|
|
|
|
|
|
gst_query_parse_convert (query, &src_fmt, &src_val, &dest_fmt, &dest_val);
|
|
|
|
if (!(res =
|
|
|
|
gst_mad_convert_src (pad, src_fmt, src_val, &dest_fmt,
|
|
|
|
&dest_val)))
|
|
|
|
goto error;
|
|
|
|
gst_query_set_convert (query, src_fmt, src_val, dest_fmt, dest_val);
|
|
|
|
break;
|
|
|
|
}
|
2002-05-26 21:59:22 +00:00
|
|
|
default:
|
2006-01-10 11:43:37 +00:00
|
|
|
res = gst_pad_query_default (pad, query);
|
2002-05-26 21:59:22 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-12-09 18:38:53 +00:00
|
|
|
|
|
|
|
if (peer)
|
|
|
|
gst_object_unref (peer);
|
|
|
|
|
2002-05-26 21:59:22 +00:00
|
|
|
return res;
|
2005-05-11 22:42:47 +00:00
|
|
|
|
|
|
|
error:
|
|
|
|
|
|
|
|
GST_DEBUG ("error handling query");
|
2005-12-09 18:38:53 +00:00
|
|
|
|
|
|
|
if (peer)
|
|
|
|
gst_object_unref (peer);
|
|
|
|
|
2005-05-11 22:42:47 +00:00
|
|
|
return FALSE;
|
2002-05-26 21:59:22 +00:00
|
|
|
}
|
|
|
|
|
2003-01-20 19:38:37 +00:00
|
|
|
static gboolean
|
2004-03-14 22:34:30 +00:00
|
|
|
index_seek (GstMad * mad, GstPad * pad, GstEvent * event)
|
2003-01-20 19:38:37 +00:00
|
|
|
{
|
Various event updates and cleanups.
Original commit message from CVS:
* ext/amrnb/amrnbparse.c: (gst_amrnbparse_event),
(gst_amrnbparse_loop):
* ext/dv/gstdvdec.c: (gst_dvdec_handle_sink_event),
(gst_dvdec_handle_src_event), (gst_dvdec_decode_frame):
* ext/mad/gstid3tag.c: (gst_id3_tag_src_event),
(gst_id3_tag_sink_event), (gst_id3_tag_chain):
* ext/mad/gstmad.c: (gst_mad_src_query), (index_seek),
(normal_seek), (gst_mad_sink_event), (gst_mad_chain):
* ext/mpeg2dec/gstmpeg2dec.c:
* ext/shout2/gstshout2.c: (gst_shout2send_event):
* ext/sidplay/gstsiddec.cc:
* gst/avi/gstavidemux.c: (gst_avi_demux_handle_src_event),
(gst_avi_demux_send_event), (gst_avi_demux_stream_header),
(gst_avi_demux_handle_seek), (gst_avi_demux_process_next_entry):
* gst/goom/gstgoom.c: (gst_goom_event):
* gst/realmedia/rmdemux.c: (gst_rmdemux_sink_event),
(gst_rmdemux_chain), (gst_rmdemux_send_event),
(gst_rmdemux_add_stream):
* gst/wavparse/gstwavparse.c: (gst_wavparse_handle_seek),
(gst_wavparse_stream_headers), (gst_wavparse_stream_data),
(gst_wavparse_loop), (gst_wavparse_srcpad_event):
Various event updates and cleanups.
2005-07-27 18:37:25 +00:00
|
|
|
gdouble rate;
|
|
|
|
GstFormat format;
|
|
|
|
GstSeekFlags flags;
|
|
|
|
GstSeekType cur_type, stop_type;
|
|
|
|
gint64 cur, stop;
|
ext/mad/gstmad.c: move GstIndexEntry *entry variable declaration before the first instruction
Original commit message from CVS:
* ext/mad/gstmad.c: (index_seek):
move GstIndexEntry *entry variable declaration before
the first instruction
* ext/mad/gstmad.c:
remove debug macros with variable number of parameter by using
GST_DEBUG for WIN32
* gst/dvdsub/gstdvdsubdec.c: (gst_dvd_sub_dec_parse_subpic):
use gst_guint64_to_gdouble for conversions
* gst/mpegstream/gstmpegdemux.c: (gst_mpeg_demux_sync_stream_to_time):
replace __FUNCTION__ which is not supported by MSVC by the current function name
* gst/mpegstream/gstmpegdemux.c: (gst_mpeg_demux_reset):
remove LL suffix by using G_GINT64_CONSTANT
* gst/mpegstream/gstmpegparse.c: (gst_mpeg_parse_parse_packhead),(gst_mpeg_parse_get_rate):
use gst_guint64_to_gdouble for conversions
* gst/mpegstream/gstmpegparse.h:
remove LL suffix by using G_GINT64_CONSTANT
* win32/vs6:
add project files for tagac3parse, asfdemux, dvdlpcmdec, dvdsub, iec958, lame,
mad, mpegaudioparse, mpegstream, realmedia, synaesthesia
2006-04-09 18:09:40 +00:00
|
|
|
GstIndexEntry *entry = NULL;
|
Various event updates and cleanups.
Original commit message from CVS:
* ext/amrnb/amrnbparse.c: (gst_amrnbparse_event),
(gst_amrnbparse_loop):
* ext/dv/gstdvdec.c: (gst_dvdec_handle_sink_event),
(gst_dvdec_handle_src_event), (gst_dvdec_decode_frame):
* ext/mad/gstid3tag.c: (gst_id3_tag_src_event),
(gst_id3_tag_sink_event), (gst_id3_tag_chain):
* ext/mad/gstmad.c: (gst_mad_src_query), (index_seek),
(normal_seek), (gst_mad_sink_event), (gst_mad_chain):
* ext/mpeg2dec/gstmpeg2dec.c:
* ext/shout2/gstshout2.c: (gst_shout2send_event):
* ext/sidplay/gstsiddec.cc:
* gst/avi/gstavidemux.c: (gst_avi_demux_handle_src_event),
(gst_avi_demux_send_event), (gst_avi_demux_stream_header),
(gst_avi_demux_handle_seek), (gst_avi_demux_process_next_entry):
* gst/goom/gstgoom.c: (gst_goom_event):
* gst/realmedia/rmdemux.c: (gst_rmdemux_sink_event),
(gst_rmdemux_chain), (gst_rmdemux_send_event),
(gst_rmdemux_add_stream):
* gst/wavparse/gstwavparse.c: (gst_wavparse_handle_seek),
(gst_wavparse_stream_headers), (gst_wavparse_stream_data),
(gst_wavparse_loop), (gst_wavparse_srcpad_event):
Various event updates and cleanups.
2005-07-27 18:37:25 +00:00
|
|
|
|
2003-01-20 19:38:37 +00:00
|
|
|
/* since we know the exact byteoffset of the frame,
|
|
|
|
make sure to try bytes first */
|
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
const GstFormat try_all_formats[] = {
|
2003-01-20 19:38:37 +00:00
|
|
|
GST_FORMAT_BYTES,
|
|
|
|
GST_FORMAT_TIME,
|
|
|
|
0
|
|
|
|
};
|
|
|
|
const GstFormat *try_formats = try_all_formats;
|
|
|
|
const GstFormat *peer_formats;
|
|
|
|
|
Various event updates and cleanups.
Original commit message from CVS:
* ext/amrnb/amrnbparse.c: (gst_amrnbparse_event),
(gst_amrnbparse_loop):
* ext/dv/gstdvdec.c: (gst_dvdec_handle_sink_event),
(gst_dvdec_handle_src_event), (gst_dvdec_decode_frame):
* ext/mad/gstid3tag.c: (gst_id3_tag_src_event),
(gst_id3_tag_sink_event), (gst_id3_tag_chain):
* ext/mad/gstmad.c: (gst_mad_src_query), (index_seek),
(normal_seek), (gst_mad_sink_event), (gst_mad_chain):
* ext/mpeg2dec/gstmpeg2dec.c:
* ext/shout2/gstshout2.c: (gst_shout2send_event):
* ext/sidplay/gstsiddec.cc:
* gst/avi/gstavidemux.c: (gst_avi_demux_handle_src_event),
(gst_avi_demux_send_event), (gst_avi_demux_stream_header),
(gst_avi_demux_handle_seek), (gst_avi_demux_process_next_entry):
* gst/goom/gstgoom.c: (gst_goom_event):
* gst/realmedia/rmdemux.c: (gst_rmdemux_sink_event),
(gst_rmdemux_chain), (gst_rmdemux_send_event),
(gst_rmdemux_add_stream):
* gst/wavparse/gstwavparse.c: (gst_wavparse_handle_seek),
(gst_wavparse_stream_headers), (gst_wavparse_stream_data),
(gst_wavparse_loop), (gst_wavparse_srcpad_event):
Various event updates and cleanups.
2005-07-27 18:37:25 +00:00
|
|
|
gst_event_parse_seek (event, &rate, &format, &flags,
|
|
|
|
&cur_type, &cur, &stop_type, &stop);
|
|
|
|
|
2010-09-29 19:24:23 +00:00
|
|
|
if (rate < 0.0)
|
|
|
|
return FALSE;
|
|
|
|
|
2007-07-13 15:46:13 +00:00
|
|
|
if (format == GST_FORMAT_TIME) {
|
|
|
|
gst_segment_set_seek (&mad->segment, rate, format, flags, cur_type,
|
|
|
|
cur, stop_type, stop, NULL);
|
|
|
|
} else {
|
|
|
|
gst_segment_init (&mad->segment, GST_FORMAT_UNDEFINED);
|
|
|
|
}
|
|
|
|
|
ext/mad/gstmad.c: move GstIndexEntry *entry variable declaration before the first instruction
Original commit message from CVS:
* ext/mad/gstmad.c: (index_seek):
move GstIndexEntry *entry variable declaration before
the first instruction
* ext/mad/gstmad.c:
remove debug macros with variable number of parameter by using
GST_DEBUG for WIN32
* gst/dvdsub/gstdvdsubdec.c: (gst_dvd_sub_dec_parse_subpic):
use gst_guint64_to_gdouble for conversions
* gst/mpegstream/gstmpegdemux.c: (gst_mpeg_demux_sync_stream_to_time):
replace __FUNCTION__ which is not supported by MSVC by the current function name
* gst/mpegstream/gstmpegdemux.c: (gst_mpeg_demux_reset):
remove LL suffix by using G_GINT64_CONSTANT
* gst/mpegstream/gstmpegparse.c: (gst_mpeg_parse_parse_packhead),(gst_mpeg_parse_get_rate):
use gst_guint64_to_gdouble for conversions
* gst/mpegstream/gstmpegparse.h:
remove LL suffix by using G_GINT64_CONSTANT
* win32/vs6:
add project files for tagac3parse, asfdemux, dvdlpcmdec, dvdsub, iec958, lame,
mad, mpegaudioparse, mpegstream, realmedia, synaesthesia
2006-04-09 18:09:40 +00:00
|
|
|
entry = gst_index_get_assoc_entry (mad->index, mad->index_id,
|
|
|
|
GST_INDEX_LOOKUP_BEFORE, 0, format, cur);
|
2004-03-14 22:34:30 +00:00
|
|
|
|
2004-04-05 12:28:57 +00:00
|
|
|
GST_DEBUG ("index seek");
|
|
|
|
|
2003-01-20 19:38:37 +00:00
|
|
|
if (!entry)
|
|
|
|
return FALSE;
|
2004-03-14 22:34:30 +00:00
|
|
|
|
2005-05-11 22:42:47 +00:00
|
|
|
#if 0
|
2003-01-20 19:38:37 +00:00
|
|
|
peer_formats = gst_pad_get_formats (GST_PAD_PEER (mad->sinkpad));
|
2005-05-11 22:42:47 +00:00
|
|
|
#else
|
|
|
|
peer_formats = try_all_formats; /* FIXME */
|
|
|
|
#endif
|
2003-01-20 19:38:37 +00:00
|
|
|
|
|
|
|
while (gst_formats_contains (peer_formats, *try_formats)) {
|
|
|
|
gint64 value;
|
2003-08-02 00:56:11 +00:00
|
|
|
GstEvent *seek_event;
|
2004-03-14 22:34:30 +00:00
|
|
|
|
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
|
2004-03-15 19:32:25 +00:00
|
|
|
" -> %s %" G_GINT64_FORMAT,
|
Various event updates and cleanups.
Original commit message from CVS:
* ext/amrnb/amrnbparse.c: (gst_amrnbparse_event),
(gst_amrnbparse_loop):
* ext/dv/gstdvdec.c: (gst_dvdec_handle_sink_event),
(gst_dvdec_handle_src_event), (gst_dvdec_decode_frame):
* ext/mad/gstid3tag.c: (gst_id3_tag_src_event),
(gst_id3_tag_sink_event), (gst_id3_tag_chain):
* ext/mad/gstmad.c: (gst_mad_src_query), (index_seek),
(normal_seek), (gst_mad_sink_event), (gst_mad_chain):
* ext/mpeg2dec/gstmpeg2dec.c:
* ext/shout2/gstshout2.c: (gst_shout2send_event):
* ext/sidplay/gstsiddec.cc:
* gst/avi/gstavidemux.c: (gst_avi_demux_handle_src_event),
(gst_avi_demux_send_event), (gst_avi_demux_stream_header),
(gst_avi_demux_handle_seek), (gst_avi_demux_process_next_entry):
* gst/goom/gstgoom.c: (gst_goom_event):
* gst/realmedia/rmdemux.c: (gst_rmdemux_sink_event),
(gst_rmdemux_chain), (gst_rmdemux_send_event),
(gst_rmdemux_add_stream):
* gst/wavparse/gstwavparse.c: (gst_wavparse_handle_seek),
(gst_wavparse_stream_headers), (gst_wavparse_stream_data),
(gst_wavparse_loop), (gst_wavparse_srcpad_event):
Various event updates and cleanups.
2005-07-27 18:37:25 +00:00
|
|
|
gst_format_get_details (format)->nick,
|
|
|
|
cur, gst_format_get_details (*try_formats)->nick, value);
|
2003-07-25 02:04:01 +00:00
|
|
|
|
Various event updates and cleanups.
Original commit message from CVS:
* ext/amrnb/amrnbparse.c: (gst_amrnbparse_event),
(gst_amrnbparse_loop):
* ext/dv/gstdvdec.c: (gst_dvdec_handle_sink_event),
(gst_dvdec_handle_src_event), (gst_dvdec_decode_frame):
* ext/mad/gstid3tag.c: (gst_id3_tag_src_event),
(gst_id3_tag_sink_event), (gst_id3_tag_chain):
* ext/mad/gstmad.c: (gst_mad_src_query), (index_seek),
(normal_seek), (gst_mad_sink_event), (gst_mad_chain):
* ext/mpeg2dec/gstmpeg2dec.c:
* ext/shout2/gstshout2.c: (gst_shout2send_event):
* ext/sidplay/gstsiddec.cc:
* gst/avi/gstavidemux.c: (gst_avi_demux_handle_src_event),
(gst_avi_demux_send_event), (gst_avi_demux_stream_header),
(gst_avi_demux_handle_seek), (gst_avi_demux_process_next_entry):
* gst/goom/gstgoom.c: (gst_goom_event):
* gst/realmedia/rmdemux.c: (gst_rmdemux_sink_event),
(gst_rmdemux_chain), (gst_rmdemux_send_event),
(gst_rmdemux_add_stream):
* gst/wavparse/gstwavparse.c: (gst_wavparse_handle_seek),
(gst_wavparse_stream_headers), (gst_wavparse_stream_data),
(gst_wavparse_loop), (gst_wavparse_srcpad_event):
Various event updates and cleanups.
2005-07-27 18:37:25 +00:00
|
|
|
seek_event = gst_event_new_seek (rate, *try_formats, flags,
|
|
|
|
cur_type, value, stop_type, stop);
|
2003-01-20 19:38:37 +00:00
|
|
|
|
|
|
|
if (gst_pad_send_event (GST_PAD_PEER (mad->sinkpad), seek_event)) {
|
2004-03-15 19:32:25 +00:00
|
|
|
/* seek worked, we're done, loop will exit */
|
|
|
|
mad->restart = TRUE;
|
Various event updates and cleanups.
Original commit message from CVS:
* ext/amrnb/amrnbparse.c: (gst_amrnbparse_event),
(gst_amrnbparse_loop):
* ext/dv/gstdvdec.c: (gst_dvdec_handle_sink_event),
(gst_dvdec_handle_src_event), (gst_dvdec_decode_frame):
* ext/mad/gstid3tag.c: (gst_id3_tag_src_event),
(gst_id3_tag_sink_event), (gst_id3_tag_chain):
* ext/mad/gstmad.c: (gst_mad_src_query), (index_seek),
(normal_seek), (gst_mad_sink_event), (gst_mad_chain):
* ext/mpeg2dec/gstmpeg2dec.c:
* ext/shout2/gstshout2.c: (gst_shout2send_event):
* ext/sidplay/gstsiddec.cc:
* gst/avi/gstavidemux.c: (gst_avi_demux_handle_src_event),
(gst_avi_demux_send_event), (gst_avi_demux_stream_header),
(gst_avi_demux_handle_seek), (gst_avi_demux_process_next_entry):
* gst/goom/gstgoom.c: (gst_goom_event):
* gst/realmedia/rmdemux.c: (gst_rmdemux_sink_event),
(gst_rmdemux_chain), (gst_rmdemux_send_event),
(gst_rmdemux_add_stream):
* gst/wavparse/gstwavparse.c: (gst_wavparse_handle_seek),
(gst_wavparse_stream_headers), (gst_wavparse_stream_data),
(gst_wavparse_loop), (gst_wavparse_srcpad_event):
Various event updates and cleanups.
2005-07-27 18:37:25 +00:00
|
|
|
g_assert (format == GST_FORMAT_TIME);
|
|
|
|
mad->segment_start = cur;
|
2004-03-15 19:32:25 +00:00
|
|
|
return TRUE;
|
2003-01-20 19:38:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
try_formats++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2004-03-14 22:34:30 +00:00
|
|
|
normal_seek (GstMad * mad, GstPad * pad, GstEvent * event)
|
2003-01-20 19:38:37 +00:00
|
|
|
{
|
Various event updates and cleanups.
Original commit message from CVS:
* ext/amrnb/amrnbparse.c: (gst_amrnbparse_event),
(gst_amrnbparse_loop):
* ext/dv/gstdvdec.c: (gst_dvdec_handle_sink_event),
(gst_dvdec_handle_src_event), (gst_dvdec_decode_frame):
* ext/mad/gstid3tag.c: (gst_id3_tag_src_event),
(gst_id3_tag_sink_event), (gst_id3_tag_chain):
* ext/mad/gstmad.c: (gst_mad_src_query), (index_seek),
(normal_seek), (gst_mad_sink_event), (gst_mad_chain):
* ext/mpeg2dec/gstmpeg2dec.c:
* ext/shout2/gstshout2.c: (gst_shout2send_event):
* ext/sidplay/gstsiddec.cc:
* gst/avi/gstavidemux.c: (gst_avi_demux_handle_src_event),
(gst_avi_demux_send_event), (gst_avi_demux_stream_header),
(gst_avi_demux_handle_seek), (gst_avi_demux_process_next_entry):
* gst/goom/gstgoom.c: (gst_goom_event):
* gst/realmedia/rmdemux.c: (gst_rmdemux_sink_event),
(gst_rmdemux_chain), (gst_rmdemux_send_event),
(gst_rmdemux_add_stream):
* gst/wavparse/gstwavparse.c: (gst_wavparse_handle_seek),
(gst_wavparse_stream_headers), (gst_wavparse_stream_data),
(gst_wavparse_loop), (gst_wavparse_srcpad_event):
Various event updates and cleanups.
2005-07-27 18:37:25 +00:00
|
|
|
gdouble rate;
|
|
|
|
GstFormat format, conv;
|
|
|
|
GstSeekFlags flags;
|
|
|
|
GstSeekType cur_type, stop_type;
|
|
|
|
gint64 cur, stop;
|
|
|
|
gint64 time_cur, time_stop;
|
|
|
|
gint64 bytes_cur, bytes_stop;
|
2005-11-22 17:39:36 +00:00
|
|
|
gboolean flush;
|
2005-05-11 22:42:47 +00:00
|
|
|
|
|
|
|
/* const GstFormat *peer_formats; */
|
2003-01-20 19:38:37 +00:00
|
|
|
gboolean res;
|
2004-03-14 22:34:30 +00:00
|
|
|
|
2004-04-05 12:28:57 +00:00
|
|
|
GST_DEBUG ("normal seek");
|
|
|
|
|
Various event updates and cleanups.
Original commit message from CVS:
* ext/amrnb/amrnbparse.c: (gst_amrnbparse_event),
(gst_amrnbparse_loop):
* ext/dv/gstdvdec.c: (gst_dvdec_handle_sink_event),
(gst_dvdec_handle_src_event), (gst_dvdec_decode_frame):
* ext/mad/gstid3tag.c: (gst_id3_tag_src_event),
(gst_id3_tag_sink_event), (gst_id3_tag_chain):
* ext/mad/gstmad.c: (gst_mad_src_query), (index_seek),
(normal_seek), (gst_mad_sink_event), (gst_mad_chain):
* ext/mpeg2dec/gstmpeg2dec.c:
* ext/shout2/gstshout2.c: (gst_shout2send_event):
* ext/sidplay/gstsiddec.cc:
* gst/avi/gstavidemux.c: (gst_avi_demux_handle_src_event),
(gst_avi_demux_send_event), (gst_avi_demux_stream_header),
(gst_avi_demux_handle_seek), (gst_avi_demux_process_next_entry):
* gst/goom/gstgoom.c: (gst_goom_event):
* gst/realmedia/rmdemux.c: (gst_rmdemux_sink_event),
(gst_rmdemux_chain), (gst_rmdemux_send_event),
(gst_rmdemux_add_stream):
* gst/wavparse/gstwavparse.c: (gst_wavparse_handle_seek),
(gst_wavparse_stream_headers), (gst_wavparse_stream_data),
(gst_wavparse_loop), (gst_wavparse_srcpad_event):
Various event updates and cleanups.
2005-07-27 18:37:25 +00:00
|
|
|
gst_event_parse_seek (event, &rate, &format, &flags,
|
|
|
|
&cur_type, &cur, &stop_type, &stop);
|
|
|
|
|
2010-09-29 19:24:23 +00:00
|
|
|
if (rate < 0.0)
|
|
|
|
return FALSE;
|
|
|
|
|
Various event updates and cleanups.
Original commit message from CVS:
* ext/amrnb/amrnbparse.c: (gst_amrnbparse_event),
(gst_amrnbparse_loop):
* ext/dv/gstdvdec.c: (gst_dvdec_handle_sink_event),
(gst_dvdec_handle_src_event), (gst_dvdec_decode_frame):
* ext/mad/gstid3tag.c: (gst_id3_tag_src_event),
(gst_id3_tag_sink_event), (gst_id3_tag_chain):
* ext/mad/gstmad.c: (gst_mad_src_query), (index_seek),
(normal_seek), (gst_mad_sink_event), (gst_mad_chain):
* ext/mpeg2dec/gstmpeg2dec.c:
* ext/shout2/gstshout2.c: (gst_shout2send_event):
* ext/sidplay/gstsiddec.cc:
* gst/avi/gstavidemux.c: (gst_avi_demux_handle_src_event),
(gst_avi_demux_send_event), (gst_avi_demux_stream_header),
(gst_avi_demux_handle_seek), (gst_avi_demux_process_next_entry):
* gst/goom/gstgoom.c: (gst_goom_event):
* gst/realmedia/rmdemux.c: (gst_rmdemux_sink_event),
(gst_rmdemux_chain), (gst_rmdemux_send_event),
(gst_rmdemux_add_stream):
* gst/wavparse/gstwavparse.c: (gst_wavparse_handle_seek),
(gst_wavparse_stream_headers), (gst_wavparse_stream_data),
(gst_wavparse_loop), (gst_wavparse_srcpad_event):
Various event updates and cleanups.
2005-07-27 18:37:25 +00:00
|
|
|
if (format != GST_FORMAT_TIME) {
|
|
|
|
conv = GST_FORMAT_TIME;
|
|
|
|
if (!gst_mad_convert_src (pad, format, cur, &conv, &time_cur))
|
|
|
|
goto convert_error;
|
|
|
|
if (!gst_mad_convert_src (pad, format, stop, &conv, &time_stop))
|
|
|
|
goto convert_error;
|
2005-05-11 22:42:47 +00:00
|
|
|
} else {
|
Various event updates and cleanups.
Original commit message from CVS:
* ext/amrnb/amrnbparse.c: (gst_amrnbparse_event),
(gst_amrnbparse_loop):
* ext/dv/gstdvdec.c: (gst_dvdec_handle_sink_event),
(gst_dvdec_handle_src_event), (gst_dvdec_decode_frame):
* ext/mad/gstid3tag.c: (gst_id3_tag_src_event),
(gst_id3_tag_sink_event), (gst_id3_tag_chain):
* ext/mad/gstmad.c: (gst_mad_src_query), (index_seek),
(normal_seek), (gst_mad_sink_event), (gst_mad_chain):
* ext/mpeg2dec/gstmpeg2dec.c:
* ext/shout2/gstshout2.c: (gst_shout2send_event):
* ext/sidplay/gstsiddec.cc:
* gst/avi/gstavidemux.c: (gst_avi_demux_handle_src_event),
(gst_avi_demux_send_event), (gst_avi_demux_stream_header),
(gst_avi_demux_handle_seek), (gst_avi_demux_process_next_entry):
* gst/goom/gstgoom.c: (gst_goom_event):
* gst/realmedia/rmdemux.c: (gst_rmdemux_sink_event),
(gst_rmdemux_chain), (gst_rmdemux_send_event),
(gst_rmdemux_add_stream):
* gst/wavparse/gstwavparse.c: (gst_wavparse_handle_seek),
(gst_wavparse_stream_headers), (gst_wavparse_stream_data),
(gst_wavparse_loop), (gst_wavparse_srcpad_event):
Various event updates and cleanups.
2005-07-27 18:37:25 +00:00
|
|
|
time_cur = cur;
|
|
|
|
time_stop = stop;
|
2003-05-29 09:12:17 +00:00
|
|
|
}
|
2004-03-14 22:34:30 +00:00
|
|
|
|
2007-07-13 15:46:13 +00:00
|
|
|
gst_segment_set_seek (&mad->segment, rate, GST_FORMAT_TIME, flags, cur_type,
|
|
|
|
time_cur, stop_type, time_stop, NULL);
|
|
|
|
|
Various event updates and cleanups.
Original commit message from CVS:
* ext/amrnb/amrnbparse.c: (gst_amrnbparse_event),
(gst_amrnbparse_loop):
* ext/dv/gstdvdec.c: (gst_dvdec_handle_sink_event),
(gst_dvdec_handle_src_event), (gst_dvdec_decode_frame):
* ext/mad/gstid3tag.c: (gst_id3_tag_src_event),
(gst_id3_tag_sink_event), (gst_id3_tag_chain):
* ext/mad/gstmad.c: (gst_mad_src_query), (index_seek),
(normal_seek), (gst_mad_sink_event), (gst_mad_chain):
* ext/mpeg2dec/gstmpeg2dec.c:
* ext/shout2/gstshout2.c: (gst_shout2send_event):
* ext/sidplay/gstsiddec.cc:
* gst/avi/gstavidemux.c: (gst_avi_demux_handle_src_event),
(gst_avi_demux_send_event), (gst_avi_demux_stream_header),
(gst_avi_demux_handle_seek), (gst_avi_demux_process_next_entry):
* gst/goom/gstgoom.c: (gst_goom_event):
* gst/realmedia/rmdemux.c: (gst_rmdemux_sink_event),
(gst_rmdemux_chain), (gst_rmdemux_send_event),
(gst_rmdemux_add_stream):
* gst/wavparse/gstwavparse.c: (gst_wavparse_handle_seek),
(gst_wavparse_stream_headers), (gst_wavparse_stream_data),
(gst_wavparse_loop), (gst_wavparse_srcpad_event):
Various event updates and cleanups.
2005-07-27 18:37:25 +00:00
|
|
|
GST_DEBUG ("seek to time %" GST_TIME_FORMAT "-%" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (time_cur), GST_TIME_ARGS (time_stop));
|
2005-05-11 22:42:47 +00:00
|
|
|
|
2003-01-20 19:38:37 +00:00
|
|
|
/* shave off the flush flag, we'll need it later */
|
2005-11-22 17:39:36 +00:00
|
|
|
flush = ((flags & GST_SEEK_FLAG_FLUSH) != 0);
|
2004-03-14 22:34:30 +00:00
|
|
|
|
Various event updates and cleanups.
Original commit message from CVS:
* ext/amrnb/amrnbparse.c: (gst_amrnbparse_event),
(gst_amrnbparse_loop):
* ext/dv/gstdvdec.c: (gst_dvdec_handle_sink_event),
(gst_dvdec_handle_src_event), (gst_dvdec_decode_frame):
* ext/mad/gstid3tag.c: (gst_id3_tag_src_event),
(gst_id3_tag_sink_event), (gst_id3_tag_chain):
* ext/mad/gstmad.c: (gst_mad_src_query), (index_seek),
(normal_seek), (gst_mad_sink_event), (gst_mad_chain):
* ext/mpeg2dec/gstmpeg2dec.c:
* ext/shout2/gstshout2.c: (gst_shout2send_event):
* ext/sidplay/gstsiddec.cc:
* gst/avi/gstavidemux.c: (gst_avi_demux_handle_src_event),
(gst_avi_demux_send_event), (gst_avi_demux_stream_header),
(gst_avi_demux_handle_seek), (gst_avi_demux_process_next_entry):
* gst/goom/gstgoom.c: (gst_goom_event):
* gst/realmedia/rmdemux.c: (gst_rmdemux_sink_event),
(gst_rmdemux_chain), (gst_rmdemux_send_event),
(gst_rmdemux_add_stream):
* gst/wavparse/gstwavparse.c: (gst_wavparse_handle_seek),
(gst_wavparse_stream_headers), (gst_wavparse_stream_data),
(gst_wavparse_loop), (gst_wavparse_srcpad_event):
Various event updates and cleanups.
2005-07-27 18:37:25 +00:00
|
|
|
conv = GST_FORMAT_BYTES;
|
|
|
|
if (!gst_mad_convert_sink (pad, GST_FORMAT_TIME, time_cur, &conv, &bytes_cur))
|
|
|
|
goto convert_error;
|
|
|
|
if (!gst_mad_convert_sink (pad, GST_FORMAT_TIME, time_stop, &conv,
|
|
|
|
&bytes_stop))
|
|
|
|
goto convert_error;
|
|
|
|
|
|
|
|
{
|
2005-05-11 22:42:47 +00:00
|
|
|
GstEvent *seek_event;
|
2004-03-14 22:34:30 +00:00
|
|
|
|
2005-05-11 22:42:47 +00:00
|
|
|
/* conversion succeeded, create the seek */
|
|
|
|
seek_event =
|
Various event updates and cleanups.
Original commit message from CVS:
* ext/amrnb/amrnbparse.c: (gst_amrnbparse_event),
(gst_amrnbparse_loop):
* ext/dv/gstdvdec.c: (gst_dvdec_handle_sink_event),
(gst_dvdec_handle_src_event), (gst_dvdec_decode_frame):
* ext/mad/gstid3tag.c: (gst_id3_tag_src_event),
(gst_id3_tag_sink_event), (gst_id3_tag_chain):
* ext/mad/gstmad.c: (gst_mad_src_query), (index_seek),
(normal_seek), (gst_mad_sink_event), (gst_mad_chain):
* ext/mpeg2dec/gstmpeg2dec.c:
* ext/shout2/gstshout2.c: (gst_shout2send_event):
* ext/sidplay/gstsiddec.cc:
* gst/avi/gstavidemux.c: (gst_avi_demux_handle_src_event),
(gst_avi_demux_send_event), (gst_avi_demux_stream_header),
(gst_avi_demux_handle_seek), (gst_avi_demux_process_next_entry):
* gst/goom/gstgoom.c: (gst_goom_event):
* gst/realmedia/rmdemux.c: (gst_rmdemux_sink_event),
(gst_rmdemux_chain), (gst_rmdemux_send_event),
(gst_rmdemux_add_stream):
* gst/wavparse/gstwavparse.c: (gst_wavparse_handle_seek),
(gst_wavparse_stream_headers), (gst_wavparse_stream_data),
(gst_wavparse_loop), (gst_wavparse_srcpad_event):
Various event updates and cleanups.
2005-07-27 18:37:25 +00:00
|
|
|
gst_event_new_seek (rate, GST_FORMAT_BYTES, flags, cur_type,
|
|
|
|
bytes_cur, stop_type, bytes_stop);
|
2005-05-11 22:42:47 +00:00
|
|
|
|
|
|
|
/* do the seek */
|
Various event updates and cleanups.
Original commit message from CVS:
* ext/amrnb/amrnbparse.c: (gst_amrnbparse_event),
(gst_amrnbparse_loop):
* ext/dv/gstdvdec.c: (gst_dvdec_handle_sink_event),
(gst_dvdec_handle_src_event), (gst_dvdec_decode_frame):
* ext/mad/gstid3tag.c: (gst_id3_tag_src_event),
(gst_id3_tag_sink_event), (gst_id3_tag_chain):
* ext/mad/gstmad.c: (gst_mad_src_query), (index_seek),
(normal_seek), (gst_mad_sink_event), (gst_mad_chain):
* ext/mpeg2dec/gstmpeg2dec.c:
* ext/shout2/gstshout2.c: (gst_shout2send_event):
* ext/sidplay/gstsiddec.cc:
* gst/avi/gstavidemux.c: (gst_avi_demux_handle_src_event),
(gst_avi_demux_send_event), (gst_avi_demux_stream_header),
(gst_avi_demux_handle_seek), (gst_avi_demux_process_next_entry):
* gst/goom/gstgoom.c: (gst_goom_event):
* gst/realmedia/rmdemux.c: (gst_rmdemux_sink_event),
(gst_rmdemux_chain), (gst_rmdemux_send_event),
(gst_rmdemux_add_stream):
* gst/wavparse/gstwavparse.c: (gst_wavparse_handle_seek),
(gst_wavparse_stream_headers), (gst_wavparse_stream_data),
(gst_wavparse_loop), (gst_wavparse_srcpad_event):
Various event updates and cleanups.
2005-07-27 18:37:25 +00:00
|
|
|
res = gst_pad_push_event (mad->sinkpad, seek_event);
|
2005-11-22 17:39:36 +00:00
|
|
|
|
|
|
|
if (res) {
|
|
|
|
/* we need to break out of the processing loop on flush */
|
|
|
|
mad->restart = flush;
|
|
|
|
mad->segment_start = time_cur;
|
|
|
|
mad->last_ts = time_cur;
|
|
|
|
}
|
2005-05-11 22:42:47 +00:00
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
peer_formats = gst_pad_get_formats (GST_PAD_PEER (mad->sinkpad));
|
2003-01-20 19:38:37 +00:00
|
|
|
/* while we did not exhaust our seek formats without result */
|
|
|
|
while (peer_formats && *peer_formats && !res) {
|
|
|
|
gint64 desired_offset;
|
2004-03-14 22:34:30 +00:00
|
|
|
|
2003-01-20 19:38:37 +00:00
|
|
|
format = *peer_formats;
|
2004-03-14 22:34:30 +00:00
|
|
|
|
2003-01-20 19:38:37 +00:00
|
|
|
/* 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,
|
2004-03-15 19:32:25 +00:00
|
|
|
&format, &desired_offset)) {
|
2004-03-14 22:34:30 +00:00
|
|
|
GstEvent *seek_event;
|
|
|
|
|
|
|
|
/* conversion succeeded, create the seek */
|
2004-07-11 19:27:43 +00:00
|
|
|
seek_event =
|
|
|
|
gst_event_new_seek (format | GST_EVENT_SEEK_METHOD (event) | flush,
|
2004-03-15 19:32:25 +00:00
|
|
|
desired_offset);
|
2004-03-14 22:34:30 +00:00
|
|
|
/* do the seek */
|
|
|
|
if (gst_pad_send_event (GST_PAD_PEER (mad->sinkpad), seek_event)) {
|
2004-03-15 19:32:25 +00:00
|
|
|
/* seek worked, we're done, loop will exit */
|
|
|
|
res = TRUE;
|
2003-01-20 19:38:37 +00:00
|
|
|
}
|
2004-03-14 22:34:30 +00:00
|
|
|
}
|
2003-01-20 19:38:37 +00:00
|
|
|
/* 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;
|
2004-03-14 22:34:30 +00:00
|
|
|
|
2003-01-20 19:38:37 +00:00
|
|
|
peer_formats++;
|
|
|
|
}
|
2005-05-11 22:42:47 +00:00
|
|
|
#endif
|
2003-01-20 19:38:37 +00:00
|
|
|
|
|
|
|
return res;
|
Various event updates and cleanups.
Original commit message from CVS:
* ext/amrnb/amrnbparse.c: (gst_amrnbparse_event),
(gst_amrnbparse_loop):
* ext/dv/gstdvdec.c: (gst_dvdec_handle_sink_event),
(gst_dvdec_handle_src_event), (gst_dvdec_decode_frame):
* ext/mad/gstid3tag.c: (gst_id3_tag_src_event),
(gst_id3_tag_sink_event), (gst_id3_tag_chain):
* ext/mad/gstmad.c: (gst_mad_src_query), (index_seek),
(normal_seek), (gst_mad_sink_event), (gst_mad_chain):
* ext/mpeg2dec/gstmpeg2dec.c:
* ext/shout2/gstshout2.c: (gst_shout2send_event):
* ext/sidplay/gstsiddec.cc:
* gst/avi/gstavidemux.c: (gst_avi_demux_handle_src_event),
(gst_avi_demux_send_event), (gst_avi_demux_stream_header),
(gst_avi_demux_handle_seek), (gst_avi_demux_process_next_entry):
* gst/goom/gstgoom.c: (gst_goom_event):
* gst/realmedia/rmdemux.c: (gst_rmdemux_sink_event),
(gst_rmdemux_chain), (gst_rmdemux_send_event),
(gst_rmdemux_add_stream):
* gst/wavparse/gstwavparse.c: (gst_wavparse_handle_seek),
(gst_wavparse_stream_headers), (gst_wavparse_stream_data),
(gst_wavparse_loop), (gst_wavparse_srcpad_event):
Various event updates and cleanups.
2005-07-27 18:37:25 +00:00
|
|
|
|
|
|
|
/* ERRORS */
|
|
|
|
convert_error:
|
|
|
|
{
|
|
|
|
/* probably unsupported seek format */
|
|
|
|
GST_DEBUG ("failed to convert format %u into GST_FORMAT_TIME", format);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2003-01-20 19:38:37 +00:00
|
|
|
}
|
|
|
|
|
2002-03-30 17:06:26 +00:00
|
|
|
static gboolean
|
2004-03-14 22:34:30 +00:00
|
|
|
gst_mad_src_event (GstPad * pad, GstEvent * event)
|
2002-03-30 17:06:26 +00:00
|
|
|
{
|
|
|
|
gboolean res = TRUE;
|
|
|
|
GstMad *mad;
|
2003-01-08 16:11:48 +00:00
|
|
|
|
2005-05-06 11:04:30 +00:00
|
|
|
mad = GST_MAD (GST_PAD_PARENT (pad));
|
2002-03-30 17:06:26 +00:00
|
|
|
|
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
|
|
|
case GST_EVENT_SEEK:
|
2008-10-08 13:59:57 +00:00
|
|
|
/* the all-formats seek logic, ref the event, we need it later */
|
2005-07-22 08:53:19 +00:00
|
|
|
gst_event_ref (event);
|
2008-10-08 13:59:57 +00:00
|
|
|
if (!(res = gst_pad_push_event (mad->sinkpad, event))) {
|
2005-07-22 08:53:19 +00:00
|
|
|
if (mad->index)
|
|
|
|
res = index_seek (mad, pad, event);
|
|
|
|
else
|
|
|
|
res = normal_seek (mad, pad, event);
|
|
|
|
}
|
2008-10-08 13:59:57 +00:00
|
|
|
gst_event_unref (event);
|
2002-03-30 17:06:26 +00:00
|
|
|
break;
|
|
|
|
default:
|
2008-10-08 13:59:57 +00:00
|
|
|
res = gst_pad_push_event (mad->sinkpad, event);
|
2002-03-30 17:06:26 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2006-01-31 22:03:30 +00:00
|
|
|
static inline gint32
|
2001-12-20 22:10:54 +00:00
|
|
|
scale (mad_fixed_t sample)
|
|
|
|
{
|
2006-01-31 22:03:30 +00:00
|
|
|
#if MAD_F_FRACBITS < 28
|
2001-12-20 22:10:54 +00:00
|
|
|
/* round */
|
2006-01-31 22:03:30 +00:00
|
|
|
sample += (1L << (28 - MAD_F_FRACBITS - 1));
|
|
|
|
#endif
|
2001-12-20 22:10:54 +00:00
|
|
|
|
|
|
|
/* clip */
|
|
|
|
if (sample >= MAD_F_ONE)
|
|
|
|
sample = MAD_F_ONE - 1;
|
|
|
|
else if (sample < -MAD_F_ONE)
|
|
|
|
sample = -MAD_F_ONE;
|
|
|
|
|
2006-01-31 22:03:30 +00:00
|
|
|
#if MAD_F_FRACBITS < 28
|
2001-12-20 22:10:54 +00:00
|
|
|
/* quantize */
|
2006-01-31 22:03:30 +00:00
|
|
|
sample >>= (28 - MAD_F_FRACBITS);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* convert from 29 bits to 32 bits */
|
|
|
|
return (gint32) (sample << 3);
|
2001-12-20 22:10:54 +00:00
|
|
|
}
|
|
|
|
|
2002-02-06 18:10:35 +00:00
|
|
|
/* do we need this function? */
|
|
|
|
static void
|
2004-03-14 22:34:30 +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
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2008-09-28 17:31:37 +00:00
|
|
|
|
2002-02-06 18:10:35 +00:00
|
|
|
static void
|
2004-03-14 22:34:30 +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
|
|
|
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
|
2004-03-14 22:34:30 +00:00
|
|
|
gst_mad_update_info (GstMad * mad)
|
2001-12-20 22:27:35 +00:00
|
|
|
{
|
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
|
|
|
|
2005-12-06 19:48:07 +00:00
|
|
|
#define CHECK_HEADER(h1,str) \
|
|
|
|
G_STMT_START{ \
|
|
|
|
if (mad->header.h1 != header->h1 || mad->new_header) { \
|
|
|
|
mad->header.h1 = header->h1; \
|
|
|
|
changed = TRUE; \
|
|
|
|
}; \
|
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;
|
|
|
|
} else {
|
|
|
|
mad->framecount++;
|
|
|
|
mad->vbr_rate += header->bitrate;
|
|
|
|
}
|
|
|
|
mad->vbr_average = (gint) (mad->vbr_rate / mad->framecount);
|
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
CHECK_HEADER (layer, "layer");
|
|
|
|
CHECK_HEADER (mode, "mode");
|
|
|
|
CHECK_HEADER (emphasis, "emphasis");
|
ext/mad/gstmad.c: Port fixes for bugs 314771, 308772, 140237, and 302625
Original commit message from CVS:
* ext/mad/gstmad.c: (gst_mad_init), (scale), (gst_mad_update_info),
(gst_mad_sink_event), (gst_mad_check_caps_reset), (gst_mad_chain),
(gst_mad_change_state):
Port fixes for bugs 314771, 308772, 140237, and 302625
from 0.8 (Patch by Jonathan Matthew, Fixes #329575)
Use GST_EVENT_FLUSH_STOP to clear data from the current input
buffer, to avoid using it for any future decoding.
2006-02-16 09:50:43 +00:00
|
|
|
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
|
|
|
|
2004-03-06 18:39:39 +00:00
|
|
|
if (changed) {
|
|
|
|
GstTagList *list;
|
|
|
|
GEnumValue *mode;
|
|
|
|
GEnumValue *emphasis;
|
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
mode =
|
2008-01-10 17:24:09 +00:00
|
|
|
g_enum_get_value (g_type_class_peek (GST_TYPE_MAD_MODE),
|
2004-03-15 19:32:25 +00:00
|
|
|
mad->header.mode);
|
2004-03-14 22:34:30 +00:00
|
|
|
emphasis =
|
2008-01-10 17:24:09 +00:00
|
|
|
g_enum_get_value (g_type_class_peek (GST_TYPE_MAD_EMPHASIS),
|
2004-03-15 19:32:25 +00:00
|
|
|
mad->header.emphasis);
|
2004-03-06 18:39:39 +00:00
|
|
|
list = gst_tag_list_new ();
|
|
|
|
gst_tag_list_add (list, GST_TAG_MERGE_REPLACE,
|
2004-03-15 19:32:25 +00:00
|
|
|
GST_TAG_LAYER, mad->header.layer,
|
|
|
|
GST_TAG_MODE, mode->value_nick,
|
|
|
|
GST_TAG_EMPHASIS, emphasis->value_nick, NULL);
|
2006-03-14 19:41:17 +00:00
|
|
|
if (!mad->framed) {
|
|
|
|
gchar *str;
|
|
|
|
|
|
|
|
str = g_strdup_printf ("MPEG-1 layer %d", mad->header.layer);
|
|
|
|
gst_tag_list_add (list, GST_TAG_MERGE_REPLACE,
|
|
|
|
GST_TAG_AUDIO_CODEC, str, NULL);
|
|
|
|
g_free (str);
|
|
|
|
}
|
ext/mad/gstmad.c: Port fixes for bugs 314771, 308772, 140237, and 302625
Original commit message from CVS:
* ext/mad/gstmad.c: (gst_mad_init), (scale), (gst_mad_update_info),
(gst_mad_sink_event), (gst_mad_check_caps_reset), (gst_mad_chain),
(gst_mad_change_state):
Port fixes for bugs 314771, 308772, 140237, and 302625
from 0.8 (Patch by Jonathan Matthew, Fixes #329575)
Use GST_EVENT_FLUSH_STOP to clear data from the current input
buffer, to avoid using it for any future decoding.
2006-02-16 09:50:43 +00:00
|
|
|
if (!mad->xing_found) {
|
|
|
|
gst_tag_list_add (list, GST_TAG_MERGE_REPLACE,
|
|
|
|
GST_TAG_BITRATE, mad->header.bitrate, NULL);
|
|
|
|
}
|
2005-05-06 11:04:30 +00:00
|
|
|
gst_element_post_message (GST_ELEMENT (mad),
|
|
|
|
gst_message_new_tag (GST_OBJECT (mad), list));
|
2004-03-06 18:39:39 +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
|
|
|
}
|
|
|
|
|
2005-05-06 11:04:30 +00:00
|
|
|
static gboolean
|
|
|
|
gst_mad_sink_event (GstPad * pad, GstEvent * event)
|
2002-12-11 21:57:39 +00:00
|
|
|
{
|
2005-05-06 11:04:30 +00:00
|
|
|
GstMad *mad = GST_MAD (GST_PAD_PARENT (pad));
|
2005-07-16 16:43:53 +00:00
|
|
|
gboolean result;
|
2002-12-11 21:57:39 +00:00
|
|
|
|
2005-11-22 17:39:36 +00:00
|
|
|
GST_DEBUG ("handling %s event", GST_EVENT_TYPE_NAME (event));
|
2005-07-16 16:43:53 +00:00
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
switch (GST_EVENT_TYPE (event)) {
|
2005-11-22 17:39:36 +00:00
|
|
|
case GST_EVENT_NEWSEGMENT:{
|
|
|
|
GstFormat format;
|
2007-07-13 15:46:13 +00:00
|
|
|
gboolean update;
|
|
|
|
gdouble rate, applied_rate;
|
|
|
|
gint64 start, stop, pos;
|
2005-11-22 17:39:36 +00:00
|
|
|
|
2007-07-13 15:46:13 +00:00
|
|
|
gst_event_parse_new_segment_full (event, &update, &rate, &applied_rate,
|
|
|
|
&format, &start, &stop, &pos);
|
2005-11-22 17:39:36 +00:00
|
|
|
|
|
|
|
if (format == GST_FORMAT_TIME) {
|
|
|
|
/* FIXME: is this really correct? */
|
|
|
|
mad->tempsize = 0;
|
|
|
|
result = gst_pad_push_event (mad->srcpad, event);
|
|
|
|
/* we don't need to restart when we get here */
|
|
|
|
mad->restart = FALSE;
|
2006-03-14 19:41:17 +00:00
|
|
|
mad->framed = TRUE;
|
2007-07-13 15:46:13 +00:00
|
|
|
gst_segment_set_newsegment_full (&mad->segment, update, rate,
|
|
|
|
applied_rate, GST_FORMAT_TIME, start, stop, pos);
|
2005-11-22 17:39:36 +00:00
|
|
|
} else {
|
|
|
|
GST_DEBUG ("dropping newsegment event in format %s",
|
|
|
|
gst_format_get_name (format));
|
|
|
|
/* on restart the chain function will generate a new
|
|
|
|
* newsegment event, so we can just drop this one */
|
|
|
|
mad->restart = TRUE;
|
|
|
|
gst_event_unref (event);
|
|
|
|
mad->tempsize = 0;
|
2006-03-14 19:41:17 +00:00
|
|
|
mad->framed = FALSE;
|
2005-11-22 17:39:36 +00:00
|
|
|
result = TRUE;
|
|
|
|
}
|
2002-12-11 21:57:39 +00:00
|
|
|
break;
|
2005-11-22 17:39:36 +00:00
|
|
|
}
|
2004-04-07 15:48:40 +00:00
|
|
|
case GST_EVENT_EOS:
|
2010-09-29 19:24:23 +00:00
|
|
|
if (mad->segment.rate < 0.0)
|
|
|
|
gst_mad_chain_reverse (mad, NULL);
|
2004-04-07 15:48:40 +00:00
|
|
|
mad->caps_set = FALSE; /* could be a new stream */
|
2005-07-16 16:43:53 +00:00
|
|
|
result = gst_pad_push_event (mad->srcpad, event);
|
ext/mad/gstmad.c: Port fixes for bugs 314771, 308772, 140237, and 302625
Original commit message from CVS:
* ext/mad/gstmad.c: (gst_mad_init), (scale), (gst_mad_update_info),
(gst_mad_sink_event), (gst_mad_check_caps_reset), (gst_mad_chain),
(gst_mad_change_state):
Port fixes for bugs 314771, 308772, 140237, and 302625
from 0.8 (Patch by Jonathan Matthew, Fixes #329575)
Use GST_EVENT_FLUSH_STOP to clear data from the current input
buffer, to avoid using it for any future decoding.
2006-02-16 09:50:43 +00:00
|
|
|
break;
|
|
|
|
case GST_EVENT_FLUSH_STOP:
|
|
|
|
/* Clear any stored data, as it won't make sense once
|
|
|
|
* the new data arrives */
|
|
|
|
mad->tempsize = 0;
|
|
|
|
mad_frame_mute (&mad->frame);
|
|
|
|
mad_synth_mute (&mad->synth);
|
2010-09-29 19:24:23 +00:00
|
|
|
gst_mad_clear_queues (mad);
|
|
|
|
/* fall-through */
|
2008-05-10 00:44:00 +00:00
|
|
|
case GST_EVENT_FLUSH_START:
|
ext/mad/gstmad.c: Port fixes for bugs 314771, 308772, 140237, and 302625
Original commit message from CVS:
* ext/mad/gstmad.c: (gst_mad_init), (scale), (gst_mad_update_info),
(gst_mad_sink_event), (gst_mad_check_caps_reset), (gst_mad_chain),
(gst_mad_change_state):
Port fixes for bugs 314771, 308772, 140237, and 302625
from 0.8 (Patch by Jonathan Matthew, Fixes #329575)
Use GST_EVENT_FLUSH_STOP to clear data from the current input
buffer, to avoid using it for any future decoding.
2006-02-16 09:50:43 +00:00
|
|
|
result = gst_pad_event_default (pad, event);
|
2004-04-07 15:48:40 +00:00
|
|
|
break;
|
2002-12-11 21:57:39 +00:00
|
|
|
default:
|
2008-02-27 13:18:57 +00:00
|
|
|
if (mad->restart) {
|
2008-02-27 15:23:51 +00:00
|
|
|
/* Cache all other events if we still have to send a NEWSEGMENT */
|
|
|
|
mad->pending_events = g_list_append (mad->pending_events, event);
|
2008-02-27 13:18:57 +00:00
|
|
|
result = TRUE;
|
|
|
|
} else {
|
|
|
|
result = gst_pad_event_default (pad, event);
|
|
|
|
}
|
2002-12-11 21:57:39 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-11-22 17:39:36 +00:00
|
|
|
return result;
|
2002-12-11 21:57:39 +00:00
|
|
|
}
|
|
|
|
|
2003-01-20 19:38:37 +00:00
|
|
|
static gboolean
|
2004-03-14 22:34:30 +00:00
|
|
|
gst_mad_check_restart (GstMad * mad)
|
2003-01-20 19:38:37 +00:00
|
|
|
{
|
|
|
|
gboolean yes = mad->restart;
|
2004-03-14 22:34:30 +00:00
|
|
|
|
2003-01-20 19:38:37 +00:00
|
|
|
if (mad->restart) {
|
|
|
|
mad->restart = FALSE;
|
|
|
|
mad->tempsize = 0;
|
|
|
|
}
|
|
|
|
return yes;
|
|
|
|
}
|
|
|
|
|
2004-03-05 23:32:36 +00:00
|
|
|
|
2011-02-17 16:06:51 +00:00
|
|
|
/* The following code has been taken from
|
2004-03-05 23:32:36 +00:00
|
|
|
* rhythmbox/metadata/monkey-media/stream-info-impl/id3-vfs/mp3bitrate.c
|
|
|
|
* which took it from xine-lib/src/demuxers/demux_mpgaudio.c
|
2011-02-17 16:06:51 +00:00
|
|
|
* This code has been kindly relicensed to LGPL by Thibaut Mattern and
|
2004-03-05 23:32:36 +00:00
|
|
|
* Bastien Nocera
|
|
|
|
*/
|
2004-07-25 14:08:58 +00:00
|
|
|
#define BE_32(x) GST_READ_UINT32_BE(x)
|
2004-03-05 23:32:36 +00:00
|
|
|
|
2005-12-06 19:48:07 +00:00
|
|
|
#define FOURCC_TAG( ch0, ch1, ch2, ch3 ) \
|
|
|
|
( (long)(unsigned char)(ch3) | \
|
|
|
|
( (long)(unsigned char)(ch2) << 8 ) | \
|
|
|
|
( (long)(unsigned char)(ch1) << 16 ) | \
|
|
|
|
( (long)(unsigned char)(ch0) << 24 ) )
|
2004-03-05 23:32:36 +00:00
|
|
|
|
|
|
|
/* Xing header stuff */
|
|
|
|
#define XING_TAG FOURCC_TAG('X', 'i', 'n', 'g')
|
|
|
|
#define XING_FRAMES_FLAG 0x0001
|
|
|
|
#define XING_BYTES_FLAG 0x0002
|
|
|
|
#define XING_TOC_FLAG 0x0004
|
|
|
|
#define XING_VBR_SCALE_FLAG 0x0008
|
|
|
|
#define XING_TOC_LENGTH 100
|
|
|
|
|
|
|
|
/* check for valid "Xing" VBR header */
|
2004-03-14 22:34:30 +00:00
|
|
|
static int
|
|
|
|
is_xhead (unsigned char *buf)
|
2004-03-05 23:32:36 +00:00
|
|
|
{
|
2004-03-14 22:34:30 +00:00
|
|
|
return (BE_32 (buf) == XING_TAG);
|
2004-03-05 23:32:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#undef LOG
|
2004-12-01 20:07:24 +00:00
|
|
|
/*#define LOG*/
|
2004-03-05 23:32:36 +00:00
|
|
|
#ifdef LOG
|
ext/mad/gstmad.c: move GstIndexEntry *entry variable declaration before the first instruction
Original commit message from CVS:
* ext/mad/gstmad.c: (index_seek):
move GstIndexEntry *entry variable declaration before
the first instruction
* ext/mad/gstmad.c:
remove debug macros with variable number of parameter by using
GST_DEBUG for WIN32
* gst/dvdsub/gstdvdsubdec.c: (gst_dvd_sub_dec_parse_subpic):
use gst_guint64_to_gdouble for conversions
* gst/mpegstream/gstmpegdemux.c: (gst_mpeg_demux_sync_stream_to_time):
replace __FUNCTION__ which is not supported by MSVC by the current function name
* gst/mpegstream/gstmpegdemux.c: (gst_mpeg_demux_reset):
remove LL suffix by using G_GINT64_CONSTANT
* gst/mpegstream/gstmpegparse.c: (gst_mpeg_parse_parse_packhead),(gst_mpeg_parse_get_rate):
use gst_guint64_to_gdouble for conversions
* gst/mpegstream/gstmpegparse.h:
remove LL suffix by using G_GINT64_CONSTANT
* win32/vs6:
add project files for tagac3parse, asfdemux, dvdlpcmdec, dvdsub, iec958, lame,
mad, mpegaudioparse, mpegstream, realmedia, synaesthesia
2006-04-09 18:09:40 +00:00
|
|
|
#ifndef WIN32
|
2004-03-05 23:32:36 +00:00
|
|
|
#define lprintf(x...) g_print(x)
|
|
|
|
#else
|
ext/mad/gstmad.c: move GstIndexEntry *entry variable declaration before the first instruction
Original commit message from CVS:
* ext/mad/gstmad.c: (index_seek):
move GstIndexEntry *entry variable declaration before
the first instruction
* ext/mad/gstmad.c:
remove debug macros with variable number of parameter by using
GST_DEBUG for WIN32
* gst/dvdsub/gstdvdsubdec.c: (gst_dvd_sub_dec_parse_subpic):
use gst_guint64_to_gdouble for conversions
* gst/mpegstream/gstmpegdemux.c: (gst_mpeg_demux_sync_stream_to_time):
replace __FUNCTION__ which is not supported by MSVC by the current function name
* gst/mpegstream/gstmpegdemux.c: (gst_mpeg_demux_reset):
remove LL suffix by using G_GINT64_CONSTANT
* gst/mpegstream/gstmpegparse.c: (gst_mpeg_parse_parse_packhead),(gst_mpeg_parse_get_rate):
use gst_guint64_to_gdouble for conversions
* gst/mpegstream/gstmpegparse.h:
remove LL suffix by using G_GINT64_CONSTANT
* win32/vs6:
add project files for tagac3parse, asfdemux, dvdlpcmdec, dvdsub, iec958, lame,
mad, mpegaudioparse, mpegstream, realmedia, synaesthesia
2006-04-09 18:09:40 +00:00
|
|
|
#define lprintf GST_DEBUG
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#ifndef WIN32
|
2004-03-05 23:32:36 +00:00
|
|
|
#define lprintf(x...)
|
ext/mad/gstmad.c: move GstIndexEntry *entry variable declaration before the first instruction
Original commit message from CVS:
* ext/mad/gstmad.c: (index_seek):
move GstIndexEntry *entry variable declaration before
the first instruction
* ext/mad/gstmad.c:
remove debug macros with variable number of parameter by using
GST_DEBUG for WIN32
* gst/dvdsub/gstdvdsubdec.c: (gst_dvd_sub_dec_parse_subpic):
use gst_guint64_to_gdouble for conversions
* gst/mpegstream/gstmpegdemux.c: (gst_mpeg_demux_sync_stream_to_time):
replace __FUNCTION__ which is not supported by MSVC by the current function name
* gst/mpegstream/gstmpegdemux.c: (gst_mpeg_demux_reset):
remove LL suffix by using G_GINT64_CONSTANT
* gst/mpegstream/gstmpegparse.c: (gst_mpeg_parse_parse_packhead),(gst_mpeg_parse_get_rate):
use gst_guint64_to_gdouble for conversions
* gst/mpegstream/gstmpegparse.h:
remove LL suffix by using G_GINT64_CONSTANT
* win32/vs6:
add project files for tagac3parse, asfdemux, dvdlpcmdec, dvdsub, iec958, lame,
mad, mpegaudioparse, mpegstream, realmedia, synaesthesia
2006-04-09 18:09:40 +00:00
|
|
|
#else
|
|
|
|
#define lprintf GST_DEBUG
|
|
|
|
#endif
|
2004-03-05 23:32:36 +00:00
|
|
|
#endif
|
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
static int
|
|
|
|
mpg123_parse_xing_header (struct mad_header *header,
|
|
|
|
const guint8 * buf, int bufsize, int *bitrate, int *time)
|
2004-03-05 23:32:36 +00:00
|
|
|
{
|
|
|
|
int i;
|
2004-03-14 22:34:30 +00:00
|
|
|
guint8 *ptr = (guint8 *) buf;
|
2004-03-05 23:32:36 +00:00
|
|
|
double frame_duration;
|
2009-04-19 12:02:44 +00:00
|
|
|
int xflags, xframes, xbytes;
|
2004-03-05 23:32:36 +00:00
|
|
|
int abr;
|
2004-03-06 12:04:32 +00:00
|
|
|
guint8 xtoc[XING_TOC_LENGTH];
|
2004-12-01 20:07:24 +00:00
|
|
|
int lsf_bit = !(header->flags & MAD_FLAG_LSF_EXT);
|
2004-03-14 22:34:30 +00:00
|
|
|
|
2004-03-05 23:32:36 +00:00
|
|
|
xframes = xbytes = 0;
|
|
|
|
|
|
|
|
/* offset of the Xing header */
|
2004-03-14 22:34:30 +00:00
|
|
|
if (lsf_bit) {
|
2004-12-01 20:07:24 +00:00
|
|
|
if (header->mode != MAD_MODE_SINGLE_CHANNEL)
|
2004-03-05 23:32:36 +00:00
|
|
|
ptr += (32 + 4);
|
|
|
|
else
|
|
|
|
ptr += (17 + 4);
|
|
|
|
} else {
|
2004-12-01 20:07:24 +00:00
|
|
|
if (header->mode != MAD_MODE_SINGLE_CHANNEL)
|
2004-03-05 23:32:36 +00:00
|
|
|
ptr += (17 + 4);
|
|
|
|
else
|
|
|
|
ptr += (9 + 4);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ptr >= (buf + bufsize - 4))
|
|
|
|
return 0;
|
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
if (is_xhead (ptr)) {
|
|
|
|
lprintf ("Xing header found\n");
|
2004-03-05 23:32:36 +00:00
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
ptr += 4;
|
|
|
|
if (ptr >= (buf + bufsize - 4))
|
|
|
|
return 0;
|
2004-03-05 23:32:36 +00:00
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
xflags = BE_32 (ptr);
|
2004-03-05 23:32:36 +00:00
|
|
|
ptr += 4;
|
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
if (xflags & XING_FRAMES_FLAG) {
|
|
|
|
if (ptr >= (buf + bufsize - 4))
|
2004-03-15 19:32:25 +00:00
|
|
|
return 0;
|
2004-03-14 22:34:30 +00:00
|
|
|
xframes = BE_32 (ptr);
|
|
|
|
lprintf ("xframes: %d\n", xframes);
|
2004-03-05 23:32:36 +00:00
|
|
|
ptr += 4;
|
|
|
|
}
|
2004-03-14 22:34:30 +00:00
|
|
|
if (xflags & XING_BYTES_FLAG) {
|
|
|
|
if (ptr >= (buf + bufsize - 4))
|
2004-03-15 19:32:25 +00:00
|
|
|
return 0;
|
2004-03-14 22:34:30 +00:00
|
|
|
xbytes = BE_32 (ptr);
|
|
|
|
lprintf ("xbytes: %d\n", xbytes);
|
|
|
|
ptr += 4;
|
2004-03-05 23:32:36 +00:00
|
|
|
}
|
2004-03-14 22:34:30 +00:00
|
|
|
if (xflags & XING_TOC_FLAG) {
|
2008-01-08 19:42:38 +00:00
|
|
|
guchar old = 0;
|
|
|
|
|
2004-03-14 22:34:30 +00:00
|
|
|
lprintf ("toc found\n");
|
|
|
|
if (ptr >= (buf + bufsize - XING_TOC_LENGTH))
|
2004-03-15 19:32:25 +00:00
|
|
|
return 0;
|
2008-01-08 19:42:38 +00:00
|
|
|
if (*ptr != 0) {
|
|
|
|
lprintf ("skipping broken Xing TOC\n");
|
|
|
|
goto skip_toc;
|
|
|
|
}
|
2004-03-14 22:34:30 +00:00
|
|
|
for (i = 0; i < XING_TOC_LENGTH; i++) {
|
2004-03-15 19:32:25 +00:00
|
|
|
xtoc[i] = *(ptr + i);
|
2008-01-08 19:42:38 +00:00
|
|
|
if (old > xtoc[i]) {
|
|
|
|
lprintf ("skipping broken Xing TOC\n");
|
|
|
|
goto skip_toc;
|
|
|
|
}
|
2004-03-15 19:32:25 +00:00
|
|
|
lprintf ("%d ", xtoc[i]);
|
2004-03-05 23:32:36 +00:00
|
|
|
}
|
2004-03-14 22:34:30 +00:00
|
|
|
lprintf ("\n");
|
2008-01-08 19:42:38 +00:00
|
|
|
skip_toc:
|
2004-03-14 22:34:30 +00:00
|
|
|
ptr += XING_TOC_LENGTH;
|
2004-03-05 23:32:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (xflags & XING_VBR_SCALE_FLAG) {
|
2004-03-14 22:34:30 +00:00
|
|
|
if (ptr >= (buf + bufsize - 4))
|
2004-03-15 19:32:25 +00:00
|
|
|
return 0;
|
2009-04-19 12:02:44 +00:00
|
|
|
lprintf ("xvbr_scale: %d\n", BE_32 (ptr));
|
2004-03-05 23:32:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 1 kbit = 1000 bits ! (and not 1024 bits) */
|
|
|
|
if (xflags & (XING_FRAMES_FLAG | XING_BYTES_FLAG)) {
|
|
|
|
if (header->layer == MAD_LAYER_I) {
|
2004-03-15 19:32:25 +00:00
|
|
|
frame_duration = 384.0 / (double) header->samplerate;
|
2004-03-05 23:32:36 +00:00
|
|
|
} else {
|
2004-03-15 19:32:25 +00:00
|
|
|
int slots_per_frame;
|
2004-03-14 22:34:30 +00:00
|
|
|
|
2004-03-15 19:32:25 +00:00
|
|
|
slots_per_frame = ((header->layer == MAD_LAYER_III)
|
|
|
|
&& !lsf_bit) ? 72 : 144;
|
|
|
|
frame_duration = slots_per_frame * 8.0 / (double) header->samplerate;
|
2004-03-05 23:32:36 +00:00
|
|
|
}
|
2004-03-14 22:34:30 +00:00
|
|
|
abr = ((double) xbytes * 8.0) / ((double) xframes * frame_duration);
|
|
|
|
lprintf ("abr: %d bps\n", abr);
|
2004-03-05 23:32:36 +00:00
|
|
|
if (bitrate != NULL) {
|
2004-03-15 19:32:25 +00:00
|
|
|
*bitrate = abr;
|
2004-03-05 23:32:36 +00:00
|
|
|
}
|
|
|
|
if (time != NULL) {
|
2004-03-15 19:32:25 +00:00
|
|
|
*time = (double) xframes *frame_duration;
|
2004-03-14 22:34:30 +00:00
|
|
|
|
2004-03-15 19:32:25 +00:00
|
|
|
lprintf ("stream_length: %d s, %d min %d s\n", *time,
|
|
|
|
*time / 60, *time % 60);
|
2004-03-05 23:32:36 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* it's a stupid Xing header */
|
|
|
|
lprintf ("not a Xing VBR file\n");
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
} else {
|
2004-03-14 22:34:30 +00:00
|
|
|
lprintf ("Xing header not found\n");
|
2004-03-05 23:32:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2004-03-14 22:34:30 +00:00
|
|
|
|
2004-03-05 23:32:36 +00:00
|
|
|
/* End of Xine code */
|
|
|
|
|
2004-04-05 12:28:57 +00:00
|
|
|
/* internal function to check if the header has changed and thus the
|
|
|
|
* caps need to be reset. Only call during normal mode, not resyncing */
|
2005-05-06 11:04:30 +00:00
|
|
|
static void
|
2004-04-05 12:28:57 +00:00
|
|
|
gst_mad_check_caps_reset (GstMad * mad)
|
|
|
|
{
|
|
|
|
guint nchannels;
|
ext/mad/gstmad.c: Port fixes for bugs 314771, 308772, 140237, and 302625
Original commit message from CVS:
* ext/mad/gstmad.c: (gst_mad_init), (scale), (gst_mad_update_info),
(gst_mad_sink_event), (gst_mad_check_caps_reset), (gst_mad_chain),
(gst_mad_change_state):
Port fixes for bugs 314771, 308772, 140237, and 302625
from 0.8 (Patch by Jonathan Matthew, Fixes #329575)
Use GST_EVENT_FLUSH_STOP to clear data from the current input
buffer, to avoid using it for any future decoding.
2006-02-16 09:50:43 +00:00
|
|
|
guint rate, old_rate = mad->rate;
|
2004-04-05 12:28:57 +00:00
|
|
|
|
|
|
|
nchannels = MAD_NCHANNELS (&mad->frame.header);
|
|
|
|
|
|
|
|
#if MAD_VERSION_MINOR <= 12
|
|
|
|
rate = mad->header.sfreq;
|
|
|
|
#else
|
|
|
|
rate = mad->frame.header.samplerate;
|
|
|
|
#endif
|
|
|
|
|
2004-04-07 15:48:40 +00:00
|
|
|
/* rate and channels are not supposed to change in a continuous stream,
|
|
|
|
* so check this first before doing anything */
|
|
|
|
|
|
|
|
/* only set caps if they weren't already set for this continuous stream */
|
|
|
|
if (mad->channels != nchannels || mad->rate != rate) {
|
|
|
|
if (mad->caps_set) {
|
|
|
|
GST_DEBUG
|
|
|
|
("Header changed from %d Hz/%d ch to %d Hz/%d ch, failed sync after seek ?",
|
|
|
|
mad->rate, mad->channels, rate, nchannels);
|
ext/mad/gstmad.c: Allow for mp3 rate/channels changes. However, only very conservatively. Reason that we *have* to en...
Original commit message from CVS:
* ext/mad/gstmad.c: (gst_mad_check_caps_reset),
(gst_mad_change_state):
Allow for mp3 rate/channels changes. However, only very
conservatively. Reason that we *have* to enable this is smiply
because the mad find_sync() function is not good enough, it will
regularly sync on random data as valid frames and therefore make
us provide random caps as *final* caps of the stream. The best fix
I could think of is to simply require several of the same stream
changes in a row before we change caps.
The actual testcase that works now is #
* ext/ogg/Makefile.am:
* ext/ogg/gstogg.c: (plugin_init):
* ext/ogg/gstogmparse.c:
OGM support (video only for now; I need an audio sample file).
* gst/asfdemux/gstasfdemux.c: (gst_asf_demux_base_init),
(gst_asf_demux_process_stream), (gst_asf_demux_video_caps),
(gst_asf_demux_add_video_stream):
WMV extradata.
* gst/playback/gstplaybasebin.c: (unknown_type):
Don't error out on single unknown-types after all. It's wrong.
If we found type of video and audio but not of a subtitle stream,
it will still error out (which is unwanted). Will find a better fix
later on.
* gst/typefind/gsttypefindfunctions.c: (ogmvideo_type_find),
(ogmaudio_type_find), (plugin_init):
OGM support.
2004-09-20 12:40:40 +00:00
|
|
|
/* we're conservative on stream changes. However, our *initial* caps
|
|
|
|
* might have been wrong as well - mad ain't perfect in syncing. So,
|
|
|
|
* we count caps changes and change if we pass a limit treshold (3). */
|
|
|
|
if (nchannels != mad->pending_channels || rate != mad->pending_rate) {
|
|
|
|
mad->times_pending = 0;
|
|
|
|
mad->pending_channels = nchannels;
|
|
|
|
mad->pending_rate = rate;
|
|
|
|
}
|
|
|
|
if (++mad->times_pending < 3)
|
2005-05-06 11:04:30 +00:00
|
|
|
return;
|
2004-04-07 15:48:40 +00:00
|
|
|
}
|
|
|
|
}
|
2004-04-05 12:28:57 +00:00
|
|
|
gst_mad_update_info (mad);
|
|
|
|
|
|
|
|
if (mad->channels != nchannels || mad->rate != rate) {
|
|
|
|
GstCaps *caps;
|
|
|
|
|
2005-05-06 11:04:30 +00:00
|
|
|
if (mad->stream.options & MAD_OPTION_HALFSAMPLERATE)
|
|
|
|
rate >>= 1;
|
|
|
|
|
|
|
|
/* FIXME see if peer can accept the caps */
|
|
|
|
|
2004-04-05 12:28:57 +00:00
|
|
|
/* we set the caps even when the pad is not connected so they
|
|
|
|
* can be gotten for streaminfo */
|
|
|
|
caps = gst_caps_new_simple ("audio/x-raw-int",
|
|
|
|
"endianness", G_TYPE_INT, G_BYTE_ORDER,
|
|
|
|
"signed", G_TYPE_BOOLEAN, TRUE,
|
2006-01-31 22:03:30 +00:00
|
|
|
"width", G_TYPE_INT, 32,
|
|
|
|
"depth", G_TYPE_INT, 32,
|
2004-04-05 12:28:57 +00:00
|
|
|
"rate", G_TYPE_INT, rate, "channels", G_TYPE_INT, nchannels, NULL);
|
|
|
|
|
2005-05-06 11:04:30 +00:00
|
|
|
gst_pad_set_caps (mad->srcpad, caps);
|
2005-11-15 22:46:23 +00:00
|
|
|
gst_caps_unref (caps);
|
|
|
|
|
2005-05-06 11:04:30 +00:00
|
|
|
mad->caps_set = TRUE; /* set back to FALSE on discont */
|
|
|
|
mad->channels = nchannels;
|
|
|
|
mad->rate = rate;
|
ext/mad/gstmad.c: Port fixes for bugs 314771, 308772, 140237, and 302625
Original commit message from CVS:
* ext/mad/gstmad.c: (gst_mad_init), (scale), (gst_mad_update_info),
(gst_mad_sink_event), (gst_mad_check_caps_reset), (gst_mad_chain),
(gst_mad_change_state):
Port fixes for bugs 314771, 308772, 140237, and 302625
from 0.8 (Patch by Jonathan Matthew, Fixes #329575)
Use GST_EVENT_FLUSH_STOP to clear data from the current input
buffer, to avoid using it for any future decoding.
2006-02-16 09:50:43 +00:00
|
|
|
|
|
|
|
/* update sample count so we don't come up with crazy timestamps */
|
|
|
|
if (mad->total_samples && old_rate) {
|
|
|
|
mad->total_samples = mad->total_samples * rate / old_rate;
|
|
|
|
}
|
2004-04-05 12:28:57 +00:00
|
|
|
}
|
|
|
|
}
|
2004-03-05 23:32:36 +00:00
|
|
|
|
2010-09-29 19:24:23 +00:00
|
|
|
static void
|
|
|
|
gst_mad_clear_queues (GstMad * mad)
|
|
|
|
{
|
|
|
|
g_list_foreach (mad->queued, (GFunc) gst_mini_object_unref, NULL);
|
|
|
|
g_list_free (mad->queued);
|
|
|
|
mad->queued = NULL;
|
|
|
|
g_list_foreach (mad->gather, (GFunc) gst_mini_object_unref, NULL);
|
|
|
|
g_list_free (mad->gather);
|
|
|
|
mad->gather = NULL;
|
|
|
|
g_list_foreach (mad->decode, (GFunc) gst_mini_object_unref, NULL);
|
|
|
|
g_list_free (mad->decode);
|
|
|
|
mad->decode = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_mad_flush_decode (GstMad * mad)
|
|
|
|
{
|
|
|
|
GstFlowReturn res = GST_FLOW_OK;
|
|
|
|
GList *walk;
|
|
|
|
|
|
|
|
walk = mad->decode;
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (mad, "flushing buffers to decoder");
|
|
|
|
|
|
|
|
/* clear buffer and decoder state */
|
|
|
|
mad->tempsize = 0;
|
|
|
|
mad_frame_mute (&mad->frame);
|
|
|
|
mad_synth_mute (&mad->synth);
|
|
|
|
|
|
|
|
mad->process = TRUE;
|
|
|
|
while (walk) {
|
|
|
|
GList *next;
|
|
|
|
GstBuffer *buf = GST_BUFFER_CAST (walk->data);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (mad, "decoding buffer %p, ts %" GST_TIME_FORMAT,
|
|
|
|
buf, GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)));
|
|
|
|
|
|
|
|
next = g_list_next (walk);
|
|
|
|
/* decode buffer, resulting data prepended to output queue */
|
|
|
|
gst_buffer_ref (buf);
|
|
|
|
res = gst_mad_chain (mad->sinkpad, buf);
|
|
|
|
|
|
|
|
/* if we generated output, we can discard the buffer, else we
|
|
|
|
* keep it in the queue */
|
|
|
|
if (mad->queued) {
|
|
|
|
GST_DEBUG_OBJECT (mad, "decoded buffer to %p", mad->queued->data);
|
|
|
|
mad->decode = g_list_delete_link (mad->decode, walk);
|
|
|
|
gst_buffer_unref (buf);
|
|
|
|
} else {
|
|
|
|
GST_DEBUG_OBJECT (mad, "buffer did not decode, keeping");
|
|
|
|
}
|
|
|
|
walk = next;
|
|
|
|
}
|
|
|
|
mad->process = FALSE;
|
|
|
|
|
|
|
|
/* now send queued data downstream */
|
|
|
|
while (mad->queued) {
|
|
|
|
GstBuffer *buf = GST_BUFFER_CAST (mad->queued->data);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (mad, "pushing buffer %p of size %u, "
|
|
|
|
"time %" GST_TIME_FORMAT ", dur %" GST_TIME_FORMAT, buf,
|
2011-04-19 17:24:23 +00:00
|
|
|
gst_buffer_get_size (buf), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)),
|
2010-09-29 19:24:23 +00:00
|
|
|
GST_TIME_ARGS (GST_BUFFER_DURATION (buf)));
|
|
|
|
res = gst_pad_push (mad->srcpad, buf);
|
|
|
|
|
|
|
|
mad->queued = g_list_delete_link (mad->queued, mad->queued);
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstFlowReturn
|
|
|
|
gst_mad_chain_reverse (GstMad * mad, GstBuffer * buf)
|
|
|
|
{
|
|
|
|
GstFlowReturn result = GST_FLOW_OK;
|
|
|
|
|
|
|
|
/* if we have a discont, move buffers to the decode list */
|
|
|
|
if (!buf || GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_DISCONT)) {
|
|
|
|
GST_DEBUG_OBJECT (mad, "received discont");
|
|
|
|
while (mad->gather) {
|
|
|
|
GstBuffer *gbuf;
|
|
|
|
|
|
|
|
gbuf = GST_BUFFER_CAST (mad->gather->data);
|
|
|
|
/* remove from the gather list */
|
|
|
|
mad->gather = g_list_delete_link (mad->gather, mad->gather);
|
|
|
|
/* copy to decode queue */
|
|
|
|
mad->decode = g_list_prepend (mad->decode, gbuf);
|
|
|
|
}
|
|
|
|
/* decode stuff in the decode queue */
|
|
|
|
gst_mad_flush_decode (mad);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (G_LIKELY (buf)) {
|
|
|
|
GST_DEBUG_OBJECT (mad, "gathering buffer %p of size %u, "
|
|
|
|
"time %" GST_TIME_FORMAT ", dur %" GST_TIME_FORMAT, buf,
|
2011-04-19 17:24:23 +00:00
|
|
|
gst_buffer_get_size (buf), GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (buf)),
|
2010-09-29 19:24:23 +00:00
|
|
|
GST_TIME_ARGS (GST_BUFFER_DURATION (buf)));
|
|
|
|
|
|
|
|
/* add buffer to gather queue */
|
|
|
|
mad->gather = g_list_prepend (mad->gather, buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2005-05-06 11:04:30 +00:00
|
|
|
static GstFlowReturn
|
|
|
|
gst_mad_chain (GstPad * pad, GstBuffer * buffer)
|
2001-12-20 22:10:54 +00:00
|
|
|
{
|
|
|
|
GstMad *mad;
|
2011-04-19 17:24:23 +00:00
|
|
|
guint8 *data, *bdata;
|
|
|
|
gsize bsize, size, tempsize;
|
2002-09-18 22:04:32 +00:00
|
|
|
gboolean new_pts = FALSE;
|
2008-10-08 13:59:57 +00:00
|
|
|
gboolean discont;
|
2003-01-20 19:38:37 +00:00
|
|
|
GstClockTime timestamp;
|
2005-05-06 11:04:30 +00:00
|
|
|
GstFlowReturn result = GST_FLOW_OK;
|
2001-12-20 22:10:54 +00:00
|
|
|
|
2005-05-06 11:04:30 +00:00
|
|
|
mad = GST_MAD (GST_PAD_PARENT (pad));
|
2001-12-20 22:10:54 +00:00
|
|
|
|
2004-04-05 11:38:04 +00:00
|
|
|
/* restarts happen on discontinuities, ie. seek, flush, PAUSED to PLAYING */
|
2005-08-09 13:02:54 +00:00
|
|
|
if (gst_mad_check_restart (mad)) {
|
2006-01-04 15:17:15 +00:00
|
|
|
mad->need_newsegment = TRUE;
|
2004-04-05 11:38:04 +00:00
|
|
|
GST_DEBUG ("mad restarted");
|
2005-08-09 13:02:54 +00:00
|
|
|
}
|
2003-01-20 19:38:37 +00:00
|
|
|
|
2010-09-29 19:24:23 +00:00
|
|
|
if (mad->segment.rate < 0.0) {
|
|
|
|
if (!mad->process)
|
|
|
|
return gst_mad_chain_reverse (mad, buffer);
|
|
|
|
/* no output discont */
|
|
|
|
discont = FALSE;
|
|
|
|
} else {
|
|
|
|
/* take discont flag */
|
|
|
|
discont = GST_BUFFER_IS_DISCONT (buffer);
|
|
|
|
}
|
2008-10-08 13:59:57 +00:00
|
|
|
|
2003-01-20 19:38:37 +00:00
|
|
|
timestamp = GST_BUFFER_TIMESTAMP (buffer);
|
2009-05-06 11:17:35 +00:00
|
|
|
GST_DEBUG ("mad in timestamp %" GST_TIME_FORMAT " duration:%" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (timestamp), GST_TIME_ARGS (GST_BUFFER_DURATION (buffer)));
|
2003-01-20 19:38:37 +00:00
|
|
|
|
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)) {
|
2004-04-05 11:38:04 +00:00
|
|
|
/* if there is nothing left to process in our temporary buffer,
|
|
|
|
* we can set this timestamp on the next outgoing buffer */
|
2002-09-18 22:04:32 +00:00
|
|
|
if (mad->tempsize == 0) {
|
2004-04-05 11:38:04 +00:00
|
|
|
/* we have to save the result here because we can't yet convert
|
2005-11-22 17:39:36 +00:00
|
|
|
* the timestamp to a sample offset, as the samplerate might not
|
|
|
|
* be known yet */
|
2003-05-30 14:48:29 +00:00
|
|
|
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
|
|
|
}
|
2005-07-16 16:43:53 +00:00
|
|
|
GST_DEBUG ("last_ts %" GST_TIME_FORMAT, GST_TIME_ARGS (mad->last_ts));
|
2002-02-03 20:10:04 +00:00
|
|
|
|
2003-01-08 16:11:48 +00:00
|
|
|
/* handle data */
|
2011-04-19 17:24:23 +00:00
|
|
|
bdata = gst_buffer_map (buffer, &bsize, NULL, GST_MAP_READ);
|
|
|
|
|
|
|
|
data = bdata;
|
|
|
|
size = bsize;
|
2002-05-26 21:59:22 +00:00
|
|
|
|
2006-08-16 10:34:57 +00:00
|
|
|
tempsize = mad->tempsize;
|
|
|
|
|
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 */
|
2004-03-14 22:34:30 +00:00
|
|
|
while (size > 0) {
|
2001-12-28 01:59:26 +00:00
|
|
|
gint tocopy;
|
2004-04-05 11:38:04 +00:00
|
|
|
guchar *mad_input_buffer; /* convenience pointer to tempbuffer */
|
2001-12-28 01:59:26 +00:00
|
|
|
|
2008-10-08 13:59:57 +00:00
|
|
|
if (mad->tempsize == 0 && discont) {
|
|
|
|
mad->discont = TRUE;
|
|
|
|
discont = FALSE;
|
|
|
|
}
|
2004-11-05 03:33:26 +00:00
|
|
|
tocopy =
|
|
|
|
MIN (MAD_BUFFER_MDLEN, MIN (size,
|
|
|
|
MAD_BUFFER_MDLEN * 3 - mad->tempsize));
|
|
|
|
if (tocopy == 0) {
|
|
|
|
GST_ELEMENT_ERROR (mad, STREAM, DECODE, (NULL),
|
|
|
|
("mad claims to need more data than %u bytes, we don't have that much",
|
|
|
|
MAD_BUFFER_MDLEN * 3));
|
2005-05-06 11:04:30 +00:00
|
|
|
result = GST_FLOW_ERROR;
|
|
|
|
goto end;
|
2004-11-05 03:33:26 +00:00
|
|
|
}
|
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 */
|
2006-10-05 17:07:52 +00:00
|
|
|
GST_LOG ("tempbuffer size %ld, copying %d bytes from incoming buffer",
|
2004-04-05 11:38:04 +00:00
|
|
|
mad->tempsize, tocopy);
|
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 */
|
2006-08-16 10:34:57 +00:00
|
|
|
while (mad->tempsize > 0) {
|
2004-04-07 15:48:40 +00:00
|
|
|
gint consumed = 0;
|
2002-11-02 17:40:16 +00:00
|
|
|
guint nsamples;
|
2007-03-27 12:02:49 +00:00
|
|
|
guint64 time_offset = GST_CLOCK_TIME_NONE;
|
|
|
|
guint64 time_duration = GST_CLOCK_TIME_NONE;
|
2005-05-06 11:04:30 +00:00
|
|
|
unsigned char const *before_sync, *after_sync;
|
2005-11-25 00:03:52 +00:00
|
|
|
gboolean goto_exit = FALSE;
|
2001-12-28 01:59:26 +00:00
|
|
|
|
2004-04-05 12:28:57 +00:00
|
|
|
mad->in_error = FALSE;
|
2004-10-13 14:21:02 +00:00
|
|
|
|
2001-12-28 01:59:26 +00:00
|
|
|
mad_stream_buffer (&mad->stream, mad_input_buffer, mad->tempsize);
|
|
|
|
|
2004-10-13 14:21:02 +00:00
|
|
|
/* added separate header decoding to catch errors earlier, also fixes
|
|
|
|
* some weird decoding errors... */
|
2005-05-06 11:04:30 +00:00
|
|
|
GST_LOG ("decoding the header now");
|
|
|
|
if (mad_header_decode (&mad->frame.header, &mad->stream) == -1) {
|
2006-08-16 10:34:57 +00:00
|
|
|
if (mad->stream.error == MAD_ERROR_BUFLEN) {
|
2006-10-05 17:07:52 +00:00
|
|
|
GST_LOG ("not enough data in tempbuffer (%ld), breaking to get more",
|
2006-08-16 10:34:57 +00:00
|
|
|
mad->tempsize);
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
GST_WARNING ("mad_header_decode had an error: %s",
|
|
|
|
mad_stream_errorstr (&mad->stream));
|
|
|
|
}
|
2005-05-06 11:04:30 +00:00
|
|
|
}
|
|
|
|
|
2004-10-13 14:21:02 +00:00
|
|
|
GST_LOG ("decoding one frame now");
|
|
|
|
|
2001-12-28 01:59:26 +00:00
|
|
|
if (mad_frame_decode (&mad->frame, &mad->stream) == -1) {
|
2004-10-13 14:21:02 +00:00
|
|
|
GST_LOG ("got error %d", mad->stream.error);
|
|
|
|
|
2004-03-15 19:32:25 +00:00
|
|
|
/* not enough data, need to wait for next buffer? */
|
|
|
|
if (mad->stream.error == MAD_ERROR_BUFLEN) {
|
2004-11-05 03:33:26 +00:00
|
|
|
if (mad->stream.next_frame == mad_input_buffer) {
|
2006-10-05 17:07:52 +00:00
|
|
|
GST_LOG
|
|
|
|
("not enough data in tempbuffer (%ld), breaking to get more",
|
2004-11-05 03:33:26 +00:00
|
|
|
mad->tempsize);
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
GST_LOG ("sync error, flushing unneeded data");
|
2005-11-25 00:03:52 +00:00
|
|
|
goto next_no_samples;
|
2004-11-05 03:33:26 +00:00
|
|
|
}
|
2009-02-19 19:08:10 +00:00
|
|
|
} else if (mad->stream.error == MAD_ERROR_BADDATAPTR) {
|
|
|
|
/* Flush data */
|
|
|
|
goto next_no_samples;
|
2004-03-15 19:32:25 +00:00
|
|
|
}
|
2004-04-05 12:28:57 +00:00
|
|
|
/* we are in an error state */
|
|
|
|
mad->in_error = TRUE;
|
2005-11-28 15:47:01 +00:00
|
|
|
GST_WARNING ("mad_frame_decode had an error: %s",
|
2004-04-05 12:28:57 +00:00
|
|
|
mad_stream_errorstr (&mad->stream));
|
2004-03-15 19:32:25 +00:00
|
|
|
if (!MAD_RECOVERABLE (mad->stream.error)) {
|
|
|
|
GST_ELEMENT_ERROR (mad, STREAM, DECODE, (NULL), (NULL));
|
2005-05-06 11:04:30 +00:00
|
|
|
result = GST_FLOW_ERROR;
|
|
|
|
goto end;
|
2004-03-15 19:32:25 +00:00
|
|
|
} else if (mad->stream.error == MAD_ERROR_LOSTSYNC) {
|
|
|
|
/* lost sync, force a resync */
|
2004-04-05 12:28:57 +00:00
|
|
|
GST_INFO ("recoverable lost sync error");
|
|
|
|
|
2011-03-11 17:45:37 +00:00
|
|
|
#ifdef HAVE_ID3TAG
|
|
|
|
{
|
|
|
|
signed long tagsize;
|
|
|
|
|
|
|
|
tagsize = id3_tag_query (mad->stream.this_frame,
|
|
|
|
mad->stream.bufend - mad->stream.this_frame);
|
|
|
|
|
|
|
|
if (tagsize > mad->tempsize) {
|
|
|
|
GST_INFO ("mad: got partial id3 tag in buffer, skipping");
|
|
|
|
} else if (tagsize > 0) {
|
|
|
|
struct id3_tag *tag;
|
|
|
|
id3_byte_t const *data;
|
|
|
|
|
|
|
|
GST_INFO ("mad: got ID3 tag size %ld", tagsize);
|
|
|
|
|
|
|
|
data = mad->stream.this_frame;
|
|
|
|
|
|
|
|
/* mad has moved the pointer to the next frame over the start of the
|
|
|
|
* id3 tags, so we need to flush one byte less than the tagsize */
|
|
|
|
mad_stream_skip (&mad->stream, tagsize - 1);
|
|
|
|
|
|
|
|
tag = id3_tag_parse (data, tagsize);
|
|
|
|
if (tag) {
|
|
|
|
GstTagList *list;
|
|
|
|
|
|
|
|
list = gst_mad_id3_to_tag_list (tag);
|
|
|
|
id3_tag_delete (tag);
|
|
|
|
GST_DEBUG ("found tag");
|
|
|
|
gst_element_post_message (GST_ELEMENT (mad),
|
|
|
|
gst_message_new_tag (GST_OBJECT (mad),
|
|
|
|
gst_tag_list_copy (list)));
|
|
|
|
if (mad->tags) {
|
|
|
|
gst_tag_list_insert (mad->tags, list, GST_TAG_MERGE_PREPEND);
|
|
|
|
} else {
|
|
|
|
mad->tags = gst_tag_list_copy (list);
|
|
|
|
}
|
|
|
|
if (mad->need_newsegment)
|
|
|
|
mad->pending_events =
|
|
|
|
g_list_append (mad->pending_events,
|
|
|
|
gst_event_new_tag (list));
|
|
|
|
else
|
|
|
|
gst_pad_push_event (mad->srcpad, gst_event_new_tag (list));
|
2004-03-15 19:32:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-03-11 17:45:37 +00:00
|
|
|
#endif /* HAVE_ID3TAG */
|
2004-03-15 19:32:25 +00:00
|
|
|
}
|
|
|
|
|
2005-05-06 11:04:30 +00:00
|
|
|
mad_frame_mute (&mad->frame);
|
|
|
|
mad_synth_mute (&mad->synth);
|
|
|
|
before_sync = mad->stream.ptr.byte;
|
|
|
|
if (mad_stream_sync (&mad->stream) != 0)
|
|
|
|
GST_WARNING ("mad_stream_sync failed");
|
|
|
|
after_sync = mad->stream.ptr.byte;
|
|
|
|
/* a succesful resync should make us drop bytes as consumed, so
|
|
|
|
calculate from the byte pointers before and after resync */
|
|
|
|
consumed = after_sync - before_sync;
|
|
|
|
GST_DEBUG ("resynchronization consumes %d bytes", consumed);
|
|
|
|
GST_DEBUG ("synced to data: 0x%0x 0x%0x", *mad->stream.ptr.byte,
|
|
|
|
*(mad->stream.ptr.byte + 1));
|
|
|
|
|
|
|
|
mad_stream_sync (&mad->stream);
|
|
|
|
/* recoverable errors pass */
|
2005-11-25 00:03:52 +00:00
|
|
|
goto next_no_samples;
|
2001-12-28 01:59:26 +00:00
|
|
|
}
|
2002-03-30 17:06:26 +00:00
|
|
|
|
2004-03-05 23:32:36 +00:00
|
|
|
if (mad->check_for_xing) {
|
2005-06-29 16:36:15 +00:00
|
|
|
int bitrate = 0, time = 0;
|
2004-03-15 19:32:25 +00:00
|
|
|
GstTagList *list;
|
|
|
|
int frame_len = mad->stream.next_frame - mad->stream.this_frame;
|
|
|
|
|
2006-08-16 10:34:57 +00:00
|
|
|
mad->check_for_xing = FALSE;
|
|
|
|
|
2004-03-15 19:32:25 +00:00
|
|
|
/* Assume Xing headers can only be the first frame in a mp3 file */
|
|
|
|
if (mpg123_parse_xing_header (&mad->frame.header,
|
|
|
|
mad->stream.this_frame, frame_len, &bitrate, &time)) {
|
ext/mad/gstmad.c: Port fixes for bugs 314771, 308772, 140237, and 302625
Original commit message from CVS:
* ext/mad/gstmad.c: (gst_mad_init), (scale), (gst_mad_update_info),
(gst_mad_sink_event), (gst_mad_check_caps_reset), (gst_mad_chain),
(gst_mad_change_state):
Port fixes for bugs 314771, 308772, 140237, and 302625
from 0.8 (Patch by Jonathan Matthew, Fixes #329575)
Use GST_EVENT_FLUSH_STOP to clear data from the current input
buffer, to avoid using it for any future decoding.
2006-02-16 09:50:43 +00:00
|
|
|
mad->xing_found = TRUE;
|
2004-03-15 19:32:25 +00:00
|
|
|
list = gst_tag_list_new ();
|
|
|
|
gst_tag_list_add (list, GST_TAG_MERGE_REPLACE,
|
|
|
|
GST_TAG_DURATION, (gint64) time * 1000 * 1000 * 1000,
|
|
|
|
GST_TAG_BITRATE, bitrate, NULL);
|
2005-05-06 11:04:30 +00:00
|
|
|
gst_element_post_message (GST_ELEMENT (mad),
|
|
|
|
gst_message_new_tag (GST_OBJECT (mad), gst_tag_list_copy (list)));
|
2008-02-27 13:18:57 +00:00
|
|
|
|
|
|
|
if (mad->need_newsegment)
|
|
|
|
mad->pending_events =
|
|
|
|
g_list_append (mad->pending_events, gst_event_new_tag (list));
|
|
|
|
else
|
|
|
|
gst_pad_push_event (mad->srcpad, gst_event_new_tag (list));
|
2004-03-15 19:32:25 +00:00
|
|
|
|
2006-08-16 10:34:57 +00:00
|
|
|
goto next_no_samples;
|
|
|
|
}
|
2004-03-05 23:32:36 +00:00
|
|
|
}
|
2004-04-05 12:28:57 +00:00
|
|
|
|
|
|
|
/* if we're not resyncing/in error, check if caps need to be set again */
|
2005-05-06 11:04:30 +00:00
|
|
|
if (!mad->in_error)
|
|
|
|
gst_mad_check_caps_reset (mad);
|
2004-03-14 22:34:30 +00:00
|
|
|
nsamples = MAD_NSBSAMPLES (&mad->frame.header) *
|
2004-03-15 19:32:25 +00:00
|
|
|
(mad->stream.options & MAD_OPTION_HALFSAMPLERATE ? 16 : 32);
|
2001-12-20 22:27:35 +00:00
|
|
|
|
2008-05-19 15:07:07 +00:00
|
|
|
if (mad->rate == 0) {
|
|
|
|
g_warning ("mad->rate is 0; timestamps cannot be calculated");
|
2004-03-14 22:34:30 +00:00
|
|
|
} else {
|
2004-03-15 19:32:25 +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;
|
2005-06-29 16:14:30 +00:00
|
|
|
gint64 total;
|
2004-03-15 19:32:25 +00:00
|
|
|
|
2007-03-27 12:02:49 +00:00
|
|
|
/* Convert incoming timestamp to a number of encoded samples */
|
2005-05-12 19:48:45 +00:00
|
|
|
gst_pad_query_convert (mad->srcpad, GST_FORMAT_TIME, mad->last_ts,
|
2005-06-29 16:14:30 +00:00
|
|
|
&format, &total);
|
2007-03-27 12:02:49 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (mad, "calculated samples offset from ts is %"
|
|
|
|
G_GUINT64_FORMAT " accumulated samples offset is %"
|
|
|
|
G_GUINT64_FORMAT, total, mad->total_samples);
|
|
|
|
|
|
|
|
/* We are using the incoming timestamps to generate the outgoing ones
|
|
|
|
* if available. However some muxing formats are not precise enough
|
2011-02-17 16:06:51 +00:00
|
|
|
* to allow us to generate a perfect stream. When converting the
|
2007-03-27 12:02:49 +00:00
|
|
|
* timestamp to a number of encoded samples so far we are introducing
|
2011-02-17 16:06:51 +00:00
|
|
|
* a lot of potential error compared to our accumulated number of
|
|
|
|
* samples encoded. If the difference between those 2 numbers is
|
|
|
|
* bigger than half a frame we then use the incoming timestamp
|
2007-03-27 12:02:49 +00:00
|
|
|
* as a reference, otherwise we continue using our accumulated samples
|
|
|
|
* counter */
|
|
|
|
if (ABS (mad->total_samples - total) > nsamples / 2) {
|
|
|
|
GST_DEBUG_OBJECT (mad, "difference is bigger than half a frame, "
|
|
|
|
"using calculated samples offset %" G_GUINT64_FORMAT, total);
|
|
|
|
/* Override our accumulated samples counter */
|
|
|
|
mad->total_samples = total;
|
|
|
|
/* We use that timestamp directly */
|
|
|
|
time_offset = mad->last_ts;
|
|
|
|
}
|
|
|
|
|
2004-03-15 19:32:25 +00:00
|
|
|
mad->last_ts = GST_CLOCK_TIME_NONE;
|
|
|
|
}
|
2007-03-27 12:02:49 +00:00
|
|
|
|
|
|
|
if (!GST_CLOCK_TIME_IS_VALID (time_offset)) {
|
|
|
|
time_offset = gst_util_uint64_scale_int (mad->total_samples,
|
|
|
|
GST_SECOND, mad->rate);
|
|
|
|
}
|
|
|
|
/* Duration is next timestamp - this one to generate a continuous
|
|
|
|
* stream */
|
2006-04-21 20:37:43 +00:00
|
|
|
time_duration =
|
2007-03-27 12:02:49 +00:00
|
|
|
gst_util_uint64_scale_int (mad->total_samples + nsamples,
|
|
|
|
GST_SECOND, mad->rate) - time_offset;
|
2003-01-20 19:38:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mad->index) {
|
2004-03-15 19:32:25 +00:00
|
|
|
guint64 x_bytes = mad->base_byte_offset + mad->bytes_consumed;
|
2003-01-20 19:38:37 +00:00
|
|
|
|
2011-02-17 16:05:58 +00:00
|
|
|
gst_index_add_association (mad->index, mad->index_id,
|
|
|
|
GST_ASSOCIATION_FLAG_DELTA_UNIT,
|
2004-03-15 19:32:25 +00:00
|
|
|
GST_FORMAT_BYTES, x_bytes, GST_FORMAT_TIME, time_offset, NULL);
|
2003-01-20 19:38:37 +00:00
|
|
|
}
|
|
|
|
|
2005-10-06 13:14:38 +00:00
|
|
|
if (mad->segment_start <= (time_offset ==
|
2004-03-15 19:32:25 +00:00
|
|
|
GST_CLOCK_TIME_NONE ? 0 : time_offset)) {
|
2003-01-20 19:38:37 +00:00
|
|
|
|
2004-03-15 19:32:25 +00:00
|
|
|
/* for sample accurate seeking, calculate how many samples
|
|
|
|
to skip and send the remaining pcm samples */
|
2003-01-20 19:38:37 +00:00
|
|
|
|
2005-11-25 00:03:52 +00:00
|
|
|
GstBuffer *outbuffer = NULL;
|
2011-04-19 17:24:23 +00:00
|
|
|
gpointer odata;
|
|
|
|
gsize osize;
|
2004-03-15 19:32:25 +00:00
|
|
|
mad_fixed_t const *left_ch, *right_ch;
|
2002-11-02 17:40:16 +00:00
|
|
|
|
2006-06-17 19:35:41 +00:00
|
|
|
if (mad->need_newsegment) {
|
|
|
|
gint64 start = time_offset;
|
|
|
|
|
|
|
|
GST_DEBUG ("Sending NEWSEGMENT event, start=%" GST_TIME_FORMAT,
|
|
|
|
GST_TIME_ARGS (start));
|
|
|
|
|
2007-07-13 15:46:13 +00:00
|
|
|
gst_segment_set_newsegment (&mad->segment, FALSE, 1.0,
|
|
|
|
GST_FORMAT_TIME, start, GST_CLOCK_TIME_NONE, start);
|
|
|
|
|
2006-06-17 19:35:41 +00:00
|
|
|
gst_pad_push_event (mad->srcpad,
|
|
|
|
gst_event_new_new_segment (FALSE, 1.0, GST_FORMAT_TIME,
|
|
|
|
start, GST_CLOCK_TIME_NONE, start));
|
|
|
|
mad->need_newsegment = FALSE;
|
|
|
|
}
|
|
|
|
|
2008-02-27 13:18:57 +00:00
|
|
|
if (mad->pending_events) {
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
for (l = mad->pending_events; l != NULL; l = l->next) {
|
|
|
|
gst_pad_push_event (mad->srcpad, GST_EVENT (l->data));
|
|
|
|
}
|
|
|
|
g_list_free (mad->pending_events);
|
|
|
|
mad->pending_events = NULL;
|
|
|
|
}
|
|
|
|
|
2005-05-06 11:04:30 +00:00
|
|
|
/* will attach the caps to the buffer */
|
2011-04-29 13:43:47 +00:00
|
|
|
outbuffer = gst_buffer_new_and_alloc (nsamples * mad->channels * 4);
|
|
|
|
gst_buffer_set_caps (outbuffer, GST_PAD_CAPS (mad->srcpad));
|
2010-12-16 09:30:31 +00:00
|
|
|
|
2005-11-25 00:03:52 +00:00
|
|
|
mad_synth_frame (&mad->synth, &mad->frame);
|
|
|
|
left_ch = mad->synth.pcm.samples[0];
|
|
|
|
right_ch = mad->synth.pcm.samples[1];
|
2005-06-27 09:25:19 +00:00
|
|
|
|
2009-05-06 11:17:35 +00:00
|
|
|
GST_DEBUG ("mad out timestamp %" GST_TIME_FORMAT " dur: %"
|
|
|
|
GST_TIME_FORMAT, GST_TIME_ARGS (time_offset),
|
|
|
|
GST_TIME_ARGS (time_duration));
|
2005-07-16 16:43:53 +00:00
|
|
|
|
2004-03-15 19:32:25 +00:00
|
|
|
GST_BUFFER_TIMESTAMP (outbuffer) = time_offset;
|
|
|
|
GST_BUFFER_DURATION (outbuffer) = time_duration;
|
|
|
|
GST_BUFFER_OFFSET (outbuffer) = mad->total_samples;
|
2008-10-08 13:59:57 +00:00
|
|
|
GST_BUFFER_OFFSET_END (outbuffer) = mad->total_samples + nsamples;
|
2002-02-03 20:10:04 +00:00
|
|
|
|
2011-04-19 17:24:23 +00:00
|
|
|
odata = gst_buffer_map (outbuffer, &osize, NULL, GST_MAP_WRITE);
|
|
|
|
|
2004-03-15 19:32:25 +00:00
|
|
|
/* output sample(s) in 16-bit signed native-endian PCM */
|
2004-04-05 12:28:57 +00:00
|
|
|
if (mad->channels == 1) {
|
2004-03-15 19:32:25 +00:00
|
|
|
gint count = nsamples;
|
2011-04-19 17:24:23 +00:00
|
|
|
gint32 *ptr = odata;
|
2004-03-14 22:34:30 +00:00
|
|
|
|
2004-03-15 19:32:25 +00:00
|
|
|
while (count--) {
|
2011-04-19 17:24:23 +00:00
|
|
|
*ptr++ = scale (*left_ch++) & 0xffffffff;
|
2004-03-15 19:32:25 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
gint count = nsamples;
|
2011-04-19 17:24:23 +00:00
|
|
|
gint32 *ptr = odata;
|
2004-03-14 22:34:30 +00:00
|
|
|
|
2004-03-15 19:32:25 +00:00
|
|
|
while (count--) {
|
2011-04-19 17:24:23 +00:00
|
|
|
*ptr++ = scale (*left_ch++) & 0xffffffff;
|
|
|
|
*ptr++ = scale (*right_ch++) & 0xffffffff;
|
2004-03-15 19:32:25 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-19 17:24:23 +00:00
|
|
|
gst_buffer_unmap (outbuffer, odata, osize);
|
2004-03-14 22:34:30 +00:00
|
|
|
|
2007-07-24 05:05:29 +00:00
|
|
|
if ((outbuffer = gst_audio_buffer_clip (outbuffer, &mad->segment,
|
|
|
|
mad->rate, 4 * mad->channels))) {
|
2007-07-13 15:46:13 +00:00
|
|
|
GST_LOG_OBJECT (mad,
|
|
|
|
"pushing buffer, off=%" G_GUINT64_FORMAT ", ts=%" GST_TIME_FORMAT,
|
|
|
|
GST_BUFFER_OFFSET (outbuffer),
|
|
|
|
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuffer)));
|
2008-10-08 13:59:57 +00:00
|
|
|
|
|
|
|
/* apply discont */
|
|
|
|
if (mad->discont) {
|
|
|
|
GST_BUFFER_FLAG_SET (outbuffer, GST_BUFFER_FLAG_DISCONT);
|
|
|
|
mad->discont = FALSE;
|
|
|
|
}
|
|
|
|
|
2007-07-13 15:46:13 +00:00
|
|
|
mad->segment.last_stop = GST_BUFFER_TIMESTAMP (outbuffer);
|
2010-09-29 19:24:23 +00:00
|
|
|
if (mad->segment.rate > 0.0) {
|
|
|
|
result = gst_pad_push (mad->srcpad, outbuffer);
|
|
|
|
} else {
|
|
|
|
GST_LOG_OBJECT (mad, "queued buffer");
|
|
|
|
mad->queued = g_list_prepend (mad->queued, outbuffer);
|
|
|
|
result = GST_FLOW_OK;
|
|
|
|
}
|
2007-07-13 15:46:13 +00:00
|
|
|
if (result != GST_FLOW_OK) {
|
|
|
|
/* Head for the exit, dropping samples as we go */
|
|
|
|
goto_exit = TRUE;
|
|
|
|
}
|
|
|
|
} else {
|
2007-07-24 05:05:29 +00:00
|
|
|
GST_LOG_OBJECT (mad, "Dropping buffer");
|
2005-05-06 11:04:30 +00:00
|
|
|
}
|
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 */
|
2006-08-16 10:34:57 +00:00
|
|
|
if (new_pts && (mad->stream.next_frame - mad_input_buffer >= tempsize)) {
|
2004-03-15 19:32:25 +00:00
|
|
|
new_pts = FALSE;
|
2006-08-16 10:34:57 +00:00
|
|
|
mad->last_ts = timestamp;
|
2004-03-15 19:32:25 +00:00
|
|
|
mad->base_byte_offset = GST_BUFFER_OFFSET (buffer);
|
|
|
|
mad->bytes_consumed = 0;
|
2002-09-18 22:04:32 +00:00
|
|
|
}
|
2006-08-16 10:34:57 +00:00
|
|
|
tempsize = 0;
|
2008-10-08 13:59:57 +00:00
|
|
|
if (discont) {
|
|
|
|
mad->discont = TRUE;
|
|
|
|
discont = FALSE;
|
|
|
|
}
|
2002-09-18 22:04:32 +00:00
|
|
|
|
2003-01-20 19:38:37 +00:00
|
|
|
if (gst_mad_check_restart (mad)) {
|
2004-03-15 19:32:25 +00:00
|
|
|
goto end;
|
2002-05-07 21:02:24 +00:00
|
|
|
}
|
2002-06-09 14:30:16 +00:00
|
|
|
|
2005-11-25 00:03:52 +00:00
|
|
|
next_no_samples:
|
2001-12-28 01:59:26 +00:00
|
|
|
/* figure out how many bytes mad consumed */
|
2004-04-07 15:48:40 +00:00
|
|
|
/* if consumed is already set, it's from the resync higher up, so
|
|
|
|
we need to use that value instead. Otherwise, recalculate from
|
|
|
|
mad's consumption */
|
|
|
|
if (consumed == 0)
|
|
|
|
consumed = mad->stream.next_frame - mad_input_buffer;
|
|
|
|
|
2004-04-05 12:28:57 +00:00
|
|
|
GST_LOG ("mad consumed %d bytes", consumed);
|
2001-12-28 01:59:26 +00:00
|
|
|
/* 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;
|
2005-11-25 00:03:52 +00:00
|
|
|
if (goto_exit == TRUE)
|
|
|
|
goto end;
|
2001-12-28 01:59:26 +00:00
|
|
|
}
|
2004-04-05 12:28:57 +00:00
|
|
|
/* we only get here from breaks, tempsize never actually drops below 0 */
|
2001-12-28 01:59:26 +00:00
|
|
|
memmove (mad->tempbuffer, mad_input_buffer, mad->tempsize);
|
2001-12-20 22:10:54 +00:00
|
|
|
}
|
2005-05-06 11:04:30 +00:00
|
|
|
result = GST_FLOW_OK;
|
2001-12-20 22:10:54 +00:00
|
|
|
|
2002-05-07 21:02:24 +00:00
|
|
|
end:
|
2011-04-19 17:24:23 +00:00
|
|
|
gst_buffer_unmap (buffer, bdata, bsize);
|
2001-12-28 01:59:26 +00:00
|
|
|
gst_buffer_unref (buffer);
|
2005-05-06 11:04:30 +00:00
|
|
|
|
|
|
|
return result;
|
2001-12-20 22:10:54 +00:00
|
|
|
}
|
|
|
|
|
2005-09-02 15:43:54 +00:00
|
|
|
static GstStateChangeReturn
|
|
|
|
gst_mad_change_state (GstElement * element, GstStateChange transition)
|
2001-12-20 22:10:54 +00:00
|
|
|
{
|
|
|
|
GstMad *mad;
|
2005-09-02 15:43:54 +00:00
|
|
|
GstStateChangeReturn ret;
|
2001-12-20 22:10:54 +00:00
|
|
|
|
|
|
|
mad = GST_MAD (element);
|
|
|
|
|
2005-05-25 12:58:23 +00:00
|
|
|
switch (transition) {
|
2005-09-02 15:43:54 +00:00
|
|
|
case GST_STATE_CHANGE_NULL_TO_READY:
|
2001-12-28 01:59:26 +00:00
|
|
|
break;
|
2005-09-02 15:43:54 +00:00
|
|
|
case GST_STATE_CHANGE_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;
|
2008-10-08 13:59:57 +00:00
|
|
|
mad->discont = TRUE;
|
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;
|
2004-04-07 15:48:40 +00:00
|
|
|
mad->caps_set = FALSE;
|
ext/mad/gstmad.c: Allow for mp3 rate/channels changes. However, only very conservatively. Reason that we *have* to en...
Original commit message from CVS:
* ext/mad/gstmad.c: (gst_mad_check_caps_reset),
(gst_mad_change_state):
Allow for mp3 rate/channels changes. However, only very
conservatively. Reason that we *have* to enable this is smiply
because the mad find_sync() function is not good enough, it will
regularly sync on random data as valid frames and therefore make
us provide random caps as *final* caps of the stream. The best fix
I could think of is to simply require several of the same stream
changes in a row before we change caps.
The actual testcase that works now is #
* ext/ogg/Makefile.am:
* ext/ogg/gstogg.c: (plugin_init):
* ext/ogg/gstogmparse.c:
OGM support (video only for now; I need an audio sample file).
* gst/asfdemux/gstasfdemux.c: (gst_asf_demux_base_init),
(gst_asf_demux_process_stream), (gst_asf_demux_video_caps),
(gst_asf_demux_add_video_stream):
WMV extradata.
* gst/playback/gstplaybasebin.c: (unknown_type):
Don't error out on single unknown-types after all. It's wrong.
If we found type of video and audio but not of a subtitle stream,
it will still error out (which is unwanted). Will find a better fix
later on.
* gst/typefind/gsttypefindfunctions.c: (ogmvideo_type_find),
(ogmaudio_type_find), (plugin_init):
OGM support.
2004-09-20 12:40:40 +00:00
|
|
|
mad->times_pending = mad->pending_rate = mad->pending_channels = 0;
|
2002-09-02 18:13:26 +00:00
|
|
|
mad->vbr_average = 0;
|
2007-07-13 15:46:13 +00:00
|
|
|
gst_segment_init (&mad->segment, GST_FORMAT_TIME);
|
2002-12-07 14:32:21 +00:00
|
|
|
mad->new_header = TRUE;
|
2006-03-14 19:41:17 +00:00
|
|
|
mad->framed = FALSE;
|
2002-12-07 14:32:21 +00:00
|
|
|
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;
|
2004-03-14 22:34:30 +00:00
|
|
|
if (mad->ignore_crc)
|
2004-03-15 19:32:25 +00:00
|
|
|
options |= MAD_OPTION_IGNORECRC;
|
2004-03-14 22:34:30 +00:00
|
|
|
if (mad->half)
|
2004-03-15 19:32:25 +00:00
|
|
|
options |= MAD_OPTION_HALFSAMPLERATE;
|
2002-11-02 17:40:16 +00:00
|
|
|
mad_stream_options (&mad->stream, options);
|
2001-12-28 01:59:26 +00:00
|
|
|
break;
|
2002-11-02 17:40:16 +00:00
|
|
|
}
|
2005-09-02 15:43:54 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
|
2001-12-28 01:59:26 +00:00
|
|
|
break;
|
2005-05-25 12:58:23 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-04-19 17:24:23 +00:00
|
|
|
ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
|
2005-05-25 12:58:23 +00:00
|
|
|
|
|
|
|
switch (transition) {
|
2005-09-02 15:43:54 +00:00
|
|
|
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
|
2001-12-28 01:59:26 +00:00
|
|
|
break;
|
2005-09-02 15:43:54 +00:00
|
|
|
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
2001-12-28 01:59:26 +00:00
|
|
|
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;
|
ext/mad/gstmad.c: Port fixes for bugs 314771, 308772, 140237, and 302625
Original commit message from CVS:
* ext/mad/gstmad.c: (gst_mad_init), (scale), (gst_mad_update_info),
(gst_mad_sink_event), (gst_mad_check_caps_reset), (gst_mad_chain),
(gst_mad_change_state):
Port fixes for bugs 314771, 308772, 140237, and 302625
from 0.8 (Patch by Jonathan Matthew, Fixes #329575)
Use GST_EVENT_FLUSH_STOP to clear data from the current input
buffer, to avoid using it for any future decoding.
2006-02-16 09:50:43 +00:00
|
|
|
mad->check_for_xing = TRUE;
|
2003-11-24 04:08:47 +00:00
|
|
|
if (mad->tags) {
|
2004-03-15 19:32:25 +00:00
|
|
|
gst_tag_list_free (mad->tags);
|
|
|
|
mad->tags = NULL;
|
2003-11-24 04:08:47 +00:00
|
|
|
}
|
2010-09-29 19:24:23 +00:00
|
|
|
gst_mad_clear_queues (mad);
|
2001-12-28 01:59:26 +00:00
|
|
|
break;
|
2005-09-02 15:43:54 +00:00
|
|
|
case GST_STATE_CHANGE_READY_TO_NULL:
|
2001-12-28 01:59:26 +00:00
|
|
|
break;
|
2005-05-25 12:58:23 +00:00
|
|
|
default:
|
|
|
|
break;
|
2001-12-28 01:59:26 +00:00
|
|
|
}
|
2005-05-25 12:58:23 +00:00
|
|
|
return ret;
|
2001-12-28 01:59:26 +00:00
|
|
|
}
|
2009-06-05 19:53:57 +00:00
|
|
|
|
2011-03-11 17:45:37 +00:00
|
|
|
#ifdef HAVE_ID3TAG
|
2009-06-05 19:53:57 +00:00
|
|
|
/* id3 tag helper (FIXME: why does mad parse id3 tags at all? It shouldn't) */
|
|
|
|
static GstTagList *
|
|
|
|
gst_mad_id3_to_tag_list (const struct id3_tag *tag)
|
|
|
|
{
|
|
|
|
const struct id3_frame *frame;
|
|
|
|
const id3_ucs4_t *ucs4;
|
|
|
|
id3_utf8_t *utf8;
|
|
|
|
GstTagList *tag_list;
|
|
|
|
GType tag_type;
|
|
|
|
guint i = 0;
|
|
|
|
|
|
|
|
tag_list = gst_tag_list_new ();
|
|
|
|
|
|
|
|
while ((frame = id3_tag_findframe (tag, NULL, i++)) != NULL) {
|
|
|
|
const union id3_field *field;
|
|
|
|
unsigned int nstrings, j;
|
|
|
|
const gchar *tag_name;
|
|
|
|
|
|
|
|
/* find me the function to query the frame id */
|
|
|
|
gchar *id = g_strndup (frame->id, 5);
|
|
|
|
|
|
|
|
tag_name = gst_tag_from_id3_tag (id);
|
|
|
|
if (tag_name == NULL) {
|
|
|
|
g_free (id);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp (id, "COMM") == 0) {
|
|
|
|
if (frame->nfields < 4)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
ucs4 = id3_field_getfullstring (&frame->fields[3]);
|
|
|
|
g_assert (ucs4);
|
|
|
|
|
|
|
|
utf8 = id3_ucs4_utf8duplicate (ucs4);
|
|
|
|
if (utf8 == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!g_utf8_validate ((char *) utf8, -1, NULL)) {
|
|
|
|
GST_ERROR ("converted string is not valid utf-8");
|
|
|
|
g_free (utf8);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND,
|
|
|
|
GST_TAG_COMMENT, utf8, NULL);
|
|
|
|
|
|
|
|
g_free (utf8);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (frame->nfields < 2)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
field = &frame->fields[1];
|
|
|
|
nstrings = id3_field_getnstrings (field);
|
|
|
|
|
|
|
|
for (j = 0; j < nstrings; ++j) {
|
|
|
|
ucs4 = id3_field_getstrings (field, j);
|
|
|
|
g_assert (ucs4);
|
|
|
|
|
|
|
|
if (strcmp (id, ID3_FRAME_GENRE) == 0)
|
|
|
|
ucs4 = id3_genre_name (ucs4);
|
|
|
|
|
|
|
|
utf8 = id3_ucs4_utf8duplicate (ucs4);
|
|
|
|
if (utf8 == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!g_utf8_validate ((char *) utf8, -1, NULL)) {
|
|
|
|
GST_ERROR ("converted string is not valid utf-8");
|
|
|
|
free (utf8);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
tag_type = gst_tag_get_type (tag_name);
|
|
|
|
|
|
|
|
/* be sure to add non-string tags here */
|
|
|
|
switch (tag_type) {
|
|
|
|
case G_TYPE_UINT:
|
|
|
|
{
|
|
|
|
guint tmp;
|
|
|
|
gchar *check;
|
|
|
|
|
|
|
|
tmp = strtoul ((char *) utf8, &check, 10);
|
|
|
|
|
|
|
|
if (strcmp (tag_name, GST_TAG_DATE) == 0) {
|
|
|
|
GDate *d;
|
|
|
|
|
|
|
|
if (*check != '\0')
|
|
|
|
break;
|
|
|
|
if (tmp == 0)
|
|
|
|
break;
|
|
|
|
d = g_date_new_dmy (1, 1, tmp);
|
|
|
|
tmp = g_date_get_julian (d);
|
|
|
|
g_date_free (d);
|
|
|
|
} else if (strcmp (tag_name, GST_TAG_TRACK_NUMBER) == 0) {
|
|
|
|
if (*check == '/') {
|
|
|
|
guint total;
|
|
|
|
|
|
|
|
check++;
|
|
|
|
total = strtoul (check, &check, 10);
|
|
|
|
if (*check != '\0')
|
|
|
|
break;
|
|
|
|
|
|
|
|
gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND,
|
|
|
|
GST_TAG_TRACK_COUNT, total, NULL);
|
|
|
|
}
|
|
|
|
} else if (strcmp (tag_name, GST_TAG_ALBUM_VOLUME_NUMBER) == 0) {
|
|
|
|
if (*check == '/') {
|
|
|
|
guint total;
|
|
|
|
|
|
|
|
check++;
|
|
|
|
total = strtoul (check, &check, 10);
|
|
|
|
if (*check != '\0')
|
|
|
|
break;
|
|
|
|
|
|
|
|
gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND,
|
|
|
|
GST_TAG_ALBUM_VOLUME_COUNT, total, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*check != '\0')
|
|
|
|
break;
|
|
|
|
gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND, tag_name, tmp,
|
|
|
|
NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case G_TYPE_UINT64:
|
|
|
|
{
|
|
|
|
guint64 tmp;
|
|
|
|
|
|
|
|
g_assert (strcmp (tag_name, GST_TAG_DURATION) == 0);
|
|
|
|
tmp = strtoul ((char *) utf8, NULL, 10);
|
|
|
|
if (tmp == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND,
|
|
|
|
GST_TAG_DURATION, tmp * 1000 * 1000, NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case G_TYPE_STRING:{
|
|
|
|
gst_tag_list_add (tag_list, GST_TAG_MERGE_APPEND,
|
|
|
|
tag_name, (const gchar *) utf8, NULL);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* handles GST_TYPE_DATE and anything else */
|
|
|
|
default:{
|
|
|
|
GValue src = { 0, };
|
|
|
|
GValue dest = { 0, };
|
|
|
|
|
|
|
|
g_value_init (&src, G_TYPE_STRING);
|
|
|
|
g_value_set_string (&src, (const gchar *) utf8);
|
|
|
|
|
|
|
|
g_value_init (&dest, tag_type);
|
|
|
|
if (g_value_transform (&src, &dest)) {
|
|
|
|
gst_tag_list_add_values (tag_list, GST_TAG_MERGE_APPEND,
|
|
|
|
tag_name, &dest, NULL);
|
|
|
|
} else {
|
|
|
|
GST_WARNING ("Failed to transform tag from string to type '%s'",
|
|
|
|
g_type_name (tag_type));
|
|
|
|
}
|
|
|
|
g_value_unset (&src);
|
|
|
|
g_value_unset (&dest);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free (utf8);
|
|
|
|
}
|
|
|
|
g_free (id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return tag_list;
|
|
|
|
}
|
2011-03-11 17:45:37 +00:00
|
|
|
#endif /* HAVE_ID3TAG */
|
2009-06-05 19:53:57 +00:00
|
|
|
|
|
|
|
/* plugin initialisation */
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
plugin_init (GstPlugin * plugin)
|
|
|
|
{
|
|
|
|
GST_DEBUG_CATEGORY_INIT (mad_debug, "mad", 0, "mad mp3 decoding");
|
|
|
|
|
|
|
|
return gst_element_register (plugin, "mad", GST_RANK_SECONDARY,
|
|
|
|
gst_mad_get_type ());
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
|
|
|
GST_VERSION_MINOR,
|
|
|
|
"mad",
|
|
|
|
"mp3 decoding based on the mad library",
|
|
|
|
plugin_init, VERSION, "GPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN);
|