| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/host/audio_pump.h" | 5 #include "remoting/host/audio_pump.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> |
| 10 |
| 9 #include "base/macros.h" | 11 #include "base/macros.h" |
| 10 #include "base/memory/scoped_vector.h" | 12 #include "base/memory/scoped_vector.h" |
| 11 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 12 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
| 13 #include "remoting/codec/audio_encoder.h" | 15 #include "remoting/codec/audio_encoder.h" |
| 14 #include "remoting/host/audio_capturer.h" | 16 #include "remoting/host/audio_capturer.h" |
| 15 #include "remoting/proto/audio.pb.h" | 17 #include "remoting/proto/audio.pb.h" |
| 16 #include "remoting/protocol/audio_stub.h" | 18 #include "remoting/protocol/audio_stub.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 18 | 20 |
| 19 namespace remoting { | 21 namespace remoting { |
| 20 | 22 |
| 21 namespace { | 23 namespace { |
| 22 | 24 |
| 23 // Creates a dummy packet with 1k data | 25 // Creates a dummy packet with 1k data |
| 24 scoped_ptr<AudioPacket> MakeAudioPacket() { | 26 scoped_ptr<AudioPacket> MakeAudioPacket() { |
| 25 scoped_ptr<AudioPacket> packet(new AudioPacket); | 27 scoped_ptr<AudioPacket> packet(new AudioPacket); |
| 26 packet->add_data()->resize(1000); | 28 packet->add_data()->resize(1000); |
| 27 return packet.Pass(); | 29 return packet; |
| 28 } | 30 } |
| 29 | 31 |
| 30 } // namespace | 32 } // namespace |
| 31 | 33 |
| 32 class FakeAudioCapturer : public AudioCapturer { | 34 class FakeAudioCapturer : public AudioCapturer { |
| 33 public: | 35 public: |
| 34 FakeAudioCapturer() {} | 36 FakeAudioCapturer() {} |
| 35 ~FakeAudioCapturer() override {} | 37 ~FakeAudioCapturer() override {} |
| 36 | 38 |
| 37 bool Start(const PacketCapturedCallback& callback) override { | 39 bool Start(const PacketCapturedCallback& callback) override { |
| 38 callback_ = callback; | 40 callback_ = callback; |
| 39 return true; | 41 return true; |
| 40 } | 42 } |
| 41 | 43 |
| 42 const PacketCapturedCallback& callback() { return callback_; } | 44 const PacketCapturedCallback& callback() { return callback_; } |
| 43 | 45 |
| 44 private: | 46 private: |
| 45 PacketCapturedCallback callback_; | 47 PacketCapturedCallback callback_; |
| 46 | 48 |
| 47 DISALLOW_COPY_AND_ASSIGN(FakeAudioCapturer); | 49 DISALLOW_COPY_AND_ASSIGN(FakeAudioCapturer); |
| 48 }; | 50 }; |
| 49 | 51 |
| 50 class FakeAudioEncoder : public AudioEncoder { | 52 class FakeAudioEncoder : public AudioEncoder { |
| 51 public: | 53 public: |
| 52 FakeAudioEncoder() {} | 54 FakeAudioEncoder() {} |
| 53 ~FakeAudioEncoder() override {} | 55 ~FakeAudioEncoder() override {} |
| 54 | 56 |
| 55 scoped_ptr<AudioPacket> Encode(scoped_ptr<AudioPacket> packet) override { | 57 scoped_ptr<AudioPacket> Encode(scoped_ptr<AudioPacket> packet) override { |
| 56 return packet.Pass(); | 58 return packet; |
| 57 } | 59 } |
| 58 int GetBitrate() override { | 60 int GetBitrate() override { |
| 59 return 160000; | 61 return 160000; |
| 60 } | 62 } |
| 61 | 63 |
| 62 private: | 64 private: |
| 63 DISALLOW_COPY_AND_ASSIGN(FakeAudioEncoder); | 65 DISALLOW_COPY_AND_ASSIGN(FakeAudioEncoder); |
| 64 }; | 66 }; |
| 65 | 67 |
| 66 class AudioPumpTest : public testing::Test, public protocol::AudioStub { | 68 class AudioPumpTest : public testing::Test, public protocol::AudioStub { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 void AudioPumpTest::TearDown() { | 103 void AudioPumpTest::TearDown() { |
| 102 pump_.reset(); | 104 pump_.reset(); |
| 103 | 105 |
| 104 // Let the message loop run to finish destroying the capturer. | 106 // Let the message loop run to finish destroying the capturer. |
| 105 base::RunLoop().RunUntilIdle(); | 107 base::RunLoop().RunUntilIdle(); |
| 106 } | 108 } |
| 107 | 109 |
| 108 void AudioPumpTest::ProcessAudioPacket( | 110 void AudioPumpTest::ProcessAudioPacket( |
| 109 scoped_ptr<AudioPacket> audio_packet, | 111 scoped_ptr<AudioPacket> audio_packet, |
| 110 const base::Closure& done) { | 112 const base::Closure& done) { |
| 111 sent_packets_.push_back(audio_packet.Pass()); | 113 sent_packets_.push_back(std::move(audio_packet)); |
| 112 done_closures_.push_back(done); | 114 done_closures_.push_back(done); |
| 113 } | 115 } |
| 114 | 116 |
| 115 // Verify that the pump pauses pumping when the network is congested. | 117 // Verify that the pump pauses pumping when the network is congested. |
| 116 TEST_F(AudioPumpTest, BufferSizeLimit) { | 118 TEST_F(AudioPumpTest, BufferSizeLimit) { |
| 117 // Run message loop to let the pump start the capturer. | 119 // Run message loop to let the pump start the capturer. |
| 118 base::RunLoop().RunUntilIdle(); | 120 base::RunLoop().RunUntilIdle(); |
| 119 ASSERT_FALSE(capturer_->callback().is_null()); | 121 ASSERT_FALSE(capturer_->callback().is_null()); |
| 120 | 122 |
| 121 // Try sending 100 packets, 1k each. The pump should stop pumping and start | 123 // Try sending 100 packets, 1k each. The pump should stop pumping and start |
| (...skipping 12 matching lines...) Expand all Loading... |
| 134 done_closures_.front().Run(); | 136 done_closures_.front().Run(); |
| 135 base::RunLoop().RunUntilIdle(); | 137 base::RunLoop().RunUntilIdle(); |
| 136 | 138 |
| 137 // Verify that the pump continues to send captured audio. | 139 // Verify that the pump continues to send captured audio. |
| 138 capturer_->callback().Run(MakeAudioPacket()); | 140 capturer_->callback().Run(MakeAudioPacket()); |
| 139 base::RunLoop().RunUntilIdle(); | 141 base::RunLoop().RunUntilIdle(); |
| 140 EXPECT_EQ(num_sent_packets + 1, sent_packets_.size()); | 142 EXPECT_EQ(num_sent_packets + 1, sent_packets_.size()); |
| 141 } | 143 } |
| 142 | 144 |
| 143 } // namespace remoting | 145 } // namespace remoting |
| OLD | NEW |