[FFmpeg-devel] [PATCH v2 01/14] vvcdec: add thread executor

Nuo Mi nuomi2021 at gmail.com
Sun Jul 16 10:07:54 EEST 2023


On Sat, Jul 15, 2023 at 6:38 AM Michael Niedermayer <michael at niedermayer.cc>
wrote:

> On Fri, Jul 07, 2023 at 10:05:27PM +0800, Nuo Mi wrote:
> > The executor design pattern was inroduced by java
> > <
> https://docs.oracle.com/en/java/javase/20/docs/api/java.base/java/util/concurrent/Executor.html
> >
> > it also adapted by python
> > <https://docs.python.org/3/library/concurrent.futures.html>
> > Compared to handcrafted thread pool management, it greatly simplifies
> the thread code.
> > ---
> >  libavcodec/Makefile     |   1 +
> >  libavcodec/executor.c   | 182 ++++++++++++++++++++++++++++++++++++++++
> >  libavcodec/executor.h   |  67 +++++++++++++++
> >  libavcodec/vvc/Makefile |   4 +
> >  4 files changed, 254 insertions(+)
> >  create mode 100644 libavcodec/executor.c
> >  create mode 100644 libavcodec/executor.h
> >  create mode 100644 libavcodec/vvc/Makefile
>
> [...]
>
> > +++ b/libavcodec/executor.h
> > @@ -0,0 +1,67 @@
> > +/*
> > + * Copyright (C) 2022 Nuo Mi
> > + *
> > + * 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 AVCODEC_EXECUTOR_H
> > +#define AVCODEC_EXECUTOR_H
> > +
> > +typedef struct Executor Executor;
> > +typedef struct Tasklet Tasklet;
> > +
> > +struct Tasklet {
> > +    Tasklet *next;
> > +};
> > +
> > +typedef struct TaskletCallbacks {
> > +    void *user_data;
> > +
> > +    int local_context_size;
> > +
> > +    // return 1 if a's priority > b's priority
> > +    int (*priority_higher)(const Tasklet *a, const Tasklet *b);
> > +
> > +    // task is ready for run
> > +    int (*ready)(const Tasklet *t, void *user_data);
> > +
> > +    // run the task
> > +    int (*run)(Tasklet *t, void *local_context, void *user_data);
> > +} TaskletCallbacks;
> > +
> > +/**
> > + * Alloc executor
> > + * @param callbacks callback strucutre for executor
> > + * @param thread_count worker thread number
> > + * @return return the executor
> > + */
> > +Executor* ff_executor_alloc(const TaskletCallbacks *callbacks, int
> thread_count);
> > +
> > +/**
> > + * Free executor
> > + * @param e  pointer to executor
> > + */
> > +void ff_executor_free(Executor **e);
> > +
> > +/**
> > + * Add task to executor
> > + * @param e pointer to executor
> > + * @param t pointer to task. If NULL, it will wakeup one work thread
> > + */
> > +void ff_executor_execute(Executor *e, Tasklet *t);
> > +
> > +#endif //AVCODEC_EXECUTOR_H
>
> This would be quite useful outside libavcodec
> In fact id like to use it in libavradio to do the first stage of FFTs
> (which
> are the overwhelming bulk of computations ATM) and maybe eventually later
> stages too
>
Thank you. Glad to hear it.

>
> Maybe this could be made available to the outside of libavcodec
> as avpriv_ or av_ ?
> maybe from libavutil ?
>
avpriv_  is better since it is not a public API for ffmpeg's users(yet)
I will move it to libavutil and send separate patches for the executor
only.

>
> thx
>
> [...]
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> Take away the freedom of one citizen and you will be jailed, take away
> the freedom of all citizens and you will be congratulated by your peers
> in Parliament.
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
>


More information about the ffmpeg-devel mailing list