diff options
author | Wim Taymans <wim.taymans@collabora.co.uk> | 2009-12-24 19:25:52 +0100 |
---|---|---|
committer | Wim Taymans <wim@metal.(none)> | 2009-12-24 19:25:52 +0100 |
commit | d7ecbc6ac300feccb17e88a4b3bc7723bb88eb53 (patch) | |
tree | 0c052080dddf03ec4e7fd599e347d1169b066f00 | |
parent | bb780fdf73546ec5604eb95326682bd9d6192807 (diff) |
collectpads: don't keep buffers reffed longer than needed
Make sure we take ownership of the buffer early without increasing its refcount
when we go in the collect function. This reduces the amount of copies needed in
order to make the buffer writable in most cases.
-rw-r--r-- | libs/gst/base/gstcollectpads.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/libs/gst/base/gstcollectpads.c b/libs/gst/base/gstcollectpads.c index 411fb66a55..f9aa1168a4 100644 --- a/libs/gst/base/gstcollectpads.c +++ b/libs/gst/base/gstcollectpads.c | |||
@@ -1307,7 +1307,6 @@ gst_collect_pads_chain (GstPad * pad, GstBuffer * buffer) | |||
1307 | GstCollectPads *pads; | 1307 | GstCollectPads *pads; |
1308 | GstCollectPadsPrivate *priv; | 1308 | GstCollectPadsPrivate *priv; |
1309 | GstFlowReturn ret; | 1309 | GstFlowReturn ret; |
1310 | GstBuffer **buffer_p; | ||
1311 | 1310 | ||
1312 | GST_DEBUG ("Got buffer for pad %s:%s", GST_DEBUG_PAD_NAME (pad)); | 1311 | GST_DEBUG ("Got buffer for pad %s:%s", GST_DEBUG_PAD_NAME (pad)); |
1313 | 1312 | ||
@@ -1346,12 +1345,15 @@ gst_collect_pads_chain (GstPad * pad, GstBuffer * buffer) | |||
1346 | 1345 | ||
1347 | /* One more pad has data queued */ | 1346 | /* One more pad has data queued */ |
1348 | pads->queuedpads++; | 1347 | pads->queuedpads++; |
1349 | buffer_p = &data->buffer; | 1348 | /* take ownership of the buffer */ |
1350 | gst_buffer_replace (buffer_p, buffer); | 1349 | if (data->buffer) |
1350 | gst_buffer_unref (data->buffer); | ||
1351 | data->buffer = buffer; | ||
1352 | buffer = NULL; | ||
1351 | 1353 | ||
1352 | /* update segment last position if in TIME */ | 1354 | /* update segment last position if in TIME */ |
1353 | if (G_LIKELY (data->segment.format == GST_FORMAT_TIME)) { | 1355 | if (G_LIKELY (data->segment.format == GST_FORMAT_TIME)) { |
1354 | GstClockTime timestamp = GST_BUFFER_TIMESTAMP (buffer); | 1356 | GstClockTime timestamp = GST_BUFFER_TIMESTAMP (data->buffer); |
1355 | 1357 | ||
1356 | if (GST_CLOCK_TIME_IS_VALID (timestamp)) | 1358 | if (GST_CLOCK_TIME_IS_VALID (timestamp)) |
1357 | gst_segment_set_last_stop (&data->segment, GST_FORMAT_TIME, timestamp); | 1359 | gst_segment_set_last_stop (&data->segment, GST_FORMAT_TIME, timestamp); |
@@ -1405,7 +1407,8 @@ unlock_done: | |||
1405 | GST_DEBUG ("Pad %s:%s done", GST_DEBUG_PAD_NAME (pad)); | 1407 | GST_DEBUG ("Pad %s:%s done", GST_DEBUG_PAD_NAME (pad)); |
1406 | GST_OBJECT_UNLOCK (pads); | 1408 | GST_OBJECT_UNLOCK (pads); |
1407 | unref_data (data); | 1409 | unref_data (data); |
1408 | gst_buffer_unref (buffer); | 1410 | if (buffer) |
1411 | gst_buffer_unref (buffer); | ||
1409 | return ret; | 1412 | return ret; |
1410 | 1413 | ||
1411 | pad_removed: | 1414 | pad_removed: |
@@ -1448,9 +1451,8 @@ unexpected: | |||
1448 | clipped: | 1451 | clipped: |
1449 | { | 1452 | { |
1450 | GST_DEBUG ("clipped buffer on pad %s:%s", GST_DEBUG_PAD_NAME (pad)); | 1453 | GST_DEBUG ("clipped buffer on pad %s:%s", GST_DEBUG_PAD_NAME (pad)); |
1451 | GST_OBJECT_UNLOCK (pads); | 1454 | ret = GST_FLOW_OK; |
1452 | unref_data (data); | 1455 | goto unlock_done; |
1453 | return GST_FLOW_OK; | ||
1454 | } | 1456 | } |
1455 | error: | 1457 | error: |
1456 | { | 1458 | { |