Mercurial > libavcodec.hg
annotate beosthread.c @ 4970:28b67304e5d0 libavcodec
Fix r8963
author | ramiro |
---|---|
date | Thu, 10 May 2007 15:00:09 +0000 |
parents | f99e40a7155b |
children | 4dbe6578f811 |
rev | line source |
---|---|
2362
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
1 /* |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
2 * Copyright (c) 2004 François Revol <revol@free.fr> |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
3 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
4 * This file is part of FFmpeg. |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
5 * |
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
6 * FFmpeg is free software; you can redistribute it and/or |
2362
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
7 * modify it under the terms of the GNU Lesser General Public |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
8 * License as published by the Free Software Foundation; either |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
9 * version 2.1 of the License, or (at your option) any later version. |
2362
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
10 * |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
11 * FFmpeg is distributed in the hope that it will be useful, |
2362
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
14 * Lesser General Public License for more details. |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
15 * |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
16 * You should have received a copy of the GNU Lesser General Public |
3947
c8c591fe26f8
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
3036
diff
changeset
|
17 * License along with FFmpeg; if not, write to the Free Software |
3036
0b546eab515d
Update licensing information: The FSF changed postal address.
diego
parents:
2979
diff
changeset
|
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
2362
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
19 * |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
20 */ |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
21 //#define DEBUG |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
22 |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
23 #include "avcodec.h" |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
24 |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
25 #include <OS.h> |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
26 |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
27 typedef struct ThreadContext{ |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
28 AVCodecContext *avctx; |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
29 thread_id thread; |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
30 sem_id work_sem; |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
31 sem_id done_sem; |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
32 int (*func)(AVCodecContext *c, void *arg); |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
33 void *arg; |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
34 int ret; |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
35 }ThreadContext; |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
36 |
2469
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
37 // it's odd Be never patented that :D |
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
38 struct benaphore { |
2979 | 39 vint32 atom; |
40 sem_id sem; | |
2469
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
41 }; |
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
42 static inline int lock_ben(struct benaphore *ben) |
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
43 { |
2979 | 44 if (atomic_add(&ben->atom, 1) > 0) |
45 return acquire_sem(ben->sem); | |
46 return B_OK; | |
2469
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
47 } |
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
48 static inline int unlock_ben(struct benaphore *ben) |
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
49 { |
2979 | 50 if (atomic_add(&ben->atom, -1) > 1) |
51 return release_sem(ben->sem); | |
52 return B_OK; | |
2469
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
53 } |
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
54 |
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
55 static struct benaphore av_thread_lib_ben; |
2362
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
56 |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
57 static int32 ff_thread_func(void *v){ |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
58 ThreadContext *c= v; |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
59 |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
60 for(;;){ |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
61 //printf("thread_func %X enter wait\n", (int)v); fflush(stdout); |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
62 acquire_sem(c->work_sem); |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
63 //printf("thread_func %X after wait (func=%X)\n", (int)v, (int)c->func); fflush(stdout); |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
64 if(c->func) |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
65 c->ret= c->func(c->avctx, c->arg); |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
66 else |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
67 return 0; |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
68 //printf("thread_func %X signal complete\n", (int)v); fflush(stdout); |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
69 release_sem(c->done_sem); |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
70 } |
2967 | 71 |
2362
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
72 return B_OK; |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
73 } |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
74 |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
75 /** |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
76 * free what has been allocated by avcodec_thread_init(). |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
77 * must be called after decoding has finished, especially dont call while avcodec_thread_execute() is running |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
78 */ |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
79 void avcodec_thread_free(AVCodecContext *s){ |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
80 ThreadContext *c= s->thread_opaque; |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
81 int i; |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
82 int32 ret; |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
83 |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
84 for(i=0; i<s->thread_count; i++){ |
2967 | 85 |
2362
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
86 c[i].func= NULL; |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
87 release_sem(c[i].work_sem); |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
88 wait_for_thread(c[i].thread, &ret); |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
89 if(c[i].work_sem > B_OK) delete_sem(c[i].work_sem); |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
90 if(c[i].done_sem > B_OK) delete_sem(c[i].done_sem); |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
91 } |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
92 |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
93 av_freep(&s->thread_opaque); |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
94 } |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
95 |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
96 int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count){ |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
97 ThreadContext *c= s->thread_opaque; |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
98 int i; |
2967 | 99 |
2362
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
100 assert(s == c->avctx); |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
101 assert(count <= s->thread_count); |
2967 | 102 |
2362
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
103 /* note, we can be certain that this is not called with the same AVCodecContext by different threads at the same time */ |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
104 |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
105 for(i=0; i<count; i++){ |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
106 c[i].arg= arg[i]; |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
107 c[i].func= func; |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
108 c[i].ret= 12345; |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
109 |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
110 release_sem(c[i].work_sem); |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
111 } |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
112 for(i=0; i<count; i++){ |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
113 acquire_sem(c[i].done_sem); |
2967 | 114 |
2362
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
115 c[i].func= NULL; |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
116 if(ret) ret[i]= c[i].ret; |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
117 } |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
118 return 0; |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
119 } |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
120 |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
121 int avcodec_thread_init(AVCodecContext *s, int thread_count){ |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
122 int i; |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
123 ThreadContext *c; |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
124 |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
125 s->thread_count= thread_count; |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
126 |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
127 assert(!s->thread_opaque); |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
128 c= av_mallocz(sizeof(ThreadContext)*thread_count); |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
129 s->thread_opaque= c; |
2967 | 130 |
2362
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
131 for(i=0; i<thread_count; i++){ |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
132 //printf("init semaphors %d\n", i); fflush(stdout); |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
133 c[i].avctx= s; |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
134 |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
135 if((c[i].work_sem = create_sem(0, "ff work sem")) < B_OK) |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
136 goto fail; |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
137 if((c[i].done_sem = create_sem(0, "ff done sem")) < B_OK) |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
138 goto fail; |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
139 |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
140 //printf("create thread %d\n", i); fflush(stdout); |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
141 c[i].thread = spawn_thread(ff_thread_func, "libavcodec thread", B_LOW_PRIORITY, &c[i] ); |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
142 if( c[i].thread < B_OK ) goto fail; |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
143 resume_thread(c[i].thread ); |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
144 } |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
145 //printf("init done\n"); fflush(stdout); |
2967 | 146 |
2362
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
147 s->execute= avcodec_thread_execute; |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
148 |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
149 return 0; |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
150 fail: |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
151 avcodec_thread_free(s); |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
152 return -1; |
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff
changeset
|
153 } |
2469
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
154 |
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
155 /* provide a mean to serialize calls to avcodec_*() for thread safety. */ |
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
156 |
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
157 int avcodec_thread_lock_lib(void) |
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
158 { |
2979 | 159 return lock_ben(&av_thread_lib_ben); |
2469
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
160 } |
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
161 |
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
162 int avcodec_thread_unlock_lib(void) |
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
163 { |
2979 | 164 return unlock_ben(&av_thread_lib_ben); |
2469
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
165 } |
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
166 |
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
167 /* our versions of _init and _fini (which are called by those actually from crt.o) */ |
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
168 |
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
169 void initialize_after(void) |
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
170 { |
2979 | 171 av_thread_lib_ben.atom = 0; |
172 av_thread_lib_ben.sem = create_sem(0, "libavcodec benaphore"); | |
2469
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
173 } |
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
174 |
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
175 void uninitialize_before(void) |
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
176 { |
2979 | 177 delete_sem(av_thread_lib_ben.sem); |
2469
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
178 } |
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
179 |
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
180 |
df02930c138b
added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents:
2362
diff
changeset
|
181 |