diff options
author | xians@chromium.org <xians@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-27 13:52:57 +0000 |
---|---|---|
committer | xians@chromium.org <xians@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-05-27 13:52:57 +0000 |
commit | 0df892bbc36e98473907433ec38efd7d102b5a6e (patch) | |
tree | 7de5b0db4e3f1a91887a2f75fd32704847f34cbe /media | |
parent | 1d6b5b83b9406b096d35f145924ab72f231e7e0b (diff) | |
download | chromium_src-0df892bbc36e98473907433ec38efd7d102b5a6e.zip chromium_src-0df892bbc36e98473907433ec38efd7d102b5a6e.tar.gz chromium_src-0df892bbc36e98473907433ec38efd7d102b5a6e.tar.bz2 |
reland 260073013: Added automatic mode to FakeInputAudioStream to generate automatic beeps
Added automatic mode to FakeInputAudioStream to generate automatic beeps.
This patch is to allow writing audio only tests using the fake input stream, also it changes the name of the fake device from "Default" to "Fake Audio", which I hope it will make things less confusing.
NOTRY=true
TBR=grunell@chromium.org
BUG=358541
TEST=bots existing webrtc tests.
Review URL: https://codereview.chromium.org/301633004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@272964 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r-- | media/audio/fake_audio_input_stream.cc | 47 | ||||
-rw-r--r-- | media/audio/fake_audio_input_stream.h | 1 | ||||
-rw-r--r-- | media/audio/mock_audio_manager.cc | 7 |
3 files changed, 36 insertions, 19 deletions
diff --git a/media/audio/fake_audio_input_stream.cc b/media/audio/fake_audio_input_stream.cc index 5ec09a4..e05b257 100644 --- a/media/audio/fake_audio_input_stream.cc +++ b/media/audio/fake_audio_input_stream.cc @@ -20,10 +20,16 @@ namespace { const int kBeepDurationMilliseconds = 20; const int kBeepFrequency = 400; +// Intervals between two automatic beeps. +const int kAutomaticBeepIntervalInMs = 500; + +// Automatic beep will be triggered every |kAutomaticBeepIntervalInMs| unless +// users explicitly call BeepOnce(), which will disable the automatic beep. struct BeepContext { - BeepContext() : beep_once(false) {} + BeepContext() : beep_once(false), automatic(true) {} base::Lock beep_lock; bool beep_once; + bool automatic; }; static base::LazyInstance<BeepContext> g_beep_context = @@ -78,14 +84,37 @@ void FakeAudioInputStream::Start(AudioInputCallback* callback) { void FakeAudioInputStream::DoCallback() { DCHECK(callback_); + const TimeTicks now = TimeTicks::Now(); + base::TimeDelta next_callback_time = + last_callback_time_ + callback_interval_ * 2 - now; + + // If we are falling behind, try to catch up as much as we can in the next + // callback. + if (next_callback_time < base::TimeDelta()) + next_callback_time = base::TimeDelta(); + + // Accumulate the time from the last beep. + interval_from_last_beep_ += now - last_callback_time_; + + last_callback_time_ = now; + memset(buffer_.get(), 0, buffer_size_); bool should_beep = false; { BeepContext* beep_context = g_beep_context.Pointer(); base::AutoLock auto_lock(beep_context->beep_lock); - should_beep = beep_context->beep_once; - beep_context->beep_once = false; + if (beep_context->automatic) { + base::TimeDelta delta = interval_from_last_beep_ - + TimeDelta::FromMilliseconds(kAutomaticBeepIntervalInMs); + if (delta > base::TimeDelta()) { + should_beep = true; + interval_from_last_beep_ = delta; + } + } else { + should_beep = beep_context->beep_once; + beep_context->beep_once = false; + } } // If this object was instructed to generate a beep or has started to @@ -103,7 +132,6 @@ void FakeAudioInputStream::DoCallback() { while (position + high_bytes <= buffer_size_) { // Write high values first. memset(buffer_.get() + position, 128, high_bytes); - // Then leave low values in the buffer with |high_bytes|. position += high_bytes * 2; } @@ -116,16 +144,6 @@ void FakeAudioInputStream::DoCallback() { callback_->OnData(this, buffer_.get(), buffer_size_, buffer_size_, 1.0); frames_elapsed_ += params_.frames_per_buffer(); - const TimeTicks now = TimeTicks::Now(); - base::TimeDelta next_callback_time = - last_callback_time_ + callback_interval_ * 2 - now; - - // If we are falling behind, try to catch up as much as we can in the next - // callback. - if (next_callback_time < base::TimeDelta()) - next_callback_time = base::TimeDelta(); - - last_callback_time_ = now; thread_.message_loop()->PostDelayedTask( FROM_HERE, base::Bind(&FakeAudioInputStream::DoCallback, base::Unretained(this)), @@ -163,6 +181,7 @@ void FakeAudioInputStream::BeepOnce() { BeepContext* beep_context = g_beep_context.Pointer(); base::AutoLock auto_lock(beep_context->beep_lock); beep_context->beep_once = true; + beep_context->automatic = false; } } // namespace media diff --git a/media/audio/fake_audio_input_stream.h b/media/audio/fake_audio_input_stream.h index 5879ab3..8dc2427 100644 --- a/media/audio/fake_audio_input_stream.h +++ b/media/audio/fake_audio_input_stream.h @@ -63,6 +63,7 @@ class MEDIA_EXPORT FakeAudioInputStream base::Thread thread_; base::TimeTicks last_callback_time_; base::TimeDelta callback_interval_; + base::TimeDelta interval_from_last_beep_; int beep_duration_in_buffers_; int beep_generated_in_buffers_; int beep_period_in_frames_; diff --git a/media/audio/mock_audio_manager.cc b/media/audio/mock_audio_manager.cc index e774b8c..7183405 100644 --- a/media/audio/mock_audio_manager.cc +++ b/media/audio/mock_audio_manager.cc @@ -34,11 +34,8 @@ void MockAudioManager::ShowAudioInputSettings() { void MockAudioManager::GetAudioInputDeviceNames( AudioDeviceNames* device_names) { - DCHECK(device_names->empty()); - device_names->push_back(media::AudioDeviceName("fake_device_name_1", - "fake_device_id_1")); - device_names->push_back(media::AudioDeviceName("fake_device_name_2", - "fake_device_id_2")); + // Do not inject fake devices here, use + // AudioInputDeviceManager::GetFakeDeviceNames() instead. } void MockAudioManager::GetAudioOutputDeviceNames( |