FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 typedef struct ThreadFrame {
37  // progress->data is an array of 2 ints holding progress for top/bottom
38  // fields
40 } ThreadFrame;
41 
42 /**
43  * Wait for decoding threads to finish and reset internal state.
44  * Called by avcodec_flush_buffers().
45  *
46  * @param avctx The context.
47  */
48 void ff_thread_flush(AVCodecContext *avctx);
49 
50 /**
51  * Submit a new frame to a decoding thread.
52  * Returns the next available frame in picture. *got_picture_ptr
53  * will be 0 if none is available.
54  * The return value on success is the size of the consumed packet for
55  * compatibility with avcodec_decode_video2(). This means the decoder
56  * has to consume the full packet.
57  *
58  * Parameters are the same as avcodec_decode_video2().
59  */
60 int ff_thread_decode_frame(AVCodecContext *avctx, AVFrame *picture,
61  int *got_picture_ptr, AVPacket *avpkt);
62 
63 /**
64  * If the codec defines update_thread_context(), call this
65  * when they are ready for the next thread to start decoding
66  * the next frame. After calling it, do not change any variables
67  * read by the update_thread_context() method, or call ff_thread_get_buffer().
68  *
69  * @param avctx The context.
70  */
72 
73 /**
74  * Notify later decoding threads when part of their reference picture is ready.
75  * Call this when some part of the picture is finished decoding.
76  * Later calls with lower values of progress have no effect.
77  *
78  * @param f The picture being decoded.
79  * @param progress Value, in arbitrary units, of how much of the picture has decoded.
80  * @param field The field being decoded, for field-picture codecs.
81  * 0 for top field or frame pictures, 1 for bottom field.
82  */
83 void ff_thread_report_progress(ThreadFrame *f, int progress, int field);
84 
85 /**
86  * Wait for earlier decoding threads to finish reference pictures.
87  * Call this before accessing some part of a picture, with a given
88  * value for progress, and it will return after the responsible decoding
89  * thread calls ff_thread_report_progress() with the same or
90  * higher value for progress.
91  *
92  * @param f The picture being referenced.
93  * @param progress Value, in arbitrary units, to wait for.
94  * @param field The field being referenced, for field-picture codecs.
95  * 0 for top field or frame pictures, 1 for bottom field.
96  */
97 void ff_thread_await_progress(ThreadFrame *f, int progress, int field);
98 
99 /**
100  * Wrapper around get_format() for frame-multithreaded codecs.
101  * Call this function instead of avctx->get_format().
102  * Cannot be called after the codec has called ff_thread_finish_setup().
103  *
104  * @param avctx The current context.
105  * @param fmt The list of available formats.
106  */
108 
109 /**
110  * Wrapper around get_buffer() for frame-multithreaded codecs.
111  * Call this function instead of ff_get_buffer(f).
112  * Cannot be called after the codec has called ff_thread_finish_setup().
113  *
114  * @param avctx The current context.
115  * @param f The frame to write into.
116  */
118 
119 /**
120  * Wrapper around release_buffer() frame-for multithreaded codecs.
121  * Call this function instead of avctx->release_buffer(f).
122  * The AVFrame will be copied and the actual release_buffer() call
123  * will be performed later. The contents of data pointed to by the
124  * AVFrame should not be changed until ff_thread_get_buffer() is called
125  * on it.
126  *
127  * @param avctx The current context.
128  * @param f The picture being released.
129  */
131 
133 
136  int (*action_func2)(AVCodecContext *c, void *arg, int jobnr, int threadnr),
137  int (*main_func)(AVCodecContext *c), void *arg, int *ret, int job_count);
139 int ff_alloc_entries(AVCodecContext *avctx, int count);
140 void ff_reset_entries(AVCodecContext *avctx);
141 void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, int n);
142 void ff_thread_await_progress2(AVCodecContext *avctx, int field, int thread, int shift);
143 
144 #endif /* AVCODEC_THREAD_H */
static int shift(int a, int b)
Definition: sonic.c:82
This structure describes decoded (raw) audio or video data.
Definition: frame.h:226
const char * fmt
Definition: avisynth_c.h:769
void ff_thread_flush(AVCodecContext *avctx)
Wait for decoding threads to finish and reset internal state.
int ff_alloc_entries(AVCodecContext *avctx, int count)
void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
Wrapper around release_buffer() frame-for multithreaded codecs.
AVFrame * f
Definition: thread.h:35
void ff_thread_report_progress(ThreadFrame *f, int progress, int field)
Notify later decoding threads when part of their reference picture is ready.
void ff_thread_free(AVCodecContext *s)
Definition: pthread.c:82
enum AVPixelFormat ff_thread_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Wrapper around get_format() for frame-multithreaded codecs.
#define src
Definition: vp8dsp.c:254
#define f(width, name)
Definition: cbs_vp9.c:255
int ff_thread_ref_frame(ThreadFrame *dst, ThreadFrame *src)
Definition: utils.c:1794
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)
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
void ff_thread_report_progress2(AVCodecContext *avctx, int field, int thread, int n)
const char * arg
Definition: jacosubdec.c:66
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...
void ff_thread_await_progress(ThreadFrame *f, int progress, int field)
Wait for earlier decoding threads to finish reference pictures.
GLsizei count
Definition: opengl_enc.c:109
int ff_thread_init(AVCodecContext *s)
Definition: pthread.c:70
#define s(width, name)
Definition: cbs_vp9.c:257
int n
Definition: avisynth_c.h:684
AVBufferRef * progress
Definition: thread.h:39
Libavcodec external API header.
main external API structure.
Definition: avcodec.h:1533
void ff_reset_entries(AVCodecContext *avctx)
AVCodecContext * owner[2]
Definition: thread.h:36
refcounted data buffer API
int( main_func)(AVCodecContext *c)
Definition: pthread_slice.c:41
#define flags(name, subs,...)
Definition: cbs_av1.c:596
A reference to a data buffer.
Definition: buffer.h:81
static double c[64]
int ff_thread_decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, AVPacket *avpkt)
Submit a new frame to a decoding thread.
void ff_thread_await_progress2(AVCodecContext *avctx, int field, int thread, int shift)
int( action_func2)(AVCodecContext *c, void *arg, int jobnr, int threadnr)
Definition: pthread_slice.c:40
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
This structure stores compressed data.
Definition: avcodec.h:1422