]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/pthread.c
Set gray (128) U/V planes for chroma-less samples. Fixes two fate samples
[ffmpeg] / libavcodec / pthread.c
index 71f2da630f260f32617f79c3d337d49196a32807..1628b21a1fd61122beac6f6e590eb6f6246432cc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004 Roman Shaposhnik.
+ * Copyright (c) 2004 Roman Shaposhnik
  *
  * Many thanks to Steven M. Schultz for providing clever ideas and
  * to Michael Niedermayer <michaelni@gmx.at> for writing initial
 
 #include "avcodec.h"
 
-typedef int (action_t)(AVCodecContext *c, void *arg);
+typedef int (action_func)(AVCodecContext *c, void *arg);
+typedef int (action_func2)(AVCodecContext *c, void *arg, int jobnr, int threadnr);
 
 typedef struct ThreadContext {
     pthread_t *workers;
-    action_t *func;
+    action_func *func;
+    action_func2 *func2;
     void *args;
     int *rets;
     int rets_count;
@@ -68,7 +70,8 @@ static void* attribute_align_arg worker(void *v)
         }
         pthread_mutex_unlock(&c->current_job_lock);
 
-        c->rets[our_job%c->rets_count] = c->func(avctx, (char*)c->args + our_job*c->job_size);
+        c->rets[our_job%c->rets_count] = c->func ? c->func(avctx, (char*)c->args + our_job*c->job_size):
+                                                   c->func2(avctx, c->args, our_job, self_id);
 
         pthread_mutex_lock(&c->current_job_lock);
         our_job = c->current_job++;
@@ -101,7 +104,7 @@ void avcodec_thread_free(AVCodecContext *avctx)
     av_freep(&avctx->thread_opaque);
 }
 
-int avcodec_thread_execute(AVCodecContext *avctx, action_t* func, void *arg, int *ret, int job_count, int job_size)
+static int avcodec_thread_execute(AVCodecContext *avctx, action_func* func, void *arg, int *ret, int job_count, int job_size)
 {
     ThreadContext *c= avctx->thread_opaque;
     int dummy_ret;
@@ -130,11 +133,23 @@ int avcodec_thread_execute(AVCodecContext *avctx, action_t* func, void *arg, int
     return 0;
 }
 
+static int avcodec_thread_execute2(AVCodecContext *avctx, action_func2* func2, void *arg, int *ret, int job_count)
+{
+    ThreadContext *c= avctx->thread_opaque;
+    c->func2 = func2;
+    return avcodec_thread_execute(avctx, NULL, arg, ret, job_count, 0);
+}
+
 int avcodec_thread_init(AVCodecContext *avctx, int thread_count)
 {
     int i;
     ThreadContext *c;
 
+    avctx->thread_count = thread_count;
+
+    if (thread_count <= 1)
+        return 0;
+
     c = av_mallocz(sizeof(ThreadContext));
     if (!c)
         return -1;
@@ -146,7 +161,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->job_size = 0;
@@ -167,5 +181,6 @@ int avcodec_thread_init(AVCodecContext *avctx, int thread_count)
     avcodec_thread_park_workers(c, thread_count);
 
     avctx->execute = avcodec_thread_execute;
+    avctx->execute2 = avcodec_thread_execute2;
     return 0;
 }