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 support functions
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 
34 /**
35  * Wait for decoding threads to finish and reset internal state.
36  * Called by avcodec_flush_buffers().
37  *
38  * @param avctx The context.
39  */
40 void ff_thread_flush(AVCodecContext *avctx);
41 
42 /**
43  * Submit a new frame to a decoding thread.
44  * Returns the next available frame in picture. *got_picture_ptr
45  * will be 0 if none is available.
46  * The return value on success is the size of the consumed packet for
47  * compatibility with FFCodec.decode. This means the decoder
48  * has to consume the full packet.
49  *
50  * Parameters are the same as FFCodec.decode.
51  */
52 int ff_thread_decode_frame(AVCodecContext *avctx, AVFrame *picture,
53  int *got_picture_ptr, AVPacket *avpkt);
54 
55 /**
56  * If the codec defines update_thread_context(), call this
57  * when they are ready for the next thread to start decoding
58  * the next frame. After calling it, do not change any variables
59  * read by the update_thread_context() method, or call ff_thread_get_buffer().
60  *
61  * @param avctx The context.
62  */
64 
65 #if FF_API_THREAD_SAFE_CALLBACKS
66 /**
67  * Wrapper around get_format() for frame-multithreaded codecs.
68  * Call this function instead of avctx->get_format().
69  * Cannot be called after the codec has called ff_thread_finish_setup().
70  *
71  * @param avctx The current context.
72  * @param fmt The list of available formats.
73  */
75 #else
76 #define ff_thread_get_format ff_get_format
77 #endif
78 
79 /**
80  * Wrapper around get_buffer() for frame-multithreaded codecs.
81  * Call this function instead of ff_get_buffer(f).
82  * Cannot be called after the codec has called ff_thread_finish_setup().
83  *
84  * @param avctx The current context.
85  * @param f The frame to write into.
86  */
88 
89 /**
90  * Wrapper around release_buffer() frame-for multithreaded codecs.
91  * Call this function instead of avctx->release_buffer(f).
92  * The AVFrame will be copied and the actual release_buffer() call
93  * will be performed later. The contents of data pointed to by the
94  * AVFrame should not be changed until ff_thread_get_buffer() is called
95  * on it.
96  *
97  * @param avctx The current context.
98  * @param f The picture being released.
99  */
101 
104  int (*action_func2)(AVCodecContext *c, void *arg, int jobnr, int threadnr),
105  int (*main_func)(AVCodecContext *c), void *arg, int *ret, int job_count);
107 int ff_slice_thread_allocz_entries(AVCodecContext *avctx, int count);
109 void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, int n);
110 void ff_thread_await_progress2(AVCodecContext *avctx, int field, int thread, int shift);
111 
112 #endif /* AVCODEC_THREAD_H */
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
ff_thread_init
int ff_thread_init(AVCodecContext *s)
Definition: pthread.c:74
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:325
ff_thread_decode_frame
int ff_thread_decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, AVPacket *avpkt)
Submit a new frame to a decoding thread.
Definition: pthread_frame.c:510
s
#define s(width, name)
Definition: cbs_vp9.c:256
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
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
ff_thread_flush
void ff_thread_flush(AVCodecContext *avctx)
Wait for decoding threads to finish and reset internal state.
Definition: pthread_frame.c:902
ff_thread_free
void ff_thread_free(AVCodecContext *s)
Definition: pthread.c:86
f
f
Definition: af_crystalizer.c:122
ff_thread_get_format
enum AVPixelFormat ff_thread_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Wrapper around get_format() for frame-multithreaded codecs.
Definition: pthread_frame.c:1005
buffer.h
ff_slice_thread_init_progress
int ff_slice_thread_init_progress(AVCodecContext *avctx)
Definition: pthread_slice.c:179
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
ff_thread_release_buffer
void ff_thread_release_buffer(AVCodecContext *avctx, AVFrame *f)
Wrapper around release_buffer() frame-for multithreaded codecs.
Definition: pthread_frame.c:1074
AVCodecContext
main external API structure.
Definition: avcodec.h:398
ff_thread_report_progress2
void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, int n)
Definition: pthread_slice.c:210
shift
static int shift(int a, int b)
Definition: sonic.c:88
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:639
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)
AVPacket
This structure stores compressed data.
Definition: packet.h:351
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
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:1035