| 125 | } |
| 126 | |
| 127 | int avcodec_thread_init(AVCodecContext *s, int thread_count){ |
| 128 | int i; |
| 129 | ThreadContext *c; |
| 130 | uint32_t threadid; |
| 131 | |
| 132 | s->thread_count= thread_count; |
| 133 | |
| 134 | if (thread_count <= 1) |
| 135 | return 0; |
| 136 | |
| 137 | assert(!s->thread_opaque); |
| 138 | c= av_mallocz(sizeof(ThreadContext)*thread_count); |
| 139 | s->thread_opaque= c; |
| 140 | if(!(c[0].work_sem = CreateSemaphore(NULL, 0, INT_MAX, NULL))) |
| 141 | goto fail; |
| 142 | if(!(c[0].job_sem = CreateSemaphore(NULL, 1, 1, NULL))) |
| 143 | goto fail; |
| 144 | if(!(c[0].done_sem = CreateSemaphore(NULL, 0, INT_MAX, NULL))) |
| 145 | goto fail; |
| 146 | |
| 147 | for(i=0; i<thread_count; i++){ |
| 148 | //printf("init semaphors %d\n", i); fflush(stdout); |
| 149 | c[i].avctx= s; |
| 150 | c[i].work_sem = c[0].work_sem; |
| 151 | c[i].job_sem = c[0].job_sem; |
| 152 | c[i].done_sem = c[0].done_sem; |
| 153 | c[i].threadnr = i; |
| 154 | |
| 155 | //printf("create thread %d\n", i); fflush(stdout); |
| 156 | c[i].thread = (HANDLE)_beginthreadex(NULL, 0, thread_func, &c[i], 0, &threadid ); |
| 157 | if( !c[i].thread ) goto fail; |
| 158 | } |
| 159 | //printf("init done\n"); fflush(stdout); |
| 160 | |
| 161 | s->execute= avcodec_thread_execute; |
| 162 | s->execute2= avcodec_thread_execute2; |
| 163 | |
| 164 | return 0; |
| 165 | fail: |
| 166 | avcodec_thread_free(s); |
| 167 | return -1; |
| 168 | } |
nothing calls this directly
no test coverage detected