mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-06-05 15:08:53 +00:00
buffer: Fix memory copying logic in copy_into()
https://bugzilla.gnome.org/show_bug.cgi?id=695035
This commit is contained in:
parent
3360299ef4
commit
64affd3e61
1 changed files with 12 additions and 10 deletions
|
@ -402,7 +402,6 @@ gst_buffer_copy_into (GstBuffer * dest, GstBuffer * src,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & GST_BUFFER_COPY_MEMORY) {
|
if (flags & GST_BUFFER_COPY_MEMORY) {
|
||||||
GstMemory *mem;
|
|
||||||
gsize skip, left, len, dest_len, i, bsize;
|
gsize skip, left, len, dest_len, i, bsize;
|
||||||
gboolean deep;
|
gboolean deep;
|
||||||
|
|
||||||
|
@ -415,38 +414,41 @@ gst_buffer_copy_into (GstBuffer * dest, GstBuffer * src,
|
||||||
|
|
||||||
/* copy and make regions of the memory */
|
/* copy and make regions of the memory */
|
||||||
for (i = 0; i < len && left > 0; i++) {
|
for (i = 0; i < len && left > 0; i++) {
|
||||||
mem = GST_BUFFER_MEM_PTR (src, i);
|
GstMemory *mem = GST_BUFFER_MEM_PTR (src, i);
|
||||||
|
|
||||||
bsize = gst_memory_get_sizes (mem, NULL, NULL);
|
bsize = gst_memory_get_sizes (mem, NULL, NULL);
|
||||||
|
|
||||||
if (bsize <= skip) {
|
if (bsize <= skip) {
|
||||||
/* don't copy buffer */
|
/* don't copy buffer */
|
||||||
skip -= bsize;
|
skip -= bsize;
|
||||||
} else {
|
} else {
|
||||||
|
GstMemory *newmem = NULL;
|
||||||
gsize tocopy;
|
gsize tocopy;
|
||||||
|
|
||||||
tocopy = MIN (bsize - skip, left);
|
tocopy = MIN (bsize - skip, left);
|
||||||
|
|
||||||
if (tocopy < bsize && !deep && !GST_MEMORY_IS_NO_SHARE (mem)) {
|
if (tocopy < bsize && !deep && !GST_MEMORY_IS_NO_SHARE (mem)) {
|
||||||
/* we need to clip something */
|
/* we need to clip something */
|
||||||
mem = gst_memory_share (mem, skip, tocopy);
|
newmem = gst_memory_share (mem, skip, tocopy);
|
||||||
skip = 0;
|
if (newmem)
|
||||||
|
skip = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (deep || GST_MEMORY_IS_NO_SHARE (mem) || (!mem && tocopy < bsize)) {
|
if (deep || GST_MEMORY_IS_NO_SHARE (mem) || (!newmem && tocopy < bsize)) {
|
||||||
/* deep copy or we're not allowed to share this memory
|
/* deep copy or we're not allowed to share this memory
|
||||||
* between buffers, always copy then */
|
* between buffers, always copy then */
|
||||||
mem = gst_memory_copy (mem, skip, tocopy);
|
newmem = gst_memory_copy (mem, skip, tocopy);
|
||||||
skip = 0;
|
skip = 0;
|
||||||
} else {
|
} else if (!newmem) {
|
||||||
mem = gst_memory_ref (mem);
|
newmem = gst_memory_ref (mem);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mem) {
|
if (!newmem) {
|
||||||
gst_buffer_remove_memory_range (dest, dest_len, -1);
|
gst_buffer_remove_memory_range (dest, dest_len, -1);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
_memory_add (dest, -1, mem, TRUE);
|
_memory_add (dest, -1, newmem, TRUE);
|
||||||
left -= tocopy;
|
left -= tocopy;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue