---
libavcodec/avcodec.h | 3 ++
libavcodec/thread.h | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++
mt-work/todo.txt | 1 -
3 files changed, 54 insertions(+), 1 deletions(-)
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index bd7693d..6f70fcb 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -501,6 +501,9 @@ typedef struct RcOverride{
* This can be used to prevent truncation of the last audio samples.
*/
#define CODEC_CAP_SMALL_LAST_FRAME 0x0040
+/**
+ * Codec supports frame-based multithreading.
+ */
#define CODEC_CAP_FRAME_THREADS 0x0080
//The following defines may change, don't expect compatibility if you use them.
diff --git a/libavcodec/thread.h b/libavcodec/thread.h
index 4f7321b..7211625 100644
--- a/libavcodec/thread.h
+++ b/libavcodec/thread.h
@@ -1,5 +1,6 @@
/*
* Multithreading support
+ * Copyright (c) 2008 Alexander Strange <[EMAIL PROTECTED]>
*
* This file is part of FFmpeg.
*
@@ -18,6 +19,12 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
+/**
+ * @file thread.h
+ * Multithreading support header.
+ * @author Alexander Strange <[EMAIL PROTECTED]>
+ */
+
#ifndef FFMPEG_THREAD_H
#define FFMPEG_THREAD_H
#include "config.h"
@@ -30,15 +37,59 @@ int ff_decode_frame_threaded(AVCodecContext *avctx,
void *data, int *data_size,
const uint8_t *buf, int buf_size);
+/**
+ * Call this function after doing all setup work for the next
+ * frame. The codec's update_context will be called afterwards
+ * in another thread. After calling this, no variable read by
+ * update_context may be modified.
+ */
void ff_report_predecode_done(AVCodecContext *avctx);
+
+/**
+ * Call this function after decoding some part of a frame.
+ * Subsequent calls with lower progress values will be ignored.
+ *
+ * @param f The frame being decoded
+ * @param progress An arbitrary number of parts decoded so far
+ */
void ff_report_decode_progress(AVFrame *f, int progress);
+
+/**
+ * Call this function before accessing a reference frame.
+ * Afterwards, all parts up to and including the passed
+ * value will be available.
+ */
void ff_await_decode_progress(AVFrame *f, int progress);
+/**
+ * Allocate a frame with avctx->get_buffer() and set
+ * values needed for multithreading. Codecs must call
+ * this instead of using get_buffer() directly if
+ * frame threading is enabled.
+ */
int ff_get_buffer(AVCodecContext *avctx, AVFrame *f);
+
+/**
+ * Immediately release the passed frame using the
+ * context passed to ff_get_buffer(). Codecs must
+ * call this instead of avctx->release_buffer() if
+ * frame threading is enabled and the frame can
+ * be safely deallocated immediately.
+ */
void ff_release_buffer(AVFrame *f);
+
+/**
+ * Release the passed frame after all decoding
+ * threads started earlier than the current thread
+ * have completed. This should be used to dispose of
+ * reference frames when the current thread no longer
+ * needs them, since earlier threads may still be running.
+ */
void ff_delayed_release_buffer(AVCodecContext *avctx, AVFrame *f);
+///True if frame threading is active.
#define USE_FRAME_THREADING(avctx) (avctx->thread_algorithm == FF_THREAD_MULTIFRAME)
+///True if calling AVCodecContext execute() will run in parallel.
#define USE_AVCODEC_EXECUTE(avctx) (avctx->thread_algorithm == FF_THREAD_MULTISLICE)
#else
static inline void ff_frame_thread_flush(AVCodecContext *avctx) {}
diff --git a/mt-work/todo.txt b/mt-work/todo.txt
index dbdbf43..bcbeacd 100644
--- a/mt-work/todo.txt
+++ b/mt-work/todo.txt
@@ -1,5 +1,4 @@
Todo
-- Document new API functions
- Maybe write a guide to converting codecs, if the API documentation itself isn't enough
- Don't use the user's AVCodecContext for the first decoding thread, since it will read from it while user code is running and cause a race condition. This is easier than forbidding reading/writing to avctx after calling predecode_done.
- Files with packed B-frames don't decode some frames properly in mplayer, possibly because of the above.
_______________________________________________
FFmpeg-soc mailing list
[email protected]
https://lists.mplayerhq.hu/mailman/listinfo/ffmpeg-soc