remove infinite loop code cleanup

Original commit message from CVS:
remove infinite loop
code cleanup
This commit is contained in:
Jeremy Simon 2002-12-07 15:28:24 +00:00
parent 92f37b4e01
commit c99d527681
3 changed files with 98 additions and 96 deletions

2
common

@ -1 +1 @@
Subproject commit c73793f7022cbc8ffd39f9c0b0587078f47c0b06 Subproject commit 9d5642850b94f5bc21d565f8c900a0606fbb518f

View file

@ -117,6 +117,8 @@ static GstElementStateReturn
static GstElementClass *parent_class = NULL; static GstElementClass *parent_class = NULL;
gboolean first_time = TRUE, need_caps = FALSE;
#define GST_TYPE_MODPLUG_MIXFREQ (gst_modplug_mixfreq_get_type()) #define GST_TYPE_MODPLUG_MIXFREQ (gst_modplug_mixfreq_get_type())
static GType static GType
@ -300,8 +302,6 @@ gst_modplug_init (GstModPlug *modplug)
modplug->srcpad = gst_pad_new_from_template( GST_PAD_TEMPLATE_GET (modplug_src_template_factory), "src"); modplug->srcpad = gst_pad_new_from_template( GST_PAD_TEMPLATE_GET (modplug_src_template_factory), "src");
gst_element_add_pad(GST_ELEMENT(modplug),modplug->srcpad); gst_element_add_pad(GST_ELEMENT(modplug),modplug->srcpad);
modplug->bs = gst_bytestream_new (modplug->sinkpad);
gst_pad_set_event_function (modplug->srcpad, (GstPadEventFunction)GST_DEBUG_FUNCPTR(gst_modplug_src_event)); gst_pad_set_event_function (modplug->srcpad, (GstPadEventFunction)GST_DEBUG_FUNCPTR(gst_modplug_src_event));
gst_pad_set_query_function (modplug->srcpad, gst_modplug_src_query); gst_pad_set_query_function (modplug->srcpad, gst_modplug_src_query);
@ -323,7 +323,7 @@ gst_modplug_init (GstModPlug *modplug)
modplug->channel = 2; modplug->channel = 2;
modplug->frequency = 44100; modplug->frequency = 44100;
modplug->mSoundFile = new CSoundFile; first_time = TRUE;
} }
@ -356,7 +356,7 @@ gst_modplug_src_query (GstPad *pad, GstPadQueryType type,
{ {
gboolean res = TRUE; gboolean res = TRUE;
GstModPlug *modplug; GstModPlug *modplug;
float tmp; gfloat tmp;
modplug = GST_MODPLUG (gst_pad_get_parent (pad)); modplug = GST_MODPLUG (gst_pad_get_parent (pad));
@ -390,8 +390,6 @@ gst_modplug_src_query (GstPad *pad, GstPadQueryType type,
} }
static gboolean static gboolean
gst_modplug_src_event (GstPad *pad, GstEvent *event) gst_modplug_src_event (GstPad *pad, GstEvent *event)
{ {
@ -427,35 +425,41 @@ gst_modplug_src_event (GstPad *pad, GstEvent *event)
} }
static void static void
gst_modplug_loop (GstElement *element) gst_modplug_loop (GstElement *element)
{ {
GstModPlug *modplug; GstModPlug *modplug;
GstBuffer *buffer_out; GstBuffer *buffer_out;
gint mode16bits; GstEvent *event;
guint64 total_samples, sync_point;
float temp;
g_return_if_fail (element != NULL); g_return_if_fail (element != NULL);
g_return_if_fail (GST_IS_MODPLUG (element)); g_return_if_fail (GST_IS_MODPLUG (element));
modplug = GST_MODPLUG (element); modplug = GST_MODPLUG (element);
srcpad = modplug->srcpad;
modplug->buffer_in = (guint8 *) g_malloc( gst_bytestream_length (modplug->bs)); if (first_time)
{
gint mode16bits;
modplug->bs = gst_bytestream_new (modplug->sinkpad);
gst_bytestream_peek_bytes (modplug->bs, &modplug->buffer_in, gst_bytestream_length (modplug->bs)); gst_bytestream_peek_bytes (modplug->bs, &modplug->buffer_in, gst_bytestream_length (modplug->bs));
if ( modplug->_16bit )
mode16bits = 16;
else
mode16bits = 8;
gst_modplug_setup( modplug );
modplug->mSoundFile = new CSoundFile; modplug->mSoundFile = new CSoundFile;
modplug->mSoundFile->Create( modplug->buffer_in, gst_bytestream_length (modplug->bs)); modplug->mSoundFile->Create( modplug->buffer_in, gst_bytestream_length (modplug->bs));
gst_modplug_setup( modplug );
modplug->length = 1152 * modplug->channel;
if ( modplug->_16bit )
{
modplug->length *= 2;
mode16bits = 16;
}
else
mode16bits = 8;
modplug->audiobuffer = (guchar *) g_malloc (modplug->length);
gst_pad_try_set_caps (modplug->srcpad, gst_pad_try_set_caps (modplug->srcpad,
GST_CAPS_NEW ( GST_CAPS_NEW (
@ -470,24 +474,18 @@ gst_modplug_loop (GstElement *element)
"rate", GST_PROPS_INT (modplug->frequency), "rate", GST_PROPS_INT (modplug->frequency),
"channels", GST_PROPS_INT (modplug->channel))); "channels", GST_PROPS_INT (modplug->channel)));
modplug->length = 1152 * modplug->channel; first_time = FALSE;
}
if ( modplug->_16bit )
modplug->length *= 2;
modplug->audiobuffer = (guchar *) g_malloc( modplug->length );
total_samples = 0;
sync_point = 0;
do {
if (modplug->seek_at != -1) if (modplug->seek_at != -1)
{ {
int seek_to_pos; gint seek_to_pos;
gint64 total; gint64 total;
gfloat temp;
total = modplug->mSoundFile->GetSongTime() * GST_SECOND; total = modplug->mSoundFile->GetSongTime() * GST_SECOND;
temp = (float) total / modplug->seek_at; temp = (gfloat) total / modplug->seek_at;
seek_to_pos = (int) (modplug->mSoundFile->GetMaxPosition() / temp); seek_to_pos = (int) (modplug->mSoundFile->GetMaxPosition() / temp);
modplug->mSoundFile->SetCurrentPos (seek_to_pos); modplug->mSoundFile->SetCurrentPos (seek_to_pos);
@ -501,7 +499,7 @@ gst_modplug_loop (GstElement *element)
GST_BUFFER_DATA (buffer_out) = (guchar *) g_memdup (modplug->audiobuffer, modplug->length); GST_BUFFER_DATA (buffer_out) = (guchar *) g_memdup (modplug->audiobuffer, modplug->length);
GST_BUFFER_SIZE (buffer_out) = modplug->length; GST_BUFFER_SIZE (buffer_out) = modplug->length;
total_samples+=1152; modplug->total_samples += 1152;
if (modplug->seek_at != -1) if (modplug->seek_at != -1)
{ {
@ -515,26 +513,22 @@ gst_modplug_loop (GstElement *element)
time = (gint64) (total * modplug->mSoundFile->GetCurrentPos()) / modplug->mSoundFile->GetMaxPosition(); time = (gint64) (total * modplug->mSoundFile->GetCurrentPos()) / modplug->mSoundFile->GetMaxPosition();
discont = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME, time, NULL); discont = gst_event_new_discontinuous (FALSE, GST_FORMAT_TIME, time, NULL);
total_samples = time * modplug->frequency / GST_SECOND ; modplug->total_samples = time * modplug->frequency / GST_SECOND ;
gst_pad_push (modplug->srcpad, GST_BUFFER (discont)); gst_pad_push (modplug->srcpad, GST_BUFFER (discont));
} }
GST_BUFFER_TIMESTAMP( buffer_out ) = total_samples * GST_SECOND / modplug->frequency; GST_BUFFER_TIMESTAMP (buffer_out) = modplug->total_samples * GST_SECOND / modplug->frequency;
gst_pad_push( srcpad, buffer_out ); gst_pad_push (modplug->srcpad, buffer_out);
gst_element_yield (element);
} }
else else
{ {
free( modplug->audiobuffer ); event = gst_event_new (GST_EVENT_EOS);
gst_pad_push (modplug->srcpad, GST_BUFFER (gst_event_new (GST_EVENT_EOS))); gst_pad_push (modplug->srcpad, GST_BUFFER (event));
gst_element_set_eos (GST_ELEMENT (modplug)); gst_element_set_eos (element);
break;
} }
} }
while ( 1 );
}
static GstElementStateReturn static GstElementStateReturn
@ -546,21 +540,28 @@ gst_modplug_change_state (GstElement *element)
switch (GST_STATE_TRANSITION (element)) { switch (GST_STATE_TRANSITION (element)) {
case GST_STATE_NULL_TO_READY: case GST_STATE_NULL_TO_READY:
break; break;
case GST_STATE_READY_TO_PAUSED: case GST_STATE_READY_TO_PAUSED:
first_time = TRUE;
modplug->total_samples = 0;
modplug->seek_at = -1;
break; break;
case GST_STATE_PAUSED_TO_PLAYING: case GST_STATE_PAUSED_TO_PLAYING:
break; break;
case GST_STATE_PLAYING_TO_PAUSED: case GST_STATE_PLAYING_TO_PAUSED:
break; break;
case GST_STATE_PAUSED_TO_READY: case GST_STATE_PAUSED_TO_READY:
/* modplug->mSoundFile->SetCurrentPos( 0 ); */ gst_bytestream_destroy (modplug->bs);
modplug->mSoundFile->Destroy ();
g_free (modplug->audiobuffer);
g_free (modplug->buffer_in);
modplug->bs = NULL;
modplug->audiobuffer = NULL;
modplug->buffer_in = NULL;
break; break;
case GST_STATE_READY_TO_NULL: case GST_STATE_READY_TO_NULL:
/* g_free( modplug->buffer_in ); break;
g_free( modplug->audiobuffer ); default:
modplug->mSoundFile->Destroy();*/
break; break;
} }

View file

@ -70,6 +70,7 @@ struct _GstModPlug {
gint32 length; gint32 length;
gboolean restart; gboolean restart;
gint64 seek_at; gint64 seek_at;
guint64 total_samples;
CSoundFile *mSoundFile; CSoundFile *mSoundFile;
}; };