Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(288)

Unified Diff: media/audio/audio_input_controller.cc

Issue 7129057: Fix bug when unplugging an audio input device whilst using speech input. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Feedback changes Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/audio/audio_input_controller.h ('k') | media/audio/audio_input_controller_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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);
« no previous file with comments | « media/audio/audio_input_controller.h ('k') | media/audio/audio_input_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698