comparison decoders/mpglib/interface.c @ 279:52b9f37998db

Removed global state variable; should be thread safe now.
author Ryan C. Gordon <icculus@icculus.org>
date Thu, 14 Mar 2002 16:38:59 +0000
parents 9e7f9e09ea0e
children ad4c8f34136a
comparison
equal deleted inserted replaced
278:dfe4a46f88f7 279:52b9f37998db
9 9
10 #include "mpg123_sdlsound.h" 10 #include "mpg123_sdlsound.h"
11 #include "mpglib_sdlsound.h" 11 #include "mpglib_sdlsound.h"
12 12
13 /* Global mp .. it's a hack */ 13 /* Global mp .. it's a hack */
14 struct mpstr *gmp; 14 /*struct mpstr *gmp;*/
15 15
16 16
17 BOOL InitMP3(struct mpstr *mp) 17 BOOL InitMP3(struct mpstr *mp)
18 { 18 {
19 static int init = 0; 19 static int init = 0;
156 int decodeMP3(struct mpstr *mp,char *in,int isize,char *out, 156 int decodeMP3(struct mpstr *mp,char *in,int isize,char *out,
157 int osize,int *done) 157 int osize,int *done)
158 { 158 {
159 int len; 159 int len;
160 160
161 gmp = mp;
162
163 if(osize < 4608) { 161 if(osize < 4608) {
164 Sound_SetError("MPGLIB: Not enough output space for decoding!"); 162 Sound_SetError("MPGLIB: Not enough output space for decoding!");
165 return MP3_ERR; 163 return MP3_ERR;
166 } 164 }
167 165
215 *done = 0; 213 *done = 0;
216 if(mp->fr.error_protection) 214 if(mp->fr.error_protection)
217 getbits(16); 215 getbits(16);
218 switch(mp->fr.lay) { 216 switch(mp->fr.lay) {
219 case 1: 217 case 1:
220 do_layer1(&mp->fr,(unsigned char *) out,done); 218 do_layer1(&mp->fr,(unsigned char *) out,done,mp);
221 break; 219 break;
222 case 2: 220 case 2:
223 do_layer2(&mp->fr,(unsigned char *) out,done); 221 do_layer2(&mp->fr,(unsigned char *) out,done,mp);
224 break; 222 break;
225 case 3: 223 case 3:
226 do_layer3(&mp->fr,(unsigned char *) out,done); 224 do_layer3(&mp->fr,(unsigned char *) out,done,mp);
227 break; 225 break;
228 } 226 }
229 227
230 mp->fsizeold = mp->framesize; 228 mp->fsizeold = mp->framesize;
231 mp->framesize = 0; 229 mp->framesize = 0;
232 230
233 return MP3_OK; 231 return MP3_OK;
234 } 232 }
235 233
236 int set_pointer(long backstep) 234 int set_pointer(long backstep, struct mpstr *mp)
237 { 235 {
238 unsigned char *bsbufold; 236 unsigned char *bsbufold;
239 if(gmp->fsizeold < 0 && backstep > 0) { 237 if(mp->fsizeold < 0 && backstep > 0) {
240 Sound_SetError("MPGLIB: Can't step back!"); /* FIXME: need formatting: %ld!\n",backstep); */ 238 Sound_SetError("MPGLIB: Can't step back!"); /* FIXME: need formatting: %ld!\n",backstep); */
241 return MP3_ERR; 239 return MP3_ERR;
242 } 240 }
243 bsbufold = gmp->bsspace[gmp->bsnum] + 512; 241 bsbufold = mp->bsspace[mp->bsnum] + 512;
244 wordpointer -= backstep; 242 wordpointer -= backstep;
245 if (backstep) 243 if (backstep)
246 memcpy(wordpointer,bsbufold+gmp->fsizeold-backstep,backstep); 244 memcpy(wordpointer,bsbufold+mp->fsizeold-backstep,backstep);
247 bitindex = 0; 245 bitindex = 0;
248 return MP3_OK; 246 return MP3_OK;
249 } 247 }
250 248
251 249