Bug 1341254 - Update libspeex_resampler to 79822c. r=karlt
authorPaul Adenot <paul@paul.cx>
Mon, 06 Mar 2017 17:16:23 +0100
changeset 347149 c8df499e005abc1438c394dfa72257e369097d7d
parent 347148 4b1b4e0d85790a4cc752993c1cbf12e4a4ce0e3d
child 347150 9bbcd60ba4e7f77a8b43ce63586c27ecde9cbcc2
push id31491
push usercbook@mozilla.com
push dateMon, 13 Mar 2017 14:24:00 +0000
treeherdermozilla-central@8d9fd089cabd [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskarlt
bugs1341254
milestone55.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 1341254 - Update libspeex_resampler to 79822c. r=karlt MozReview-Commit-ID: EDYCyjrWmz1
media/libspeex_resampler/README_MOZILLA
media/libspeex_resampler/fix-overflow.patch
media/libspeex_resampler/handle-memory-error.patch
media/libspeex_resampler/hugemem.patch
media/libspeex_resampler/outside-speex.patch
media/libspeex_resampler/set-rate-overflow-no-return.patch
media/libspeex_resampler/src/arch.h
media/libspeex_resampler/src/fixed_generic.h
media/libspeex_resampler/src/resample.c
media/libspeex_resampler/src/resample_sse.c
media/libspeex_resampler/src/speex_resampler.h
media/libspeex_resampler/src/stack_alloc.h
media/libspeex_resampler/update.sh
--- a/media/libspeex_resampler/README_MOZILLA
+++ b/media/libspeex_resampler/README_MOZILLA
@@ -1,5 +1,5 @@
 This source is from the Speex DSP library
-(http://git.xiph.org/?p=speexdsp.git), from commit d60e75b2.
+(http://git.xiph.org/?p=speexdsp.git), from commit 79822c.
 
 It consists in the audio resampling code (resampler.c) and its header files
 dependancies, imported into the tree using the update.sh script.
deleted file mode 100644
--- a/media/libspeex_resampler/fix-overflow.patch
+++ /dev/null
@@ -1,87 +0,0 @@
-diff --git a/media/libspeex_resampler/fix-overflow.patch b/media/libspeex_resampler/fix-overflow.patch
-new file mode 100644
-index 0000000..e69de29
-diff --git a/media/libspeex_resampler/src/resample.c b/media/libspeex_resampler/src/resample.c
-index a3859e3..d99595a 100644
---- a/media/libspeex_resampler/src/resample.c
-+++ b/media/libspeex_resampler/src/resample.c
-@@ -98,6 +98,10 @@ static void speex_free (void *ptr) {free(ptr);}
- #define NULL 0
- #endif
- 
-+#ifndef UINT32_MAX
-+#define UINT32_MAX 4294967296U
-+#endif
-+
- #include "simd_detect.h"
- 
- /* Numer of elements to allocate on the stack */
-@@ -603,6 +607,22 @@ static int resampler_basic_zero(SpeexResamplerState *st, spx_uint32_t channel_in
-    return out_sample;
- }
- 
-+static int _muldiv_safe(spx_uint32_t value, spx_uint32_t mul, spx_uint32_t div)
-+{
-+  /* TODO: Could be simplified with 64 bits operation. */
-+  spx_uint32_t major = value / div;
-+  spx_uint32_t remainder = value % div;
-+  return remainder <= UINT32_MAX / mul && major <= UINT32_MAX / mul &&
-+         major * mul <= UINT32_MAX - remainder * mul / div;
-+}
-+
-+static spx_uint32_t _muldiv(spx_uint32_t value, spx_uint32_t mul, spx_uint32_t div)
-+{
-+  spx_uint32_t major = value / div;
-+  spx_uint32_t remainder = value % div;
-+  return remainder * mul / div + major * mul;
-+}
-+
- static int update_filter(SpeexResamplerState *st)
- {
-    spx_uint32_t old_length = st->filt_len;
-@@ -620,8 +640,9 @@ static int update_filter(SpeexResamplerState *st)
-    {
-       /* down-sampling */
-       st->cutoff = quality_map[st->quality].downsample_bandwidth * st->den_rate / st->num_rate;
--      /* FIXME: divide the numerator and denominator by a certain amount if they're too large */
--      st->filt_len = st->filt_len*st->num_rate / st->den_rate;
-+      if (!_muldiv_safe(st->filt_len,st->num_rate,st->den_rate))
-+         goto fail;
-+      st->filt_len = _muldiv(st->filt_len,st->num_rate,st->den_rate);
-       /* Round up to make sure we have a multiple of 8 for SSE */
-       st->filt_len = ((st->filt_len-1)&(~0x7))+8;
-       if (2*st->den_rate < st->num_rate)
-@@ -1129,7 +1150,9 @@ EXPORT int speex_resampler_set_rate_frac(SpeexResamplerState *st, spx_uint32_t r
-    {
-       for (i=0;i<st->nb_channels;i++)
-       {
--         st->samp_frac_num[i]=st->samp_frac_num[i]*st->den_rate/old_den;
-+         if (!_muldiv_safe(st->samp_frac_num[i],st->den_rate,old_den))
-+            return RESAMPLER_ERR_OVERFLOW;
-+         st->samp_frac_num[i]= _muldiv(st->samp_frac_num[i],st->den_rate,old_den);
-          /* Safety net */
-          if (st->samp_frac_num[i] >= st->den_rate)
-             st->samp_frac_num[i] = st->den_rate-1;
-diff --git a/media/libspeex_resampler/src/speex_resampler.h b/media/libspeex_resampler/src/speex_resampler.h
-index 70abe52..1286872 100644
---- a/media/libspeex_resampler/src/speex_resampler.h
-+++ b/media/libspeex_resampler/src/speex_resampler.h
-@@ -106,7 +106,8 @@ enum {
-    RESAMPLER_ERR_BAD_STATE       = 2,
-    RESAMPLER_ERR_INVALID_ARG     = 3,
-    RESAMPLER_ERR_PTR_OVERLAP     = 4,
--   
-+   RESAMPLER_ERR_OVERFLOW        = 5,
-+
-    RESAMPLER_ERR_MAX_ERROR
- };
- 
-diff --git a/media/libspeex_resampler/update.sh b/media/libspeex_resampler/update.sh
-index d4a025b..6950bc6 100644
---- a/media/libspeex_resampler/update.sh
-+++ b/media/libspeex_resampler/update.sh
-@@ -26,3 +26,4 @@ patch -p3 < set-skip-frac.patch
- patch -p3 < hugemem.patch
- patch -p3 < remove-empty-asm-clobber.patch
- patch -p3 < handle-memory-error.patch
-+patch -p3 < fix-overflow.patch
deleted file mode 100644
--- a/media/libspeex_resampler/handle-memory-error.patch
+++ /dev/null
@@ -1,46 +0,0 @@
-diff --git a/media/libspeex_resampler/src/resample.c b/media/libspeex_resampler/src/resample.c
-index 83ad119..a3859e3 100644
---- a/media/libspeex_resampler/src/resample.c
-+++ b/media/libspeex_resampler/src/resample.c
-@@ -811,6 +811,12 @@ EXPORT SpeexResamplerState *speex_resampler_init_frac(spx_uint32_t nb_channels,
-       return NULL;
-    }
-    st = (SpeexResamplerState *)speex_alloc(sizeof(SpeexResamplerState));
-+   if (!st)
-+   {
-+      if (err)
-+         *err = RESAMPLER_ERR_ALLOC_FAILED;
-+      return NULL;
-+   }
-    st->initialised = 0;
-    st->started = 0;
-    st->in_rate = 0;
-@@ -832,9 +838,12 @@ EXPORT SpeexResamplerState *speex_resampler_init_frac(spx_uint32_t nb_channels,
-    st->buffer_size = 160;
-    
-    /* Per channel data */
--   st->last_sample = (spx_int32_t*)speex_alloc(nb_channels*sizeof(spx_int32_t));
--   st->magic_samples = (spx_uint32_t*)speex_alloc(nb_channels*sizeof(spx_uint32_t));
--   st->samp_frac_num = (spx_uint32_t*)speex_alloc(nb_channels*sizeof(spx_uint32_t));
-+   if (!(st->last_sample = (spx_int32_t*)speex_alloc(nb_channels*sizeof(spx_int32_t))))
-+      goto fail;
-+   if (!(st->magic_samples = (spx_uint32_t*)speex_alloc(nb_channels*sizeof(spx_uint32_t))))
-+      goto fail;
-+   if (!(st->samp_frac_num = (spx_uint32_t*)speex_alloc(nb_channels*sizeof(spx_uint32_t))))
-+      goto fail;
-    for (i=0;i<nb_channels;i++)
-    {
-       st->last_sample[i] = 0;
-@@ -857,6 +866,12 @@ EXPORT SpeexResamplerState *speex_resampler_init_frac(spx_uint32_t nb_channels,
-       *err = filter_err;
- 
-    return st;
-+
-+fail:
-+   if (err)
-+      *err = RESAMPLER_ERR_ALLOC_FAILED;
-+   speex_resampler_destroy(st);
-+   return NULL;
- }
- 
- EXPORT void speex_resampler_destroy(SpeexResamplerState *st)
--- a/media/libspeex_resampler/hugemem.patch
+++ b/media/libspeex_resampler/hugemem.patch
@@ -1,13 +1,13 @@
 diff --git a/media/libspeex_resampler/src/resample.c b/media/libspeex_resampler/src/resample.c
 --- a/media/libspeex_resampler/src/resample.c
 +++ b/media/libspeex_resampler/src/resample.c
 @@ -56,16 +56,18 @@
-    (e.g. 2/3), and get rid of the rounding operations in the inner loop. 
+    (e.g. 2/3), and get rid of the rounding operations in the inner loop.
     The latter both reduces CPU time and makes the algorithm more SIMD-friendly.
  */
  
  #ifdef HAVE_CONFIG_H
  #include "config.h"
  #endif
  
 +#define RESAMPLE_HUGEMEM 1
@@ -15,25 +15,25 @@ diff --git a/media/libspeex_resampler/sr
  #ifdef OUTSIDE_SPEEX
  #include <stdlib.h>
  static void *speex_alloc (int size) {return calloc(size,1);}
  static void *speex_realloc (void *ptr, int size) {return realloc(ptr, size);}
  static void speex_free (void *ptr) {free(ptr);}
  #include "speex_resampler.h"
  #include "arch.h"
  #else /* OUTSIDE_SPEEX */
-@@ -632,25 +634,26 @@ static int update_filter(SpeexResamplerS
+@@ -643,25 +645,26 @@ static int update_filter(SpeexResamplerS
           st->oversample >>= 1;
        if (st->oversample < 1)
           st->oversample = 1;
     } else {
        /* up-sampling */
        st->cutoff = quality_map[st->quality].upsample_bandwidth;
     }
-    
+ 
 -   /* Choose the resampling type that requires the least amount of memory */
 -#ifdef RESAMPLE_FULL_SINC_TABLE
 -   use_direct = 1;
 -   if (INT_MAX/sizeof(spx_word16_t)/st->den_rate < st->filt_len)
 -      goto fail;
 +   use_direct =
 +#ifdef RESAMPLE_HUGEMEM
 +      /* Choose the direct resampler, even with higher initialization costs,
@@ -49,8 +49,9 @@ diff --git a/media/libspeex_resampler/sr
     if (use_direct)
     {
        min_sinc_table_length = st->filt_len*st->den_rate;
     } else {
        if ((INT_MAX/sizeof(spx_word16_t)-8)/st->oversample < st->filt_len)
           goto fail;
  
        min_sinc_table_length = st->filt_len*st->oversample+8;
+
--- a/media/libspeex_resampler/outside-speex.patch
+++ b/media/libspeex_resampler/outside-speex.patch
@@ -10,21 +10,21 @@ diff --git a/media/libspeex_resampler/sr
  #ifndef SPEEX_RESAMPLER_H
  #define SPEEX_RESAMPLER_H
  
 -#ifdef OUTSIDE_SPEEX
 +#if 1 /* OUTSIDE_SPEEX */
  
  /********* WARNING: MENTAL SANITY ENDS HERE *************/
  
- /* If the resampler is defined outside of Speex, we change the symbol names so that 
+ /* If the resampler is defined outside of Speex, we change the symbol names so that
     there won't be any clash if linking with Speex later on. */
  
  /* #define RANDOM_PREFIX your software name here */
 +#define RANDOM_PREFIX moz_speex
  #ifndef RANDOM_PREFIX
  #error "Please define RANDOM_PREFIX (above) to something specific to your project to prevent symbol name clashes"
  #endif
  
  #define CAT_PREFIX2(a,b) a ## b
  #define CAT_PREFIX(a,b) CAT_PREFIX2(a, b)
-       
+ 
  #define speex_resampler_init CAT_PREFIX(RANDOM_PREFIX,_resampler_init)
--- a/media/libspeex_resampler/set-rate-overflow-no-return.patch
+++ b/media/libspeex_resampler/set-rate-overflow-no-return.patch
@@ -1,23 +1,25 @@
+diff --git a/media/libspeex_resampler/src/resample.c b/media/libspeex_resampler/src/resample.c
 --- a/media/libspeex_resampler/src/resample.c
 +++ b/media/libspeex_resampler/src/resample.c
-@@ -1146,17 +1146,19 @@ EXPORT int speex_resampler_set_rate_frac
-       }
-    }
-       
+@@ -1141,18 +1141,19 @@ EXPORT int speex_resampler_set_rate_frac
+ 
+    st->num_rate /= fact;
+    st->den_rate /= fact;
+ 
     if (old_den > 0)
     {
        for (i=0;i<st->nb_channels;i++)
        {
-          if (!_muldiv_safe(st->samp_frac_num[i],st->den_rate,old_den))
+-         if (_muldiv(&st->samp_frac_num[i],st->samp_frac_num[i],st->den_rate,old_den) != RESAMPLER_ERR_SUCCESS)
 -            return RESAMPLER_ERR_OVERFLOW;
-+         {
-+             st->samp_frac_num[i] = st->den_rate-1;
++         if (_muldiv(&st->samp_frac_num[i],st->samp_frac_num[i],st->den_rate,old_den) != RESAMPLER_ERR_SUCCESS) {
++           st->samp_frac_num[i] = st->den_rate-1;
 +         }
-          st->samp_frac_num[i]= _muldiv(st->samp_frac_num[i],st->den_rate,old_den);
           /* Safety net */
           if (st->samp_frac_num[i] >= st->den_rate)
              st->samp_frac_num[i] = st->den_rate-1;
        }
     }
-    
+ 
     if (st->initialised)
+       return update_filter(st);
--- a/media/libspeex_resampler/src/arch.h
+++ b/media/libspeex_resampler/src/arch.h
@@ -2,28 +2,28 @@
 /**
    @file arch.h
    @brief Various architecture definitions Speex
 */
 /*
    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions
    are met:
-   
+
    - Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
-   
+
    - Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
-   
+
    - Neither the name of the Xiph.org Foundation nor the names of its
    contributors may be used to endorse or promote products derived from
    this software without specific prior written permission.
-   
+
    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
@@ -96,16 +96,18 @@ typedef spx_word32_t spx_sig_t;
 #define GAIN_SCALING 64
 #define GAIN_SCALING_1 0.015625
 
 #define LPC_SHIFT    13
 #define LSP_SHIFT    13
 #define SIG_SHIFT    14
 #define GAIN_SHIFT   6
 
+#define WORD2INT(x) ((x) < -32767 ? -32768 : ((x) > 32766 ? 32767 : (x)))
+
 #define VERY_SMALL 0
 #define VERY_LARGE32 ((spx_word32_t)2147483647)
 #define VERY_LARGE16 ((spx_word16_t)32767)
 #define Q15_ONE ((spx_word16_t)32767)
 
 
 #ifdef FIXED_DEBUG
 #include "fixed_debug.h"
@@ -198,28 +200,29 @@ typedef float spx_word32_t;
 #define MULT16_16_P13(a,b)     ((a)*(b))
 #define MULT16_16_P14(a,b)     ((a)*(b))
 
 #define DIV32_16(a,b)     (((spx_word32_t)(a))/(spx_word16_t)(b))
 #define PDIV32_16(a,b)     (((spx_word32_t)(a))/(spx_word16_t)(b))
 #define DIV32(a,b)     (((spx_word32_t)(a))/(spx_word32_t)(b))
 #define PDIV32(a,b)     (((spx_word32_t)(a))/(spx_word32_t)(b))
 
-
+#define WORD2INT(x) ((x) < -32767.5f ? -32768 : \
+                    ((x) > 32766.5f ? 32767 : (spx_int16_t)floor(.5 + (x))))
 #endif
 
 
 #if defined (CONFIG_TI_C54X) || defined (CONFIG_TI_C55X)
 
 /* 2 on TI C5x DSP */
-#define BYTES_PER_CHAR 2 
+#define BYTES_PER_CHAR 2
 #define BITS_PER_CHAR 16
 #define LOG2_BITS_PER_CHAR 4
 
-#else 
+#else
 
 #define BYTES_PER_CHAR 1
 #define BITS_PER_CHAR 8
 #define LOG2_BITS_PER_CHAR 3
 
 #endif
 
 
--- a/media/libspeex_resampler/src/fixed_generic.h
+++ b/media/libspeex_resampler/src/fixed_generic.h
@@ -2,28 +2,28 @@
 /**
    @file fixed_generic.h
    @brief Generic fixed-point operations
 */
 /*
    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions
    are met:
-   
+
    - Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
-   
+
    - Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
-   
+
    - Neither the name of the Xiph.org Foundation nor the names of its
    contributors may be used to endorse or promote products derived from
    this software without specific prior written permission.
-   
+
    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
--- a/media/libspeex_resampler/src/resample.c
+++ b/media/libspeex_resampler/src/resample.c
@@ -1,11 +1,11 @@
 /* Copyright (C) 2007-2008 Jean-Marc Valin
    Copyright (C) 2008      Thorvald Natvig
-      
+
    File: resample.c
    Arbitrary resampling code
 
    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are
    met:
 
    1. Redistributions of source code must retain the above copyright notice,
@@ -33,32 +33,32 @@
 
 /*
    The design goals of this code are:
       - Very fast algorithm
       - SIMD-friendly algorithm
       - Low memory requirement
       - Good *perceptual* quality (and not best SNR)
 
-   Warning: This resampler is relatively new. Although I think I got rid of 
+   Warning: This resampler is relatively new. Although I think I got rid of
    all the major bugs and I don't expect the API to change anymore, there
    may be something I've missed. So use with caution.
 
    This algorithm is based on this original resampling algorithm:
    Smith, Julius O. Digital Audio Resampling Home Page
-   Center for Computer Research in Music and Acoustics (CCRMA), 
+   Center for Computer Research in Music and Acoustics (CCRMA),
    Stanford University, 2007.
-   Web published at http://www-ccrma.stanford.edu/~jos/resample/.
+   Web published at http://ccrma.stanford.edu/~jos/resample/.
 
-   There is one main difference, though. This resampler uses cubic 
+   There is one main difference, though. This resampler uses cubic
    interpolation instead of linear interpolation in the above paper. This
    makes the table much smaller and makes it possible to compute that table
-   on a per-stream basis. In turn, being able to tweak the table for each 
-   stream makes it possible to both reduce complexity on simple ratios 
-   (e.g. 2/3), and get rid of the rounding operations in the inner loop. 
+   on a per-stream basis. In turn, being able to tweak the table for each
+   stream makes it possible to both reduce complexity on simple ratios
+   (e.g. 2/3), and get rid of the rounding operations in the inner loop.
    The latter both reduces CPU time and makes the algorithm more SIMD-friendly.
 */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
 #endif
 
 #define RESAMPLE_HUGEMEM 1
@@ -80,22 +80,16 @@ static void speex_free (void *ptr) {free
 #include "stack_alloc.h"
 #include <math.h>
 #include <limits.h>
 
 #ifndef M_PI
 #define M_PI 3.14159265358979323846
 #endif
 
-#ifdef FIXED_POINT
-#define WORD2INT(x) ((x) < -32767 ? -32768 : ((x) > 32766 ? 32767 : (x)))  
-#else
-#define WORD2INT(x) ((x) < -32767.5f ? -32768 : ((x) > 32766.5f ? 32767 : floor(.5+(x))))  
-#endif
-               
 #define IMAX(a,b) ((a) > (b) ? (a) : (b))
 #define IMIN(a,b) ((a) < (b) ? (a) : (b))
 
 #ifndef NULL
 #define NULL 0
 #endif
 
 #ifndef UINT32_MAX
@@ -113,39 +107,39 @@ static void speex_free (void *ptr) {free
 
 typedef int (*resampler_basic_func)(SpeexResamplerState *, spx_uint32_t , const spx_word16_t *, spx_uint32_t *, spx_word16_t *, spx_uint32_t *);
 
 struct SpeexResamplerState_ {
    spx_uint32_t in_rate;
    spx_uint32_t out_rate;
    spx_uint32_t num_rate;
    spx_uint32_t den_rate;
-   
+
    int    quality;
    spx_uint32_t nb_channels;
    spx_uint32_t filt_len;
    spx_uint32_t mem_alloc_size;
    spx_uint32_t buffer_size;
    int          int_advance;
    int          frac_advance;
    float  cutoff;
    spx_uint32_t oversample;
    int          initialised;
    int          started;
-   
+
    /* These are per-channel */
    spx_int32_t  *last_sample;
    spx_uint32_t *samp_frac_num;
    spx_uint32_t *magic_samples;
-   
+
    spx_word16_t *mem;
    spx_word16_t *sinc_table;
    spx_uint32_t sinc_table_length;
    resampler_basic_func resampler_ptr;
-         
+
    int    in_stride;
    int    out_stride;
 } ;
 
 static const double kaiser12_table[68] = {
    0.99859849, 1.00000000, 0.99859849, 0.99440475, 0.98745105, 0.97779076,
    0.96549770, 0.95066529, 0.93340547, 0.91384741, 0.89213598, 0.86843014,
    0.84290116, 0.81573067, 0.78710866, 0.75723148, 0.72629970, 0.69451601,
@@ -177,30 +171,30 @@ static const double kaiser10_table[36] =
 
 static const double kaiser8_table[36] = {
    0.99635258, 1.00000000, 0.99635258, 0.98548012, 0.96759014, 0.94302200,
    0.91223751, 0.87580811, 0.83439927, 0.78875245, 0.73966538, 0.68797126,
    0.63451750, 0.58014482, 0.52566725, 0.47185369, 0.41941150, 0.36897272,
    0.32108304, 0.27619388, 0.23465776, 0.19672670, 0.16255380, 0.13219758,
    0.10562887, 0.08273982, 0.06335451, 0.04724088, 0.03412321, 0.02369490,
    0.01563093, 0.00959968, 0.00527363, 0.00233883, 0.00050000, 0.00000000};
-   
+
 static const double kaiser6_table[36] = {
    0.99733006, 1.00000000, 0.99733006, 0.98935595, 0.97618418, 0.95799003,
    0.93501423, 0.90755855, 0.87598009, 0.84068475, 0.80211977, 0.76076565,
    0.71712752, 0.67172623, 0.62508937, 0.57774224, 0.53019925, 0.48295561,
    0.43647969, 0.39120616, 0.34752997, 0.30580127, 0.26632152, 0.22934058,
    0.19505503, 0.16360756, 0.13508755, 0.10953262, 0.08693120, 0.06722600,
    0.05031820, 0.03607231, 0.02432151, 0.01487334, 0.00752000, 0.00000000};
 
 struct FuncDef {
    const double *table;
    int oversample;
 };
-      
+
 static const struct FuncDef _KAISER12 = {kaiser12_table, 64};
 #define KAISER12 (&_KAISER12)
 /*static struct FuncDef _KAISER12 = {kaiser12_table, 32};
 #define KAISER12 (&_KAISER12)*/
 static const struct FuncDef _KAISER10 = {kaiser10_table, 32};
 #define KAISER10 (&_KAISER10)
 static const struct FuncDef _KAISER8 = {kaiser8_table, 32};
 #define KAISER8 (&_KAISER8)
@@ -212,17 +206,17 @@ struct QualityMapping {
    int oversample;
    float downsample_bandwidth;
    float upsample_bandwidth;
    const struct FuncDef *window_func;
 };
 
 
 /* This table maps conversion quality to internal parameters. There are two
-   reasons that explain why the up-sampling bandwidth is larger than the 
+   reasons that explain why the up-sampling bandwidth is larger than the
    down-sampling bandwidth:
    1) When up-sampling, we can assume that the spectrum is already attenuated
       close to the Nyquist rate (from an A/D or a previous resampling filter)
    2) Any aliasing that occurs very close to the Nyquist rate will be masked
       by the sinusoids/noise just below the Nyquist rate (guaranteed only for
       up-sampling).
 */
 static const struct QualityMapping quality_map[11] = {
@@ -238,28 +232,28 @@ static const struct QualityMapping quali
    {192, 32, 0.968f, 0.968f, KAISER12}, /* Q9 */  /* 95.5% cutoff (~100 dB stop) 10 */
    {256, 32, 0.975f, 0.975f, KAISER12}, /* Q10 */ /* 96.6% cutoff (~100 dB stop) 10 */
 };
 /*8,24,40,56,80,104,128,160,200,256,320*/
 static double compute_func(float x, const struct FuncDef *func)
 {
    float y, frac;
    double interp[4];
-   int ind; 
+   int ind;
    y = x*func->oversample;
    ind = (int)floor(y);
    frac = (y-ind);
    /* CSE with handle the repeated powers */
    interp[3] =  -0.1666666667*frac + 0.1666666667*(frac*frac*frac);
    interp[2] = frac + 0.5*(frac*frac) - 0.5*(frac*frac*frac);
    /*interp[2] = 1.f - 0.5f*frac - frac*frac + 0.5f*frac*frac*frac;*/
    interp[0] = -0.3333333333*frac + 0.5*(frac*frac) - 0.1666666667*(frac*frac*frac);
    /* Just to make sure we don't have rounding problems */
    interp[1] = 1.f-interp[3]-interp[2]-interp[0];
-   
+
    /*sum = frac*accum[1] + (1-frac)*accum[2];*/
    return interp[0]*func->table[ind] + interp[1]*func->table[ind+1] + interp[2]*func->table[ind+2] + interp[3]*func->table[ind+3];
 }
 
 #if 0
 #include <stdio.h>
 int main(int argc, char **argv)
 {
@@ -488,17 +482,17 @@ static int resampler_basic_interpolate_s
       sum = MULT16_32_Q15(interp[0],SHR32(accum[0], 1)) + MULT16_32_Q15(interp[1],SHR32(accum[1], 1)) + MULT16_32_Q15(interp[2],SHR32(accum[2], 1)) + MULT16_32_Q15(interp[3],SHR32(accum[3], 1));
       sum = SATURATE32PSHR(sum, 15, 32767);
 #ifdef OVERRIDE_INTERPOLATE_PRODUCT_SINGLE
       } else {
       cubic_coef(frac, interp);
       sum = interpolate_product_single(iptr, st->sinc_table + st->oversample + 4 - offset - 2, N, st->oversample, interp);
       }
 #endif
-      
+
       out[out_stride * out_sample++] = sum;
       last_sample += int_advance;
       samp_frac_num += frac_advance;
       if (samp_frac_num >= den_rate)
       {
          samp_frac_num -= den_rate;
          last_sample++;
       }
@@ -554,17 +548,17 @@ static int resampler_basic_interpolate_d
       cubic_coef(frac, interp);
       sum = MULT16_32_Q15(interp[0],accum[0]) + MULT16_32_Q15(interp[1],accum[1]) + MULT16_32_Q15(interp[2],accum[2]) + MULT16_32_Q15(interp[3],accum[3]);
 #ifdef OVERRIDE_INTERPOLATE_PRODUCT_DOUBLE
       } else {
       cubic_coef(frac, interp);
       sum = interpolate_product_double(iptr, st->sinc_table + st->oversample + 4 - offset - 2, N, st->oversample, interp);
       }
 #endif
-      
+
       out[out_stride * out_sample++] = PSHR32(sum,15);
       last_sample += int_advance;
       samp_frac_num += frac_advance;
       if (samp_frac_num >= den_rate)
       {
          samp_frac_num -= den_rate;
          last_sample++;
       }
@@ -602,69 +596,65 @@ static int resampler_basic_zero(SpeexRes
       }
    }
 
    st->last_sample[channel_index] = last_sample;
    st->samp_frac_num[channel_index] = samp_frac_num;
    return out_sample;
 }
 
-static int _muldiv_safe(spx_uint32_t value, spx_uint32_t mul, spx_uint32_t div)
+static int _muldiv(spx_uint32_t *result, spx_uint32_t value, spx_uint32_t mul, spx_uint32_t div)
 {
-  /* TODO: Could be simplified with 64 bits operation. */
-  spx_uint32_t major = value / div;
-  spx_uint32_t remainder = value % div;
-  return remainder <= UINT32_MAX / mul && major <= UINT32_MAX / mul &&
-         major * mul <= UINT32_MAX - remainder * mul / div;
-}
-
-static spx_uint32_t _muldiv(spx_uint32_t value, spx_uint32_t mul, spx_uint32_t div)
-{
-  spx_uint32_t major = value / div;
-  spx_uint32_t remainder = value % div;
-  return remainder * mul / div + major * mul;
+   speex_assert(result);
+   spx_uint32_t major = value / div;
+   spx_uint32_t remainder = value % div;
+   /* TODO: Could use 64 bits operation to check for overflow. But only guaranteed in C99+ */
+   if (remainder > UINT32_MAX / mul || major > UINT32_MAX / mul
+       || major * mul > UINT32_MAX - remainder * mul / div)
+      return RESAMPLER_ERR_OVERFLOW;
+   *result = remainder * mul / div + major * mul;
+   return RESAMPLER_ERR_SUCCESS;
 }
 
 static int update_filter(SpeexResamplerState *st)
 {
    spx_uint32_t old_length = st->filt_len;
    spx_uint32_t old_alloc_size = st->mem_alloc_size;
    int use_direct;
    spx_uint32_t min_sinc_table_length;
    spx_uint32_t min_alloc_size;
 
    st->int_advance = st->num_rate/st->den_rate;
    st->frac_advance = st->num_rate%st->den_rate;
    st->oversample = quality_map[st->quality].oversample;
    st->filt_len = quality_map[st->quality].base_length;
-   
+
    if (st->num_rate > st->den_rate)
    {
       /* down-sampling */
       st->cutoff = quality_map[st->quality].downsample_bandwidth * st->den_rate / st->num_rate;
-      if (!_muldiv_safe(st->filt_len,st->num_rate,st->den_rate))
+      if (_muldiv(&st->filt_len,st->filt_len,st->num_rate,st->den_rate) != RESAMPLER_ERR_SUCCESS)
          goto fail;
-      st->filt_len = _muldiv(st->filt_len,st->num_rate,st->den_rate);
       /* Round up to make sure we have a multiple of 8 for SSE */
       st->filt_len = ((st->filt_len-1)&(~0x7))+8;
       if (2*st->den_rate < st->num_rate)
          st->oversample >>= 1;
       if (4*st->den_rate < st->num_rate)
          st->oversample >>= 1;
       if (8*st->den_rate < st->num_rate)
          st->oversample >>= 1;
       if (16*st->den_rate < st->num_rate)
          st->oversample >>= 1;
       if (st->oversample < 1)
          st->oversample = 1;
    } else {
       /* up-sampling */
       st->cutoff = quality_map[st->quality].upsample_bandwidth;
    }
-   
+
    use_direct =
 #ifdef RESAMPLE_HUGEMEM
       /* Choose the direct resampler, even with higher initialization costs,
          when resampling any multiple of 100 to 44100. */
       st->den_rate <= 441
 #else
       /* Choose the resampling type that requires the least amount of memory */
       st->filt_len*st->den_rate <= st->filt_len*st->oversample+8
@@ -754,17 +744,17 @@ static int update_filter(SpeexResamplerS
       /*speex_warning("increase filter size");*/
       for (i=st->nb_channels;i--;)
       {
          spx_uint32_t j;
          spx_uint32_t olen = old_length;
          /*if (st->magic_samples[i])*/
          {
             /* Try and remove the magic samples as if nothing had happened */
-            
+
             /* FIXME: This is wrong but for now we need it to avoid going over the array bounds */
             olen = old_length + 2*st->magic_samples[i];
             for (j=old_length-1+st->magic_samples[i];j--;)
                st->mem[i*st->mem_alloc_size+j+st->magic_samples[i]] = st->mem[i*old_alloc_size+j];
             for (j=0;j<st->magic_samples[i];j++)
                st->mem[i*st->mem_alloc_size+j] = 0;
             st->magic_samples[i] = 0;
          }
@@ -820,17 +810,17 @@ EXPORT SpeexResamplerState *speex_resamp
 }
 
 EXPORT SpeexResamplerState *speex_resampler_init_frac(spx_uint32_t nb_channels, spx_uint32_t ratio_num, spx_uint32_t ratio_den, spx_uint32_t in_rate, spx_uint32_t out_rate, int quality, int *err)
 {
    spx_uint32_t i;
    SpeexResamplerState *st;
    int filter_err;
 
-   if (quality > 10 || quality < 0)
+   if (nb_channels == 0 || ratio_num == 0 || ratio_den == 0 || quality > 10 || quality < 0)
    {
       if (err)
          *err = RESAMPLER_ERR_INVALID_ARG;
       return NULL;
    }
    st = (SpeexResamplerState *)speex_alloc(sizeof(SpeexResamplerState));
    if (!st)
    {
@@ -845,37 +835,31 @@ EXPORT SpeexResamplerState *speex_resamp
    st->num_rate = 0;
    st->den_rate = 0;
    st->quality = -1;
    st->sinc_table_length = 0;
    st->mem_alloc_size = 0;
    st->filt_len = 0;
    st->mem = 0;
    st->resampler_ptr = 0;
-         
+
    st->cutoff = 1.f;
    st->nb_channels = nb_channels;
    st->in_stride = 1;
    st->out_stride = 1;
-   
+
    st->buffer_size = 160;
-   
+
    /* Per channel data */
    if (!(st->last_sample = (spx_int32_t*)speex_alloc(nb_channels*sizeof(spx_int32_t))))
       goto fail;
    if (!(st->magic_samples = (spx_uint32_t*)speex_alloc(nb_channels*sizeof(spx_uint32_t))))
       goto fail;
    if (!(st->samp_frac_num = (spx_uint32_t*)speex_alloc(nb_channels*sizeof(spx_uint32_t))))
       goto fail;
-   for (i=0;i<nb_channels;i++)
-   {
-      st->last_sample[i] = 0;
-      st->magic_samples[i] = 0;
-      st->samp_frac_num[i] = 0;
-   }
 
    speex_resampler_set_quality(st, quality);
    speex_resampler_set_rate_frac(st, ratio_num, ratio_den, in_rate, out_rate);
 
    filter_err = update_filter(st);
    if (filter_err == RESAMPLER_ERR_SUCCESS)
    {
       st->initialised = 1;
@@ -907,44 +891,44 @@ EXPORT void speex_resampler_destroy(Spee
 
 static int speex_resampler_process_native(SpeexResamplerState *st, spx_uint32_t channel_index, spx_uint32_t *in_len, spx_word16_t *out, spx_uint32_t *out_len)
 {
    int j=0;
    const int N = st->filt_len;
    int out_sample = 0;
    spx_word16_t *mem = st->mem + channel_index * st->mem_alloc_size;
    spx_uint32_t ilen;
-   
+
    st->started = 1;
-   
+
    /* Call the right resampler through the function ptr */
    out_sample = st->resampler_ptr(st, channel_index, mem, in_len, out, out_len);
-   
+
    if (st->last_sample[channel_index] < (spx_int32_t)*in_len)
       *in_len = st->last_sample[channel_index];
    *out_len = out_sample;
    st->last_sample[channel_index] -= *in_len;
-   
+
    ilen = *in_len;
 
    for(j=0;j<N-1;++j)
      mem[j] = mem[j+ilen];
 
    return RESAMPLER_ERR_SUCCESS;
 }
 
 static int speex_resampler_magic(SpeexResamplerState *st, spx_uint32_t channel_index, spx_word16_t **out, spx_uint32_t out_len) {
    spx_uint32_t tmp_in_len = st->magic_samples[channel_index];
    spx_word16_t *mem = st->mem + channel_index * st->mem_alloc_size;
    const int N = st->filt_len;
-   
+
    speex_resampler_process_native(st, channel_index, &tmp_in_len, *out, &out_len);
 
    st->magic_samples[channel_index] -= tmp_in_len;
-   
+
    /* If we couldn't process all "magic" input samples, save the rest for next time */
    if (st->magic_samples[channel_index])
    {
       spx_uint32_t i;
       for (i=0;i<st->magic_samples[channel_index];i++)
          mem[N-1+i]=mem[N-1+i+tmp_in_len];
    }
    *out += out_len*st->out_stride;
@@ -960,23 +944,23 @@ EXPORT int speex_resampler_process_float
    int j;
    spx_uint32_t ilen = *in_len;
    spx_uint32_t olen = *out_len;
    spx_word16_t *x = st->mem + channel_index * st->mem_alloc_size;
    const int filt_offs = st->filt_len - 1;
    const spx_uint32_t xlen = st->mem_alloc_size - filt_offs;
    const int istride = st->in_stride;
 
-   if (st->magic_samples[channel_index]) 
+   if (st->magic_samples[channel_index])
       olen -= speex_resampler_magic(st, channel_index, &out, olen);
    if (! st->magic_samples[channel_index]) {
       while (ilen && olen) {
         spx_uint32_t ichunk = (ilen > xlen) ? xlen : ilen;
         spx_uint32_t ochunk = olen;
- 
+
         if (in) {
            for(j=0;j<ichunk;++j)
               x[j+filt_offs]=in[j*istride];
         } else {
           for(j=0;j<ichunk;++j)
             x[j+filt_offs]=0;
         }
         speex_resampler_process_native(st, channel_index, &ichunk, out, &ochunk);
@@ -1010,17 +994,17 @@ EXPORT int speex_resampler_process_int(S
    VARDECL(spx_word16_t *ystack);
    ALLOC(ystack, ylen, spx_word16_t);
 #else
    const unsigned int ylen = FIXED_STACK_ALLOC;
    spx_word16_t ystack[FIXED_STACK_ALLOC];
 #endif
 
    st->out_stride = 1;
-   
+
    while (ilen && olen) {
      spx_word16_t *y = ystack;
      spx_uint32_t ichunk = (ilen > xlen) ? xlen : ilen;
      spx_uint32_t ochunk = (olen > ylen) ? ylen : olen;
      spx_uint32_t omagic = 0;
 
      if (st->magic_samples[channel_index]) {
        omagic = speex_resampler_magic(st, channel_index, &y, ochunk);
@@ -1047,17 +1031,17 @@ EXPORT int speex_resampler_process_int(S
      }
 
      for (j=0;j<ochunk+omagic;++j)
 #ifdef FIXED_POINT
         out[j*ostride_save] = ystack[j];
 #else
         out[j*ostride_save] = WORD2INT(ystack[j]);
 #endif
-     
+
      ilen -= ichunk;
      olen -= ochunk;
      out += (ochunk+omagic) * ostride_save;
      if (in)
        in += ichunk * istride_save;
    }
    st->out_stride = ostride_save;
    *in_len -= ilen;
@@ -1083,17 +1067,17 @@ EXPORT int speex_resampler_process_inter
          speex_resampler_process_float(st, i, in+i, in_len, out+i, out_len);
       else
          speex_resampler_process_float(st, i, NULL, in_len, out+i, out_len);
    }
    st->in_stride = istride_save;
    st->out_stride = ostride_save;
    return st->resampler_ptr == resampler_basic_zero ? RESAMPLER_ERR_ALLOC_FAILED : RESAMPLER_ERR_SUCCESS;
 }
-               
+
 EXPORT int speex_resampler_process_interleaved_int(SpeexResamplerState *st, const spx_int16_t *in, spx_uint32_t *in_len, spx_int16_t *out, spx_uint32_t *out_len)
 {
    spx_uint32_t i;
    int istride_save, ostride_save;
    spx_uint32_t bak_out_len = *out_len;
    spx_uint32_t bak_in_len = *in_len;
    istride_save = st->in_stride;
    ostride_save = st->out_stride;
@@ -1118,54 +1102,64 @@ EXPORT int speex_resampler_set_rate(Spee
 }
 
 EXPORT void speex_resampler_get_rate(SpeexResamplerState *st, spx_uint32_t *in_rate, spx_uint32_t *out_rate)
 {
    *in_rate = st->in_rate;
    *out_rate = st->out_rate;
 }
 
+static inline spx_uint32_t _gcd(spx_uint32_t a, spx_uint32_t b)
+{
+   while (b != 0)
+   {
+      spx_uint32_t temp = a;
+
+      a = b;
+      b = temp % b;
+   }
+   return a;
+}
+
 EXPORT int speex_resampler_set_rate_frac(SpeexResamplerState *st, spx_uint32_t ratio_num, spx_uint32_t ratio_den, spx_uint32_t in_rate, spx_uint32_t out_rate)
 {
    spx_uint32_t fact;
    spx_uint32_t old_den;
    spx_uint32_t i;
+
+   if (ratio_num == 0 || ratio_den == 0)
+      return RESAMPLER_ERR_INVALID_ARG;
+
    if (st->in_rate == in_rate && st->out_rate == out_rate && st->num_rate == ratio_num && st->den_rate == ratio_den)
       return RESAMPLER_ERR_SUCCESS;
-   
+
    old_den = st->den_rate;
    st->in_rate = in_rate;
    st->out_rate = out_rate;
    st->num_rate = ratio_num;
    st->den_rate = ratio_den;
-   /* FIXME: This is terribly inefficient, but who cares (at least for now)? */
-   for (fact=2;fact<=IMIN(st->num_rate, st->den_rate);fact++)
-   {
-      while ((st->num_rate % fact == 0) && (st->den_rate % fact == 0))
-      {
-         st->num_rate /= fact;
-         st->den_rate /= fact;
-      }
-   }
-      
+
+   fact = _gcd (st->num_rate, st->den_rate);
+
+   st->num_rate /= fact;
+   st->den_rate /= fact;
+
    if (old_den > 0)
    {
       for (i=0;i<st->nb_channels;i++)
       {
-         if (!_muldiv_safe(st->samp_frac_num[i],st->den_rate,old_den))
-         {
-             st->samp_frac_num[i] = st->den_rate-1;
+         if (_muldiv(&st->samp_frac_num[i],st->samp_frac_num[i],st->den_rate,old_den) != RESAMPLER_ERR_SUCCESS) {
+           st->samp_frac_num[i] = st->den_rate-1;
          }
-         st->samp_frac_num[i]= _muldiv(st->samp_frac_num[i],st->den_rate,old_den);
          /* Safety net */
          if (st->samp_frac_num[i] >= st->den_rate)
             st->samp_frac_num[i] = st->den_rate-1;
       }
    }
-   
+
    if (st->initialised)
       return update_filter(st);
    return RESAMPLER_ERR_SUCCESS;
 }
 
 EXPORT void speex_resampler_get_ratio(SpeexResamplerState *st, spx_uint32_t *ratio_num, spx_uint32_t *ratio_den)
 {
    *ratio_num = st->num_rate;
--- a/media/libspeex_resampler/src/resample_sse.c
+++ b/media/libspeex_resampler/src/resample_sse.c
@@ -4,28 +4,28 @@
 /**
    @file resample_sse.h
    @brief Resampler functions (SSE version)
 */
 /*
    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions
    are met:
-   
+
    - Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
-   
+
    - Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
-   
+
    - Neither the name of the Xiph.org Foundation nor the names of its
    contributors may be used to endorse or promote products derived from
    this software without specific prior written permission.
-   
+
    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
--- a/media/libspeex_resampler/src/speex_resampler.h
+++ b/media/libspeex_resampler/src/speex_resampler.h
@@ -1,13 +1,13 @@
 /* Copyright (C) 2007 Jean-Marc Valin
-      
+
    File: speex_resampler.h
    Resampling code
-      
+
    The design goals of this code are:
       - Very fast algorithm
       - Low memory requirement
       - Good *perceptual* quality (and not best SNR)
 
    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are
    met:
@@ -38,28 +38,28 @@
 
 #ifndef SPEEX_RESAMPLER_H
 #define SPEEX_RESAMPLER_H
 
 #if 1 /* OUTSIDE_SPEEX */
 
 /********* WARNING: MENTAL SANITY ENDS HERE *************/
 
-/* If the resampler is defined outside of Speex, we change the symbol names so that 
+/* If the resampler is defined outside of Speex, we change the symbol names so that
    there won't be any clash if linking with Speex later on. */
 
 /* #define RANDOM_PREFIX your software name here */
 #define RANDOM_PREFIX moz_speex
 #ifndef RANDOM_PREFIX
 #error "Please define RANDOM_PREFIX (above) to something specific to your project to prevent symbol name clashes"
 #endif
 
 #define CAT_PREFIX2(a,b) a ## b
 #define CAT_PREFIX(a,b) CAT_PREFIX2(a, b)
-      
+
 #define speex_resampler_init CAT_PREFIX(RANDOM_PREFIX,_resampler_init)
 #define speex_resampler_init_frac CAT_PREFIX(RANDOM_PREFIX,_resampler_init_frac)
 #define speex_resampler_destroy CAT_PREFIX(RANDOM_PREFIX,_resampler_destroy)
 #define speex_resampler_process_float CAT_PREFIX(RANDOM_PREFIX,_resampler_process_float)
 #define speex_resampler_process_int CAT_PREFIX(RANDOM_PREFIX,_resampler_process_int)
 #define speex_resampler_process_interleaved_float CAT_PREFIX(RANDOM_PREFIX,_resampler_process_interleaved_float)
 #define speex_resampler_process_interleaved_int CAT_PREFIX(RANDOM_PREFIX,_resampler_process_interleaved_int)
 #define speex_resampler_set_rate CAT_PREFIX(RANDOM_PREFIX,_resampler_set_rate)
@@ -78,17 +78,19 @@
 #define speex_resampler_set_skip_frac_num CAT_PREFIX(RANDOM_PREFIX,_resampler_set_skip_frac_num)
 #define speex_resampler_reset_mem CAT_PREFIX(RANDOM_PREFIX,_resampler_reset_mem)
 #define speex_resampler_strerror CAT_PREFIX(RANDOM_PREFIX,_resampler_strerror)
 
 #define spx_int16_t short
 #define spx_int32_t int
 #define spx_uint16_t unsigned short
 #define spx_uint32_t unsigned int
-      
+
+#define speex_assert(cond)
+
 #else /* OUTSIDE_SPEEX */
 
 #include "speexdsp_types.h"
 
 #endif /* OUTSIDE_SPEEX */
 
 #ifdef __cplusplus
 extern "C" {
@@ -118,210 +120,210 @@ typedef struct SpeexResamplerState_ Spee
  * @param nb_channels Number of channels to be processed
  * @param in_rate Input sampling rate (integer number of Hz).
  * @param out_rate Output sampling rate (integer number of Hz).
  * @param quality Resampling quality between 0 and 10, where 0 has poor quality
  * and 10 has very high quality.
  * @return Newly created resampler state
  * @retval NULL Error: not enough memory
  */
-SpeexResamplerState *speex_resampler_init(spx_uint32_t nb_channels, 
-                                          spx_uint32_t in_rate, 
-                                          spx_uint32_t out_rate, 
+SpeexResamplerState *speex_resampler_init(spx_uint32_t nb_channels,
+                                          spx_uint32_t in_rate,
+                                          spx_uint32_t out_rate,
                                           int quality,
                                           int *err);
 
-/** Create a new resampler with fractional input/output rates. The sampling 
- * rate ratio is an arbitrary rational number with both the numerator and 
+/** Create a new resampler with fractional input/output rates. The sampling
+ * rate ratio is an arbitrary rational number with both the numerator and
  * denominator being 32-bit integers.
  * @param nb_channels Number of channels to be processed
  * @param ratio_num Numerator of the sampling rate ratio
  * @param ratio_den Denominator of the sampling rate ratio
  * @param in_rate Input sampling rate rounded to the nearest integer (in Hz).
  * @param out_rate Output sampling rate rounded to the nearest integer (in Hz).
  * @param quality Resampling quality between 0 and 10, where 0 has poor quality
  * and 10 has very high quality.
  * @return Newly created resampler state
  * @retval NULL Error: not enough memory
  */
-SpeexResamplerState *speex_resampler_init_frac(spx_uint32_t nb_channels, 
-                                               spx_uint32_t ratio_num, 
-                                               spx_uint32_t ratio_den, 
-                                               spx_uint32_t in_rate, 
-                                               spx_uint32_t out_rate, 
+SpeexResamplerState *speex_resampler_init_frac(spx_uint32_t nb_channels,
+                                               spx_uint32_t ratio_num,
+                                               spx_uint32_t ratio_den,
+                                               spx_uint32_t in_rate,
+                                               spx_uint32_t out_rate,
                                                int quality,
                                                int *err);
 
 /** Destroy a resampler state.
  * @param st Resampler state
  */
 void speex_resampler_destroy(SpeexResamplerState *st);
 
 /** Resample a float array. The input and output buffers must *not* overlap.
  * @param st Resampler state
- * @param channel_index Index of the channel to process for the multi-channel 
+ * @param channel_index Index of the channel to process for the multi-channel
  * base (0 otherwise)
  * @param in Input buffer
- * @param in_len Number of input samples in the input buffer. Returns the 
+ * @param in_len Number of input samples in the input buffer. Returns the
  * number of samples processed
  * @param out Output buffer
  * @param out_len Size of the output buffer. Returns the number of samples written
  */
-int speex_resampler_process_float(SpeexResamplerState *st, 
-                                   spx_uint32_t channel_index, 
-                                   const float *in, 
-                                   spx_uint32_t *in_len, 
-                                   float *out, 
+int speex_resampler_process_float(SpeexResamplerState *st,
+                                   spx_uint32_t channel_index,
+                                   const float *in,
+                                   spx_uint32_t *in_len,
+                                   float *out,
                                    spx_uint32_t *out_len);
 
 /** Resample an int array. The input and output buffers must *not* overlap.
  * @param st Resampler state
- * @param channel_index Index of the channel to process for the multi-channel 
+ * @param channel_index Index of the channel to process for the multi-channel
  * base (0 otherwise)
  * @param in Input buffer
  * @param in_len Number of input samples in the input buffer. Returns the number
  * of samples processed
  * @param out Output buffer
  * @param out_len Size of the output buffer. Returns the number of samples written
  */
-int speex_resampler_process_int(SpeexResamplerState *st, 
-                                 spx_uint32_t channel_index, 
-                                 const spx_int16_t *in, 
-                                 spx_uint32_t *in_len, 
-                                 spx_int16_t *out, 
+int speex_resampler_process_int(SpeexResamplerState *st,
+                                 spx_uint32_t channel_index,
+                                 const spx_int16_t *in,
+                                 spx_uint32_t *in_len,
+                                 spx_int16_t *out,
                                  spx_uint32_t *out_len);
 
 /** Resample an interleaved float array. The input and output buffers must *not* overlap.
  * @param st Resampler state
  * @param in Input buffer
  * @param in_len Number of input samples in the input buffer. Returns the number
  * of samples processed. This is all per-channel.
  * @param out Output buffer
  * @param out_len Size of the output buffer. Returns the number of samples written.
  * This is all per-channel.
  */
-int speex_resampler_process_interleaved_float(SpeexResamplerState *st, 
-                                               const float *in, 
-                                               spx_uint32_t *in_len, 
-                                               float *out, 
+int speex_resampler_process_interleaved_float(SpeexResamplerState *st,
+                                               const float *in,
+                                               spx_uint32_t *in_len,
+                                               float *out,
                                                spx_uint32_t *out_len);
 
 /** Resample an interleaved int array. The input and output buffers must *not* overlap.
  * @param st Resampler state
  * @param in Input buffer
  * @param in_len Number of input samples in the input buffer. Returns the number
  * of samples processed. This is all per-channel.
  * @param out Output buffer
  * @param out_len Size of the output buffer. Returns the number of samples written.
  * This is all per-channel.
  */
-int speex_resampler_process_interleaved_int(SpeexResamplerState *st, 
-                                             const spx_int16_t *in, 
-                                             spx_uint32_t *in_len, 
-                                             spx_int16_t *out, 
+int speex_resampler_process_interleaved_int(SpeexResamplerState *st,
+                                             const spx_int16_t *in,
+                                             spx_uint32_t *in_len,
+                                             spx_int16_t *out,
                                              spx_uint32_t *out_len);
 
 /** Set (change) the input/output sampling rates (integer value).
  * @param st Resampler state
  * @param in_rate Input sampling rate (integer number of Hz).
  * @param out_rate Output sampling rate (integer number of Hz).
  */
-int speex_resampler_set_rate(SpeexResamplerState *st, 
-                              spx_uint32_t in_rate, 
+int speex_resampler_set_rate(SpeexResamplerState *st,
+                              spx_uint32_t in_rate,
                               spx_uint32_t out_rate);
 
 /** Get the current input/output sampling rates (integer value).
  * @param st Resampler state
  * @param in_rate Input sampling rate (integer number of Hz) copied.
  * @param out_rate Output sampling rate (integer number of Hz) copied.
  */
-void speex_resampler_get_rate(SpeexResamplerState *st, 
-                              spx_uint32_t *in_rate, 
+void speex_resampler_get_rate(SpeexResamplerState *st,
+                              spx_uint32_t *in_rate,
                               spx_uint32_t *out_rate);
 
-/** Set (change) the input/output sampling rates and resampling ratio 
+/** Set (change) the input/output sampling rates and resampling ratio
  * (fractional values in Hz supported).
  * @param st Resampler state
  * @param ratio_num Numerator of the sampling rate ratio
  * @param ratio_den Denominator of the sampling rate ratio
  * @param in_rate Input sampling rate rounded to the nearest integer (in Hz).
  * @param out_rate Output sampling rate rounded to the nearest integer (in Hz).
  */
-int speex_resampler_set_rate_frac(SpeexResamplerState *st, 
-                                   spx_uint32_t ratio_num, 
-                                   spx_uint32_t ratio_den, 
-                                   spx_uint32_t in_rate, 
+int speex_resampler_set_rate_frac(SpeexResamplerState *st,
+                                   spx_uint32_t ratio_num,
+                                   spx_uint32_t ratio_den,
+                                   spx_uint32_t in_rate,
                                    spx_uint32_t out_rate);
 
 /** Get the current resampling ratio. This will be reduced to the least
  * common denominator.
  * @param st Resampler state
  * @param ratio_num Numerator of the sampling rate ratio copied
  * @param ratio_den Denominator of the sampling rate ratio copied
  */
-void speex_resampler_get_ratio(SpeexResamplerState *st, 
-                               spx_uint32_t *ratio_num, 
+void speex_resampler_get_ratio(SpeexResamplerState *st,
+                               spx_uint32_t *ratio_num,
                                spx_uint32_t *ratio_den);
 
 /** Set (change) the conversion quality.
  * @param st Resampler state
- * @param quality Resampling quality between 0 and 10, where 0 has poor 
+ * @param quality Resampling quality between 0 and 10, where 0 has poor
  * quality and 10 has very high quality.
  */
-int speex_resampler_set_quality(SpeexResamplerState *st, 
+int speex_resampler_set_quality(SpeexResamplerState *st,
                                  int quality);
 
 /** Get the conversion quality.
  * @param st Resampler state
- * @param quality Resampling quality between 0 and 10, where 0 has poor 
+ * @param quality Resampling quality between 0 and 10, where 0 has poor
  * quality and 10 has very high quality.
  */
-void speex_resampler_get_quality(SpeexResamplerState *st, 
+void speex_resampler_get_quality(SpeexResamplerState *st,
                                  int *quality);
 
 /** Set (change) the input stride.
  * @param st Resampler state
  * @param stride Input stride
  */
-void speex_resampler_set_input_stride(SpeexResamplerState *st, 
+void speex_resampler_set_input_stride(SpeexResamplerState *st,
                                       spx_uint32_t stride);
 
 /** Get the input stride.
  * @param st Resampler state
  * @param stride Input stride copied
  */
-void speex_resampler_get_input_stride(SpeexResamplerState *st, 
+void speex_resampler_get_input_stride(SpeexResamplerState *st,
                                       spx_uint32_t *stride);
 
 /** Set (change) the output stride.
  * @param st Resampler state
  * @param stride Output stride
  */
-void speex_resampler_set_output_stride(SpeexResamplerState *st, 
+void speex_resampler_set_output_stride(SpeexResamplerState *st,
                                       spx_uint32_t stride);
 
 /** Get the output stride.
  * @param st Resampler state copied
  * @param stride Output stride
  */
-void speex_resampler_get_output_stride(SpeexResamplerState *st, 
+void speex_resampler_get_output_stride(SpeexResamplerState *st,
                                       spx_uint32_t *stride);
 
 /** Get the latency introduced by the resampler measured in input samples.
  * @param st Resampler state
  */
 int speex_resampler_get_input_latency(SpeexResamplerState *st);
 
 /** Get the latency introduced by the resampler measured in output samples.
  * @param st Resampler state
  */
 int speex_resampler_get_output_latency(SpeexResamplerState *st);
 
-/** Make sure that the first samples to go out of the resamplers don't have 
- * leading zeros. This is only useful before starting to use a newly created 
+/** Make sure that the first samples to go out of the resamplers don't have
+ * leading zeros. This is only useful before starting to use a newly created
  * resampler. It is recommended to use that when resampling an audio file, as
  * it will generate a file with the same length. For real-time processing,
  * it is probably easier not to use this call (so that the output duration
  * is the same for the first frame).
  * @param st Resampler state
  */
 int speex_resampler_skip_zeros(SpeexResamplerState *st);
 
--- a/media/libspeex_resampler/src/stack_alloc.h
+++ b/media/libspeex_resampler/src/stack_alloc.h
@@ -2,28 +2,28 @@
 /**
    @file stack_alloc.h
    @brief Temporary memory allocation on stack
 */
 /*
    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions
    are met:
-   
+
    - Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
-   
+
    - Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
-   
+
    - Neither the name of the Xiph.org Foundation nor the names of its
    contributors may be used to endorse or promote products derived from
    this software without specific prior written permission.
-   
+
    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
    CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
@@ -96,17 +96,17 @@
 
 #define ALIGN(stack, size) ((stack) += ((size) - (long)(stack)) & ((size) - 1))
 
 #define PUSH(stack, size, type) (ALIGN((stack),sizeof(type)),(stack)+=((size)*sizeof(type)),(type*)((stack)-((size)*sizeof(type))))
 
 #endif
 
 #if defined(VAR_ARRAYS)
-#define VARDECL(var) 
+#define VARDECL(var)
 #define ALLOC(var, size, type) type var[size]
 #elif defined(USE_ALLOCA)
 #define VARDECL(var) var
 #define ALLOC(var, size, type) var = alloca(sizeof(type)*(size))
 #else
 #define VARDECL(var) var
 #define ALLOC(var, size, type) var = PUSH(stack, size, type)
 #endif
--- a/media/libspeex_resampler/update.sh
+++ b/media/libspeex_resampler/update.sh
@@ -20,11 +20,9 @@ cp $1/AUTHORS .
 cp $1/COPYING .
 
 # apply outstanding local patches
 patch -p3 < outside-speex.patch
 patch -p3 < simd-detect-runtime.patch
 patch -p3 < set-skip-frac.patch
 patch -p3 < hugemem.patch
 patch -p3 < remove-empty-asm-clobber.patch
-patch -p3 < handle-memory-error.patch
-patch -p3 < fix-overflow.patch
 patch -p3 < set-rate-overflow-no-return.patch