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 <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/message_loop/message_loop.h" | 15 #include "base/message_loop/message_loop.h" |
16 #include "base/run_loop.h" | 16 #include "base/run_loop.h" |
17 #include "remoting/codec/audio_encoder.h" | 17 #include "remoting/codec/audio_encoder.h" |
18 #include "remoting/proto/audio.pb.h" | 18 #include "remoting/proto/audio.pb.h" |
19 #include "remoting/protocol/audio_source.h" | 19 #include "remoting/protocol/audio_source.h" |
20 #include "remoting/protocol/audio_stub.h" | 20 #include "remoting/protocol/audio_stub.h" |
21 #include "remoting/protocol/fake_audio_source.h" | 21 #include "remoting/protocol/fake_audio_source.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
23 | 23 |
24 namespace remoting { | 24 namespace remoting { |
25 namespace protocol { | 25 namespace protocol { |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 // Creates a dummy packet with 1k data | 29 // Creates a dummy packet with 1k data |
30 std::unique_ptr<AudioPacket> MakeAudioPacket() { | 30 std::unique_ptr<AudioPacket> MakeAudioPacket(int channel_count = 2) { |
31 std::unique_ptr<AudioPacket> packet(new AudioPacket); | 31 std::unique_ptr<AudioPacket> packet(new AudioPacket); |
32 packet->add_data()->resize(1000); | 32 packet->add_data()->resize(1024); |
33 packet->set_encoding(AudioPacket::ENCODING_RAW); | |
34 packet->set_sampling_rate(AudioPacket::SAMPLING_RATE_44100); | |
35 packet->set_bytes_per_sample(AudioPacket::BYTES_PER_SAMPLE_2); | |
36 packet->set_channels(static_cast<AudioPacket::Channels>(channel_count)); | |
33 return packet; | 37 return packet; |
34 } | 38 } |
35 | 39 |
36 } // namespace | 40 } // namespace |
37 | 41 |
38 class FakeAudioEncoder : public AudioEncoder { | 42 class FakeAudioEncoder : public AudioEncoder { |
39 public: | 43 public: |
40 FakeAudioEncoder() {} | 44 FakeAudioEncoder() {} |
41 ~FakeAudioEncoder() override {} | 45 ~FakeAudioEncoder() override {} |
42 | 46 |
43 std::unique_ptr<AudioPacket> Encode( | 47 std::unique_ptr<AudioPacket> Encode( |
44 std::unique_ptr<AudioPacket> packet) override { | 48 std::unique_ptr<AudioPacket> packet) override { |
49 EXPECT_TRUE(!!packet); | |
50 EXPECT_LE(packet->channels(), 2); | |
45 return packet; | 51 return packet; |
46 } | 52 } |
47 int GetBitrate() override { return 160000; } | 53 int GetBitrate() override { return 160000; } |
48 | 54 |
49 private: | 55 private: |
50 DISALLOW_COPY_AND_ASSIGN(FakeAudioEncoder); | 56 DISALLOW_COPY_AND_ASSIGN(FakeAudioEncoder); |
51 }; | 57 }; |
52 | 58 |
53 class AudioPumpTest : public testing::Test, public protocol::AudioStub { | 59 class AudioPumpTest : public testing::Test, public protocol::AudioStub { |
54 public: | 60 public: |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 // to be sent below. | 126 // to be sent below. |
121 done_closures_.front().Run(); | 127 done_closures_.front().Run(); |
122 base::RunLoop().RunUntilIdle(); | 128 base::RunLoop().RunUntilIdle(); |
123 | 129 |
124 // Verify that the pump continues to send captured audio. | 130 // Verify that the pump continues to send captured audio. |
125 source_->callback().Run(MakeAudioPacket()); | 131 source_->callback().Run(MakeAudioPacket()); |
126 base::RunLoop().RunUntilIdle(); | 132 base::RunLoop().RunUntilIdle(); |
127 EXPECT_EQ(num_sent_packets + 1, sent_packets_.size()); | 133 EXPECT_EQ(num_sent_packets + 1, sent_packets_.size()); |
128 } | 134 } |
129 | 135 |
136 TEST_F(AudioPumpTest, DownmixAudioPacket) { | |
137 base::RunLoop().RunUntilIdle(); | |
joedow
2017/05/26 16:01:51
Please add a comment here to note why this is need
Hzj_jie
2017/05/26 20:08:04
Done.
| |
138 ASSERT_TRUE(source_->callback()); | |
139 | |
140 // Randomly generate several audio packets with different channel counts. | |
joedow
2017/05/26 16:01:51
nit: This isn't random if you define a static list
Hzj_jie
2017/05/26 20:08:03
Done.
| |
141 static const int kChannels[] = { | |
142 8, 6, 2, 1, 8, 8, 8, 8, 6, 6, 6, 6, 2, | |
143 }; | |
joedow
2017/05/26 16:01:51
Would it make sense to use the enum names here ins
Hzj_jie
2017/05/26 20:08:04
Done.
| |
144 | |
145 for (size_t i = 0; i < arraysize(kChannels); i++) { | |
146 source_->callback().Run(MakeAudioPacket(kChannels[i])); | |
147 base::RunLoop().RunUntilIdle(); | |
joedow
2017/05/26 16:01:51
Please add comments (as in the test above) to expl
Hzj_jie
2017/05/26 20:08:04
Done.
| |
148 done_closures_.front().Run(); | |
149 base::RunLoop().RunUntilIdle(); | |
150 } | |
151 | |
152 EXPECT_EQ(sent_packets_.size(), arraysize(kChannels)); | |
153 } | |
154 | |
130 } // namespace protocol | 155 } // namespace protocol |
131 } // namespace remoting | 156 } // namespace remoting |
OLD | NEW |