From 6f92032333c89d168b400d826dbae46506d97aac Mon Sep 17 00:00:00 2001 From: Jeremy Simon Date: Mon, 20 Jan 2003 21:02:58 +0000 Subject: handle bytestream event Original commit message from CVS: handle bytestream event --- gst/modplug/gstmodplug.cc | 56 +++++++++++++++++++++++++++++++++++++++-------- gst/modplug/gstmodplug.h | 2 -- 2 files changed, 47 insertions(+), 11 deletions(-) diff --git a/gst/modplug/gstmodplug.cc b/gst/modplug/gstmodplug.cc index a6f6ca3db..8329eadd5 100644 --- a/gst/modplug/gstmodplug.cc +++ b/gst/modplug/gstmodplug.cc @@ -359,6 +359,8 @@ gst_modplug_init (GstModPlug *modplug) modplug->_16bit = TRUE; modplug->channel = 2; modplug->frequency = 44100; + + modplug->state = MODPLUG_STATE_NEED_TUNE; } @@ -410,6 +412,7 @@ gst_modplug_get_query_types (GstPad *pad) GST_QUERY_POSITION, (GstQueryType)0 }; + return gst_modplug_src_query_types; } @@ -575,6 +578,29 @@ modplug_negotiate (GstModPlug *modplug) return TRUE; } + +static void +gst_modplug_handle_event (GstModPlug *modplug) +{ + guint32 remaining; + GstEvent *event; + + gst_bytestream_get_status (modplug->bs, &remaining, &event); + + if (!event) { + g_warning ("modplug: no bytestream event"); + return; + } + + switch (GST_EVENT_TYPE (event)) { + case GST_EVENT_DISCONTINUOUS: + gst_bytestream_flush_fast (modplug->bs, remaining); + default: + gst_pad_event_default (modplug->sinkpad, event); + break; + } +} + static void gst_modplug_loop (GstElement *element) { @@ -589,8 +615,7 @@ gst_modplug_loop (GstElement *element) if (modplug->state == MODPLUG_STATE_NEED_TUNE) { /* GstBuffer *buf;*/ - - modplug->total_samples = 0; + modplug->seek_at = -1; modplug->need_discont = FALSE; modplug->eos = FALSE; @@ -624,10 +649,21 @@ gst_modplug_loop (GstElement *element) } */ - modplug->song_size = gst_bytestream_length (modplug->bs); - - gst_bytestream_peek_bytes (modplug->bs, &modplug->buffer_in, modplug->song_size); - modplug->state = MODPLUG_STATE_LOAD_TUNE; + if (modplug->bs) + { + guint64 got; + + modplug->song_size = gst_bytestream_length (modplug->bs); + + got = gst_bytestream_peek_bytes (modplug->bs, &modplug->buffer_in, modplug->song_size); + + if ( got < modplug->song_size ) + { + gst_modplug_handle_event (modplug); + return; + } + modplug->state = MODPLUG_STATE_LOAD_TUNE; + } } if (modplug->state == MODPLUG_STATE_LOAD_TUNE) @@ -649,7 +685,7 @@ gst_modplug_loop (GstElement *element) modplug->state = MODPLUG_STATE_PLAY_TUNE; } - if (modplug->state == MODPLUG_STATE_PLAY_TUNE) + if (modplug->state == MODPLUG_STATE_PLAY_TUNE && !modplug->eos) { if (modplug->seek_at != -1) { @@ -698,8 +734,9 @@ gst_modplug_loop (GstElement *element) if (GST_PAD_IS_USABLE (modplug->srcpad)) { event = gst_event_new (GST_EVENT_EOS); - gst_pad_push (modplug->srcpad, GST_BUFFER (event)); - gst_element_set_eos (element); + gst_pad_push (modplug->srcpad, GST_BUFFER (event)); + gst_element_set_eos (element); + modplug->eos = TRUE; } } } @@ -733,6 +770,7 @@ gst_modplug_change_state (GstElement *element) g_free (modplug->buffer_in); modplug->audiobuffer = NULL; modplug->buffer_in = NULL; + gst_caps_unref (modplug->streaminfo); modplug->state = MODPLUG_STATE_NEED_TUNE; break; case GST_STATE_READY_TO_NULL: diff --git a/gst/modplug/gstmodplug.h b/gst/modplug/gstmodplug.h index 901670c80..0e8356c88 100644 --- a/gst/modplug/gstmodplug.h +++ b/gst/modplug/gstmodplug.h @@ -75,9 +75,7 @@ struct _GstModPlug { gboolean need_discont; gboolean eos; gint64 seek_at; - guint64 total_samples; guint64 song_size; - guint64 bytes_read; CSoundFile *mSoundFile; }; -- cgit v1.2.1