diff options
author | Alexander Strange <astrange@ithinksw.com> | 2011-02-07 21:15:44 -0500 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2011-02-11 02:53:58 +0100 |
commit | b38f008ea64cc5c0087fc9804569338ef005897c (patch) | |
tree | 010130d14be559e429b24181c83cd5bade94909c /libavcodec/avcodec.h | |
parent | 8a278ad30d6f9a428c71dfab5bd6fe68d4717094 (diff) | |
download | ffmpeg-b38f008ea64cc5c0087fc9804569338ef005897c.tar.gz |
Frame-based multithreading framework using pthreads
See doc/multithreading.txt for details on use in codecs.
Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
Diffstat (limited to 'libavcodec/avcodec.h')
-rw-r--r-- | libavcodec/avcodec.h | 88 |
1 files changed, 87 insertions, 1 deletions
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index 09f0a12b00..90446cd6d7 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -32,7 +32,7 @@ #include "libavutil/cpu.h" #define LIBAVCODEC_VERSION_MAJOR 52 -#define LIBAVCODEC_VERSION_MINOR 110 +#define LIBAVCODEC_VERSION_MINOR 111 #define LIBAVCODEC_VERSION_MICRO 0 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ @@ -728,6 +728,10 @@ typedef struct RcOverride{ * Codec is able to deal with negative linesizes */ #define CODEC_CAP_NEG_LINESIZES 0x0800 +/** + * Codec supports frame-level multithreading. + */ +#define CODEC_CAP_FRAME_THREADS 0x1000 //The following defines may change, don't expect compatibility if you use them. #define MB_TYPE_INTRA4x4 0x0001 @@ -1029,6 +1033,20 @@ typedef struct AVPanScan{ int64_t pkt_dts;\ \ /**\ + * the AVCodecContext which ff_thread_get_buffer() was last called on\ + * - encoding: Set by libavcodec.\ + * - decoding: Set by libavcodec.\ + */\ + struct AVCodecContext *owner;\ +\ + /**\ + * used by multithreading to store frame-specific info\ + * - encoding: Set by libavcodec.\ + * - decoding: Set by libavcodec.\ + */\ + void *thread_opaque;\ +\ + /**\ * frame timestamp estimated using various heuristics, in stream time base\ * - encoding: unused\ * - decoding: set by libavcodec, read by user.\ @@ -1246,6 +1264,10 @@ typedef struct AVCodecContext { * decoder to draw a horizontal band. It improves cache usage. Not * all codecs can do that. You must check the codec capabilities * beforehand. + * When multithreading is used, it may be called from multiple threads + * at the same time; threads might draw different parts of the same AVFrame, + * or multiple AVFrames, and there is no guarantee that slices will be drawn + * in order. * The function is also used by hardware acceleration APIs. * It is called at least once during frame decoding to pass * the data needed for hardware render. @@ -1499,6 +1521,9 @@ typedef struct AVCodecContext { * if CODEC_CAP_DR1 is not set then get_buffer() must call * avcodec_default_get_buffer() instead of providing buffers allocated by * some other means. + * If frame multithreading is used and thread_safe_callbacks is set, + * it may be called from a different thread, but not from more than one at once. + * Does not need to be reentrant. * - encoding: unused * - decoding: Set by libavcodec, user can override. */ @@ -1508,6 +1533,8 @@ typedef struct AVCodecContext { * Called to release buffers which were allocated with get_buffer. * A released buffer can be reused in get_buffer(). * pic.data[*] must be set to NULL. + * May be called from a different thread if frame multithreading is used, + * but not by more than one thread at once, so does not need to be reentrant. * - encoding: unused * - decoding: Set by libavcodec, user can override. */ @@ -1811,6 +1838,7 @@ typedef struct AVCodecContext { #define FF_DEBUG_VIS_QP 0x00002000 #define FF_DEBUG_VIS_MB_TYPE 0x00004000 #define FF_DEBUG_BUFFERS 0x00008000 +#define FF_DEBUG_THREADS 0x00010000 /** * debug @@ -2836,6 +2864,44 @@ typedef struct AVCodecContext { AVPacket *pkt; /** + * Whether this is a copy of the context which had init() called on it. + * This is used by multithreading - shared tables and picture pointers + * should be freed from the original context only. + * - encoding: Set by libavcodec. + * - decoding: Set by libavcodec. + */ + int is_copy; + + /** + * Which multithreading methods to use. + * Use of FF_THREAD_FRAME will increase decoding delay by one frame per thread, + * so clients which cannot provide future frames should not use it. + * + * - encoding: Set by user, otherwise the default is used. + * - decoding: Set by user, otherwise the default is used. + */ + int thread_type; +#define FF_THREAD_FRAME 1 //< Decode more than one frame at once +#define FF_THREAD_SLICE 2 //< Decode more than one part of a single frame at once + + /** + * Which multithreading methods are in use by the codec. + * - encoding: Set by libavcodec. + * - decoding: Set by libavcodec. + */ + int active_thread_type; + + /** + * Set by the client if its custom get_buffer() callback can be called + * from another thread, which allows faster multithreaded decoding. + * draw_horiz_band() will be called from other threads regardless of this setting. + * Ignored if the default get_buffer() is used. + * - encoding: Set by user. + * - decoding: Set by user. + */ + int thread_safe_callbacks; + + /** * Current statistics for PTS correction. * - decoding: maintained and used by libavcodec * - encoding: unused @@ -2897,6 +2963,26 @@ typedef struct AVCodec { uint8_t max_lowres; ///< maximum value for lowres supported by the decoder AVClass *priv_class; ///< AVClass for the private context const AVProfile *profiles; ///< array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN} + + /** + * @defgroup framethreading Frame-level threading support functions. + * @{ + */ + /** + * If defined, called on thread contexts when they are created. + * If the codec allocates writable tables in init(), re-allocate them here. + * priv_data will be set to a copy of the original. + */ + int (*init_thread_copy)(AVCodecContext *); + /** + * Copy necessary context variables from a previous thread context to the current one. + * If not defined, the next thread will start automatically; otherwise, the codec + * must call ff_thread_finish_setup(). + * + * dst and src will (rarely) point to the same context, in which case memcpy should be skipped. + */ + int (*update_thread_context)(AVCodecContext *dst, const AVCodecContext *src); + /** @} */ } AVCodec; /** |