| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/client/audio_player.h" | 5 #include "remoting/client/audio_player.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <memory> |
| 10 |
| 9 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
| 12 | 13 |
| 13 namespace { | 14 namespace { |
| 14 | 15 |
| 15 const int kAudioSamplesPerFrame = 25; | 16 const int kAudioSamplesPerFrame = 25; |
| 16 const int kAudioSampleBytes = 4; | 17 const int kAudioSampleBytes = 4; |
| 17 const int kAudioFrameBytes = kAudioSamplesPerFrame * kAudioSampleBytes; | 18 const int kAudioFrameBytes = kAudioSamplesPerFrame * kAudioSampleBytes; |
| 18 const int kPaddingBytes = 16; | 19 const int kPaddingBytes = 16; |
| 19 | 20 |
| 20 // TODO(garykac): Generate random audio data in the tests rather than having | 21 // TODO(garykac): Generate random audio data in the tests rather than having |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 } | 76 } |
| 76 | 77 |
| 77 int GetNumQueuedPackets() { | 78 int GetNumQueuedPackets() { |
| 78 return static_cast<int>(audio_->queued_packets_.size()); | 79 return static_cast<int>(audio_->queued_packets_.size()); |
| 79 } | 80 } |
| 80 | 81 |
| 81 int GetBytesConsumed() { | 82 int GetBytesConsumed() { |
| 82 return static_cast<int>(audio_->bytes_consumed_); | 83 return static_cast<int>(audio_->bytes_consumed_); |
| 83 } | 84 } |
| 84 | 85 |
| 85 scoped_ptr<AudioPlayer> audio_; | 86 std::unique_ptr<AudioPlayer> audio_; |
| 86 scoped_ptr<char[]> buffer_; | 87 std::unique_ptr<char[]> buffer_; |
| 87 }; | 88 }; |
| 88 | 89 |
| 89 scoped_ptr<AudioPacket> CreatePacketWithSamplingRate( | 90 std::unique_ptr<AudioPacket> CreatePacketWithSamplingRate( |
| 90 AudioPacket::SamplingRate rate, int samples) { | 91 AudioPacket::SamplingRate rate, |
| 91 scoped_ptr<AudioPacket> packet(new AudioPacket()); | 92 int samples) { |
| 93 std::unique_ptr<AudioPacket> packet(new AudioPacket()); |
| 92 packet->set_encoding(AudioPacket::ENCODING_RAW); | 94 packet->set_encoding(AudioPacket::ENCODING_RAW); |
| 93 packet->set_sampling_rate(rate); | 95 packet->set_sampling_rate(rate); |
| 94 packet->set_bytes_per_sample(AudioPacket::BYTES_PER_SAMPLE_2); | 96 packet->set_bytes_per_sample(AudioPacket::BYTES_PER_SAMPLE_2); |
| 95 packet->set_channels(AudioPacket::CHANNELS_STEREO); | 97 packet->set_channels(AudioPacket::CHANNELS_STEREO); |
| 96 | 98 |
| 97 // The data must be a multiple of 4 bytes (channels x bytes_per_sample). | 99 // The data must be a multiple of 4 bytes (channels x bytes_per_sample). |
| 98 std::string data; | 100 std::string data; |
| 99 data.resize(samples * kAudioSampleBytes, kDummyAudioData); | 101 data.resize(samples * kAudioSampleBytes, kDummyAudioData); |
| 100 packet->add_data(data); | 102 packet->add_data(data); |
| 101 | 103 |
| 102 return packet; | 104 return packet; |
| 103 } | 105 } |
| 104 | 106 |
| 105 scoped_ptr<AudioPacket> CreatePacket44100Hz(int samples) { | 107 std::unique_ptr<AudioPacket> CreatePacket44100Hz(int samples) { |
| 106 return CreatePacketWithSamplingRate(AudioPacket::SAMPLING_RATE_44100, | 108 return CreatePacketWithSamplingRate(AudioPacket::SAMPLING_RATE_44100, |
| 107 samples); | 109 samples); |
| 108 } | 110 } |
| 109 | 111 |
| 110 scoped_ptr<AudioPacket> CreatePacket48000Hz(int samples) { | 112 std::unique_ptr<AudioPacket> CreatePacket48000Hz(int samples) { |
| 111 return CreatePacketWithSamplingRate(AudioPacket::SAMPLING_RATE_48000, | 113 return CreatePacketWithSamplingRate(AudioPacket::SAMPLING_RATE_48000, |
| 112 samples); | 114 samples); |
| 113 } | 115 } |
| 114 | 116 |
| 115 TEST_F(AudioPlayerTest, Init) { | 117 TEST_F(AudioPlayerTest, Init) { |
| 116 ASSERT_EQ(0, GetNumQueuedPackets()); | 118 ASSERT_EQ(0, GetNumQueuedPackets()); |
| 117 | 119 |
| 118 audio_->ProcessAudioPacket(CreatePacket44100Hz(10)); | 120 audio_->ProcessAudioPacket(CreatePacket44100Hz(10)); |
| 119 ASSERT_EQ(1, GetNumQueuedPackets()); | 121 ASSERT_EQ(1, GetNumQueuedPackets()); |
| 120 } | 122 } |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 | 305 |
| 304 // Attempt to consume a frame of 25 samples. | 306 // Attempt to consume a frame of 25 samples. |
| 305 ConsumeAudioFrame(); | 307 ConsumeAudioFrame(); |
| 306 ASSERT_EQ(0, GetNumQueuedSamples()); | 308 ASSERT_EQ(0, GetNumQueuedSamples()); |
| 307 ASSERT_EQ(0, GetNumQueuedPackets()); | 309 ASSERT_EQ(0, GetNumQueuedPackets()); |
| 308 ASSERT_EQ(0, GetBytesConsumed()); | 310 ASSERT_EQ(0, GetBytesConsumed()); |
| 309 CheckAudioFrameBytes(packet1_samples * kAudioSampleBytes); | 311 CheckAudioFrameBytes(packet1_samples * kAudioSampleBytes); |
| 310 } | 312 } |
| 311 | 313 |
| 312 } // namespace remoting | 314 } // namespace remoting |
| OLD | NEW |