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

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

Powered by Google App Engine
This is Rietveld 408576698