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

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

Issue 10636036: Enable renderer side mixing behind a flag. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove new mixer address != old mixer address test. Created 8 years, 5 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
(Empty)
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
3 // found in the LICENSE file.
4
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"
8 #include "media/base/audio_renderer_mixer.h"
9 #include "media/base/audio_renderer_mixer_input.h"
10 #include "media/base/fake_audio_render_callback.h"
11 #include "media/base/mock_audio_renderer_sink.h"
12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14
15 namespace content {
16
17 static const int kBitsPerChannel = 16;
18 static const int kSampleRate = 48000;
19 static const int kBufferSize = 8192;
20 static const ChannelLayout kChannelLayout = CHANNEL_LAYOUT_STEREO;
21
22 // By sub-classing AudioDeviceFactory we've overridden the factory to use our
23 // CreateAudioDevice() method globally.
24 class MockAudioRenderSinkFactory : public AudioDeviceFactory {
25 public:
26 MockAudioRenderSinkFactory() {}
27 virtual ~MockAudioRenderSinkFactory() {}
28
29 protected:
30 virtual media::MockAudioRendererSink* CreateAudioDevice() {
31 media::MockAudioRendererSink* sink = new media::MockAudioRendererSink();
32 EXPECT_CALL(*sink, Start());
33 EXPECT_CALL(*sink, Stop());
34 return sink;
35 }
36
37 DISALLOW_COPY_AND_ASSIGN(MockAudioRenderSinkFactory);
38 };
39
40 class AudioRendererMixerManagerTest : public testing::Test {
41 public:
42 AudioRendererMixerManagerTest() {
43 // We don't want to deal with instantiating a real AudioDevice since it's
44 // not important to our testing, so use a mock AudioDeviceFactory.
45 mock_sink_factory_.reset(new MockAudioRenderSinkFactory());
46 manager_.reset(new AudioRendererMixerManager(kSampleRate, kBufferSize));
47 }
48
49 media::AudioRendererMixer* GetMixer(const media::AudioParameters& params) {
50 return manager_->GetMixer(params);
51 }
52
53 void RemoveMixer(const media::AudioParameters& params) {
54 return manager_->RemoveMixer(params);
55 }
56
57 // Number of instantiated mixers.
58 int mixer_count() {
59 return manager_->mixers_.size();
60 }
61
62 protected:
63 scoped_ptr<MockAudioRenderSinkFactory> mock_sink_factory_;
64 scoped_ptr<AudioRendererMixerManager> manager_;
65
66 DISALLOW_COPY_AND_ASSIGN(AudioRendererMixerManagerTest);
67 };
68
69 // Verify GetMixer() and RemoveMixer() both work as expected; particularly with
70 // respect to the explicit ref counting done.
71 TEST_F(AudioRendererMixerManagerTest, GetRemoveMixer) {
72 // There should be no mixers outstanding to start with.
73 EXPECT_EQ(mixer_count(), 0);
74
75 media::AudioParameters params1(
76 media::AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate,
77 kBitsPerChannel, kBufferSize);
78
79 media::AudioRendererMixer* mixer1 = GetMixer(params1);
80 ASSERT_TRUE(mixer1);
81 EXPECT_EQ(mixer_count(), 1);
82
83 // The same parameters should return the same mixer1.
84 EXPECT_EQ(mixer1, GetMixer(params1));
85 EXPECT_EQ(mixer_count(), 1);
86
87 // Remove the extra mixer we just acquired.
88 RemoveMixer(params1);
89 EXPECT_EQ(mixer_count(), 1);
90
91 media::AudioParameters params2(
92 media::AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate * 2,
93 kBitsPerChannel, kBufferSize * 2);
94 media::AudioRendererMixer* mixer2 = GetMixer(params2);
95 ASSERT_TRUE(mixer2);
96 EXPECT_EQ(mixer_count(), 2);
97
98 // Different parameters should result in a different mixer1.
99 EXPECT_NE(mixer1, mixer2);
100
101 // Remove both outstanding mixers.
102 RemoveMixer(params1);
103 EXPECT_EQ(mixer_count(), 1);
104 RemoveMixer(params2);
105 EXPECT_EQ(mixer_count(), 0);
106 }
107
108 // Verify CreateInput() provides AudioRendererMixerInput with the appropriate
109 // callbacks and they are working as expected.
110 TEST_F(AudioRendererMixerManagerTest, CreateInput) {
111 media::AudioParameters params(
112 media::AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate,
113 kBitsPerChannel, kBufferSize);
114
115 // Create a mixer input and ensure it doesn't instantiate a mixer yet.
116 EXPECT_EQ(mixer_count(), 0);
117 scoped_refptr<media::AudioRendererMixerInput> input(manager_->CreateInput());
118 EXPECT_EQ(mixer_count(), 0);
119
120 // Implicitly test that AudioRendererMixerInput was provided with the expected
121 // callbacks needed to acquire an AudioRendererMixer and remove it.
122 media::FakeAudioRenderCallback callback(0);
123 input->Initialize(params, &callback);
124 EXPECT_EQ(mixer_count(), 1);
125
126 // Destroying the input should destroy the mixer.
127 input = NULL;
128 EXPECT_EQ(mixer_count(), 0);
129 }
130
131 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/audio_renderer_mixer_manager.cc ('k') | content/renderer/media/render_audiosourceprovider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698