summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-09 19:16:31 +0000
committerananta@chromium.org <ananta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-05-09 19:16:31 +0000
commit0a35579ba0fbbd84ad1f2062e9d49d8106b0ef86 (patch)
tree6bd8431fa5a0fc1e405d3601db5e8fe80e13e8c6 /media
parent4c965c3f5b22af171ce0ade8199d9c37090a96a2 (diff)
downloadchromium_src-0a35579ba0fbbd84ad1f2062e9d49d8106b0ef86.zip
chromium_src-0a35579ba0fbbd84ad1f2062e9d49d8106b0ef86.tar.gz
chromium_src-0a35579ba0fbbd84ad1f2062e9d49d8106b0ef86.tar.bz2
Revert 269354 "Added automatic mode to FakeInputAudioStream to g..."
This CL caused the MediaAccessAPIDeny_TestDenyWithPreventDefault to fail on the mac builders. The same test also failed in the mac chromium rel browser tests try runs. Sadly they showed up as green. Please fix and reland > 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. > > TBR=dalecurtis@chromium.org > NOTRY=true > > BUG=358541 > TEST=bots existing webrtc tests. > > Review URL: https://codereview.chromium.org/272723006 TBR=xians@chromium.org Review URL: https://codereview.chromium.org/273163002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269391 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/audio/fake_audio_input_stream.cc47
-rw-r--r--media/audio/fake_audio_input_stream.h1
-rw-r--r--media/audio/mock_audio_manager.cc7
3 files changed, 19 insertions, 36 deletions
diff --git a/media/audio/fake_audio_input_stream.cc b/media/audio/fake_audio_input_stream.cc
index e05b257..5ec09a4 100644
--- a/media/audio/fake_audio_input_stream.cc
+++ b/media/audio/fake_audio_input_stream.cc
@@ -20,16 +20,10 @@ 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), automatic(true) {}
+ BeepContext() : beep_once(false) {}
base::Lock beep_lock;
bool beep_once;
- bool automatic;
};
static base::LazyInstance<BeepContext> g_beep_context =
@@ -84,37 +78,14 @@ 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);
- 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;
- }
+ should_beep = beep_context->beep_once;
+ beep_context->beep_once = false;
}
// If this object was instructed to generate a beep or has started to
@@ -132,6 +103,7 @@ 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;
}
@@ -144,6 +116,16 @@ 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)),
@@ -181,7 +163,6 @@ 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 8dc2427..5879ab3 100644
--- a/media/audio/fake_audio_input_stream.h
+++ b/media/audio/fake_audio_input_stream.h
@@ -63,7 +63,6 @@ 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 7183405..e774b8c 100644
--- a/media/audio/mock_audio_manager.cc
+++ b/media/audio/mock_audio_manager.cc
@@ -34,8 +34,11 @@ void MockAudioManager::ShowAudioInputSettings() {
void MockAudioManager::GetAudioInputDeviceNames(
AudioDeviceNames* device_names) {
- // Do not inject fake devices here, use
- // AudioInputDeviceManager::GetFakeDeviceNames() instead.
+ 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"));
}
void MockAudioManager::GetAudioOutputDeviceNames(