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

Side by Side Diff: remoting/protocol/audio_pump_unittest.cc

Issue 2903153004: [Chromoting] Implement down mixing in AudioPump (Closed)
Patch Set: Add more comments to explain the downmix and layout selection logic Created 3 years, 6 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
OLDNEW
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_EQ(packet->encoding(), AudioPacket::ENCODING_RAW);
51 EXPECT_EQ(packet->sampling_rate(), AudioPacket::SAMPLING_RATE_44100);
52 EXPECT_EQ(packet->bytes_per_sample(), AudioPacket::BYTES_PER_SAMPLE_2);
53 EXPECT_LE(packet->channels(), AudioPacket::CHANNELS_STEREO);
45 return packet; 54 return packet;
46 } 55 }
47 int GetBitrate() override { return 160000; } 56 int GetBitrate() override { return 160000; }
48 57
49 private: 58 private:
50 DISALLOW_COPY_AND_ASSIGN(FakeAudioEncoder); 59 DISALLOW_COPY_AND_ASSIGN(FakeAudioEncoder);
51 }; 60 };
52 61
53 class AudioPumpTest : public testing::Test, public protocol::AudioStub { 62 class AudioPumpTest : public testing::Test, public protocol::AudioStub {
54 public: 63 public:
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 // to be sent below. 129 // to be sent below.
121 done_closures_.front().Run(); 130 done_closures_.front().Run();
122 base::RunLoop().RunUntilIdle(); 131 base::RunLoop().RunUntilIdle();
123 132
124 // Verify that the pump continues to send captured audio. 133 // Verify that the pump continues to send captured audio.
125 source_->callback().Run(MakeAudioPacket()); 134 source_->callback().Run(MakeAudioPacket());
126 base::RunLoop().RunUntilIdle(); 135 base::RunLoop().RunUntilIdle();
127 EXPECT_EQ(num_sent_packets + 1, sent_packets_.size()); 136 EXPECT_EQ(num_sent_packets + 1, sent_packets_.size());
128 } 137 }
129 138
139 TEST_F(AudioPumpTest, DownmixAudioPacket) {
140 // Run message loop to let the pump start the capturer.
141 base::RunLoop().RunUntilIdle();
142 ASSERT_TRUE(source_->callback());
143
144 // Generate several audio packets with different channel counts.
145 static const int kChannels[] = {
146 AudioPacket::CHANNELS_7_1,
147 AudioPacket::CHANNELS_6_1,
148 AudioPacket::CHANNELS_5_1,
149 AudioPacket::CHANNELS_STEREO,
150 AudioPacket::CHANNELS_MONO,
151 AudioPacket::CHANNELS_7_1,
152 AudioPacket::CHANNELS_7_1,
153 AudioPacket::CHANNELS_7_1,
154 AudioPacket::CHANNELS_7_1,
155 AudioPacket::CHANNELS_6_1,
156 AudioPacket::CHANNELS_6_1,
157 AudioPacket::CHANNELS_6_1,
158 AudioPacket::CHANNELS_6_1,
159 AudioPacket::CHANNELS_5_1,
160 AudioPacket::CHANNELS_5_1,
161 AudioPacket::CHANNELS_5_1,
162 AudioPacket::CHANNELS_5_1,
163 AudioPacket::CHANNELS_STEREO,
164 AudioPacket::CHANNELS_STEREO,
165 AudioPacket::CHANNELS_STEREO,
166 AudioPacket::CHANNELS_STEREO,
167 AudioPacket::CHANNELS_MONO,
168 AudioPacket::CHANNELS_MONO,
169 AudioPacket::CHANNELS_MONO,
170 AudioPacket::CHANNELS_MONO,
171 };
172
173 for (size_t i = 0; i < arraysize(kChannels); i++) {
174 source_->callback().Run(MakeAudioPacket(kChannels[i]));
175 // Run message loop to let the pump processes the audio packet and send it
176 // to the encoder.
177 base::RunLoop().RunUntilIdle();
178 // Call done closure to allow one more packet to be sent.
179 ASSERT_EQ(done_closures_.size(), 1U);
180 done_closures_.front().Run();
181 done_closures_.pop_back();
182 base::RunLoop().RunUntilIdle();
183 }
184
185 ASSERT_EQ(sent_packets_.size(), arraysize(kChannels));
186 }
187
130 } // namespace protocol 188 } // namespace protocol
131 } // namespace remoting 189 } // namespace remoting
OLDNEW
« remoting/protocol/audio_pump.cc ('K') | « remoting/protocol/audio_pump.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698