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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « remoting/host/audio_pump.cc ('k') | remoting/remoting_test.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "remoting/host/audio_pump.h"
6
7 #include "base/memory/scoped_vector.h"
8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h"
10 #include "remoting/codec/audio_encoder.h"
11 #include "remoting/host/audio_capturer.h"
12 #include "remoting/proto/audio.pb.h"
13 #include "remoting/protocol/audio_stub.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 namespace remoting {
17
18 namespace {
19
20 // Creates a dummy packet with 1k data
21 scoped_ptr<AudioPacket> MakeAudioPacket() {
22 scoped_ptr<AudioPacket> packet(new AudioPacket);
23 packet->add_data()->resize(1000);
24 return packet.Pass();
25 }
26
27 } // namespace
28
29 class FakeAudioCapturer : public AudioCapturer {
30 public:
31 FakeAudioCapturer() {}
32 ~FakeAudioCapturer() override {}
33
34 bool Start(const PacketCapturedCallback& callback) override {
35 callback_ = callback;
36 return true;
37 }
38
39 const PacketCapturedCallback& callback() { return callback_; }
40
41 private:
42 PacketCapturedCallback callback_;
43
44 DISALLOW_COPY_AND_ASSIGN(FakeAudioCapturer);
45 };
46
47 class FakeAudioEncoder : public AudioEncoder {
48 public:
49 FakeAudioEncoder() {}
50 ~FakeAudioEncoder() override {}
51
52 scoped_ptr<AudioPacket> Encode(scoped_ptr<AudioPacket> packet) override {
53 return packet.Pass();
54 }
55 int GetBitrate() override {
56 return 160000;
57 }
58
59 private:
60 DISALLOW_COPY_AND_ASSIGN(FakeAudioEncoder);
61 };
62
63 class AudioPumpTest : public testing::Test, public protocol::AudioStub {
64 public:
65 AudioPumpTest() {}
66
67 void SetUp() override;
68 void TearDown() override;
69
70 // protocol::AudioStub interface.
71 void ProcessAudioPacket(scoped_ptr<AudioPacket> audio_packet,
72 const base::Closure& done) override;
73
74 protected:
75 base::MessageLoop message_loop_;
76
77 // |capturer_| and |encoder_| are owned by the |pump_|.
78 FakeAudioCapturer* capturer_;
79 FakeAudioEncoder* encoder_;
80
81 scoped_ptr<AudioPump> pump_;
82
83 ScopedVector<AudioPacket> sent_packets_;
84 std::vector<base::Closure> done_closures_;
85
86 private:
87 DISALLOW_COPY_AND_ASSIGN(AudioPumpTest);
88 };
89
90 void AudioPumpTest::SetUp() {
91 capturer_ = new FakeAudioCapturer();
92 encoder_ = new FakeAudioEncoder();
93 pump_.reset(new AudioPump(message_loop_.task_runner(),
94 make_scoped_ptr(capturer_),
95 make_scoped_ptr(encoder_), this));
96 }
97
98 void AudioPumpTest::TearDown() {
99 pump_.reset();
100
101 // Let the message loop run to finish destroying the capturer.
102 base::RunLoop().RunUntilIdle();
103 }
104
105 void AudioPumpTest::ProcessAudioPacket(
106 scoped_ptr<AudioPacket> audio_packet,
107 const base::Closure& done) {
108 sent_packets_.push_back(audio_packet.Pass());
109 done_closures_.push_back(done);
110 }
111
112 // Verify that the pump pauses pumping when the network is congested.
113 TEST_F(AudioPumpTest, BufferSizeLimit) {
114 // Run message loop to let the pump start the capturer.
115 base::RunLoop().RunUntilIdle();
116 ASSERT_FALSE(capturer_->callback().is_null());
117
118 // Try sending 100 packets, 1k each. The pump should stop pumping and start
119 // dropping the data at some point.
120 for (size_t i = 0; i < 100; ++i) {
121 capturer_->callback().Run(MakeAudioPacket());
122 base::RunLoop().RunUntilIdle();
123 }
124
125 size_t num_sent_packets = sent_packets_.size();
126 EXPECT_LT(num_sent_packets, 100U);
127 EXPECT_GT(num_sent_packets, 0U);
128
129 // Call done closure for the first packet. This should allow one more packet
130 // to be sent below.
131 done_closures_.front().Run();
132 base::RunLoop().RunUntilIdle();
133
134 // Verify that the pump continues to send captured audio.
135 capturer_->callback().Run(MakeAudioPacket());
136 base::RunLoop().RunUntilIdle();
137 EXPECT_EQ(num_sent_packets + 1, sent_packets_.size());
138 }
139
140 } // namespace remoting
OLDNEW
« 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