Index: media/audio/audio_input_controller.cc |
diff --git a/media/audio/audio_input_controller.cc b/media/audio/audio_input_controller.cc |
index 311a54ef840581ea69ef0cd65a52e13f33f16512..41f1f6421f98711b20960a383da34b48e6fb6554 100644 |
--- a/media/audio/audio_input_controller.cc |
+++ b/media/audio/audio_input_controller.cc |
@@ -4,12 +4,14 @@ |
#include "media/audio/audio_input_controller.h" |
+#include "base/logging.h" |
#include "base/threading/thread_restrictions.h" |
#include "media/base/limits.h" |
namespace media { |
static const int kMaxInputChannels = 2; |
+const int kDataCountCheckInterval = 1000; // One second. |
// static |
AudioInputController::Factory* AudioInputController::factory_ = NULL; |
@@ -18,6 +20,8 @@ AudioInputController::AudioInputController(EventHandler* handler, |
SyncWriter* sync_writer) |
: handler_(handler), |
stream_(NULL), |
+ on_data_call_count_(1), |
+ previous_on_data_count_(0), |
state_(kEmpty), |
thread_("AudioInputControllerThread"), |
sync_writer_(sync_writer) { |
@@ -123,6 +127,8 @@ void AudioInputController::DoCreate(AudioParameters params) { |
return; |
} |
+ ScheduleDataCountCheck(); |
+ |
state_ = kCreated; |
handler_->OnCreated(this); |
} |
@@ -168,6 +174,30 @@ void AudioInputController::DoReportError(int code) { |
handler_->OnError(this, code); |
} |
+void AudioInputController::DoDataCountCheck() { |
+ DCHECK_EQ(thread_.message_loop(), MessageLoop::current()); |
+ |
+ if (previous_on_data_count_ < on_data_call_count_) { |
+ // More data has arrived since last check. |
+ previous_on_data_count_ = on_data_call_count_; |
+ ScheduleDataCountCheck(); |
+ return; |
+ } |
+ |
+ // Have not received new data from an audio input device for |
+ // |kDataCountInterval| milliseconds. If a device is unplugged we may not get |
+ // an OnClosed callback on Windows so report an error. |
+ // See http://crbug.com/79936 for details. |
+ handler_->OnError(this, 0); |
+} |
+ |
+void AudioInputController::ScheduleDataCountCheck() { |
+ thread_.message_loop()->PostDelayedTask( |
satish1
2011/06/14 15:39:56
I see the DelayTimer class cancels the timer on de
allanwoj
2011/06/15 10:11:40
Done.
|
+ FROM_HERE, |
+ NewRunnableMethod(this, &AudioInputController::DoDataCountCheck), |
+ kDataCountCheckInterval); |
+} |
+ |
void AudioInputController::OnData(AudioInputStream* stream, const uint8* data, |
uint32 size) { |
{ |
@@ -176,6 +206,8 @@ void AudioInputController::OnData(AudioInputStream* stream, const uint8* data, |
return; |
} |
+ ++on_data_call_count_; |
+ |
// Use SyncSocket if we are in a low-latency mode. |
if (LowLatencyMode()) { |
sync_writer_->Write(data, size); |