125 #if FF_API_GET_BUFFER
126 #define THREAD_SAFE_CALLBACKS(avctx) \
127 ((avctx)->thread_safe_callbacks || (!(avctx)->get_buffer && (avctx)->get_buffer2 == avcodec_default_get_buffer2))
129 #define THREAD_SAFE_CALLBACKS(avctx) \
130 ((avctx)->thread_safe_callbacks || (avctx)->get_buffer2 == avcodec_default_get_buffer2)
149 while (p->
state == STATE_INPUT_READY && !fctx->
die)
152 if (fctx->
die)
break;
164 "free the frame on failure. This is a bug, please report it.\n");
172 for (i = 0; i < MAX_BUFFERS; i++)
174 p->progress[i][0] = INT_MAX;
175 p->progress[i][1] = INT_MAX;
178 p->
state = STATE_INPUT_READY;
263 #define copy_fields(s, e) memcpy(&dst->s, &src->s, (char*)&dst->e - (char*)&dst->s);
268 #if FF_API_GET_BUFFER
338 if (prev_thread->
state == STATE_SETTING_UP) {
340 while (prev_thread->
state == STATE_SETTING_UP)
355 p->
state = STATE_SETTING_UP;
373 while (p->
state != STATE_SETUP_FINISHED && p->
state != STATE_INPUT_READY) {
376 while (p->
state == STATE_SETTING_UP)
380 case STATE_GET_BUFFER:
383 case STATE_GET_FORMAT:
391 p->
state = STATE_SETTING_UP;
405 AVFrame *picture,
int *got_picture_ptr,
444 p = &fctx->
threads[finished++];
446 if (p->
state != STATE_INPUT_READY) {
448 while (p->
state != STATE_INPUT_READY)
483 if (!progress || progress[field] >= n)
return;
501 if (!progress || progress[field] >= n)
return;
509 while (progress[field] < n)
519 if(p->
state == STATE_SETUP_FINISHED){
524 p->
state = STATE_SETUP_FINISHED;
534 for (i = 0; i < thread_count; i++) {
537 if (p->
state != STATE_INPUT_READY) {
539 while (p->
state != STATE_INPUT_READY)
564 for (i = 0; i < thread_count; i++) {
582 for (i = 0; i < thread_count; i++) {
634 if (thread_count <= 1) {
652 for (i = 0; i < thread_count; i++) {
692 err = codec->
init(copy);
775 if (p->
state != STATE_SETTING_UP &&
777 av_log(avctx,
AV_LOG_ERROR,
"get_buffer() cannot be called after ff_thread_finish_setup()\n");
789 progress[0] = progress[1] = -1;
805 p->
state = STATE_GET_BUFFER;
808 while (p->
state != STATE_SETTING_UP)
834 if (p->
state != STATE_SETTING_UP) {
835 av_log(avctx,
AV_LOG_ERROR,
"get_format() cannot be called after ff_thread_finish_setup()\n");
840 p->
state = STATE_GET_FORMAT;
843 while (p->
state != STATE_SETTING_UP)
876 if (!f->
f || !f->
f->
buf[0])
885 if (can_direct_free) {
static int thread_get_buffer_internal(AVCodecContext *avctx, ThreadFrame *f, int flags)
static av_unused void w32thread_init(void)
pthread_cond_t progress_cond
Used by child threads to wait for progress to change.
const struct AVCodec * codec
static av_always_inline int pthread_mutex_destroy(pthread_mutex_t *mutex)
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
#define copy_fields(s, e)
This structure describes decoded (raw) audio or video data.
static av_always_inline int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex)
#define FF_DEBUG_VIS_QP
only access through AVOptions from outside libavcodec
Context used by codec threads and stored in their AVCodecInternal thread_ctx.
AVFrame * requested_frame
AVFrame the codec passed to get_buffer()
int coded_width
Bitstream width / height, may be different from width/height e.g.
void(* flush)(AVCodecContext *)
Flush buffers.
#define AV_LOG_WARNING
Something somehow does not look correct.
memory handling functions
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
AVFrame * coded_frame
the picture in the bitstream
enum AVColorRange color_range
MPEG vs JPEG YUV range.
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel...
AVPacket * pkt
Current packet as passed into the decoder, to avoid having to pass the packet into every function...
os2threads to pthreads wrapper
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
int(* decode)(AVCodecContext *, void *outdata, int *outdata_size, AVPacket *avpkt)
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
#define FF_DEBUG_VIS_MB_TYPE
only access through AVOptions from outside libavcodec
pthread_cond_t input_cond
Used to wait for a new packet from the main thread.
void ff_thread_await_progress(ThreadFrame *f, int n, int field)
Wait for earlier decoding threads to finish reference pictures.
attribute_deprecated int(* get_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called at the beginning of each frame to get a buffer for it.
enum AVPixelFormat * available_formats
Format array for get_format()
static av_always_inline int pthread_cond_destroy(pthread_cond_t *cond)
AVPacket avpkt
Input packet (for decoding) or output (for encoding).
attribute_deprecated void(* release_buffer)(struct AVCodecContext *c, AVFrame *pic)
Called to release buffers which were allocated with get_buffer.
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
struct AVHWAccel * hwaccel
Hardware accelerator in use.
#define av_assert0(cond)
assert() equivalent, that is always enabled.
int(* init_thread_copy)(AVCodecContext *)
If defined, called on thread contexts when they are created.
Set when the thread is awaiting a packet.
enum AVPixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum AVPixelFormat *fmt)
enum AVSampleFormat sample_fmt
audio sample format
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
void * hwaccel_context
Hardware accelerator context.
static attribute_align_arg void * frame_worker_thread(void *arg)
Codec worker thread.
Multithreading support functions.
#define THREAD_SAFE_CALLBACKS(avctx)
static int submit_packet(PerThreadContext *p, AVPacket *avpkt)
int requested_flags
flags passed to get_buffer() for requested_frame
int next_decoding
The next context to submit a packet to.
static av_always_inline int pthread_cond_signal(pthread_cond_t *cond)
static void copy(LZOContext *c, int cnt)
Copies bytes from input to output buffer with checking.
int bits_per_coded_sample
bits per sample/pixel from the demuxer (needed for huffyuv).
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...
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Context stored in the client AVCodecInternal thread_ctx.
AVCodecContext * avctx
Context used to decode packets passed to this thread.
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
int ff_thread_decode_frame(AVCodecContext *avctx, AVFrame *picture, int *got_picture_ptr, AVPacket *avpkt)
Submit a new frame to a decoding thread.
int slice_count
slice count
Libavcodec version macros.
int(* close)(AVCodecContext *)
int av_reallocp_array(void *ptr, size_t nmemb, size_t size)
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
int has_b_frames
Size of the frame reordering buffer in the decoder.
PerThreadContext * prev_thread
The last thread submit_packet() was called on.
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given block if it is not large enough, otherwise do nothing.
void ff_frame_thread_free(AVCodecContext *avctx, int thread_count)
void ff_thread_release_buffer(AVCodecContext *avctx, ThreadFrame *f)
Wrapper around release_buffer() frame-for multithreaded codecs.
#define CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
int is_copy
Whether the parent AVCodecContext is a copy of the context which had init() called on it...
Set before the codec has called ff_thread_finish_setup().
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
int active_thread_type
Which multithreading methods are in use by the codec.
int capabilities
Codec capabilities.
int result
The result of the last codec decode/encode() call.
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
simple assert() macros that are a bit more flexible than ISO C assert().
enum PerThreadContext::@78 state
int die
Set when threads should exit.
Libavcodec external API header.
reference-counted frame API
uint64_t channel_layout
Audio channel layout.
common internal API header
pthread_cond_t output_cond
Used by the main thread to wait for frames to finish.
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...
#define FF_API_GET_BUFFER
int width
picture width / height.
Set after the codec has called ff_thread_finish_setup().
int idct_algo
IDCT algorithm, see FF_IDCT_* below.
void ff_thread_report_progress(ThreadFrame *f, int n, int field)
Notify later decoding threads when part of their reference picture is ready.
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
static av_always_inline int pthread_join(pthread_t thread, void **value_ptr)
static av_always_inline int pthread_mutex_init(pthread_mutex_t *mutex, const pthread_mutexattr_t *attr)
int64_t reordered_opaque
opaque 64bit number (generally a PTS) that will be reordered and output in AVFrame.reordered_opaque
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
Set when the codec calls get_format().
int got_frame
The output of got_picture_ptr from the last avcodec_decode_video() call.
static int update_context_from_user(AVCodecContext *dst, AVCodecContext *src)
Update the next thread's AVCodecContext with values set by the user.
int ff_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Select the (possibly hardware accelerated) pixel format.
pthread_mutex_t buffer_mutex
Mutex used to protect get/release_buffer().
pthread_mutex_t progress_mutex
Mutex used to protect frame progress values and progress_cond.
static av_always_inline int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *), void *arg)
int avcodec_default_get_buffer2(AVCodecContext *s, AVFrame *frame, int flags)
The default callback for AVCodecContext.get_buffer2().
enum AVMediaType codec_type
AVBufferRef * av_buffer_alloc(int size)
Allocate an AVBuffer of the given size using av_malloc().
int sample_rate
samples per second
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
main external API structure.
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
uint8_t * data
The data buffer.
int ff_get_buffer(AVCodecContext *avctx, AVFrame *frame, int flags)
Get a buffer for a frame.
int ff_init_buffer_info(AVCodecContext *s, AVFrame *frame)
does needed setup of pkt_pts/pos and such for (re)get_buffer();
#define FF_THREAD_FRAME
Decode more than one frame at once.
int slice_flags
slice flags
enum AVPixelFormat(* get_format)(struct AVCodecContext *s, const enum AVPixelFormat *fmt)
callback to negotiate the pixelFormat
enum AVColorSpace colorspace
YUV colorspace type.
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
enum AVPixelFormat result_format
get_format() result
int delaying
Set for the first N packets, where N is the number of threads.
refcounted data buffer API
enum AVPixelFormat ff_thread_get_format(AVCodecContext *avctx, const enum AVPixelFormat *fmt)
Wrapper around get_format() for frame-multithreaded codecs.
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.
attribute_deprecated int dtg_active_format
DTG active format information (additional aspect ratio information only used in DVB MPEG-2 transport ...
PerThreadContext * threads
The contexts for each thread.
int allocate_progress
Whether to allocate progress for frame threading.
AVFrame * released_buffers
Array of frames passed to ff_thread_release_buffer().
struct FrameThreadContext * parent
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
const AVClass * priv_class
AVClass for the private context.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
int64_t pkt_dts
DTS copied from the AVPacket that triggered returning this frame.
void av_opt_free(void *obj)
Free all allocated objects in obj.
#define FF_DISABLE_DEPRECATION_WARNINGS
common internal api header.
common internal and external API header
int released_buffers_allocated
void * hwaccel_priv_data
hwaccel-specific private data
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 av_always_inline int pthread_cond_init(pthread_cond_t *cond, const pthread_condattr_t *attr)
int thread_safe_callbacks
Set by the client if its custom get_buffer() callback can be called synchronously from another thread...
int(* update_thread_context)(AVCodecContext *dst, const AVCodecContext *src)
Copy necessary context variables from a previous thread context to the current one.
void ff_thread_flush(AVCodecContext *avctx)
Wait for decoding threads to finish and reset internal state.
AVFrame * frame
Output frame (for decoding) or input (for encoding).
int ff_thread_can_start_frame(AVCodecContext *avctx)
#define FF_ENABLE_DEPRECATION_WARNINGS
static av_always_inline int pthread_cond_broadcast(pthread_cond_t *cond)
int channels
number of audio channels
static av_always_inline int pthread_mutex_unlock(pthread_mutex_t *mutex)
struct AVCodecInternal * internal
Private context used for internal data.
pthread_mutex_t mutex
Mutex used to protect the contents of the PerThreadContext.
w32threads to pthreads wrapper
static void park_frame_worker_threads(FrameThreadContext *fctx, int thread_count)
Waits for all threads to finish.
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
static void * av_mallocz_array(size_t nmemb, size_t size)
int * slice_offset
slice offsets in the frame in bytes
int frame_number
Frame counter, set by libavcodec.
static void release_delayed_buffers(PerThreadContext *p)
Releases the buffers that this decoding thread was the last user of.
static av_always_inline int pthread_mutex_lock(pthread_mutex_t *mutex)
int debug_mv
debug Code outside libavcodec should access this field using AVOptions
int next_finished
The next context to return output from.
int(* init)(AVCodecContext *)
uint8_t ** extended_data
pointers to the data planes/channels.
AVPixelFormat
Pixel format.
This structure stores compressed data.
Set when the codec calls get_buffer().
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
int ff_frame_thread_init(AVCodecContext *avctx)
void * opaque
Private data of the user, can be used to carry app specific stuff.