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 int ff_slice_thread_allocz_entries(AVCodecContext *avctx, int count);
61 void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, int n);
62 void ff_thread_await_progress2(AVCodecContext *avctx, int field, int thread, int shift);
63 
68 };
69 
70 /**
71  * Allows to synchronize objects whose lifetime is the whole decoding
72  * process among all frame threads.
73  *
74  * When called from a non-copy thread, do nothing.
75  * When called from another thread, place a new RefStruct reference
76  * at the given offset in the calling thread's private data from
77  * the RefStruct reference in the private data of the first decoding thread.
78  * The first thread must have a valid RefStruct reference at the given
79  * offset in its private data; the calling thread must not have
80  * a reference at this offset in its private data (must be NULL).
81  *
82  * @param avctx an AVCodecContext
83  * @param offset offset of the RefStruct reference in avctx's private data
84  *
85  * @retval FF_THREAD_IS_COPY if frame-threading is in use and the
86  * calling thread is a copy; in this case, the RefStruct reference
87  * will be set.
88  * @retval FF_THREAD_IS_MAIN_THREAD if frame-threading is in use
89  * and the calling thread is the main thread.
90  * @retval FF_THREAD_NO_FRAME_THREADING if frame-threading is not in use.
91  */
93 
94 #endif /* AVCODEC_THREAD_H */
FF_THREAD_IS_FIRST_THREAD
@ FF_THREAD_IS_FIRST_THREAD
Definition: thread.h:66
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:374
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:1794
ff_slice_thread_allocz_entries
int ff_slice_thread_allocz_entries(AVCodecContext *avctx, int count)
Definition: pthread_slice.c:240
field
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
Definition: writing_filters.txt:78
arg
const char * arg
Definition: jacosubdec.c:67
ff_thread_await_progress2
void ff_thread_await_progress2(AVCodecContext *avctx, int field, int thread, int shift)
Definition: pthread_slice.c:222
FF_THREAD_IS_COPY
@ FF_THREAD_IS_COPY
Definition: thread.h:65
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
shift
static int shift(int a, int b)
Definition: bonk.c:261
buffer.h
ff_slice_thread_init_progress
int ff_slice_thread_init_progress(AVCodecContext *avctx)
Definition: pthread_slice.c:179
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:67
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:445
ff_thread_report_progress2
void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, int n)
Definition: pthread_slice.c:210
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:670
ThreadingStatus
ThreadingStatus
Definition: thread.h:64
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:1046
ff_thread_can_start_frame
int ff_thread_can_start_frame(AVCodecContext *avctx)
Definition: pthread_frame.c:1010