FFmpeg
|
#include "config.h"
#include <stdatomic.h>
#include <stdint.h>
#include "avcodec.h"
#include "avcodec_internal.h"
#include "codec_internal.h"
#include "decode.h"
#include "hwaccel_internal.h"
#include "hwconfig.h"
#include "internal.h"
#include "pthread_internal.h"
#include "refstruct.h"
#include "thread.h"
#include "threadframe.h"
#include "version_major.h"
#include "libavutil/avassert.h"
#include "libavutil/buffer.h"
#include "libavutil/common.h"
#include "libavutil/cpu.h"
#include "libavutil/frame.h"
#include "libavutil/internal.h"
#include "libavutil/log.h"
#include "libavutil/mem.h"
#include "libavutil/opt.h"
#include "libavutil/thread.h"
Go to the source code of this file.
Data Structures | |
struct | ThreadFrameProgress |
struct | PerThreadContext |
Context used by codec threads and stored in their AVCodecInternal thread_ctx. More... | |
struct | FrameThreadContext |
Context stored in the client AVCodecInternal thread_ctx. More... | |
Macros | |
#define | OFF(member) offsetof(FrameThreadContext, member) |
#define | OFF(member) offsetof(PerThreadContext, member) |
Enumerations | |
enum | { STATE_INPUT_READY, STATE_SETTING_UP, STATE_SETUP_FINISHED } |
enum | { UNINITIALIZED, NEEDS_CLOSE, INITIALIZED } |
Functions | |
static int | hwaccel_serial (const AVCodecContext *avctx) |
static void | async_lock (FrameThreadContext *fctx) |
static void | async_unlock (FrameThreadContext *fctx) |
static void | thread_set_name (PerThreadContext *p) |
static attribute_align_arg void * | frame_worker_thread (void *arg) |
Codec worker thread. More... | |
static int | update_context_from_thread (AVCodecContext *dst, const AVCodecContext *src, int for_user) |
Update the next thread's AVCodecContext with values from the reference thread's context. More... | |
static int | update_context_from_user (AVCodecContext *dst, const AVCodecContext *src) |
Update the next thread's AVCodecContext with values set by the user. More... | |
static int | submit_packet (PerThreadContext *p, AVCodecContext *user_avctx, 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. More... | |
void | ff_thread_report_progress (ThreadFrame *f, int n, int field) |
Notify later decoding threads when part of their reference picture is ready. More... | |
void | ff_thread_await_progress (const ThreadFrame *f, int n, int field) |
Wait for earlier decoding threads to finish reference pictures. More... | |
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. More... | |
static void | park_frame_worker_threads (FrameThreadContext *fctx, int thread_count) |
Waits for all threads to finish. More... | |
DEFINE_OFFSET_ARRAY (FrameThreadContext, thread_ctx, pthread_init_cnt,(OFF(buffer_mutex), OFF(hwaccel_mutex), OFF(async_mutex)),(OFF(async_cond))) | |
DEFINE_OFFSET_ARRAY (PerThreadContext, per_thread, pthread_init_cnt,(OFF(progress_mutex), OFF(mutex)),(OFF(input_cond), OFF(progress_cond), OFF(output_cond))) | |
void | ff_frame_thread_free (AVCodecContext *avctx, int thread_count) |
static av_cold int | init_thread (PerThreadContext *p, int *threads_to_free, FrameThreadContext *fctx, AVCodecContext *avctx, const FFCodec *codec, int first) |
int | ff_frame_thread_init (AVCodecContext *avctx) |
void | ff_thread_flush (AVCodecContext *avctx) |
Wait for decoding threads to finish and reset internal state. More... | |
int | ff_thread_can_start_frame (AVCodecContext *avctx) |
static int | thread_get_buffer_internal (AVCodecContext *avctx, AVFrame *f, int flags) |
int | ff_thread_get_buffer (AVCodecContext *avctx, AVFrame *f, int flags) |
Wrapper around get_buffer() for frame-multithreaded codecs. More... | |
int | ff_thread_get_ext_buffer (AVCodecContext *avctx, ThreadFrame *f, int flags) |
Wrapper around ff_get_buffer() for frame-multithreaded codecs. More... | |
void | ff_thread_release_ext_buffer (ThreadFrame *f) |
Unref a ThreadFrame. More... | |
Frame multithreading support functions
Definition in file pthread_frame.c.
#define OFF | ( | member | ) | offsetof(FrameThreadContext, member) |
Definition at line 690 of file pthread_frame.c.
#define OFF | ( | member | ) | offsetof(PerThreadContext, member) |
Definition at line 690 of file pthread_frame.c.
anonymous enum |
Enumerator | |
---|---|
STATE_INPUT_READY | Set when the thread is awaiting a packet. |
STATE_SETTING_UP | Set before the codec has called ff_thread_finish_setup(). |
STATE_SETUP_FINISHED | Set after the codec has called ff_thread_finish_setup(). |
Definition at line 54 of file pthread_frame.c.
anonymous enum |
Enumerator | |
---|---|
UNINITIALIZED | Thread has not been created, AVCodec->close mustn't be called. |
NEEDS_CLOSE | FFCodec->close needs to be called. |
INITIALIZED | Thread has been properly set up. |
Definition at line 63 of file pthread_frame.c.
|
static |
Definition at line 147 of file pthread_frame.c.
Referenced by ff_thread_finish_setup(), and frame_worker_thread().
|
static |
Definition at line 152 of file pthread_frame.c.
Referenced by ff_thread_decode_frame(), ff_thread_finish_setup(), and park_frame_worker_threads().
|
static |
Definition at line 161 of file pthread_frame.c.
Referenced by ff_thread_decode_frame(), frame_worker_thread(), and park_frame_worker_threads().
|
static |
Definition at line 170 of file pthread_frame.c.
Referenced by frame_worker_thread().
|
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 188 of file pthread_frame.c.
Referenced by init_thread().
|
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 273 of file pthread_frame.c.
Referenced by ff_thread_decode_frame(), ff_thread_flush(), init_thread(), 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 394 of file pthread_frame.c.
Referenced by submit_packet().
|
static |
Definition at line 424 of file pthread_frame.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 FFCodec.decode. This means the decoder has to consume the full packet.
Parameters are the same as FFCodec.decode.
Definition at line 488 of file pthread_frame.c.
Referenced by decode_simple_internal().
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 573 of file pthread_frame.c.
Referenced by decode(), decode_finish_row(), decode_frame(), decode_frame_common(), decode_nal_units(), decode_slice(), decode_tiles(), ff_h264_field_end(), ff_h264_queue_decode_slice(), ff_hevc_hls_filter(), ff_mpv_frame_end(), ff_mpv_frame_start(), ff_mpv_report_decode_progress(), ff_rv34_decode_frame(), finish_frame(), generate_missing_ref(), h264_field_start(), mimic_decode_frame(), rv34_decode_slice(), vp3_draw_horiz_band(), vp78_decode_frame(), vp78_decode_mb_row_sliced(), vp9_decode_frame(), and wavpack_decode_frame().
void ff_thread_await_progress | ( | const 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 596 of file pthread_frame.c.
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 617 of file pthread_frame.c.
Referenced by frame_worker_thread().
|
static |
Waits for all threads to finish.
Definition at line 663 of file pthread_frame.c.
Referenced by ff_frame_thread_free(), and ff_thread_flush().
DEFINE_OFFSET_ARRAY | ( | FrameThreadContext | , |
thread_ctx | , | ||
pthread_init_cnt | , | ||
(OFF(buffer_mutex), OFF(hwaccel_mutex), OFF(async_mutex)) | , | ||
(OFF(async_cond)) | |||
) |
DEFINE_OFFSET_ARRAY | ( | PerThreadContext | , |
per_thread | , | ||
pthread_init_cnt | , | ||
(OFF(progress_mutex), OFF(mutex)) | , | ||
(OFF(input_cond), OFF(progress_cond), OFF(output_cond)) | |||
) |
void ff_frame_thread_free | ( | AVCodecContext * | avctx, |
int | thread_count | ||
) |
Definition at line 696 of file pthread_frame.c.
Referenced by ff_frame_thread_init(), and ff_thread_free().
|
static |
Definition at line 757 of file pthread_frame.c.
Referenced by ff_frame_thread_init().
int ff_frame_thread_init | ( | AVCodecContext * | avctx | ) |
Definition at line 836 of file pthread_frame.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 896 of file pthread_frame.c.
Referenced by avcodec_flush_buffers().
int ff_thread_can_start_frame | ( | AVCodecContext * | avctx | ) |
Definition at line 924 of file pthread_frame.c.
Referenced by ff_mpv_frame_start(), and h264_frame_start().
|
static |
Definition at line 937 of file pthread_frame.c.
Referenced by ff_thread_get_buffer().
int ff_thread_get_buffer | ( | AVCodecContext * | avctx, |
AVFrame * | 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 960 of file pthread_frame.c.
Referenced by 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.
Call this function instead of ff_get_buffer() if you might need to wait for progress on this frame. 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 968 of file pthread_frame.c.
Referenced by alloc_frame(), alloc_picture(), decode_frame(), decode_idat_chunk(), mimic_decode_frame(), vp8_alloc_frame(), vp9_frame_alloc(), and wavpack_decode_block().
void ff_thread_release_ext_buffer | ( | ThreadFrame * | f | ) |
Unref a ThreadFrame.
This is basically a wrapper around av_frame_unref() and should be called instead of it.
avctx | The current context. |
f | The picture being released. |
Definition at line 996 of file pthread_frame.c.
Referenced by decode_frame(), decode_idat_chunk(), ff_h264_unref_picture(), ff_hevc_unref_frame(), ff_mpeg_unref_picture(), ffv1_decode_close(), h264_field_start(), mimic_decode_end(), mimic_decode_frame(), png_dec_end(), update_frames(), vp3_decode_flush(), vp8_alloc_frame(), vp8_release_frame(), vp9_decode_flush(), vp9_decode_frame(), vp9_decode_free(), vp9_frame_unref(), wavpack_decode_block(), wavpack_decode_end(), and wavpack_decode_frame().