diff options
Diffstat (limited to 'libavutil/buffer.c')
-rw-r--r-- | libavutil/buffer.c | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/libavutil/buffer.c b/libavutil/buffer.c index 0e2b4ef1b4..8d1aa5fa84 100644 --- a/libavutil/buffer.c +++ b/libavutil/buffer.c @@ -1,18 +1,18 @@ /* - * This file is part of Libav. + * This file is part of FFmpeg. * - * Libav is free software; you can redistribute it and/or + * FFmpeg is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * - * Libav is distributed in the hope that it will be useful, + * FFmpeg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with Libav; if not, write to the Free Software + * License along with FFmpeg; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ @@ -104,14 +104,17 @@ AVBufferRef *av_buffer_ref(AVBufferRef *buf) return ret; } -void av_buffer_unref(AVBufferRef **buf) +static void buffer_replace(AVBufferRef **dst, AVBufferRef **src) { AVBuffer *b; - if (!buf || !*buf) - return; - b = (*buf)->buffer; - av_freep(buf); + b = (*dst)->buffer; + + if (src) { + **dst = **src; + av_freep(src); + } else + av_freep(dst); if (atomic_fetch_add_explicit(&b->refcount, -1, memory_order_acq_rel) == 1) { b->free(b->opaque, b->data); @@ -119,6 +122,14 @@ void av_buffer_unref(AVBufferRef **buf) } } +void av_buffer_unref(AVBufferRef **buf) +{ + if (!buf || !*buf) + return; + + buffer_replace(buf, NULL); +} + int av_buffer_is_writable(const AVBufferRef *buf) { if (buf->buffer->flags & AV_BUFFER_FLAG_READONLY) @@ -127,6 +138,16 @@ int av_buffer_is_writable(const AVBufferRef *buf) return atomic_load(&buf->buffer->refcount) == 1; } +void *av_buffer_get_opaque(const AVBufferRef *buf) +{ + return buf->buffer->opaque; +} + +int av_buffer_get_ref_count(const AVBufferRef *buf) +{ + return atomic_load(&buf->buffer->refcount); +} + int av_buffer_make_writable(AVBufferRef **pbuf) { AVBufferRef *newbuf, *buf = *pbuf; @@ -139,8 +160,8 @@ int av_buffer_make_writable(AVBufferRef **pbuf) return AVERROR(ENOMEM); memcpy(newbuf->data, buf->data, buf->size); - av_buffer_unref(pbuf); - *pbuf = newbuf; + + buffer_replace(pbuf, &newbuf); return 0; } @@ -181,8 +202,7 @@ int av_buffer_realloc(AVBufferRef **pbuf, int size) memcpy(new->data, buf->data, FFMIN(size, buf->size)); - av_buffer_unref(pbuf); - *pbuf = new; + buffer_replace(pbuf, &new); return 0; } @@ -270,6 +290,9 @@ static void pool_release_buffer(void *opaque, uint8_t *data) BufferPoolEntry *buf = opaque; AVBufferPool *pool = buf->pool; + if(CONFIG_MEMORY_POISONING) + memset(buf->data, FF_MEMORY_POISON, pool->size); + ff_mutex_lock(&pool->mutex); buf->next = pool->pool; pool->pool = buf; |