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

Unified Diff: trunk/src/media/audio/fake_audio_input_stream.cc

Issue 300143005: Revert 272884 "reland 260073013: Added automatic mode to FakeInp..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 7 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 | « trunk/src/media/audio/fake_audio_input_stream.h ('k') | trunk/src/media/audio/mock_audio_manager.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: trunk/src/media/audio/fake_audio_input_stream.cc
===================================================================
--- trunk/src/media/audio/fake_audio_input_stream.cc (revision 272929)
+++ trunk/src/media/audio/fake_audio_input_stream.cc (working copy)
@@ -20,16 +20,10 @@
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::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 @@
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 @@
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 @@
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
« no previous file with comments | « trunk/src/media/audio/fake_audio_input_stream.h ('k') | trunk/src/media/audio/mock_audio_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698