Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(208)

Side by Side Diff: media/blink/webaudiosourceprovider_impl_unittest.cc

Issue 1781043002: media::WebAudioSourceProviderImpl, add support for getting a copy of passing AudioBuses (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: dalecurtis@ comments. Added inner class for Audio tapping: TeeFilter. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "base/bind.h"
7 #include "base/macros.h" 8 #include "base/macros.h"
8 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 10 #include "base/run_loop.h"
10 #include "media/audio/audio_parameters.h" 11 #include "media/audio/audio_parameters.h"
11 #include "media/base/fake_audio_render_callback.h" 12 #include "media/base/fake_audio_render_callback.h"
12 #include "media/base/mock_audio_renderer_sink.h" 13 #include "media/base/mock_audio_renderer_sink.h"
13 #include "media/blink/webaudiosourceprovider_impl.h" 14 #include "media/blink/webaudiosourceprovider_impl.h"
14 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 #include "third_party/WebKit/public/platform/WebAudioSourceProviderClient.h" 17 #include "third_party/WebKit/public/platform/WebAudioSourceProviderClient.h"
17 18
19 using ::testing::_;
20
18 namespace media { 21 namespace media {
19 22
20 namespace { 23 namespace {
21 const float kTestVolume = 0.25; 24 const float kTestVolume = 0.25;
22 } // namespace 25 } // namespace
23 26
24 class WebAudioSourceProviderImplTest 27 class WebAudioSourceProviderImplTest
25 : public testing::Test, 28 : public testing::Test,
26 public blink::WebAudioSourceProviderClient { 29 public blink::WebAudioSourceProviderClient {
27 public: 30 public:
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 sizeof(*bus1->channel(ch)) * bus1->frames()) != 0) { 81 sizeof(*bus1->channel(ch)) * bus1->frames()) != 0) {
79 return false; 82 return false;
80 } 83 }
81 } 84 }
82 return true; 85 return true;
83 } 86 }
84 87
85 // blink::WebAudioSourceProviderClient implementation. 88 // blink::WebAudioSourceProviderClient implementation.
86 MOCK_METHOD2(setFormat, void(size_t numberOfChannels, float sampleRate)); 89 MOCK_METHOD2(setFormat, void(size_t numberOfChannels, float sampleRate));
87 90
91 // CopyAudioCB. Added forwarder method due to GMock troubles with scoped_ptr.
92 MOCK_METHOD4(DoCopyAudioCB,
93 void(AudioBus*,
94 uint32_t delay_milliseconds,
95 int channels,
96 int sample_rate));
97 void OnAudioBus(scoped_ptr<AudioBus> bus,
98 uint32_t delay_milliseconds,
99 int channels,
100 int sample_rate) {
101 DoCopyAudioCB(bus.get(), delay_milliseconds, channels, sample_rate);
102 }
103
104 int Render(AudioBus* audio_bus) {
105 return wasp_impl_->RenderForTesting(audio_bus);
106 }
107
88 protected: 108 protected:
89 AudioParameters params_; 109 AudioParameters params_;
90 FakeAudioRenderCallback fake_callback_; 110 FakeAudioRenderCallback fake_callback_;
91 scoped_refptr<MockAudioRendererSink> mock_sink_; 111 scoped_refptr<MockAudioRendererSink> mock_sink_;
92 scoped_refptr<WebAudioSourceProviderImpl> wasp_impl_; 112 scoped_refptr<WebAudioSourceProviderImpl> wasp_impl_;
93 base::MessageLoop message_loop_; 113 base::MessageLoop message_loop_;
94 114
95 DISALLOW_COPY_AND_ASSIGN(WebAudioSourceProviderImplTest); 115 DISALLOW_COPY_AND_ASSIGN(WebAudioSourceProviderImplTest);
96 }; 116 };
97 117
(...skipping 12 matching lines...) Expand all
110 base::RunLoop().RunUntilIdle(); 130 base::RunLoop().RunUntilIdle();
111 131
112 // setClient() with the same client should do nothing. 132 // setClient() with the same client should do nothing.
113 wasp_impl_->setClient(this); 133 wasp_impl_->setClient(this);
114 base::RunLoop().RunUntilIdle(); 134 base::RunLoop().RunUntilIdle();
115 } 135 }
116 136
117 // Verify AudioRendererSink functionality w/ and w/o a client. 137 // Verify AudioRendererSink functionality w/ and w/o a client.
118 TEST_F(WebAudioSourceProviderImplTest, SinkMethods) { 138 TEST_F(WebAudioSourceProviderImplTest, SinkMethods) {
119 wasp_impl_->Initialize(params_, &fake_callback_); 139 wasp_impl_->Initialize(params_, &fake_callback_);
120 ASSERT_EQ(mock_sink_->callback(), &fake_callback_);
121 140
122 // Without a client all WASP calls should fall through to the underlying sink. 141 // Without a client all WASP calls should fall through to the underlying sink.
123 CallAllSinkMethodsAndVerify(true); 142 CallAllSinkMethodsAndVerify(true);
124 143
125 // With a client no calls should reach the Stop()'d sink. Also, setClient() 144 // With a client no calls should reach the Stop()'d sink. Also, setClient()
126 // should propagate the params provided during Initialize() at call time. 145 // should propagate the params provided during Initialize() at call time.
127 SetClient(this); 146 SetClient(this);
128 CallAllSinkMethodsAndVerify(false); 147 CallAllSinkMethodsAndVerify(false);
129 148
130 // Removing the client should cause WASP to revert to the underlying sink. 149 // Removing the client should cause WASP to revert to the underlying sink.
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 ASSERT_TRUE(CompareBusses(bus1.get(), bus2.get())); 252 ASSERT_TRUE(CompareBusses(bus1.get(), bus2.get()));
234 253
235 // Stop() should return silence. 254 // Stop() should return silence.
236 wasp_impl_->Stop(); 255 wasp_impl_->Stop();
237 bus1->channel(0)[0] = 1; 256 bus1->channel(0)[0] = 1;
238 bus2->Zero(); 257 bus2->Zero();
239 wasp_impl_->provideInput(audio_data, params_.frames_per_buffer()); 258 wasp_impl_->provideInput(audio_data, params_.frames_per_buffer());
240 ASSERT_TRUE(CompareBusses(bus1.get(), bus2.get())); 259 ASSERT_TRUE(CompareBusses(bus1.get(), bus2.get()));
241 } 260 }
242 261
262 // Verify CopyAudioCB is called if registered.
263 TEST_F(WebAudioSourceProviderImplTest, CopyAudioCB) {
264 testing::InSequence s;
265 wasp_impl_->Initialize(params_, &fake_callback_);
266 wasp_impl_->RegisterCopyAudioCallback(base::Bind(
267 &WebAudioSourceProviderImplTest::OnAudioBus, base::Unretained(this)));
268
269 const scoped_ptr<AudioBus> bus1 = AudioBus::Create(params_);
270 EXPECT_CALL(*this,
271 DoCopyAudioCB(_, 0, params_.channels(), params_.sample_rate()))
272 .Times(1);
273 Render(bus1.get());
274
275 wasp_impl_->ResetCopyAudioCallback();
276 EXPECT_CALL(*this, DoCopyAudioCB(_, _, _, _)).Times(0);
277 Render(bus1.get());
278
279 testing::Mock::VerifyAndClear(mock_sink_.get());
280 }
281
243 } // namespace media 282 } // namespace media
OLDNEW
« media/blink/webaudiosourceprovider_impl.cc ('K') | « media/blink/webaudiosourceprovider_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698