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

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

Issue 22886005: Switch audio synchronization from sleep() based to select() based. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix DCHECK. Created 7 years, 2 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_parameters.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/memory/shared_memory.h" 8 #include "base/memory/shared_memory.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/process/process_handle.h" 10 #include "base/process/process_handle.h"
11 #include "base/sync_socket.h" 11 #include "base/sync_socket.h"
12 #include "base/test/test_timeouts.h" 12 #include "base/test/test_timeouts.h"
13 #include "media/audio/audio_output_device.h" 13 #include "media/audio/audio_output_device.h"
14 #include "media/audio/sample_rates.h" 14 #include "media/audio/sample_rates.h"
15 #include "media/audio/shared_memory_util.h"
16 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
17 #include "testing/gmock_mutant.h" 16 #include "testing/gmock_mutant.h"
18 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
19 18
20 using base::CancelableSyncSocket; 19 using base::CancelableSyncSocket;
21 using base::SharedMemory; 20 using base::SharedMemory;
22 using base::SyncSocket; 21 using base::SyncSocket;
23 using testing::_; 22 using testing::_;
24 using testing::DoAll; 23 using testing::DoAll;
25 using testing::Invoke; 24 using testing::Invoke;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 125
127 int AudioOutputDeviceTest::CalculateMemorySize() { 126 int AudioOutputDeviceTest::CalculateMemorySize() {
128 // Calculate output and input memory size. 127 // Calculate output and input memory size.
129 int output_memory_size = 128 int output_memory_size =
130 AudioBus::CalculateMemorySize(default_audio_parameters_); 129 AudioBus::CalculateMemorySize(default_audio_parameters_);
131 130
132 int frames = default_audio_parameters_.frames_per_buffer(); 131 int frames = default_audio_parameters_.frames_per_buffer();
133 int input_memory_size = 132 int input_memory_size =
134 AudioBus::CalculateMemorySize(input_channels_, frames); 133 AudioBus::CalculateMemorySize(input_channels_, frames);
135 134
136 int io_buffer_size = output_memory_size + input_memory_size; 135 return output_memory_size + input_memory_size;
137
138 // This is where it gets a bit hacky. The shared memory contract between
139 // AudioOutputDevice and its browser side counter part includes a bit more
140 // than just the audio data, so we must call TotalSharedMemorySizeInBytes()
141 // to get the actual size needed to fit the audio data plus the extra data.
142 return TotalSharedMemorySizeInBytes(io_buffer_size);
143 } 136 }
144 137
145 AudioOutputDeviceTest::AudioOutputDeviceTest() 138 AudioOutputDeviceTest::AudioOutputDeviceTest()
146 : synchronized_io_(GetParam()), 139 : synchronized_io_(GetParam()),
147 input_channels_(synchronized_io_ ? 2 : 0) { 140 input_channels_(synchronized_io_ ? 2 : 0) {
148 default_audio_parameters_.Reset( 141 default_audio_parameters_.Reset(
149 AudioParameters::AUDIO_PCM_LINEAR, 142 AudioParameters::AUDIO_PCM_LINEAR,
150 CHANNEL_LAYOUT_STEREO, 2, input_channels_, 143 CHANNEL_LAYOUT_STEREO, 2, input_channels_,
151 48000, 16, 1024); 144 48000, 16, 1024);
152 145
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 // ownership will be transferred and AudioOutputDevice is responsible for 179 // ownership will be transferred and AudioOutputDevice is responsible for
187 // freeing. 180 // freeing.
188 SyncSocket::Handle audio_device_socket = SyncSocket::kInvalidHandle; 181 SyncSocket::Handle audio_device_socket = SyncSocket::kInvalidHandle;
189 ASSERT_TRUE(DuplicateSocketHandle(renderer_socket_.handle(), 182 ASSERT_TRUE(DuplicateSocketHandle(renderer_socket_.handle(),
190 &audio_device_socket)); 183 &audio_device_socket));
191 base::SharedMemoryHandle duplicated_memory_handle; 184 base::SharedMemoryHandle duplicated_memory_handle;
192 ASSERT_TRUE(shared_memory_.ShareToProcess(base::GetCurrentProcessHandle(), 185 ASSERT_TRUE(shared_memory_.ShareToProcess(base::GetCurrentProcessHandle(),
193 &duplicated_memory_handle)); 186 &duplicated_memory_handle));
194 187
195 audio_device_->OnStreamCreated(duplicated_memory_handle, audio_device_socket, 188 audio_device_->OnStreamCreated(duplicated_memory_handle, audio_device_socket,
196 PacketSizeInBytes(kMemorySize)); 189 kMemorySize);
197 io_loop_.RunUntilIdle(); 190 io_loop_.RunUntilIdle();
198 } 191 }
199 192
200 void AudioOutputDeviceTest::ExpectRenderCallback() { 193 void AudioOutputDeviceTest::ExpectRenderCallback() {
201 // We should get a 'play' notification when we call OnStreamCreated(). 194 // We should get a 'play' notification when we call OnStreamCreated().
202 // Respond by asking for some audio data. This should ask our callback 195 // Respond by asking for some audio data. This should ask our callback
203 // to provide some audio data that AudioOutputDevice then writes into the 196 // to provide some audio data that AudioOutputDevice then writes into the
204 // shared memory section. 197 // shared memory section.
205 const int kMemorySize = CalculateMemorySize(); 198 const int kMemorySize = CalculateMemorySize();
206 199
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 ExpectRenderCallback(); 276 ExpectRenderCallback();
284 CreateStream(); 277 CreateStream();
285 WaitUntilRenderCallback(); 278 WaitUntilRenderCallback();
286 StopAudioDevice(); 279 StopAudioDevice();
287 } 280 }
288 281
289 INSTANTIATE_TEST_CASE_P(Render, AudioOutputDeviceTest, Values(false)); 282 INSTANTIATE_TEST_CASE_P(Render, AudioOutputDeviceTest, Values(false));
290 INSTANTIATE_TEST_CASE_P(RenderIO, AudioOutputDeviceTest, Values(true)); 283 INSTANTIATE_TEST_CASE_P(RenderIO, AudioOutputDeviceTest, Values(true));
291 284
292 } // namespace media. 285 } // namespace media.
OLDNEW
« no previous file with comments | « media/audio/audio_output_device.cc ('k') | media/audio/audio_parameters.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698