Originally committed as revision 20225 to svn://svn.ffmpeg.org/ffmpeg/trunk
Unified · Split
| @@ -32,10 +32,12 @@ typedef struct ThreadContext{ · 31 unmodified lines | ||
| 32 | 32 | HANDLE job_sem; |
| 33 | 33 | HANDLE done_sem; |
| 34 | 34 | int (*func)(AVCodecContext *c, void *arg); |
| 35 | + int (*func2)(AVCodecContext *c, void *arg, int, int); | |
| 35 | 36 | void *arg; |
| 36 | 37 | int argsize; |
| 37 | 38 | int *jobnr; |
| 38 | 39 | int *ret; |
| 40 | + int threadnr; | |
| 39 | 41 | }ThreadContext; |
| 40 | 42 | |
| 41 | 43 | |
| @@ -52,6 +54,8 @@ static unsigned WINAPI attribute_align_arg thread_func(void *v){ · 10 unmodified lines | ||
| 52 | 54 | //printf("thread_func %X after wait (func=%X)\n", (int)v, (int)c->func); fflush(stdout); |
| 53 | 55 | if(c->func) |
| 54 | 56 | ret= c->func(c->avctx, (uint8_t *)c->arg + jobnr*c->argsize); |
| 57 | + else if (c->func2) | |
| 58 | + ret= c->func2(c->avctx, c->arg, jobnr, c->threadnr); | |
| 55 | 59 | else |
| 56 | 60 | return 0; |
| 57 | 61 | if (c->ret) |
| @@ -74,6 +78,7 @@ void avcodec_thread_free(AVCodecContext *s){ · 16 unmodified lines | ||
| 74 | 78 | for(i=0; i<s->thread_count; i++){ |
| 75 | 79 | |
| 76 | 80 | c[i].func= NULL; |
| 81 | + c[i].func2= NULL; | |
| 77 | 82 | } |
| 78 | 83 | ReleaseSemaphore(c[0].work_sem, s->thread_count, 0); |
| 79 | 84 | for(i=0; i<s->thread_count; i++){ |
| @@ -110,6 +115,14 @@ int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, vo · 30 unmodified lines | ||
| 110 | 115 | return 0; |
| 111 | 116 | } |
| 112 | 117 | |
| 118 | +int avcodec_thread_execute2(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2, int, int),void *arg, int *ret, int count){ | |
| 119 | + ThreadContext *c= s->thread_opaque; | |
| 120 | + int i; | |
| 121 | + for(i=0; i<s->thread_count; i++) | |
| 122 | + c[i].func2 = func; | |
| 123 | + avcodec_thread_execute(s, NULL, arg, ret, count, 0); | |
| 124 | +} | |
| 125 | + | |
| 113 | 126 | int avcodec_thread_init(AVCodecContext *s, int thread_count){ |
| 114 | 127 | int i; |
| 115 | 128 | ThreadContext *c; |
| @@ -133,6 +146,7 @@ int avcodec_thread_init(AVCodecContext *s, int thread_count){ · 17 unmodified lines | ||
| 133 | 146 | c[i].work_sem = c[0].work_sem; |
| 134 | 147 | c[i].job_sem = c[0].job_sem; |
| 135 | 148 | c[i].done_sem = c[0].done_sem; |
| 149 | + c[i].threadnr = i; | |
| 136 | 150 | |
| 137 | 151 | //printf("create thread %d\n", i); fflush(stdout); |
| 138 | 152 | c[i].thread = (HANDLE)_beginthreadex(NULL, 0, thread_func, &c[i], 0, &threadid ); |
| @@ -141,6 +155,7 @@ int avcodec_thread_init(AVCodecContext *s, int thread_count){ · 2 unmodified lines | ||
| 141 | 155 | //printf("init done\n"); fflush(stdout); |
| 142 | 156 | |
| 143 | 157 | s->execute= avcodec_thread_execute; |
| 158 | + s->execute2= avcodec_thread_execute2; | |
| 144 | 159 | |
| 145 | 160 | return 0; |
| 146 | 161 | fail: |