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/mediums/audio/audio_player_impl.h" |
9 #include "components/copresence/public/copresence_constants.h" | 10 #include "components/copresence/public/copresence_constants.h" |
10 #include "components/copresence/test/audio_test_support.h" | 11 #include "components/copresence/test/audio_test_support.h" |
11 #include "media/audio/audio_manager.h" | 12 #include "media/audio/audio_manager.h" |
12 #include "media/audio/audio_manager_base.h" | 13 #include "media/audio/audio_manager_base.h" |
13 #include "media/base/audio_bus.h" | 14 #include "media/base/audio_bus.h" |
14 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 class TestAudioOutputStream : public media::AudioOutputStream { | 19 class TestAudioOutputStream : public media::AudioOutputStream { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 public: | 75 public: |
75 AudioPlayerTest() : buffer_index_(0), player_(NULL) { | 76 AudioPlayerTest() : buffer_index_(0), player_(NULL) { |
76 if (!media::AudioManager::Get()) | 77 if (!media::AudioManager::Get()) |
77 media::AudioManager::CreateForTesting(); | 78 media::AudioManager::CreateForTesting(); |
78 } | 79 } |
79 | 80 |
80 virtual ~AudioPlayerTest() { DeletePlayer(); } | 81 virtual ~AudioPlayerTest() { DeletePlayer(); } |
81 | 82 |
82 void CreatePlayer() { | 83 void CreatePlayer() { |
83 DeletePlayer(); | 84 DeletePlayer(); |
84 player_ = new AudioPlayer(); | 85 player_ = new AudioPlayerImpl(); |
85 player_->set_output_stream_for_testing(new TestAudioOutputStream( | 86 player_->set_output_stream_for_testing(new TestAudioOutputStream( |
86 kDefaultFrameCount, | 87 kDefaultFrameCount, |
87 kMaxFrameCount, | 88 kMaxFrameCount, |
88 base::Bind(&AudioPlayerTest::GatherSamples, AsWeakPtr()))); | 89 base::Bind(&AudioPlayerTest::GatherSamples, AsWeakPtr()))); |
89 player_->Initialize(); | 90 player_->Initialize(); |
90 } | 91 } |
91 | 92 |
92 void DeletePlayer() { | 93 void DeletePlayer() { |
93 if (!player_) | 94 if (!player_) |
94 return; | 95 return; |
(...skipping 27 matching lines...) Expand all Loading... |
122 player_->FlushAudioLoopForTesting(); | 123 player_->FlushAudioLoopForTesting(); |
123 return player_->is_playing_; | 124 return player_->is_playing_; |
124 } | 125 } |
125 | 126 |
126 static const int kDefaultFrameCount = 1024; | 127 static const int kDefaultFrameCount = 1024; |
127 static const int kMaxFrameCount = 1024 * 10; | 128 static const int kMaxFrameCount = 1024 * 10; |
128 | 129 |
129 scoped_ptr<media::AudioBus> buffer_; | 130 scoped_ptr<media::AudioBus> buffer_; |
130 int buffer_index_; | 131 int buffer_index_; |
131 | 132 |
132 AudioPlayer* player_; | 133 // Deleted by calling Finalize() on the object. |
| 134 AudioPlayerImpl* player_; |
133 base::MessageLoop message_loop_; | 135 base::MessageLoop message_loop_; |
134 }; | 136 }; |
135 | 137 |
136 TEST_F(AudioPlayerTest, BasicPlayAndStop) { | 138 TEST_F(AudioPlayerTest, BasicPlayAndStop) { |
137 CreatePlayer(); | 139 CreatePlayer(); |
138 scoped_refptr<media::AudioBusRefCounted> samples = | 140 scoped_refptr<media::AudioBusRefCounted> samples = |
139 media::AudioBusRefCounted::Create(1, 7331); | 141 media::AudioBusRefCounted::Create(1, 7331); |
140 | 142 |
141 player_->Play(samples); | 143 player_->Play(samples); |
142 EXPECT_TRUE(IsPlaying()); | 144 EXPECT_TRUE(IsPlaying()); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 TEST_F(AudioPlayerTest, PlayingEndToEnd) { | 182 TEST_F(AudioPlayerTest, PlayingEndToEnd) { |
181 const int kNumSamples = kDefaultFrameCount * 10; | 183 const int kNumSamples = kDefaultFrameCount * 10; |
182 CreatePlayer(); | 184 CreatePlayer(); |
183 | 185 |
184 PlayAndVerifySamples(CreateRandomAudioRefCounted(0x1337, 1, kNumSamples)); | 186 PlayAndVerifySamples(CreateRandomAudioRefCounted(0x1337, 1, kNumSamples)); |
185 | 187 |
186 DeletePlayer(); | 188 DeletePlayer(); |
187 } | 189 } |
188 | 190 |
189 } // namespace copresence | 191 } // namespace copresence |
OLD | NEW |