FFmpeg
|
Multithreading support functions. More...
#include "config.h"
#include "avcodec.h"
#include "internal.h"
#include "thread.h"
#include "libavutil/avassert.h"
#include "libavutil/common.h"
#include "libavutil/cpu.h"
#include "libavutil/internal.h"
Go to the source code of this file.
Data Structures | |
struct | ThreadContext |
struct | PerThreadContext |
Context used by codec threads and stored in their AVCodecContext thread_opaque. More... | |
struct | FrameThreadContext |
Context stored in the client AVCodecContext thread_opaque. More... | |
Macros | |
#define | MAX_AUTO_THREADS 16 |
#define | THREAD_SAFE_CALLBACKS(avctx) ((avctx)->thread_safe_callbacks || (!(avctx)->get_buffer && (avctx)->get_buffer2 == avcodec_default_get_buffer2)) |
#define | copy_fields(s, e) memcpy(&dst->s, &src->s, (char*)&dst->e - (char*)&dst->s); |
Typedefs | |
typedef int( | action_func )(AVCodecContext *c, void *arg) |
typedef int( | action_func2 )(AVCodecContext *c, void *arg, int jobnr, int threadnr) |
Functions | |
static void *attribute_align_arg | worker (void *v) |
static av_always_inline void | avcodec_thread_park_workers (ThreadContext *c, int thread_count) |
static void | thread_free (AVCodecContext *avctx) |
static int | avcodec_thread_execute (AVCodecContext *avctx, action_func *func, void *arg, int *ret, int job_count, int job_size) |
static int | avcodec_thread_execute2 (AVCodecContext *avctx, action_func2 *func2, void *arg, int *ret, int job_count) |
static int | thread_init_internal (AVCodecContext *avctx) |
static attribute_align_arg void * | frame_worker_thread (void *arg) |
Codec worker thread. | |
static int | update_context_from_thread (AVCodecContext *dst, AVCodecContext *src, int for_user) |
Update the next thread's AVCodecContext with values from the reference thread's context. | |
static int | update_context_from_user (AVCodecContext *dst, AVCodecContext *src) |
Update the next thread's AVCodecContext with values set by the user. | |
static void | release_delayed_buffers (PerThreadContext *p) |
Releases the buffers that this decoding thread was the last user of. | |
static int | submit_packet (PerThreadContext *p, AVPacket *avpkt) |
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_report_progress (ThreadFrame *f, int n, int field) |
Notify later decoding threads when part of their reference picture is ready. | |
void | ff_thread_await_progress (ThreadFrame *f, int n, int field) |
Wait for earlier decoding threads to finish reference pictures. | |
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 start decoding the next frame. | |
static void | park_frame_worker_threads (FrameThreadContext *fctx, int thread_count) |
Waits for all threads to finish. | |
static void | frame_thread_free (AVCodecContext *avctx, int thread_count) |
static int | frame_thread_init (AVCodecContext *avctx) |
void | ff_thread_flush (AVCodecContext *avctx) |
Wait for decoding threads to finish and reset internal state. | |
int | ff_thread_can_start_frame (AVCodecContext *avctx) |
static int | thread_get_buffer_internal (AVCodecContext *avctx, ThreadFrame *f, int flags) |
enum AVPixelFormat | ff_thread_get_format (AVCodecContext *avctx, const enum AVPixelFormat *fmt) |
Wrapper around get_format() for frame-multithreaded codecs. | |
int | ff_thread_get_buffer (AVCodecContext *avctx, ThreadFrame *f, int flags) |
Wrapper around get_buffer() for frame-multithreaded codecs. | |
void | ff_thread_release_buffer (AVCodecContext *avctx, ThreadFrame *f) |
Wrapper around release_buffer() frame-for multithreaded codecs. | |
static void | validate_thread_parameters (AVCodecContext *avctx) |
Set the threading algorithms used. | |
int | ff_thread_init (AVCodecContext *avctx) |
void | ff_thread_free (AVCodecContext *avctx) |
void | ff_thread_report_progress2 (AVCodecContext *avctx, int field, int thread, int n) |
void | ff_thread_await_progress2 (AVCodecContext *avctx, int field, int thread, int shift) |
int | ff_alloc_entries (AVCodecContext *avctx, int count) |
void | ff_reset_entries (AVCodecContext *avctx) |
#define MAX_AUTO_THREADS 16 |
Definition at line 154 of file pthread.c.
Referenced by frame_thread_init(), thread_init_internal(), and validate_thread_parameters().
#define THREAD_SAFE_CALLBACKS | ( | avctx | ) | ((avctx)->thread_safe_callbacks || (!(avctx)->get_buffer && (avctx)->get_buffer2 == avcodec_default_get_buffer2)) |
Definition at line 316 of file pthread.c.
Referenced by ff_thread_can_start_frame(), frame_worker_thread(), and thread_get_buffer_internal().
typedef int( action_func2)(AVCodecContext *c, void *arg, int jobnr, int threadnr) |
|
static |
Definition at line 156 of file pthread.c.
Referenced by thread_init_internal().
|
static |
Definition at line 192 of file pthread.c.
Referenced by avcodec_thread_execute(), and thread_init_internal().
|
static |
Definition at line 199 of file pthread.c.
Referenced by ff_thread_free().
|
static |
Definition at line 219 of file pthread.c.
Referenced by avcodec_thread_execute2(), and thread_init_internal().
|
static |
Definition at line 252 of file pthread.c.
Referenced by thread_init_internal().
|
static |
Definition at line 259 of file pthread.c.
Referenced by ff_thread_init().
|
static |
Codec worker thread.
Automatically calls ff_thread_finish_setup() if the codec does not provide an update_thread_context method, or if the codec returns before calling it.
Definition at line 326 of file pthread.c.
Referenced by frame_thread_init().
|
static |
Update the next thread's AVCodecContext with values from the reference thread's context.
dst | The destination context. |
src | The source context. |
for_user | 0 if the destination is a codec thread, 1 if the destination is the user's thread |
Definition at line 375 of file pthread.c.
Referenced by ff_thread_decode_frame(), ff_thread_flush(), frame_thread_free(), frame_thread_init(), and submit_packet().
|
static |
Update the next thread's AVCodecContext with values set by the user.
dst | The destination context. |
src | The source context. |
Definition at line 434 of file pthread.c.
Referenced by ff_thread_decode_frame().
|
static |
Releases the buffers that this decoding thread was the last user of.
Definition at line 480 of file pthread.c.
Referenced by ff_thread_flush(), frame_thread_free(), and submit_packet().
|
static |
Definition at line 500 of file pthread.c.
Referenced by 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.
Returns the next available frame in picture. *got_picture_ptr will be 0 if none is available. The return value on success is the size of the consumed packet for compatibility with avcodec_decode_video2(). This means the decoder has to consume the full packet.
Parameters are the same as avcodec_decode_video2().
Definition at line 588 of file pthread.c.
Referenced by avcodec_decode_audio4(), and avcodec_decode_video2().
void ff_thread_report_progress | ( | ThreadFrame * | f, |
int | progress, | ||
int | field | ||
) |
Notify later decoding threads when part of their reference picture is ready.
Call this when some part of the picture is finished decoding. Later calls with lower values of progress have no effect.
f | The picture being decoded. |
progress | Value, in arbitrary units, of how much of the picture has decoded. |
field | The field being decoded, for field-picture codecs. 0 for top field or frame pictures, 1 for bottom field. |
Definition at line 662 of file pthread.c.
Referenced by decode(), decode_finish_row(), decode_frame(), decode_nal_units(), decode_slice_header(), ff_hevc_hls_filters(), ff_MPV_frame_end(), ff_MPV_frame_start(), ff_MPV_report_decode_progress(), ff_rv34_decode_frame(), ff_vp8_decode_frame(), field_end(), finish_frame(), generate_missing_ref(), hevc_frame_start(), mimic_decode_frame(), rv34_decode_slice(), vp3_draw_horiz_band(), and vp8_decode_mb_row_sliced().
void ff_thread_await_progress | ( | ThreadFrame * | f, |
int | progress, | ||
int | field | ||
) |
Wait for earlier decoding threads to finish reference pictures.
Call this before accessing some part of a picture, with a given value for progress, and it will return after the responsible decoding thread calls ff_thread_report_progress() with the same or higher value for progress.
f | The picture being referenced. |
progress | Value, in arbitrary units, to wait for. |
field | The field being referenced, for field-picture codecs. 0 for top field or frame pictures, 1 for bottom field. |
Definition at line 680 of file pthread.c.
Referenced by await_reference_mb_row(), await_reference_row(), await_references(), decode(), decode_frame(), decode_slice(), ff_er_frame_end(), ff_vp8_decode_frame(), guess_mv(), hevc_await_progress(), is_intra_more_likely(), mpeg4_decode_mb(), MPV_decode_mb_internal(), rv34_decode_mv(), rv34_mc(), temporal_luma_motion_vector(), vp8_decode_mb_row_no_filter(), vp8_mc_chroma(), and vp8_mc_luma().
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 start decoding the next frame.
After calling it, do not change any variables read by the update_thread_context() method, or call ff_thread_get_buffer().
avctx | The context. |
Definition at line 698 of file pthread.c.
Referenced by decode_frame(), decode_postinit(), ff_h263_decode_frame(), ff_rv34_decode_frame(), ff_vp8_decode_frame(), frame_worker_thread(), hevc_frame_start(), mimic_decode_frame(), mpeg_field_start(), tak_decode_frame(), and thread_get_buffer_internal().
|
static |
Waits for all threads to finish.
Definition at line 714 of file pthread.c.
Referenced by ff_thread_flush(), and frame_thread_free().
|
static |
Definition at line 731 of file pthread.c.
Referenced by ff_thread_free(), and frame_thread_init().
|
static |
Definition at line 794 of file pthread.c.
Referenced by ff_thread_init().
void ff_thread_flush | ( | AVCodecContext * | avctx | ) |
Wait for decoding threads to finish and reset internal state.
Called by avcodec_flush_buffers().
avctx | The context. |
Definition at line 894 of file pthread.c.
Referenced by avcodec_flush_buffers().
int ff_thread_can_start_frame | ( | AVCodecContext * | avctx | ) |
|
static |
Definition at line 932 of file pthread.c.
Referenced by ff_thread_get_buffer().
enum AVPixelFormat ff_thread_get_format | ( | AVCodecContext * | avctx, |
const enum AVPixelFormat * | fmt | ||
) |
Wrapper around get_format() for frame-multithreaded codecs.
Call this function instead of avctx->get_format(). Cannot be called after the codec has called ff_thread_finish_setup().
avctx | The current context. |
fmt | The list of available formats. |
Definition at line 997 of file pthread.c.
Referenced by get_pixel_format(), and mpeg_get_pixelformat().
int ff_thread_get_buffer | ( | AVCodecContext * | avctx, |
ThreadFrame * | f, | ||
int | flags | ||
) |
Wrapper around get_buffer() for frame-multithreaded codecs.
Call this function instead of ff_get_buffer(f). Cannot be called after the codec has called ff_thread_finish_setup().
avctx | The current context. |
f | The frame to write into. |
Definition at line 1023 of file pthread.c.
Referenced by alloc_frame(), alloc_frame_buffer(), alloc_picture(), decode_element(), decode_entropy_coded_image(), decode_frame(), dnxhd_decode_frame(), flac_decode_frame(), init_image(), jpeg2000_decode_frame(), lag_decode_frame(), libopenjpeg_decode_frame(), mimic_decode_frame(), tak_decode_frame(), tta_decode_frame(), vp8_alloc_frame(), and wavpack_decode_block().
void ff_thread_release_buffer | ( | AVCodecContext * | avctx, |
ThreadFrame * | f | ||
) |
Wrapper around release_buffer() frame-for multithreaded codecs.
Call this function instead of avctx->release_buffer(f). The AVFrame will be copied and the actual release_buffer() call will be performed later. The contents of data pointed to by the AVFrame should not be changed until ff_thread_get_buffer() is called on it.
avctx | The current context. |
f | The picture being released. |
Definition at line 1031 of file pthread.c.
Referenced by decode_frame(), ff_hevc_unref_frame(), ff_mpeg_unref_picture(), ff_thread_ref_frame(), ffv1_close(), mimic_decode_end(), mimic_decode_frame(), mimic_decode_update_thread_context(), png_dec_end(), ref_frame(), unref_picture(), update_frames(), update_thread_context(), vp3_decode_flush(), vp8_alloc_frame(), and vp8_release_frame().
|
static |
Set the threading algorithms used.
Threading requires more than one thread. Frame threading requires entire frames to be passed to the codec, and introduces extra decoding delay, so is incompatible with low_delay.
avctx | The context. |
Definition at line 1090 of file pthread.c.
Referenced by ff_thread_init().
int ff_thread_init | ( | AVCodecContext * | avctx | ) |
Definition at line 1114 of file pthread.c.
Referenced by avcodec_open2().
void ff_thread_free | ( | AVCodecContext * | avctx | ) |
Definition at line 1130 of file pthread.c.
Referenced by avcodec_close(), and thread_init_internal().
void ff_thread_report_progress2 | ( | AVCodecContext * | avctx, |
int | field, | ||
int | thread, | ||
int | n | ||
) |
Definition at line 1138 of file pthread.c.
Referenced by hls_decode_entry_wpp().
void ff_thread_await_progress2 | ( | AVCodecContext * | avctx, |
int | field, | ||
int | thread, | ||
int | shift | ||
) |
Definition at line 1149 of file pthread.c.
Referenced by hls_decode_entry_wpp().
int ff_alloc_entries | ( | AVCodecContext * | avctx, |
int | count | ||
) |
Definition at line 1165 of file pthread.c.
Referenced by hls_slice_data_wpp().
void ff_reset_entries | ( | AVCodecContext * | avctx | ) |
Definition at line 1191 of file pthread.c.
Referenced by hls_slice_data_wpp().