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

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

Issue 12102004: Renderer side audio device change wip... Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 10 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/logging.h"
5 #include "base/memory/ref_counted.h" 6 #include "base/memory/ref_counted.h"
6 #include "base/memory/scoped_ptr.h" 7 #include "base/memory/scoped_ptr.h"
7 #include "content/renderer/media/audio_renderer_mixer_manager.h" 8 #include "content/renderer/media/audio_renderer_mixer_manager.h"
9 #include "media/base/audio_hardware_config.h"
8 #include "media/base/audio_renderer_mixer.h" 10 #include "media/base/audio_renderer_mixer.h"
9 #include "media/base/audio_renderer_mixer_input.h" 11 #include "media/base/audio_renderer_mixer_input.h"
10 #include "media/base/fake_audio_render_callback.h" 12 #include "media/base/fake_audio_render_callback.h"
11 #include "media/base/mock_audio_renderer_sink.h" 13 #include "media/base/mock_audio_renderer_sink.h"
12 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
14 16
15 namespace content { 17 namespace content {
16 18
17 static const int kBitsPerChannel = 16; 19 static const int kBitsPerChannel = 16;
18 static const int kSampleRate = 48000; 20 static const int kSampleRate = 48000;
19 static const int kBufferSize = 8192; 21 static const int kBufferSize = 8192;
20 static const media::ChannelLayout kChannelLayout = media::CHANNEL_LAYOUT_STEREO; 22 static const media::ChannelLayout kChannelLayout = media::CHANNEL_LAYOUT_STEREO;
21 23
22 static const int kRenderViewId = 123; 24 static const int kRenderViewId = 123;
23 static const int kAnotherRenderViewId = 456; 25 static const int kAnotherRenderViewId = 456;
24 26
27 class FakeAudioHardwareConfig : public media::AudioHardwareConfig {
28 public:
29 FakeAudioHardwareConfig() {}
30 virtual ~FakeAudioHardwareConfig() {}
31
32 virtual int GetOutputBufferSize() { return kBufferSize; }
33 virtual int GetOutputSampleRate() { return kSampleRate; }
34
35 virtual int GetInputSampleRate() {
36 NOTIMPLEMENTED();
37 return 0;
38 }
39
40 virtual media::ChannelLayout GetInputChannelLayout() {
41 NOTIMPLEMENTED();
42 return media::CHANNEL_LAYOUT_NONE;
43 }
44 };
45
25 class AudioRendererMixerManagerTest : public testing::Test { 46 class AudioRendererMixerManagerTest : public testing::Test {
26 public: 47 public:
27 AudioRendererMixerManagerTest() { 48 AudioRendererMixerManagerTest() {
28 manager_.reset(new AudioRendererMixerManager(kSampleRate, kBufferSize)); 49 manager_.reset(new AudioRendererMixerManager(&fake_config_));
29 50
30 // 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
31 // it's not important to our testing, so we inject a mock. 52 // it's not important to our testing, so we inject a mock.
32 mock_sink_ = new media::MockAudioRendererSink(); 53 mock_sink_ = new media::MockAudioRendererSink();
33 manager_->SetAudioRendererSinkForTesting(mock_sink_); 54 manager_->SetAudioRendererSinkForTesting(mock_sink_);
34 } 55 }
35 56
36 media::AudioRendererMixer* GetMixer(int source_render_view_id, 57 media::AudioRendererMixer* GetMixer(int source_render_view_id,
37 const media::AudioParameters& params) { 58 const media::AudioParameters& params) {
38 return manager_->GetMixer(source_render_view_id, params); 59 return manager_->GetMixer(source_render_view_id, params);
39 } 60 }
40 61
41 void RemoveMixer(int source_render_view_id, 62 void RemoveMixer(int source_render_view_id,
42 const media::AudioParameters& params) { 63 const media::AudioParameters& params) {
43 return manager_->RemoveMixer(source_render_view_id, params); 64 return manager_->RemoveMixer(source_render_view_id, params);
44 } 65 }
45 66
46 // Number of instantiated mixers. 67 // Number of instantiated mixers.
47 int mixer_count() { 68 int mixer_count() {
48 return manager_->mixers_.size(); 69 return manager_->mixers_.size();
49 } 70 }
50 71
51 protected: 72 protected:
73 FakeAudioHardwareConfig fake_config_;
52 scoped_ptr<AudioRendererMixerManager> manager_; 74 scoped_ptr<AudioRendererMixerManager> manager_;
53 scoped_refptr<media::MockAudioRendererSink> mock_sink_; 75 scoped_refptr<media::MockAudioRendererSink> mock_sink_;
54 76
55 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerManagerTest); 77 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerManagerTest);
56 }; 78 };
57 79
58 // Verify GetMixer() and RemoveMixer() both work as expected; particularly with 80 // Verify GetMixer() and RemoveMixer() both work as expected; particularly with
59 // respect to the explicit ref counting done. 81 // respect to the explicit ref counting done.
60 TEST_F(AudioRendererMixerManagerTest, GetRemoveMixer) { 82 TEST_F(AudioRendererMixerManagerTest, GetRemoveMixer) {
61 // Since we're testing two different sets of parameters, we expect 83 // Since we're testing two different sets of parameters, we expect
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 EXPECT_EQ(mixer_count(), 2); 154 EXPECT_EQ(mixer_count(), 2);
133 155
134 // Destroying the inputs should destroy the mixers. 156 // Destroying the inputs should destroy the mixers.
135 input = NULL; 157 input = NULL;
136 EXPECT_EQ(mixer_count(), 1); 158 EXPECT_EQ(mixer_count(), 1);
137 another_input = NULL; 159 another_input = NULL;
138 EXPECT_EQ(mixer_count(), 0); 160 EXPECT_EQ(mixer_count(), 0);
139 } 161 }
140 162
141 } // namespace content 163 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/audio_renderer_mixer_manager.cc ('k') | content/renderer/media/renderer_audio_hardware_config.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698