OLD | NEW |
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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 | 127 |
129 int AudioOutputDeviceTest::CalculateMemorySize() { | 128 int AudioOutputDeviceTest::CalculateMemorySize() { |
130 // Calculate output and input memory size. | 129 // Calculate output and input memory size. |
131 int output_memory_size = | 130 int output_memory_size = |
132 AudioBus::CalculateMemorySize(default_audio_parameters_); | 131 AudioBus::CalculateMemorySize(default_audio_parameters_); |
133 | 132 |
134 int frames = default_audio_parameters_.frames_per_buffer(); | 133 int frames = default_audio_parameters_.frames_per_buffer(); |
135 int input_memory_size = | 134 int input_memory_size = |
136 AudioBus::CalculateMemorySize(input_channels_, frames); | 135 AudioBus::CalculateMemorySize(input_channels_, frames); |
137 | 136 |
138 int io_buffer_size = output_memory_size + input_memory_size; | 137 return output_memory_size + input_memory_size; |
139 | |
140 // This is where it gets a bit hacky. The shared memory contract between | |
141 // AudioOutputDevice and its browser side counter part includes a bit more | |
142 // than just the audio data, so we must call TotalSharedMemorySizeInBytes() | |
143 // to get the actual size needed to fit the audio data plus the extra data. | |
144 return TotalSharedMemorySizeInBytes(io_buffer_size); | |
145 } | 138 } |
146 | 139 |
147 AudioOutputDeviceTest::AudioOutputDeviceTest() | 140 AudioOutputDeviceTest::AudioOutputDeviceTest() |
148 : synchronized_io_(GetParam()), | 141 : synchronized_io_(GetParam()), |
149 input_channels_(synchronized_io_ ? 2 : 0) { | 142 input_channels_(synchronized_io_ ? 2 : 0) { |
150 default_audio_parameters_.Reset( | 143 default_audio_parameters_.Reset( |
151 AudioParameters::AUDIO_PCM_LINEAR, | 144 AudioParameters::AUDIO_PCM_LINEAR, |
152 CHANNEL_LAYOUT_STEREO, 2, input_channels_, | 145 CHANNEL_LAYOUT_STEREO, 2, input_channels_, |
153 48000, 16, 1024); | 146 48000, 16, 1024); |
154 | 147 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 // ownership will be transferred and AudioOutputDevice is responsible for | 181 // ownership will be transferred and AudioOutputDevice is responsible for |
189 // freeing. | 182 // freeing. |
190 SyncSocket::Handle audio_device_socket = SyncSocket::kInvalidHandle; | 183 SyncSocket::Handle audio_device_socket = SyncSocket::kInvalidHandle; |
191 ASSERT_TRUE(DuplicateSocketHandle(renderer_socket_.handle(), | 184 ASSERT_TRUE(DuplicateSocketHandle(renderer_socket_.handle(), |
192 &audio_device_socket)); | 185 &audio_device_socket)); |
193 base::SharedMemoryHandle duplicated_memory_handle; | 186 base::SharedMemoryHandle duplicated_memory_handle; |
194 ASSERT_TRUE(shared_memory_.ShareToProcess(base::GetCurrentProcessHandle(), | 187 ASSERT_TRUE(shared_memory_.ShareToProcess(base::GetCurrentProcessHandle(), |
195 &duplicated_memory_handle)); | 188 &duplicated_memory_handle)); |
196 | 189 |
197 audio_device_->OnStreamCreated(duplicated_memory_handle, audio_device_socket, | 190 audio_device_->OnStreamCreated(duplicated_memory_handle, audio_device_socket, |
198 PacketSizeInBytes(kMemorySize)); | 191 kMemorySize); |
199 io_loop_.RunUntilIdle(); | 192 io_loop_.RunUntilIdle(); |
200 } | 193 } |
201 | 194 |
202 void AudioOutputDeviceTest::ExpectRenderCallback() { | 195 void AudioOutputDeviceTest::ExpectRenderCallback() { |
203 // We should get a 'play' notification when we call OnStreamCreated(). | 196 // We should get a 'play' notification when we call OnStreamCreated(). |
204 // Respond by asking for some audio data. This should ask our callback | 197 // Respond by asking for some audio data. This should ask our callback |
205 // to provide some audio data that AudioOutputDevice then writes into the | 198 // to provide some audio data that AudioOutputDevice then writes into the |
206 // shared memory section. | 199 // shared memory section. |
207 const int kMemorySize = CalculateMemorySize(); | 200 const int kMemorySize = CalculateMemorySize(); |
208 | 201 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 ExpectRenderCallback(); | 278 ExpectRenderCallback(); |
286 CreateStream(); | 279 CreateStream(); |
287 WaitUntilRenderCallback(); | 280 WaitUntilRenderCallback(); |
288 StopAudioDevice(); | 281 StopAudioDevice(); |
289 } | 282 } |
290 | 283 |
291 INSTANTIATE_TEST_CASE_P(Render, AudioOutputDeviceTest, Values(false)); | 284 INSTANTIATE_TEST_CASE_P(Render, AudioOutputDeviceTest, Values(false)); |
292 INSTANTIATE_TEST_CASE_P(RenderIO, AudioOutputDeviceTest, Values(true)); | 285 INSTANTIATE_TEST_CASE_P(RenderIO, AudioOutputDeviceTest, Values(true)); |
293 | 286 |
294 } // namespace media. | 287 } // namespace media. |
OLD | NEW |