OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/copresence/mediums/audio/audio_player.h" | 5 #include "components/copresence/mediums/audio/audio_player.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
9 #include "components/copresence/public/copresence_constants.h" | 9 #include "components/copresence/public/copresence_constants.h" |
10 #include "components/copresence/test/audio_test_support.h" | 10 #include "components/copresence/test/audio_test_support.h" |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 public: | 74 public: |
75 AudioPlayerTest() : buffer_index_(0), player_(NULL) { | 75 AudioPlayerTest() : buffer_index_(0), player_(NULL) { |
76 if (!media::AudioManager::Get()) | 76 if (!media::AudioManager::Get()) |
77 media::AudioManager::CreateForTesting(); | 77 media::AudioManager::CreateForTesting(); |
78 } | 78 } |
79 | 79 |
80 virtual ~AudioPlayerTest() { DeletePlayer(); } | 80 virtual ~AudioPlayerTest() { DeletePlayer(); } |
81 | 81 |
82 void CreatePlayer() { | 82 void CreatePlayer() { |
83 DeletePlayer(); | 83 DeletePlayer(); |
84 player_ = new AudioPlayer(); | 84 player_ = new AudioPlayerImpl(); |
85 player_->set_output_stream_for_testing(new TestAudioOutputStream( | 85 player_->set_output_stream_for_testing(new TestAudioOutputStream( |
86 kDefaultFrameCount, | 86 kDefaultFrameCount, |
87 kMaxFrameCount, | 87 kMaxFrameCount, |
88 base::Bind(&AudioPlayerTest::GatherSamples, AsWeakPtr()))); | 88 base::Bind(&AudioPlayerTest::GatherSamples, AsWeakPtr()))); |
89 player_->Initialize(); | 89 player_->Initialize(); |
90 } | 90 } |
91 | 91 |
92 void DeletePlayer() { | 92 void DeletePlayer() { |
93 if (!player_) | 93 if (!player_) |
94 return; | 94 return; |
(...skipping 27 matching lines...) Expand all Loading... |
122 player_->FlushAudioLoopForTesting(); | 122 player_->FlushAudioLoopForTesting(); |
123 return player_->is_playing_; | 123 return player_->is_playing_; |
124 } | 124 } |
125 | 125 |
126 static const int kDefaultFrameCount = 1024; | 126 static const int kDefaultFrameCount = 1024; |
127 static const int kMaxFrameCount = 1024 * 10; | 127 static const int kMaxFrameCount = 1024 * 10; |
128 | 128 |
129 scoped_ptr<media::AudioBus> buffer_; | 129 scoped_ptr<media::AudioBus> buffer_; |
130 int buffer_index_; | 130 int buffer_index_; |
131 | 131 |
132 AudioPlayer* player_; | 132 AudioPlayerImpl* player_; |
133 base::MessageLoop message_loop_; | 133 base::MessageLoop message_loop_; |
134 }; | 134 }; |
135 | 135 |
136 TEST_F(AudioPlayerTest, BasicPlayAndStop) { | 136 TEST_F(AudioPlayerTest, BasicPlayAndStop) { |
137 CreatePlayer(); | 137 CreatePlayer(); |
138 scoped_refptr<media::AudioBusRefCounted> samples = | 138 scoped_refptr<media::AudioBusRefCounted> samples = |
139 media::AudioBusRefCounted::Create(1, 7331); | 139 media::AudioBusRefCounted::Create(1, 7331); |
140 | 140 |
141 player_->Play(samples); | 141 player_->Play(samples); |
142 EXPECT_TRUE(IsPlaying()); | 142 EXPECT_TRUE(IsPlaying()); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 TEST_F(AudioPlayerTest, PlayingEndToEnd) { | 180 TEST_F(AudioPlayerTest, PlayingEndToEnd) { |
181 const int kNumSamples = kDefaultFrameCount * 10; | 181 const int kNumSamples = kDefaultFrameCount * 10; |
182 CreatePlayer(); | 182 CreatePlayer(); |
183 | 183 |
184 PlayAndVerifySamples(CreateRandomAudioRefCounted(0x1337, 1, kNumSamples)); | 184 PlayAndVerifySamples(CreateRandomAudioRefCounted(0x1337, 1, kNumSamples)); |
185 | 185 |
186 DeletePlayer(); | 186 DeletePlayer(); |
187 } | 187 } |
188 | 188 |
189 } // namespace copresence | 189 } // namespace copresence |
OLD | NEW |