| 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "base/synchronization/waitable_event.h" | 7 #include "base/synchronization/waitable_event.h" |
| 8 #include "base/win/scoped_co_mem.h" | 8 #include "base/win/scoped_co_mem.h" |
| 9 #include "base/win/scoped_com_initializer.h" | 9 #include "base/win/scoped_com_initializer.h" |
| 10 #include "base/win/scoped_handle.h" | 10 #include "base/win/scoped_handle.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 {eRender, eConsole}, | 66 {eRender, eConsole}, |
| 67 {eRender, eCommunications}, | 67 {eRender, eCommunications}, |
| 68 {eRender, eMultimedia}, | 68 {eRender, eMultimedia}, |
| 69 {eCapture, eConsole}, | 69 {eCapture, eConsole}, |
| 70 {eCapture, eCommunications}, | 70 {eCapture, eCommunications}, |
| 71 {eCapture, eMultimedia} | 71 {eCapture, eMultimedia} |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 // Create default devices for all flow/role combinations above. | 74 // Create default devices for all flow/role combinations above. |
| 75 ScopedComPtr<IMMDevice> audio_device; | 75 ScopedComPtr<IMMDevice> audio_device; |
| 76 for (int i = 0; i < arraysize(data); ++i) { | 76 for (size_t i = 0; i < arraysize(data); ++i) { |
| 77 audio_device = | 77 audio_device = |
| 78 CoreAudioUtil::CreateDefaultDevice(data[i].flow, data[i].role); | 78 CoreAudioUtil::CreateDefaultDevice(data[i].flow, data[i].role); |
| 79 EXPECT_TRUE(audio_device.get()); | 79 EXPECT_TRUE(audio_device.get()); |
| 80 EXPECT_EQ(data[i].flow, CoreAudioUtil::GetDataFlow(audio_device.get())); | 80 EXPECT_EQ(data[i].flow, CoreAudioUtil::GetDataFlow(audio_device.get())); |
| 81 } | 81 } |
| 82 | 82 |
| 83 // Only eRender and eCapture are allowed as flow parameter. | 83 // Only eRender and eCapture are allowed as flow parameter. |
| 84 audio_device = CoreAudioUtil::CreateDefaultDevice(eAll, eConsole); | 84 audio_device = CoreAudioUtil::CreateDefaultDevice(eAll, eConsole); |
| 85 EXPECT_FALSE(audio_device.get()); | 85 EXPECT_FALSE(audio_device.get()); |
| 86 } | 86 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 } data[] = { | 118 } data[] = { |
| 119 {eRender, eConsole}, | 119 {eRender, eConsole}, |
| 120 {eRender, eCommunications}, | 120 {eRender, eCommunications}, |
| 121 {eCapture, eConsole}, | 121 {eCapture, eConsole}, |
| 122 {eCapture, eCommunications} | 122 {eCapture, eCommunications} |
| 123 }; | 123 }; |
| 124 | 124 |
| 125 // Get name and ID of default devices for all flow/role combinations above. | 125 // Get name and ID of default devices for all flow/role combinations above. |
| 126 ScopedComPtr<IMMDevice> audio_device; | 126 ScopedComPtr<IMMDevice> audio_device; |
| 127 AudioDeviceName device_name; | 127 AudioDeviceName device_name; |
| 128 for (int i = 0; i < arraysize(data); ++i) { | 128 for (size_t i = 0; i < arraysize(data); ++i) { |
| 129 audio_device = | 129 audio_device = |
| 130 CoreAudioUtil::CreateDefaultDevice(data[i].flow, data[i].role); | 130 CoreAudioUtil::CreateDefaultDevice(data[i].flow, data[i].role); |
| 131 EXPECT_TRUE(SUCCEEDED( | 131 EXPECT_TRUE(SUCCEEDED( |
| 132 CoreAudioUtil::GetDeviceName(audio_device.get(), &device_name))); | 132 CoreAudioUtil::GetDeviceName(audio_device.get(), &device_name))); |
| 133 EXPECT_FALSE(device_name.device_name.empty()); | 133 EXPECT_FALSE(device_name.device_name.empty()); |
| 134 EXPECT_FALSE(device_name.unique_id.empty()); | 134 EXPECT_FALSE(device_name.unique_id.empty()); |
| 135 } | 135 } |
| 136 } | 136 } |
| 137 | 137 |
| 138 TEST_F(CoreAudioUtilWinTest, GetAudioControllerID) { | 138 TEST_F(CoreAudioUtilWinTest, GetAudioControllerID) { |
| 139 ABORT_AUDIO_TEST_IF_NOT(DevicesAvailable()); | 139 ABORT_AUDIO_TEST_IF_NOT(DevicesAvailable()); |
| 140 | 140 |
| 141 ScopedComPtr<IMMDeviceEnumerator> enumerator( | 141 ScopedComPtr<IMMDeviceEnumerator> enumerator( |
| 142 CoreAudioUtil::CreateDeviceEnumerator()); | 142 CoreAudioUtil::CreateDeviceEnumerator()); |
| 143 ASSERT_TRUE(enumerator.get()); | 143 ASSERT_TRUE(enumerator.get()); |
| 144 | 144 |
| 145 // Enumerate all active input and output devices and fetch the ID of | 145 // Enumerate all active input and output devices and fetch the ID of |
| 146 // the associated device. | 146 // the associated device. |
| 147 EDataFlow flows[] = { eRender , eCapture }; | 147 EDataFlow flows[] = { eRender , eCapture }; |
| 148 for (int i = 0; i < arraysize(flows); ++i) { | 148 for (size_t i = 0; i < arraysize(flows); ++i) { |
| 149 ScopedComPtr<IMMDeviceCollection> collection; | 149 ScopedComPtr<IMMDeviceCollection> collection; |
| 150 ASSERT_TRUE(SUCCEEDED(enumerator->EnumAudioEndpoints(flows[i], | 150 ASSERT_TRUE(SUCCEEDED(enumerator->EnumAudioEndpoints(flows[i], |
| 151 DEVICE_STATE_ACTIVE, collection.Receive()))); | 151 DEVICE_STATE_ACTIVE, collection.Receive()))); |
| 152 UINT count = 0; | 152 UINT count = 0; |
| 153 collection->GetCount(&count); | 153 collection->GetCount(&count); |
| 154 for (UINT j = 0; j < count; ++j) { | 154 for (UINT j = 0; j < count; ++j) { |
| 155 ScopedComPtr<IMMDevice> device; | 155 ScopedComPtr<IMMDevice> device; |
| 156 collection->Item(j, device.Receive()); | 156 collection->Item(j, device.Receive()); |
| 157 std::string controller_id( | 157 std::string controller_id( |
| 158 CoreAudioUtil::GetAudioControllerID(device.get(), enumerator.get())); | 158 CoreAudioUtil::GetAudioControllerID(device.get(), enumerator.get())); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 const std::string id = name.unique_id; | 198 const std::string id = name.unique_id; |
| 199 EXPECT_TRUE(CoreAudioUtil::DeviceIsDefault(eRender, eConsole, id)); | 199 EXPECT_TRUE(CoreAudioUtil::DeviceIsDefault(eRender, eConsole, id)); |
| 200 EXPECT_FALSE(CoreAudioUtil::DeviceIsDefault(eCapture, eConsole, id)); | 200 EXPECT_FALSE(CoreAudioUtil::DeviceIsDefault(eCapture, eConsole, id)); |
| 201 } | 201 } |
| 202 | 202 |
| 203 TEST_F(CoreAudioUtilWinTest, CreateDefaultClient) { | 203 TEST_F(CoreAudioUtilWinTest, CreateDefaultClient) { |
| 204 ABORT_AUDIO_TEST_IF_NOT(DevicesAvailable()); | 204 ABORT_AUDIO_TEST_IF_NOT(DevicesAvailable()); |
| 205 | 205 |
| 206 EDataFlow data[] = {eRender, eCapture}; | 206 EDataFlow data[] = {eRender, eCapture}; |
| 207 | 207 |
| 208 for (int i = 0; i < arraysize(data); ++i) { | 208 for (size_t i = 0; i < arraysize(data); ++i) { |
| 209 ScopedComPtr<IAudioClient> client; | 209 ScopedComPtr<IAudioClient> client; |
| 210 client = CoreAudioUtil::CreateDefaultClient(data[i], eConsole); | 210 client = CoreAudioUtil::CreateDefaultClient(data[i], eConsole); |
| 211 EXPECT_TRUE(client.get()); | 211 EXPECT_TRUE(client.get()); |
| 212 } | 212 } |
| 213 } | 213 } |
| 214 | 214 |
| 215 TEST_F(CoreAudioUtilWinTest, CreateClient) { | 215 TEST_F(CoreAudioUtilWinTest, CreateClient) { |
| 216 ABORT_AUDIO_TEST_IF_NOT(DevicesAvailable()); | 216 ABORT_AUDIO_TEST_IF_NOT(DevicesAvailable()); |
| 217 | 217 |
| 218 EDataFlow data[] = {eRender, eCapture}; | 218 EDataFlow data[] = {eRender, eCapture}; |
| 219 | 219 |
| 220 for (int i = 0; i < arraysize(data); ++i) { | 220 for (size_t i = 0; i < arraysize(data); ++i) { |
| 221 ScopedComPtr<IMMDevice> device; | 221 ScopedComPtr<IMMDevice> device; |
| 222 ScopedComPtr<IAudioClient> client; | 222 ScopedComPtr<IAudioClient> client; |
| 223 device = CoreAudioUtil::CreateDefaultDevice(data[i], eConsole); | 223 device = CoreAudioUtil::CreateDefaultDevice(data[i], eConsole); |
| 224 EXPECT_TRUE(device.get()); | 224 EXPECT_TRUE(device.get()); |
| 225 EXPECT_EQ(data[i], CoreAudioUtil::GetDataFlow(device.get())); | 225 EXPECT_EQ(data[i], CoreAudioUtil::GetDataFlow(device.get())); |
| 226 client = CoreAudioUtil::CreateClient(device.get()); | 226 client = CoreAudioUtil::CreateClient(device.get()); |
| 227 EXPECT_TRUE(client.get()); | 227 EXPECT_TRUE(client.get()); |
| 228 } | 228 } |
| 229 } | 229 } |
| 230 | 230 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 } | 275 } |
| 276 } | 276 } |
| 277 | 277 |
| 278 TEST_F(CoreAudioUtilWinTest, GetDevicePeriod) { | 278 TEST_F(CoreAudioUtilWinTest, GetDevicePeriod) { |
| 279 ABORT_AUDIO_TEST_IF_NOT(DevicesAvailable()); | 279 ABORT_AUDIO_TEST_IF_NOT(DevicesAvailable()); |
| 280 | 280 |
| 281 EDataFlow data[] = {eRender, eCapture}; | 281 EDataFlow data[] = {eRender, eCapture}; |
| 282 | 282 |
| 283 // Verify that the device periods are valid for the default render and | 283 // Verify that the device periods are valid for the default render and |
| 284 // capture devices. | 284 // capture devices. |
| 285 for (int i = 0; i < arraysize(data); ++i) { | 285 for (size_t i = 0; i < arraysize(data); ++i) { |
| 286 ScopedComPtr<IAudioClient> client; | 286 ScopedComPtr<IAudioClient> client; |
| 287 REFERENCE_TIME shared_time_period = 0; | 287 REFERENCE_TIME shared_time_period = 0; |
| 288 REFERENCE_TIME exclusive_time_period = 0; | 288 REFERENCE_TIME exclusive_time_period = 0; |
| 289 client = CoreAudioUtil::CreateDefaultClient(data[i], eConsole); | 289 client = CoreAudioUtil::CreateDefaultClient(data[i], eConsole); |
| 290 EXPECT_TRUE(client.get()); | 290 EXPECT_TRUE(client.get()); |
| 291 EXPECT_TRUE(SUCCEEDED(CoreAudioUtil::GetDevicePeriod( | 291 EXPECT_TRUE(SUCCEEDED(CoreAudioUtil::GetDevicePeriod( |
| 292 client.get(), AUDCLNT_SHAREMODE_SHARED, &shared_time_period))); | 292 client.get(), AUDCLNT_SHAREMODE_SHARED, &shared_time_period))); |
| 293 EXPECT_GT(shared_time_period, 0); | 293 EXPECT_GT(shared_time_period, 0); |
| 294 EXPECT_TRUE(SUCCEEDED(CoreAudioUtil::GetDevicePeriod( | 294 EXPECT_TRUE(SUCCEEDED(CoreAudioUtil::GetDevicePeriod( |
| 295 client.get(), AUDCLNT_SHAREMODE_EXCLUSIVE, &exclusive_time_period))); | 295 client.get(), AUDCLNT_SHAREMODE_EXCLUSIVE, &exclusive_time_period))); |
| 296 EXPECT_GT(exclusive_time_period, 0); | 296 EXPECT_GT(exclusive_time_period, 0); |
| 297 EXPECT_LE(exclusive_time_period, shared_time_period); | 297 EXPECT_LE(exclusive_time_period, shared_time_period); |
| 298 } | 298 } |
| 299 } | 299 } |
| 300 | 300 |
| 301 TEST_F(CoreAudioUtilWinTest, GetPreferredAudioParameters) { | 301 TEST_F(CoreAudioUtilWinTest, GetPreferredAudioParameters) { |
| 302 ABORT_AUDIO_TEST_IF_NOT(DevicesAvailable()); | 302 ABORT_AUDIO_TEST_IF_NOT(DevicesAvailable()); |
| 303 | 303 |
| 304 EDataFlow data[] = {eRender, eCapture}; | 304 EDataFlow data[] = {eRender, eCapture}; |
| 305 | 305 |
| 306 // Verify that the preferred audio parameters are OK for the default render | 306 // Verify that the preferred audio parameters are OK for the default render |
| 307 // and capture devices. | 307 // and capture devices. |
| 308 for (int i = 0; i < arraysize(data); ++i) { | 308 for (size_t i = 0; i < arraysize(data); ++i) { |
| 309 ScopedComPtr<IAudioClient> client; | 309 ScopedComPtr<IAudioClient> client; |
| 310 AudioParameters params; | 310 AudioParameters params; |
| 311 client = CoreAudioUtil::CreateDefaultClient(data[i], eConsole); | 311 client = CoreAudioUtil::CreateDefaultClient(data[i], eConsole); |
| 312 EXPECT_TRUE(client.get()); | 312 EXPECT_TRUE(client.get()); |
| 313 EXPECT_TRUE(SUCCEEDED( | 313 EXPECT_TRUE(SUCCEEDED( |
| 314 CoreAudioUtil::GetPreferredAudioParameters(client.get(), ¶ms))); | 314 CoreAudioUtil::GetPreferredAudioParameters(client.get(), ¶ms))); |
| 315 EXPECT_TRUE(params.IsValid()); | 315 EXPECT_TRUE(params.IsValid()); |
| 316 } | 316 } |
| 317 } | 317 } |
| 318 | 318 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 } | 379 } |
| 380 | 380 |
| 381 TEST_F(CoreAudioUtilWinTest, CreateRenderAndCaptureClients) { | 381 TEST_F(CoreAudioUtilWinTest, CreateRenderAndCaptureClients) { |
| 382 ABORT_AUDIO_TEST_IF_NOT(DevicesAvailable()); | 382 ABORT_AUDIO_TEST_IF_NOT(DevicesAvailable()); |
| 383 | 383 |
| 384 EDataFlow data[] = {eRender, eCapture}; | 384 EDataFlow data[] = {eRender, eCapture}; |
| 385 | 385 |
| 386 WAVEFORMATPCMEX format; | 386 WAVEFORMATPCMEX format; |
| 387 uint32 endpoint_buffer_size = 0; | 387 uint32 endpoint_buffer_size = 0; |
| 388 | 388 |
| 389 for (int i = 0; i < arraysize(data); ++i) { | 389 for (size_t i = 0; i < arraysize(data); ++i) { |
| 390 ScopedComPtr<IAudioClient> client; | 390 ScopedComPtr<IAudioClient> client; |
| 391 ScopedComPtr<IAudioRenderClient> render_client; | 391 ScopedComPtr<IAudioRenderClient> render_client; |
| 392 ScopedComPtr<IAudioCaptureClient> capture_client; | 392 ScopedComPtr<IAudioCaptureClient> capture_client; |
| 393 | 393 |
| 394 client = CoreAudioUtil::CreateDefaultClient(data[i], eConsole); | 394 client = CoreAudioUtil::CreateDefaultClient(data[i], eConsole); |
| 395 EXPECT_TRUE(client.get()); | 395 EXPECT_TRUE(client.get()); |
| 396 EXPECT_TRUE(SUCCEEDED( | 396 EXPECT_TRUE(SUCCEEDED( |
| 397 CoreAudioUtil::GetSharedModeMixFormat(client.get(), &format))); | 397 CoreAudioUtil::GetSharedModeMixFormat(client.get(), &format))); |
| 398 if (data[i] == eRender) { | 398 if (data[i] == eRender) { |
| 399 // It is not possible to create a render client using an unitialized | 399 // It is not possible to create a render client using an unitialized |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 } | 491 } |
| 492 | 492 |
| 493 TEST_F(CoreAudioUtilWinTest, GetDefaultOutputDeviceID) { | 493 TEST_F(CoreAudioUtilWinTest, GetDefaultOutputDeviceID) { |
| 494 ABORT_AUDIO_TEST_IF_NOT(DevicesAvailable()); | 494 ABORT_AUDIO_TEST_IF_NOT(DevicesAvailable()); |
| 495 | 495 |
| 496 std::string default_device_id(CoreAudioUtil::GetDefaultOutputDeviceID()); | 496 std::string default_device_id(CoreAudioUtil::GetDefaultOutputDeviceID()); |
| 497 EXPECT_FALSE(default_device_id.empty()); | 497 EXPECT_FALSE(default_device_id.empty()); |
| 498 } | 498 } |
| 499 | 499 |
| 500 } // namespace media | 500 } // namespace media |
| OLD | NEW |