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 "content/renderer/media/webaudiosourceprovider_impl.h" | 5 #include "content/renderer/media/webaudiosourceprovider_impl.h" |
6 #include "media/audio/audio_parameters.h" | 6 #include "media/audio/audio_parameters.h" |
7 #include "media/base/fake_audio_render_callback.h" | 7 #include "media/base/fake_audio_render_callback.h" |
8 #include "media/base/mock_audio_renderer_sink.h" | 8 #include "media/base/mock_audio_renderer_sink.h" |
9 #include "testing/gmock/include/gmock/gmock.h" | 9 #include "testing/gmock/include/gmock/gmock.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 #include "third_party/WebKit/public/web/WebAudioSourceProviderClient.h" | 11 #include "third_party/WebKit/public/web/WebAudioSourceProviderClient.h" |
12 | 12 |
13 namespace content { | 13 namespace content { |
14 | 14 |
15 namespace { | 15 namespace { |
16 const float kTestVolume = 0.25; | 16 const float kTestVolume = 0.25; |
17 } // namespace | 17 } // namespace |
18 | 18 |
19 class WebAudioSourceProviderImplTest | 19 class WebAudioSourceProviderImplTest |
20 : public testing::Test, | 20 : public testing::Test, |
21 public WebKit::WebAudioSourceProviderClient { | 21 public blink::WebAudioSourceProviderClient { |
22 public: | 22 public: |
23 WebAudioSourceProviderImplTest() | 23 WebAudioSourceProviderImplTest() |
24 : params_(media::AudioParameters::AUDIO_PCM_LINEAR, | 24 : params_(media::AudioParameters::AUDIO_PCM_LINEAR, |
25 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 64), | 25 media::CHANNEL_LAYOUT_STEREO, 48000, 16, 64), |
26 fake_callback_(0.1), | 26 fake_callback_(0.1), |
27 mock_sink_(new media::MockAudioRendererSink()), | 27 mock_sink_(new media::MockAudioRendererSink()), |
28 wasp_impl_(new WebAudioSourceProviderImpl(mock_sink_)) { | 28 wasp_impl_(new WebAudioSourceProviderImpl(mock_sink_)) { |
29 } | 29 } |
30 | 30 |
31 virtual ~WebAudioSourceProviderImplTest() {} | 31 virtual ~WebAudioSourceProviderImplTest() {} |
(...skipping 12 matching lines...) Expand all Loading... |
44 | 44 |
45 EXPECT_CALL(*mock_sink_.get(), SetVolume(kTestVolume)).Times(verify); | 45 EXPECT_CALL(*mock_sink_.get(), SetVolume(kTestVolume)).Times(verify); |
46 wasp_impl_->SetVolume(kTestVolume); | 46 wasp_impl_->SetVolume(kTestVolume); |
47 | 47 |
48 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(verify); | 48 EXPECT_CALL(*mock_sink_.get(), Stop()).Times(verify); |
49 wasp_impl_->Stop(); | 49 wasp_impl_->Stop(); |
50 | 50 |
51 testing::Mock::VerifyAndClear(mock_sink_.get()); | 51 testing::Mock::VerifyAndClear(mock_sink_.get()); |
52 } | 52 } |
53 | 53 |
54 void SetClient(WebKit::WebAudioSourceProviderClient* client) { | 54 void SetClient(blink::WebAudioSourceProviderClient* client) { |
55 testing::InSequence s; | 55 testing::InSequence s; |
56 | 56 |
57 if (client) { | 57 if (client) { |
58 EXPECT_CALL(*mock_sink_.get(), Stop()); | 58 EXPECT_CALL(*mock_sink_.get(), Stop()); |
59 EXPECT_CALL(*this, setFormat(params_.channels(), params_.sample_rate())); | 59 EXPECT_CALL(*this, setFormat(params_.channels(), params_.sample_rate())); |
60 } | 60 } |
61 wasp_impl_->setClient(client); | 61 wasp_impl_->setClient(client); |
62 | 62 |
63 testing::Mock::VerifyAndClear(mock_sink_.get()); | 63 testing::Mock::VerifyAndClear(mock_sink_.get()); |
64 testing::Mock::VerifyAndClear(this); | 64 testing::Mock::VerifyAndClear(this); |
65 } | 65 } |
66 | 66 |
67 bool CompareBusses(const media::AudioBus* bus1, const media::AudioBus* bus2) { | 67 bool CompareBusses(const media::AudioBus* bus1, const media::AudioBus* bus2) { |
68 EXPECT_EQ(bus1->channels(), bus2->channels()); | 68 EXPECT_EQ(bus1->channels(), bus2->channels()); |
69 EXPECT_EQ(bus1->frames(), bus2->frames()); | 69 EXPECT_EQ(bus1->frames(), bus2->frames()); |
70 for (int ch = 0; ch < bus1->channels(); ++ch) { | 70 for (int ch = 0; ch < bus1->channels(); ++ch) { |
71 if (memcmp(bus1->channel(ch), bus2->channel(ch), | 71 if (memcmp(bus1->channel(ch), bus2->channel(ch), |
72 sizeof(*bus1->channel(ch)) * bus1->frames()) != 0) { | 72 sizeof(*bus1->channel(ch)) * bus1->frames()) != 0) { |
73 return false; | 73 return false; |
74 } | 74 } |
75 } | 75 } |
76 return true; | 76 return true; |
77 } | 77 } |
78 | 78 |
79 // WebKit::WebAudioSourceProviderClient implementation. | 79 // blink::WebAudioSourceProviderClient implementation. |
80 MOCK_METHOD2(setFormat, void(size_t numberOfChannels, float sampleRate)); | 80 MOCK_METHOD2(setFormat, void(size_t numberOfChannels, float sampleRate)); |
81 | 81 |
82 protected: | 82 protected: |
83 media::AudioParameters params_; | 83 media::AudioParameters params_; |
84 media::FakeAudioRenderCallback fake_callback_; | 84 media::FakeAudioRenderCallback fake_callback_; |
85 scoped_refptr<media::MockAudioRendererSink> mock_sink_; | 85 scoped_refptr<media::MockAudioRendererSink> mock_sink_; |
86 scoped_refptr<WebAudioSourceProviderImpl> wasp_impl_; | 86 scoped_refptr<WebAudioSourceProviderImpl> wasp_impl_; |
87 | 87 |
88 DISALLOW_COPY_AND_ASSIGN(WebAudioSourceProviderImplTest); | 88 DISALLOW_COPY_AND_ASSIGN(WebAudioSourceProviderImplTest); |
89 }; | 89 }; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 EXPECT_CALL(*mock_sink_.get(), Play()); | 146 EXPECT_CALL(*mock_sink_.get(), Play()); |
147 SetClient(NULL); | 147 SetClient(NULL); |
148 } | 148 } |
149 | 149 |
150 // Test the AudioRendererSink state machine and its effects on provideInput(). | 150 // Test the AudioRendererSink state machine and its effects on provideInput(). |
151 TEST_F(WebAudioSourceProviderImplTest, ProvideInput) { | 151 TEST_F(WebAudioSourceProviderImplTest, ProvideInput) { |
152 scoped_ptr<media::AudioBus> bus1 = media::AudioBus::Create(params_); | 152 scoped_ptr<media::AudioBus> bus1 = media::AudioBus::Create(params_); |
153 scoped_ptr<media::AudioBus> bus2 = media::AudioBus::Create(params_); | 153 scoped_ptr<media::AudioBus> bus2 = media::AudioBus::Create(params_); |
154 | 154 |
155 // Point the WebVector into memory owned by |bus1|. | 155 // Point the WebVector into memory owned by |bus1|. |
156 WebKit::WebVector<float*> audio_data(static_cast<size_t>(bus1->channels())); | 156 blink::WebVector<float*> audio_data(static_cast<size_t>(bus1->channels())); |
157 for (size_t i = 0; i < audio_data.size(); ++i) | 157 for (size_t i = 0; i < audio_data.size(); ++i) |
158 audio_data[i] = bus1->channel(i); | 158 audio_data[i] = bus1->channel(i); |
159 | 159 |
160 // Verify provideInput() works before Initialize() and returns silence. | 160 // Verify provideInput() works before Initialize() and returns silence. |
161 bus1->channel(0)[0] = 1; | 161 bus1->channel(0)[0] = 1; |
162 bus2->Zero(); | 162 bus2->Zero(); |
163 wasp_impl_->provideInput(audio_data, params_.frames_per_buffer()); | 163 wasp_impl_->provideInput(audio_data, params_.frames_per_buffer()); |
164 ASSERT_TRUE(CompareBusses(bus1.get(), bus2.get())); | 164 ASSERT_TRUE(CompareBusses(bus1.get(), bus2.get())); |
165 | 165 |
166 wasp_impl_->Initialize(params_, &fake_callback_); | 166 wasp_impl_->Initialize(params_, &fake_callback_); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
212 ASSERT_FALSE(CompareBusses(bus1.get(), bus2.get())); | 212 ASSERT_FALSE(CompareBusses(bus1.get(), bus2.get())); |
213 | 213 |
214 // Stop() should return silence. | 214 // Stop() should return silence. |
215 wasp_impl_->Stop(); | 215 wasp_impl_->Stop(); |
216 bus1->channel(0)[0] = 1; | 216 bus1->channel(0)[0] = 1; |
217 wasp_impl_->provideInput(audio_data, params_.frames_per_buffer()); | 217 wasp_impl_->provideInput(audio_data, params_.frames_per_buffer()); |
218 ASSERT_TRUE(CompareBusses(bus1.get(), bus2.get())); | 218 ASSERT_TRUE(CompareBusses(bus1.get(), bus2.get())); |
219 } | 219 } |
220 | 220 |
221 } // namespace content | 221 } // namespace content |
OLD | NEW |