annotate beosthread.c @ 4166:eced83504436 libavcodec

mp3 header (de)compression bitstream filter this will make mp3 frames 4 bytes smaller, it will not give you binary identical mp3 files, but it will give you mp3 files which decode to binary identical output this will only work in containers providing at least packet size, sample_rate and number of channels bugreports about mp3 files for which this fails are welcome and this is experimental (dont expect compatibility and dont even expect to be able to decompress what you compressed, hell dont even expect this to work without editing the source a little)
author michael
date Fri, 10 Nov 2006 01:41:53 +0000
parents c8c591fe26f8
children f99e40a7155b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 #include "common.h"
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
25
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
26 #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
27
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
28 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
29 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
30 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
31 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
32 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
33 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
34 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
35 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
36 }ThreadContext;
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
37
2469
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
38 // 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
39 struct benaphore {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
40 vint32 atom;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
41 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
42 };
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
43 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
44 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
45 if (atomic_add(&ben->atom, 1) > 0)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
46 return acquire_sem(ben->sem);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
47 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
48 }
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
49 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
50 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
51 if (atomic_add(&ben->atom, -1) > 1)
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
52 return release_sem(ben->sem);
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
53 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
54 }
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
55
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
56 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
57
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
58 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
59 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
60
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
61 for(;;){
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
62 //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
63 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
64 //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
65 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
66 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
67 else
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
68 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
69 //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
70 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
71 }
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2469
diff changeset
72
2362
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
73 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
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 /**
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
77 * 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
78 * 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
79 */
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
80 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
81 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
82 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
83 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
84
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
85 for(i=0; i<s->thread_count; i++){
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2469
diff changeset
86
2362
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
87 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
88 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
89 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
90 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
91 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
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
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
94 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
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
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
97 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
98 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
99 int i;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2469
diff changeset
100
2362
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(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
102 assert(count <= s->thread_count);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2469
diff changeset
103
2362
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
104 /* 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
105
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
106 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
107 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
108 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
109 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
110
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
111 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
112 }
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
113 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
114 acquire_sem(c[i].done_sem);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2469
diff changeset
115
2362
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
116 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
117 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
118 }
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
119 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
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
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 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
123 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
124 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
125
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
126 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
127
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
128 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
129 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
130 s->thread_opaque= c;
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2469
diff changeset
131
2362
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
132 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
133 //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
134 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
135
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
136 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
137 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
138 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
139 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
140
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
141 //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
142 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
143 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
144 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
145 }
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
146 //printf("init done\n"); fflush(stdout);
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2469
diff changeset
147
2362
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
148 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
149
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
150 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
151 fail:
7a6ff8cc7c95 BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
diff changeset
152 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
153 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
154 }
2469
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
155
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
156 /* 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
157
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
158 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
159 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
160 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
161 }
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
162
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
163 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
164 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
165 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
166 }
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
167
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
168 /* 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
169
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
170 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
171 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
172 av_thread_lib_ben.atom = 0;
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
173 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
174 }
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
175
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
176 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
177 {
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
178 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
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
df02930c138b added a lock/unlock_lib pair to allow extern progs to serialize access to lavc.
mmu_man
parents: 2362
diff changeset
182