Bug 666672 - Fix OSX compile warnings in sydneyaudio and vorbis. r=giles
authorAtul Aggarwal <atulagrwl@gmail.com>
Thu, 01 Sep 2011 11:19:22 +0530
changeset 78604 f61c120e00f2e3ef2b7aa22900c5e134b5abc1bb
parent 78603 606bfc565805dc2c9bcb9125dfc258ca942a0457
child 78605 7ccfcddfed82ea4d7c0afcb439618326c65f8b40
push id340
push userclegnitto@mozilla.com
push dateTue, 08 Nov 2011 22:56:33 +0000
treeherdermozilla-beta@f745dc151615 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgiles
bugs666672
milestone9.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 666672 - Fix OSX compile warnings in sydneyaudio and vorbis. r=giles
media/libsydneyaudio/src/sydney_audio_alsa.c
media/libsydneyaudio/src/sydney_audio_mac.c
media/libvorbis/README_MOZILLA
media/libvorbis/bug666672_gccWarnings.diff
media/libvorbis/lib/vorbis_codebook.c
media/libvorbis/lib/vorbis_floor1.c
media/libvorbis/lib/vorbis_psy.c
media/libvorbis/update.sh
--- a/media/libsydneyaudio/src/sydney_audio_alsa.c
+++ b/media/libsydneyaudio/src/sydney_audio_alsa.c
@@ -382,22 +382,23 @@ sa_stream_drain(sa_stream_t *s)
 {
   if (s == NULL || s->output_unit == NULL) {
     return SA_ERROR_NO_INIT;
   }
 
   if (snd_pcm_state(s->output_unit) == SND_PCM_STATE_PREPARED) {
     size_t min_samples = 0;
     size_t min_bytes = 0;
+    void *buf;
 
     if (sa_stream_get_min_write(s, &min_samples) < 0)
       return SA_ERROR_SYSTEM;
     min_bytes = snd_pcm_frames_to_bytes(s->output_unit, min_samples);    
 
-    void* buf = malloc(min_bytes);
+    buf = malloc(min_bytes);
     if (!buf)
       return SA_ERROR_SYSTEM;
     memset(buf, 0, min_bytes);
     sa_stream_write(s, buf, min_bytes);
     free(buf);
   }
 
   if (snd_pcm_state(s->output_unit) != SND_PCM_STATE_RUNNING) {
--- a/media/libsydneyaudio/src/sydney_audio_mac.c
+++ b/media/libsydneyaudio/src/sydney_audio_mac.c
@@ -115,16 +115,18 @@ sa_stream_create_pcm(
   sa_stream_t      ** _s,
   const char        * client_name,
   sa_mode_t           mode,
   sa_pcm_format_t     format,
   unsigned  int       rate,
   unsigned  int       n_channels
 ) {
 
+  sa_stream_t   * s;
+
   /*
    * Make sure we return a NULL stream pointer on failure.
    */
   if (_s == NULL) {
     return SA_ERROR_INVALID;
   }
   *_s = NULL;
 
@@ -133,17 +135,16 @@ sa_stream_create_pcm(
   }
   if (format != SA_PCM_FORMAT_S16_NE) {
     return SA_ERROR_NOT_SUPPORTED;
   }
 
   /*
    * Allocate the instance and required resources.
    */
-  sa_stream_t   * s;
   if ((s = malloc(sizeof(sa_stream_t))) == NULL) {
     return SA_ERROR_OOM;
   }
   if ((s->bl_head = new_buffer()) == NULL) {
     free(s);
     return SA_ERROR_OOM;
   }
   if (pthread_mutex_init(&s->mutex, NULL) != 0) {
@@ -165,46 +166,49 @@ sa_stream_create_pcm(
   *_s = s;
   return SA_SUCCESS;
 }
 
 
 int
 sa_stream_open(sa_stream_t *s) {
 
+  ComponentDescription desc;
+  Component comp;
+  AURenderCallbackStruct input;
+  AudioStreamBasicDescription fmt;
+
   if (s == NULL) {
     return SA_ERROR_NO_INIT;
   }
   if (s->output_unit != NULL) {
     return SA_ERROR_INVALID;
   }
 
   /*
    * Open the default audio output unit.
    */
-  ComponentDescription desc;
   desc.componentType         = kAudioUnitType_Output;
   desc.componentSubType      = kAudioUnitSubType_DefaultOutput;
   desc.componentManufacturer = kAudioUnitManufacturer_Apple;
   desc.componentFlags        = 0;
   desc.componentFlagsMask    = 0;
 
-  Component comp = FindNextComponent(NULL, &desc);
+  comp = FindNextComponent(NULL, &desc);
   if (comp == NULL) {
     return SA_ERROR_NO_DEVICE;
   }
 
   if (OpenAComponent(comp, &s->output_unit) != noErr) {
     return SA_ERROR_NO_DEVICE;
   }
 
   /*
    * Set up the render callback used to feed audio data into the output unit.
    */
-  AURenderCallbackStruct input;
   input.inputProc       = audio_callback;
   input.inputProcRefCon = s;
   if (AudioUnitSetProperty(s->output_unit, kAudioUnitProperty_SetRenderCallback,
       kAudioUnitScope_Input, 0, &input, sizeof(input)) != 0) {
     return SA_ERROR_SYSTEM;
   }
 
   /*
@@ -217,17 +221,16 @@ sa_stream_open(sa_stream_t *s) {
    *          audio (which is what we have), this is one frame
    * rate   = the number of complete frames per second
    *
    * Note that this definition of frame differs from, well, pretty much everyone
    * else's. See this really long link for more info:
    *
    * http://developer.apple.com/documentation/MusicAudio/Reference/CoreAudioDataTypesRef/Reference/reference.html#//apple_ref/c/tdef/AudioStreamBasicDescription
    */
-  AudioStreamBasicDescription fmt;
   fmt.mFormatID         = kAudioFormatLinearPCM;
   fmt.mFormatFlags      = kLinearPCMFormatFlagIsSignedInteger |
 #ifdef __BIG_ENDIAN__
                           kLinearPCMFormatFlagIsBigEndian |
 #endif
                           kLinearPCMFormatFlagIsPacked;
   fmt.mSampleRate       = s->rate;
   fmt.mChannelsPerFrame = s->n_channels;
@@ -254,31 +257,32 @@ sa_stream_open(sa_stream_t *s) {
 
   return SA_SUCCESS;
 }
 
 
 int
 sa_stream_destroy(sa_stream_t *s) {
 
+  int result = SA_SUCCESS;
+
   if (s == NULL) {
     return SA_SUCCESS;
   }
 
   /*
    * Shut down the audio output device.  Don't hold the mutex when stopping
    * the audio device, because it is possible to deadlock with this thread
    * holding mutex then waiting on an internal Core Audio lock, and with the
    * callback thread holding the Core Audio lock and waiting on the mutex.
    * This does not need to be protected by the mutex anyway because
    * AudioOutputUnitStop, when called from the non-callback thread, blocks
    * until in-flight callbacks complete and the HAL shuts down.  See:
    * http://lists.apple.com/archives/coreaudio-api/2005/Dec/msg00055.html
    */
-  int result = SA_SUCCESS;
   if (s->output_unit != NULL) {
     if (s->playing && AudioOutputUnitStop(s->output_unit) != 0) {
       result = SA_ERROR_SYSTEM;
     }
     if (AudioUnitUninitialize(s->output_unit) != 0) {
       result = SA_ERROR_SYSTEM;
     }
     if (CloseComponent(s->output_unit) != noErr) {
@@ -308,29 +312,30 @@ sa_stream_destroy(sa_stream_t *s) {
  * -----------------------------------------------------------------------------
  * Data read and write functions
  * -----------------------------------------------------------------------------
  */
 
 int
 sa_stream_write(sa_stream_t *s, const void *data, size_t nbytes) {
 
+  int result = SA_SUCCESS;
+
   if (s == NULL || s->output_unit == NULL) {
     return SA_ERROR_NO_INIT;
   }
   if (nbytes == 0) {
     return SA_SUCCESS;
   }
 
   pthread_mutex_lock(&s->mutex);
 
   /*
    * Append the new data to the end of our buffer list.
    */
-  int result = SA_SUCCESS;
   while (1) {
     unsigned int avail = s->bl_tail->size - s->bl_tail->end;
 
     if (nbytes <= avail) {
 
       /*
        * The new data will fit into the current tail buffer, so
        * just copy it in and we're done.
@@ -366,18 +371,19 @@ sa_stream_write(sa_stream_t *s, const vo
            * do here; spinning won't help because the audio callback
            * hasn't been enabled yet. Oh well, error time.
            */
           printf("Too much audio data received before audio device enabled!\n");
           result = SA_ERROR_SYSTEM;
           break;
         }
         while (s->n_bufs == BUF_LIMIT) {
+          struct timespec ts = {0, 1000000};
+
           pthread_mutex_unlock(&s->mutex);
-          struct timespec ts = {0, 1000000};
           nanosleep(&ts, NULL);
           pthread_mutex_lock(&s->mutex);
         }
       }
 
       /* 
        * Allocate a new tail buffer, and go 'round again to fill it up.
        */
@@ -415,71 +421,77 @@ audio_callback(
   void                        * arg,
   AudioUnitRenderActionFlags  * action_flags,
   const AudioTimeStamp        * time_stamp,
   UInt32                        bus_num,
   UInt32                        n_frames,
   AudioBufferList             * data
 ) {
 
+  sa_stream_t     * s = arg;
+  unsigned char   * dst;
+  unsigned int      bytes_per_frame;
+  unsigned int      bytes_to_copy;
+
 #ifdef TIMING_TRACE
   printf(".");  /* audio read 'tick' */
 #endif
 
   /*
    * We're dealing with interleaved data, so the system should only
    * have provided one buffer to be filled.
    */
   assert(data->mNumberBuffers == 1);
 
-  sa_stream_t     * s = arg;
-
   pthread_mutex_lock(&s->mutex);
 
-  unsigned char   * dst             = data->mBuffers[0].mData;
-  unsigned int      bytes_per_frame = s->n_channels * s->bytes_per_ch;
-  unsigned int      bytes_to_copy   = n_frames * bytes_per_frame;
+  dst             = data->mBuffers[0].mData;
+  bytes_per_frame = s->n_channels * s->bytes_per_ch;
+  bytes_to_copy   = n_frames * bytes_per_frame;
 
   s->bytes_played += s->bytes_played_last;
   s->bytes_played_last = 0;
 
   /*
    * Consume data from the start of the buffer list.
    */
   while (1) {
+    unsigned int avail = s->bl_head->end - s->bl_head->start;
+
     assert(s->bl_head->start <= s->bl_head->end);
-    unsigned int avail = s->bl_head->end - s->bl_head->start;
 
     if (avail >= bytes_to_copy) {
 
       /*
        * We have all we need in the head buffer, so just grab it and go.
        */
       memcpy(dst, s->bl_head->data + s->bl_head->start, bytes_to_copy);
       s->bl_head->start += bytes_to_copy;
       s->bytes_played_last += bytes_to_copy;
       break;
 
     } else {
 
+      sa_buf  * next;
+
       /*
        * Copy what we can from the head and move on to the next buffer.
        */
       memcpy(dst, s->bl_head->data + s->bl_head->start, avail);
       s->bl_head->start += avail;
       dst += avail;
       bytes_to_copy -= avail;
       s->bytes_played_last += avail;
 
       /*
        * We want to free the now-empty buffer, but not if it's also the
        * current tail. If it is the tail, we don't have enough data to fill
        * the destination buffer, so we'll just zero it out and give up.
        */
-      sa_buf  * next = s->bl_head->next;
+      next = s->bl_head->next;
       if (next == NULL) {
 #ifdef TIMING_TRACE
         printf("!");  /* not enough audio data */
 #endif
         memset(dst, 0, bytes_to_copy);
         break;
       }
       free(s->bl_head);
@@ -500,27 +512,29 @@ audio_callback(
  * -----------------------------------------------------------------------------
  * General query and support functions
  * -----------------------------------------------------------------------------
  */
 
 int
 sa_stream_get_write_size(sa_stream_t *s, size_t *size) {
 
+  unsigned int avail;
+
   if (s == NULL || s->output_unit == NULL) {
     return SA_ERROR_NO_INIT;
   }
 
   pthread_mutex_lock(&s->mutex);
 
   /*
    * The sum of the free space in the tail buffer plus the size of any new
    * buffers represents the write space available before blocking.
    */
-  unsigned int avail = s->bl_tail->size - s->bl_tail->end;
+  avail = s->bl_tail->size - s->bl_tail->end;
   avail += (BUF_LIMIT - s->n_bufs) * BUF_SIZE;
   *size = avail;
 
   pthread_mutex_unlock(&s->mutex);
   return SA_SUCCESS;
 }
 
 
@@ -607,29 +621,30 @@ sa_stream_drain(sa_stream_t *s)
     return SA_ERROR_NO_INIT;
   }
 
   if (!s->playing) {
     return SA_ERROR_INVALID;
   }
 
   while (1) {
-    pthread_mutex_lock(&s->mutex);
     sa_buf  * b;
     size_t    used = 0;
+    struct timespec ts = {0, 1000000};
+
+    pthread_mutex_lock(&s->mutex);
     for (b = s->bl_head; b != NULL; b = b->next) {
       used += b->end - b->start;
     }
     pthread_mutex_unlock(&s->mutex);
 
     if (used == 0) {
       break;
     }
 
-    struct timespec ts = {0, 1000000};
     nanosleep(&ts, NULL);
   }
   return SA_SUCCESS;
 }
 
 
 
 /*
@@ -651,22 +666,23 @@ sa_stream_set_volume_abs(sa_stream_t *s,
   pthread_mutex_unlock(&s->mutex);
   return SA_SUCCESS;
 }
 
 
 int
 sa_stream_get_volume_abs(sa_stream_t *s, float *vol) {
 
+  Float32 local_vol = 0;
+
   if (s == NULL || s->output_unit == NULL) {
     return SA_ERROR_NO_INIT;
   }
 
   pthread_mutex_lock(&s->mutex);
-  Float32 local_vol = 0;
   AudioUnitGetParameter(s->output_unit, kHALOutputParam_Volume,
       kAudioUnitParameterFlag_Output, 0, &local_vol);
   *vol = local_vol;
   pthread_mutex_unlock(&s->mutex);
   return SA_SUCCESS;
 }
 
 
--- a/media/libvorbis/README_MOZILLA
+++ b/media/libvorbis/README_MOZILLA
@@ -4,8 +4,9 @@ made were those applied by update.sh and
 Makefile.in files for the Mozilla build system.
 
 The upstream release used was libvorbis 1.3.2 (SVN r17614).
 
 Some files are renamed during the copy to prevent clashes with object
 file names with other Mozilla libraries.
 
 alloca.diff - Bug 469639 - Failed to build firefox trunk on OpenSolaris
+bug666672_gccWarnings.diff - Bug 666672 - Fixing some gcc compiler warnings
new file mode 100644
--- /dev/null
+++ b/media/libvorbis/bug666672_gccWarnings.diff
@@ -0,0 +1,91 @@
+diff --git a/media/libvorbis/lib/vorbis_codebook.c b/media/libvorbis/lib/vorbis_codebook.c
+--- a/media/libvorbis/lib/vorbis_codebook.c
++++ b/media/libvorbis/lib/vorbis_codebook.c
+@@ -243,17 +243,17 @@ static_codebook *vorbis_staticbook_unpac
+         quantvals=(s->dim==0?0:_book_maptype1_quantvals(s));
+         break;
+       case 2:
+         quantvals=s->entries*s->dim;
+         break;
+       }
+ 
+       /* quantized values */
+-      if((quantvals*s->q_quant+7>>3)>opb->storage-oggpack_bytes(opb))
++      if(((quantvals*s->q_quant+7)>>3)>opb->storage-oggpack_bytes(opb))
+         goto _eofout;
+       s->quantlist=_ogg_malloc(sizeof(*s->quantlist)*quantvals);
+       for(i=0;i<quantvals;i++)
+         s->quantlist[i]=oggpack_read(opb,s->q_quant);
+ 
+       if(quantvals&&s->quantlist[quantvals-1]==-1)goto _eofout;
+     }
+     break;
+diff --git a/media/libvorbis/lib/vorbis_floor1.c b/media/libvorbis/lib/vorbis_floor1.c
+--- a/media/libvorbis/lib/vorbis_floor1.c
++++ b/media/libvorbis/lib/vorbis_floor1.c
+@@ -1030,17 +1030,17 @@ static void *floor1_inverse1(vorbis_bloc
+         }else{
+           if(val&1){
+             val= -((val+1)>>1);
+           }else{
+             val>>=1;
+           }
+         }
+ 
+-        fit_value[i]=val+predicted&0x7fff;
++        fit_value[i]=(val+predicted)&0x7fff;
+         fit_value[look->loneighbor[i-2]]&=0x7fff;
+         fit_value[look->hineighbor[i-2]]&=0x7fff;
+ 
+       }else{
+         fit_value[i]=predicted|0x8000;
+       }
+ 
+     }
+diff --git a/media/libvorbis/lib/vorbis_psy.c b/media/libvorbis/lib/vorbis_psy.c
+--- a/media/libvorbis/lib/vorbis_psy.c
++++ b/media/libvorbis/lib/vorbis_psy.c
+@@ -1149,37 +1149,38 @@ void _vp_couple_quantize_normalize(int b
+ 
+             }else{
+               /* lossy (point) coupling */
+               if(j<limit-i){
+                 /* dipole */
+                 reM[j] += reA[j];
+                 qeM[j] = fabs(reM[j]);
+               }else{
++#if 0
+                 /* AoTuV */
+                 /** @ M2 **
+                     The boost problem by the combination of noise normalization and point stereo is eased.
+                     However, this is a temporary patch.
+                     by Aoyumi @ 2004/04/18
+                 */
+-                /*float derate = (1.0 - de*((float)(j-limit+i) / (float)(n-limit)));
+-                /* elliptical 
++                float derate = (1.0 - de*((float)(j-limit+i) / (float)(n-limit)));
++                /* elliptical */
+                 if(reM[j]+reA[j]<0){
+                   reM[j] = - (qeM[j] = (fabs(reM[j])+fabs(reA[j]))*derate*derate);
+                 }else{
+                   reM[j] =   (qeM[j] = (fabs(reM[j])+fabs(reA[j]))*derate*derate);
+-                  }*/
+-
++                }
++#else
+                 /* elliptical */
+                 if(reM[j]+reA[j]<0){
+                   reM[j] = - (qeM[j] = fabs(reM[j])+fabs(reA[j]));
+                 }else{
+                   reM[j] =   (qeM[j] = fabs(reM[j])+fabs(reA[j]));
+                 }
+-
++#endif
+ 
+               }
+               reA[j]=qeA[j]=0.f;
+               fA[j]=1;
+               iA[j]=0;
+             }
+           }
+           floorM[j]=floorA[j]=floorM[j]+floorA[j];
--- a/media/libvorbis/lib/vorbis_codebook.c
+++ b/media/libvorbis/lib/vorbis_codebook.c
@@ -243,17 +243,17 @@ static_codebook *vorbis_staticbook_unpac
         quantvals=(s->dim==0?0:_book_maptype1_quantvals(s));
         break;
       case 2:
         quantvals=s->entries*s->dim;
         break;
       }
 
       /* quantized values */
-      if((quantvals*s->q_quant+7>>3)>opb->storage-oggpack_bytes(opb))
+      if(((quantvals*s->q_quant+7)>>3)>opb->storage-oggpack_bytes(opb))
         goto _eofout;
       s->quantlist=_ogg_malloc(sizeof(*s->quantlist)*quantvals);
       for(i=0;i<quantvals;i++)
         s->quantlist[i]=oggpack_read(opb,s->q_quant);
 
       if(quantvals&&s->quantlist[quantvals-1]==-1)goto _eofout;
     }
     break;
--- a/media/libvorbis/lib/vorbis_floor1.c
+++ b/media/libvorbis/lib/vorbis_floor1.c
@@ -1030,17 +1030,17 @@ static void *floor1_inverse1(vorbis_bloc
         }else{
           if(val&1){
             val= -((val+1)>>1);
           }else{
             val>>=1;
           }
         }
 
-        fit_value[i]=val+predicted&0x7fff;
+        fit_value[i]=(val+predicted)&0x7fff;
         fit_value[look->loneighbor[i-2]]&=0x7fff;
         fit_value[look->hineighbor[i-2]]&=0x7fff;
 
       }else{
         fit_value[i]=predicted|0x8000;
       }
 
     }
--- a/media/libvorbis/lib/vorbis_psy.c
+++ b/media/libvorbis/lib/vorbis_psy.c
@@ -1149,37 +1149,38 @@ void _vp_couple_quantize_normalize(int b
 
             }else{
               /* lossy (point) coupling */
               if(j<limit-i){
                 /* dipole */
                 reM[j] += reA[j];
                 qeM[j] = fabs(reM[j]);
               }else{
+#if 0
                 /* AoTuV */
                 /** @ M2 **
                     The boost problem by the combination of noise normalization and point stereo is eased.
                     However, this is a temporary patch.
                     by Aoyumi @ 2004/04/18
                 */
-                /*float derate = (1.0 - de*((float)(j-limit+i) / (float)(n-limit)));
-                /* elliptical 
+                float derate = (1.0 - de*((float)(j-limit+i) / (float)(n-limit)));
+                /* elliptical */
                 if(reM[j]+reA[j]<0){
                   reM[j] = - (qeM[j] = (fabs(reM[j])+fabs(reA[j]))*derate*derate);
                 }else{
                   reM[j] =   (qeM[j] = (fabs(reM[j])+fabs(reA[j]))*derate*derate);
-                  }*/
-
+                }
+#else
                 /* elliptical */
                 if(reM[j]+reA[j]<0){
                   reM[j] = - (qeM[j] = fabs(reM[j])+fabs(reA[j]));
                 }else{
                   reM[j] =   (qeM[j] = fabs(reM[j])+fabs(reA[j]));
                 }
-
+#endif
 
               }
               reA[j]=qeA[j]=0.f;
               fA[j]=1;
               iA[j]=0;
             }
           }
           floorM[j]=floorA[j]=floorM[j]+floorA[j];
--- a/media/libvorbis/update.sh
+++ b/media/libvorbis/update.sh
@@ -42,8 +42,9 @@ cp $1/lib/codebook.c ./lib/vorbis_codebo
 cp $1/lib/bitrate.c ./lib/vorbis_bitrate.c
 cp $1/lib/block.c ./lib/vorbis_block.c
 cp $1/include/vorbis/codec.h ./include/vorbis/codec.h
 cp $1/todo.txt ./todo.txt
 cp $1/COPYING ./COPYING
 cp $1/README ./README
 cp $1/AUTHORS ./AUTHORS
 patch -p3 < ./alloca.diff
+patch -p3 < ./bug666672_gccWarnings.diff