Mercurial > libavcodec.hg
annotate os2thread.c @ 3109:6ade7a72ae52 libavcodec
Add installlib and install-headers targets like everywhere else.
author | diego |
---|---|
date | Sat, 11 Feb 2006 16:50:45 +0000 |
parents | 4bf348f8e2b1 |
children | 84c509024ee9 |
rev | line source |
---|---|
3081
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
1 /* |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
2 * Copyright (c) 2004 Michael Niedermayer <michaelni@gmx.at> |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
3 * |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
4 * This library is free software; you can redistribute it and/or |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
5 * modify it under the terms of the GNU Lesser General Public |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
6 * License as published by the Free Software Foundation; either |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
7 * version 2 of the License, or (at your option) any later version. |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
8 * |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
9 * This library is distributed in the hope that it will be useful, |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
12 * Lesser General Public License for more details. |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
13 * |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
14 * You should have received a copy of the GNU Lesser General Public |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
15 * License along with this library; if not, write to the Free Software |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
17 * |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
18 */ |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
19 //#define DEBUG |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
20 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
21 // Ported by Vlad Stelmahovsky |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
22 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
23 #include "avcodec.h" |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
24 #include "common.h" |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
25 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
26 #ifdef HAVE_THREADS |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
27 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
28 #define INCL_DOS |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
29 #define INCL_DOSERRORS |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
30 #define INCL_DOSDEVIOCTL |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
31 #include <os2.h> |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
32 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
33 typedef struct ThreadContext{ |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
34 AVCodecContext *avctx; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
35 int thread; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
36 HEV work_sem; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
37 HEV done_sem; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
38 int (*func)(AVCodecContext *c, void *arg); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
39 void *arg; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
40 int ret; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
41 }ThreadContext; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
42 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
43 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
44 void thread_func(void *v){ |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
45 ThreadContext *c= v; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
46 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
47 for(;;){ |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
48 //printf("thread_func %X enter wait\n", (int)v); fflush(stdout); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
49 DosWaitEventSem(c->work_sem, SEM_INDEFINITE_WAIT); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
50 // WaitForSingleObject(c->work_sem, INFINITE); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
51 //printf("thread_func %X after wait (func=%X)\n", (int)v, (int)c->func); fflush(stdout); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
52 if(c->func) |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
53 c->ret= c->func(c->avctx, c->arg); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
54 else |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
55 return; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
56 //printf("thread_func %X signal complete\n", (int)v); fflush(stdout); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
57 DosPostEventSem(c->done_sem); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
58 // ReleaseSemaphore(c->done_sem, 1, 0); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
59 } |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
60 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
61 return; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
62 } |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
63 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
64 /** |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
65 * free what has been allocated by avcodec_thread_init(). |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
66 * must be called after decoding has finished, especially dont call while avcodec_thread_execute() is running |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
67 */ |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
68 void avcodec_thread_free(AVCodecContext *s){ |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
69 ThreadContext *c= s->thread_opaque; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
70 int i; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
71 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
72 for(i=0; i<s->thread_count; i++){ |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
73 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
74 c[i].func= NULL; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
75 DosPostEventSem(c[i].work_sem); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
76 // ReleaseSemaphore(c[i].work_sem, 1, 0); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
77 DosWaitThread((PTID)&c[i].thread,DCWW_WAIT); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
78 // WaitForSingleObject(c[i].thread, INFINITE); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
79 if(c[i].work_sem) DosCloseEventSem(c[i].work_sem);//CloseHandle(c[i].work_sem); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
80 if(c[i].done_sem) DosCloseEventSem(c[i].done_sem);//CloseHandle(c[i].done_sem); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
81 } |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
82 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
83 av_freep(&s->thread_opaque); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
84 } |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
85 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
86 int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count){ |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
87 ThreadContext *c= s->thread_opaque; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
88 int i; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
89 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
90 assert(s == c->avctx); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
91 assert(count <= s->thread_count); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
92 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
93 /* note, we can be certain that this is not called with the same AVCodecContext by different threads at the same time */ |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
94 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
95 for(i=0; i<count; i++){ |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
96 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
97 c[i].arg= arg[i]; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
98 c[i].func= func; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
99 c[i].ret= 12345; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
100 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
101 DosPostEventSem(c[i].work_sem); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
102 // ReleaseSemaphore(c[i].work_sem, 1, 0); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
103 } |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
104 for(i=0; i<count; i++){ |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
105 DosWaitEventSem(c[i].done_sem,SEM_INDEFINITE_WAIT); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
106 // WaitForSingleObject(c[i].done_sem, INFINITE); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
107 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
108 c[i].func= NULL; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
109 if(ret) ret[i]= c[i].ret; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
110 } |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
111 return 0; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
112 } |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
113 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
114 int avcodec_thread_init(AVCodecContext *s, int thread_count){ |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
115 int i; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
116 ThreadContext *c; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
117 uint32_t threadid; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
118 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
119 s->thread_count= thread_count; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
120 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
121 assert(!s->thread_opaque); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
122 c= av_mallocz(sizeof(ThreadContext)*thread_count); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
123 s->thread_opaque= c; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
124 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
125 for(i=0; i<thread_count; i++){ |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
126 //printf("init semaphors %d\n", i); fflush(stdout); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
127 c[i].avctx= s; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
128 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
129 if (DosCreateEventSem(NULL,&c[i].work_sem,DC_SEM_SHARED,0)) |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
130 goto fail; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
131 if (DosCreateEventSem(NULL,&c[i].done_sem,DC_SEM_SHARED,0)) |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
132 goto fail; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
133 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
134 //printf("create thread %d\n", i); fflush(stdout); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
135 // c[i].thread = (HANDLE)_beginthreadex(NULL, 0, thread_func, &c[i], 0, &threadid ); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
136 c[i].thread = _beginthread(thread_func, NULL, 0x10000, &c[i]); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
137 if( c[i].thread <= 0 ) goto fail; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
138 } |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
139 //printf("init done\n"); fflush(stdout); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
140 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
141 s->execute= avcodec_thread_execute; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
142 |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
143 return 0; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
144 fail: |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
145 avcodec_thread_free(s); |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
146 return -1; |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
147 } |
4bf348f8e2b1
os2 thread, network and freetype2 support by (Paul Smedley | paulat a t smedleydot d o t info)
michael
parents:
diff
changeset
|
148 #endif |