libavcodec/pthread.c File Reference

Multithreading support functions. More...

#include <pthread.h>
#include "avcodec.h"
#include "thread.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...

Defines

#define MAX_BUFFERS   (32+1)
 Max number of frame buffers that can be allocated when using frame threads.
#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 (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)
 Updates the next thread's AVCodecContext with values from the reference thread's context.
static void update_context_from_user (AVCodecContext *dst, AVCodecContext *src)
 Update the next thread's AVCodecContext with values set by the user.
static void free_progress (AVFrame *f)
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)
 Submits a new frame to a decoding thread.
void ff_thread_report_progress (AVFrame *f, int n, int field)
 Notifies later decoding threads when part of their reference picture is ready.
void ff_thread_await_progress (AVFrame *f, int n, int field)
 Waits 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.
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)
 Waits for decoding threads to finish and resets internal state.
static int * allocate_progress (PerThreadContext *p)
int ff_thread_get_buffer (AVCodecContext *avctx, AVFrame *f)
 Wrapper around get_buffer() for frame-multithreaded codecs.
void ff_thread_release_buffer (AVCodecContext *avctx, AVFrame *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)


Detailed Description

Multithreading support functions.

See also:
doc/multithreading.txt

Definition in file pthread.c.


Define Documentation

#define copy_fields ( s,
 )     memcpy(&dst->s, &src->s, (char*)&dst->e - (char*)&dst->s);

#define MAX_BUFFERS   (32+1)

Max number of frame buffers that can be allocated when using frame threads.

Definition at line 58 of file pthread.c.

Referenced by allocate_progress(), and ff_thread_release_buffer().


Typedef Documentation

typedef int( action_func)(AVCodecContext *c, void *arg)

Definition at line 37 of file pthread.c.

typedef int( action_func2)(AVCodecContext *c, void *arg, int jobnr, int threadnr)

Definition at line 38 of file pthread.c.


Function Documentation

static int* allocate_progress ( PerThreadContext p  )  [static]

Definition at line 765 of file pthread.c.

Referenced by ff_thread_get_buffer().

static int avcodec_thread_execute ( AVCodecContext avctx,
action_func func,
void *  arg,
int *  ret,
int  job_count,
int  job_size 
) [static]

Definition at line 188 of file pthread.c.

Referenced by avcodec_thread_execute2(), ff_thread_init(), and thread_init().

static int avcodec_thread_execute2 ( AVCodecContext avctx,
action_func2 func2,
void *  arg,
int *  ret,
int  job_count 
) [static]

Definition at line 220 of file pthread.c.

Referenced by ff_thread_init(), and thread_init().

static av_always_inline void avcodec_thread_park_workers ( ThreadContext c,
int  thread_count 
) [static]

Definition at line 162 of file pthread.c.

Referenced by avcodec_thread_execute(), and thread_init().

void ff_thread_await_progress ( AVFrame f,
int  progress,
int  field 
)

Waits 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.

Parameters:
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 582 of file pthread.c.

Referenced by await_reference_mb_row(), await_reference_row(), await_references(), decode(), ff_er_frame_end(), guess_mv(), is_intra_more_likely(), mpeg4_decode_mb(), mpeg4_decode_video_packet_header(), MPV_decode_mb_internal(), vp8_decode_frame(), vp8_mc_chroma(), and vp8_mc_luma().

int ff_thread_decode_frame ( AVCodecContext avctx,
AVFrame picture,
int *  got_picture_ptr,
AVPacket avpkt 
)

Submits a new frame to a decoding thread.

Returns the next available frame in picture. *got_picture_ptr will be 0 if none is available.

Parameters are the same as avcodec_decode_video2().

Definition at line 492 of file pthread.c.

Referenced by avcodec_decode_video2().

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().

Parameters:
avctx The context.

Definition at line 600 of file pthread.c.

Referenced by decode_postinit(), ff_h263_decode_frame(), ff_thread_get_buffer(), frame_worker_thread(), mimic_decode_frame(), mpeg_field_start(), and vp8_decode_frame().

void ff_thread_flush ( AVCodecContext avctx  ) 

Waits for decoding threads to finish and resets internal state.

Called by avcodec_flush_buffers().

Parameters:
avctx The context.

Definition at line 746 of file pthread.c.

Referenced by avcodec_flush_buffers().

void ff_thread_free ( AVCodecContext avctx  ) 

Definition at line 913 of file pthread.c.

Referenced by avcodec_close(), ff_thread_init(), and thread_init().

int ff_thread_get_buffer ( AVCodecContext avctx,
AVFrame f 
)

Wrapper around get_buffer() for frame-multithreaded codecs.

Call this function instead of avctx->get_buffer(f). Cannot be called after the codec has called ff_thread_finish_setup().

Parameters:
avctx The current context.
f The frame to write into.

Definition at line 782 of file pthread.c.

Referenced by alloc_frame_buffer(), decode_frame(), mimic_decode_frame(), and vp8_decode_frame().

int ff_thread_init ( AVCodecContext avctx  ) 

Definition at line 894 of file pthread.c.

Referenced by avcodec_open2(), and avcodec_thread_init().

void ff_thread_release_buffer ( AVCodecContext avctx,
AVFrame 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.

Parameters:
avctx The current context.
f The picture being released.

Definition at line 843 of file pthread.c.

Referenced by decode_frame(), free_frame_buffer(), mimic_decode_end(), mimic_decode_frame(), update_frames(), vp8_decode_flush(), and vp8_decode_frame().

void ff_thread_report_progress ( AVFrame f,
int  progress,
int  field 
)

Notifies 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.

Parameters:
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 564 of file pthread.c.

Referenced by decode(), decode_finish_row(), decode_slice_header(), field_end(), mimic_decode_frame(), MPV_frame_end(), MPV_frame_start(), MPV_report_decode_progress(), vp3_draw_horiz_band(), and vp8_decode_frame().

static void frame_thread_free ( AVCodecContext avctx,
int  thread_count 
) [static]

Definition at line 628 of file pthread.c.

Referenced by ff_thread_free(), and frame_thread_init().

static int frame_thread_init ( AVCodecContext avctx  )  [static]

Definition at line 681 of file pthread.c.

Referenced by ff_thread_init().

static attribute_align_arg void* frame_worker_thread ( void *  arg  )  [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 278 of file pthread.c.

Referenced by frame_thread_init().

static void free_progress ( AVFrame f  )  [static]

Definition at line 400 of file pthread.c.

Referenced by release_delayed_buffers().

static void park_frame_worker_threads ( FrameThreadContext fctx,
int  thread_count 
) [static]

Waits for all threads to finish.

Definition at line 612 of file pthread.c.

Referenced by ff_thread_flush(), and frame_thread_free().

static void release_delayed_buffers ( PerThreadContext p  )  [static]

Releases the buffers that this decoding thread was the last user of.

Definition at line 409 of file pthread.c.

Referenced by frame_thread_free(), and submit_packet().

static int submit_packet ( PerThreadContext p,
AVPacket avpkt 
) [static]

Definition at line 426 of file pthread.c.

Referenced by ff_thread_decode_frame().

static void thread_free ( AVCodecContext avctx  )  [static]

Definition at line 168 of file pthread.c.

Referenced by ff_thread_free().

static int thread_init ( AVCodecContext avctx  )  [static]

Definition at line 227 of file pthread.c.

Referenced by ff_thread_init().

static int update_context_from_thread ( AVCodecContext dst,
AVCodecContext src,
int  for_user 
) [static]

Updates the next thread's AVCodecContext with values from the reference thread's context.

Parameters:
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 324 of file pthread.c.

Referenced by ff_thread_decode_frame(), ff_thread_flush(), frame_thread_free(), frame_thread_init(), and submit_packet().

static void update_context_from_user ( AVCodecContext dst,
AVCodecContext src 
) [static]

Update the next thread's AVCodecContext with values set by the user.

Parameters:
dst The destination context.
src The source context.

Definition at line 376 of file pthread.c.

Referenced by ff_thread_decode_frame().

static void validate_thread_parameters ( AVCodecContext avctx  )  [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.

Parameters:
avctx The context.

Definition at line 878 of file pthread.c.

Referenced by ff_thread_init().

static void* attribute_align_arg worker ( void *  v  )  [static]

Definition at line 129 of file pthread.c.

Referenced by thread_init().


Generated on Fri Oct 26 02:39:46 2012 for FFmpeg by  doxygen 1.5.8