Backed out 3 changesets (bug 904784, bug 899159) for not being intended for esr24 on a CLOSED TREE. DONTBUILD for good measure.
authorRyan VanderMeulen <ryanvm@gmail.com>
Wed, 11 Sep 2013 14:48:24 -0400
changeset 148565 c9b5ea71452297bd145fcd13438566c52a81c090
parent 148564 dbbba1b53eb738a07f3d425c69fa274dd80dacb0
child 148568 6086386093015f5735de497304daf57bcba4613a
push id9
push userryanvm@gmail.com
push dateWed, 11 Sep 2013 18:48:35 +0000
bugs904784, 899159
milestone24.0esrpre
backs out8c2e54e91eca441af75014ee2cb95b6db4aeea48
5e530d9b4cb5a27f0dbb92abdaffec728e1781ab
cb5b1d8e602abdc8b62b4144f291ffd2964cce86
Backed out 3 changesets (bug 904784, bug 899159) for not being intended for esr24 on a CLOSED TREE. DONTBUILD for good measure. Backed out changeset 8c2e54e91eca (bug 904784) Backed out changeset 5e530d9b4cb5 (bug 899159) Backed out changeset cb5b1d8e602a (bug 904784)
media/webrtc/trunk/webrtc/modules/audio_device/android/audio_device_opensles_android.cc
--- a/media/webrtc/trunk/webrtc/modules/audio_device/android/audio_device_opensles_android.cc
+++ b/media/webrtc/trunk/webrtc/modules/audio_device/android/audio_device_opensles_android.cc
@@ -63,27 +63,26 @@ AudioDeviceAndroidOpenSLES::AudioDeviceA
       is_play_initialized_(false),
       is_mic_initialized_(false),
       is_speaker_initialized_(false),
       playout_delay_(0),
       recording_delay_(0),
       agc_enabled_(false),
       rec_thread_(NULL),
       rec_timer_(*EventWrapper::Create()),
-      mic_sampling_rate_(N_REC_SAMPLES_PER_SEC),
-      speaker_sampling_rate_(N_PLAY_SAMPLES_PER_SEC),
+      mic_sampling_rate_(N_REC_SAMPLES_PER_SEC * 1000),
+      speaker_sampling_rate_(N_PLAY_SAMPLES_PER_SEC * 1000),
       max_speaker_vol_(0),
       min_speaker_vol_(0),
       loundspeaker_on_(false),
       opensles_lib_(0) {
   WEBRTC_OPENSL_TRACE(kTraceMemory, kTraceAudioDevice, id, "%s created",
                       __FUNCTION__);
   memset(rec_buf_, 0, sizeof(rec_buf_));
   memset(play_buf_, 0, sizeof(play_buf_));
-  UpdateRecordingDelay();
 }
 
 AudioDeviceAndroidOpenSLES::~AudioDeviceAndroidOpenSLES() {
   WEBRTC_OPENSL_TRACE(kTraceMemory, kTraceAudioDevice, id_, "%s destroyed",
                       __FUNCTION__);
 
   Terminate();
 
@@ -1252,50 +1251,44 @@ WebRtc_Word32 AudioDeviceAndroidOpenSLES
 WebRtc_Word32 AudioDeviceAndroidOpenSLES::CPULoad(
     WebRtc_UWord16& load) const {
   WEBRTC_OPENSL_TRACE(kTraceWarning, kTraceAudioDevice, id_,
                       "  API call not supported on this platform");
   return -1;
 }
 
 bool AudioDeviceAndroidOpenSLES::PlayoutWarning() const {
-  CriticalSectionScoped lock(&crit_sect_);
   return (play_warning_ > 0);
 }
 
 bool AudioDeviceAndroidOpenSLES::PlayoutError() const {
-  CriticalSectionScoped lock(&crit_sect_);
   return (play_error_ > 0);
 }
 
 bool AudioDeviceAndroidOpenSLES::RecordingWarning() const {
-  CriticalSectionScoped lock(&crit_sect_);
   return (rec_warning_ > 0);
 }
 
 bool AudioDeviceAndroidOpenSLES::RecordingError() const {
-  CriticalSectionScoped lock(&crit_sect_);
   return (rec_error_ > 0);
 }
 
 void AudioDeviceAndroidOpenSLES::ClearPlayoutWarning() {
   play_warning_ = 0;
 }
 
 void AudioDeviceAndroidOpenSLES::ClearPlayoutError() {
   play_error_ = 0;
 }
 
 void AudioDeviceAndroidOpenSLES::ClearRecordingWarning() {
-  CriticalSectionScoped lock(&crit_sect_);
   rec_warning_ = 0;
 }
 
 void AudioDeviceAndroidOpenSLES::ClearRecordingError() {
-  CriticalSectionScoped lock(&crit_sect_);
   rec_error_ = 0;
 }
 
 WebRtc_Word32 AudioDeviceAndroidOpenSLES::SetLoudspeakerStatus(bool enable) {
   loundspeaker_on_ = enable;
   return 0;
 }
 
@@ -1365,72 +1358,46 @@ bool AudioDeviceAndroidOpenSLES::RecThre
   // TODO(leozwang): Add seting correct scheduling and thread priority.
 
   const unsigned int num_samples = mic_sampling_rate_ / 100;
   const unsigned int num_bytes =
     N_REC_CHANNELS * num_samples * sizeof(int16_t);
   const unsigned int total_bytes = num_bytes;
   WebRtc_Word8 buf[REC_MAX_TEMP_BUF_SIZE_PER_10ms];
 
-  // Always grab crit_sect_ first, then callback_crit_sect_
-  // And vice-versa for releasing
-  crit_sect_.Enter();
-  callback_crit_sect_.Enter();
-  while (is_recording_) {
+  {
+    // Always grab crit_sect_ first, then callback_crit_sect_
+    // And vice-versa for releasing
+    CriticalSectionScoped lock(&crit_sect_);
+    CriticalSectionScoped callback_lock(&callback_crit_sect_);
+    if (!is_recording_) {
+      return true;
+    }
     if (rec_voe_audio_queue_.size() <= 0) {
-      callback_crit_sect_.Leave();
-      crit_sect_.Leave();
-      // Wait for max 40ms for incoming audio data before looping the
-      // poll and checking for ::Stop() being called (which waits for us
-      // to return).  Actual time between audio callbacks will vary, but
-      // is based on AudioRecord min buffer sizes, which may be 15-80ms
-      // or more, depending on sampling frequency, but typically will be
-      // 25ish ms at 44100Hz.  We also don't want to take "too long" to
-      // exit after ::Stop().  This value of 40ms is arbitrary.
-      rec_timer_.Wait(40);
-      crit_sect_.Enter();
-      callback_crit_sect_.Enter();
-      if (rec_voe_audio_queue_.size() <= 0) {
-        // still no audio data; check for ::Stop()
-        callback_crit_sect_.Leave();
-        crit_sect_.Leave();
-        return true;
-      }
+      rec_timer_.Wait(1);
+      return true;
     }
 
     WebRtc_Word8* audio = rec_voe_audio_queue_.front();
     rec_voe_audio_queue_.pop();
     memcpy(buf, audio, total_bytes);
     memset(audio, 0, total_bytes);
     rec_voe_ready_queue_.push(audio);
-
-    voe_audio_buffer_->SetRecordedBuffer(buf, num_samples);
-    voe_audio_buffer_->SetVQEData(playout_delay_, recording_delay_, 0);
+  }
 
-    // All other implementations UnLock around DeliverRecordedData() only
-    callback_crit_sect_.Leave();
-    crit_sect_.Leave();
-    voe_audio_buffer_->DeliverRecordedData();
-    crit_sect_.Enter();
-    callback_crit_sect_.Enter();
-  }
-  callback_crit_sect_.Leave();
-  crit_sect_.Leave();
-
-  // if is_recording is false, we either *just* were started, or for some reason
-  // Stop() failed to get us to return for 10 seconds - and when we return here,
-  // Stop will kill us anyways.
-  rec_timer_.Wait(1);
+  UpdateRecordingDelay();
+  voe_audio_buffer_->SetRecordedBuffer(buf, num_samples);
+  voe_audio_buffer_->SetVQEData(playout_delay_, recording_delay_, 0);
+  voe_audio_buffer_->DeliverRecordedData();
 
   return true;
 }
 
 void AudioDeviceAndroidOpenSLES::RecorderSimpleBufferQueueCallbackHandler(
-    SLAndroidSimpleBufferQueueItf queue_itf) {
-
+  SLAndroidSimpleBufferQueueItf queue_itf) {
   const unsigned int num_samples = mic_sampling_rate_ / 100;
   const unsigned int num_bytes =
     N_REC_CHANNELS * num_samples * sizeof(int16_t);
   const unsigned int total_bytes = num_bytes;
   WebRtc_Word8* audio;
 
   {
     // use this instead of crit_sect_ to avoid race against StopRecording()
@@ -1438,40 +1405,34 @@ void AudioDeviceAndroidOpenSLES::Recorde
     // this to exit, leading to possible deadlock (bug 904784)
     CriticalSectionScoped lock(&callback_crit_sect_);
     if (!is_recording_) {
       return;
     }
     audio = rec_queue_.front();
     rec_queue_.pop();
     rec_voe_audio_queue_.push(audio);
-    rec_timer_.Set(); // wake up record thread to process it
 
     if (rec_voe_ready_queue_.size() <= 0) {
       // Log Error.
       rec_error_ = 1;
       WEBRTC_OPENSL_TRACE(kTraceError, kTraceAudioDevice, id_,
                           "  Audio Rec thread buffers underrun");
-      // This isn't good, but continuing (as it used to) is even worse.
-      // Worst case we end up with buffers building up at the other end or
-      // starved.  To be fixed in full rewrite from upstream.
-      return;
     } else {
       audio = rec_voe_ready_queue_.front();
       rec_voe_ready_queue_.pop();
     }
   }
 
   WebRtc_Word32 res = (*queue_itf)->Enqueue(queue_itf,
                                             audio,
                                             total_bytes);
   if (res != SL_RESULT_SUCCESS) {
     WEBRTC_OPENSL_TRACE(kTraceWarning, kTraceAudioDevice, id_,
                         "  recorder callback Enqueue failed, %d", res);
-    CriticalSectionScoped lock(&crit_sect_);
     rec_warning_ = 1;
     return;
   } else {
     rec_queue_.push(audio);
   }
 
   // TODO(leozwang): OpenSL ES doesn't support AudioRecorder
   // volume control now, add it when it's ready.
@@ -1504,17 +1465,16 @@ WebRtc_Word32 AudioDeviceAndroidOpenSLES
   if (sles_engine_ == NULL) {
     WEBRTC_OPENSL_TRACE(kTraceError, kTraceAudioDevice, id_,
                         "  SL Object is NULL");
     return -1;
   }
 
   mic_sampling_rate_ = N_REC_SAMPLES_PER_SEC;
   speaker_sampling_rate_ = N_PLAY_SAMPLES_PER_SEC;
-  UpdateRecordingDelay();
 
   WEBRTC_OPENSL_TRACE(kTraceStateInfo, kTraceAudioDevice, id_,
                       "  mic sample rate (%d), speaker sample rate (%d)",
                       mic_sampling_rate_, speaker_sampling_rate_);
   return 0;
 }
 
 }  // namespace webrtc