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

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: Renderer Side Mixing! 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 static const int kBitsPerChannel = 16;
16 static const int kSampleRate = 48000;
17 static const int kBufferSize = 8192;
18 static const ChannelLayout kChannelLayout = CHANNEL_LAYOUT_STEREO;
19
20 // By sub-classing content::AudioDeviceFactory we've overridden the factory to
21 // use our CreateAudioDevice() method globally.
22 class MockAudioRenderSinkFactory : public content::AudioDeviceFactory {
23 virtual media::MockAudioRendererSink* CreateAudioDevice() {
24 media::MockAudioRendererSink* sink = new media::MockAudioRendererSink();
25 EXPECT_CALL(*sink, Start());
26 EXPECT_CALL(*sink, Stop());
27 return sink;
28 }
29 };
30
31 class AudioRendererMixerManagerTest : public testing::Test {
32 public:
33 AudioRendererMixerManagerTest() {
34 // We don't want to deal with instantiating a real AudioDevice since it's
35 // not important to our testing, so use a mock AudioDeviceFactory.
36 mock_sink_factory_.reset(new MockAudioRenderSinkFactory());
37 manager_.reset(new AudioRendererMixerManager());
38 }
39
40 media::AudioRendererMixer* GetMixer(const media::AudioParameters& params) {
41 return manager_->GetMixer(params);
42 }
43
44 void RemoveMixer(const media::AudioParameters& params) {
45 return manager_->RemoveMixer(params);
46 }
47
48 // Number of instantiated mixers.
49 int mixer_count() {
50 return manager_->mixer_map_.size();
51 }
52
53 protected:
54 scoped_ptr<MockAudioRenderSinkFactory> mock_sink_factory_;
55 scoped_ptr<AudioRendererMixerManager> manager_;
56 };
57
58 // Verify GetMixer() and RemoveMixer() both work as expected; particularly with
59 // respect to the explicit ref counting done.
60 TEST_F(AudioRendererMixerManagerTest, GetRemoveMixer) {
61 // There should be no mixers outstanding to start with.
62 EXPECT_EQ(mixer_count(), 0);
63
64 media::AudioParameters params1(
65 media::AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate,
66 kBitsPerChannel, kBufferSize);
67
68 media::AudioRendererMixer* mixer1 = GetMixer(params1);
69 ASSERT_TRUE(mixer1);
70 EXPECT_EQ(mixer_count(), 1);
71
72 // The same parameters should return the same mixer1.
73 EXPECT_EQ(mixer1, GetMixer(params1));
74 EXPECT_EQ(mixer_count(), 1);
75
76 // Remove the extra mixer we just acquired.
77 RemoveMixer(params1);
78 EXPECT_EQ(mixer_count(), 1);
79
80 media::AudioParameters params2(
81 media::AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate * 2,
82 kBitsPerChannel, kBufferSize * 2);
83 media::AudioRendererMixer* mixer2 = GetMixer(params2);
84 ASSERT_TRUE(mixer2);
85 EXPECT_EQ(mixer_count(), 2);
86
87 // Different parameters should result in a different mixer1.
88 EXPECT_NE(mixer1, mixer2);
89
90 // Remove both outstanding mixers.
91 RemoveMixer(params1);
92 EXPECT_EQ(mixer_count(), 1);
93 RemoveMixer(params2);
94 EXPECT_EQ(mixer_count(), 0);
95
96 // Verify the old mixer was actually removed and we get a new one if we send
97 // the same audio parameters again.
98 EXPECT_NE(mixer1, GetMixer(params1));
99 EXPECT_EQ(mixer_count(), 1);
100 RemoveMixer(params1);
101 }
102
103 // Verify CreateInput() provides AudioRendererMixerInput with the appropriate
104 // callbacks and they are working as expected.
105 TEST_F(AudioRendererMixerManagerTest, CreateInput) {
106 media::AudioParameters params(
107 media::AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, kSampleRate,
108 kBitsPerChannel, kBufferSize);
109
110 // Create an a mixer input and ensure it doesn't instantiate a mixer yet.
111 EXPECT_EQ(mixer_count(), 0);
112 scoped_refptr<media::AudioRendererMixerInput> input(manager_->CreateInput());
113 EXPECT_EQ(mixer_count(), 0);
114
115 // Implicitly test that AudioRendererMixerInput was provided with the expected
116 // callbacks needed to acquire an AudioRendererMixer and remove it.
117 media::FakeAudioRenderCallback callback(0);
118 input->Initialize(params, &callback);
119 EXPECT_EQ(mixer_count(), 1);
120
121 // Destroying the input should destroy the mixer.
122 input = NULL;
123 EXPECT_EQ(mixer_count(), 0);
124 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698