Bug 1021328: ensure no paths lose far-end audio chunks in getUserMedia r=mccr8
authorRandell Jesup <rjesup@jesup.org>
Sat, 07 Jun 2014 00:11:42 -0400
changeset 207675 dbb05142c66657d6b6928ef24caa2755f5073725
parent 207674 d7dc39d162348d21bd2b51b3a3b56fa2fe969dd5
child 207676 553bf8d3404cd2b8ded27786daef295354c733f4
push id494
push userraliiev@mozilla.com
push dateMon, 25 Aug 2014 18:42:16 +0000
treeherdermozilla-release@a3cc3e46b571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmccr8
bugs1021328
milestone32.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 1021328: ensure no paths lose far-end audio chunks in getUserMedia r=mccr8
content/media/webrtc/AudioOutputObserver.h
content/media/webrtc/MediaEngineWebRTCAudio.cpp
--- a/content/media/webrtc/AudioOutputObserver.h
+++ b/content/media/webrtc/AudioOutputObserver.h
@@ -38,17 +38,17 @@ public:
 private:
   uint32_t mPlayoutFreq;
   uint32_t mPlayoutChannels;
 
   nsAutoPtr<webrtc::SingleRwFifo> mPlayoutFifo;
   uint32_t mChunkSize;
 
   // chunking to 10ms support
-  nsAutoPtr<FarEndAudioChunk> mSaved;
+  FarEndAudioChunk *mSaved; // can't be nsAutoPtr since we need to use moz_free()
   uint32_t mSamplesSaved;
 };
 
 // XXX until there's a registration API in MSG
 extern StaticAutoPtr<AudioOutputObserver> gFarendObserver;
 
 }
 
--- a/content/media/webrtc/MediaEngineWebRTCAudio.cpp
+++ b/content/media/webrtc/MediaEngineWebRTCAudio.cpp
@@ -49,33 +49,35 @@ NS_IMPL_ISUPPORTS0(MediaEngineWebRTCAudi
 
 // XXX temp until MSG supports registration
 StaticAutoPtr<AudioOutputObserver> gFarendObserver;
 
 AudioOutputObserver::AudioOutputObserver()
   : mPlayoutFreq(0)
   , mPlayoutChannels(0)
   , mChunkSize(0)
+  , mSaved(nullptr)
   , mSamplesSaved(0)
 {
   // Buffers of 10ms chunks
   mPlayoutFifo = new webrtc::SingleRwFifo(MAX_AEC_FIFO_DEPTH/10);
 }
 
 AudioOutputObserver::~AudioOutputObserver()
 {
   Clear();
 }
 
 void
 AudioOutputObserver::Clear()
 {
   while (mPlayoutFifo->size() > 0) {
-    (void) mPlayoutFifo->Pop();
+    moz_free(mPlayoutFifo->Pop());
   }
+  moz_free(mSaved);
   mSaved = nullptr;
 }
 
 FarEndAudioChunk *
 AudioOutputObserver::Pop()
 {
   return (FarEndAudioChunk *) mPlayoutFifo->Pop();
 }
@@ -149,17 +151,18 @@ AudioOutputObserver::InsertFarEnd(const 
 
     if (mSamplesSaved >= mChunkSize) {
       int free_slots = mPlayoutFifo->capacity() - mPlayoutFifo->size();
       if (free_slots <= 0) {
         // XXX We should flag an overrun for the reader.  We can't drop data from it due to
         // thread safety issues.
         break;
       } else {
-        mPlayoutFifo->Push((int8_t *) mSaved.forget()); // takes ownership
+        mPlayoutFifo->Push((int8_t *) mSaved); // takes ownership
+        mSaved = nullptr;
         mSamplesSaved = 0;
       }
     }
   }
 }
 
 void
 MediaEngineWebRTCAudioSource::GetName(nsAString& aName)
@@ -512,34 +515,34 @@ MediaEngineWebRTCAudioSource::Process(in
   int length, int samplingFreq, bool isStereo)
 {
   // On initial capture, throw away all far-end data except the most recent sample
   // since it's already irrelevant and we want to keep avoid confusing the AEC far-end
   // input code with "old" audio.
   if (!mStarted) {
     mStarted  = true;
     while (gFarendObserver->Size() > 1) {
-      FarEndAudioChunk *buffer = gFarendObserver->Pop(); // only call if size() > 0
-      free(buffer);
+      moz_free(gFarendObserver->Pop()); // only call if size() > 0
     }
   }
 
   while (gFarendObserver->Size() > 0) {
     FarEndAudioChunk *buffer = gFarendObserver->Pop(); // only call if size() > 0
     if (buffer) {
       int length = buffer->mSamples;
-      if (mVoERender->ExternalPlayoutData(buffer->mData,
-                                          gFarendObserver->PlayoutFrequency(),
-                                          gFarendObserver->PlayoutChannels(),
-                                          mPlayoutDelay,
-                                          length) == -1) {
+      int res = mVoERender->ExternalPlayoutData(buffer->mData,
+                                                gFarendObserver->PlayoutFrequency(),
+                                                gFarendObserver->PlayoutChannels(),
+                                                mPlayoutDelay,
+                                                length);
+      moz_free(buffer);
+      if (res == -1) {
         return;
       }
     }
-    free(buffer);
   }
 
 #ifdef PR_LOGGING
   mSamples += length;
   if (mSamples > samplingFreq) {
     mSamples %= samplingFreq; // just in case mSamples >> samplingFreq
     if (PR_LOG_TEST(GetMediaManagerLog(), PR_LOG_DEBUG)) {
       webrtc::EchoStatistics echo;