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

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

Issue 10836025: Part 1: Plumb render view ID to render host (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address review comments Created 8 years, 4 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 ChannelLayout kChannelLayout = CHANNEL_LAYOUT_STEREO; 20 static const ChannelLayout kChannelLayout = 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(
32 int render_view_id) 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() OVERRIDE {
38 ADD_FAILURE(); 40 ADD_FAILURE();
39 return NULL; 41 return NULL;
40 } 42 }
41 43
42 DISALLOW_COPY_AND_ASSIGN(MockAudioRenderSinkFactory); 44 DISALLOW_COPY_AND_ASSIGN(MockAudioRenderSinkFactory);
43 }; 45 };
44 46
45 class AudioRendererMixerManagerTest : public testing::Test { 47 class AudioRendererMixerManagerTest : public testing::Test {
46 public: 48 public:
47 AudioRendererMixerManagerTest() { 49 AudioRendererMixerManagerTest() {
48 // We don't want to deal with instantiating a real AudioOutputDevice since 50 // 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. 51 // it's not important to our testing, so use a mock AudioDeviceFactory.
50 mock_sink_factory_.reset(new MockAudioRenderSinkFactory()); 52 mock_sink_factory_.reset(new MockAudioRenderSinkFactory());
51 manager_.reset(new AudioRendererMixerManager(kSampleRate, kBufferSize)); 53 manager_.reset(new AudioRendererMixerManager(kSampleRate, kBufferSize));
52 } 54 }
53 55
54 media::AudioRendererMixer* GetMixer(const media::AudioParameters& params) { 56 media::AudioRendererMixer* GetMixer(const media::AudioParameters& params) {
55 return manager_->GetMixer(params); 57 return manager_->GetMixer(kRenderViewId, params);
56 } 58 }
57 59
58 void RemoveMixer(const media::AudioParameters& params) { 60 void RemoveMixer(const media::AudioParameters& params) {
59 return manager_->RemoveMixer(params); 61 return manager_->RemoveMixer(params);
60 } 62 }
61 63
62 // Number of instantiated mixers. 64 // Number of instantiated mixers.
63 int mixer_count() { 65 int mixer_count() {
64 return manager_->mixers_.size(); 66 return manager_->mixers_.size();
65 } 67 }
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 114
113 // Verify CreateInput() provides AudioRendererMixerInput with the appropriate 115 // Verify CreateInput() provides AudioRendererMixerInput with the appropriate
114 // callbacks and they are working as expected. 116 // callbacks and they are working as expected.
115 TEST_F(AudioRendererMixerManagerTest, CreateInput) { 117 TEST_F(AudioRendererMixerManagerTest, CreateInput) {
116 media::AudioParameters params( 118 media::AudioParameters params(
117 media::AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate, 119 media::AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate,
118 kBitsPerChannel, kBufferSize); 120 kBitsPerChannel, kBufferSize);
119 121
120 // Create a mixer input and ensure it doesn't instantiate a mixer yet. 122 // Create a mixer input and ensure it doesn't instantiate a mixer yet.
121 EXPECT_EQ(mixer_count(), 0); 123 EXPECT_EQ(mixer_count(), 0);
122 scoped_refptr<media::AudioRendererMixerInput> input(manager_->CreateInput()); 124 scoped_refptr<media::AudioRendererMixerInput> input(
125 manager_->CreateInput(kRenderViewId));
123 EXPECT_EQ(mixer_count(), 0); 126 EXPECT_EQ(mixer_count(), 0);
124 127
125 // Implicitly test that AudioRendererMixerInput was provided with the expected 128 // Implicitly test that AudioRendererMixerInput was provided with the expected
126 // callbacks needed to acquire an AudioRendererMixer and remove it. 129 // callbacks needed to acquire an AudioRendererMixer and remove it.
127 media::FakeAudioRenderCallback callback(0); 130 media::FakeAudioRenderCallback callback(0);
128 input->Initialize(params, &callback); 131 input->Initialize(params, &callback);
129 EXPECT_EQ(mixer_count(), 1); 132 EXPECT_EQ(mixer_count(), 1);
130 133
131 // Destroying the input should destroy the mixer. 134 // Destroying the input should destroy the mixer.
132 input = NULL; 135 input = NULL;
133 EXPECT_EQ(mixer_count(), 0); 136 EXPECT_EQ(mixer_count(), 0);
134 } 137 }
135 138
136 } // namespace content 139 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698