[FFmpeg-soc] [PATCH 5/9] Split setting avctx->thread_count from the rest of pthread init.
Alexander Strange
astrange at ithinksw.com
Thu May 29 05:46:33 CEST 2008
Make sure it's called from whichever of avcodec_open and
avcodec_thread_init comes later.
---
libavcodec/thread.c | 21 ++++++++++++++++++---
libavcodec/utils.c | 12 ++++++++++++
2 files changed, 30 insertions(+), 3 deletions(-)
diff --git a/libavcodec/thread.c b/libavcodec/thread.c
index 975cadd..5b9f4fa 100644
--- a/libavcodec/thread.c
+++ b/libavcodec/thread.c
@@ -24,6 +24,7 @@
#include <pthread.h>
#include "avcodec.h"
+#include "thread.h"
typedef int (action_t)(AVCodecContext *c, void *arg);
@@ -80,7 +81,7 @@ static av_always_inline void
avcodec_thread_park_workers(ThreadContext *c, int t
pthread_mutex_unlock(&c->current_job_lock);
}
-void avcodec_thread_free(AVCodecContext *avctx)
+void ff_thread_free(AVCodecContext *avctx)
{
ThreadContext *c = avctx->thread_opaque;
int i;
@@ -131,7 +132,7 @@ int avcodec_thread_execute(AVCodecContext *avctx,
action_t* func, void **arg, in
return 0;
}
-int avcodec_thread_init(AVCodecContext *avctx, int thread_count)
+int ff_thread_init(AVCodecContext *avctx, int thread_count)
{
int i;
ThreadContext *c;
@@ -147,7 +148,6 @@ int avcodec_thread_init(AVCodecContext *avctx, int
thread_count)
}
avctx->thread_opaque = c;
- avctx->thread_count = thread_count;
c->current_job = 0;
c->job_count = 0;
c->done = 0;
@@ -169,3 +169,18 @@ int avcodec_thread_init(AVCodecContext *avctx,
int thread_count)
avctx->execute = avcodec_thread_execute;
return 0;
}
+
+int avcodec_thread_init(AVCodecContext *s, int thread_count)
+{
+ s->thread_count = thread_count;
+
+ if (!s->thread_opaque)
+ return ff_thread_init(s, thread_count);
+
+ return 0;
+}
+
+void avcodec_thread_free(AVCodecContext *s)
+{
+ ff_thread_free(s);
+}
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 3fd5eb3..72dc3c7 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -31,6 +31,8 @@
#include "dsputil.h"
#include "opt.h"
#include "imgconvert.h"
+#include "thread.h"
+
#include <stdarg.h>
#include <limits.h>
#include <float.h>
@@ -883,6 +885,16 @@ int attribute_align_arg
avcodec_open(AVCodecContext *avctx, AVCodec *codec)
goto end;
}
}
+
+ if (avctx->thread_count > 1) {
+ ret = ff_thread_init(avctx, avctx->thread_count);
+ if (ret < 0) {
+ av_freep(&avctx->priv_data);
+ avctx->codec= NULL;
+ goto end;
+ }
+ }
+
ret=0;
end:
entangled_thread_counter--;
--
1.5.5.1
More information about the FFmpeg-soc
mailing list