FFmpeg: libavcodec/pthread_slice.c Source File
Go to the documentation of this file. 1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 /**
20 * @file
21 * Slice multithreading support functions
22 * @see doc/multithreading.txt
23 */
24
25 #include "config.h"
26
32
39
43
48
57
63
68 }
69
70 static void worker_func(
void *priv,
int jobnr,
int threadnr,
int nb_jobs,
int nb_threads)
71 {
75
76 ret =
c->func ?
c->func(avctx, (
char *)
c->args +
c->job_size * jobnr)
77 :
c->func2(avctx,
c->args, jobnr, threadnr);
80 }
81
83 {
86
88
89 for (
i = 0;
i <
c->thread_count;
i++) {
93 }
94
98 }
99
101 {
103
106
107 if (job_count <= 0)
108 return 0;
109
110 c->job_size = job_size;
114
116 return 0;
117 }
118
120 {
124 }
125
127 {
130 c->mainfunc = mainfunc;
132 }
133
135 {
138 void (*mainfunc)(void *);
139
140 // We cannot do this in the encoder init as the threads are created before
145
150 // use number of cores + 1 as thread count if there is more than one
151 if (nb_cpus > 1)
153 else
155 }
156
157 if (thread_count <= 1) {
159 return 0;
160 }
161
170 return 0;
171 }
173
176 return 0;
177 }
178
180 {
183
188 }
189
190 for (;
i < thread_count;
i++) {
193 if (err) {
196 }
198 if (err) {
202 }
203 }
204 err = 0;
207 return err;
208 }
209
211 {
215
220 }
221
223 {
227
228 if (!entries || !
field)
return;
229
232
236 }
238 }
239
241 {
244
247 }
248
253 }
255 }
256
257 return 0;
258 }
259
261 {
264 }
int(* func)(AVBPrint *dst, const char *in, const char *arg)
#define FF_CODEC_CAP_SLICE_THREAD_HAS_MF
Codec initializes slice-based threading with a main function.
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.
void ff_slice_thread_free(AVCodecContext *avctx)
struct AVSliceThread AVSliceThread
static void main_function(void *priv)
const struct AVCodec * codec
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.
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
void ff_reset_entries(AVCodecContext *avctx)
void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, int n)
static double(*const func2[])(void *, double, double)
void ff_thread_await_progress2(AVCodecContext *avctx, int field, int thread, int shift)
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this field
struct AVCodecInternal * internal
Private context used for internal data.
int av_cold ff_slice_thread_init_progress(AVCodecContext *avctx)
static void worker_func(void *priv, int jobnr, int threadnr, int nb_jobs, int nb_threads)
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
#define pthread_mutex_unlock(a)
static int thread_execute2(AVCodecContext *avctx, action_func2 *func2, void *arg, int *ret, int job_count)
static int thread_execute(AVCodecContext *avctx, action_func *func, void *arg, int *ret, int job_count, int job_size)
static const av_always_inline FFCodec * ffcodec(const AVCodec *codec)
#define FF_THREAD_SLICE
Decode more than one part of a single frame at once.
int avcodec_default_execute(AVCodecContext *c, int(*func)(AVCodecContext *c2, void *arg2), void *arg, int *ret, int count, int size)
static av_always_inline int pthread_cond_destroy(pthread_cond_t *cond)
int ff_slice_thread_init(AVCodecContext *avctx)
int av_codec_is_encoder(const AVCodec *codec)
static av_always_inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
int ff_slice_thread_execute_with_mainfunc(AVCodecContext *avctx, action_func2 *func2, main_func *mainfunc, void *arg, int *ret, int job_count)
unsigned caps_internal
Internal codec capabilities FF_CODEC_CAP_*.
#define i(width, name, range_min, range_max)
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)
int() action_func2(AVCodecContext *c, void *arg, int jobnr, int threadnr)
static av_always_inline int pthread_cond_signal(pthread_cond_t *cond)
main external API structure.
int active_thread_type
Which multithreading methods are in use by the codec.
int(* execute)(struct AVCodecContext *c, int(*func)(struct AVCodecContext *c2, void *arg), void *arg2, int *ret, int count, int size)
The codec may call this to execute several independent things.
static av_always_inline int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
static int shift(int a, int b)
int() action_func(AVCodecContext *c, void *arg)
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)
int(* execute2)(struct AVCodecContext *c, int(*func)(struct AVCodecContext *c2, void *arg, int jobnr, int threadnr), void *arg2, int *ret, int count)
The codec may call this to execute several independent things.
int ff_alloc_entries(AVCodecContext *avctx, int count)
#define pthread_mutex_lock(a)
Generated on Wed Aug 24 2022 21:41:45 for FFmpeg by
doxygen
1.8.17