FFmpeg
thread.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 Alexander Strange <astrange@ithinksw.com>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @file
23  * Multithreading API for decoders
24  * @author Alexander Strange <astrange@ithinksw.com>
25  */
26 
27 #ifndef AVCODEC_THREAD_H
28 #define AVCODEC_THREAD_H
29 
30 #include "libavutil/buffer.h"
31 
32 #include "avcodec.h"
33 
35 
36 /**
37  * If the codec defines update_thread_context(), call this
38  * when they are ready for the next thread to start decoding
39  * the next frame. After calling it, do not change any variables
40  * read by the update_thread_context() method, or call ff_thread_get_buffer().
41  *
42  * @param avctx The context.
43  */
45 
46 /**
47  * Wrapper around get_buffer() for frame-multithreaded codecs.
48  * Call this function instead of ff_get_buffer(f).
49  * Cannot be called after the codec has called ff_thread_finish_setup().
50  *
51  * @param avctx The current context.
52  * @param f The frame to write into.
53  */
55 
57  int (*action_func2)(AVCodecContext *c, void *arg, int jobnr, int threadnr),
58  int (*main_func)(AVCodecContext *c), void *arg, int *ret, int job_count);
59 
64 };
65 
66 /**
67  * Allows to synchronize objects whose lifetime is the whole decoding
68  * process among all frame threads.
69  *
70  * When called from a non-copy thread, do nothing.
71  * When called from another thread, place a new RefStruct reference
72  * at the given offset in the calling thread's private data from
73  * the RefStruct reference in the private data of the first decoding thread.
74  * The first thread must have a valid RefStruct reference at the given
75  * offset in its private data; the calling thread must not have
76  * a reference at this offset in its private data (must be NULL).
77  *
78  * @param avctx an AVCodecContext
79  * @param offset offset of the RefStruct reference in avctx's private data
80  *
81  * @retval FF_THREAD_IS_COPY if frame-threading is in use and the
82  * calling thread is a copy; in this case, the RefStruct reference
83  * will be set.
84  * @retval FF_THREAD_IS_MAIN_THREAD if frame-threading is in use
85  * and the calling thread is the main thread.
86  * @retval FF_THREAD_NO_FRAME_THREADING if frame-threading is not in use.
87  */
89 
90 #endif /* AVCODEC_THREAD_H */
FF_THREAD_IS_FIRST_THREAD
@ FF_THREAD_IS_FIRST_THREAD
Definition: thread.h:62
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:389
ff_thread_sync_ref
enum ThreadingStatus ff_thread_sync_ref(AVCodecContext *avctx, size_t offset)
Allows to synchronize objects whose lifetime is the whole decoding process among all frame threads.
Definition: decode.c:1904
arg
const char * arg
Definition: jacosubdec.c:67
FF_THREAD_IS_COPY
@ FF_THREAD_IS_COPY
Definition: thread.h:61
c
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
Definition: undefined.txt:32
f
f
Definition: af_crystalizer.c:122
buffer.h
offset
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 just let it vf offset
Definition: writing_filters.txt:86
FF_THREAD_NO_FRAME_THREADING
@ FF_THREAD_NO_FRAME_THREADING
Definition: thread.h:63
main_func
int() main_func(AVCodecContext *c)
Definition: pthread_slice.c:42
avcodec.h
ret
ret
Definition: filter_design.txt:187
action_func2
int() action_func2(AVCodecContext *c, void *arg, int jobnr, int threadnr)
Definition: pthread_slice.c:41
AVCodecContext
main external API structure.
Definition: avcodec.h:451
ff_thread_finish_setup
void ff_thread_finish_setup(AVCodecContext *avctx)
If the codec defines update_thread_context(), call this when they are ready for the next thread to st...
Definition: pthread_frame.c:671
ThreadingStatus
ThreadingStatus
Definition: thread.h:60
ff_slice_thread_execute_with_mainfunc
int ff_slice_thread_execute_with_mainfunc(AVCodecContext *avctx, int(*action_func2)(AVCodecContext *c, void *arg, int jobnr, int threadnr), int(*main_func)(AVCodecContext *c), void *arg, int *ret, int job_count)
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:482
ff_thread_get_buffer
int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
Definition: pthread_frame.c:1049
ff_thread_can_start_frame
int ff_thread_can_start_frame(AVCodecContext *avctx)
Definition: pthread_frame.c:1013