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> |
| 8 |
7 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
8 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
10 | 12 |
11 namespace { | 13 namespace { |
12 | 14 |
13 const int kAudioSamplesPerFrame = 25; | 15 const int kAudioSamplesPerFrame = 25; |
14 const int kAudioSampleBytes = 4; | 16 const int kAudioSampleBytes = 4; |
15 const int kAudioFrameBytes = kAudioSamplesPerFrame * kAudioSampleBytes; | 17 const int kAudioFrameBytes = kAudioSamplesPerFrame * kAudioSampleBytes; |
16 const int kPaddingBytes = 16; | 18 const int kPaddingBytes = 16; |
17 | 19 |
18 // TODO(garykac): Generate random audio data in the tests rather than having | 20 // TODO(garykac): Generate random audio data in the tests rather than having |
19 // a single constant value. | 21 // a single constant value. |
20 const uint8 kDefaultBufferData = 0x5A; | 22 const uint8_t kDefaultBufferData = 0x5A; |
21 const uint8 kDummyAudioData = 0x8B; | 23 const uint8_t kDummyAudioData = 0x8B; |
22 | 24 |
23 } // namespace | 25 } // namespace |
24 | 26 |
25 namespace remoting { | 27 namespace remoting { |
26 | 28 |
27 class FakeAudioPlayer : public AudioPlayer { | 29 class FakeAudioPlayer : public AudioPlayer { |
28 public: | 30 public: |
29 FakeAudioPlayer() { | 31 FakeAudioPlayer() { |
30 } | 32 } |
31 | 33 |
32 bool ResetAudioPlayer(AudioPacket::SamplingRate) override { return true; } | 34 bool ResetAudioPlayer(AudioPacket::SamplingRate) override { return true; } |
33 | 35 |
34 uint32 GetSamplesPerFrame() override { return kAudioSamplesPerFrame; } | 36 uint32_t GetSamplesPerFrame() override { return kAudioSamplesPerFrame; } |
35 }; | 37 }; |
36 | 38 |
37 class AudioPlayerTest : public ::testing::Test { | 39 class AudioPlayerTest : public ::testing::Test { |
38 protected: | 40 protected: |
39 void SetUp() override { | 41 void SetUp() override { |
40 audio_.reset(new FakeAudioPlayer()); | 42 audio_.reset(new FakeAudioPlayer()); |
41 buffer_.reset(new char[kAudioFrameBytes + kPaddingBytes]); | 43 buffer_.reset(new char[kAudioFrameBytes + kPaddingBytes]); |
42 } | 44 } |
43 | 45 |
44 void TearDown() override {} | 46 void TearDown() override {} |
45 | 47 |
46 void ConsumeAudioFrame() { | 48 void ConsumeAudioFrame() { |
47 uint8* buffer = reinterpret_cast<uint8*>(buffer_.get()); | 49 uint8_t* buffer = reinterpret_cast<uint8_t*>(buffer_.get()); |
48 memset(buffer, kDefaultBufferData, kAudioFrameBytes + kPaddingBytes); | 50 memset(buffer, kDefaultBufferData, kAudioFrameBytes + kPaddingBytes); |
49 AudioPlayer::AudioPlayerCallback(reinterpret_cast<void*>(buffer_.get()), | 51 AudioPlayer::AudioPlayerCallback(reinterpret_cast<void*>(buffer_.get()), |
50 kAudioFrameBytes, | 52 kAudioFrameBytes, |
51 reinterpret_cast<void*>(audio_.get())); | 53 reinterpret_cast<void*>(audio_.get())); |
52 // Verify we haven't written beyond the end of the buffer. | 54 // Verify we haven't written beyond the end of the buffer. |
53 for (int i = 0; i < kPaddingBytes; i++) | 55 for (int i = 0; i < kPaddingBytes; i++) |
54 ASSERT_EQ(kDefaultBufferData, *(buffer + kAudioFrameBytes + i)); | 56 ASSERT_EQ(kDefaultBufferData, *(buffer + kAudioFrameBytes + i)); |
55 } | 57 } |
56 | 58 |
57 // Check that the first |num_bytes| bytes are filled with audio data and | 59 // Check that the first |num_bytes| bytes are filled with audio data and |
58 // the rest of the buffer is zero-filled. | 60 // the rest of the buffer is zero-filled. |
59 void CheckAudioFrameBytes(int num_bytes) { | 61 void CheckAudioFrameBytes(int num_bytes) { |
60 uint8* buffer = reinterpret_cast<uint8*>(buffer_.get()); | 62 uint8_t* buffer = reinterpret_cast<uint8_t*>(buffer_.get()); |
61 int i = 0; | 63 int i = 0; |
62 for (; i < num_bytes; i++) { | 64 for (; i < num_bytes; i++) { |
63 ASSERT_EQ(kDummyAudioData, *(buffer + i)); | 65 ASSERT_EQ(kDummyAudioData, *(buffer + i)); |
64 } | 66 } |
65 // Rest of audio frame must be filled with '0's. | 67 // Rest of audio frame must be filled with '0's. |
66 for (; i < kAudioFrameBytes; i++) { | 68 for (; i < kAudioFrameBytes; i++) { |
67 ASSERT_EQ(0, *(buffer + i)); | 69 ASSERT_EQ(0, *(buffer + i)); |
68 } | 70 } |
69 } | 71 } |
70 | 72 |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 | 303 |
302 // Attempt to consume a frame of 25 samples. | 304 // Attempt to consume a frame of 25 samples. |
303 ConsumeAudioFrame(); | 305 ConsumeAudioFrame(); |
304 ASSERT_EQ(0, GetNumQueuedSamples()); | 306 ASSERT_EQ(0, GetNumQueuedSamples()); |
305 ASSERT_EQ(0, GetNumQueuedPackets()); | 307 ASSERT_EQ(0, GetNumQueuedPackets()); |
306 ASSERT_EQ(0, GetBytesConsumed()); | 308 ASSERT_EQ(0, GetBytesConsumed()); |
307 CheckAudioFrameBytes(packet1_samples * kAudioSampleBytes); | 309 CheckAudioFrameBytes(packet1_samples * kAudioSampleBytes); |
308 } | 310 } |
309 | 311 |
310 } // namespace remoting | 312 } // namespace remoting |
OLD | NEW |