gmyth-stream/gmemcoder/src/gmencoder.c
branchtrunk
changeset 673 5ee8c970d982
parent 654 76b9c97faada
child 678 89bdaa9e72bf
     1.1 --- a/gmyth-stream/gmemcoder/src/gmencoder.c	Tue May 15 20:16:26 2007 +0100
     1.2 +++ b/gmyth-stream/gmemcoder/src/gmencoder.c	Wed May 16 18:47:09 2007 +0100
     1.3 @@ -40,6 +40,7 @@
     1.4  	GstElement *abin;
     1.5  	GstElement *vbin;
     1.6  	GstElement *sink;
     1.7 +	GstElement *src;
     1.8  	gboolean ready;
     1.9      SetupInfo *info;
    1.10      GstClockTime videot;
    1.11 @@ -47,6 +48,7 @@
    1.12      gint fd;
    1.13  	gint sources;
    1.14  	gint tick_id;
    1.15 +	gint64 duration;
    1.16  };
    1.17  
    1.18  enum {
    1.19 @@ -238,8 +240,6 @@
    1.20      GstElement *ret;
    1.21      int i;
    1.22  
    1.23 -    g_debug ("Creating element: %s", factory_name);
    1.24 -
    1.25      ret = gst_element_factory_make (factory_name, element_name);
    1.26      if (ret == NULL)
    1.27          return NULL;
    1.28 @@ -521,6 +521,8 @@
    1.29      if (src == NULL) 
    1.30          return FALSE;
    1.31  
    1.32 +	priv->src = gst_bin_get_by_name (GST_BIN (src), "src");
    1.33 +
    1.34      gst_bin_add (GST_BIN (priv->pipe), src);
    1.35  
    1.36  #ifdef SUPPORT_MULT_INPUT
    1.37 @@ -802,12 +804,12 @@
    1.38  _create_source (const gchar* uri)
    1.39  {
    1.40  
    1.41 -    GstElement *bsrc;
    1.42 -    GstElement *src;
    1.43 -    GstElement *aqueue;
    1.44 -    GstElement *vqueue;
    1.45 -    GstElement *decode;
    1.46 -    GstPad *src_pad;
    1.47 +    GstElement *bsrc = NULL;
    1.48 +    GstElement *src = NULL;
    1.49 +    GstElement *aqueue = NULL;
    1.50 +    GstElement *vqueue = NULL;
    1.51 +    GstElement *decode = NULL;
    1.52 +    GstPad *src_pad = NULL;
    1.53  
    1.54  
    1.55      bsrc = gst_bin_new (NULL);
    1.56 @@ -949,7 +951,15 @@
    1.57              priv->ready = FALSE;
    1.58  		    g_signal_emit (user_data, g_mencoder_signals[EOS], 0);
    1.59  		    break;		
    1.60 -
    1.61 +		case GST_MESSAGE_DURATION:
    1.62 +		{
    1.63 +			GstFormat format;
    1.64 +			gint64 duration;
    1.65 +			gst_message_parse_duration (msg, &format, &duration);
    1.66 +			if (format == GST_FORMAT_BYTES)
    1.67 +				priv->duration = duration;
    1.68 +			break;
    1.69 +		}
    1.70  		default:
    1.71  		{
    1.72  			break;
    1.73 @@ -1004,15 +1014,20 @@
    1.74  static gboolean
    1.75  _tick_cb (gpointer user_data)
    1.76  {
    1.77 -	GstFormat format = GST_FORMAT_TIME;
    1.78 +	GstFormat format = GST_FORMAT_BYTES;
    1.79  	gint64 cur = 0;
    1.80 -	gint64 duration = 0;
    1.81  
    1.82  	GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (user_data);
    1.83  
    1.84 -	if (gst_element_query_duration (priv->pipe, &format, &duration)) {
    1.85 -		gst_element_query_position (priv->pipe, &format, &cur);
    1.86 -		g_print ("PROGRESS:%lli%\n", (100 * cur) / duration); 
    1.87 +	if (priv->duration == 0) {
    1.88 +		gint64 d = 0;
    1.89 +		if (gst_element_query_duration (priv->src, &format, &d))
    1.90 +			priv->duration = d;
    1.91 +	}			
    1.92 +
    1.93 +	if (priv->duration != 0) {
    1.94 +		gst_element_query_position (priv->src, &format, &cur);
    1.95 +		g_print ("PROGRESS:%lli\n", (99 * cur) / priv->duration); 
    1.96  	}
    1.97  
    1.98  	return TRUE;