buffer: add option to deep copy a buffer

Add a buffer copy flag to force a memory copy in all cases.
This commit is contained in:
Wim Taymans 2013-02-16 14:59:02 +01:00
parent 6c7573226e
commit 1fcef378bd
2 changed files with 17 additions and 8 deletions

View file

@ -402,6 +402,9 @@ gst_buffer_copy_into (GstBuffer * dest, GstBuffer * src,
if (flags & GST_BUFFER_COPY_MEMORY) {
GstMemory *mem;
gsize skip, left, len, i, bsize;
gboolean deep;
deep = flags & GST_BUFFER_COPY_DEEP;
len = GST_BUFFER_MEM_LEN (src);
left = size;
@ -419,8 +422,9 @@ gst_buffer_copy_into (GstBuffer * dest, GstBuffer * src,
gsize tocopy;
tocopy = MIN (bsize - skip, left);
if (GST_MEMORY_IS_NO_SHARE (mem)) {
/* no share, always copy then */
if (deep || GST_MEMORY_IS_NO_SHARE (mem)) {
/* deep copy or we're not allowed to share this memory
* between buffers, always copy then */
mem = gst_memory_copy (mem, skip, tocopy);
skip = 0;
} else if (tocopy < bsize) {

View file

@ -377,12 +377,16 @@ gst_buffer_copy (const GstBuffer * buf)
* @GST_BUFFER_COPY_FLAGS: flag indicating that buffer flags should be copied
* @GST_BUFFER_COPY_TIMESTAMPS: flag indicating that buffer pts, dts,
* duration, offset and offset_end should be copied
* @GST_BUFFER_COPY_MEMORY: flag indicating that buffer memory should be copied
* and appended to already existing memory
* @GST_BUFFER_COPY_MEMORY: flag indicating that buffer memory should be reffed
* and appended to already existing memory. Unless the memory is marked as
* NO_SHARE, no actual copy of the memory is made but it is simply reffed.
* Add @GST_BUFFER_COPY_DEEP to force a real copy.
* @GST_BUFFER_COPY_MERGE: flag indicating that buffer memory should be
* merged
* @GST_BUFFER_COPY_META: flag indicating that buffer meta should be
* copied
* @GST_BUFFER_COPY_DEEP: flag indicating that memory should always be
* copied instead of reffed.
*
* A set of flags that can be provided to the gst_buffer_copy_into()
* function to specify which items should be copied.
@ -393,7 +397,8 @@ typedef enum {
GST_BUFFER_COPY_TIMESTAMPS = (1 << 1),
GST_BUFFER_COPY_META = (1 << 2),
GST_BUFFER_COPY_MEMORY = (1 << 3),
GST_BUFFER_COPY_MERGE = (1 << 4)
GST_BUFFER_COPY_MERGE = (1 << 4),
GST_BUFFER_COPY_DEEP = (1 << 5)
} GstBufferCopyFlags;
/**