diff options
author | Thiago Santos <thiagoss@osg.samsung.com> | 2015-03-13 18:35:01 +0000 |
---|---|---|
committer | Thiago Santos <thiagoss@osg.samsung.com> | 2015-03-13 18:37:04 +0000 |
commit | 96eaeadc0f3cbad3cf35d26f542b8359d27e316d (patch) | |
tree | 1dfe6f7db16eca01c3523ed56ebfa245891cd3e2 /gst | |
parent | d8f572647fe1ee56d4e4a0a215626339a40890fa (diff) |
gstbuffer: add gst_buffer_copy_deep
A variant of gst_buffer_copy that forces the underlying memory
to be copied.
This is added to avoid adding an extra reference to a GstMemory
that might belong to a bufferpool that is trying to be drained.
The use case is when the buffer copying is done to release the
old buffer and all its resources.
https://bugzilla.gnome.org/show_bug.cgi?id=745287
Diffstat (limited to 'gst')
-rw-r--r-- | gst/gstbuffer.c | 29 | ||||
-rw-r--r-- | gst/gstbuffer.h | 8 |
2 files changed, 32 insertions, 5 deletions
diff --git a/gst/gstbuffer.c b/gst/gstbuffer.c index 06a55b9c7..f36457245 100644 --- a/gst/gstbuffer.c +++ b/gst/gstbuffer.c @@ -508,7 +508,7 @@ gst_buffer_copy_into (GstBuffer * dest, GstBuffer * src, } static GstBuffer * -_gst_buffer_copy (GstBuffer * buffer) +gst_buffer_copy_with_flags (const GstBuffer * buffer, GstBufferFlags flags) { GstBuffer *copy; @@ -517,8 +517,9 @@ _gst_buffer_copy (GstBuffer * buffer) /* create a fresh new buffer */ copy = gst_buffer_new (); - /* we simply copy everything from our parent */ - if (!gst_buffer_copy_into (copy, buffer, GST_BUFFER_COPY_ALL, 0, -1)) + /* copy what the 'flags' want from our parent */ + /* FIXME why we can't pass const to gst_buffer_copy_into() ? */ + if (!gst_buffer_copy_into (copy, (GstBuffer *) buffer, flags, 0, -1)) gst_buffer_replace (©, NULL); if (copy) @@ -527,6 +528,28 @@ _gst_buffer_copy (GstBuffer * buffer) return copy; } +static GstBuffer * +_gst_buffer_copy (const GstBuffer * buffer) +{ + return gst_buffer_copy_with_flags (buffer, GST_BUFFER_COPY_ALL); +} + +/** + * gst_buffer_copy_deep: + * @buf: a #GstBuffer. + * + * Create a copy of the given buffer. This will make a newly allocated + * copy of the data the source buffer contains. + * + * Returns: (transfer full): a new copy of @buf. + */ +GstBuffer * +gst_buffer_copy_deep (const GstBuffer * buffer) +{ + return gst_buffer_copy_with_flags (buffer, + GST_BUFFER_COPY_ALL | GST_BUFFER_COPY_DEEP); +} + /* the default dispose function revives the buffer and returns it to the * pool when there is a pool */ static gboolean diff --git a/gst/gstbuffer.h b/gst/gstbuffer.h index 643db7d6a..dd7f23740 100644 --- a/gst/gstbuffer.h +++ b/gst/gstbuffer.h @@ -365,8 +365,11 @@ gst_buffer_unref (GstBuffer * buf) * gst_buffer_copy: * @buf: a #GstBuffer. * - * Create a copy of the given buffer. This will also make a newly allocated - * copy of the data the source buffer contains. + * Create a copy of the given buffer. This will only copy the buffer's + * data to a newly allocated memory if needed (if the type of memory + * requires it), otherwise the underlying data is just referenced. + * Check gst_buffer_copy_deep() if you want to force the data + * to be copied to newly allocated memory. * * Returns: (transfer full): a new copy of @buf. */ @@ -380,6 +383,7 @@ gst_buffer_copy (const GstBuffer * buf) return GST_BUFFER (gst_mini_object_copy (GST_MINI_OBJECT_CONST_CAST (buf))); } +GstBuffer * gst_buffer_copy_deep (const GstBuffer * buf); /** * GstBufferCopyFlags: |