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

Side by Side Diff: content/renderer/media/audio_renderer_mixer_manager_unittest.cc

Issue 11166002: Plumb render view ID from audio-related code in renderer through IPCs to AudioRendererHost in brows… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased. Created 8 years, 2 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 | Annotate | Revision Log
OLDNEW
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" 6 #include "content/renderer/media/audio_device_factory.h"
7 #include "content/renderer/media/audio_renderer_mixer_manager.h" 7 #include "content/renderer/media/audio_renderer_mixer_manager.h"
8 #include "media/base/audio_renderer_mixer.h" 8 #include "media/base/audio_renderer_mixer.h"
9 #include "media/base/audio_renderer_mixer_input.h" 9 #include "media/base/audio_renderer_mixer_input.h"
10 #include "media/base/fake_audio_render_callback.h" 10 #include "media/base/fake_audio_render_callback.h"
11 #include "media/base/mock_audio_renderer_sink.h" 11 #include "media/base/mock_audio_renderer_sink.h"
12 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace content { 15 namespace content {
16 16
17 static const int kBitsPerChannel = 16; 17 static const int kBitsPerChannel = 16;
18 static const int kSampleRate = 48000; 18 static const int kSampleRate = 48000;
19 static const int kBufferSize = 8192; 19 static const int kBufferSize = 8192;
20 static const media::ChannelLayout kChannelLayout = media::CHANNEL_LAYOUT_STEREO; 20 static const media::ChannelLayout kChannelLayout = media::CHANNEL_LAYOUT_STEREO;
21 static const int kRenderViewId = -2;
21 22
22 // By sub-classing AudioDeviceFactory we've overridden the factory to use our 23 // By sub-classing AudioDeviceFactory we've overridden the factory to use our
23 // CreateAudioDevice() method globally. 24 // CreateAudioDevice() method globally.
24 class MockAudioRenderSinkFactory : public AudioDeviceFactory { 25 class MockAudioRenderSinkFactory : public AudioDeviceFactory {
25 public: 26 public:
26 MockAudioRenderSinkFactory() {} 27 MockAudioRenderSinkFactory() {}
27 virtual ~MockAudioRenderSinkFactory() {} 28 virtual ~MockAudioRenderSinkFactory() {}
28 29
29 protected: 30 protected:
30 virtual media::MockAudioRendererSink* CreateOutputDevice() OVERRIDE { 31 virtual media::MockAudioRendererSink* CreateOutputDevice(int render_view_id)
32 OVERRIDE {
31 media::MockAudioRendererSink* sink = new media::MockAudioRendererSink(); 33 media::MockAudioRendererSink* sink = new media::MockAudioRendererSink();
32 EXPECT_CALL(*sink, Start()); 34 EXPECT_CALL(*sink, Start());
33 EXPECT_CALL(*sink, Stop()); 35 EXPECT_CALL(*sink, Stop());
34 return sink; 36 return sink;
35 } 37 }
36 38
37 virtual media::AudioInputDevice* CreateInputDevice() OVERRIDE { 39 virtual media::AudioInputDevice* CreateInputDevice(int render_view_id)
40 OVERRIDE {
38 ADD_FAILURE(); 41 ADD_FAILURE();
39 return NULL; 42 return NULL;
40 } 43 }
41 44
42 DISALLOW_COPY_AND_ASSIGN(MockAudioRenderSinkFactory); 45 DISALLOW_COPY_AND_ASSIGN(MockAudioRenderSinkFactory);
43 }; 46 };
44 47
45 class AudioRendererMixerManagerTest : public testing::Test { 48 class AudioRendererMixerManagerTest : public testing::Test {
46 public: 49 public:
47 AudioRendererMixerManagerTest() { 50 AudioRendererMixerManagerTest() {
48 // We don't want to deal with instantiating a real AudioOutputDevice since 51 // We don't want to deal with instantiating a real AudioOutputDevice since
49 // it's not important to our testing, so use a mock AudioDeviceFactory. 52 // it's not important to our testing, so use a mock AudioDeviceFactory.
50 mock_sink_factory_.reset(new MockAudioRenderSinkFactory()); 53 mock_sink_factory_.reset(new MockAudioRenderSinkFactory());
51 manager_.reset(new AudioRendererMixerManager(kSampleRate, kBufferSize)); 54 manager_.reset(new AudioRendererMixerManager(kSampleRate, kBufferSize));
52 } 55 }
53 56
54 media::AudioRendererMixer* GetMixer(const media::AudioParameters& params) { 57 media::AudioRendererMixer* GetMixer(const media::AudioParameters& params) {
55 return manager_->GetMixer(params); 58 return manager_->GetMixer(kRenderViewId, params);
56 } 59 }
57 60
58 void RemoveMixer(const media::AudioParameters& params) { 61 void RemoveMixer(const media::AudioParameters& params) {
59 return manager_->RemoveMixer(params); 62 return manager_->RemoveMixer(kRenderViewId, params);
60 } 63 }
61 64
62 // Number of instantiated mixers. 65 // Number of instantiated mixers.
63 int mixer_count() { 66 int mixer_count() {
64 return manager_->mixers_.size(); 67 int count = 0;
68 typedef AudioRendererMixerManager::AudioRendererMixerMap MixerMap;
69 for (MixerMap::const_iterator it = manager_->mixers_.begin();
70 it != manager_->mixers_.end(); ++it) {
71 count += it->second.size();
72 }
73 return count;
65 } 74 }
66 75
67 protected: 76 protected:
68 scoped_ptr<MockAudioRenderSinkFactory> mock_sink_factory_; 77 scoped_ptr<MockAudioRenderSinkFactory> mock_sink_factory_;
69 scoped_ptr<AudioRendererMixerManager> manager_; 78 scoped_ptr<AudioRendererMixerManager> manager_;
70 79
71 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerManagerTest); 80 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerManagerTest);
72 }; 81 };
73 82
74 // Verify GetMixer() and RemoveMixer() both work as expected; particularly with 83 // Verify GetMixer() and RemoveMixer() both work as expected; particularly with
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 121
113 // Verify CreateInput() provides AudioRendererMixerInput with the appropriate 122 // Verify CreateInput() provides AudioRendererMixerInput with the appropriate
114 // callbacks and they are working as expected. 123 // callbacks and they are working as expected.
115 TEST_F(AudioRendererMixerManagerTest, CreateInput) { 124 TEST_F(AudioRendererMixerManagerTest, CreateInput) {
116 media::AudioParameters params( 125 media::AudioParameters params(
117 media::AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, 126 media::AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate,
118 kBitsPerChannel, kBufferSize); 127 kBitsPerChannel, kBufferSize);
119 128
120 // Create a mixer input and ensure it doesn't instantiate a mixer yet. 129 // Create a mixer input and ensure it doesn't instantiate a mixer yet.
121 EXPECT_EQ(mixer_count(), 0); 130 EXPECT_EQ(mixer_count(), 0);
122 scoped_refptr<media::AudioRendererMixerInput> input(manager_->CreateInput()); 131 scoped_refptr<media::AudioRendererMixerInput> input(
132 manager_->CreateInput(kRenderViewId));
123 EXPECT_EQ(mixer_count(), 0); 133 EXPECT_EQ(mixer_count(), 0);
124 134
125 // Implicitly test that AudioRendererMixerInput was provided with the expected 135 // Implicitly test that AudioRendererMixerInput was provided with the expected
126 // callbacks needed to acquire an AudioRendererMixer and remove it. 136 // callbacks needed to acquire an AudioRendererMixer and remove it.
127 media::FakeAudioRenderCallback callback(0); 137 media::FakeAudioRenderCallback callback(0);
128 input->Initialize(params, &callback); 138 input->Initialize(params, &callback);
129 EXPECT_EQ(mixer_count(), 1); 139 EXPECT_EQ(mixer_count(), 1);
130 140
131 // Destroying the input should destroy the mixer. 141 // Destroying the input should destroy the mixer.
132 input = NULL; 142 input = NULL;
133 EXPECT_EQ(mixer_count(), 0); 143 EXPECT_EQ(mixer_count(), 0);
134 } 144 }
135 145
136 } // namespace content 146 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698