Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/test/simple_test_tick_clock.h" | 5 #include "base/test/simple_test_tick_clock.h" |
| 6 #include "media/cast/audio_receiver/audio_decoder.h" | 6 #include "media/cast/audio_receiver/audio_decoder.h" |
| 7 #include "media/cast/cast_environment.h" | 7 #include "media/cast/cast_environment.h" |
| 8 #include "media/cast/test/fake_task_runner.h" | 8 #include "media/cast/test/fake_task_runner.h" |
| 9 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 } | 23 } |
| 24 }; | 24 }; |
| 25 } // namespace. | 25 } // namespace. |
| 26 | 26 |
| 27 class AudioDecoderTest : public ::testing::Test { | 27 class AudioDecoderTest : public ::testing::Test { |
| 28 protected: | 28 protected: |
| 29 AudioDecoderTest() { | 29 AudioDecoderTest() { |
| 30 testing_clock_ = new base::SimpleTestTickClock(); | 30 testing_clock_ = new base::SimpleTestTickClock(); |
| 31 testing_clock_->Advance(base::TimeDelta::FromMilliseconds(1234)); | 31 testing_clock_->Advance(base::TimeDelta::FromMilliseconds(1234)); |
| 32 task_runner_ = new test::FakeTaskRunner(testing_clock_); | 32 task_runner_ = new test::FakeTaskRunner(testing_clock_); |
| 33 cast_environment_ = new CastEnvironment( | 33 cast_environment_ = |
| 34 scoped_ptr<base::TickClock>(testing_clock_).Pass(), task_runner_, | 34 new CastEnvironment(scoped_ptr<base::TickClock>(testing_clock_).Pass(), |
| 35 task_runner_, task_runner_, task_runner_, task_runner_, task_runner_, | 35 task_runner_, |
| 36 GetDefaultCastReceiverLoggingConfig()); | 36 task_runner_, |
| 37 task_runner_, | |
| 38 task_runner_, | |
| 39 task_runner_, | |
| 40 task_runner_, | |
| 41 GetDefaultCastReceiverLoggingConfig()); | |
| 37 } | 42 } |
| 38 virtual ~AudioDecoderTest() {} | 43 virtual ~AudioDecoderTest() {} |
| 39 | 44 |
| 40 void Configure(const AudioReceiverConfig& audio_config) { | 45 void Configure(const AudioReceiverConfig& audio_config) { |
| 41 audio_decoder_.reset( | 46 audio_decoder_.reset( |
| 42 new AudioDecoder(cast_environment_, audio_config, &cast_feedback_)); | 47 new AudioDecoder(cast_environment_, audio_config, &cast_feedback_)); |
| 43 } | 48 } |
| 44 | 49 |
| 45 TestRtpPayloadFeedback cast_feedback_; | 50 TestRtpPayloadFeedback cast_feedback_; |
| 46 // Owned by CastEnvironment. | 51 // Owned by CastEnvironment. |
| 47 base::SimpleTestTickClock* testing_clock_; | 52 base::SimpleTestTickClock* testing_clock_; |
| 48 scoped_refptr<test::FakeTaskRunner> task_runner_; | 53 scoped_refptr<test::FakeTaskRunner> task_runner_; |
| 49 scoped_refptr<CastEnvironment> cast_environment_; | 54 scoped_refptr<CastEnvironment> cast_environment_; |
| 50 scoped_ptr<AudioDecoder> audio_decoder_; | 55 scoped_ptr<AudioDecoder> audio_decoder_; |
| 56 | |
| 57 DISALLOW_COPY_AND_ASSIGN(AudioDecoderTest); | |
| 51 }; | 58 }; |
| 52 | 59 |
| 53 TEST_F(AudioDecoderTest, Pcm16MonoNoResampleOnePacket) { | 60 TEST_F(AudioDecoderTest, Pcm16MonoNoResampleOnePacket) { |
| 54 AudioReceiverConfig audio_config; | 61 AudioReceiverConfig audio_config; |
| 55 audio_config.rtp_payload_type = 127; | 62 audio_config.rtp_payload_type = 127; |
| 56 audio_config.frequency = 16000; | 63 audio_config.frequency = 16000; |
| 57 audio_config.channels = 1; | 64 audio_config.channels = 1; |
| 58 audio_config.codec = transport::kPcm16; | 65 audio_config.codec = transport::kPcm16; |
| 59 audio_config.use_external_decoder = false; | 66 audio_config.use_external_decoder = false; |
| 60 Configure(audio_config); | 67 Configure(audio_config); |
| 61 | 68 |
| 62 RtpCastHeader rtp_header; | 69 RtpCastHeader rtp_header; |
| 63 rtp_header.webrtc.header.payloadType = 127; | 70 rtp_header.webrtc.header.payloadType = 127; |
| 64 rtp_header.webrtc.header.sequenceNumber = 1234; | 71 rtp_header.webrtc.header.sequenceNumber = 1234; |
| 65 rtp_header.webrtc.header.timestamp = 0x87654321; | 72 rtp_header.webrtc.header.timestamp = 0x87654321; |
| 66 rtp_header.webrtc.header.ssrc = 0x12345678; | 73 rtp_header.webrtc.header.ssrc = 0x12345678; |
| 67 rtp_header.webrtc.header.paddingLength = 0; | 74 rtp_header.webrtc.header.paddingLength = 0; |
| 68 rtp_header.webrtc.header.headerLength = 12; | 75 rtp_header.webrtc.header.headerLength = 12; |
| 69 rtp_header.webrtc.type.Audio.channel = 1; | 76 rtp_header.webrtc.type.Audio.channel = 1; |
| 70 rtp_header.webrtc.type.Audio.isCNG = false; | 77 rtp_header.webrtc.type.Audio.isCNG = false; |
| 71 | 78 |
| 72 std::vector<int16> payload(640, 0x1234); | 79 std::vector<int16> payload(640, 0x1234); |
| 73 int number_of_10ms_blocks = 4; | 80 int number_of_10ms_blocks = 4; |
| 74 int desired_frequency = 16000; | 81 int desired_frequency = 16000; |
| 75 PcmAudioFrame audio_frame; | 82 PcmAudioFrame audio_frame; |
| 76 uint32 rtp_timestamp; | 83 uint32 rtp_timestamp; |
| 77 | 84 |
| 78 EXPECT_FALSE(audio_decoder_->GetRawAudioFrame(number_of_10ms_blocks, | 85 EXPECT_FALSE(audio_decoder_->GetRawAudioFrame( |
|
hubbe
2014/01/29 20:07:39
Hmm, this isn't actually easier to read IMHO.
Does
mikhal1
2014/01/29 21:02:38
Apparently the tool prefers everything in one line
| |
| 79 desired_frequency, | 86 number_of_10ms_blocks, desired_frequency, &audio_frame, &rtp_timestamp)); |
| 80 &audio_frame, | |
| 81 &rtp_timestamp)); | |
| 82 | 87 |
| 83 uint8* payload_data = reinterpret_cast<uint8*>(&payload[0]); | 88 uint8* payload_data = reinterpret_cast<uint8*>(&payload[0]); |
| 84 size_t payload_size = payload.size() * sizeof(int16); | 89 size_t payload_size = payload.size() * sizeof(int16); |
| 85 | 90 |
| 86 audio_decoder_->IncomingParsedRtpPacket(payload_data, | 91 audio_decoder_->IncomingParsedRtpPacket( |
| 87 payload_size, rtp_header); | 92 payload_data, payload_size, rtp_header); |
| 88 | 93 |
| 89 EXPECT_TRUE(audio_decoder_->GetRawAudioFrame(number_of_10ms_blocks, | 94 EXPECT_TRUE(audio_decoder_->GetRawAudioFrame( |
| 90 desired_frequency, | 95 number_of_10ms_blocks, desired_frequency, &audio_frame, &rtp_timestamp)); |
| 91 &audio_frame, | |
| 92 &rtp_timestamp)); | |
| 93 EXPECT_EQ(1, audio_frame.channels); | 96 EXPECT_EQ(1, audio_frame.channels); |
| 94 EXPECT_EQ(16000, audio_frame.frequency); | 97 EXPECT_EQ(16000, audio_frame.frequency); |
| 95 EXPECT_EQ(640ul, audio_frame.samples.size()); | 98 EXPECT_EQ(640ul, audio_frame.samples.size()); |
| 96 // First 10 samples per channel are 0 from NetEq. | 99 // First 10 samples per channel are 0 from NetEq. |
| 97 for (size_t i = 10; i < audio_frame.samples.size(); ++i) { | 100 for (size_t i = 10; i < audio_frame.samples.size(); ++i) { |
| 98 EXPECT_EQ(0x3412, audio_frame.samples[i]); | 101 EXPECT_EQ(0x3412, audio_frame.samples[i]); |
| 99 } | 102 } |
| 100 } | 103 } |
| 101 | 104 |
| 102 TEST_F(AudioDecoderTest, Pcm16StereoNoResampleTwoPackets) { | 105 TEST_F(AudioDecoderTest, Pcm16StereoNoResampleTwoPackets) { |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 118 rtp_header.webrtc.header.headerLength = 12; | 121 rtp_header.webrtc.header.headerLength = 12; |
| 119 | 122 |
| 120 rtp_header.webrtc.type.Audio.isCNG = false; | 123 rtp_header.webrtc.type.Audio.isCNG = false; |
| 121 rtp_header.webrtc.type.Audio.channel = 2; | 124 rtp_header.webrtc.type.Audio.channel = 2; |
| 122 | 125 |
| 123 std::vector<int16> payload(640, 0x1234); | 126 std::vector<int16> payload(640, 0x1234); |
| 124 | 127 |
| 125 uint8* payload_data = reinterpret_cast<uint8*>(&payload[0]); | 128 uint8* payload_data = reinterpret_cast<uint8*>(&payload[0]); |
| 126 size_t payload_size = payload.size() * sizeof(int16); | 129 size_t payload_size = payload.size() * sizeof(int16); |
| 127 | 130 |
| 128 audio_decoder_->IncomingParsedRtpPacket(payload_data, | 131 audio_decoder_->IncomingParsedRtpPacket( |
| 129 payload_size, rtp_header); | 132 payload_data, payload_size, rtp_header); |
| 130 | 133 |
| 131 int number_of_10ms_blocks = 2; | 134 int number_of_10ms_blocks = 2; |
| 132 int desired_frequency = 16000; | 135 int desired_frequency = 16000; |
| 133 PcmAudioFrame audio_frame; | 136 PcmAudioFrame audio_frame; |
| 134 uint32 rtp_timestamp; | 137 uint32 rtp_timestamp; |
| 135 | 138 |
| 136 EXPECT_TRUE(audio_decoder_->GetRawAudioFrame(number_of_10ms_blocks, | 139 EXPECT_TRUE(audio_decoder_->GetRawAudioFrame( |
| 137 desired_frequency, | 140 number_of_10ms_blocks, desired_frequency, &audio_frame, &rtp_timestamp)); |
| 138 &audio_frame, | |
| 139 &rtp_timestamp)); | |
| 140 EXPECT_EQ(2, audio_frame.channels); | 141 EXPECT_EQ(2, audio_frame.channels); |
| 141 EXPECT_EQ(16000, audio_frame.frequency); | 142 EXPECT_EQ(16000, audio_frame.frequency); |
| 142 EXPECT_EQ(640ul, audio_frame.samples.size()); | 143 EXPECT_EQ(640ul, audio_frame.samples.size()); |
| 143 // First 10 samples per channel are 0 from NetEq. | 144 // First 10 samples per channel are 0 from NetEq. |
| 144 for (size_t i = 10 * audio_config.channels; i < audio_frame.samples.size(); | 145 for (size_t i = 10 * audio_config.channels; i < audio_frame.samples.size(); |
| 145 ++i) { | 146 ++i) { |
| 146 EXPECT_EQ(0x3412, audio_frame.samples[i]); | 147 EXPECT_EQ(0x3412, audio_frame.samples[i]); |
| 147 } | 148 } |
| 148 | 149 |
| 149 rtp_header.frame_id++; | 150 rtp_header.frame_id++; |
| 150 rtp_header.webrtc.header.sequenceNumber++; | 151 rtp_header.webrtc.header.sequenceNumber++; |
| 151 rtp_header.webrtc.header.timestamp += (audio_config.frequency / 100) * 2 * 2; | 152 rtp_header.webrtc.header.timestamp += (audio_config.frequency / 100) * 2 * 2; |
| 152 | 153 |
| 153 audio_decoder_->IncomingParsedRtpPacket(payload_data, | 154 audio_decoder_->IncomingParsedRtpPacket( |
| 154 payload_size, rtp_header); | 155 payload_data, payload_size, rtp_header); |
| 155 | 156 |
| 156 EXPECT_TRUE(audio_decoder_->GetRawAudioFrame(number_of_10ms_blocks, | 157 EXPECT_TRUE(audio_decoder_->GetRawAudioFrame( |
| 157 desired_frequency, | 158 number_of_10ms_blocks, desired_frequency, &audio_frame, &rtp_timestamp)); |
| 158 &audio_frame, | |
| 159 &rtp_timestamp)); | |
| 160 EXPECT_EQ(2, audio_frame.channels); | 159 EXPECT_EQ(2, audio_frame.channels); |
| 161 EXPECT_EQ(16000, audio_frame.frequency); | 160 EXPECT_EQ(16000, audio_frame.frequency); |
| 162 EXPECT_EQ(640ul, audio_frame.samples.size()); | 161 EXPECT_EQ(640ul, audio_frame.samples.size()); |
| 163 for (size_t i = 0; i < audio_frame.samples.size(); ++i) { | 162 for (size_t i = 0; i < audio_frame.samples.size(); ++i) { |
| 164 EXPECT_NEAR(0x3412, audio_frame.samples[i], 1000); | 163 EXPECT_NEAR(0x3412, audio_frame.samples[i], 1000); |
| 165 } | 164 } |
| 166 // Test cast callback. | 165 // Test cast callback. |
| 167 audio_decoder_->SendCastMessage(); | 166 audio_decoder_->SendCastMessage(); |
| 168 testing_clock_->Advance(base::TimeDelta::FromMilliseconds(33)); | 167 testing_clock_->Advance(base::TimeDelta::FromMilliseconds(33)); |
| 169 audio_decoder_->SendCastMessage(); | 168 audio_decoder_->SendCastMessage(); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 187 rtp_header.webrtc.header.headerLength = 12; | 186 rtp_header.webrtc.header.headerLength = 12; |
| 188 | 187 |
| 189 rtp_header.webrtc.type.Audio.isCNG = false; | 188 rtp_header.webrtc.type.Audio.isCNG = false; |
| 190 rtp_header.webrtc.type.Audio.channel = 2; | 189 rtp_header.webrtc.type.Audio.channel = 2; |
| 191 | 190 |
| 192 std::vector<int16> payload(640, 0x1234); | 191 std::vector<int16> payload(640, 0x1234); |
| 193 | 192 |
| 194 uint8* payload_data = reinterpret_cast<uint8*>(&payload[0]); | 193 uint8* payload_data = reinterpret_cast<uint8*>(&payload[0]); |
| 195 size_t payload_size = payload.size() * sizeof(int16); | 194 size_t payload_size = payload.size() * sizeof(int16); |
| 196 | 195 |
| 197 audio_decoder_->IncomingParsedRtpPacket(payload_data, | 196 audio_decoder_->IncomingParsedRtpPacket( |
| 198 payload_size, rtp_header); | 197 payload_data, payload_size, rtp_header); |
| 199 | 198 |
| 200 int number_of_10ms_blocks = 2; | 199 int number_of_10ms_blocks = 2; |
| 201 int desired_frequency = 48000; | 200 int desired_frequency = 48000; |
| 202 PcmAudioFrame audio_frame; | 201 PcmAudioFrame audio_frame; |
| 203 uint32 rtp_timestamp; | 202 uint32 rtp_timestamp; |
| 204 | 203 |
| 205 EXPECT_TRUE(audio_decoder_->GetRawAudioFrame(number_of_10ms_blocks, | 204 EXPECT_TRUE(audio_decoder_->GetRawAudioFrame( |
| 206 desired_frequency, | 205 number_of_10ms_blocks, desired_frequency, &audio_frame, &rtp_timestamp)); |
| 207 &audio_frame, | |
| 208 &rtp_timestamp)); | |
| 209 | 206 |
| 210 EXPECT_EQ(2, audio_frame.channels); | 207 EXPECT_EQ(2, audio_frame.channels); |
| 211 EXPECT_EQ(48000, audio_frame.frequency); | 208 EXPECT_EQ(48000, audio_frame.frequency); |
| 212 EXPECT_EQ(1920ul, audio_frame.samples.size()); // Upsampled to 48 KHz. | 209 EXPECT_EQ(1920ul, audio_frame.samples.size()); // Upsampled to 48 KHz. |
| 213 int count = 0; | 210 int count = 0; |
| 214 // Resampling makes the variance worse. | 211 // Resampling makes the variance worse. |
| 215 for (size_t i = 100 * audio_config.channels; i < audio_frame.samples.size(); | 212 for (size_t i = 100 * audio_config.channels; i < audio_frame.samples.size(); |
| 216 ++i) { | 213 ++i) { |
| 217 EXPECT_NEAR(0x3412, audio_frame.samples[i], 400); | 214 EXPECT_NEAR(0x3412, audio_frame.samples[i], 400); |
| 218 if (0x3412 == audio_frame.samples[i]) count++; | 215 if (0x3412 == audio_frame.samples[i]) |
| 216 count++; | |
| 219 } | 217 } |
| 220 } | 218 } |
| 221 | 219 |
| 222 } // namespace cast | 220 } // namespace cast |
| 223 } // namespace media | 221 } // namespace media |
| OLD | NEW |