]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
make mpglib more not threadsafe
authorAnthony Minessale <anthony.minessale@gmail.com>
Wed, 12 Dec 2007 20:50:58 +0000 (20:50 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Wed, 12 Dec 2007 20:50:58 +0000 (20:50 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6704 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/formats/mod_shout/decode_ntom.c
src/mod/formats/mod_shout/interface.c
src/mod/formats/mod_shout/mpglib.h

index 59c11d0b85ca9d215d89f768e42b4366e1ef945e..2e927ba2d2e4c8a4af36df86a0adba5eee71c13c 100644 (file)
   else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; } \
   else { *(samples) = sum; }
 
-#define NTOM_MUL (32768)
-static unsigned long ntom_val[2] = { NTOM_MUL >> 1, NTOM_MUL >> 1 };
-static unsigned long ntom_step = NTOM_MUL;
 
+//static unsigned long ntom_val[2] = { NTOM_MUL >> 1, NTOM_MUL >> 1 };
+//static unsigned long ntom_step = NTOM_MUL;
 
-int synth_ntom_set_step(long m, long n)
+
+int synth_ntom_set_step(struct mpstr *mp, long m, long n)
 {
        if (param.verbose > 1)
                debug_printf("Init rate converter: %ld->%ld\n", m, n);
@@ -36,14 +36,14 @@ int synth_ntom_set_step(long m, long n)
        }
 
        n *= NTOM_MUL;
-       ntom_step = n / m;
+       mp->ntom_step = n / m;
 
-       if (ntom_step > 8 * NTOM_MUL) {
+       if (mp->ntom_step > 8 * NTOM_MUL) {
                debug_printf("%d max. 1:8 conversion allowed!\n", __LINE__);
                return (1);
        }
 
-       ntom_val[0] = ntom_val[1] = NTOM_MUL >> 1;
+       mp->ntom_val[0] = mp->ntom_val[1] = NTOM_MUL >> 1;
 
        return (0);
 
@@ -89,12 +89,12 @@ int synth_ntom(struct mpstr *mp, real * bandPtr, int channel, unsigned char *out
                bo--;
                bo &= 0xf;
                buf = mp->synth_buffs[0];
-               ntom = ntom_val[1] = ntom_val[0];
+               ntom = mp->ntom_val[1] = mp->ntom_val[0];
        } else {
                samples++;
                out += 2;                               /* to compute the right *pnt value */
                buf = mp->synth_buffs[1];
-               ntom = ntom_val[1];
+               ntom = mp->ntom_val[1];
        }
 
        if (bo & 0x1) {
@@ -116,7 +116,7 @@ int synth_ntom(struct mpstr *mp, real * bandPtr, int channel, unsigned char *out
                for (j = 16; j; j--, window += 0x10) {
                        real sum;
 
-                       ntom += ntom_step;
+                       ntom += mp->ntom_step;
                        if (ntom < NTOM_MUL) {
                                window += 16;
                                b0 += 16;
@@ -147,7 +147,7 @@ int synth_ntom(struct mpstr *mp, real * bandPtr, int channel, unsigned char *out
                        }
                }
 
-               ntom += ntom_step;
+               ntom += mp->ntom_step;
                if (ntom >= NTOM_MUL) {
                        real sum;
                        sum = window[0x0] * b0[0x0];
@@ -172,7 +172,7 @@ int synth_ntom(struct mpstr *mp, real * bandPtr, int channel, unsigned char *out
                for (j = 15; j; j--, b0 -= 0x20, window -= 0x10) {
                        real sum;
 
-                       ntom += ntom_step;
+                       ntom += mp->ntom_step;
                        if (ntom < NTOM_MUL) {
                                window -= 16;
                                b0 += 16;
@@ -204,7 +204,7 @@ int synth_ntom(struct mpstr *mp, real * bandPtr, int channel, unsigned char *out
                }
        }
 
-       ntom_val[channel] = ntom;
+       mp->ntom_val[channel] = ntom;
        *pnt = ((unsigned char *) samples - out);
 
        return clip;
index f188189377f61135177521a6be6e1a5f31aa8847..b5af8fe85e66222949272fc1e9fbddded0b981f2 100644 (file)
@@ -27,6 +27,9 @@ BOOL InitMP3(struct mpstr *mp, long outscale, int samplerate)
        mp->bsnum = 0;
        mp->synth_bo = 1;
        mp->outsamplerate = samplerate;
+       mp->ntom_val[0] = NTOM_MUL >> 1;
+       mp->ntom_val[1] = NTOM_MUL >> 1;
+       mp->ntom_step = NTOM_MUL;
 
        make_decode_tables_scale(mp, outscale);
 
@@ -241,7 +244,7 @@ int decodeMP3(struct mpstr *mp, char *in, int isize, char *out, int osize, int *
                                m = n;
                        }
 
-                       if (synth_ntom_set_step(n, m))
+                       if (synth_ntom_set_step(mp, n, m))
                                return MP3_ERR;
 
 
index 3ad9283eb6e53773bf8e25f95fff203e813cd0ca..93176eca86121b2fe1d9a9048e1102753ef4aa33 100644 (file)
@@ -3,6 +3,7 @@
 #else
 #define debug_printf(fmt,...)
 #endif
+#define NTOM_MUL (32768)
 
 struct buf {
        unsigned char *pnt;
@@ -39,7 +40,8 @@ struct mpstr {
        int longLimit[9][23];           /*sample limits re setting volume */
        int shortLimit[9][14];
        real decwin[512 + 32];          /* scale table */
-
+       unsigned long ntom_val[2];
+       unsigned long ntom_step;
 };
 
 #define BOOL int
@@ -54,7 +56,7 @@ BOOL InitMP3(struct mpstr *mp, long outscale, int samplerate);
 int decodeMP3(struct mpstr *mp, char *inmemory, int inmemsize, char *outmemory, int outmemsize, int *done);
 void ExitMP3(struct mpstr *mp);
 
-extern int synth_ntom_set_step(long, long);
+extern int synth_ntom_set_step(struct mpstr *mp, long, long);
 extern int synth_ntom(struct mpstr *mp, real * bandPtr, int channel, unsigned char *out, int *pnt);
 extern int synth_ntom_mono(struct mpstr *mp, real * bandPtr, unsigned char *samples, int *pnt);
 extern int synth_ntom_8bit(real *, int, unsigned char *, int *);