Backed out 2 changesets (bug 1285541) for causing a frequent mda failure
authorWes Kocher <wkocher@mozilla.com>
Fri, 08 Jul 2016 15:21:43 -0700
changeset 304263 6b82281bc9275e8961c11760624c781c99f0a497
parent 304262 14b16ac3899119428c9c434d4e4e2c75f7a1e5f7
child 304264 4548ba932bde3067a722b267f9b1e43256740d4e
push id79281
push userkwierso@gmail.com
push dateFri, 08 Jul 2016 22:21:49 +0000
treeherdermozilla-inbound@6b82281bc927 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1285541
milestone50.0a1
backs out53ac5a12a19b1243e8df3b68de2183a0d853eec0
aea13acdf417e8178e731645bc1701163d191ee5
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
Backed out 2 changesets (bug 1285541) for causing a frequent mda failure Backed out changeset 53ac5a12a19b (bug 1285541) Backed out changeset aea13acdf417 (bug 1285541)
CLOBBER
media/libcubeb/README_MOZILLA
media/libcubeb/src/cubeb_audiounit.c
media/libcubeb/src/cubeb_audiounit.cpp
media/libcubeb/src/cubeb_osx_run_loop.h
media/libcubeb/src/cubeb_resampler_internal.h
media/libcubeb/src/cubeb_ring_array.h
media/libcubeb/src/moz.build
media/libcubeb/update.sh
--- a/CLOBBER
+++ b/CLOBBER
@@ -17,9 +17,9 @@
 #
 # Modifying this file will now automatically clobber the buildbot machines \o/
 #
 
 # Are you updating CLOBBER because you think it's needed for your WebIDL
 # changes to stick? As of bug 928195, this shouldn't be necessary! Please
 # don't change CLOBBER for WebIDL changes any more.
 
-Bug 1285541 - touch clobber to fix bustage
+Bug 1267887 - Build skew after updating rust mp4parse
--- a/media/libcubeb/README_MOZILLA
+++ b/media/libcubeb/README_MOZILLA
@@ -1,8 +1,8 @@
 The source from this directory was copied from the cubeb 
 git repository using the update.sh script.  The only changes
 made were those applied by update.sh and the addition of
 Makefile.in build files for the Mozilla build system.
 
 The cubeb git repository is: git://github.com/kinetiknz/cubeb.git
 
-The git commit ID used was 9d28cd3133bc8f40172ede9897f6755c46526c7b.
+The git commit ID used was b8aebef33a096640d6cbd7a6fa568bccef1b339c.
rename from media/libcubeb/src/cubeb_audiounit.cpp
rename to media/libcubeb/src/cubeb_audiounit.c
--- a/media/libcubeb/src/cubeb_audiounit.cpp
+++ b/media/libcubeb/src/cubeb_audiounit.c
@@ -22,17 +22,16 @@
 #include "cubeb/cubeb.h"
 #include "cubeb-internal.h"
 #include "cubeb_panner.h"
 #if !TARGET_OS_IPHONE
 #include "cubeb_osx_run_loop.h"
 #endif
 #include "cubeb_resampler.h"
 #include "cubeb_ring_array.h"
-#include "cubeb_utils.h"
 
 #if !defined(kCFCoreFoundationVersionNumber10_7)
 /* From CoreFoundation CFBase.h */
 #define kCFCoreFoundationVersionNumber10_7 635.00
 #endif
 
 #if !TARGET_OS_IPHONE && MAC_OS_X_VERSION_MIN_REQUIRED < 1060
 #define AudioComponent Component
@@ -52,29 +51,29 @@ typedef UInt32  AudioFormatFlags;
 #define AU_IN_BUS     1
 
 #if TARGET_OS_IPHONE
 #define CUBEB_AUDIOUNIT_SUBTYPE kAudioUnitSubType_RemoteIO
 #else
 #define CUBEB_AUDIOUNIT_SUBTYPE kAudioUnitSubType_HALOutput
 #endif
 
-// #define LOGGING_ENABLED
+//#define LOGGING_ENABLED
 #ifdef LOGGING_ENABLED
 #define LOG(...) do {                           \
     fprintf(stderr, __VA_ARGS__);               \
   } while(0)
 #else
 #define LOG(...)
 #endif
 
-extern cubeb_ops const audiounit_ops;
+static struct cubeb_ops const audiounit_ops;
 
 struct cubeb {
-  cubeb_ops const * ops;
+  struct cubeb_ops const * ops;
   pthread_mutex_t mutex;
   int active_streams;
   int limit_streams;
   cubeb_device_collection_changed_callback collection_changed_callback;
   void * collection_changed_user_ptr;
   /* Differentiate input from output devices. */
   cubeb_device_type collection_changed_devtype;
   uint32_t devtype_device_count;
@@ -161,17 +160,17 @@ audiounit_make_silent(AudioBuffer * ioDa
 static OSStatus
 audiounit_input_callback(void * user_ptr,
                          AudioUnitRenderActionFlags * flags,
                          AudioTimeStamp const * tstamp,
                          UInt32 bus,
                          UInt32 input_frames,
                          AudioBufferList * bufs)
 {
-  cubeb_stream * stm = static_cast<cubeb_stream *>(user_ptr);
+  cubeb_stream * stm = user_ptr;
   long outframes, frames;
 
   pthread_mutex_lock(&stm->mutex);
 
   assert(stm->input_unit != NULL);
   assert(AU_IN_BUS == bus);
 
   if (stm->shutdown) {
@@ -249,37 +248,33 @@ audiounit_output_callback(void * user_pt
                           AudioTimeStamp const * tstamp,
                           UInt32 bus,
                           UInt32 output_frames,
                           AudioBufferList * outBufferList)
 {
   assert(AU_OUT_BUS == bus);
   assert(outBufferList->mNumberBuffers == 1);
 
-  cubeb_stream * stm = static_cast<cubeb_stream *>(user_ptr);
+  cubeb_stream * stm = user_ptr;
 
   LOG("- output(%p): buffers %d, size %d, channels %d, frames %d\n", stm,
       outBufferList->mNumberBuffers, outBufferList->mBuffers[0].mDataByteSize,
       outBufferList->mBuffers[0].mNumberChannels, output_frames);
 
   long outframes = 0, input_frames = 0;
   void * output_buffer = NULL, * input_buffer = NULL;
 
   pthread_mutex_lock(&stm->mutex);
 
   if (stm->shutdown) {
     audiounit_make_silent(&outBufferList->mBuffers[0]);
     pthread_mutex_unlock(&stm->mutex);
     return noErr;
   }
 
-  LOG("- output(%p): buffers %d, size %d, channels %d, frames %d\n", stm,
-      outBufferList->mNumberBuffers, outBufferList->mBuffers[0].mDataByteSize,
-      outBufferList->mBuffers[0].mNumberChannels, output_frames);
-
   stm->current_latency_frames = audiotimestamp_to_latency(tstamp, stm);
   if (stm->draining) {
     OSStatus r = AudioOutputUnitStop(stm->output_unit);
     assert(r == 0);
     if (stm->input_unit) {
       r = AudioOutputUnitStop(stm->input_unit);
       assert(r == 0);
     }
@@ -288,38 +283,41 @@ audiounit_output_callback(void * user_pt
     audiounit_make_silent(&outBufferList->mBuffers[0]);
     return noErr;
   }
   /* Get output buffer. */
   output_buffer = outBufferList->mBuffers[0].mData;
   /* If Full duplex get also input buffer */
   AudioBuffer * input_aud_buf = NULL;
   if (stm->input_unit != NULL) {
+    /* Output callback came first */
+    if (stm->frames_read == 0) {
+      LOG("Output callback came first send silent.\n");
+      audiounit_make_silent(&outBufferList->mBuffers[0]);
+      pthread_mutex_unlock(&stm->mutex);
+      return noErr;
+    }
     /* Input samples stored previously in input callback. */
     input_aud_buf = ring_array_get_data_buffer(&stm->input_buffer_array);
     if (input_aud_buf == NULL) {
+      LOG("Requested more output than input. "
+             "This is either a hole or we are after a stream stop and input thread stopped before output\n");
       /* Provide silent input. Other than that we could provide silent output and exit without
-       * calling user callback. This is not preferred because the user loose the control of
+       * calling user callback. I do not prefer it because the user loose the control of
        * the output. Also resampler loose frame counting and produce less frame than
        * expected at some point in the future breaking an assert. */
-      LOG("Input hole. Requested more input than existing.\n");
 
       /* Avoid here to allocate new memory since we are inside callback. Use the existing
        * allocated buffers since the ring array is empty and the buffer is not used. */
       input_aud_buf = ring_array_get_dummy_buffer(&stm->input_buffer_array);
-      /* Output callback came first */
-      if (stm->frames_read == 0) {
-        LOG("Output callback came first send silent.\n");
-      }
       audiounit_make_silent(input_aud_buf);
     }
-    // The input buffer
     input_buffer = input_aud_buf->mData;
-    // Number of input frames in the buffer
     input_frames = stm->input_buffer_frames;
+    assert(stm->frames_read > 0);
   }
 
   /* Call user callback through resampler. */
   outframes = cubeb_resampler_fill(stm->resampler,
                                    input_buffer,
                                    input_buffer ? &input_frames : NULL,
                                    output_buffer,
                                    output_frames);
@@ -355,28 +353,26 @@ audiounit_output_callback(void * user_pt
       cubeb_pan_stereo_buffer_float((float*)output_buffer, outframes, panning);
     } else if (outaff & kAudioFormatFlagIsSignedInteger) {
       cubeb_pan_stereo_buffer_int((short*)output_buffer, outframes, panning);
     }
   }
   return noErr;
 }
 
-extern "C" {
-int
+/*static*/ int
 audiounit_init(cubeb ** context, char const * context_name)
 {
   cubeb * ctx;
   int r;
 
   *context = NULL;
 
-  ctx = new cubeb;
+  ctx = calloc(1, sizeof(*ctx));
   assert(ctx);
-  PodZero(ctx, 1);
 
   ctx->ops = &audiounit_ops;
 
   r = pthread_mutex_init(&ctx->mutex, NULL);
   assert(r == 0);
 
   ctx->active_streams = 0;
 
@@ -384,17 +380,16 @@ audiounit_init(cubeb ** context, char co
 #if !TARGET_OS_IPHONE
   cubeb_set_coreaudio_notification_runloop();
 #endif
 
   *context = ctx;
 
   return CUBEB_OK;
 }
-}
 
 static char const *
 audiounit_get_backend_id(cubeb * ctx)
 {
   return "audiounit";
 }
 
 #if !TARGET_OS_IPHONE
@@ -711,17 +706,17 @@ audiounit_get_min_latency(cubeb * ctx, c
   //TODO: [[AVAudioSession sharedInstance] inputLatency]
   return CUBEB_ERROR_NOT_SUPPORTED;
 #else
   AudioValueRange latency_range;
   if (audiounit_get_acceptable_latency_range(&latency_range) != CUBEB_OK) {
     return CUBEB_ERROR;
   }
 
-  *latency_ms = ceil((latency_range.mMinimum * 1000 ) / params.rate);
+  *latency_ms = (latency_range.mMinimum * 1000 + params.rate - 1) / params.rate;
 #endif
 
   return CUBEB_OK;
 }
 
 static int
 audiounit_get_preferred_sample_rate(cubeb * ctx, uint32_t * rate)
 {
@@ -750,17 +745,17 @@ audiounit_get_preferred_sample_rate(cube
                                  NULL,
                                  &size,
                                  &fsamplerate);
 
   if (r != noErr) {
     return CUBEB_ERROR;
   }
 
-  *rate = static_cast<uint32_t>(fsamplerate);
+  *rate = (uint32_t)fsamplerate;
 #endif
   return CUBEB_OK;
 }
 
 static OSStatus audiounit_remove_device_listener(cubeb * context);
 
 static void
 audiounit_destroy(cubeb * ctx)
@@ -773,17 +768,17 @@ audiounit_destroy(cubeb * ctx)
     pthread_mutex_lock(&ctx->mutex);
     audiounit_remove_device_listener(ctx);
     pthread_mutex_unlock(&ctx->mutex);
   }
 
   int r = pthread_mutex_destroy(&ctx->mutex);
   assert(r == 0);
 
-  delete ctx;
+  free(ctx);
 }
 
 static void audiounit_stream_destroy(cubeb_stream * stm);
 
 static int
 audio_stream_desc_init(AudioStreamBasicDescription * ss,
                        const cubeb_stream_params * stream_params)
 {
@@ -862,17 +857,17 @@ audiounit_create_unit(AudioUnit * unit,
         is_input ? AU_OUT_BUS : AU_IN_BUS, &enable, sizeof(UInt32)) != noErr) {
     return CUBEB_ERROR;
   }
 
   if (device == NULL) {
     devid = audiounit_get_default_device_id(is_input ? CUBEB_DEVICE_TYPE_INPUT
                                                      : CUBEB_DEVICE_TYPE_OUTPUT);
   } else {
-    devid = *(static_cast<AudioDeviceID*>(device));
+    devid = (AudioDeviceID)device;
   }
   int err = AudioUnitSetProperty(*unit, kAudioOutputUnitProperty_CurrentDevice,
                                  kAudioUnitScope_Global,
                                  is_input ? AU_IN_BUS : AU_OUT_BUS,
                                  &devid, sizeof(AudioDeviceID));
   if (err != noErr) {
     return CUBEB_ERROR;
   }
@@ -945,19 +940,18 @@ audiounit_stream_init(cubeb * context,
                               output_stream_params,
                               output_device);
     if (r != CUBEB_OK) {
       LOG("Create output stream failed\n");
       return r;
     }
   }
 
-  stm = new cubeb_stream;
+  stm = calloc(1, sizeof(cubeb_stream));
   assert(stm);
-  PodZero(stm, 1);
 
   /* These could be different in the future if we have both
    * full-duplex stream and different devices for input vs output. */
   stm->input_unit  = (input_stream_params != NULL) ? input_unit : NULL;
   stm->output_unit = (output_stream_params != NULL) ? output_unit : NULL;
   stm->context = context;
   stm->data_callback = data_callback;
   stm->state_callback = state_callback;
@@ -971,16 +965,37 @@ audiounit_stream_init(cubeb * context,
   assert(r == 0);
   pthread_mutexattr_destroy(&attr);
 
   /* Init data members where necessary */
   stm->hw_latency_frames = UINT64_MAX;
 
   /* Setup Input Stream! */
   if (input_stream_params != NULL) {
+    size = sizeof(UInt32);
+    if (AudioUnitGetProperty(stm->input_unit,
+                             kAudioDevicePropertyBufferFrameSize,
+                             kAudioUnitScope_Input,
+                             AU_IN_BUS,
+                             &stm->input_buffer_frames,
+                             &size) != 0) {
+      audiounit_stream_destroy(stm);
+      return CUBEB_ERROR;
+    }
+
+    if (AudioUnitSetProperty(stm->input_unit,
+                             kAudioDevicePropertyBufferFrameSize,
+                             kAudioUnitScope_Output,
+                             AU_IN_BUS,
+                             &stm->input_buffer_frames,
+                             size) != 0) {
+      audiounit_stream_destroy(stm);
+      return CUBEB_ERROR;
+    }
+
     /* Get input device sample rate. */
     AudioStreamBasicDescription input_hw_desc;
     size = sizeof(AudioStreamBasicDescription);
     if (AudioUnitGetProperty(stm->input_unit,
                              kAudioUnitProperty_StreamFormat,
                              kAudioUnitScope_Input,
                              AU_IN_BUS,
                              &input_hw_desc,
@@ -992,29 +1007,16 @@ audiounit_stream_init(cubeb * context,
 
     /* Set format description according to the input params. */
     r = audio_stream_desc_init(&stm->input_desc, input_stream_params);
     if (r != CUBEB_OK) {
       audiounit_stream_destroy(stm);
       return r;
     }
 
-    // Use latency to calculate buffer size
-    stm->input_buffer_frames = (latency / 1000.0) * stm->input_hw_rate;
-    LOG("Calculated input number of frames %u for latency %u\n", stm->input_buffer_frames, latency);
-    if (AudioUnitSetProperty(stm->input_unit,
-                             kAudioDevicePropertyBufferFrameSize,
-                             kAudioUnitScope_Output,
-                             AU_IN_BUS,
-                             &stm->input_buffer_frames,
-                             sizeof(UInt32)) != 0) {
-      audiounit_stream_destroy(stm);
-      return CUBEB_ERROR;
-    }
-
     AudioStreamBasicDescription src_desc = stm->input_desc;
     /* Input AudioUnit must be configured with device's sample rate.
        we will resample inside input callback. */
     src_desc.mSampleRate = stm->input_hw_rate;
 
     if (AudioUnitSetProperty(stm->input_unit,
                              kAudioUnitProperty_StreamFormat,
                              kAudioUnitScope_Output,
@@ -1065,55 +1067,26 @@ audiounit_stream_init(cubeb * context,
   /* Setup Output Stream! */
   if (output_stream_params != NULL) {
     r = audio_stream_desc_init(&stm->output_desc, output_stream_params);
     if (r != CUBEB_OK) {
       audiounit_stream_destroy(stm);
       return r;
     }
 
-    /* Get output device sample rate. */
-    AudioStreamBasicDescription output_hw_desc;
-    size = sizeof(AudioStreamBasicDescription);
-    memset(&output_hw_desc, 0, size);
-    if (AudioUnitGetProperty(stm->output_unit,
-                             kAudioUnitProperty_StreamFormat,
-                             kAudioUnitScope_Output,
-                             AU_OUT_BUS,
-                             &output_hw_desc,
-                             &size) != 0) {
-      audiounit_stream_destroy(stm);
-      return CUBEB_ERROR;
-    }
-
     if (AudioUnitSetProperty(stm->output_unit,
                              kAudioUnitProperty_StreamFormat,
                              kAudioUnitScope_Input,
                              AU_OUT_BUS,
                              &stm->output_desc,
                              sizeof(AudioStreamBasicDescription)) != 0) {
       audiounit_stream_destroy(stm);
       return CUBEB_ERROR;
     }
 
-    // Use latency to set number of frames in out buffer. Use the
-    // device sampling rate, internal resampler of audiounit will
-    // calculate the expected number of frames.
-    uint32_t output_buffer_frames = (latency / 1000.0) * output_hw_desc.mSampleRate;
-    LOG("Calculated output number of frames %u for latency %u\n", output_buffer_frames, latency);
-    if (AudioUnitSetProperty(stm->output_unit,
-                             kAudioDevicePropertyBufferFrameSize,
-                             kAudioUnitScope_Input,
-                             AU_OUT_BUS,
-                             &output_buffer_frames,
-                             sizeof(output_buffer_frames)) != 0) {
-      audiounit_stream_destroy(stm);
-      return CUBEB_ERROR;
-    }
-
     assert(stm->output_unit != NULL);
     aurcbs_out.inputProc = audiounit_output_callback;
     aurcbs_out.inputProcRefCon = stm;
     if (AudioUnitSetProperty(stm->output_unit,
                              kAudioUnitProperty_SetRenderCallback,
                              kAudioUnitScope_Global,
                              AU_OUT_BUS,
                              &aurcbs_out,
@@ -1247,17 +1220,17 @@ audiounit_stream_destroy(cubeb_stream * 
   int r = pthread_mutex_destroy(&stm->mutex);
   assert(r == 0);
 
   pthread_mutex_lock(&stm->context->mutex);
   assert(stm->context->active_streams >= 1);
   stm->context->active_streams -= 1;
   pthread_mutex_unlock(&stm->context->mutex);
 
-  delete stm;
+  free(stm);
 }
 
 static int
 audiounit_stream_start(cubeb_stream * stm)
 {
   pthread_mutex_lock(&stm->context->mutex);
   stm->shutdown = 0;
   stm->draining = 0;
@@ -1369,17 +1342,17 @@ audiounit_stream_get_latency(cubeb_strea
                                    &device_safety_offset);
     if (r != noErr) {
       pthread_mutex_unlock(&stm->mutex);
       return CUBEB_ERROR;
     }
 
     /* This part is fixed and depend on the stream parameter and the hardware. */
     stm->hw_latency_frames =
-      static_cast<uint32_t>(unit_latency_sec * stm->output_desc.mSampleRate)
+      (uint32_t)(unit_latency_sec * stm->output_desc.mSampleRate)
       + device_latency_frames
       + device_safety_offset;
   }
 
   *latency = stm->hw_latency_frames + stm->current_latency_frames;
   pthread_mutex_unlock(&stm->mutex);
 
   return CUBEB_OK;
@@ -1441,33 +1414,37 @@ int audiounit_stream_get_current_device(
   };
 
   *device = NULL;
 
   if (audiounit_get_output_device_id(&output_device_id) != CUBEB_OK) {
     return CUBEB_ERROR;
   }
 
-  *device = new cubeb_device;
+  *device = malloc(sizeof(cubeb_device));
   if (!*device) {
     return CUBEB_ERROR;
   }
-  PodZero(*device, 1);
 
   size = sizeof(UInt32);
   /* This fails with some USB headset, so simply return an empty string. */
   r = AudioObjectGetPropertyData(output_device_id,
                                  &datasource_address,
                                  0, NULL, &size, &data);
   if (r != noErr) {
     size = 0;
     data = 0;
   }
 
-  (*device)->output_name = new char[size + 1];
+  (*device)->output_name = malloc(size + 1);
+  if (!(*device)->output_name) {
+    return CUBEB_ERROR;
+  }
+
+  (*device)->output_name = malloc(size + 1);
   if (!(*device)->output_name) {
     return CUBEB_ERROR;
   }
 
   // Turn the four chars packed into a uint32 into a string
   strdata[0] = (char)(data >> 24);
   strdata[1] = (char)(data >> 16);
   strdata[2] = (char)(data >> 8);
@@ -1483,17 +1460,17 @@ int audiounit_stream_get_current_device(
   size = sizeof(UInt32);
   r = AudioObjectGetPropertyData(input_device_id, &datasource_address_input, 0, NULL, &size, &data);
   if (r != noErr) {
     LOG("Error when getting device !\n");
     size = 0;
     data = 0;
   }
 
-  (*device)->input_name = new char[size + 1];
+  (*device)->input_name = malloc(size + 1);
   if (!(*device)->input_name) {
     return CUBEB_ERROR;
   }
 
   // Turn the four chars packed into a uint32 into a string
   strdata[0] = (char)(data >> 24);
   strdata[1] = (char)(data >> 16);
   strdata[2] = (char)(data >> 8);
@@ -1504,19 +1481,19 @@ int audiounit_stream_get_current_device(
 
   return CUBEB_OK;
 #endif
 }
 
 int audiounit_stream_device_destroy(cubeb_stream * stream,
                                     cubeb_device * device)
 {
-  delete [] device->output_name;
-  delete [] device->input_name;
-  delete device;
+  free(device->output_name);
+  free(device->input_name);
+  free(device);
   return CUBEB_OK;
 }
 
 int audiounit_stream_register_device_changed_callback(cubeb_stream * stream,
                                                       cubeb_device_changed_callback  device_changed_callback)
 {
   /* Note: second register without unregister first causes 'nope' error.
    * Current implementation requires unregister before register a new cb. */
@@ -1546,27 +1523,27 @@ audiounit_get_devices(AudioObjectID ** d
                                      kAudioObjectPropertyScopeGlobal,
                                      kAudioObjectPropertyElementMaster };
 
   ret = AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &adr, 0, NULL, &size);
   if (ret != noErr) {
     return ret;
   }
 
-  *count = static_cast<uint32_t>(size / sizeof(AudioObjectID));
+  *count = (uint32_t)(size / sizeof(AudioObjectID));
   if (size >= sizeof(AudioObjectID)) {
     if (*devices != NULL) {
-      delete [] (*devices);
+      free(*devices);
     }
-    *devices = new AudioObjectID[*count];
-    PodZero(*devices, *count);
+    *devices = malloc(size);
+    memset(*devices, 0, size);
 
     ret = AudioObjectGetPropertyData(kAudioObjectSystemObject, &adr, 0, NULL, &size, (void *)*devices);
     if (ret != noErr) {
-      delete [] (*devices);
+      free(*devices);
       *devices = NULL;
     }
   } else {
     *devices = NULL;
     ret = -1;
   }
 
   return ret;
@@ -1578,37 +1555,37 @@ audiounit_strref_to_cstr_utf8(CFStringRe
   CFIndex len, size;
   char * ret;
   if (strref == NULL) {
     return NULL;
   }
 
   len = CFStringGetLength(strref);
   size = CFStringGetMaximumSizeForEncoding(len, kCFStringEncodingUTF8);
-  ret = new char[size];
+  ret = malloc(size);
 
   if (!CFStringGetCString(strref, ret, size, kCFStringEncodingUTF8)) {
-    delete [] ret;
+    free(ret);
     ret = NULL;
   }
 
   return ret;
 }
 
 static uint32_t
 audiounit_get_channel_count(AudioObjectID devid, AudioObjectPropertyScope scope)
 {
   AudioObjectPropertyAddress adr = { 0, scope, kAudioObjectPropertyElementMaster };
   UInt32 size = 0;
   uint32_t i, ret = 0;
 
   adr.mSelector = kAudioDevicePropertyStreamConfiguration;
 
   if (AudioObjectGetPropertyDataSize(devid, &adr, 0, NULL, &size) == noErr && size > 0) {
-    AudioBufferList * list = static_cast<AudioBufferList *>(alloca(size));
+    AudioBufferList * list = alloca(size);
     if (AudioObjectGetPropertyData(devid, &adr, 0, NULL, &size, list) == noErr) {
       for (i = 0; i < list->mNumberBuffers; i++)
         ret += list->mBuffers[i].mNumberChannels;
     }
   }
 
   return ret;
 }
@@ -1629,30 +1606,30 @@ audiounit_get_available_samplerate(Audio
   }
 
   adr.mSelector = kAudioDevicePropertyAvailableNominalSampleRates;
   UInt32 size = 0;
   AudioValueRange range;
   if (AudioObjectHasProperty(devid, &adr) &&
       AudioObjectGetPropertyDataSize(devid, &adr, 0, NULL, &size) == noErr) {
     uint32_t i, count = size / sizeof(AudioValueRange);
-    AudioValueRange * ranges = new AudioValueRange[count];
+    AudioValueRange * ranges = malloc(size);
     range.mMinimum = 9999999999.0;
     range.mMaximum = 0.0;
     if (AudioObjectGetPropertyData(devid, &adr, 0, NULL, &size, ranges) == noErr) {
       for (i = 0; i < count; i++) {
         if (ranges[i].mMaximum > range.mMaximum)
           range.mMaximum = ranges[i].mMaximum;
         if (ranges[i].mMinimum < range.mMinimum)
           range.mMinimum = ranges[i].mMinimum;
       }
     }
-    delete [] ranges;
-    *max = static_cast<uint32_t>(range.mMaximum);
-    *min = static_cast<uint32_t>(range.mMinimum);
+    free(ranges);
+    *max = (uint32_t)range.mMaximum;
+    *min = (uint32_t)range.mMinimum;
   } else {
     *min = *max = 0;
   }
 
 }
 
 static UInt32
 audiounit_get_device_presentation_latency(AudioObjectID devid, AudioObjectPropertyScope scope)
@@ -1701,18 +1678,17 @@ audiounit_create_device_from_hwdev(Audio
     return NULL;
   }
 
   ch = audiounit_get_channel_count(devid, adr.mScope);
   if (ch == 0) {
     return NULL;
   }
 
-  ret = new cubeb_device_info;
-  PodZero(ret, 1);
+  ret = calloc(1, sizeof(cubeb_device_info));
 
   size = sizeof(CFStringRef);
   adr.mSelector = kAudioDevicePropertyDeviceUID;
   if (AudioObjectGetPropertyData(devid, &adr, 0, NULL, &size, &str) == noErr && str != NULL) {
     ret->device_id = audiounit_strref_to_cstr_utf8(str);
     ret->devid = (cubeb_devid)(size_t)devid;
     ret->group_id = strdup(ret->device_id);
     CFRelease(str);
@@ -1752,17 +1728,17 @@ audiounit_create_device_from_hwdev(Audio
   }
 
   ret->type = type;
   ret->state = CUBEB_DEVICE_STATE_ENABLED;
   ret->preferred = (devid == audiounit_get_default_device_id(type)) ?
     CUBEB_DEVICE_PREF_ALL : CUBEB_DEVICE_PREF_NONE;
 
   ret->max_channels = ch;
-  ret->format = (cubeb_device_fmt)CUBEB_DEVICE_FMT_ALL; /* CoreAudio supports All! */
+  ret->format = CUBEB_DEVICE_FMT_ALL; /* CoreAudio supports All! */
   /* kAudioFormatFlagsAudioUnitCanonical is deprecated, prefer floating point */
   ret->default_format = CUBEB_DEVICE_FMT_F32NE;
   audiounit_get_available_samplerate(devid, adr.mScope,
       &ret->min_rate, &ret->max_rate, &ret->default_rate);
 
   latency = audiounit_get_device_presentation_latency(devid, adr.mScope);
 
   adr.mSelector = kAudioDevicePropertyBufferFrameSizeRange;
@@ -1785,18 +1761,18 @@ audiounit_enumerate_devices(cubeb * cont
   AudioObjectID * hwdevs = NULL;
   uint32_t i, hwdevcount = 0;
   OSStatus err;
 
   if ((err = audiounit_get_devices(&hwdevs, &hwdevcount)) != noErr) {
     return CUBEB_ERROR;
   }
 
-  *collection = static_cast<cubeb_device_collection *>(malloc(sizeof(cubeb_device_collection) +
-      sizeof(cubeb_device_info*) * (hwdevcount > 0 ? hwdevcount - 1 : 0)));
+  *collection = malloc(sizeof(cubeb_device_collection) +
+      sizeof(cubeb_device_info*) * (hwdevcount > 0 ? hwdevcount - 1 : 0));
   (*collection)->count = 0;
 
   if (hwdevcount > 0) {
     cubeb_device_info * cur;
 
     if (type & CUBEB_DEVICE_TYPE_OUTPUT) {
       for (i = 0; i < hwdevcount; i++) {
         if ((cur = audiounit_create_device_from_hwdev(hwdevs[i], CUBEB_DEVICE_TYPE_OUTPUT)) != NULL)
@@ -1807,17 +1783,17 @@ audiounit_enumerate_devices(cubeb * cont
     if (type & CUBEB_DEVICE_TYPE_INPUT) {
       for (i = 0; i < hwdevcount; i++) {
         if ((cur = audiounit_create_device_from_hwdev(hwdevs[i], CUBEB_DEVICE_TYPE_INPUT)) != NULL)
           (*collection)->device[(*collection)->count++] = cur;
       }
     }
   }
 
-  delete [] hwdevs;
+  free(hwdevs);
 
   return CUBEB_OK;
 }
 
 /* qsort compare method. */
 int compare_devid(const void * a, const void * b)
 {
   return (*(AudioObjectID*)a - *(AudioObjectID*)b);
@@ -1844,17 +1820,17 @@ audiounit_get_devices_of_type(cubeb_devi
   if (ret != noErr) {
     return 0;
   }
   /* Expected sorted but did not find anything in the docs. */
   qsort(devices, count, sizeof(AudioObjectID), compare_devid);
 
   if (devtype == (CUBEB_DEVICE_TYPE_INPUT | CUBEB_DEVICE_TYPE_OUTPUT)) {
     if (devid_array) {
-      *devid_array = new AudioObjectID[count];
+      *devid_array = calloc(count, sizeof(AudioObjectID));
       assert(*devid_array);
       memcpy(*devid_array, &devices, count * sizeof(AudioObjectID));
     }
     return count;
   }
 
   AudioObjectPropertyScope scope = (devtype == CUBEB_DEVICE_TYPE_INPUT) ?
                                          kAudioDevicePropertyScopeInput :
@@ -1866,17 +1842,17 @@ audiounit_get_devices_of_type(cubeb_devi
     /* For device in the given scope channel must be > 0. */
     if (audiounit_get_channel_count(devices[i], scope) > 0) {
       devices_in_scope[dev_count] = devices[i];
       ++dev_count;
     }
   }
 
   if (devid_array && dev_count > 0) {
-    *devid_array = static_cast<AudioObjectID *>(calloc(dev_count, sizeof(AudioObjectID)));
+    *devid_array = calloc(dev_count, sizeof(AudioObjectID));
     assert(*devid_array);
     memcpy(*devid_array, &devices_in_scope, dev_count * sizeof(AudioObjectID));
   }
   return dev_count;
 }
 
 static uint32_t
 audiounit_equal_arrays(AudioObjectID * left, AudioObjectID * right, uint32_t size)
@@ -1891,41 +1867,41 @@ audiounit_equal_arrays(AudioObjectID * l
 }
 
 static OSStatus
 audiounit_collection_changed_callback(AudioObjectID inObjectID,
                                       UInt32 inNumberAddresses,
                                       const AudioObjectPropertyAddress * inAddresses,
                                       void * inClientData)
 {
-  cubeb * context = static_cast<cubeb *>(inClientData);
+  cubeb * context = inClientData;
   pthread_mutex_lock(&context->mutex);
   if (context->collection_changed_callback == NULL) {
     /* Listener removed while waiting in mutex, abort. */
     pthread_mutex_unlock(&context->mutex);
     return noErr;
   }
 
   /* Differentiate input from output changes. */
   if (context->collection_changed_devtype == CUBEB_DEVICE_TYPE_INPUT ||
       context->collection_changed_devtype == CUBEB_DEVICE_TYPE_OUTPUT) {
     AudioObjectID * devices = NULL;
     uint32_t new_number_of_devices = audiounit_get_devices_of_type(context->collection_changed_devtype, &devices);
     /* When count is the same examine the devid for the case of coalescing. */
     if (context->devtype_device_count == new_number_of_devices &&
         audiounit_equal_arrays(devices, context->devtype_device_array, new_number_of_devices)) {
       /* Device changed for the other scope, ignore. */
-      delete [] devices;
+      free(devices);
       pthread_mutex_unlock(&context->mutex);
       return noErr;
     }
     /* Device on desired scope changed, reset counter and array. */
     context->devtype_device_count = new_number_of_devices;
     /* Free the old array before replace. */
-    delete [] context->devtype_device_array;
+    free(context->devtype_device_array);
     context->devtype_device_array = devices;
   }
 
   context->collection_changed_callback(context, context->collection_changed_user_ptr);
   pthread_mutex_unlock(&context->mutex);
   return noErr;
 }
 
@@ -1976,22 +1952,22 @@ audiounit_remove_device_listener(cubeb *
 
   /* Note: unregister a non registered cb is not a problem, not checking. */
   OSStatus ret = AudioObjectRemovePropertyListener(kAudioObjectSystemObject,
                                                    &devAddr,
                                                    audiounit_collection_changed_callback,
                                                    context);
   if (ret == noErr) {
     /* Reset all values. */
-    context->collection_changed_devtype = CUBEB_DEVICE_TYPE_UNKNOWN;
+    context->collection_changed_devtype = 0;
     context->collection_changed_callback = NULL;
     context->collection_changed_user_ptr = NULL;
     context->devtype_device_count = 0;
     if (context->devtype_device_array) {
-      delete [] context->devtype_device_array;
+      free(context->devtype_device_array);
       context->devtype_device_array = NULL;
     }
   }
   return ret;
 }
 
 int audiounit_register_device_collection_changed(cubeb * context,
                                                  cubeb_device_type devtype,
@@ -2006,29 +1982,29 @@ int audiounit_register_device_collection
                                         user_ptr);
   } else {
     ret = audiounit_remove_device_listener(context);
   }
   pthread_mutex_unlock(&context->mutex);
   return (ret == noErr) ? CUBEB_OK : CUBEB_ERROR;
 }
 
-cubeb_ops const audiounit_ops = {
-  /*.init =*/ audiounit_init,
-  /*.get_backend_id =*/ audiounit_get_backend_id,
-  /*.get_max_channel_count =*/ audiounit_get_max_channel_count,
-  /*.get_min_latency =*/ audiounit_get_min_latency,
-  /*.get_preferred_sample_rate =*/ audiounit_get_preferred_sample_rate,
-  /*.enumerate_devices =*/ audiounit_enumerate_devices,
-  /*.destroy =*/ audiounit_destroy,
-  /*.stream_init =*/ audiounit_stream_init,
-  /*.stream_destroy =*/ audiounit_stream_destroy,
-  /*.stream_start =*/ audiounit_stream_start,
-  /*.stream_stop =*/ audiounit_stream_stop,
-  /*.stream_get_position =*/ audiounit_stream_get_position,
-  /*.stream_get_latency =*/ audiounit_stream_get_latency,
-  /*.stream_set_volume =*/ audiounit_stream_set_volume,
-  /*.stream_set_panning =*/ audiounit_stream_set_panning,
-  /*.stream_get_current_device =*/ audiounit_stream_get_current_device,
-  /*.stream_device_destroy =*/ audiounit_stream_device_destroy,
-  /*.stream_register_device_changed_callback =*/ audiounit_stream_register_device_changed_callback,
-  /*.register_device_collection_changed =*/ audiounit_register_device_collection_changed
+static struct cubeb_ops const audiounit_ops = {
+  .init = audiounit_init,
+  .get_backend_id = audiounit_get_backend_id,
+  .get_max_channel_count = audiounit_get_max_channel_count,
+  .get_min_latency = audiounit_get_min_latency,
+  .get_preferred_sample_rate = audiounit_get_preferred_sample_rate,
+  .enumerate_devices = audiounit_enumerate_devices,
+  .destroy = audiounit_destroy,
+  .stream_init = audiounit_stream_init,
+  .stream_destroy = audiounit_stream_destroy,
+  .stream_start = audiounit_stream_start,
+  .stream_stop = audiounit_stream_stop,
+  .stream_get_position = audiounit_stream_get_position,
+  .stream_get_latency = audiounit_stream_get_latency,
+  .stream_set_volume = audiounit_stream_set_volume,
+  .stream_set_panning = audiounit_stream_set_panning,
+  .stream_get_current_device = audiounit_stream_get_current_device,
+  .stream_device_destroy = audiounit_stream_device_destroy,
+  .stream_register_device_changed_callback = audiounit_stream_register_device_changed_callback,
+  .register_device_collection_changed = audiounit_register_device_collection_changed
 };
--- a/media/libcubeb/src/cubeb_osx_run_loop.h
+++ b/media/libcubeb/src/cubeb_osx_run_loop.h
@@ -6,17 +6,9 @@
  */
 
 /* On OSX 10.6 and after, the notification callbacks from the audio hardware are
  * called on the main thread. Setting the kAudioHardwarePropertyRunLoop property
  * to null tells the OSX to use a separate thread for that.
  *
  * This has to be called only once per process, so it is in a separate header
  * for easy integration in other code bases.  */
-#if defined(__cplusplus)
-extern "C" {
-#endif
-
 void cubeb_set_coreaudio_notification_runloop();
-
-#if defined(__cplusplus)
-}
-#endif
--- a/media/libcubeb/src/cubeb_resampler_internal.h
+++ b/media/libcubeb/src/cubeb_resampler_internal.h
@@ -258,17 +258,17 @@ public:
   }
 
   /** Returns the number of frames to pass in the input of the resampler to have
    * exactly `output_frame_count` resampled frames. This can return a number
    * slightly bigger than what is strictly necessary, but it guaranteed that the
    * number of output frames will be exactly equal. */
   uint32_t input_needed_for_output(uint32_t output_frame_count)
   {
-    return (uint32_t)ceilf((output_frame_count - samples_to_frames(resampling_out_buffer.length()))
+    return (uint32_t)ceilf((output_frame_count - samples_to_frames(resampling_in_buffer.length()))
                           * resampling_ratio);
 
   }
 
   /** Returns a pointer to the input buffer, that contains empty space for at
    * least `frame_count` elements. This is useful so that consumer can directly
    * write into the input buffer of the resampler. The pointer returned is
    * adjusted so that leftover data are not overwritten.
@@ -327,17 +327,17 @@ private:
   /** Storage for the input frames, to be resampled. Also contains
    * any unresampled frames after resampling. */
   auto_array<T> resampling_in_buffer;
   /* Storage for the resampled frames, to be passed back to the caller. */
   auto_array<T> resampling_out_buffer;
   /** Additional latency inserted into the pipeline for synchronisation. */
   uint32_t additional_latency;
   /** When `input_buffer` is called, this allows tracking the number of samples
-      that were in the buffer. */
+      that where in the buffer. */
   uint32_t leftover_samples;
 };
 
 /** This class allows delaying an audio stream by `frames` frames. */
 template<typename T>
 class delay_line : public processor {
 public:
   /** Constructor
--- a/media/libcubeb/src/cubeb_ring_array.h
+++ b/media/libcubeb/src/cubeb_ring_array.h
@@ -3,17 +3,19 @@
  *
  * This program is made available under an ISC-style license.  See the
  * accompanying file LICENSE for details.
  */
 
 #ifndef CUBEB_RING_ARRAY_H
 #define CUBEB_RING_ARRAY_H
 
-#include "cubeb_utils.h"
+#if defined(__cplusplus)
+extern "C" {
+#endif
 
 /** Ring array of pointers is used to hold buffers. In case that
     asynchronous producer/consumer callbacks do not arrive in a
     repeated order the ring array stores the buffers and fetch
     them in the correct order. */
 
 typedef struct {
   AudioBuffer * buffer_array;   /**< Array that hold pointers of the allocated space for the buffers. */
@@ -27,21 +29,20 @@ single_audiobuffer_init(AudioBuffer * bu
                         uint32_t bytesPerFrame,
                         uint32_t channelsPerFrame,
                         uint32_t frames)
 {
   assert(buffer);
   assert(bytesPerFrame > 0 && channelsPerFrame && frames > 0);
 
   size_t size = bytesPerFrame * frames;
-  buffer->mData = operator new(size);
+  buffer->mData = calloc(1, size);
   if (buffer->mData == NULL) {
     return CUBEB_ERROR;
   }
-  PodZero(static_cast<char*>(buffer->mData), size);
 
   buffer->mNumberChannels = channelsPerFrame;
   buffer->mDataByteSize = size;
 
   return CUBEB_OK;
 }
 
 /** Initialize the ring array.
@@ -58,18 +59,17 @@ ring_array_init(ring_array * ra,
   if (capacity == 0 || bytesPerFrame == 0 ||
       channelsPerFrame == 0 || framesPerBuffer == 0) {
     return CUBEB_ERROR_INVALID_PARAMETER;
   }
   ra->capacity = capacity;
   ra->tail = 0;
   ra->count = 0;
 
-  ra->buffer_array = new AudioBuffer[ra->capacity];
-  PodZero(ra->buffer_array, ra->capacity);
+  ra->buffer_array = calloc(ra->capacity, sizeof(AudioBuffer));
   if (ra->buffer_array == NULL) {
     return CUBEB_ERROR;
   }
 
   for (unsigned int i = 0; i < ra->capacity; ++i) {
     if (single_audiobuffer_init(&ra->buffer_array[i],
                                 bytesPerFrame,
                                 channelsPerFrame,
@@ -87,36 +87,36 @@ void
 ring_array_destroy(ring_array * ra)
 {
   assert(ra);
   if (ra->buffer_array == NULL){
     return;
   }
   for (unsigned int i = 0; i < ra->capacity; ++i) {
     if (ra->buffer_array[i].mData) {
-      operator delete(ra->buffer_array[i].mData);
+      free(ra->buffer_array[i].mData);
     }
   }
-  delete [] ra->buffer_array;
+  free(ra->buffer_array);
 }
 
 /** Get the allocated buffer to be stored with fresh data.
     @param ra The ring_array pointer.
     @retval Pointer of the allocated space to be stored with fresh data or NULL if full. */
 AudioBuffer *
 ring_array_get_free_buffer(ring_array * ra)
 {
   assert(ra && ra->buffer_array);
   assert(ra->buffer_array[0].mData != NULL);
   if (ra->count == ra->capacity) {
     return NULL;
   }
 
   assert(ra->count == 0 || (ra->tail + ra->count) % ra->capacity != ra->tail);
-  AudioBuffer * ret = &ra->buffer_array[(ra->tail + ra->count) % ra->capacity];
+  void * ret = &ra->buffer_array[(ra->tail + ra->count) % ra->capacity];
 
   ++ra->count;
   assert(ra->count <= ra->capacity);
 
   return ret;
 }
 
 /** Get the next available buffer with data.
@@ -126,17 +126,17 @@ AudioBuffer *
 ring_array_get_data_buffer(ring_array * ra)
 {
   assert(ra && ra->buffer_array);
   assert(ra->buffer_array[0].mData != NULL);
 
   if (ra->count == 0) {
     return NULL;
   }
-  AudioBuffer * ret = &ra->buffer_array[ra->tail];
+  void * ret = &ra->buffer_array[ra->tail];
 
   ra->tail = (ra->tail + 1) % ra->capacity;
   assert(ra->tail < ra->capacity);
 
   assert(ra->count > 0);
   --ra->count;
 
   return ret;
@@ -151,9 +151,13 @@ ring_array_get_dummy_buffer(ring_array *
   assert(ra && ra->buffer_array);
   assert(ra->capacity > 0);
   if (ra->count > 0) {
     return NULL;
   }
   return &ra->buffer_array[0];
 }
 
+#if defined(__cplusplus)
+}
+#endif
+
 #endif //CUBEB_RING_ARRAY_H
--- a/media/libcubeb/src/moz.build
+++ b/media/libcubeb/src/moz.build
@@ -31,17 +31,17 @@ if CONFIG['MOZ_PULSEAUDIO']:
 if CONFIG['OS_ARCH'] == 'OpenBSD':
     SOURCES += [
         'cubeb_sndio.c',
     ]
     DEFINES['USE_SNDIO'] = True
 
 if CONFIG['OS_TARGET'] == 'Darwin':
     SOURCES += [
-        'cubeb_audiounit.cpp',
+        'cubeb_audiounit.c',
         'cubeb_resampler.cpp'
     ]
     if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
         SOURCES += [
             'cubeb_osx_run_loop.c',
         ]
     DEFINES['USE_AUDIOUNIT'] = True
 
--- a/media/libcubeb/update.sh
+++ b/media/libcubeb/update.sh
@@ -7,20 +7,19 @@ cp $1/README.md .
 cp $1/include/cubeb/cubeb.h include
 cp $1/src/android/audiotrack_definitions.h src/android
 cp $1/src/android/sles_definitions.h src/android
 cp $1/src/cubeb-internal.h src
 cp $1/src/cubeb-speex-resampler.h src
 cp $1/src/cubeb.c src
 cp $1/src/cubeb_alsa.c src
 cp $1/src/cubeb_audiotrack.c src
-cp $1/src/cubeb_audiounit.cpp src
+cp $1/src/cubeb_audiounit.c src
 cp $1/src/cubeb_jack.cpp src
 cp $1/src/cubeb_opensl.c src
-cp $1/src/cubeb_osx_run_loop.h src
 cp $1/src/cubeb_panner.cpp src
 cp $1/src/cubeb_panner.h src
 cp $1/src/cubeb_pulse.c src
 cp $1/src/cubeb_resampler.cpp src
 cp $1/src/cubeb_resampler.h src
 cp $1/src/cubeb_resampler_internal.h src
 cp $1/src/cubeb_ring_array.h src
 cp $1/src/cubeb_sndio.c src