#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
+
#include <string.h>
#include <math.h>
static void gst_wavparse_dispose (GObject * object);
-static gboolean gst_wavparse_sink_activate (GstPad * sinkpad);
-static gboolean gst_wavparse_sink_activate_pull (GstPad * sinkpad,
- gboolean active);
+static gboolean gst_wavparse_sink_activate (GstPad * sinkpad,
+ GstObject * parent);
+static gboolean gst_wavparse_sink_activate_mode (GstPad * sinkpad,
+ GstObject * parent, GstPadMode mode, gboolean active);
static gboolean gst_wavparse_send_event (GstElement * element,
GstEvent * event);
static GstStateChangeReturn gst_wavparse_change_state (GstElement * element,
GstStateChange transition);
-static const GstQueryType *gst_wavparse_get_query_types (GstPad * pad);
-static gboolean gst_wavparse_pad_query (GstPad * pad, GstQuery * query);
-static gboolean gst_wavparse_pad_convert (GstPad * pad,
- GstFormat src_format,
+static gboolean gst_wavparse_pad_query (GstPad * pad, GstObject * parent,
+ GstQuery * query);
+static gboolean gst_wavparse_pad_convert (GstPad * pad, GstFormat src_format,
gint64 src_value, GstFormat * dest_format, gint64 * dest_value);
-static GstFlowReturn gst_wavparse_chain (GstPad * pad, GstBuffer * buf);
-static gboolean gst_wavparse_sink_event (GstPad * pad, GstEvent * event);
+static GstFlowReturn gst_wavparse_chain (GstPad * pad, GstObject * parent,
+ GstBuffer * buf);
+static gboolean gst_wavparse_sink_event (GstPad * pad, GstObject * parent,
+ GstEvent * event);
static void gst_wavparse_loop (GstPad * pad);
-static gboolean gst_wavparse_srcpad_event (GstPad * pad, GstEvent * event);
+static gboolean gst_wavparse_srcpad_event (GstPad * pad, GstObject * parent,
+ GstEvent * event);
+
+static void gst_wavparse_set_property (GObject * object, guint prop_id,
+ const GValue * value, GParamSpec * pspec);
+static void gst_wavparse_get_property (GObject * object, guint prop_id,
+ GValue * value, GParamSpec * pspec);
+
+#define DEFAULT_IGNORE_LENGTH FALSE
+
+enum
+{
+ PROP_0,
+ PROP_IGNORE_LENGTH,
+};
static GstStaticPadTemplate sink_template_factory =
-GST_STATIC_PAD_TEMPLATE ("wavparse_sink",
+GST_STATIC_PAD_TEMPLATE ("sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS ("audio/x-wav")
);
-#define DEBUG_INIT(bla) \
+#define DEBUG_INIT \
GST_DEBUG_CATEGORY_INIT (wavparse_debug, "wavparse", 0, "WAV parser");
-GST_BOILERPLATE_FULL (GstWavParse, gst_wavparse, GstElement,
- GST_TYPE_ELEMENT, DEBUG_INIT);
+#define gst_wavparse_parent_class parent_class
+G_DEFINE_TYPE_WITH_CODE (GstWavParse, gst_wavparse, GST_TYPE_ELEMENT,
+ DEBUG_INIT);
-static void
-gst_wavparse_base_init (gpointer g_class)
+typedef struct
{
- GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
- GstPadTemplate *src_template;
-
- /* register pads */
- gst_element_class_add_static_pad_template (element_class,
- &sink_template_factory);
-
- src_template = gst_pad_template_new ("wavparse_src", GST_PAD_SRC,
- GST_PAD_SOMETIMES, gst_riff_create_audio_template_caps ());
- gst_element_class_add_pad_template (element_class, src_template);
- gst_object_unref (src_template);
-
- gst_element_class_set_details_simple (element_class, "WAV audio demuxer",
- "Codec/Demuxer/Audio",
- "Parse a .wav file into raw audio",
- "Erik Walthinsen <omega@cse.ogi.edu>");
-}
+ /* Offset Size Description Value
+ * 0x00 4 ID unique identification value
+ * 0x04 4 Position play order position
+ * 0x08 4 Data Chunk ID RIFF ID of corresponding data chunk
+ * 0x0c 4 Chunk Start Byte Offset of Data Chunk *
+ * 0x10 4 Block Start Byte Offset to sample of First Channel
+ * 0x14 4 Sample Offset Byte Offset to sample byte of First Channel
+ */
+ guint32 id;
+ guint32 position;
+ guint32 data_chunk_id;
+ guint32 chunk_start;
+ guint32 block_start;
+ guint32 sample_offset;
+} GstWavParseCue;
+
+typedef struct
+{
+ /* Offset Size Description Value
+ * 0x08 4 Cue Point ID 0 - 0xFFFFFFFF
+ * 0x0c Text
+ */
+ guint32 cue_point_id;
+ gchar *text;
+} GstWavParseLabl;
static void
gst_wavparse_class_init (GstWavParseClass * klass)
{
GstElementClass *gstelement_class;
GObjectClass *object_class;
+ GstPadTemplate *src_template;
gstelement_class = (GstElementClass *) klass;
object_class = (GObjectClass *) klass;
object_class->dispose = gst_wavparse_dispose;
+ object_class->set_property = gst_wavparse_set_property;
+ object_class->get_property = gst_wavparse_get_property;
+
+ /**
+ * GstWavParse:ignore-length
+ *
+ * This selects whether the length found in a data chunk
+ * should be ignored. This may be useful for streamed audio
+ * where the length is unknown until the end of streaming,
+ * and various software/hardware just puts some random value
+ * in there and hopes it doesn't break too much.
+ *
+ * Since: 0.10.36
+ */
+ g_object_class_install_property (object_class, PROP_IGNORE_LENGTH,
+ g_param_spec_boolean ("ignore-length",
+ "Ignore length",
+ "Ignore length from the Wave header",
+ DEFAULT_IGNORE_LENGTH, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)
+ );
+
gstelement_class->change_state = gst_wavparse_change_state;
gstelement_class->send_event = gst_wavparse_send_event;
+
+ /* register pads */
+ gst_element_class_add_pad_template (gstelement_class,
+ gst_static_pad_template_get (&sink_template_factory));
+
+ src_template = gst_pad_template_new ("src", GST_PAD_SRC,
+ GST_PAD_ALWAYS, gst_riff_create_audio_template_caps ());
+ gst_element_class_add_pad_template (gstelement_class, src_template);
+
+ gst_element_class_set_static_metadata (gstelement_class, "WAV audio demuxer",
+ "Codec/Demuxer/Audio",
+ "Parse a .wav file into raw audio",
+ "Erik Walthinsen <omega@cse.ogi.edu>");
}
static void
if (wav->tags)
gst_tag_list_free (wav->tags);
wav->tags = NULL;
+ if (wav->toc)
+ gst_toc_unref (wav->toc);
+ wav->toc = NULL;
+ if (wav->cues)
+ g_list_free_full (wav->cues, g_free);
+ wav->cues = NULL;
+ if (wav->labls)
+ g_list_free_full (wav->labls, g_free);
+ wav->labls = NULL;
if (wav->caps)
gst_caps_unref (wav->caps);
wav->caps = NULL;
if (wav->start_segment)
gst_event_unref (wav->start_segment);
wav->start_segment = NULL;
- if (wav->close_segment)
- gst_event_unref (wav->close_segment);
- wav->close_segment = NULL;
}
static void
}
static void
-gst_wavparse_init (GstWavParse * wavparse, GstWavParseClass * g_class)
+gst_wavparse_init (GstWavParse * wavparse)
{
gst_wavparse_reset (wavparse);
gst_pad_new_from_static_template (&sink_template_factory, "sink");
gst_pad_set_activate_function (wavparse->sinkpad,
GST_DEBUG_FUNCPTR (gst_wavparse_sink_activate));
- gst_pad_set_activatepull_function (wavparse->sinkpad,
- GST_DEBUG_FUNCPTR (gst_wavparse_sink_activate_pull));
+ gst_pad_set_activatemode_function (wavparse->sinkpad,
+ GST_DEBUG_FUNCPTR (gst_wavparse_sink_activate_mode));
gst_pad_set_chain_function (wavparse->sinkpad,
GST_DEBUG_FUNCPTR (gst_wavparse_chain));
gst_pad_set_event_function (wavparse->sinkpad,
GST_DEBUG_FUNCPTR (gst_wavparse_sink_event));
gst_element_add_pad (GST_ELEMENT_CAST (wavparse), wavparse->sinkpad);
- /* src, will be created later */
- wavparse->srcpad = NULL;
-}
-
-static void
-gst_wavparse_destroy_sourcepad (GstWavParse * wavparse)
-{
- if (wavparse->srcpad) {
- gst_element_remove_pad (GST_ELEMENT_CAST (wavparse), wavparse->srcpad);
- wavparse->srcpad = NULL;
- }
-}
-
-static void
-gst_wavparse_create_sourcepad (GstWavParse * wavparse)
-{
- GstElementClass *klass = GST_ELEMENT_GET_CLASS (wavparse);
- GstPadTemplate *src_template;
-
- /* destroy previous one */
- gst_wavparse_destroy_sourcepad (wavparse);
-
- /* source */
- src_template = gst_element_class_get_pad_template (klass, "wavparse_src");
- wavparse->srcpad = gst_pad_new_from_template (src_template, "src");
+ /* src */
+ wavparse->srcpad =
+ gst_pad_new_from_template (gst_element_class_get_pad_template
+ (GST_ELEMENT_GET_CLASS (wavparse), "src"), "src");
gst_pad_use_fixed_caps (wavparse->srcpad);
- gst_pad_set_query_type_function (wavparse->srcpad,
- GST_DEBUG_FUNCPTR (gst_wavparse_get_query_types));
gst_pad_set_query_function (wavparse->srcpad,
GST_DEBUG_FUNCPTR (gst_wavparse_pad_query));
gst_pad_set_event_function (wavparse->srcpad,
GST_DEBUG_FUNCPTR (gst_wavparse_srcpad_event));
-
- GST_DEBUG_OBJECT (wavparse, "srcpad created");
-}
-
-/* Compute (value * nom) % denom, avoiding overflow. This can be used
- * to perform ceiling or rounding division together with
- * gst_util_uint64_scale[_int]. */
-#define uint64_scale_modulo(val, nom, denom) \
- ((val % denom) * (nom % denom) % denom)
-
-/* Like gst_util_uint64_scale, but performs ceiling division. */
-static guint64
-uint64_ceiling_scale_int (guint64 val, gint num, gint denom)
-{
- guint64 result = gst_util_uint64_scale_int (val, num, denom);
-
- if (uint64_scale_modulo (val, num, denom) == 0)
- return result;
- else
- return result + 1;
+ gst_element_add_pad (GST_ELEMENT_CAST (wavparse), wavparse->srcpad);
}
-/* Like gst_util_uint64_scale, but performs ceiling division. */
-static guint64
-uint64_ceiling_scale (guint64 val, guint64 num, guint64 denom)
-{
- guint64 result = gst_util_uint64_scale (val, num, denom);
-
- if (uint64_scale_modulo (val, num, denom) == 0)
- return result;
- else
- return result + 1;
-}
-
-
/* FIXME: why is that not in use? */
#if 0
static void
/* Note: gst_riff_create_audio_caps might need to fix values in
* the header header depending on the format, so call it first */
- caps = gst_riff_create_audio_caps (header->format, NULL, header, NULL);
+ /* FIXME: Need to handle the channel reorder map */
+ caps = gst_riff_create_audio_caps (header->format, NULL, header, NULL, NULL);
g_free (header);
if (caps == NULL)
gst_element_add_pad (GST_ELEMENT_CAST (wav), wav->srcpad);
gst_element_no_more_pads (GST_ELEMENT_CAST (wav));
- GST_DEBUG ("frequency %d, channels %d", wav->rate, wav->channels);
+ GST_DEBUG ("frequency %u, channels %u", wav->rate, wav->channels);
return TRUE;
GST_WARNING_OBJECT (wav, "could not peek head");
return FALSE;
}
- GST_DEBUG_OBJECT (wav, "got tag (%08x) %4.4s, length %d", tag,
- (gchar *) & tag, length);
+ GST_DEBUG_OBJECT (wav, "got tag (%08x) %4.4s, length %u", tag,
+ (const gchar *) &tag, length);
switch (tag) {
case GST_RIFF_TAG_LIST:
}
if (wav->bps > 0) {
- *bytepos = uint64_ceiling_scale (ts, (guint64) wav->bps, GST_SECOND);
+ *bytepos = gst_util_uint64_scale_ceil (ts, (guint64) wav->bps, GST_SECOND);
return TRUE;
} else if (wav->fact) {
guint64 bps =
gst_util_uint64_scale_int (wav->datasize, wav->rate, wav->fact);
- *bytepos = uint64_ceiling_scale (ts, bps, GST_SECOND);
+ *bytepos = gst_util_uint64_scale_ceil (ts, bps, GST_SECOND);
return TRUE;
}
if (cur_type != GST_SEEK_TYPE_NONE)
res =
gst_pad_query_convert (wav->srcpad, format, cur,
- &wav->segment.format, &cur);
+ wav->segment.format, &cur);
if (res && stop_type != GST_SEEK_TYPE_NONE)
res =
gst_pad_query_convert (wav->srcpad, format, stop,
- &wav->segment.format, &stop);
+ wav->segment.format, &stop);
if (!res)
goto no_format;
if (!event || wav->state != GST_WAVPARSE_DATA) {
if (wav->start_segment)
gst_event_unref (wav->start_segment);
- wav->start_segment =
- gst_event_new_new_segment (FALSE, wav->segment.rate,
- wav->segment.format, wav->segment.last_stop, wav->segment.duration,
- wav->segment.last_stop);
+ wav->start_segment = gst_event_new_segment (&wav->segment);
res = TRUE;
} else {
/* convert seek positions to byte positions in data sections */
* as it completes one iteration (and thus might block when the sink is
* blocking in preroll). */
if (flush) {
- if (wav->srcpad) {
- GST_DEBUG_OBJECT (wav, "sending flush start");
- gst_pad_push_event (wav->srcpad, gst_event_new_flush_start ());
- }
+ GST_DEBUG_OBJECT (wav, "sending flush start");
+ gst_pad_push_event (wav->srcpad, gst_event_new_flush_start ());
} else {
gst_pad_pause_task (wav->sinkpad);
}
GST_PAD_STREAM_LOCK (wav->sinkpad);
/* save current position */
- last_stop = wav->segment.last_stop;
+ last_stop = wav->segment.position;
GST_DEBUG_OBJECT (wav, "stopped streaming at %" G_GINT64_FORMAT, last_stop);
* right values in the segment to perform the seek */
if (event) {
GST_DEBUG_OBJECT (wav, "configuring seek");
- gst_segment_set_seek (&seeksegment, rate, format, flags,
+ gst_segment_do_seek (&seeksegment, rate, format, flags,
cur_type, cur, stop_type, stop, &update);
}
/* bring offset to bytes, if the bps is 0, we have the segment in BYTES and
* we can just copy the last_stop. If not, we use the bps to convert TIME to
* bytes. */
- if (!gst_wavparse_time_to_bytepos (wav, seeksegment.last_stop,
+ if (!gst_wavparse_time_to_bytepos (wav, seeksegment.position,
(gint64 *) & wav->offset))
- wav->offset = seeksegment.last_stop;
+ wav->offset = seeksegment.position;
GST_LOG_OBJECT (wav, "offset=%" G_GUINT64_FORMAT, wav->offset);
wav->offset -= (wav->offset % wav->bytes_per_sample);
GST_LOG_OBJECT (wav, "offset=%" G_GUINT64_FORMAT, wav->offset);
/* make sure filesize is not exceeded due to rounding errors or so,
* same precaution as in _stream_headers */
bformat = GST_FORMAT_BYTES;
- if (gst_pad_query_peer_duration (wav->sinkpad, &bformat, &upstream_size))
+ if (gst_pad_peer_query_duration (wav->sinkpad, bformat, &upstream_size))
wav->end_offset = MIN (wav->end_offset, upstream_size);
/* this is the range of bytes we will use for playback */
wav->end_offset, GST_TIME_ARGS (seeksegment.start), GST_TIME_ARGS (stop));
/* prepare for streaming again */
- if (wav->srcpad) {
- if (flush) {
- /* if we sent a FLUSH_START, we now send a FLUSH_STOP */
- GST_DEBUG_OBJECT (wav, "sending flush stop");
- gst_pad_push_event (wav->srcpad, gst_event_new_flush_stop ());
- } else if (wav->segment_running) {
- /* we are running the current segment and doing a non-flushing seek,
- * close the segment first based on the previous last_stop. */
- GST_DEBUG_OBJECT (wav, "closing running segment %" G_GINT64_FORMAT
- " to %" G_GINT64_FORMAT, wav->segment.start, wav->segment.last_stop);
-
- /* queue the segment for sending in the stream thread */
- if (wav->close_segment)
- gst_event_unref (wav->close_segment);
- wav->close_segment = gst_event_new_new_segment (TRUE,
- wav->segment.rate, wav->segment.format,
- wav->segment.start, wav->segment.last_stop, wav->segment.start);
- }
+ if (flush) {
+ /* if we sent a FLUSH_START, we now send a FLUSH_STOP */
+ GST_DEBUG_OBJECT (wav, "sending flush stop");
+ gst_pad_push_event (wav->srcpad, gst_event_new_flush_stop (TRUE));
}
/* now we did the seek and can activate the new segment values */
if (wav->segment.flags & GST_SEEK_FLAG_SEGMENT) {
gst_element_post_message (GST_ELEMENT_CAST (wav),
gst_message_new_segment_start (GST_OBJECT_CAST (wav),
- wav->segment.format, wav->segment.last_stop));
+ wav->segment.format, wav->segment.position));
}
/* now create the newsegment */
GST_DEBUG_OBJECT (wav, "Creating newsegment from %" G_GINT64_FORMAT
- " to %" G_GINT64_FORMAT, wav->segment.last_stop, stop);
+ " to %" G_GINT64_FORMAT, wav->segment.position, stop);
/* store the newsegment event so it can be sent from the streaming thread. */
if (wav->start_segment)
gst_event_unref (wav->start_segment);
- wav->start_segment =
- gst_event_new_new_segment (FALSE, wav->segment.rate,
- wav->segment.format, wav->segment.last_stop, stop,
- wav->segment.last_stop);
+ wav->start_segment = gst_event_new_segment (&wav->segment);
/* mark discont if we are going to stream from another position. */
- if (last_stop != wav->segment.last_stop) {
+ if (last_stop != wav->segment.position) {
GST_DEBUG_OBJECT (wav, "mark DISCONT, we did a seek to another position");
wav->discont = TRUE;
}
/* and start the streaming task again */
- wav->segment_running = TRUE;
if (!wav->streaming) {
gst_pad_start_task (wav->sinkpad, (GstTaskFunction) gst_wavparse_loop,
- wav->sinkpad);
+ wav->sinkpad, NULL);
}
GST_PAD_STREAM_UNLOCK (wav->sinkpad);
if (gst_adapter_available (wav->adapter) < 8)
return FALSE;
- data = gst_adapter_peek (wav->adapter, 8);
+ data = gst_adapter_map (wav->adapter, 8);
*tag = GST_READ_UINT32_LE (data);
*size = GST_READ_UINT32_LE (data + 4);
+ gst_adapter_unmap (wav->adapter);
- GST_DEBUG ("Next chunk size is %d bytes, type %" GST_FOURCC_FORMAT, *size,
+ GST_DEBUG ("Next chunk size is %u bytes, type %" GST_FOURCC_FORMAT, *size,
GST_FOURCC_ARGS (*tag));
return TRUE;
* so we throw poor man's exception, which can be caught if caller really
* wants to handle 0 size chunk */
if (!(*size) || (*size) >= (1 << 30)) {
- GST_INFO ("Invalid/unexpected chunk size %d for tag %" GST_FOURCC_FORMAT,
+ GST_INFO ("Invalid/unexpected chunk size %u for tag %" GST_FOURCC_FORMAT,
*size, GST_FOURCC_ARGS (*tag));
/* chain should give up */
wav->abort_buffering = TRUE;
if (wav->bps > 0) {
GST_INFO_OBJECT (wav, "Got datasize %" G_GUINT64_FORMAT, wav->datasize);
wav->duration =
- uint64_ceiling_scale (wav->datasize, GST_SECOND, (guint64) wav->bps);
+ gst_util_uint64_scale_ceil (wav->datasize, GST_SECOND,
+ (guint64) wav->bps);
GST_INFO_OBJECT (wav, "Got duration (bps) %" GST_TIME_FORMAT,
GST_TIME_ARGS (wav->duration));
return TRUE;
} else if (wav->fact) {
- wav->duration = uint64_ceiling_scale_int (GST_SECOND, wav->fact, wav->rate);
+ wav->duration =
+ gst_util_uint64_scale_int_ceil (GST_SECOND, wav->fact, wav->rate);
GST_INFO_OBJECT (wav, "Got duration (fact) %" GST_TIME_FORMAT,
GST_TIME_ARGS (wav->duration));
return TRUE;
return TRUE;
}
+/*
+ * gst_wavparse_cue_chunk:
+ * @wav GstWavParse object
+ * @data holder for data
+ * @size holder for data size
+ *
+ * Parse cue chunk from @data to wav->cues.
+ *
+ * Returns: %TRUE when cue chunk is available
+ */
+static gboolean
+gst_wavparse_cue_chunk (GstWavParse * wav, const guint8 * data, guint32 size)
+{
+ guint32 i, ncues;
+ GList *cues = NULL;
+ GstWavParseCue *cue;
+
+ if (wav->cues) {
+ GST_WARNING_OBJECT (wav, "found another cue's");
+ return TRUE;
+ }
+
+ ncues = GST_READ_UINT32_LE (data);
+
+ if (size < 4 + ncues * 24) {
+ GST_WARNING_OBJECT (wav, "broken file %d %d", size, ncues);
+ return FALSE;
+ }
+
+ /* parse data */
+ data += 4;
+ for (i = 0; i < ncues; i++) {
+ cue = g_new0 (GstWavParseCue, 1);
+ cue->id = GST_READ_UINT32_LE (data);
+ cue->position = GST_READ_UINT32_LE (data + 4);
+ cue->data_chunk_id = GST_READ_UINT32_LE (data + 8);
+ cue->chunk_start = GST_READ_UINT32_LE (data + 12);
+ cue->block_start = GST_READ_UINT32_LE (data + 16);
+ cue->sample_offset = GST_READ_UINT32_LE (data + 20);
+ cues = g_list_append (cues, cue);
+ data += 24;
+ }
+
+ wav->cues = cues;
+
+ return TRUE;
+}
+
+/*
+ * gst_wavparse_labl_chunk:
+ * @wav GstWavParse object
+ * @data holder for data
+ * @size holder for data size
+ *
+ * Parse labl from @data to wav->labls.
+ *
+ * Returns: %TRUE when labl chunk is available
+ */
+static gboolean
+gst_wavparse_labl_chunk (GstWavParse * wav, const guint8 * data, guint32 size)
+{
+ GstWavParseLabl *labl;
+
+ if (size < 5)
+ return FALSE;
+
+ labl = g_new0 (GstWavParseLabl, 1);
+
+ /* parse data */
+ data += 8;
+ labl->cue_point_id = GST_READ_UINT32_LE (data);
+ labl->text = (gchar *) g_new0 (gchar *, size - 4 + 1);
+ memcpy (labl->text, data + 4, size - 4);
+
+ wav->labls = g_list_append (wav->labls, labl);
+
+ return TRUE;
+}
+
+/*
+ * gst_wavparse_adtl_chunk:
+ * @wav GstWavParse object
+ * @data holder for data
+ * @size holder for data size
+ *
+ * Parse adtl from @data.
+ *
+ * Returns: %TRUE when adtl chunk is available
+ */
+static gboolean
+gst_wavparse_adtl_chunk (GstWavParse * wav, const guint8 * data, guint32 size)
+{
+ guint32 ltag, lsize, offset = 0;
+
+ while (size >= 8) {
+ ltag = GST_READ_UINT32_LE (data + offset);
+ lsize = GST_READ_UINT32_LE (data + offset + 4);
+ switch (ltag) {
+ case GST_RIFF_TAG_labl:
+ gst_wavparse_labl_chunk (wav, data + offset, size);
+ default:
+ break;
+ }
+ offset += 8 + GST_ROUND_UP_2 (lsize);
+ size -= 8 + GST_ROUND_UP_2 (lsize);
+ }
+
+ return TRUE;
+}
+
+/*
+ * gst_wavparse_create_toc:
+ * @wav GstWavParse object
+ *
+ * Create TOC from wav->cues and wav->labls.
+ */
+static gboolean
+gst_wavparse_create_toc (GstWavParse * wav)
+{
+ gint64 start, stop;
+ gchar *id;
+ GList *list;
+ GstWavParseCue *cue;
+ GstWavParseLabl *labl;
+ GstTagList *tags;
+ GstToc *toc;
+ GstTocEntry *entry = NULL, *cur_subentry = NULL, *prev_subentry = NULL;
+
+ GST_OBJECT_LOCK (wav);
+ if (wav->toc) {
+ GST_OBJECT_UNLOCK (wav);
+ GST_WARNING_OBJECT (wav, "found another TOC");
+ return FALSE;
+ }
+
+ toc = gst_toc_new ();
+
+ /* add cue edition */
+ entry = gst_toc_entry_new (GST_TOC_ENTRY_TYPE_EDITION, "cue");
+ gst_toc_entry_set_start_stop_times (entry, 0, wav->duration);
+ gst_toc_append_entry (toc, entry);
+
+ /* add chapters in cue edition */
+ list = g_list_first (wav->cues);
+ while (list != NULL) {
+ cue = list->data;
+ prev_subentry = cur_subentry;
+ /* previous chapter stop time = current chapter start time */
+ if (prev_subentry != NULL) {
+ gst_toc_entry_get_start_stop_times (prev_subentry, &start, NULL);
+ stop = gst_util_uint64_scale_round (cue->position, GST_SECOND, wav->rate);
+ gst_toc_entry_set_start_stop_times (prev_subentry, start, stop);
+ }
+ id = g_strdup_printf ("%08x", cue->id);
+ cur_subentry = gst_toc_entry_new (GST_TOC_ENTRY_TYPE_CHAPTER, id);
+ g_free (id);
+ start = gst_util_uint64_scale_round (cue->position, GST_SECOND, wav->rate);
+ stop = wav->duration;
+ gst_toc_entry_set_start_stop_times (cur_subentry, start, stop);
+ gst_toc_entry_append_sub_entry (entry, cur_subentry);
+ list = g_list_next (list);
+ }
+
+ /* add tags in chapters */
+ list = g_list_first (wav->labls);
+ while (list != NULL) {
+ labl = list->data;
+ id = g_strdup_printf ("%08x", labl->cue_point_id);
+ cur_subentry = gst_toc_find_entry (toc, id);
+ g_free (id);
+ if (cur_subentry != NULL) {
+ tags = gst_tag_list_new_empty ();
+ gst_tag_list_add (tags, GST_TAG_MERGE_APPEND, GST_TAG_TITLE, labl->text,
+ NULL);
+ gst_toc_entry_set_tags (cur_subentry, tags);
+ }
+ list = g_list_next (list);
+ }
+
+ /* send data as TOC */
+ wav->toc = toc;
+
+ /* send TOC event */
+ if (wav->toc) {
+ GST_OBJECT_UNLOCK (wav);
+ gst_pad_push_event (wav->srcpad, gst_event_new_toc (wav->toc, FALSE));
+ }
+
+ return TRUE;
+}
+
#define MAX_BUFFER_SIZE 4096
static GstFlowReturn
GstCaps *caps = NULL;
gchar *codec_name = NULL;
GstEvent **event_p;
- GstFormat bformat;
gint64 upstream_size = 0;
/* search for "_fmt" chunk, which should be first */
/* Note: gst_riff_create_audio_caps might need to fix values in
* the header header depending on the format, so call it first */
+ /* FIXME: Need to handle the channel reorder map */
caps = gst_riff_create_audio_caps (header->format, NULL, header, extra,
- NULL, &codec_name);
+ NULL, &codec_name, NULL);
if (extra)
gst_buffer_unref (extra);
wav->rate = header->rate;
wav->channels = header->channels;
wav->blockalign = header->blockalign;
- wav->depth = header->size;
+ wav->depth = header->bits_per_sample;
wav->av_bps = header->av_bps;
wav->vbr = FALSE;
{
/* Note: workaround for mp2/mp3 embedded in wav, that relies on the
* bitrate inside the mpeg stream */
- GST_INFO ("resetting bps from %d to 0 for mp2/3", wav->av_bps);
+ GST_INFO ("resetting bps from %u to 0 for mp2/3", wav->av_bps);
wav->bps = 0;
break;
}
case GST_RIFF_WAVE_FORMAT_PCM:
- if (wav->blockalign > wav->channels * (guint) ceil (wav->depth / 8.0))
+ if (wav->blockalign > wav->channels * ((wav->depth + 7) / 8))
goto invalid_blockalign;
/* fall through */
default:
wav->got_fmt = TRUE;
if (codec_name) {
- wav->tags = gst_tag_list_new ();
+ wav->tags = gst_tag_list_new_empty ();
gst_tag_list_add (wav->tags, GST_TAG_MERGE_REPLACE,
GST_TAG_AUDIO_CODEC, codec_name, NULL);
}
- bformat = GST_FORMAT_BYTES;
- gst_pad_query_peer_duration (wav->sinkpad, &bformat, &upstream_size);
+ gst_pad_peer_query_duration (wav->sinkpad, GST_FORMAT_BYTES, &upstream_size);
GST_DEBUG_OBJECT (wav, "upstream size %" G_GUINT64_FORMAT, upstream_size);
/* loop headers until we get data */
if (!gst_wavparse_peek_chunk_info (wav, &tag, &size))
goto exit;
} else {
+ GstMapInfo map;
+
+ buf = NULL;
if ((res =
gst_pad_pull_range (wav->sinkpad, wav->offset, 8,
&buf)) != GST_FLOW_OK)
goto header_read_error;
- tag = GST_READ_UINT32_LE (GST_BUFFER_DATA (buf));
- size = GST_READ_UINT32_LE (GST_BUFFER_DATA (buf) + 4);
+ gst_buffer_map (buf, &map, GST_MAP_READ);
+ tag = GST_READ_UINT32_LE (map.data);
+ size = GST_READ_UINT32_LE (map.data + 4);
+ gst_buffer_unmap (buf, &map);
}
GST_INFO_OBJECT (wav,
*/
switch (tag) {
case GST_RIFF_TAG_data:{
- GST_DEBUG_OBJECT (wav, "Got 'data' TAG, size : %d", size);
+ GST_DEBUG_OBJECT (wav, "Got 'data' TAG, size : %u", size);
+ if (wav->ignore_length) {
+ GST_DEBUG_OBJECT (wav, "Ignoring length");
+ size = 0;
+ }
if (wav->streaming) {
gst_adapter_flush (wav->adapter, 8);
gotdata = TRUE;
/* We will continue parsing tags 'till end */
wav->offset += size;
}
- GST_DEBUG_OBJECT (wav, "datasize = %d", size);
+ GST_DEBUG_OBJECT (wav, "datasize = %u", size);
break;
}
case GST_RIFF_TAG_fact:{
/* need more data */
goto exit;
}
- GST_DEBUG_OBJECT (wav, "need %d, available %d; ignoring chunk",
+ GST_DEBUG_OBJECT (wav, "need %u, available %u; ignoring chunk",
data_size, size);
break;
}
goto exit;
}
gst_adapter_flush (wav->adapter, 8);
- data = gst_adapter_peek (wav->adapter, data_size);
+ data = gst_adapter_map (wav->adapter, data_size);
wav->fact = GST_READ_UINT32_LE (data);
+ gst_adapter_unmap (wav->adapter);
gst_adapter_flush (wav->adapter, GST_ROUND_UP_2 (size));
} else {
gst_buffer_unref (buf);
+ buf = NULL;
if ((res =
gst_pad_pull_range (wav->sinkpad, wav->offset + 8,
data_size, &buf)) != GST_FLOW_OK)
goto header_read_error;
- wav->fact = GST_READ_UINT32_LE (GST_BUFFER_DATA (buf));
+ gst_buffer_extract (buf, 0, &wav->fact, 4);
+ wav->fact = GUINT32_FROM_LE (wav->fact);
gst_buffer_unref (buf);
}
GST_DEBUG_OBJECT (wav, "have fact %u", wav->fact);
case GST_RIFF_TAG_acid:{
const gst_riff_acid *acid = NULL;
const guint data_size = sizeof (gst_riff_acid);
+ gfloat tempo;
GST_INFO_OBJECT (wav, "Have acid chunk");
if (size < data_size) {
/* need more data */
goto exit;
}
- GST_DEBUG_OBJECT (wav, "need %d, available %d; ignoring chunk",
+ GST_DEBUG_OBJECT (wav, "need %u, available %u; ignoring chunk",
data_size, size);
break;
}
goto exit;
}
gst_adapter_flush (wav->adapter, 8);
- acid = (const gst_riff_acid *) gst_adapter_peek (wav->adapter,
+ acid = (const gst_riff_acid *) gst_adapter_map (wav->adapter,
data_size);
+ tempo = acid->tempo;
+ gst_adapter_unmap (wav->adapter);
} else {
+ GstMapInfo map;
gst_buffer_unref (buf);
+ buf = NULL;
if ((res =
gst_pad_pull_range (wav->sinkpad, wav->offset + 8,
size, &buf)) != GST_FLOW_OK)
goto header_read_error;
- acid = (const gst_riff_acid *) GST_BUFFER_DATA (buf);
+ gst_buffer_map (buf, &map, GST_MAP_READ);
+ acid = (const gst_riff_acid *) map.data;
+ tempo = acid->tempo;
+ gst_buffer_unmap (buf, &map);
}
/* send data as tags */
if (!wav->tags)
- wav->tags = gst_tag_list_new ();
+ wav->tags = gst_tag_list_new_empty ();
gst_tag_list_add (wav->tags, GST_TAG_MERGE_REPLACE,
- GST_TAG_BEATS_PER_MINUTE, acid->tempo, NULL);
+ GST_TAG_BEATS_PER_MINUTE, tempo, NULL);
size = GST_ROUND_UP_2 (size);
if (wav->streaming) {
if (gst_adapter_available (wav->adapter) < 12) {
goto exit;
}
- data = gst_adapter_peek (wav->adapter, 12);
+ data = gst_adapter_map (wav->adapter, 12);
ltag = GST_READ_UINT32_LE (data + 8);
+ gst_adapter_unmap (wav->adapter);
} else {
gst_buffer_unref (buf);
+ buf = NULL;
if ((res =
gst_pad_pull_range (wav->sinkpad, wav->offset, 12,
&buf)) != GST_FLOW_OK)
goto header_read_error;
- ltag = GST_READ_UINT32_LE (GST_BUFFER_DATA (buf) + 8);
+ gst_buffer_extract (buf, 8, <ag, 4);
+ ltag = GUINT32_FROM_LE (ltag);
}
switch (ltag) {
case GST_RIFF_LIST_INFO:{
} else {
wav->offset += 12;
gst_buffer_unref (buf);
+ buf = NULL;
if (data_size > 0) {
if ((res =
gst_pad_pull_range (wav->sinkpad, wav->offset,
}
break;
}
+ case GST_RIFF_LIST_adtl:{
+ const gint data_size = size;
+
+ GST_INFO_OBJECT (wav, "Have 'adtl' LIST, size %u", data_size);
+ if (wav->streaming) {
+ const guint8 *data = NULL;
+
+ gst_adapter_flush (wav->adapter, 12);
+ data = gst_adapter_map (wav->adapter, data_size);
+ gst_wavparse_adtl_chunk (wav, data, data_size);
+ gst_adapter_unmap (wav->adapter);
+ } else {
+ GstMapInfo map;
+
+ gst_buffer_unref (buf);
+ buf = NULL;
+ if ((res =
+ gst_pad_pull_range (wav->sinkpad, wav->offset + 12,
+ data_size, &buf)) != GST_FLOW_OK)
+ goto header_read_error;
+ gst_buffer_map (buf, &map, GST_MAP_READ);
+ gst_wavparse_adtl_chunk (wav, (const guint8 *) map.data,
+ data_size);
+ gst_buffer_unmap (buf, &map);
+ }
+ }
default:
GST_INFO_OBJECT (wav, "Ignoring LIST chunk %" GST_FOURCC_FORMAT,
GST_FOURCC_ARGS (ltag));
}
break;
}
+ case GST_RIFF_TAG_cue:{
+ const guint data_size = size;
+
+ GST_DEBUG_OBJECT (wav, "Have 'cue' TAG, size : %u", data_size);
+ if (wav->streaming) {
+ const guint8 *data = NULL;
+
+ if (!gst_wavparse_peek_chunk (wav, &tag, &size)) {
+ goto exit;
+ }
+ gst_adapter_flush (wav->adapter, 8);
+ wav->offset += 8;
+ data = gst_adapter_map (wav->adapter, data_size);
+ if (!gst_wavparse_cue_chunk (wav, data, data_size)) {
+ goto header_read_error;
+ }
+ gst_adapter_unmap (wav->adapter);
+ } else {
+ GstMapInfo map;
+
+ wav->offset += 8;
+ gst_buffer_unref (buf);
+ buf = NULL;
+ if ((res =
+ gst_pad_pull_range (wav->sinkpad, wav->offset,
+ data_size, &buf)) != GST_FLOW_OK)
+ goto header_read_error;
+ gst_buffer_map (buf, &map, GST_MAP_READ);
+ if (!gst_wavparse_cue_chunk (wav, (const guint8 *) map.data,
+ data_size)) {
+ goto header_read_error;
+ }
+ gst_buffer_unmap (buf, &map);
+ }
+ size = GST_ROUND_UP_2 (size);
+ if (wav->streaming) {
+ gst_adapter_flush (wav->adapter, size);
+ } else {
+ gst_buffer_unref (buf);
+ }
+ size = GST_ROUND_UP_2 (size);
+ wav->offset += size;
+ break;
+ }
default:
if (!gst_waveparse_ignore_chunk (wav, buf, tag, size))
/* need more data */
wav->bps =
(guint32) gst_util_uint64_scale ((guint64) wav->rate, wav->datasize,
(guint64) wav->fact);
- GST_INFO_OBJECT (wav, "calculated bps : %d, enabling VBR", wav->bps);
+ GST_INFO_OBJECT (wav, "calculated bps : %u, enabling VBR", wav->bps);
#endif
wav->vbr = TRUE;
}
if (gst_wavparse_calculate_duration (wav)) {
gst_segment_init (&wav->segment, GST_FORMAT_TIME);
- gst_segment_set_duration (&wav->segment, GST_FORMAT_TIME, wav->duration);
+ if (!wav->ignore_length)
+ wav->segment.duration = wav->duration;
+ if (!wav->toc)
+ gst_wavparse_create_toc (wav);
} else {
/* no bitrate, let downstream peer do the math, we'll feed it bytes. */
gst_segment_init (&wav->segment, GST_FORMAT_BYTES);
- gst_segment_set_duration (&wav->segment, GST_FORMAT_BYTES, wav->datasize);
+ if (!wav->ignore_length)
+ wav->segment.duration = wav->datasize;
}
/* now we have all the info to perform a pending seek if any, if no
if (wav->blockalign > 0)
wav->max_buf_size -= (wav->max_buf_size % wav->blockalign);
- GST_DEBUG_OBJECT (wav, "max buffer size %d", wav->max_buf_size);
+ GST_DEBUG_OBJECT (wav, "max buffer size %u", wav->max_buf_size);
return GST_FLOW_OK;
{
GST_ELEMENT_ERROR (wav, STREAM, FAILED, (NULL),
("Stream claims blockalign = %u, which is more than %u - invalid data",
- wav->blockalign, wav->channels * (guint) ceil (wav->depth / 8.0)));
+ wav->blockalign, wav->channels * ((wav->depth + 7) / 8)));
goto fail;
}
invalid_bps:
unknown_format:
{
GST_ELEMENT_ERROR (wav, STREAM, TYPE_NOT_FOUND, (NULL),
- ("No caps found for format 0x%x, %d channels, %d Hz",
+ ("No caps found for format 0x%x, %u channels, %u Hz",
wav->format, wav->channels, wav->rate));
goto fail;
}
if (wav->caps) {
s = gst_caps_get_structure (wav->caps, 0);
- if (s && gst_structure_has_name (s, "audio/x-raw-int") && buf != NULL) {
+ if (s && gst_structure_has_name (s, "audio/x-raw") && buf != NULL) {
GstTypeFindProbability prob;
GstCaps *tf_caps;
}
}
- gst_wavparse_create_sourcepad (wav);
- gst_pad_set_active (wav->srcpad, TRUE);
gst_pad_set_caps (wav->srcpad, wav->caps);
gst_caps_replace (&wav->caps, NULL);
- gst_element_add_pad (GST_ELEMENT_CAST (wav), wav->srcpad);
- gst_element_no_more_pads (GST_ELEMENT_CAST (wav));
-
- if (wav->close_segment) {
- GST_DEBUG_OBJECT (wav, "Send close segment event on newpad");
- gst_pad_push_event (wav->srcpad, wav->close_segment);
- wav->close_segment = NULL;
- }
if (wav->start_segment) {
GST_DEBUG_OBJECT (wav, "Send start segment event on newpad");
gst_pad_push_event (wav->srcpad, wav->start_segment);
}
if (wav->tags) {
- gst_element_found_tags_for_pad (GST_ELEMENT_CAST (wav), wav->srcpad,
- wav->tags);
+ gst_pad_push_event (wav->srcpad, gst_event_new_tag ("GstParser",
+ wav->tags));
wav->tags = NULL;
}
}
* amounts of data regardless of the playback rate */
desired =
MIN (gst_guint64_to_gdouble (wav->dataleft),
- wav->max_buf_size * wav->segment.abs_rate);
+ wav->max_buf_size * ABS (wav->segment.rate));
if (desired >= wav->blockalign && wav->blockalign > 0)
desired -= (desired % wav->blockalign);
if (G_UNLIKELY (extra)) {
extra = wav->bytes_per_sample - extra;
if (extra <= avail) {
- GST_DEBUG_OBJECT (wav, "flushing %d bytes to sample boundary", extra);
+ GST_DEBUG_OBJECT (wav, "flushing %u bytes to sample boundary", extra);
gst_adapter_flush (wav->adapter, extra);
wav->offset += extra;
wav->dataleft -= extra;
goto iterate_adapter;
} else {
- GST_DEBUG_OBJECT (wav, "flushing %d bytes", avail);
+ GST_DEBUG_OBJECT (wav, "flushing %u bytes", avail);
gst_adapter_clear (wav->adapter);
wav->offset += avail;
wav->dataleft -= avail;
}
if (avail < desired) {
- GST_LOG_OBJECT (wav, "Got only %d bytes of data from the sinkpad", avail);
+ GST_LOG_OBJECT (wav, "Got only %u bytes of data from the sinkpad", avail);
return GST_FLOW_OK;
}
goto pull_error;
/* we may get a short buffer at the end of the file */
- if (GST_BUFFER_SIZE (buf) < desired) {
- GST_LOG_OBJECT (wav, "Got only %u bytes of data", GST_BUFFER_SIZE (buf));
- if (GST_BUFFER_SIZE (buf) >= wav->blockalign) {
- buf = gst_buffer_make_metadata_writable (buf);
- GST_BUFFER_SIZE (buf) -= (GST_BUFFER_SIZE (buf) % wav->blockalign);
+ if (gst_buffer_get_size (buf) < desired) {
+ gsize size = gst_buffer_get_size (buf);
+
+ GST_LOG_OBJECT (wav, "Got only %" G_GSIZE_FORMAT " bytes of data", size);
+ if (size >= wav->blockalign) {
+ buf = gst_buffer_make_writable (buf);
+ gst_buffer_resize (buf, 0, size - (size % wav->blockalign));
} else {
gst_buffer_unref (buf);
goto found_eos;
}
}
- obtained = GST_BUFFER_SIZE (buf);
+ obtained = gst_buffer_get_size (buf);
/* our positions in bytes */
pos = wav->offset - wav->datastart;
nextpos = pos + obtained;
/* update offsets, does not overflow. */
+ buf = gst_buffer_make_writable (buf);
GST_BUFFER_OFFSET (buf) = pos / wav->bytes_per_sample;
GST_BUFFER_OFFSET_END (buf) = nextpos / wav->bytes_per_sample;
/* this will also push the segment events */
gst_wavparse_add_src_pad (wav, buf);
} else {
- /* If we have a pending close/start segment, send it now. */
- if (G_UNLIKELY (wav->close_segment != NULL)) {
- gst_pad_push_event (wav->srcpad, wav->close_segment);
- wav->close_segment = NULL;
- }
+ /* If we have a pending start segment, send it now. */
if (G_UNLIKELY (wav->start_segment != NULL)) {
gst_pad_push_event (wav->srcpad, wav->start_segment);
wav->start_segment = NULL;
if (wav->bps > 0) {
/* and timestamps if we have a bitrate, be careful for overflows */
- timestamp = uint64_ceiling_scale (pos, GST_SECOND, (guint64) wav->bps);
+ timestamp =
+ gst_util_uint64_scale_ceil (pos, GST_SECOND, (guint64) wav->bps);
next_timestamp =
- uint64_ceiling_scale (nextpos, GST_SECOND, (guint64) wav->bps);
+ gst_util_uint64_scale_ceil (nextpos, GST_SECOND, (guint64) wav->bps);
duration = next_timestamp - timestamp;
/* update current running segment position */
if (G_LIKELY (next_timestamp >= wav->segment.start))
- gst_segment_set_last_stop (&wav->segment, GST_FORMAT_TIME,
- next_timestamp);
+ wav->segment.position = next_timestamp;
} else if (wav->fact) {
guint64 bps =
gst_util_uint64_scale_int (wav->datasize, wav->rate, wav->fact);
/* and timestamps if we have a bitrate, be careful for overflows */
- timestamp = uint64_ceiling_scale (pos, GST_SECOND, bps);
- next_timestamp = uint64_ceiling_scale (nextpos, GST_SECOND, bps);
+ timestamp = gst_util_uint64_scale_ceil (pos, GST_SECOND, bps);
+ next_timestamp = gst_util_uint64_scale_ceil (nextpos, GST_SECOND, bps);
duration = next_timestamp - timestamp;
} else {
/* no bitrate, all we know is that the first sample has timestamp 0, all
duration = GST_CLOCK_TIME_NONE;
/* update current running segment position with byte offset */
if (G_LIKELY (nextpos >= wav->segment.start))
- gst_segment_set_last_stop (&wav->segment, GST_FORMAT_BYTES, nextpos);
+ wav->segment.position = nextpos;
}
if ((pos > 0) && wav->vbr) {
/* don't set timestamps for VBR files if it's not the first buffer */
GST_BUFFER_TIMESTAMP (buf) = timestamp;
GST_BUFFER_DURATION (buf) = duration;
- /* don't forget to set the caps on the buffer */
- gst_buffer_set_caps (buf, GST_PAD_CAPS (wav->srcpad));
-
GST_LOG_OBJECT (wav,
"Got buffer. timestamp:%" GST_TIME_FORMAT " , duration:%" GST_TIME_FORMAT
- ", size:%u", GST_TIME_ARGS (timestamp), GST_TIME_ARGS (duration),
- GST_BUFFER_SIZE (buf));
+ ", size:%" G_GSIZE_FORMAT, GST_TIME_ARGS (timestamp),
+ GST_TIME_ARGS (duration), gst_buffer_get_size (buf));
if ((res = gst_pad_push (wav->srcpad, buf)) != GST_FLOW_OK)
goto push_error;
found_eos:
{
GST_DEBUG_OBJECT (wav, "found EOS");
- return GST_FLOW_UNEXPECTED;
+ return GST_FLOW_EOS;
}
pull_error:
{
/* check if we got EOS */
- if (res == GST_FLOW_UNEXPECTED)
+ if (res == GST_FLOW_EOS)
goto found_eos;
GST_WARNING_OBJECT (wav,
const gchar *reason = gst_flow_get_name (ret);
GST_DEBUG_OBJECT (wav, "pausing task, reason %s", reason);
- wav->segment_running = FALSE;
gst_pad_pause_task (pad);
- if (ret == GST_FLOW_UNEXPECTED) {
+ if (ret == GST_FLOW_EOS) {
+ /* handle end-of-stream/segment */
+ /* so align our position with the end of it, if there is one
+ * this ensures a subsequent will arrive at correct base/acc time */
+ if (wav->segment.format == GST_FORMAT_TIME) {
+ if (wav->segment.rate > 0.0 &&
+ GST_CLOCK_TIME_IS_VALID (wav->segment.stop))
+ wav->segment.position = wav->segment.stop;
+ else if (wav->segment.rate < 0.0)
+ wav->segment.position = wav->segment.start;
+ }
/* add pad before we perform EOS */
if (G_UNLIKELY (wav->first)) {
wav->first = FALSE;
gst_element_post_message (GST_ELEMENT_CAST (wav),
gst_message_new_segment_done (GST_OBJECT_CAST (wav),
wav->segment.format, stop));
+ gst_pad_push_event (wav->srcpad,
+ gst_event_new_segment_done (wav->segment.format, stop));
} else {
- if (wav->srcpad != NULL)
- gst_pad_push_event (wav->srcpad, gst_event_new_eos ());
+ gst_pad_push_event (wav->srcpad, gst_event_new_eos ());
}
- } else if (ret == GST_FLOW_NOT_LINKED || ret < GST_FLOW_UNEXPECTED) {
+ } else if (ret == GST_FLOW_NOT_LINKED || ret < GST_FLOW_EOS) {
/* for fatal errors we post an error message, post the error
* first so the app knows about the error first. */
GST_ELEMENT_ERROR (wav, STREAM, FAILED,
(_("Internal data flow error.")),
("streaming task paused, reason %s (%d)", reason, ret));
- if (wav->srcpad != NULL)
- gst_pad_push_event (wav->srcpad, gst_event_new_eos ());
+ gst_pad_push_event (wav->srcpad, gst_event_new_eos ());
}
return;
}
}
static GstFlowReturn
-gst_wavparse_chain (GstPad * pad, GstBuffer * buf)
+gst_wavparse_chain (GstPad * pad, GstObject * parent, GstBuffer * buf)
{
GstFlowReturn ret;
- GstWavParse *wav = GST_WAVPARSE (GST_PAD_PARENT (pad));
+ GstWavParse *wav = GST_WAVPARSE (parent);
- GST_LOG_OBJECT (wav, "adapter_push %u bytes", GST_BUFFER_SIZE (buf));
+ GST_LOG_OBJECT (wav, "adapter_push %" G_GSIZE_FORMAT " bytes",
+ gst_buffer_get_size (buf));
gst_adapter_push (wav->adapter, buf);
}
static gboolean
-gst_wavparse_sink_event (GstPad * pad, GstEvent * event)
+gst_wavparse_sink_event (GstPad * pad, GstObject * parent, GstEvent * event)
{
- GstWavParse *wav = GST_WAVPARSE (GST_PAD_PARENT (pad));
+ GstWavParse *wav = GST_WAVPARSE (parent);
gboolean ret = TRUE;
GST_LOG_OBJECT (wav, "handling %s event", GST_EVENT_TYPE_NAME (event));
switch (GST_EVENT_TYPE (event)) {
- case GST_EVENT_NEWSEGMENT:
+ case GST_EVENT_CAPS:
{
- GstFormat format;
- gdouble rate, arate;
- gint64 start, stop, time, offset = 0, end_offset = -1;
- gboolean update;
+ /* discard, we'll come up with proper src caps */
+ gst_event_unref (event);
+ break;
+ }
+ case GST_EVENT_SEGMENT:
+ {
+ gint64 start, stop, offset = 0, end_offset = -1;
GstSegment segment;
/* some debug output */
- gst_segment_init (&segment, GST_FORMAT_UNDEFINED);
- gst_event_parse_new_segment_full (event, &update, &rate, &arate, &format,
- &start, &stop, &time);
- gst_segment_set_newsegment_full (&segment, update, rate, arate, format,
- start, stop, time);
- GST_DEBUG_OBJECT (wav,
- "received format %d newsegment %" GST_SEGMENT_FORMAT, format,
+ gst_event_copy_segment (event, &segment);
+ GST_DEBUG_OBJECT (wav, "received newsegment %" GST_SEGMENT_FORMAT,
&segment);
if (wav->state != GST_WAVPARSE_DATA) {
/* now we are either committed to TIME or BYTE format,
* and we only expect a BYTE segment, e.g. following a seek */
- if (format == GST_FORMAT_BYTES) {
+ if (segment.format == GST_FORMAT_BYTES) {
+ /* handle (un)signed issues */
+ start = segment.start;
+ stop = segment.stop;
if (start > 0) {
offset = start;
start -= wav->datastart;
}
if (stop > 0) {
end_offset = stop;
- stop -= wav->datastart;
- stop = MAX (stop, 0);
+ segment.stop -= wav->datastart;
+ segment.stop = MAX (stop, 0);
}
if (wav->segment.format == GST_FORMAT_TIME) {
guint64 bps = wav->bps;
if (bps) {
if (start >= 0)
start =
- uint64_ceiling_scale (start, GST_SECOND, (guint64) wav->bps);
+ gst_util_uint64_scale_ceil (start, GST_SECOND,
+ (guint64) wav->bps);
if (stop >= 0)
stop =
- uint64_ceiling_scale (stop, GST_SECOND, (guint64) wav->bps);
+ gst_util_uint64_scale_ceil (stop, GST_SECOND,
+ (guint64) wav->bps);
}
}
} else {
goto exit;
}
+ segment.start = start;
+ segment.stop = stop;
+
/* accept upstream's notion of segment and distribute along */
- gst_segment_set_newsegment_full (&wav->segment, update, rate, arate,
- wav->segment.format, start, stop, start);
+ segment.format = wav->segment.format;
+ segment.time = segment.position = segment.start;
+ segment.duration = wav->segment.duration;
+ segment.base = gst_segment_to_running_time (&wav->segment,
+ GST_FORMAT_TIME, wav->segment.position);
+
+ gst_segment_copy_into (&segment, &wav->segment);
+
/* also store the newsegment event for the streaming thread */
if (wav->start_segment)
gst_event_unref (wav->start_segment);
- wav->start_segment =
- gst_event_new_new_segment_full (update, rate, arate,
- wav->segment.format, start, stop, start);
- GST_DEBUG_OBJECT (wav, "Pushing newseg update %d, rate %g, "
- "applied rate %g, format %d, start %" G_GINT64_FORMAT ", "
- "stop %" G_GINT64_FORMAT, update, rate, arate, wav->segment.format,
- start, stop);
+ GST_DEBUG_OBJECT (wav, "Storing newseg %" GST_SEGMENT_FORMAT, &segment);
+ wav->start_segment = gst_event_new_segment (&segment);
/* stream leftover data in current segment */
gst_wavparse_flush_data (wav);
/* fall-through */
case GST_EVENT_FLUSH_STOP:
+ {
+ GstClockTime dur;
+
gst_adapter_clear (wav->adapter);
wav->discont = TRUE;
+ dur = wav->segment.duration;
+ gst_segment_init (&wav->segment, wav->segment.format);
+ wav->segment.duration = dur;
/* fall-through */
+ }
default:
- ret = gst_pad_event_default (wav->sinkpad, event);
+ ret = gst_pad_event_default (wav->sinkpad, parent, event);
break;
}
"src=%" G_GINT64_FORMAT ", offset=%" G_GINT64_FORMAT, src_value,
wavparse->offset);
if (wavparse->bps > 0)
- *dest_value = uint64_ceiling_scale (src_value, GST_SECOND,
+ *dest_value = gst_util_uint64_scale_ceil (src_value, GST_SECOND,
(guint64) wavparse->bps);
else if (wavparse->fact) {
- guint64 bps = uint64_ceiling_scale_int (wavparse->datasize,
+ guint64 bps = gst_util_uint64_scale_int_ceil (wavparse->datasize,
wavparse->rate, wavparse->fact);
- *dest_value = uint64_ceiling_scale_int (src_value, GST_SECOND, bps);
+ *dest_value =
+ gst_util_uint64_scale_int_ceil (src_value, GST_SECOND, bps);
} else {
res = FALSE;
}
}
}
-static const GstQueryType *
-gst_wavparse_get_query_types (GstPad * pad)
-{
- static const GstQueryType types[] = {
- GST_QUERY_POSITION,
- GST_QUERY_DURATION,
- GST_QUERY_CONVERT,
- GST_QUERY_SEEKING,
- 0
- };
-
- return types;
-}
-
/* handle queries for location and length in requested format */
static gboolean
-gst_wavparse_pad_query (GstPad * pad, GstQuery * query)
+gst_wavparse_pad_query (GstPad * pad, GstObject * parent, GstQuery * query)
{
gboolean res = TRUE;
- GstWavParse *wav = GST_WAVPARSE (gst_pad_get_parent (pad));
+ GstWavParse *wav = GST_WAVPARSE (parent);
/* only if we know */
if (wav->state != GST_WAVPARSE_DATA) {
- gst_object_unref (wav);
return FALSE;
}
GST_INFO_OBJECT (wav, "pos query at %" G_GINT64_FORMAT, curb);
switch (format) {
- case GST_FORMAT_TIME:
- res = gst_wavparse_pad_convert (pad, GST_FORMAT_BYTES, curb,
- &format, &cur);
- break;
- default:
+ case GST_FORMAT_BYTES:
format = GST_FORMAT_BYTES;
cur = curb;
break;
+ default:
+ res = gst_wavparse_pad_convert (pad, GST_FORMAT_BYTES, curb,
+ &format, &cur);
+ break;
}
if (res)
gst_query_set_position (query, format, cur);
gint64 duration = 0;
GstFormat format;
+ if (wav->ignore_length) {
+ res = FALSE;
+ break;
+ }
+
gst_query_parse_duration (query, &format, NULL);
switch (format) {
- case GST_FORMAT_TIME:{
+ case GST_FORMAT_BYTES:{
+ format = GST_FORMAT_BYTES;
+ duration = wav->datasize;
+ break;
+ }
+ case GST_FORMAT_TIME:
if ((res = gst_wavparse_calculate_duration (wav))) {
duration = wav->duration;
}
break;
- }
default:
- format = GST_FORMAT_BYTES;
- duration = wav->datasize;
+ res = FALSE;
break;
}
- gst_query_set_duration (query, format, duration);
+ if (res)
+ gst_query_set_duration (query, format, duration);
break;
}
case GST_QUERY_CONVERT:
break;
}
default:
- res = gst_pad_query_default (pad, query);
+ res = gst_pad_query_default (pad, parent, query);
break;
}
- gst_object_unref (wav);
return res;
}
static gboolean
-gst_wavparse_srcpad_event (GstPad * pad, GstEvent * event)
+gst_wavparse_srcpad_event (GstPad * pad, GstObject * parent, GstEvent * event)
{
- GstWavParse *wavparse = GST_WAVPARSE (gst_pad_get_parent (pad));
+ GstWavParse *wavparse = GST_WAVPARSE (parent);
gboolean res = FALSE;
GST_DEBUG_OBJECT (wavparse, "%s event", GST_EVENT_TYPE_NAME (event));
}
gst_event_unref (event);
break;
+
+ case GST_EVENT_TOC_SELECT:
+ {
+ char *uid = NULL;
+ GstTocEntry *entry = NULL;
+ GstEvent *seek_event;
+ gint64 start_pos;
+
+ if (!wavparse->toc) {
+ GST_DEBUG_OBJECT (wavparse, "no TOC to select");
+ return FALSE;
+ } else {
+ gst_event_parse_toc_select (event, &uid);
+ if (uid != NULL) {
+ GST_OBJECT_LOCK (wavparse);
+ entry = gst_toc_find_entry (wavparse->toc, uid);
+ if (entry == NULL) {
+ GST_OBJECT_UNLOCK (wavparse);
+ GST_WARNING_OBJECT (wavparse, "no TOC entry with given UID: %s",
+ uid);
+ res = FALSE;
+ } else {
+ gst_toc_entry_get_start_stop_times (entry, &start_pos, NULL);
+ GST_OBJECT_UNLOCK (wavparse);
+ seek_event = gst_event_new_seek (1.0,
+ GST_FORMAT_TIME,
+ GST_SEEK_FLAG_FLUSH,
+ GST_SEEK_TYPE_SET, start_pos, GST_SEEK_TYPE_SET, -1);
+ res = gst_wavparse_perform_seek (wavparse, seek_event);
+ gst_event_unref (seek_event);
+ }
+ g_free (uid);
+ } else {
+ GST_WARNING_OBJECT (wavparse, "received empty TOC select event");
+ res = FALSE;
+ }
+ }
+ gst_event_unref (event);
+ break;
+ }
+
default:
res = gst_pad_push_event (wavparse->sinkpad, event);
break;
}
- gst_object_unref (wavparse);
return res;
}
static gboolean
-gst_wavparse_sink_activate (GstPad * sinkpad)
+gst_wavparse_sink_activate (GstPad * sinkpad, GstObject * parent)
{
- GstWavParse *wav = GST_WAVPARSE (gst_pad_get_parent (sinkpad));
- gboolean res;
+ GstWavParse *wav = GST_WAVPARSE (parent);
+ GstQuery *query;
+ gboolean pull_mode;
if (wav->adapter) {
gst_adapter_clear (wav->adapter);
wav->adapter = NULL;
}
- if (gst_pad_check_pull_range (sinkpad)) {
- GST_DEBUG ("going to pull mode");
- wav->streaming = FALSE;
- res = gst_pad_activate_pull (sinkpad, TRUE);
- } else {
- GST_DEBUG ("going to push (streaming) mode");
+ query = gst_query_new_scheduling ();
+
+ if (!gst_pad_peer_query (sinkpad, query)) {
+ gst_query_unref (query);
+ goto activate_push;
+ }
+
+ pull_mode = gst_query_has_scheduling_mode (query, GST_PAD_MODE_PULL);
+ gst_query_unref (query);
+
+ if (!pull_mode)
+ goto activate_push;
+
+ GST_DEBUG_OBJECT (sinkpad, "activating pull");
+ wav->streaming = FALSE;
+ return gst_pad_activate_mode (sinkpad, GST_PAD_MODE_PULL, TRUE);
+
+activate_push:
+ {
+ GST_DEBUG_OBJECT (sinkpad, "activating push");
wav->streaming = TRUE;
wav->adapter = gst_adapter_new ();
- res = gst_pad_activate_push (sinkpad, TRUE);
+ return gst_pad_activate_mode (sinkpad, GST_PAD_MODE_PUSH, TRUE);
}
- gst_object_unref (wav);
- return res;
}
static gboolean
-gst_wavparse_sink_activate_pull (GstPad * sinkpad, gboolean active)
+gst_wavparse_sink_activate_mode (GstPad * sinkpad, GstObject * parent,
+ GstPadMode mode, gboolean active)
{
- GstWavParse *wav = GST_WAVPARSE (GST_OBJECT_PARENT (sinkpad));
+ gboolean res;
- if (active) {
- /* if we have a scheduler we can start the task */
- wav->segment_running = TRUE;
- return gst_pad_start_task (sinkpad, (GstTaskFunction) gst_wavparse_loop,
- sinkpad);
- } else {
- wav->segment_running = FALSE;
- return gst_pad_stop_task (sinkpad);
+ switch (mode) {
+ case GST_PAD_MODE_PUSH:
+ res = TRUE;
+ break;
+ case GST_PAD_MODE_PULL:
+ if (active) {
+ /* if we have a scheduler we can start the task */
+ res = gst_pad_start_task (sinkpad, (GstTaskFunction) gst_wavparse_loop,
+ sinkpad, NULL);
+ } else {
+ res = gst_pad_stop_task (sinkpad);
+ }
+ break;
+ default:
+ res = FALSE;
+ break;
}
-};
+ return res;
+}
static GstStateChangeReturn
gst_wavparse_change_state (GstElement * element, GstStateChange transition)
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
break;
case GST_STATE_CHANGE_PAUSED_TO_READY:
- gst_wavparse_destroy_sourcepad (wav);
gst_wavparse_reset (wav);
break;
case GST_STATE_CHANGE_READY_TO_NULL:
return ret;
}
+static void
+gst_wavparse_set_property (GObject * object, guint prop_id,
+ const GValue * value, GParamSpec * pspec)
+{
+ GstWavParse *self;
+
+ g_return_if_fail (GST_IS_WAVPARSE (object));
+ self = GST_WAVPARSE (object);
+
+ switch (prop_id) {
+ case PROP_IGNORE_LENGTH:
+ self->ignore_length = g_value_get_boolean (value);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (self, prop_id, pspec);
+ }
+
+}
+
+static void
+gst_wavparse_get_property (GObject * object, guint prop_id,
+ GValue * value, GParamSpec * pspec)
+{
+ GstWavParse *self;
+
+ g_return_if_fail (GST_IS_WAVPARSE (object));
+ self = GST_WAVPARSE (object);
+
+ switch (prop_id) {
+ case PROP_IGNORE_LENGTH:
+ g_value_set_boolean (value, self->ignore_length);
+ break;
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (self, prop_id, pspec);
+ }
+}
+
static gboolean
plugin_init (GstPlugin * plugin)
{
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
GST_VERSION_MINOR,
- "wavparse",
+ wavparse,
"Parse a .wav file into raw audio",
plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)