Chromium Code Reviews| 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..529ee7dacaa78722394817d5bbf29d8fe79af76b 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,27 @@ 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 since last check so report an error. |
|
Satish
2011/06/14 14:28:04
It would be useful to explain this more and even a
allanwoj
2011/06/14 15:03:12
Done.
|
| + handler_->OnError(this, 0); |
| +} |
| + |
| +void AudioInputController::ScheduleDataCountCheck() { |
|
scherkus (not reviewing)
2011/06/13 19:04:56
consider using DelayTimer from base/timer.h
allanwoj
2011/06/14 15:03:12
Decided to keep it the way it is, this way it make
scherkus (not reviewing)
2011/06/14 21:22:02
Not sure I agree... right now I find it more confu
allanwoj
2011/06/15 10:11:40
Oh right, I see what you mean. I've gone ahead and
|
| + thread_.message_loop()->PostDelayedTask( |
| + FROM_HERE, |
| + NewRunnableMethod(this, &AudioInputController::DoDataCountCheck), |
| + kDataCountCheckInterval); |
| +} |
| + |
| void AudioInputController::OnData(AudioInputStream* stream, const uint8* data, |
| uint32 size) { |
| { |
| @@ -176,6 +203,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); |