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 | HANDLE job_sem; | 32 | HANDLE job_sem; |
| 33 | HANDLE done_sem; | 33 | HANDLE done_sem; |
| 34 | int (*func)(AVCodecContext *c, void *arg); | 34 | int (*func)(AVCodecContext *c, void *arg); |
| 35 | int (*func2)(AVCodecContext *c, void *arg, int, int); | ||
| 35 | void *arg; | 36 | void *arg; |
| 36 | int argsize; | 37 | int argsize; |
| 37 | int *jobnr; | 38 | int *jobnr; |
| 38 | int *ret; | 39 | int *ret; |
| 40 | int threadnr; | ||
| 39 | }ThreadContext; | 41 | }ThreadContext; |
| 40 | 42 | ||
| 41 | 43 | ||
| @@ -52,6 +54,8 @@ static unsigned WINAPI attribute_align_arg thread_func(void *v){ · 10 unmodified lines | |||
| 52 | //printf("thread_func %X after wait (func=%X)\n", (int)v, (int)c->func); fflush(stdout); | 54 | //printf("thread_func %X after wait (func=%X)\n", (int)v, (int)c->func); fflush(stdout); |
| 53 | if(c->func) | 55 | if(c->func) |
| 54 | ret= c->func(c->avctx, (uint8_t *)c->arg + jobnr*c->argsize); | 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 | else | 59 | else |
| 56 | return 0; | 60 | return 0; |
| 57 | if (c->ret) | 61 | if (c->ret) |
| @@ -74,6 +78,7 @@ void avcodec_thread_free(AVCodecContext *s){ · 16 unmodified lines | |||
| 74 | for(i=0; i<s->thread_count; i++){ | 78 | for(i=0; i<s->thread_count; i++){ |
| 75 | 79 | ||
| 76 | c[i].func= NULL; | 80 | c[i].func= NULL; |
| 81 | c[i].func2= NULL; | ||
| 77 | } | 82 | } |
| 78 | ReleaseSemaphore(c[0].work_sem, s->thread_count, 0); | 83 | ReleaseSemaphore(c[0].work_sem, s->thread_count, 0); |
| 79 | for(i=0; i<s->thread_count; i++){ | 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 | return 0; | 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 | int avcodec_thread_init(AVCodecContext *s, int thread_count){ | 126 | int avcodec_thread_init(AVCodecContext *s, int thread_count){ |
| 114 | int i; | 127 | int i; |
| 115 | ThreadContext *c; | 128 | ThreadContext *c; |
| @@ -133,6 +146,7 @@ int avcodec_thread_init(AVCodecContext *s, int thread_count){ · 17 unmodified lines | |||
| 133 | c[i].work_sem = c[0].work_sem; | 146 | c[i].work_sem = c[0].work_sem; |
| 134 | c[i].job_sem = c[0].job_sem; | 147 | c[i].job_sem = c[0].job_sem; |
| 135 | c[i].done_sem = c[0].done_sem; | 148 | c[i].done_sem = c[0].done_sem; |
| 149 | c[i].threadnr = i; | ||
| 136 | 150 | ||
| 137 | //printf("create thread %d\n", i); fflush(stdout); | 151 | //printf("create thread %d\n", i); fflush(stdout); |
| 138 | c[i].thread = (HANDLE)_beginthreadex(NULL, 0, thread_func, &c[i], 0, &threadid ); | 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 | //printf("init done\n"); fflush(stdout); | 155 | //printf("init done\n"); fflush(stdout); |
| 142 | 156 | ||
| 143 | s->execute= avcodec_thread_execute; | 157 | s->execute= avcodec_thread_execute; |
| 158 | s->execute2= avcodec_thread_execute2; | ||
| 144 | 159 | ||
| 145 | return 0; | 160 | return 0; |
| 146 | fail: | 161 | fail: |