[svn r154] Fixed memory leaks when sending duration (TIME and BYTES) queries to the sink pad (peer pad). trunk
authorrosfran
Thu Nov 30 19:44:22 2006 +0000 (2006-11-30)
branchtrunk
changeset 153a0e5b7d75f25
parent 152 22db2f4b6f86
child 154 30f32f34287c
[svn r154] Fixed memory leaks when sending duration (TIME and BYTES) queries to the sink pad (peer pad).
gst-plugins-nuvdemux/nuvdemux/gstnuvdemux.c
     1.1 --- a/gst-plugins-nuvdemux/nuvdemux/gstnuvdemux.c	Thu Nov 30 19:41:27 2006 +0000
     1.2 +++ b/gst-plugins-nuvdemux/nuvdemux/gstnuvdemux.c	Thu Nov 30 19:44:22 2006 +0000
     1.3 @@ -1078,14 +1078,12 @@
     1.4        return GST_FLOW_ERROR_NO_DATA;
     1.5  
     1.6      if (move) {
     1.7 -      guint8 *data = NULL;
     1.8 -      data = (guint8 *) gst_adapter_take (nuv->priv->adapter, size);
     1.9 -      *buffer = gst_buffer_new ();
    1.10 +      guint8 *data = (guint8 *) gst_adapter_take (nuv->priv->adapter, size);
    1.11 +      *buffer = gst_buffer_new_and_alloc ( size );
    1.12        gst_buffer_set_data (*buffer, data, size);
    1.13      } else {
    1.14 -      guint8 *data = NULL;
    1.15 -      data = (guint8 *) gst_adapter_peek (nuv->priv->adapter, size);
    1.16 -      *buffer = gst_buffer_new ();
    1.17 +      guint8 *data = (guint8 *) gst_adapter_peek (nuv->priv->adapter, size);
    1.18 +      *buffer = gst_buffer_new_and_alloc ( size );
    1.19        gst_buffer_set_data (*buffer, data, size);
    1.20      }
    1.21    }
    1.22 @@ -1325,7 +1323,6 @@
    1.23      interval  = current_timestamp - nuv->priv->last_update;
    1.24  
    1.25      if (interval > (10 * GST_SECOND)) {
    1.26 -        GstMessage* msg = NULL;
    1.27          gint64 average = 0;
    1.28          gint64 duration_bytes = gst_nuv_demux_get_bytes_duration (nuv);
    1.29  
    1.30 @@ -1341,8 +1338,9 @@
    1.31                  nuv->priv->duration_average = gst_util_uint64_scale (GST_SECOND, duration_bytes, average);
    1.32              }
    1.33              nuv->priv->last_update = current_timestamp;
    1.34 -            msg = gst_message_new_duration (GST_OBJECT (nuv), GST_FORMAT_TIME, nuv->priv->duration_average);
    1.35 -            gst_element_post_message (GST_ELEMENT (nuv), msg);
    1.36 +            gst_element_post_message (GST_ELEMENT (nuv), 
    1.37 +            		gst_message_new_duration (GST_OBJECT (nuv), GST_FORMAT_TIME, 
    1.38 +            						nuv->priv->duration_average) );
    1.39              GST_DEBUG_OBJECT (nuv, "New Duration Average %"G_GUINT64_FORMAT, nuv->priv->duration_average);
    1.40          }
    1.41      }
    1.42 @@ -1352,16 +1350,11 @@
    1.43  gst_nuv_demux_get_bytes_duration (GstNuvDemux *nuv)
    1.44  {
    1.45      if (nuv->priv->duration_bytes == GST_CLOCK_TIME_NONE) {
    1.46 -        GstPad *peer = gst_pad_get_peer (nuv->priv->sinkpad);
    1.47 -        GstQuery *query = gst_query_new_duration (GST_FORMAT_BYTES);
    1.48 -        if (gst_pad_query (peer, query)) {
    1.49 -            gint64 duration;
    1.50 -
    1.51 -            gst_query_parse_duration (query, NULL, &duration);
    1.52 +        GstFormat format = GST_FORMAT_BYTES;
    1.53 +        gint64 duration = 0;
    1.54 +        if (gst_pad_query_peer_duration (nuv->priv->sinkpad, &format, &duration)) {            
    1.55              nuv->priv->duration_bytes = duration;
    1.56          }
    1.57 -        gst_object_unref (peer);
    1.58 -        gst_query_unref (query);
    1.59      }
    1.60      return nuv->priv->duration_bytes;
    1.61  }
    1.62 @@ -1370,15 +1363,11 @@
    1.63  gst_nuv_demux_get_time_duration (GstNuvDemux *nuv)
    1.64  {
    1.65      if (nuv->priv->duration_time == GST_CLOCK_TIME_NONE) {
    1.66 -        GstPad *peer = gst_pad_get_peer (nuv->priv->sinkpad);
    1.67 -        GstQuery *query = gst_query_new_duration (GST_FORMAT_TIME);
    1.68 -        if (gst_pad_query (peer, query)) {
    1.69 -            gint64 duration;
    1.70 -            gst_query_parse_duration (query, NULL, &duration);
    1.71 +        GstFormat format = GST_FORMAT_TIME;
    1.72 +        gint64 duration = 0;
    1.73 +        if (gst_pad_query_peer_duration (nuv->priv->sinkpad, &format, &duration)) {            
    1.74              nuv->priv->duration_time = duration;
    1.75          }
    1.76 -        gst_object_unref (peer);
    1.77 -        gst_query_unref (query);
    1.78      }
    1.79      return nuv->priv->duration_time;
    1.80  }