# HG changeset patch # User renatofilho # Date 1179256586 -3600 # Node ID 76b9c97faada8f47c7b02ac8ef8815d96fe57c93 # Parent 3433df0d6ae3ed1766e93672e4821e8a7fa60c18 [svn r660] implemented progress function diff -r 3433df0d6ae3 -r 76b9c97faada gmyth-stream/gmemcoder/src/gmencoder.c --- a/gmyth-stream/gmemcoder/src/gmencoder.c Tue May 15 18:25:19 2007 +0100 +++ b/gmyth-stream/gmemcoder/src/gmencoder.c Tue May 15 20:16:26 2007 +0100 @@ -46,6 +46,7 @@ GstClockTime audiot; gint fd; gint sources; + gint tick_id; }; enum { @@ -100,6 +101,8 @@ const gchar* audio_encode, gchar** audio_encode_prop, guint audio_rate); +static gboolean _tick_cb (gpointer data); + @@ -604,6 +607,8 @@ g_return_if_fail (priv->ready == FALSE); priv->ready = TRUE; gst_element_set_state (priv->pipe, GST_STATE_PLAYING); + + priv->tick_id = g_timeout_add (500, _tick_cb, self); } void @@ -622,6 +627,11 @@ GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (self); g_debug ("g_mencoder_close_stream"); + if (priv->tick_id != 0) { + g_source_remove (priv->tick_id); + priv->tick_id = 0; + } + if (priv->pipe != NULL) { gst_element_set_state (priv->pipe, GST_STATE_NULL); gst_object_unref (priv->pipe); @@ -631,6 +641,8 @@ priv->sink = NULL; } priv->ready = FALSE; + + } static GstElement* @@ -937,8 +949,11 @@ priv->ready = FALSE; g_signal_emit (user_data, g_mencoder_signals[EOS], 0); break; + default: + { break; + } } return TRUE; } @@ -985,3 +1000,20 @@ g_warning ("Unknown Type"); //priv->ready = FALSE; } + +static gboolean +_tick_cb (gpointer user_data) +{ + GstFormat format = GST_FORMAT_TIME; + gint64 cur = 0; + gint64 duration = 0; + + GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (user_data); + + if (gst_element_query_duration (priv->pipe, &format, &duration)) { + gst_element_query_position (priv->pipe, &format, &cur); + g_print ("PROGRESS:%lli%\n", (100 * cur) / duration); + } + + return TRUE; +}