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 "config.h"
33 #include "avcodec.h"
34 
35 typedef struct ThreadFrame {
38  // progress->data is an array of 2 ints holding progress for top/bottom
39  // fields
41 } ThreadFrame;
42 
43 /**
44  * Wait for decoding threads to finish and reset internal state.
45  * Called by avcodec_flush_buffers().
46  *
47  * @param avctx The context.
48  */
49 void ff_thread_flush(AVCodecContext *avctx);
50 
51 /**
52  * Submit a new frame to a decoding thread.
53  * Returns the next available frame in picture. *got_picture_ptr
54  * will be 0 if none is available.
55  * The return value on success is the size of the consumed packet for
56  * compatibility with avcodec_decode_video2(). This means the decoder
57  * has to consume the full packet.
58  *
59  * Parameters are the same as avcodec_decode_video2().
60  */
61 int ff_thread_decode_frame(AVCodecContext *avctx, AVFrame *picture,
62  int *got_picture_ptr, AVPacket *avpkt);
63 
64 /**
65  * If the codec defines update_thread_context(), call this
66  * when they are ready for the next thread to start decoding
67  * the next frame. After calling it, do not change any variables
68  * read by the update_thread_context() method, or call ff_thread_get_buffer().
69  *
70  * @param avctx The context.
71  */
73 
74 /**
75  * Notify later decoding threads when part of their reference picture is ready.
76  * Call this when some part of the picture is finished decoding.
77  * Later calls with lower values of progress have no effect.
78  *
79  * @param f The picture being decoded.
80  * @param progress Value, in arbitrary units, of how much of the picture has decoded.
81  * @param field The field being decoded, for field-picture codecs.
82  * 0 for top field or frame pictures, 1 for bottom field.
83  */
84 void ff_thread_report_progress(ThreadFrame *f, int progress, int field);
85 
86 /**
87  * Wait for earlier decoding threads to finish reference pictures.
88  * Call this before accessing some part of a picture, with a given
89  * value for progress, and it will return after the responsible decoding
90  * thread calls ff_thread_report_progress() with the same or
91  * higher value for progress.
92  *
93  * @param f The picture being referenced.
94  * @param progress Value, in arbitrary units, to wait for.
95  * @param field The field being referenced, for field-picture codecs.
96  * 0 for top field or frame pictures, 1 for bottom field.
97  */
98 void ff_thread_await_progress(ThreadFrame *f, int progress, int field);
99 
100 /**
101  * Wrapper around get_format() for frame-multithreaded codecs.
102  * Call this function instead of avctx->get_format().
103  * Cannot be called after the codec has called ff_thread_finish_setup().
104  *
105  * @param avctx The current context.
106  * @param fmt The list of available formats.
107  */
109 
110 /**
111  * Wrapper around get_buffer() for frame-multithreaded codecs.
112  * Call this function instead of ff_get_buffer(f).
113  * Cannot be called after the codec has called ff_thread_finish_setup().
114  *
115  * @param avctx The current context.
116  * @param f The frame to write into.
117  */
119 
120 /**
121  * Wrapper around release_buffer() frame-for multithreaded codecs.
122  * Call this function instead of avctx->release_buffer(f).
123  * The AVFrame will be copied and the actual release_buffer() call
124  * will be performed later. The contents of data pointed to by the
125  * AVFrame should not be changed until ff_thread_get_buffer() is called
126  * on it.
127  *
128  * @param avctx The current context.
129  * @param f The picture being released.
130  */
132 
134 
137 
138 #endif /* AVCODEC_THREAD_H */
void ff_thread_await_progress(ThreadFrame *f, int progress, int field)
Wait for earlier decoding threads to finish reference pictures.
Definition: pthread.c:723
const char * s
Definition: avisynth_c.h:668
int ff_thread_ref_frame(ThreadFrame *dst, ThreadFrame *src)
This structure describes decoded (raw) audio or video data.
Definition: frame.h:76
const char * fmt
Definition: avisynth_c.h:669
AVFrame * f
Definition: thread.h:36
void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
Wrapper around release_buffer() frame-for multithreaded codecs.
Definition: pthread.c:1074
void ff_thread_report_progress(ThreadFrame *f, int progress, int field)
Notify later decoding threads when part of their reference picture is ready.
Definition: pthread.c:705
AVCodecContext * owner
Definition: thread.h:37
int ff_thread_init(AVCodecContext *s)
Definition: pthread.c:1155
struct ThreadFrame ThreadFrame
external API header
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
Definition: pthread.c:1066
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.c:632
enum AVPixelFormat ff_thread_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Wrapper around get_format() for frame-multithreaded codecs.
Definition: pthread.c:1040
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.c:741
void ff_thread_free(AVCodecContext *s)
Definition: pthread.c:1178
AVBufferRef * progress
Definition: thread.h:40
AVS_Value src
Definition: avisynth_c.h:523
main external API structure.
refcounted data buffer API
static int flags
Definition: cpu.c:23
A reference to a data buffer.
Definition: buffer.h:81
else dst[i][x+y *dst_stride[i]]
Definition: vf_mcdeint.c:160
AVPixelFormat
Pixel format.
Definition: pixfmt.h:66
This structure stores compressed data.
void ff_thread_flush(AVCodecContext *avctx)
Wait for decoding threads to finish and reset internal state.
Definition: pthread.c:931