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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "content/renderer/media/audio_device_factory.h" | |
7 #include "content/renderer/media/audio_renderer_mixer_manager.h" | 6 #include "content/renderer/media/audio_renderer_mixer_manager.h" |
8 #include "media/base/audio_renderer_mixer.h" | 7 #include "media/base/audio_renderer_mixer.h" |
9 #include "media/base/audio_renderer_mixer_input.h" | 8 #include "media/base/audio_renderer_mixer_input.h" |
10 #include "media/base/fake_audio_render_callback.h" | 9 #include "media/base/fake_audio_render_callback.h" |
11 #include "media/base/mock_audio_renderer_sink.h" | 10 #include "media/base/mock_audio_renderer_sink.h" |
12 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
14 | 13 |
15 namespace content { | 14 namespace content { |
16 | 15 |
17 static const int kBitsPerChannel = 16; | 16 static const int kBitsPerChannel = 16; |
18 static const int kSampleRate = 48000; | 17 static const int kSampleRate = 48000; |
19 static const int kBufferSize = 8192; | 18 static const int kBufferSize = 8192; |
20 static const media::ChannelLayout kChannelLayout = media::CHANNEL_LAYOUT_STEREO; | 19 static const media::ChannelLayout kChannelLayout = media::CHANNEL_LAYOUT_STEREO; |
21 | 20 |
22 // By sub-classing AudioDeviceFactory we've overridden the factory to use our | 21 // Subclass AudioRendererMixerManager to inject a mock AudioRendererSink. |
23 // CreateAudioDevice() method globally. | 22 class TestAudioRendererMixerManager : public AudioRendererMixerManager { |
24 class MockAudioRenderSinkFactory : public AudioDeviceFactory { | |
25 public: | 23 public: |
26 MockAudioRenderSinkFactory() {} | 24 TestAudioRendererMixerManager() |
27 virtual ~MockAudioRenderSinkFactory() {} | 25 : AudioRendererMixerManager(kSampleRate, kBufferSize) {} |
| 26 virtual ~TestAudioRendererMixerManager() {} |
28 | 27 |
29 protected: | 28 virtual media::AudioRendererSink* CreateAudioRendererSink() OVERRIDE { |
30 virtual media::MockAudioRendererSink* CreateOutputDevice() OVERRIDE { | 29 // We don't want to deal with instantiating a real AudioOutputDevice since |
| 30 // it's not important to our testing, so use a mock AudioDeviceFactory. |
31 media::MockAudioRendererSink* sink = new media::MockAudioRendererSink(); | 31 media::MockAudioRendererSink* sink = new media::MockAudioRendererSink(); |
32 EXPECT_CALL(*sink, Start()); | 32 EXPECT_CALL(*sink, Start()); |
33 EXPECT_CALL(*sink, Stop()); | 33 EXPECT_CALL(*sink, Stop()); |
34 return sink; | 34 return sink; |
35 } | 35 } |
36 | 36 |
37 virtual media::AudioInputDevice* CreateInputDevice() OVERRIDE { | 37 private: |
38 ADD_FAILURE(); | 38 DISALLOW_COPY_AND_ASSIGN(TestAudioRendererMixerManager); |
39 return NULL; | |
40 } | |
41 | |
42 DISALLOW_COPY_AND_ASSIGN(MockAudioRenderSinkFactory); | |
43 }; | 39 }; |
44 | 40 |
45 class AudioRendererMixerManagerTest : public testing::Test { | 41 class AudioRendererMixerManagerTest : public testing::Test { |
46 public: | 42 public: |
47 AudioRendererMixerManagerTest() { | 43 AudioRendererMixerManagerTest() { |
48 // We don't want to deal with instantiating a real AudioOutputDevice since | 44 manager_.reset(new TestAudioRendererMixerManager()); |
49 // it's not important to our testing, so use a mock AudioDeviceFactory. | |
50 mock_sink_factory_.reset(new MockAudioRenderSinkFactory()); | |
51 manager_.reset(new AudioRendererMixerManager(kSampleRate, kBufferSize)); | |
52 } | 45 } |
53 | 46 |
54 media::AudioRendererMixer* GetMixer(const media::AudioParameters& params) { | 47 media::AudioRendererMixer* GetMixer(const media::AudioParameters& params) { |
55 return manager_->GetMixer(params); | 48 return manager_->GetMixer(params); |
56 } | 49 } |
57 | 50 |
58 void RemoveMixer(const media::AudioParameters& params) { | 51 void RemoveMixer(const media::AudioParameters& params) { |
59 return manager_->RemoveMixer(params); | 52 return manager_->RemoveMixer(params); |
60 } | 53 } |
61 | 54 |
62 // Number of instantiated mixers. | 55 // Number of instantiated mixers. |
63 int mixer_count() { | 56 int mixer_count() { |
64 return manager_->mixers_.size(); | 57 return manager_->mixers_.size(); |
65 } | 58 } |
66 | 59 |
67 protected: | 60 protected: |
68 scoped_ptr<MockAudioRenderSinkFactory> mock_sink_factory_; | |
69 scoped_ptr<AudioRendererMixerManager> manager_; | 61 scoped_ptr<AudioRendererMixerManager> manager_; |
70 | 62 |
71 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerManagerTest); | 63 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerManagerTest); |
72 }; | 64 }; |
73 | 65 |
74 // Verify GetMixer() and RemoveMixer() both work as expected; particularly with | 66 // Verify GetMixer() and RemoveMixer() both work as expected; particularly with |
75 // respect to the explicit ref counting done. | 67 // respect to the explicit ref counting done. |
76 TEST_F(AudioRendererMixerManagerTest, GetRemoveMixer) { | 68 TEST_F(AudioRendererMixerManagerTest, GetRemoveMixer) { |
77 // There should be no mixers outstanding to start with. | 69 // There should be no mixers outstanding to start with. |
78 EXPECT_EQ(mixer_count(), 0); | 70 EXPECT_EQ(mixer_count(), 0); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 media::FakeAudioRenderCallback callback(0); | 119 media::FakeAudioRenderCallback callback(0); |
128 input->Initialize(params, &callback); | 120 input->Initialize(params, &callback); |
129 EXPECT_EQ(mixer_count(), 1); | 121 EXPECT_EQ(mixer_count(), 1); |
130 | 122 |
131 // Destroying the input should destroy the mixer. | 123 // Destroying the input should destroy the mixer. |
132 input = NULL; | 124 input = NULL; |
133 EXPECT_EQ(mixer_count(), 0); | 125 EXPECT_EQ(mixer_count(), 0); |
134 } | 126 } |
135 | 127 |
136 } // namespace content | 128 } // namespace content |
OLD | NEW |