Go to the documentation of this file.
19 #include <stdatomic.h>
27 #if HAVE_PTHREADS || HAVE_W32THREADS || HAVE_OS2THREADS
29 typedef struct WorkerContext {
38 WorkerContext *workers;
40 int nb_active_threads;
51 void (*
worker_func)(
void *priv,
int jobnr,
int threadnr,
int nb_jobs,
int nb_threads);
57 unsigned nb_jobs =
ctx->nb_jobs;
58 unsigned nb_active_threads =
ctx->nb_active_threads;
60 unsigned current_job = first_job;
63 ctx->worker_func(
ctx->priv, current_job, first_job, nb_jobs, nb_active_threads);
66 return current_job == nb_jobs + nb_active_threads - 1;
69 static void *attribute_align_arg thread_worker(
void *v)
97 void (*
worker_func)(
void *priv,
int jobnr,
int threadnr,
int nb_jobs,
int nb_threads),
108 nb_threads = nb_cpus + 1;
113 nb_workers = nb_threads;
121 if (nb_workers && !(
ctx->workers =
av_calloc(nb_workers,
sizeof(*
ctx->workers)))) {
129 ctx->nb_threads = nb_threads;
130 ctx->nb_active_threads = 0;
140 for (
i = 0;
i < nb_workers;
i++) {
141 WorkerContext *
w = &
ctx->workers[
i];
168 int nb_workers,
i, is_last = 0;
171 ctx->nb_jobs = nb_jobs;
172 ctx->nb_active_threads =
FFMIN(nb_jobs,
ctx->nb_threads);
175 nb_workers =
ctx->nb_active_threads;
176 if (!
ctx->main_func || !execute_main)
179 for (
i = 0;
i < nb_workers;
i++) {
180 WorkerContext *
w = &
ctx->workers[
i];
187 if (
ctx->main_func && execute_main)
188 ctx->main_func(
ctx->priv);
190 is_last = run_jobs(
ctx);
210 nb_workers =
ctx->nb_threads;
215 for (
i = 0;
i < nb_workers;
i++) {
216 WorkerContext *
w = &
ctx->workers[
i];
223 for (
i = 0;
i < nb_workers;
i++) {
224 WorkerContext *
w = &
ctx->workers[
i];
239 void (*
worker_func)(
void *priv,
int jobnr,
int threadnr,
int nb_jobs,
int nb_threads),
static av_always_inline int pthread_join(pthread_t thread, void **value_ptr)
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static av_always_inline int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
void avpriv_slicethread_execute(AVSliceThread *ctx, int nb_jobs, int execute_main)
Execute slice threading.
struct AVSliceThread AVSliceThread
int avpriv_slicethread_create(AVSliceThread **pctx, void *priv, void(*worker_func)(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads), void(*main_func)(void *priv), int nb_threads)
Create slice threading context.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
static av_always_inline int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
static void worker_func(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads)
#define pthread_mutex_unlock(a)
#define atomic_fetch_add_explicit(object, operand, order)
static av_always_inline int pthread_cond_destroy(pthread_cond_t *cond)
static av_always_inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
#define i(width, name, range_min, range_max)
#define atomic_store_explicit(object, desired, order)
int() main_func(AVCodecContext *c)
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
void * av_calloc(size_t nmemb, size_t size)
static av_always_inline int pthread_cond_signal(pthread_cond_t *cond)
static av_always_inline int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
void avpriv_slicethread_free(AVSliceThread **pctx)
Destroy slice threading context.
static av_always_inline int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
#define atomic_init(obj, value)
int(* cond)(enum AVPixelFormat pix_fmt)
#define pthread_mutex_lock(a)