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

Unified Diff: media/audio/android/audio_android_unittest.cc

Issue 1166483002: Stop enqueueing data to output audio device if consecutive empty buffers are received (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 | « no previous file | media/audio/android/opensles_output.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/audio/android/audio_android_unittest.cc
diff --git a/media/audio/android/audio_android_unittest.cc b/media/audio/android/audio_android_unittest.cc
index b8ebccf3b2b5a4e1c0694d6bafd265ecef4b3c0c..395a5d09ffdb58c9c334b5385a5de93fb940b626 100644
--- a/media/audio/android/audio_android_unittest.cc
+++ b/media/audio/android/audio_android_unittest.cc
@@ -404,6 +404,41 @@ class FullDuplexAudioSinkSource
DISALLOW_COPY_AND_ASSIGN(FullDuplexAudioSinkSource);
};
+// Implements AudioOutputStream::AudioSourceCallback and provides empty audio
+// data.
+class EmptyAudioSource : public AudioOutputStream::AudioSourceCallback {
+ public:
+ EmptyAudioSource(base::WaitableEvent* event, int size)
+ : event_(event), remaining_size_(size) {}
+ ~EmptyAudioSource() override {}
+
+ // AudioOutputStream::AudioSourceCallback implementation.
+ int OnMoreData(AudioBus* audio_bus, uint32 total_bytes_delay) override {
+ audio_bus->Zero();
+ int max_size =
+ audio_bus->frames() * audio_bus->channels() * kBytesPerSample;
+ bool stop_playing = false;
+ if (max_size > remaining_size_) {
+ stop_playing = true;
+ max_size = remaining_size_;
+ }
+ remaining_size_ -= max_size;
+ // Set event to ensure that the test can stop.
+ if (stop_playing)
+ event_->Signal();
+
+ return max_size / (audio_bus->channels() * kBytesPerSample);
+ }
+
+ void OnError(AudioOutputStream* stream) override {}
+
+ private:
+ base::WaitableEvent* event_;
+ int remaining_size_;
+
+ DISALLOW_COPY_AND_ASSIGN(EmptyAudioSource);
+};
+
// Test fixture class for tests which only exercise the output path.
class AudioAndroidOutputTest : public testing::Test {
public:
@@ -863,6 +898,29 @@ TEST_F(AudioAndroidOutputTest, DISABLED_RunOutputStreamWithFileAsSource) {
StopAndCloseAudioOutputStreamOnAudioThread();
}
+// Play empty data and verify that the data are consumed properly.
+TEST_F(AudioAndroidOutputTest, RunOutputStreamWithEmptySource) {
+ GetDefaultOutputStreamParametersOnAudioThread();
+ const AudioParameters params = audio_output_parameters();
+ DVLOG(1) << params;
+ MakeAudioOutputStreamOnAudioThread(params);
+
+ base::WaitableEvent event(false, false);
+ int size = 100000;
+ EmptyAudioSource source(&event, size);
+ base::TimeTicks start_time = base::TimeTicks::Now();
+
+ OpenAndStartAudioOutputStreamOnAudioThread(&source);
+ EXPECT_TRUE(event.TimedWait(TestTimeouts::action_max_timeout()));
+ // Verify that all the data are consumed as if they are passed through audio
+ // hardware.
+ base::TimeDelta time_passed = base::TimeTicks::Now() - start_time;
+ int estimated_consumption_time_ms = (size * 1000) /
+ (params.channels() * params.sample_rate() * kBytesPerSample);
+ EXPECT_LE(estimated_consumption_time_ms, time_passed.InMilliseconds());
+ StopAndCloseAudioOutputStreamOnAudioThread();
+}
+
// Start input streaming and run it for ten seconds while recording to a
// local audio file.
// NOTE: this test requires user interaction and is not designed to run as an
« no previous file with comments | « no previous file | media/audio/android/opensles_output.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698