Commit 1a3f48f4 authored by Wim Taymans's avatar Wim Taymans

buffer: fix resize function some more

Don't remove memory blocks from the buffer when we clip and resize, instead set
the memory offset and size to 0. This allows us to make the buffer larger again
later.
parent a19baf77
......@@ -817,7 +817,7 @@ void
gst_buffer_resize (GstBuffer * buffer, gssize offset, gsize size)
{
guint len;
guint si, di;
guint i;
gsize bsize, bufsize, bufoffs, bufmax;
GstMemory *mem;
......@@ -842,46 +842,47 @@ gst_buffer_resize (GstBuffer * buffer, gssize offset, gsize size)
len = GST_BUFFER_MEM_LEN (buffer);
/* copy and trim */
for (di = si = 0; si < len; si++) {
mem = GST_BUFFER_MEM_PTR (buffer, si);
bsize = gst_memory_get_sizes (mem, NULL, NULL);
for (i = 0; i < len; i++) {
gsize left, noffs;
if ((gssize) bsize <= offset) {
/* remove buffer */
GST_CAT_LOG (GST_CAT_BUFFER, "remove memory %p", mem);
gst_memory_unref (mem);
offset -= bsize;
} else {
gsize left;
mem = GST_BUFFER_MEM_PTR (buffer, i);
bsize = gst_memory_get_sizes (mem, NULL, NULL);
/* last buffer always gets resized to the remaining size */
if (si + 1 == len)
left = size;
else
left = MIN (bsize - offset, size);
noffs = 0;
/* last buffer always gets resized to the remaining size */
if (i + 1 == len)
left = size;
/* shrink buffers before the offset */
else if ((gssize) bsize <= offset) {
left = 0;
noffs = offset - bsize;
offset = 0;
}
/* clip other buffers */
else
left = MIN (bsize - offset, size);
if (offset != 0 || left != bsize) {
/* we need to clip something */
if (GST_MEMORY_IS_WRITABLE (mem)) {
gst_memory_resize (mem, offset, left);
} else {
GstMemory *tmp;
if (offset != 0 || left != bsize) {
/* we need to clip something */
if (GST_MEMORY_IS_WRITABLE (mem)) {
gst_memory_resize (mem, offset, left);
} else {
GstMemory *tmp;
if (mem->flags & GST_MEMORY_FLAG_NO_SHARE)
tmp = gst_memory_copy (mem, offset, left);
else
tmp = gst_memory_share (mem, offset, left);
if (mem->flags & GST_MEMORY_FLAG_NO_SHARE)
tmp = gst_memory_copy (mem, offset, left);
else
tmp = gst_memory_share (mem, offset, left);
gst_memory_unref (mem);
mem = tmp;
}
offset = 0;
gst_memory_unref (mem);
mem = tmp;
}
GST_BUFFER_MEM_PTR (buffer, di++) = mem;
size -= left;
}
offset = noffs;
size -= left;
GST_BUFFER_MEM_PTR (buffer, i) = mem;
}
GST_BUFFER_MEM_LEN (buffer) = di;
}
/**
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment