| 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/protocol/audio_pump.h" | 5 #include "remoting/protocol/audio_pump.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
| 13 #include "base/memory/scoped_vector.h" | 13 #include "base/memory/scoped_vector.h" |
| 14 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 15 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 16 #include "remoting/codec/audio_encoder.h" | 16 #include "remoting/codec/audio_encoder.h" |
| 17 #include "remoting/proto/audio.pb.h" | 17 #include "remoting/proto/audio.pb.h" |
| 18 #include "remoting/protocol/audio_source.h" | 18 #include "remoting/protocol/audio_source.h" |
| 19 #include "remoting/protocol/audio_stub.h" | 19 #include "remoting/protocol/audio_stub.h" |
| 20 #include "remoting/protocol/fake_audio_source.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 22 |
| 22 namespace remoting { | 23 namespace remoting { |
| 23 namespace protocol { | 24 namespace protocol { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 // Creates a dummy packet with 1k data | 28 // Creates a dummy packet with 1k data |
| 28 std::unique_ptr<AudioPacket> MakeAudioPacket() { | 29 std::unique_ptr<AudioPacket> MakeAudioPacket() { |
| 29 std::unique_ptr<AudioPacket> packet(new AudioPacket); | 30 std::unique_ptr<AudioPacket> packet(new AudioPacket); |
| 30 packet->add_data()->resize(1000); | 31 packet->add_data()->resize(1000); |
| 31 return packet; | 32 return packet; |
| 32 } | 33 } |
| 33 | 34 |
| 34 } // namespace | 35 } // namespace |
| 35 | 36 |
| 36 class FakeAudioSource : public AudioSource { | |
| 37 public: | |
| 38 FakeAudioSource() {} | |
| 39 ~FakeAudioSource() override {} | |
| 40 | |
| 41 bool Start(const PacketCapturedCallback& callback) override { | |
| 42 callback_ = callback; | |
| 43 return true; | |
| 44 } | |
| 45 | |
| 46 const PacketCapturedCallback& callback() { return callback_; } | |
| 47 | |
| 48 private: | |
| 49 PacketCapturedCallback callback_; | |
| 50 | |
| 51 DISALLOW_COPY_AND_ASSIGN(FakeAudioSource); | |
| 52 }; | |
| 53 | |
| 54 class FakeAudioEncoder : public AudioEncoder { | 37 class FakeAudioEncoder : public AudioEncoder { |
| 55 public: | 38 public: |
| 56 FakeAudioEncoder() {} | 39 FakeAudioEncoder() {} |
| 57 ~FakeAudioEncoder() override {} | 40 ~FakeAudioEncoder() override {} |
| 58 | 41 |
| 59 std::unique_ptr<AudioPacket> Encode( | 42 std::unique_ptr<AudioPacket> Encode( |
| 60 std::unique_ptr<AudioPacket> packet) override { | 43 std::unique_ptr<AudioPacket> packet) override { |
| 61 return packet; | 44 return packet; |
| 62 } | 45 } |
| 63 int GetBitrate() override { return 160000; } | 46 int GetBitrate() override { return 160000; } |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 base::RunLoop().RunUntilIdle(); | 121 base::RunLoop().RunUntilIdle(); |
| 139 | 122 |
| 140 // Verify that the pump continues to send captured audio. | 123 // Verify that the pump continues to send captured audio. |
| 141 source_->callback().Run(MakeAudioPacket()); | 124 source_->callback().Run(MakeAudioPacket()); |
| 142 base::RunLoop().RunUntilIdle(); | 125 base::RunLoop().RunUntilIdle(); |
| 143 EXPECT_EQ(num_sent_packets + 1, sent_packets_.size()); | 126 EXPECT_EQ(num_sent_packets + 1, sent_packets_.size()); |
| 144 } | 127 } |
| 145 | 128 |
| 146 } // namespace protocol | 129 } // namespace protocol |
| 147 } // namespace remoting | 130 } // namespace remoting |
| OLD | NEW |