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

Unified Diff: media/audio/fake_audio_worker_unittest.cc

Issue 922663002: Moved the fake input stream's processing onto the audio worker thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 10 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/fake_audio_worker.cc ('k') | media/audio/null_audio_sink.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/fake_audio_worker_unittest.cc
diff --git a/media/audio/fake_audio_consumer_unittest.cc b/media/audio/fake_audio_worker_unittest.cc
similarity index 64%
rename from media/audio/fake_audio_consumer_unittest.cc
rename to media/audio/fake_audio_worker_unittest.cc
index ab97eaea8c76c78fa263bd41793d26b58be50a00..49a69d2b08641175675f4a6c72f736e409c74696 100644
--- a/media/audio/fake_audio_consumer_unittest.cc
+++ b/media/audio/fake_audio_worker_unittest.cc
@@ -6,7 +6,7 @@
#include "base/message_loop/message_loop.h"
#include "base/time/time.h"
#include "media/audio/audio_parameters.h"
-#include "media/audio/fake_audio_consumer.h"
+#include "media/audio/fake_audio_worker.h"
#include "media/audio/simple_sources.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -14,57 +14,57 @@ namespace media {
static const int kTestCallbacks = 5;
-class FakeAudioConsumerTest : public testing::Test {
+class FakeAudioWorkerTest : public testing::Test {
public:
- FakeAudioConsumerTest()
+ FakeAudioWorkerTest()
: params_(
AudioParameters::AUDIO_FAKE, CHANNEL_LAYOUT_STEREO, 44100, 8, 128),
- fake_consumer_(message_loop_.message_loop_proxy(), params_),
- source_(params_.channels(), 200.0, params_.sample_rate()) {
+ fake_worker_(message_loop_.message_loop_proxy(), params_),
+ seen_callbacks_(0) {
time_between_callbacks_ = base::TimeDelta::FromMicroseconds(
params_.frames_per_buffer() * base::Time::kMicrosecondsPerSecond /
static_cast<float>(params_.sample_rate()));
}
- ~FakeAudioConsumerTest() override {}
+ ~FakeAudioWorkerTest() override {}
- void ConsumeData(AudioBus* audio_bus) {
- source_.OnMoreData(audio_bus, 0);
+ void CalledByFakeWorker() {
+ seen_callbacks_++;
}
void RunOnAudioThread() {
ASSERT_TRUE(message_loop_.message_loop_proxy()->BelongsToCurrentThread());
- fake_consumer_.Start(base::Bind(
- &FakeAudioConsumerTest::ConsumeData, base::Unretained(this)));
+ fake_worker_.Start(base::Bind(
+ &FakeAudioWorkerTest::CalledByFakeWorker, base::Unretained(this)));
}
void RunOnceOnAudioThread() {
ASSERT_TRUE(message_loop_.message_loop_proxy()->BelongsToCurrentThread());
RunOnAudioThread();
- // Start() should immediately post a task to run the source callback, so we
+ // Start() should immediately post a task to run the callback, so we
// should end up with only a single callback being run.
message_loop_.PostTask(FROM_HERE, base::Bind(
- &FakeAudioConsumerTest::EndTest, base::Unretained(this), 1));
+ &FakeAudioWorkerTest::EndTest, base::Unretained(this), 1));
}
void StopStartOnAudioThread() {
ASSERT_TRUE(message_loop_.message_loop_proxy()->BelongsToCurrentThread());
- fake_consumer_.Stop();
+ fake_worker_.Stop();
RunOnAudioThread();
}
void TimeCallbacksOnAudioThread(int callbacks) {
ASSERT_TRUE(message_loop_.message_loop_proxy()->BelongsToCurrentThread());
- if (source_.callbacks() == 0) {
+ if (seen_callbacks_ == 0) {
RunOnAudioThread();
start_time_ = base::TimeTicks::Now();
}
// Keep going until we've seen the requested number of callbacks.
- if (source_.callbacks() < callbacks) {
+ if (seen_callbacks_ < callbacks) {
message_loop_.PostDelayedTask(FROM_HERE, base::Bind(
- &FakeAudioConsumerTest::TimeCallbacksOnAudioThread,
+ &FakeAudioWorkerTest::TimeCallbacksOnAudioThread,
base::Unretained(this), callbacks), time_between_callbacks_ / 2);
} else {
end_time_ = base::TimeTicks::Now();
@@ -74,46 +74,45 @@ class FakeAudioConsumerTest : public testing::Test {
void EndTest(int callbacks) {
ASSERT_TRUE(message_loop_.message_loop_proxy()->BelongsToCurrentThread());
- fake_consumer_.Stop();
- EXPECT_LE(callbacks, source_.callbacks());
+ fake_worker_.Stop();
+ EXPECT_LE(callbacks, seen_callbacks_);
message_loop_.PostTask(FROM_HERE, base::MessageLoop::QuitClosure());
}
protected:
base::MessageLoop message_loop_;
AudioParameters params_;
- FakeAudioConsumer fake_consumer_;
- SineWaveAudioSource source_;
+ FakeAudioWorker fake_worker_;
base::TimeTicks start_time_;
base::TimeTicks end_time_;
base::TimeDelta time_between_callbacks_;
+ int seen_callbacks_;
private:
- DISALLOW_COPY_AND_ASSIGN(FakeAudioConsumerTest);
+ DISALLOW_COPY_AND_ASSIGN(FakeAudioWorkerTest);
};
-// Ensure the fake audio stream runs on the audio thread and handles fires
-// callbacks to the AudioSourceCallback.
-TEST_F(FakeAudioConsumerTest, FakeStreamBasicCallback) {
+// Ensure the worker runs on the audio thread and fires callbacks.
+TEST_F(FakeAudioWorkerTest, FakeBasicCallback) {
message_loop_.PostTask(FROM_HERE, base::Bind(
- &FakeAudioConsumerTest::RunOnceOnAudioThread,
+ &FakeAudioWorkerTest::RunOnceOnAudioThread,
base::Unretained(this)));
message_loop_.Run();
}
// Ensure the time between callbacks is sane.
-TEST_F(FakeAudioConsumerTest, TimeBetweenCallbacks) {
+TEST_F(FakeAudioWorkerTest, TimeBetweenCallbacks) {
message_loop_.PostTask(FROM_HERE, base::Bind(
- &FakeAudioConsumerTest::TimeCallbacksOnAudioThread,
+ &FakeAudioWorkerTest::TimeCallbacksOnAudioThread,
base::Unretained(this), kTestCallbacks));
message_loop_.Run();
// There are only (kTestCallbacks - 1) intervals between kTestCallbacks.
base::TimeDelta actual_time_between_callbacks =
- (end_time_ - start_time_) / (source_.callbacks() - 1);
+ (end_time_ - start_time_) / (seen_callbacks_ - 1);
// Ensure callback time is no faster than the expected time between callbacks.
- EXPECT_TRUE(actual_time_between_callbacks >= time_between_callbacks_);
+ EXPECT_GE(actual_time_between_callbacks, time_between_callbacks_);
// Softly check if the callback time is no slower than twice the expected time
// between callbacks. Since this test runs on the bots we can't be too strict
@@ -122,17 +121,17 @@ TEST_F(FakeAudioConsumerTest, TimeBetweenCallbacks) {
LOG(ERROR) << "Time between fake audio callbacks is too large!";
}
-// Ensure Start()/Stop() on the stream doesn't generate too many callbacks. See
-// http://crbug.com/159049
-TEST_F(FakeAudioConsumerTest, StartStopClearsCallbacks) {
+// Ensure Start()/Stop() on the worker doesn't generate too many callbacks. See
+// http://crbug.com/159049.
+TEST_F(FakeAudioWorkerTest, StartStopClearsCallbacks) {
message_loop_.PostTask(FROM_HERE, base::Bind(
- &FakeAudioConsumerTest::TimeCallbacksOnAudioThread,
+ &FakeAudioWorkerTest::TimeCallbacksOnAudioThread,
base::Unretained(this), kTestCallbacks));
// Issue a Stop() / Start() in between expected callbacks to maximize the
- // chance of catching the FakeAudioOutputStream doing the wrong thing.
+ // chance of catching the worker doing the wrong thing.
message_loop_.PostDelayedTask(FROM_HERE, base::Bind(
- &FakeAudioConsumerTest::StopStartOnAudioThread,
+ &FakeAudioWorkerTest::StopStartOnAudioThread,
base::Unretained(this)), time_between_callbacks_ / 2);
// EndTest() will ensure the proper number of callbacks have occurred.
« no previous file with comments | « media/audio/fake_audio_worker.cc ('k') | media/audio/null_audio_sink.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698