[FFmpeg-devel] [PATCH 2/3] lavfi: add a generic API for buffer queues.
Michael Niedermayer
michaelni at gmx.at
Fri Apr 27 19:19:56 CEST 2012
On Fri, Apr 27, 2012 at 05:38:41PM +0200, Nicolas George wrote:
>
> Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
> ---
> libavfilter/bufferqueue.h | 73 +++++++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 73 insertions(+), 0 deletions(-)
> create mode 100644 libavfilter/bufferqueue.h
>
> diff --git a/libavfilter/bufferqueue.h b/libavfilter/bufferqueue.h
> new file mode 100644
> index 0000000..6ad00ee
> --- /dev/null
> +++ b/libavfilter/bufferqueue.h
> @@ -0,0 +1,73 @@
> +/*
> + * Generic buffer queue
> + * Copyright (c) 2012 Nicolas George
> + *
> + * This file is part of FFmpeg.
> + *
> + * 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.
> + *
> + * 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 FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#ifndef AVFILTER_BUFFERQUEUE_H
> +#define AVFILTER_BUFFERQUEUE_H
> +
> +#ifndef FF_BUFQUEUE_SIZE
> +#define FF_BUFQUEUE_SIZE 32
> +#endif
> +
> +#include "avfilter.h"
> +#include "libavutil/avassert.h"
> +
> +struct ff_bufqueue {
> + AVFilterBufferRef *queue[FF_BUFQUEUE_SIZE];
> + unsigned short head;
> + unsigned short available;
> +};
> +
> +#define BUCKET(i) queue->queue[(queue->head + (i)) % FF_BUFQUEUE_SIZE]
i suggest & (FF_BUFQUEUE_SIZE-1) and only allowing powers of 2
the & should be much faster than a %
> +
> +static inline void ff_bufqueue_add(void *log, struct ff_bufqueue *queue,
> + AVFilterBufferRef *buf)
> +{
> + if (queue->available == FF_BUFQUEUE_SIZE) {
> + av_log(log, AV_LOG_WARNING, "Buffer queue overflow, dropping.\n");
> + avfilter_unref_buffer(BUCKET(--queue->available));
> + }
> + BUCKET(queue->available++) = buf;
> +}
> +
> +static inline AVFilterBufferRef *ff_bufqueue_get(struct ff_bufqueue *queue,
> + unsigned index)
> +{
> + return index < queue->available ? BUCKET(index) : NULL;
> +}
> +
> +static inline AVFilterBufferRef *ff_bufqueue_take(struct ff_bufqueue *queue)
> +{
> + AVFilterBufferRef *ret = queue->queue[queue->head];
> + queue->available--;
a av_assert() could be used here to detect tries to take out of an
empty queue
otherwise LGTM as long as theres no plan to use this between 2 threads
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
What does censorship reveal? It reveals fear. -- Julian Assange
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20120427/0f3c796a/attachment.asc>
More information about the ffmpeg-devel
mailing list