Bug 1269472 - Uplift libcubeb AudioUnit device-lost crash fix from upstream. r=jesup, a=sylvestre
authorMatthew Gregan <kinetik@flim.org>
Tue, 17 May 2016 17:54:11 +1200
changeset 333097 04934785596476f6dd8baccc355202aeba59af35
parent 333096 3fa0f58b23395a7f9f95384b18607ff10c581c00
child 333098 f8c2d37d27143661a99cd10f90d198aae18b3536
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup, sylvestre
bugs1269472
milestone48.0a2
Bug 1269472 - Uplift libcubeb AudioUnit device-lost crash fix from upstream. r=jesup, a=sylvestre
media/libcubeb/README_MOZILLA
media/libcubeb/bug1269472.patch
media/libcubeb/src/cubeb_audiounit.c
media/libcubeb/update.sh
--- 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 dbdfb3904deb7a0381588209cdd7388217d96e61.
+The git commit ID used was d654c426ef944f0a36e6da86c959d94271173cfb.
new file mode 100644
--- /dev/null
+++ b/media/libcubeb/bug1269472.patch
@@ -0,0 +1,73 @@
+diff --git a/media/libcubeb/src/cubeb_audiounit.c b/media/libcubeb/src/cubeb_audiounit.c
+--- a/media/libcubeb/src/cubeb_audiounit.c
++++ b/media/libcubeb/src/cubeb_audiounit.c
+@@ -146,16 +146,22 @@ audiotimestamp_to_latency(AudioTimeStamp
+   }
+ 
+   uint64_t pres = AudioConvertHostTimeToNanos(tstamp->mHostTime);
+   uint64_t now = AudioConvertHostTimeToNanos(AudioGetCurrentHostTime());
+ 
+   return ((pres - now) * stream->output_desc.mSampleRate) / 1000000000LL;
+ }
+ 
++static void
++audiounit_make_silent(AudioBuffer * ioData)
++{
++  memset(ioData->mData, 0, ioData->mDataByteSize);
++}
++
+ static OSStatus
+ audiounit_input_callback(void * user_ptr,
+                          AudioUnitRenderActionFlags * flags,
+                          AudioTimeStamp const * tstamp,
+                          UInt32 bus,
+                          UInt32 input_frames,
+                          AudioBufferList * bufs)
+ {
+@@ -188,17 +194,22 @@ audiounit_input_callback(void * user_ptr
+ 
+   /* Render input samples */
+   OSStatus r = AudioUnitRender(stm->input_unit,
+                                flags,
+                                tstamp,
+                                bus,
+                                input_frames,
+                                &input_buffer_list);
+-  assert(r == noErr);
++  if (r != noErr) {
++    LOG("Input AudioUnitRender failed with error=%d", r);
++    audiounit_make_silent(input_buffer);
++    return r;
++  }
++
+   LOG("- input:  buffers %d, size %d, channels %d, frames %d\n",
+       input_buffer_list.mNumberBuffers,
+       input_buffer_list.mBuffers[0].mDataByteSize,
+       input_buffer_list.mBuffers[0].mNumberChannels,
+       input_frames);
+ 
+   assert(input_frames > 0);
+   stm->frames_read += input_frames;
+@@ -226,22 +237,16 @@ audiounit_input_callback(void * user_ptr
+     pthread_mutex_unlock(&stm->mutex);
+     return noErr;
+   }
+ 
+   pthread_mutex_unlock(&stm->mutex);
+   return noErr;
+ }
+ 
+-static void
+-audiounit_make_silent(AudioBuffer * ioData)
+-{
+-  memset(ioData->mData, 0, ioData->mDataByteSize);
+-}
+-
+ static OSStatus
+ audiounit_output_callback(void * user_ptr,
+                           AudioUnitRenderActionFlags * flags,
+                           AudioTimeStamp const * tstamp,
+                           UInt32 bus,
+                           UInt32 output_frames,
+                           AudioBufferList * outBufferList)
+ {
--- a/media/libcubeb/src/cubeb_audiounit.c
+++ b/media/libcubeb/src/cubeb_audiounit.c
@@ -146,16 +146,22 @@ audiotimestamp_to_latency(AudioTimeStamp
   }
 
   uint64_t pres = AudioConvertHostTimeToNanos(tstamp->mHostTime);
   uint64_t now = AudioConvertHostTimeToNanos(AudioGetCurrentHostTime());
 
   return ((pres - now) * stream->output_desc.mSampleRate) / 1000000000LL;
 }
 
+static void
+audiounit_make_silent(AudioBuffer * ioData)
+{
+  memset(ioData->mData, 0, ioData->mDataByteSize);
+}
+
 static OSStatus
 audiounit_input_callback(void * user_ptr,
                          AudioUnitRenderActionFlags * flags,
                          AudioTimeStamp const * tstamp,
                          UInt32 bus,
                          UInt32 input_frames,
                          AudioBufferList * bufs)
 {
@@ -188,17 +194,22 @@ audiounit_input_callback(void * user_ptr
 
   /* Render input samples */
   OSStatus r = AudioUnitRender(stm->input_unit,
                                flags,
                                tstamp,
                                bus,
                                input_frames,
                                &input_buffer_list);
-  assert(r == noErr);
+  if (r != noErr) {
+    LOG("Input AudioUnitRender failed with error=%d", r);
+    audiounit_make_silent(input_buffer);
+    return r;
+  }
+
   LOG("- input:  buffers %d, size %d, channels %d, frames %d\n",
       input_buffer_list.mNumberBuffers,
       input_buffer_list.mBuffers[0].mDataByteSize,
       input_buffer_list.mBuffers[0].mNumberChannels,
       input_frames);
 
   assert(input_frames > 0);
   stm->frames_read += input_frames;
@@ -226,22 +237,16 @@ audiounit_input_callback(void * user_ptr
     pthread_mutex_unlock(&stm->mutex);
     return noErr;
   }
 
   pthread_mutex_unlock(&stm->mutex);
   return noErr;
 }
 
-static void
-audiounit_make_silent(AudioBuffer * ioData)
-{
-  memset(ioData->mData, 0, ioData->mDataByteSize);
-}
-
 static OSStatus
 audiounit_output_callback(void * user_ptr,
                           AudioUnitRenderActionFlags * flags,
                           AudioTimeStamp const * tstamp,
                           UInt32 bus,
                           UInt32 output_frames,
                           AudioBufferList * outBufferList)
 {
--- a/media/libcubeb/update.sh
+++ b/media/libcubeb/update.sh
@@ -47,9 +47,10 @@ if [ -n "$rev" ]; then
     version=$version-dirty
     echo "WARNING: updating from a dirty git repository."
   fi
   sed -i.bak -e "/The git commit ID used was/ s/[0-9a-f]\{40\}\(-dirty\)\{0,1\}\./$version./" README_MOZILLA
   rm README_MOZILLA.bak
 else
   echo "Remember to update README_MOZILLA with the version details."
 fi
+patch -p3 < ./bug1269472.patch