[FFmpeg-devel] [PATCH 1/2] lavu: add thread message API.

Michael Niedermayer michaelni at gmx.at
Sun Apr 20 21:53:13 CEST 2014


On Sun, Apr 20, 2014 at 07:58:00PM +0200, Nicolas George wrote:
> Le primidi 1er floréal, an CCXXII, Nicolas George a écrit :
> > You are right. I remembered wrong how the compat system works. Updated
> > version attached.
> 
> Sorry, forgot to commit before sending.
> 
> Regards,
> 
> -- 
>   Nicolas George

>  Makefile        |    2 
>  threadmessage.c |  182 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  threadmessage.h |   89 +++++++++++++++++++++++++++
>  3 files changed, 273 insertions(+)
> 2e0c5cf4cb82d683a14c433bd53cabdaae07c4d2  0001-lavu-add-thread-message-API.patch
> From 129ff96d38409e79ced27944bfd31613f917ded5 Mon Sep 17 00:00:00 2001
> From: Nicolas George <george at nsup.org>
> Date: Thu, 20 Feb 2014 14:14:34 +0100
> Subject: [PATCH 1/2] lavu: add thread message API.
> 
> TODO minor bump and APIchanges entry.
> 
> Signed-off-by: Nicolas George <george at nsup.org>
> ---
>  libavutil/Makefile        |    2 +
>  libavutil/threadmessage.c |  182 +++++++++++++++++++++++++++++++++++++++++++++
>  libavutil/threadmessage.h |   89 ++++++++++++++++++++++
>  3 files changed, 273 insertions(+)
>  create mode 100644 libavutil/threadmessage.c
>  create mode 100644 libavutil/threadmessage.h
> 
> diff --git a/libavutil/Makefile b/libavutil/Makefile
> index d2ebebc..5082e92 100644
> --- a/libavutil/Makefile
> +++ b/libavutil/Makefile
> @@ -51,6 +51,7 @@ HEADERS = adler32.h                                                     \
>            sha.h                                                         \
>            sha512.h                                                      \
>            stereo3d.h                                                    \
> +          threadmessage.h                                               \
>            time.h                                                        \
>            timecode.h                                                    \
>            timestamp.h                                                   \
> @@ -117,6 +118,7 @@ OBJS = adler32.o                                                        \
>         sha.o                                                            \
>         sha512.o                                                         \
>         stereo3d.o                                                       \
> +       threadmessage.o                                                  \
>         time.o                                                           \
>         timecode.o                                                       \
>         tree.o                                                           \
> diff --git a/libavutil/threadmessage.c b/libavutil/threadmessage.c
> new file mode 100644
> index 0000000..2c64440
> --- /dev/null
> +++ b/libavutil/threadmessage.c
> @@ -0,0 +1,182 @@
> +/*
> + * Copyright (c) 2014 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
> + */
> +
> +#include "fifo.h"
> +#include "threadmessage.h"
> +#if HAVE_THREADS
> +#if HAVE_PTHREADS
> +#include <pthread.h>
> +#elif HAVE_W32THREADS
> +#include "compat/w32pthreads.h"
> +#elif HAVE_OS2THREADS
> +#include "compat/os2threads.h"
> +#else
> +#error "Unknown threads implementation"
> +#endif
> +#endif
> +
> +struct AVThreadMessageQueue {
> +#if HAVE_THREADS
> +    AVFifoBuffer *fifo;
> +    pthread_mutex_t lock;
> +    pthread_cond_t cond;
> +    int err_send;
> +    int err_recv;
> +    unsigned elsize;
> +#endif
> +};
> +
> +int av_thread_message_queue_alloc(AVThreadMessageQueue **mq,
> +                                  unsigned elsize,
> +                                  unsigned nelem)
> +{
> +#if HAVE_THREADS
> +    AVThreadMessageQueue *rmq;
> +    int ret = 0;
> +
> +    if (nelem > INT_MAX / elsize)
> +        return AVERROR(EINVAL);
> +    if (!(rmq = av_mallocz(sizeof(*rmq))))
> +        return AVERROR(ENOMEM);
> +    if ((ret = pthread_mutex_init(&rmq->lock, NULL))) {
> +        av_free(rmq);
> +        return AVERROR(ret);
> +    }

> +    if ((ret = pthread_cond_init(&rmq->cond, NULL))) {

fails on mingw
see:
compat/w32pthreads.h:static void pthread_cond_init(pthread_cond_t *cond, const void *unused_attr)

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

There will always be a question for which you do not know the correct answer.
-------------- 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/20140420/7fb2a372/attachment.asc>


More information about the ffmpeg-devel mailing list