# HG changeset patch # User renatofilho # Date 1179337529 -3600 # Node ID a05b421242e4ea30500f92714edd88625520cb53 # Parent 85d9b58f86b0575c67889f6e3ecfca5bf6e934eb [svn r677] fixed bug on progress message diff -r 85d9b58f86b0 -r a05b421242e4 gmyth-stream/gmemcoder/src/gmencoder.c --- a/gmyth-stream/gmemcoder/src/gmencoder.c Wed May 16 17:04:46 2007 +0100 +++ b/gmyth-stream/gmemcoder/src/gmencoder.c Wed May 16 18:45:29 2007 +0100 @@ -40,6 +40,7 @@ GstElement *abin; GstElement *vbin; GstElement *sink; + GstElement *src; gboolean ready; SetupInfo *info; GstClockTime videot; @@ -47,6 +48,7 @@ gint fd; gint sources; gint tick_id; + gint64 duration; }; enum { @@ -238,8 +240,6 @@ GstElement *ret; int i; - g_debug ("Creating element: %s", factory_name); - ret = gst_element_factory_make (factory_name, element_name); if (ret == NULL) return NULL; @@ -521,6 +521,8 @@ if (src == NULL) return FALSE; + priv->src = gst_bin_get_by_name (GST_BIN (src), "src"); + gst_bin_add (GST_BIN (priv->pipe), src); #ifdef SUPPORT_MULT_INPUT @@ -802,12 +804,12 @@ _create_source (const gchar* uri) { - GstElement *bsrc; - GstElement *src; - GstElement *aqueue; - GstElement *vqueue; - GstElement *decode; - GstPad *src_pad; + GstElement *bsrc = NULL; + GstElement *src = NULL; + GstElement *aqueue = NULL; + GstElement *vqueue = NULL; + GstElement *decode = NULL; + GstPad *src_pad = NULL; bsrc = gst_bin_new (NULL); @@ -949,7 +951,15 @@ priv->ready = FALSE; g_signal_emit (user_data, g_mencoder_signals[EOS], 0); break; - + case GST_MESSAGE_DURATION: + { + GstFormat format; + gint64 duration; + gst_message_parse_duration (msg, &format, &duration); + if (format == GST_FORMAT_BYTES) + priv->duration = duration; + break; + } default: { break; @@ -1004,15 +1014,20 @@ static gboolean _tick_cb (gpointer user_data) { - GstFormat format = GST_FORMAT_TIME; + GstFormat format = GST_FORMAT_BYTES; 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); + if (priv->duration == 0) { + gint64 d = 0; + if (gst_element_query_duration (priv->src, &format, &d)) + priv->duration = d; + } + + if (priv->duration != 0) { + gst_element_query_position (priv->src, &format, &cur); + g_print ("PROGRESS:%lli\n", (99 * cur) / priv->duration); } return TRUE;