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

Unified Diff: remoting/host/audio_pump_unittest.cc

Issue 914133003: Fix AudioPump to pause the stream when the network is congested. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@audio_pump
Patch Set: 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 | « remoting/host/audio_pump.cc ('k') | remoting/remoting_test.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remoting/host/audio_pump_unittest.cc
diff --git a/remoting/host/audio_pump_unittest.cc b/remoting/host/audio_pump_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8d0ac5d57acf928feadb5e7fea6cab1b603af38a
--- /dev/null
+++ b/remoting/host/audio_pump_unittest.cc
@@ -0,0 +1,140 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "remoting/host/audio_pump.h"
+
+#include "base/memory/scoped_vector.h"
+#include "base/message_loop/message_loop.h"
+#include "base/run_loop.h"
+#include "remoting/codec/audio_encoder.h"
+#include "remoting/host/audio_capturer.h"
+#include "remoting/proto/audio.pb.h"
+#include "remoting/protocol/audio_stub.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace remoting {
+
+namespace {
+
+// Creates a dummy packet with 1k data
+scoped_ptr<AudioPacket> MakeAudioPacket() {
+ scoped_ptr<AudioPacket> packet(new AudioPacket);
+ packet->add_data()->resize(1000);
+ return packet.Pass();
+}
+
+} // namespace
+
+class FakeAudioCapturer : public AudioCapturer {
+ public:
+ FakeAudioCapturer() {}
+ ~FakeAudioCapturer() override {}
+
+ bool Start(const PacketCapturedCallback& callback) override {
+ callback_ = callback;
+ return true;
+ }
+
+ const PacketCapturedCallback& callback() { return callback_; }
+
+ private:
+ PacketCapturedCallback callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(FakeAudioCapturer);
+};
+
+class FakeAudioEncoder : public AudioEncoder {
+ public:
+ FakeAudioEncoder() {}
+ ~FakeAudioEncoder() override {}
+
+ scoped_ptr<AudioPacket> Encode(scoped_ptr<AudioPacket> packet) override {
+ return packet.Pass();
+ }
+ int GetBitrate() override {
+ return 160000;
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(FakeAudioEncoder);
+};
+
+class AudioPumpTest : public testing::Test, public protocol::AudioStub {
+ public:
+ AudioPumpTest() {}
+
+ void SetUp() override;
+ void TearDown() override;
+
+ // protocol::AudioStub interface.
+ void ProcessAudioPacket(scoped_ptr<AudioPacket> audio_packet,
+ const base::Closure& done) override;
+
+ protected:
+ base::MessageLoop message_loop_;
+
+ // |capturer_| and |encoder_| are owned by the |pump_|.
+ FakeAudioCapturer* capturer_;
+ FakeAudioEncoder* encoder_;
+
+ scoped_ptr<AudioPump> pump_;
+
+ ScopedVector<AudioPacket> sent_packets_;
+ std::vector<base::Closure> done_closures_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(AudioPumpTest);
+};
+
+void AudioPumpTest::SetUp() {
+ capturer_ = new FakeAudioCapturer();
+ encoder_ = new FakeAudioEncoder();
+ pump_.reset(new AudioPump(message_loop_.task_runner(),
+ make_scoped_ptr(capturer_),
+ make_scoped_ptr(encoder_), this));
+}
+
+void AudioPumpTest::TearDown() {
+ pump_.reset();
+
+ // Let the message loop run to finish destroying the capturer.
+ base::RunLoop().RunUntilIdle();
+}
+
+void AudioPumpTest::ProcessAudioPacket(
+ scoped_ptr<AudioPacket> audio_packet,
+ const base::Closure& done) {
+ sent_packets_.push_back(audio_packet.Pass());
+ done_closures_.push_back(done);
+}
+
+// Verify that the pump pauses pumping when the network is congested.
+TEST_F(AudioPumpTest, BufferSizeLimit) {
+ // Run message loop to let the pump start the capturer.
+ base::RunLoop().RunUntilIdle();
+ ASSERT_FALSE(capturer_->callback().is_null());
+
+ // Try sending 100 packets, 1k each. The pump should stop pumping and start
+ // dropping the data at some point.
+ for (size_t i = 0; i < 100; ++i) {
+ capturer_->callback().Run(MakeAudioPacket());
+ base::RunLoop().RunUntilIdle();
+ }
+
+ size_t num_sent_packets = sent_packets_.size();
+ EXPECT_LT(num_sent_packets, 100U);
+ EXPECT_GT(num_sent_packets, 0U);
+
+ // Call done closure for the first packet. This should allow one more packet
+ // to be sent below.
+ done_closures_.front().Run();
+ base::RunLoop().RunUntilIdle();
+
+ // Verify that the pump continues to send captured audio.
+ capturer_->callback().Run(MakeAudioPacket());
+ base::RunLoop().RunUntilIdle();
+ EXPECT_EQ(num_sent_packets + 1, sent_packets_.size());
+}
+
+} // namespace remoting
« no previous file with comments | « remoting/host/audio_pump.cc ('k') | remoting/remoting_test.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698