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

Side by Side Diff: media/audio/audio_output_device_unittest.cc

Issue 11878032: Plumb |input_channels| all the way to AudioManager (Closed) 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
« no previous file with comments | « media/audio/audio_output_device.cc ('k') | media/audio/audio_output_ipc.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <vector> 5 #include <vector>
6 6
7 #include "base/at_exit.h" 7 #include "base/at_exit.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/process_util.h" 9 #include "base/process_util.h"
10 #include "base/shared_memory.h" 10 #include "base/shared_memory.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 }; 45 };
46 46
47 class MockAudioOutputIPC : public AudioOutputIPC { 47 class MockAudioOutputIPC : public AudioOutputIPC {
48 public: 48 public:
49 MockAudioOutputIPC() {} 49 MockAudioOutputIPC() {}
50 virtual ~MockAudioOutputIPC() {} 50 virtual ~MockAudioOutputIPC() {}
51 51
52 MOCK_METHOD1(AddDelegate, int(AudioOutputIPCDelegate* delegate)); 52 MOCK_METHOD1(AddDelegate, int(AudioOutputIPCDelegate* delegate));
53 MOCK_METHOD1(RemoveDelegate, void(int stream_id)); 53 MOCK_METHOD1(RemoveDelegate, void(int stream_id));
54 54
55 MOCK_METHOD3(CreateStream, 55 MOCK_METHOD2(CreateStream,
56 void(int stream_id, const AudioParameters& params, int input_channels)); 56 void(int stream_id, const AudioParameters& params));
57 MOCK_METHOD1(PlayStream, void(int stream_id)); 57 MOCK_METHOD1(PlayStream, void(int stream_id));
58 MOCK_METHOD1(CloseStream, void(int stream_id)); 58 MOCK_METHOD1(CloseStream, void(int stream_id));
59 MOCK_METHOD2(SetVolume, void(int stream_id, double volume)); 59 MOCK_METHOD2(SetVolume, void(int stream_id, double volume));
60 MOCK_METHOD1(PauseStream, void(int stream_id)); 60 MOCK_METHOD1(PauseStream, void(int stream_id));
61 MOCK_METHOD1(FlushStream, void(int stream_id)); 61 MOCK_METHOD1(FlushStream, void(int stream_id));
62 }; 62 };
63 63
64 // Creates a copy of a SyncSocket handle that we can give to AudioOutputDevice. 64 // Creates a copy of a SyncSocket handle that we can give to AudioOutputDevice.
65 // On Windows this means duplicating the pipe handle so that AudioOutputDevice 65 // On Windows this means duplicating the pipe handle so that AudioOutputDevice
66 // can call CloseHandle() (since ownership has been transferred), but on other 66 // can call CloseHandle() (since ownership has been transferred), but on other
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 void CreateStream(); 103 void CreateStream();
104 void ExpectRenderCallback(); 104 void ExpectRenderCallback();
105 void WaitUntilRenderCallback(); 105 void WaitUntilRenderCallback();
106 void StopAudioDevice(); 106 void StopAudioDevice();
107 107
108 protected: 108 protected:
109 // Used to clean up TLS pointers that the test(s) will initialize. 109 // Used to clean up TLS pointers that the test(s) will initialize.
110 // Must remain the first member of this class. 110 // Must remain the first member of this class.
111 base::ShadowingAtExitManager at_exit_manager_; 111 base::ShadowingAtExitManager at_exit_manager_;
112 MessageLoopForIO io_loop_; 112 MessageLoopForIO io_loop_;
113 const AudioParameters default_audio_parameters_; 113 AudioParameters default_audio_parameters_;
114 StrictMock<MockRenderCallback> callback_; 114 StrictMock<MockRenderCallback> callback_;
115 StrictMock<MockAudioOutputIPC> audio_output_ipc_; 115 StrictMock<MockAudioOutputIPC> audio_output_ipc_;
116 scoped_refptr<AudioOutputDevice> audio_device_; 116 scoped_refptr<AudioOutputDevice> audio_device_;
117 117
118 private: 118 private:
119 int CalculateMemorySize(); 119 int CalculateMemorySize();
120 120
121 const bool synchronized_io_; 121 const bool synchronized_io_;
122 const int input_channels_; 122 const int input_channels_;
123 SharedMemory shared_memory_; 123 SharedMemory shared_memory_;
(...skipping 17 matching lines...) Expand all
141 int io_buffer_size = output_memory_size + input_memory_size; 141 int io_buffer_size = output_memory_size + input_memory_size;
142 142
143 // This is where it gets a bit hacky. The shared memory contract between 143 // This is where it gets a bit hacky. The shared memory contract between
144 // AudioOutputDevice and its browser side counter part includes a bit more 144 // AudioOutputDevice and its browser side counter part includes a bit more
145 // than just the audio data, so we must call TotalSharedMemorySizeInBytes() 145 // than just the audio data, so we must call TotalSharedMemorySizeInBytes()
146 // to get the actual size needed to fit the audio data plus the extra data. 146 // to get the actual size needed to fit the audio data plus the extra data.
147 return TotalSharedMemorySizeInBytes(io_buffer_size); 147 return TotalSharedMemorySizeInBytes(io_buffer_size);
148 } 148 }
149 149
150 AudioOutputDeviceTest::AudioOutputDeviceTest() 150 AudioOutputDeviceTest::AudioOutputDeviceTest()
151 : default_audio_parameters_(AudioParameters::AUDIO_PCM_LINEAR, 151 : synchronized_io_(GetParam()),
152 CHANNEL_LAYOUT_STEREO,
153 48000, 16, 1024),
154 synchronized_io_(GetParam()),
155 input_channels_(synchronized_io_ ? 2 : 0) { 152 input_channels_(synchronized_io_ ? 2 : 0) {
153 default_audio_parameters_.Reset(
154 AudioParameters::AUDIO_PCM_LINEAR,
155 CHANNEL_LAYOUT_STEREO, input_channels_,
156 48000, 16, 1024);
157
156 EXPECT_CALL(audio_output_ipc_, AddDelegate(_)) 158 EXPECT_CALL(audio_output_ipc_, AddDelegate(_))
157 .WillOnce(Return(kStreamId)); 159 .WillOnce(Return(kStreamId));
158 160
159 audio_device_ = new AudioOutputDevice( 161 audio_device_ = new AudioOutputDevice(
160 &audio_output_ipc_, io_loop_.message_loop_proxy()); 162 &audio_output_ipc_, io_loop_.message_loop_proxy());
161 163
162 if (synchronized_io_) { 164 audio_device_->Initialize(default_audio_parameters_,
163 audio_device_->InitializeIO(default_audio_parameters_, 165 &callback_);
164 input_channels_, 166
165 &callback_);
166 } else {
167 audio_device_->Initialize(default_audio_parameters_,
168 &callback_);
169 }
170 io_loop_.RunUntilIdle(); 167 io_loop_.RunUntilIdle();
171 } 168 }
172 169
173 AudioOutputDeviceTest::~AudioOutputDeviceTest() { 170 AudioOutputDeviceTest::~AudioOutputDeviceTest() {
174 EXPECT_CALL(audio_output_ipc_, RemoveDelegate(kStreamId)); 171 EXPECT_CALL(audio_output_ipc_, RemoveDelegate(kStreamId));
175 172
176 audio_device_ = NULL; 173 audio_device_ = NULL;
177 } 174 }
178 175
179 void AudioOutputDeviceTest::StartAudioDevice() { 176 void AudioOutputDeviceTest::StartAudioDevice() {
180 audio_device_->Start(); 177 audio_device_->Start();
181 178
182 EXPECT_CALL(audio_output_ipc_, CreateStream(kStreamId, _, _)); 179 EXPECT_CALL(audio_output_ipc_, CreateStream(kStreamId, _));
183 180
184 io_loop_.RunUntilIdle(); 181 io_loop_.RunUntilIdle();
185 } 182 }
186 183
187 void AudioOutputDeviceTest::CreateStream() { 184 void AudioOutputDeviceTest::CreateStream() {
188 const int kMemorySize = CalculateMemorySize(); 185 const int kMemorySize = CalculateMemorySize();
189 186
190 ASSERT_TRUE(shared_memory_.CreateAndMapAnonymous(kMemorySize)); 187 ASSERT_TRUE(shared_memory_.CreateAndMapAnonymous(kMemorySize));
191 memset(shared_memory_.memory(), 0xff, kMemorySize); 188 memset(shared_memory_.memory(), 0xff, kMemorySize);
192 189
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 ExpectRenderCallback(); 291 ExpectRenderCallback();
295 CreateStream(); 292 CreateStream();
296 WaitUntilRenderCallback(); 293 WaitUntilRenderCallback();
297 StopAudioDevice(); 294 StopAudioDevice();
298 } 295 }
299 296
300 INSTANTIATE_TEST_CASE_P(Render, AudioOutputDeviceTest, Values(false)); 297 INSTANTIATE_TEST_CASE_P(Render, AudioOutputDeviceTest, Values(false));
301 INSTANTIATE_TEST_CASE_P(RenderIO, AudioOutputDeviceTest, Values(true)); 298 INSTANTIATE_TEST_CASE_P(RenderIO, AudioOutputDeviceTest, Values(true));
302 299
303 } // namespace media. 300 } // namespace media.
OLDNEW
« no previous file with comments | « media/audio/audio_output_device.cc ('k') | media/audio/audio_output_ipc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698