FFmpeg: libavcodec/pthread_frame.c Source File
Go to the documentation of this file. 1 /*
2 * This file is part of FFmpeg.
3 *
4 * FFmpeg is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * FFmpeg is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with FFmpeg; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17 */
18
19 /**
20 * @file
21 * Frame multithreading support functions
22 * @see doc/multithreading.txt
23 */
24
25 #include <stdatomic.h>
26
41
52
53 enum {
54 /// Set when the thread is awaiting a packet.
56 /// Set before the codec has called ff_thread_finish_setup().
58 /// Set after the codec has called ff_thread_finish_setup().
60 };
61
62 enum {
63 UNINITIALIZED,
///< Thread has not been created, AVCodec->close mustn't be called
66 };
67
73
77
78 /**
79 * Context used by codec threads and stored in their AVCodecInternal thread_ctx.
80 */
83
90
93
95
96 AVPacket *
avpkt;
///< Input packet (for decoding) or output (for encoding).
97
98 /**
99 * Decoded frames from a single decode iteration.
100 */
102 int result;
///< The result of the last codec decode/encode() call.
103
105
106 int die;
///< Set when the thread should exit.
107
110
111 // set to 1 in ff_thread_finish_setup() when a threadsafe hwaccel is used;
112 // cannot check hwaccel caps directly, because
113 // worked threads clear hwaccel state for thread-unsafe hwaccels
114 // after each decode call
116
119
120 /**
121 * Context stored in the client AVCodecInternal thread_ctx.
122 */
126
129 /**
130 * This lock is used for ensuring threads run in serial when thread-unsafe
131 * hwaccel is used.
132 */
137
140
141 /**
142 * Packet to be submitted to the next thread for decoding.
143 */
145
148
149 /* hwaccel state for thread-unsafe hwaccels is temporarily stored here in
150 * order to transfer its ownership to the next decoding thread without the
151 * need for extra synchronization */
156
158 {
160 }
161
163 {
169 }
170
172 {
178 }
179
181 {
183 int idx =
p -
p->parent->threads;
185
187
189 }
190
191 // get a free frame to decode into
193 {
194 if (
df->nb_f ==
df->nb_f_allocated) {
200
202 if (!
df->f[
df->nb_f])
204
205 df->nb_f_allocated++;
206 }
207
209
210 return df->f[
df->nb_f];
211 }
212
214 {
217 memmove(
df->f,
df->f + 1, (
df->nb_f - 1) *
sizeof(*
df->f));
218 df->f[--
df->nb_f] = tmp_frame;
219 }
220
222 {
223 for (
size_t i = 0;
i <
df->nb_f;
i++)
226 }
227
229 {
230 for (
size_t i = 0;
i <
df->nb_f_allocated;
i++)
234 df->nb_f_allocated = 0;
235 }
236
237 /**
238 * Codec worker thread.
239 *
240 * Automatically calls ff_thread_finish_setup() if the codec does
241 * not provide an update_thread_context method, or if the codec returns
242 * before calling it.
243 */
245 {
249
251
253 while (1) {
255
258
260
263
264 /* If a decoder supports hwaccel, then it must call ff_get_format().
265 * Since that call must happen before ff_thread_finish_setup(), the
266 * decoder is required to implement update_thread_context() and call
267 * ff_thread_finish_setup() manually. Therefore the above
268 * ff_thread_finish_setup() call did not happen and hwaccel_serializing
269 * cannot be true here. */
271
272 /* if the previous thread uses thread-unsafe hwaccel then we take the
273 * lock to ensure the threads don't run concurrently */
276 p->hwaccel_serializing = 1;
277 }
278
282
283 /* get the frame which will store the output */
287 goto alloc_fail;
288 }
289
290 /* do the actual decoding */
294 else if (ret < 0 && frame->buf[0])
296
298 }
299
302
303 alloc_fail:
304 if (
p->hwaccel_serializing) {
305 /* wipe hwaccel state for thread-unsafe hwaccels to avoid stale
306 * pointers lying around;
307 * the state was transferred to FrameThreadContext in
308 * ff_thread_finish_setup(), so nothing is leaked */
312
313 p->hwaccel_serializing = 0;
315 }
318
319 if (
p->async_serializing) {
320 p->async_serializing = 0;
321
323 }
324
326
328
332 }
334
336 }
337
338 /**
339 * Update the next thread's AVCodecContext with values from the reference thread's context.
340 *
341 * @param dst The destination context.
342 * @param src The source context.
343 * @param for_user 0 if the destination is a codec thread, 1 if the destination is the user's thread
344 * @return 0 on success, negative error code on failure
345 */
347 {
349 int err = 0;
350
352 dst->time_base =
src->time_base;
353 dst->framerate =
src->framerate;
355 dst->height =
src->height;
356 dst->pix_fmt =
src->pix_fmt;
357 dst->sw_pix_fmt =
src->sw_pix_fmt;
358
359 dst->coded_width =
src->coded_width;
360 dst->coded_height =
src->coded_height;
361
362 dst->has_b_frames =
src->has_b_frames;
363 dst->idct_algo =
src->idct_algo;
364 #if FF_API_CODEC_PROPS
366 dst->properties =
src->properties;
368 #endif
369
370 dst->bits_per_coded_sample =
src->bits_per_coded_sample;
371 dst->sample_aspect_ratio =
src->sample_aspect_ratio;
372
373 dst->profile =
src->profile;
375
376 dst->bits_per_raw_sample =
src->bits_per_raw_sample;
377 dst->color_primaries =
src->color_primaries;
378
379 dst->alpha_mode =
src->alpha_mode;
380
381 dst->color_trc =
src->color_trc;
382 dst->colorspace =
src->colorspace;
383 dst->color_range =
src->color_range;
384 dst->chroma_sample_location =
src->chroma_sample_location;
385
386 dst->sample_rate =
src->sample_rate;
387 dst->sample_fmt =
src->sample_fmt;
389 if (err < 0)
390 return err;
391
392 if (!!
dst->hw_frames_ctx != !!
src->hw_frames_ctx ||
393 (
dst->hw_frames_ctx &&
dst->hw_frames_ctx->data !=
src->hw_frames_ctx->data)) {
395
396 if (
src->hw_frames_ctx) {
398 if (!
dst->hw_frames_ctx)
400 }
401 }
402
403 dst->hwaccel_flags =
src->hwaccel_flags;
404
406 }
407
408 if (for_user) {
411 } else {
414
417 if (err < 0)
418 return err;
419 }
420
421 // reset dst hwaccel state if needed
423 (!
dst->hwaccel && !
dst->internal->hwaccel_priv_data));
428 }
429
430 // propagate hwaccel state for threadsafe hwaccels
436
437 dst->internal->hwaccel_priv_data =
439 if (!
dst->internal->hwaccel_priv_data)
441 }
442 dst->hwaccel =
src->hwaccel;
443 }
445
446 if (
hwaccel->update_thread_context) {
448 if (err < 0) {
451 return err;
452 }
453 }
455 }
456 }
457
458 return err;
459 }
460
461 /**
462 * Update the next thread's AVCodecContext with values set by the user.
463 *
464 * @param dst The destination context.
465 * @param src The source context.
466 * @return 0 on success, negative error code on failure
467 */
469 {
470 int err;
471
473
474 dst->draw_horiz_band=
src->draw_horiz_band;
475 dst->get_buffer2 =
src->get_buffer2;
476
477 dst->opaque =
src->opaque;
479
480 dst->slice_flags =
src->slice_flags;
481 dst->flags2 =
src->flags2;
482 dst->export_side_data =
src->export_side_data;
483
484 dst->skip_loop_filter =
src->skip_loop_filter;
485 dst->skip_idct =
src->skip_idct;
486 dst->skip_frame =
src->skip_frame;
487
488 dst->frame_num =
src->frame_num;
489
492 if (err < 0)
493 return err;
494
495 return 0;
496 }
497
500 {
503 const AVCodec *codec =
p->avctx->codec;
505
507
510
512 p->avctx->internal->draining = 1;
513
518 }
521 memory_order_relaxed);
522
523 if (prev_thread) {
529 }
530
531 /* codecs without delay might not be prepared to be called repeatedly here during
532 * flushing (vp3/theora), and also don't need to be, since from this point on, they
533 * will always return EOF anyway */
534 if (!
p->avctx->internal->draining ||
540 }
541 }
542 }
543
544 /* transfer the stashed hwaccel state, if any */
545 av_assert0(!
p->avctx->hwaccel ||
p->hwaccel_threadsafe);
546 if (!
p->hwaccel_threadsafe) {
550 }
551
555
558
559 return 0;
560 }
561
563 {
566
567 /* release the async lock, permitting blocked hwaccel threads to
568 * go forward while we are in this function */
570
571 /* submit packets to threads while there are no buffered results to return */
574
575 /* get a packet to be submitted to the next thread */
580
585
586 /* do not return any frames until all threads have something to do */
589 continue;
590
593
599 }
600
606 }
607
608 /* a thread may return multiple frames AND an error
609 * we first return all the frames, then the error */
613 } else {
616 }
617
621 }
622
624 {
627
628 if (!progress ||
630 return;
631
632 p =
f->owner[
field]->internal->thread_ctx;
633
636 "%p finished %d field %d\n", progress, n,
field);
637
639
641
644 }
645
647 {
650
651 if (!progress ||
653 return;
654
655 p =
f->owner[
field]->internal->thread_ctx;
656
659 "thread awaiting %d field %d from %p\n", n,
field, progress);
660
665 }
666
669
671
673
674 p->hwaccel_threadsafe = avctx->
hwaccel &&
676
679 p->hwaccel_serializing = 1;
680 }
681
682 /* this assumes that no hwaccel calls happen before ff_thread_finish_setup() */
685 p->async_serializing = 1;
686
688 }
689
690 /* thread-unsafe hwaccels share a single private data instance, so we
691 * save hwaccel state for passing to the next thread;
692 * this is done here so that this worker thread can wipe its own hwaccel
693 * state after decoding, without requiring synchronization */
696 p->parent->stash_hwaccel = avctx->
hwaccel;
699 }
700
704 }
705
707
710 }
711
712 /// Waits for all threads to finish.
714 {
716
718
719 for (
i = 0;
i < thread_count;
i++) {
721
727 }
728 }
729
731 }
732
733 #define OFF(member) offsetof(FrameThreadContext, member)
735 (
OFF(buffer_mutex),
OFF(hwaccel_mutex),
OFF(async_mutex)),
737 #undef OFF
738
739 #define OFF(member) offsetof(PerThreadContext, member)
742 (
OFF(input_cond),
OFF(progress_cond),
OFF(output_cond)));
743 #undef OFF
744
746 {
750
752
753 for (
i = 0;
i < thread_count;
i++) {
756
763
765 }
768
769 /* When using a threadsafe hwaccel, this is where
770 * each thread's context is uninit'd and freed. */
772
777 }
778
786 &
ctx->nb_decoded_side_data);
787 }
788
790
793
795 }
796
799
802
803 /* if we have stashed hwaccel state, move it to the user-facing context,
804 * so it will be freed in ff_codec_close() */
809
811 }
812
816 {
818 int err;
819
821
827 copy->nb_decoded_side_data = 0;
828
829 /* From now on, this PerThreadContext will be cleaned up by
830 * ff_frame_thread_free in case of errors. */
831 (*threads_to_free)++;
832
835
840 copy->internal->thread_ctx =
p;
842
844
847 if (!
copy->priv_data)
849
853 if (err < 0)
854 return err;
855 }
856 }
857
859 if (err < 0)
860 return err;
861
864
865 copy->internal->is_frame_mt = 1;
867 copy->internal->is_copy = 1;
868
870 if (!
copy->internal->in_pkt)
872
874 if (!
copy->internal->last_pkt_props)
876
879 if (err < 0) {
882 return err;
883 }
884 }
886
889
891 for (
int i = 0;
i <
copy->nb_decoded_side_data;
i++) {
894 copy->decoded_side_data[
i], 0);
895 if (err < 0)
896 return err;
897 }
898 }
899
901
903 if (err < 0)
904 return err;
906
907 return 0;
908 }
909
911 {
916
917 if (!thread_count) {
919 // use number of cores + 1 as thread count if there is more than one
920 if (nb_cpus > 1)
922 else
924 }
925
926 if (thread_count <= 1) {
928 return 0;
929 }
930
932 if (!fctx)
934
936 if (err < 0) {
939 return err;
940 }
941
945
947
950
955 }
956
957 for (;
i < thread_count; ) {
960
962 if (err < 0)
964 }
965
966 return 0;
967
970 return err;
971 }
972
974 {
977
978 if (!fctx) return;
979
984 }
985
988
991
994
997
999 }
1000 }
1001
1003 {
1007
1009 return 0;
1010 }
1011
1012 return 1;
1013 }
1014
1016 {
1018 int err;
1019
1022
1026 av_log(avctx,
AV_LOG_ERROR,
"get_buffer() cannot be called after ff_thread_finish_setup()\n");
1027 return -1;
1028 }
1029
1032
1034
1035 return err;
1036 }
1037
1039 {
1044 }
1045
1047 {
1049
1050 f->owner[0] =
f->owner[1] = avctx;
1053
1057
1060
1065 }
1066
1068 {
1070 f->owner[0] =
f->owner[1] =
NULL;
1073 }
1074
1076 {
1079
1083
1085
1087
1088 memcpy(&
ref, (
const char*)
p->parent->threads[0].avctx->priv_data +
offset,
sizeof(
ref));
1091
1093 }
1094
1096 {
1098
1101 return 0;
1102 }
1103
1105 }
static void error(const char *err)
int(* update_thread_context)(struct AVCodecContext *dst, const struct AVCodecContext *src)
Copy necessary context variables from a previous thread context to the current one.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
#define FF_ENABLE_DEPRECATION_WARNINGS
static void thread_set_name(PerThreadContext *p)
void * hwaccel_context
Legacy hardware accelerator context.
static av_always_inline int pthread_join(pthread_t thread, void **value_ptr)
#define AV_LOG_WARNING
Something somehow does not look correct.
int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
Called by decoders to get the next packet for decoding.
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 just let it vf default minimum maximum flags name is the option name
pthread_cond_t input_cond
Used to wait for a new packet from the main thread.
#define atomic_store(object, desired)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Filter the word "frame" indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later. That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another. Frame references ownership and permissions
static int hwaccel_serial(const AVCodecContext *avctx)
AVFrameSideData ** decoded_side_data
Array containing static side data, such as HDR10 CLL / MDCV structures.
atomic_int debug_threads
Set if the FF_DEBUG_THREADS option is set.
const AVClass * priv_class
AVClass for the private context.
int next_decoding
The next context to submit a packet to.
#define AVERROR_EOF
End of file.
static av_cold int init_thread(PerThreadContext *p, int *threads_to_free, FrameThreadContext *fctx, AVCodecContext *avctx, const FFCodec *codec, int first)
int ff_thread_can_start_frame(AVCodecContext *avctx)
static void decoded_frames_free(DecodedFrames *df)
@ FF_THREAD_IS_FIRST_THREAD
Context stored in the client AVCodecInternal thread_ctx.
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
This structure describes decoded (raw) audio or video data.
int capabilities
Codec capabilities.
static av_always_inline int pthread_mutex_lock(pthread_mutex_t *mutex)
av_cold enum ThreadingStatus ff_thread_sync_ref(AVCodecContext *avctx, size_t offset)
Allows to synchronize objects whose lifetime is the whole decoding process among all frame threads.
@ INITIALIZED
Thread has been properly set up.
AVPacket * next_pkt
Packet to be submitted to the next thread for decoding.
int ff_thread_receive_frame(AVCodecContext *avctx, AVFrame *frame)
Submit available packets for decoding to worker threads, return a decoded frame if available.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
int av_frame_side_data_clone(AVFrameSideData ***sd, int *nb_sd, const AVFrameSideData *src, unsigned int flags)
Add a new side data entry to an array based on existing side data, taking a reference towards the con...
void * stash_hwaccel_context
int die
Set when the thread should exit.
av_cold void ff_pthread_free(void *obj, const unsigned offsets[])
int next_finished
The next context to return output from.
void av_packet_free(AVPacket **pkt)
Free the packet, if the packet is reference counted, it will be unreferenced first.
pthread_mutex_t buffer_mutex
Mutex used to protect get/release_buffer().
void ff_hwaccel_uninit(AVCodecContext *avctx)
void * av_memdup(const void *p, size_t size)
Duplicate a buffer with av_malloc().
int is_copy
When using frame-threaded decoding, this field is set for the first worker thread (e....
AVCodec p
The public AVCodec.
const struct AVCodec * codec
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
static int update_context_from_user(AVCodecContext *dst, const AVCodecContext *src)
Update the next thread's AVCodecContext with values set by the user.
unsigned pthread_init_cnt
Number of successfully initialized mutexes/conditions.
void av_opt_free(void *obj)
Free all allocated objects in obj.
#define HWACCEL_CAP_THREAD_SAFE
Context used by codec threads and stored in their AVCodecInternal thread_ctx.
static void * av_refstruct_allocz(size_t size)
Equivalent to av_refstruct_alloc_ext(size, 0, NULL, NULL)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
static av_cold void park_frame_worker_threads(FrameThreadContext *fctx, int thread_count)
Waits for all threads to finish.
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But first
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void ff_thread_report_progress(ThreadFrame *f, int n, int field)
Notify later decoding threads when part of their reference picture is ready.
int(* update_thread_context_for_user)(struct AVCodecContext *dst, const struct AVCodecContext *src)
Copy variables back to the user-facing context.
static av_always_inline int pthread_mutex_unlock(pthread_mutex_t *mutex)
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
pthread_cond_t output_cond
Used by the main thread to wait for frames to finish.
int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
av_cold void ff_thread_flush(AVCodecContext *avctx)
Wait for decoding threads to finish and reset internal state.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
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
#define atomic_load(object)
static av_always_inline int pthread_cond_broadcast(pthread_cond_t *cond)
PerThreadContext * prev_thread
The last thread submit_packet() was called on.
int(* init)(struct AVCodecContext *)
void ff_decode_internal_sync(struct AVCodecContext *dst, const struct AVCodecContext *src)
static av_always_inline int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
struct AVRefStructPool * progress_frame_pool
#define HWACCEL_CAP_ASYNC_SAFE
Header providing the internals of AVHWAccel.
Describe the class of an AVClass context structure.
@ STATE_SETTING_UP
Set before the codec has called ff_thread_finish_setup().
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
void ff_thread_await_progress(const ThreadFrame *f, int n, int field)
Wait for earlier decoding threads to finish reference pictures.
static int thread_get_buffer_internal(AVCodecContext *avctx, AVFrame *f, int flags)
static attribute_align_arg void * frame_worker_thread(void *arg)
Codec worker thread.
struct AVCodecInternal * internal
Private context used for internal data.
pthread_mutex_t progress_mutex
Mutex used to protect frame progress values and progress_cond.
pthread_mutex_t async_mutex
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_release_ext_buffer(ThreadFrame *f)
Unref a ThreadFrame.
pthread_mutex_t hwaccel_mutex
This lock is used for ensuring threads run in serial when thread-unsafe hwaccel is used.
AVCodecContext * avctx
Context used to decode packets passed to this thread.
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
#define AVPACKET_IS_EMPTY(pkt)
#define atomic_load_explicit(object, order)
DecodedFrames df
Decoded frames from a single decode iteration.
static void async_lock(FrameThreadContext *fctx)
int av_opt_copy(void *dst, const void *src)
Copy options from src object into dest object.
unsigned pthread_init_cnt
Number of successfully initialized mutexes/conditions.
#define attribute_align_arg
int result
The result of the last codec decode/encode() call.
const AVHWAccel * stash_hwaccel
av_cold void ff_frame_thread_free(AVCodecContext *avctx, int thread_count)
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
static void copy(const float *p1, float *p2, const int length)
void * hwaccel_priv_data
hwaccel-specific private data
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
AVPacket * avpkt
Input packet (for decoding) or output (for encoding).
static void async_unlock(FrameThreadContext *fctx)
pthread_cond_t async_cond
static const av_always_inline FFCodec * ffcodec(const AVCodec *codec)
static void decoded_frames_pop(DecodedFrames *df, AVFrame *dst)
struct FrameThreadContext * parent
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 just let it vf offset
@ UNINITIALIZED
Thread has not been created, AVCodec->close mustn't be called.
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
@ FF_THREAD_NO_FRAME_THREADING
int ff_thread_get_packet(AVCodecContext *avctx, AVPacket *pkt)
Get a packet for decoding.
@ STATE_SETUP_FINISHED
Set after the codec has called ff_thread_finish_setup().
@ NEEDS_CLOSE
FFCodec->close needs to be called.
int ff_decode_receive_frame_internal(struct AVCodecContext *avctx, AVFrame *frame)
Do the actual decoding and obtain a decoded frame from the decoder, if available.
static void decoded_frames_flush(DecodedFrames *df)
#define FF_THREAD_FRAME
Decode more than one frame at once.
void av_refstruct_unref(void *objp)
Decrement the reference count of the underlying object and automatically free the object if there are...
unsigned caps_internal
Internal codec capabilities FF_CODEC_CAP_*.
int av_packet_copy_props(AVPacket *dst, const AVPacket *src)
Copy only "properties" fields from src to dst.
#define i(width, name, range_min, range_max)
void av_frame_side_data_free(AVFrameSideData ***sd, int *nb_sd)
Free all side data entries and their contents, then zeroes out the values which the pointers are poin...
@ STATE_INPUT_READY
Set when the thread is awaiting a packet.
#define av_assert1(cond)
assert() equivalent, that does not lie in speed critical code.
#define atomic_store_explicit(object, desired, order)
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
const char * name
Name of the codec implementation.
int ff_thread_get_ext_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around ff_get_buffer() for frame-multithreaded codecs.
void * av_calloc(size_t nmemb, size_t size)
DEFINE_OFFSET_ARRAY(FrameThreadContext, thread_ctx, pthread_init_cnt,(OFF(buffer_mutex), OFF(hwaccel_mutex), OFF(async_mutex)),(OFF(async_cond)))
#define FFSWAP(type, a, b)
void avcodec_flush_buffers(AVCodecContext *avctx)
Reset the internal codec state / flush internal buffers.
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
struct AVCodecInternal * ff_decode_internal_alloc(void)
static AVFrame * decoded_frames_get_free(DecodedFrames *df)
static const char * hwaccel
static av_always_inline int pthread_cond_signal(pthread_cond_t *cond)
main external API structure.
int active_thread_type
Which multithreading methods are in use by the codec.
void av_refstruct_replace(void *dstp, const void *src)
Ensure *dstp refers to the same object as src.
static const FFHWAccel * ffhwaccel(const AVHWAccel *codec)
static int submit_packet(PerThreadContext *p, AVCodecContext *user_avctx, AVPacket *in_pkt)
static int ref[MAX_W *MAX_W]
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
IDirect3DDxgiInterfaceAccess _COM_Outptr_ void ** p
int(* close)(struct AVCodecContext *)
av_cold int ff_pthread_init(void *obj, const unsigned offsets[])
Initialize/destroy a list of mutexes/conditions contained in a structure.
static av_always_inline int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
int draining
decoding: AVERROR_EOF has been returned from ff_decode_get_packet(); must not be used by decoders tha...
#define FF_DISABLE_DEPRECATION_WARNINGS
av_cold int ff_frame_thread_init(AVCodecContext *avctx)
This structure stores compressed data.
pthread_mutex_t mutex
Mutex used to protect the contents of the PerThreadContext.
void ff_decode_internal_uninit(struct AVCodecContext *avctx)
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.
#define atomic_init(obj, value)
int caps_internal
Internal hwaccel capabilities.
void * priv_data
Format private data.
void * stash_hwaccel_priv
pthread_cond_t progress_cond
Used by child threads to wait for progress to change.
PerThreadContext * threads
The contexts for each thread.
static int ff_thread_setname(const char *name)
Generated on Tue Nov 18 2025 19:22:39 for FFmpeg by
doxygen
1.8.17