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 "config.h"
26
27 #include <stdatomic.h>
28 #include <stdint.h>
29
36
47
48 enum {
49 ///< Set when the thread is awaiting a packet.
51 ///< Set before the codec has called ff_thread_finish_setup().
53 /**
54 * Set when the codec calls get_buffer().
55 * State is returned to STATE_SETTING_UP afterwards.
56 */
58 /**
59 * Set when the codec calls get_format().
60 * State is returned to STATE_SETTING_UP afterwards.
61 */
63 ///< Set after the codec has called ff_thread_finish_setup().
65 };
66
67 enum {
68 UNINITIALIZED,
///< Thread has not been created, AVCodec->close mustn't be called
71 };
72
73 /**
74 * Context used by codec threads and stored in their AVCodecInternal thread_ctx.
75 */
78
85
88
90
91 AVPacket *
avpkt;
///< Input packet (for decoding) or output (for encoding).
92
93 AVFrame *
frame;
///< Output frame (for decoding) or input (for encoding).
94 int got_frame;
///< The output of got_picture_ptr from the last avcodec_decode_video() call.
95 int result;
///< The result of the last codec decode/encode() call.
96
98
99 #if FF_API_THREAD_SAFE_CALLBACKS
100 /**
101 * Array of frames passed to ff_thread_release_buffer().
102 * Frames are released after all threads referencing them are finished.
103 */
107
110
113 #endif
114
115 int die;
///< Set when the thread should exit.
116
119
122
123 /**
124 * Context stored in the client AVCodecInternal thread_ctx.
125 */
129
132 /**
133 * This lock is used for ensuring threads run in serial when hwaccel
134 * is used.
135 */
140
143
145 * Set for the first N packets, where N is the number of threads.
146 * While it is set, ff_thread_en/decode_frame won't return any results.
147 */
149
150 #if FF_API_THREAD_SAFE_CALLBACKS
151 #define THREAD_SAFE_CALLBACKS(avctx) \
152 ((avctx)->thread_safe_callbacks || (avctx)->get_buffer2 == avcodec_default_get_buffer2)
153 #endif
154
156 {
162 }
163
165 {
171 }
172
173 /**
174 * Codec worker thread.
175 *
176 * Automatically calls ff_thread_finish_setup() if the codec does
177 * not provide an update_thread_context method, or if the codec returns
178 * before calling it.
179 */
181 {
185
187 while (1) {
190
192
197 #endif
198 )
201
202 /* If a decoder supports hwaccel, then it must call ff_get_format().
203 * Since that call must happen before ff_thread_finish_setup(), the
204 * decoder is required to implement update_thread_context() and call
205 * ff_thread_finish_setup() manually. Therefore the above
206 * ff_thread_finish_setup() call did not happen and hwaccel_serializing
207 * cannot be true here. */
209
210 /* if the previous thread uses hwaccel then we take the lock to ensure
211 * the threads don't run concurrently */
215 }
216
220
224 "free the frame on failure. This is a bug, please report it.\n");
226 }
227
230
234 }
235
238
240 }
241
243
245
249 }
251
253 }
254
255 /**
256 * Update the next thread's AVCodecContext with values from the reference thread's context.
257 *
258 * @param dst The destination context.
259 * @param src The source context.
260 * @param for_user 0 if the destination is a codec thread, 1 if the destination is the user's thread
261 * @return 0 on success, negative error code on failure
262 */
264 {
265 int err = 0;
266
267 if (dst !=
src && (for_user ||
src->codec->update_thread_context)) {
274
277
281
284
287
291
296
299
305
309
310 if (
src->hw_frames_ctx) {
314 }
315 }
316
318
320 if (err < 0)
321 return err;
322 }
323
324 if (for_user) {
327 } else {
330 }
331
332 return err;
333 }
334
335 /**
336 * Update the next thread's AVCodecContext with values set by the user.
337 *
338 * @param dst The destination context.
339 * @param src The source context.
340 * @return 0 on success, negative error code on failure
341 */
343 {
345
348
351
355
359
362 #if FF_API_THREAD_SAFE_CALLBACKS
366 #endif
367
368 if (
src->slice_count &&
src->slice_offset) {
372 if (err < 0)
373 return err;
374 }
377 }
379 return 0;
380 }
381
382 #if FF_API_THREAD_SAFE_CALLBACKS
383 /// Releases the buffers that this decoding thread was the last user of.
385 {
387
390
392
393 // fix extended data in case the caller screwed it up
397 f->extended_data =
f->data;
399
401 }
402 }
403 #endif
404
407 {
412
414 return 0;
415
417
422 }
425 memory_order_relaxed);
426
427 #if FF_API_THREAD_SAFE_CALLBACKS
429 #endif
430
431 if (prev_thread) {
432 int err;
438 }
439
441 if (err) {
443 return err;
444 }
445 }
446
453 }
454
458
459 #if FF_API_THREAD_SAFE_CALLBACKS
461 /*
462 * If the client doesn't have a thread-safe get_buffer(),
463 * then decoding threads call back to the main thread,
464 * and it calls back to the client here.
465 */
466
471 int call_done = 1;
475
479 break;
482 break;
483 default:
484 call_done = 0;
485 break;
486 }
487 if (call_done) {
490 }
492 }
493 }
495 #endif
496
499
500 return 0;
501 }
502
504 AVFrame *picture,
int *got_picture_ptr,
506 {
510 int err;
511
512 /* release the async lock, permitting blocked hwaccel threads to
513 * go forward while we are in this function */
515
516 /*
517 * Submit a packet to the next decoding thread.
518 */
519
522 if (err)
524
525 /*
526 * If we're still receiving the initial packets, don't return a frame.
527 */
528
531
533 *got_picture_ptr=0;
537 }
538 }
539
540 /*
541 * Return the next available frame from the oldest thread.
542 * If we're at the end of the stream, then we have to skip threads that
543 * didn't output a frame/error, because we don't want to accidentally signal
544 * EOF (avpkt->size == 0 && *got_picture_ptr == 0 && err >= 0).
545 */
546
547 do {
548 p = &fctx->
threads[finished++];
549
555 }
556
561
562 /*
563 * A later call with avkpt->size == 0 may loop over all threads,
564 * including this one, searching for a frame/error to return before being
565 * stopped by the "finished != fctx->next_finished" condition.
566 * Make sure we don't mistakenly return the same frame/error again.
567 */
570
572 }
while (!avpkt->
size && !*got_picture_ptr && err >= 0 && finished != fctx->
next_finished);
573
575
577
579
580 /* return the size of the consumed packet if no error occurred */
581 if (err >= 0)
585 return err;
586 }
587
589 {
592
595 return;
596
597 p =
f->owner[
field]->internal->thread_ctx;
598
601 "%p finished %d field %d\n", progress, n,
field);
602
604
606
609 }
610
612 {
615
618 return;
619
620 p =
f->owner[
field]->internal->thread_ctx;
621
624 "thread awaiting %d field %d from %p\n", n,
field, progress);
625
630 }
631
634
636
640 }
641
642 /* this assumes that no hwaccel calls happen before ff_thread_finish_setup() */
646
648 }
649
653 }
654
656
659 }
660
661 /// Waits for all threads to finish.
663 {
665
667
668 for (
i = 0;
i < thread_count;
i++) {
670
676 }
678 }
679
681 }
682
683 #define OFF(member) offsetof(FrameThreadContext, member)
685 (
OFF(buffer_mutex),
OFF(hwaccel_mutex),
OFF(async_mutex)),
687 #undef OFF
688
689 #define OFF(member) offsetof(PerThreadContext, member)
692 (
OFF(input_cond),
OFF(progress_cond),
OFF(output_cond)));
693 #undef OFF
694
696 {
700
702
707 }
708 }
709
715 }
716
717 for (
i = 0;
i < thread_count;
i++) {
720
727
729 }
732
733 #if FF_API_THREAD_SAFE_CALLBACKS
738 #endif
743 }
744
746
750 }
751
753
756
758 }
759
762
764 }
765
769 {
771 int err;
772
774
779
780 /* From now on, this PerThreadContext will be cleaned up by
781 * ff_frame_thread_free in case of errors. */
782 (*threads_to_free)++;
783
786
790 copy->internal->thread_ctx = p;
791
793
796 if (!
copy->priv_data)
798
802 if (err < 0)
803 return err;
804 }
805 }
806
808 if (err < 0)
809 return err;
810
814 copy->internal->last_pkt_props = p->
avpkt;
815
817 copy->internal->is_copy = 1;
818
821 if (err < 0) {
824 return err;
825 }
826 }
828
831
833
835 if (err < 0)
836 return err;
838
839 return 0;
840 }
841
843 {
848
849 if (!thread_count) {
851 // use number of cores + 1 as thread count if there is more than one
852 if (nb_cpus > 1)
854 else
856 }
857
858 if (thread_count <= 1) {
860 return 0;
861 }
862
864 if (!fctx)
866
868 if (err < 0) {
871 return err;
872 }
873
876
879
884 }
885
886 for (;
i < thread_count; ) {
889
891 if (err < 0)
893 }
894
895 return 0;
896
899 return err;
900 }
901
903 {
906
907 if (!fctx) return;
908
913 }
914
920 // Make sure decode flush calls with size=0 won't return old frames
924
925 #if FF_API_THREAD_SAFE_CALLBACKS
927 #endif
928
931 }
932 }
933
935 {
942 #endif
943 )) {
944 return 0;
945 }
947 return 1;
948 }
949
951 {
953 int err;
954
955 f->owner[0] =
f->owner[1] = avctx;
956
959
965 #endif
966 )) {
968 av_log(avctx,
AV_LOG_ERROR,
"get_buffer() cannot be called after ff_thread_finish_setup()\n");
969 return -1;
970 }
971
977 }
979
982 }
983
985 #if !FF_API_THREAD_SAFE_CALLBACKS
987 #else
991 } else {
997
1000
1002
1004
1005 }
1009 #endif
1010 if (err)
1012
1014
1015 return err;
1016 }
1017
1018 #if FF_API_THREAD_SAFE_CALLBACKS
1021 {
1028 av_log(avctx,
AV_LOG_ERROR,
"get_format() cannot be called after ff_thread_finish_setup()\n");
1029 return -1;
1030 }
1035
1038
1040
1042
1043 return res;
1044 }
1046 #endif
1047
1049 {
1054 }
1055
1057 {
1058 #if FF_API_THREAD_SAFE_CALLBACKS
1067 #endif
1068
1070 return;
1071
1074
1076 f->owner[0] =
f->owner[1] =
NULL;
1077
1078 #if !FF_API_THREAD_SAFE_CALLBACKS
1080 #else
1081 // when the frame buffers are not allocated, just reset it to clean state
1082 if (can_direct_free || !
f->f->buf[0]) {
1084 return;
1085 }
1086
1087 fctx = p->parent;
1089
1090 if (p->num_released_buffers == p->released_buffers_allocated) {
1092 sizeof(*p->released_buffers));
1095 p->released_buffers =
tmp;
1096 }
1097
1098 if (!
tmp || !
tmp[p->released_buffers_allocated]) {
1101 }
1102 p->released_buffers_allocated++;
1103 }
1104
1105 dst = p->released_buffers[p->num_released_buffers];
1107
1108 p->num_released_buffers++;
1109
1112
1113 // make sure the frame is clean even if we fail to free it
1114 // this leaks, but it is better than crashing
1116 av_log(avctx,
AV_LOG_ERROR,
"Could not queue a frame for freeing, this will leak\n");
1117 memset(
f->f->buf, 0,
sizeof(
f->f->buf));
1118 if (
f->f->extended_buf)
1119 memset(
f->f->extended_buf, 0,
f->f->nb_extended_buf *
sizeof(*
f->f->extended_buf));
1121 }
1122 #endif
1123 }
static void error(const char *err)
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
const struct AVHWAccel * hwaccel
Hardware accelerator in use.
#define FF_ENABLE_DEPRECATION_WARNINGS
void * hwaccel_context
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.
AVPixelFormat
Pixel format.
pthread_cond_t input_cond
Used to wait for a new packet from the main thread.
#define atomic_store(object, desired)
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
enum AVPixelFormat(* get_format)(struct AVCodecContext *s, const enum AVPixelFormat *fmt)
Callback to negotiate the pixel format.
@ INITIALIZED
Thread has been properly set up.
#define FF_API_THREAD_SAFE_CALLBACKS
uint64_t channel_layout
Audio channel layout.
enum AVColorSpace colorspace
YUV colorspace type.
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
int sample_rate
samples per second
atomic_int debug_threads
Set if the FF_DEBUG_THREADS option is set.
const AVClass * priv_class
AVClass for the private context.
int(* update_thread_context)(struct AVCodecContext *dst, const struct AVCodecContext *src)
Copy necessary context variables from a previous thread context to the current one.
int next_decoding
The next context to submit a packet to.
uint8_t * data
The data buffer.
@ NEEDS_CLOSE
AVCodec->close needs to be called.
void ff_thread_flush(AVCodecContext *avctx)
Wait for decoding threads to finish and reset internal state.
int caps_internal
Internal hwaccel capabilities.
int ff_thread_can_start_frame(AVCodecContext *avctx)
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.
static void park_frame_worker_threads(FrameThreadContext *fctx, int thread_count)
Waits for all threads to finish.
This structure describes decoded (raw) audio or video data.
#define THREAD_SAFE_CALLBACKS(avctx)
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
int * slice_offset
slice offsets in the frame in bytes
int capabilities
Codec capabilities.
AVBufferRef * av_buffer_ref(const AVBufferRef *buf)
Create a new reference to an AVBuffer.
enum AVPixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum AVPixelFormat *fmt)
void(* flush)(struct AVCodecContext *)
Flush buffers.
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
@ UNINITIALIZED
Thread has not been created, AVCodec->close mustn't be called.
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.
int slice_count
slice count
pthread_mutex_t buffer_mutex
Mutex used to protect get/release_buffer().
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....
void ff_frame_thread_free(AVCodecContext *avctx, int thread_count)
enum AVDiscard skip_idct
Skip IDCT/dequantization for selected frames.
const struct AVCodec * codec
enum AVDiscard skip_frame
Skip decoding for selected frames.
enum AVPixelFormat * available_formats
Format array for get_format()
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
unsigned pthread_init_cnt
Number of successfully initialized mutexes/conditions.
int flags
AV_CODEC_FLAG_*.
Context used by codec threads and stored in their AVCodecInternal thread_ctx.
static int submit_packet(PerThreadContext *p, AVCodecContext *user_avctx, AVPacket *avpkt)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
int(* get_buffer2)(struct AVCodecContext *s, AVFrame *frame, int flags)
This callback is called at the beginning of each frame to get data buffer(s) for it.
trying all byte sequences megabyte in length and selecting the best looking sequence will yield cases to try But first
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
void ff_thread_await_progress(ThreadFrame *f, int n, int field)
Wait for earlier decoding threads to finish reference pictures.
void ff_thread_report_progress(ThreadFrame *f, int n, int field)
Notify later decoding threads when part of their reference picture is ready.
int has_b_frames
Size of the frame reordering buffer in the decoder.
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
static av_cold int init_thread(PerThreadContext *p, int *threads_to_free, FrameThreadContext *fctx, AVCodecContext *avctx, const AVCodec *codec, int first)
@ STATE_INPUT_READY
Set when the thread is awaiting a packet.
pthread_cond_t output_cond
Used by the main thread to wait for frames to finish.
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
int requested_flags
flags passed to get_buffer() for requested_frame
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
static int update_context_from_user(AVCodecContext *dst, AVCodecContext *src)
Update the next thread's AVCodecContext with values set by the user.
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.
static av_always_inline int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
int got_frame
The output of got_picture_ptr from the last avcodec_decode_video() call.
Describe the class of an AVClass context structure.
enum AVColorRange color_range
MPEG vs JPEG YUV range.
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
int slice_flags
slice flags
static attribute_align_arg void * frame_worker_thread(void *arg)
Codec worker thread.
struct AVCodecInternal * internal
Private context used for internal data.
AVFrame ** released_buffers
Array of frames passed to ff_thread_release_buffer().
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...
pthread_mutex_t hwaccel_mutex
This lock is used for ensuring threads run in serial when hwaccel is used.
AVCodecContext * avctx
Context used to decode packets passed to this thread.
void av_opt_free(void *obj)
Free all allocated objects in obj.
attribute_deprecated int thread_safe_callbacks
Set by the client if its custom get_buffer() callback can be called synchronously from another thread...
int64_t pkt_dts
DTS copied from the AVPacket that triggered returning this frame.
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
#define atomic_load_explicit(object, order)
#define pthread_mutex_unlock(a)
static void async_lock(FrameThreadContext *fctx)
unsigned pthread_init_cnt
Number of successfully initialized mutexes/conditions.
void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
Wrapper around release_buffer() frame-for multithreaded codecs.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
int result
The result of the last codec decode/encode() call.
int flags2
AV_CODEC_FLAG2_*.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int ff_thread_decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, AVPacket *avpkt)
Submit a new frame to a decoding thread.
static void copy(const float *p1, float *p2, const int length)
void * hwaccel_priv_data
hwaccel-specific private data
int(* close)(struct AVCodecContext *)
int(* update_thread_context_for_user)(struct AVCodecContext *dst, const struct AVCodecContext *src)
Copy variables back to the user-facing context.
AVPacket * avpkt
Input packet (for decoding) or output (for encoding).
static void async_unlock(FrameThreadContext *fctx)
enum AVSampleFormat sample_fmt
audio sample format
pthread_cond_t async_cond
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
Allocate, reallocate, or free an array through a pointer to a pointer.
struct FrameThreadContext * parent
AVPacket * av_packet_alloc(void)
Allocate an AVPacket and set its fields to default values.
AVBufferRef * av_buffer_alloc(size_t size)
Allocate an AVBuffer of the given size using av_malloc().
enum AVDiscard skip_loop_filter
Skip loop filtering for selected frames.
#define FF_THREAD_FRAME
Decode more than one frame at once.
int channels
number of audio channels
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
int avcodec_default_get_buffer2(AVCodecContext *s, AVFrame *frame, int flags)
The default callback for AVCodecContext.get_buffer2().
#define i(width, name, range_min, range_max)
unsigned properties
Properties of the stream that gets decoded.
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
int hwaccel_flags
Bit set of AV_HWACCEL_FLAG_* flags, which affect hardware accelerated decoding (if active).
#define atomic_store_explicit(object, desired, order)
static void release_delayed_buffers(PerThreadContext *p)
Releases the buffers that this decoding thread was the last user of.
#define HWACCEL_CAP_ASYNC_SAFE
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...
int idct_algo
IDCT algorithm, see FF_IDCT_* below.
int av_buffer_replace(AVBufferRef **pdst, const AVBufferRef *src)
Ensure dst refers to the same data as src.
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
void * av_calloc(size_t nmemb, size_t size)
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames.
@ STATE_GET_BUFFER
Set when the codec calls get_buffer().
DEFINE_OFFSET_ARRAY(FrameThreadContext, thread_ctx, pthread_init_cnt,(OFF(buffer_mutex), OFF(hwaccel_mutex), OFF(async_mutex)),(OFF(async_cond)))
int caps_internal
Internal codec capabilities.
int ff_frame_thread_init(AVCodecContext *avctx)
void * opaque
Private data of the user, can be used to carry app specific stuff.
static av_always_inline int pthread_cond_signal(pthread_cond_t *cond)
void(* draw_horiz_band)(struct AVCodecContext *s, const AVFrame *src, int offset[AV_NUM_DATA_POINTERS], int y, int type, int height)
If non NULL, 'draw_horiz_band' is called by the libavcodec decoder to draw a horizontal band.
static int thread_get_buffer_internal(AVCodecContext *avctx, ThreadFrame *f, int flags)
main external API structure.
int active_thread_type
Which multithreading methods are in use by the codec.
AVFrame * frame
Output frame (for decoding) or input (for encoding).
FF_DISABLE_DEPRECATION_WARNINGS enum AVPixelFormat ff_thread_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Wrapper around get_format() for frame-multithreaded codecs.
enum AVPixelFormat result_format
get_format() result
int export_side_data
Bit set of AV_CODEC_EXPORT_DATA_* flags, which affects the kind of metadata exported in frame,...
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
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)
#define FF_DISABLE_DEPRECATION_WARNINGS
FF_ENABLE_DEPRECATION_WARNINGS int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
int coded_width
Bitstream width / height, may be different from width/height e.g.
enum AVMediaType codec_type
int delaying
Set for the first N packets, where N is the number of threads.
@ STATE_GET_FORMAT
Set when the codec calls get_format().
#define FF_CODEC_CAP_ALLOCATE_PROGRESS
int frame_number
Frame counter, set by libavcodec.
int av_opt_copy(void *dst, const void *src)
Copy options from src object into dest object.
This structure stores compressed data.
int64_t reordered_opaque
opaque 64-bit number (generally a PTS) that will be reordered and output in AVFrame....
int(* init)(struct AVCodecContext *)
int width
picture width / height.
#define flags(name, subs,...)
pthread_mutex_t mutex
Mutex used to protect the contents of the PerThreadContext.
int(* decode)(struct AVCodecContext *avctx, void *outdata, int *got_frame_ptr, struct AVPacket *avpkt)
Decode picture or subtitle data.
AVFrame * requested_frame
AVFrame the codec passed to get_buffer()
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
#define atomic_init(obj, value)
void * priv_data
Format private data.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
int released_buffers_allocated
pthread_cond_t progress_cond
Used by child threads to wait for progress to change.
PerThreadContext * threads
The contexts for each 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.
#define pthread_mutex_lock(a)
Generated on Wed Aug 24 2022 21:37:51 for FFmpeg by
doxygen
1.8.17