FFmpeg
threadframe.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022 Andreas Rheinhardt <andreas.rheinhardt@outlook.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 #ifndef AVCODEC_THREADFRAME_H
22 #define AVCODEC_THREADFRAME_H
23 
24 #include "libavutil/frame.h"
25 #include "avcodec.h"
26 
27 typedef struct ThreadFrame {
30  // progress->data is an array of 2 ints holding progress for top/bottom
31  // fields
33 } ThreadFrame;
34 
35 /**
36  * Notify later decoding threads when part of their reference picture is ready.
37  * Call this when some part of the picture is finished decoding.
38  * Later calls with lower values of progress have no effect.
39  *
40  * @param f The picture being decoded.
41  * @param progress Value, in arbitrary units, of how much of the picture has decoded.
42  * @param field The field being decoded, for field-picture codecs.
43  * 0 for top field or frame pictures, 1 for bottom field.
44  */
45 void ff_thread_report_progress(ThreadFrame *f, int progress, int field);
46 
47 /**
48  * Wait for earlier decoding threads to finish reference pictures.
49  * Call this before accessing some part of a picture, with a given
50  * value for progress, and it will return after the responsible decoding
51  * thread calls ff_thread_report_progress() with the same or
52  * higher value for progress.
53  *
54  * @param f The picture being referenced.
55  * @param progress Value, in arbitrary units, to wait for.
56  * @param field The field being referenced, for field-picture codecs.
57  * 0 for top field or frame pictures, 1 for bottom field.
58  */
59 void ff_thread_await_progress(const ThreadFrame *f, int progress, int field);
60 
61 /**
62  * Wrapper around ff_get_buffer() for frame-multithreaded codecs.
63  * Call this function instead of ff_get_buffer() if you might need
64  * to wait for progress on this frame.
65  * Cannot be called after the codec has called ff_thread_finish_setup().
66  *
67  * @param avctx The current context.
68  * @param f The frame to write into.
69  * @note: It is fine to call this with codecs that do not support
70  * frame threading.
71  */
73 
74 /**
75  * Unref a ThreadFrame.
76  *
77  * This is basically a wrapper around av_frame_unref() and should
78  * be called instead of it.
79  *
80  * @param avctx The current context.
81  * @param f The picture being released.
82  */
84 
86 
88 
89 #endif
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:325
ff_thread_get_ext_buffer
int ff_thread_get_ext_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around ff_get_buffer() for frame-multithreaded codecs.
Definition: pthread_frame.c:1092
ff_thread_can_start_frame
int ff_thread_can_start_frame(AVCodecContext *avctx)
Definition: pthread_frame.c:983
ThreadFrame::f
AVFrame * f
Definition: threadframe.h:28
ThreadFrame::owner
AVCodecContext * owner[2]
Definition: threadframe.h:29
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
ff_thread_ref_frame
int ff_thread_ref_frame(ThreadFrame *dst, const ThreadFrame *src)
Definition: utils.c:885
ThreadFrame::progress
AVBufferRef * progress
Definition: threadframe.h:32
f
f
Definition: af_crystalizer.c:122
frame.h
ff_thread_await_progress
void ff_thread_await_progress(const ThreadFrame *f, int progress, int field)
Wait for earlier decoding threads to finish reference pictures.
Definition: pthread_frame.c:655
avcodec.h
AVCodecContext
main external API structure.
Definition: avcodec.h:398
ThreadFrame
Definition: threadframe.h:27
ff_thread_release_ext_buffer
void ff_thread_release_ext_buffer(AVCodecContext *avctx, ThreadFrame *f)
Unref a ThreadFrame.
Definition: pthread_frame.c:1190
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:82
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
ff_thread_report_progress
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_frame.c:632
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561