[svn r660] implemented progress function trunk
authorrenatofilho
Tue May 15 20:16:26 2007 +0100 (2007-05-15)
branchtrunk
changeset 65476b9c97faada
parent 653 3433df0d6ae3
child 655 ad1457d65f74
[svn r660] implemented progress function
gmyth-stream/gmemcoder/src/gmencoder.c
     1.1 --- a/gmyth-stream/gmemcoder/src/gmencoder.c	Tue May 15 18:25:19 2007 +0100
     1.2 +++ b/gmyth-stream/gmemcoder/src/gmencoder.c	Tue May 15 20:16:26 2007 +0100
     1.3 @@ -46,6 +46,7 @@
     1.4      GstClockTime audiot;
     1.5      gint fd;
     1.6  	gint sources;
     1.7 +	gint tick_id;
     1.8  };
     1.9  
    1.10  enum {
    1.11 @@ -100,6 +101,8 @@
    1.12                                            const gchar* audio_encode,
    1.13                                            gchar** audio_encode_prop,
    1.14                                            guint audio_rate);
    1.15 +static gboolean _tick_cb 				 (gpointer data);
    1.16 +
    1.17  
    1.18  
    1.19  
    1.20 @@ -604,6 +607,8 @@
    1.21      g_return_if_fail (priv->ready == FALSE);
    1.22      priv->ready = TRUE;
    1.23      gst_element_set_state (priv->pipe, GST_STATE_PLAYING);
    1.24 +
    1.25 +	priv->tick_id = g_timeout_add (500, _tick_cb, self);
    1.26  }
    1.27  
    1.28  void
    1.29 @@ -622,6 +627,11 @@
    1.30      GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (self);
    1.31  
    1.32  	g_debug ("g_mencoder_close_stream");
    1.33 +	if (priv->tick_id != 0) {			
    1.34 +		g_source_remove (priv->tick_id);
    1.35 +		priv->tick_id = 0;
    1.36 +	}
    1.37 +
    1.38      if (priv->pipe != NULL) { 
    1.39          gst_element_set_state (priv->pipe, GST_STATE_NULL);
    1.40          gst_object_unref (priv->pipe);
    1.41 @@ -631,6 +641,8 @@
    1.42          priv->sink = NULL;
    1.43      }
    1.44      priv->ready = FALSE;
    1.45 +
    1.46 +
    1.47  }
    1.48  
    1.49  static GstElement*
    1.50 @@ -937,8 +949,11 @@
    1.51              priv->ready = FALSE;
    1.52  		    g_signal_emit (user_data, g_mencoder_signals[EOS], 0);
    1.53  		    break;		
    1.54 +
    1.55  		default:
    1.56 +		{
    1.57  			break;
    1.58 +		}
    1.59  	}
    1.60  	return TRUE;
    1.61  }
    1.62 @@ -985,3 +1000,20 @@
    1.63      g_warning  ("Unknown Type");
    1.64      //priv->ready = FALSE;
    1.65  }
    1.66 +
    1.67 +static gboolean
    1.68 +_tick_cb (gpointer user_data)
    1.69 +{
    1.70 +	GstFormat format = GST_FORMAT_TIME;
    1.71 +	gint64 cur = 0;
    1.72 +	gint64 duration = 0;
    1.73 +
    1.74 +	GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (user_data);
    1.75 +
    1.76 +	if (gst_element_query_duration (priv->pipe, &format, &duration)) {
    1.77 +		gst_element_query_position (priv->pipe, &format, &cur);
    1.78 +		g_print ("PROGRESS:%lli%\n", (100 * cur) / duration); 
    1.79 +	}
    1.80 +
    1.81 +	return TRUE;
    1.82 +}