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

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

Issue 10575017: Adding experimental exclusive-mode streaming to WASAPIAudioOutputStream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changes based on review by Chris and Andrew 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
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 // Software adjust volume of samples, allows each audio stream its own 5 // Software adjust volume of samples, allows each audio stream its own
6 // volume without impacting master volume for chrome and other applications. 6 // volume without impacting master volume for chrome and other applications.
7 7
8 // Implemented as templates to allow 8, 16 and 32 bit implementations. 8 // Implemented as templates to allow 8, 16 and 32 bit implementations.
9 // 8 bit is unsigned and biased by 128. 9 // 8 bit is unsigned and biased by 128.
10 10
11 // TODO(vrk): This file has been running pretty wild and free, and it's likely 11 // TODO(vrk): This file has been running pretty wild and free, and it's likely
12 // that a lot of the functions can be simplified and made more elegant. Revisit 12 // that a lot of the functions can be simplified and made more elegant. Revisit
13 // after other audio cleanup is done. (crbug.com/120319) 13 // after other audio cleanup is done. (crbug.com/120319)
14 14
15 #include <algorithm> 15 #include <algorithm>
16 #include <limits> 16 #include <limits>
17 17
18 #include "base/atomicops.h" 18 #include "base/atomicops.h"
19 #include "base/basictypes.h" 19 #include "base/basictypes.h"
20 #include "base/logging.h" 20 #include "base/logging.h"
21 #include "base/shared_memory.h" 21 #include "base/shared_memory.h"
22 #include "base/time.h" 22 #include "base/time.h"
23 #if defined(OS_WIN)
24 #include "base/sys_info.h"
25 #include "base/win/windows_version.h"
26 #include "media/audio/audio_manager_base.h"
27 #endif
28 #include "media/audio/audio_parameters.h" 23 #include "media/audio/audio_parameters.h"
29 #include "media/audio/audio_util.h" 24 #include "media/audio/audio_util.h"
25
30 #if defined(OS_MACOSX) 26 #if defined(OS_MACOSX)
31 #include "media/audio/mac/audio_low_latency_input_mac.h" 27 #include "media/audio/mac/audio_low_latency_input_mac.h"
32 #include "media/audio/mac/audio_low_latency_output_mac.h" 28 #include "media/audio/mac/audio_low_latency_output_mac.h"
33 #endif 29 #elif defined(OS_WIN)
34 #if defined(OS_WIN) 30 #include "base/command_line.h"
31 #include "base/sys_info.h"
32 #include "base/win/windows_version.h"
35 #include "media/audio/win/audio_low_latency_input_win.h" 33 #include "media/audio/win/audio_low_latency_input_win.h"
36 #include "media/audio/win/audio_low_latency_output_win.h" 34 #include "media/audio/win/audio_low_latency_output_win.h"
35 #include "media/base/media_switches.h"
36 #include "media/audio/audio_manager_base.h"
37 #endif 37 #endif
38 38
39 using base::subtle::Atomic32; 39 using base::subtle::Atomic32;
40 40
41 const uint32 kUnknownDataSize = static_cast<uint32>(-1); 41 const uint32 kUnknownDataSize = static_cast<uint32>(-1);
42 42
43 namespace media { 43 namespace media {
44 44
45 // TODO(fbarchard): Convert to intrinsics for better efficiency. 45 // TODO(fbarchard): Convert to intrinsics for better efficiency.
46 template<class Fixed> 46 template<class Fixed>
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 #if defined(OS_MACOSX) 344 #if defined(OS_MACOSX)
345 // Hardware sample-rate on the Mac can be configured, so we must query. 345 // Hardware sample-rate on the Mac can be configured, so we must query.
346 return AUAudioOutputStream::HardwareSampleRate(); 346 return AUAudioOutputStream::HardwareSampleRate();
347 #elif defined(OS_WIN) 347 #elif defined(OS_WIN)
348 if (!IsWASAPISupported()) { 348 if (!IsWASAPISupported()) {
349 // Fall back to Windows Wave implementation on Windows XP or lower 349 // Fall back to Windows Wave implementation on Windows XP or lower
350 // and use 48kHz as default input sample rate. 350 // and use 48kHz as default input sample rate.
351 return 48000; 351 return 48000;
352 } 352 }
353 353
354 // Hardware sample-rate on Windows can be configured, so we must query. 354 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
355 // TODO(henrika): improve possibility to specify audio endpoint. 355 if (!cmd_line->HasSwitch(switches::kEnableExclusiveMode)) {
scherkus (not reviewing) 2012/06/28 00:04:41 doh rietveld swallowed my comment from the last PS
henrika (OOO until Aug 14) 2012/07/25 11:18:22 Point taken. Will improve in an upcoming version.
356 // Use the default device (same as for Wave) for now to be compatible. 356 // Hardware sample-rate on Windows can be configured, so we must query.
357 return WASAPIAudioOutputStream::HardwareSampleRate(eConsole); 357 // TODO(henrika): improve possibility to specify audio endpoint.
358 // Use the default device (same as for Wave) for now to be compatible.
359 return WASAPIAudioOutputStream::HardwareSampleRate(eConsole);
scherkus (not reviewing) 2012/06/28 00:04:41 I also noticed that all current usage for E_ROLE i
henrika (OOO until Aug 14) 2012/07/25 11:18:22 It is not so simple to fix. We have a better solut
360 } else {
361 return 44100;
scherkus (not reviewing) 2012/06/28 00:04:41 where is 44100 coming from? for example we seem t
henrika (OOO until Aug 14) 2012/07/25 11:18:22 Rewrote this section and added new comments to mak
362 }
358 #elif defined(OS_ANDROID) 363 #elif defined(OS_ANDROID)
359 return 16000; 364 return 16000;
360 #else 365 #else
361 // Hardware for Linux is nearly always 48KHz. 366 // Hardware for Linux is nearly always 48KHz.
362 // TODO(crogers) : return correct value in rare non-48KHz cases. 367 // TODO(crogers) : return correct value in rare non-48KHz cases.
363 return 48000; 368 return 48000;
scherkus (not reviewing) 2012/06/28 00:04:41 nit: can you fix indent here?
henrika (OOO until Aug 14) 2012/07/25 11:18:22 Done.
364 #endif 369 #endif
365 } 370 }
366 371
367 int GetAudioInputHardwareSampleRate(const std::string& device_id) { 372 int GetAudioInputHardwareSampleRate(const std::string& device_id) {
368 // TODO(henrika): add support for device selection on all platforms. 373 // TODO(henrika): add support for device selection on all platforms.
369 // Only exists on Windows today. 374 // Only exists on Windows today.
370 #if defined(OS_MACOSX) 375 #if defined(OS_MACOSX)
371 return AUAudioInputStream::HardwareSampleRate(); 376 return AUAudioInputStream::HardwareSampleRate();
372 #elif defined(OS_WIN) 377 #elif defined(OS_WIN)
373 if (!IsWASAPISupported()) { 378 if (!IsWASAPISupported()) {
(...skipping 16 matching lines...) Expand all
390 // Core Audio API, so a low buffer size is possible. For Linux, further 395 // Core Audio API, so a low buffer size is possible. For Linux, further
391 // tuning may be needed. 396 // tuning may be needed.
392 #if defined(OS_MACOSX) 397 #if defined(OS_MACOSX)
393 return 128; 398 return 128;
394 #elif defined(OS_WIN) 399 #elif defined(OS_WIN)
395 if (!IsWASAPISupported()) { 400 if (!IsWASAPISupported()) {
396 // Fall back to Windows Wave implementation on Windows XP or lower 401 // Fall back to Windows Wave implementation on Windows XP or lower
397 // and assume 48kHz as default sample rate. 402 // and assume 48kHz as default sample rate.
398 return 2048; 403 return 2048;
399 } 404 }
405
406 // TODO(croger): tune this size to best possible WebAudio performance.
scherkus (not reviewing) 2012/06/28 00:04:41 s/croger/crogers
henrika (OOO until Aug 14) 2012/07/25 11:18:22 Done.
407 // WebRTC always uses 480 for Windows and does not call this method.
408 // Note that exclusive mode is experimental.
409 const CommandLine* cmd_line = CommandLine::ForCurrentProcess();
410 if (cmd_line->HasSwitch(switches::kEnableExclusiveMode)) {
411 return 256;
412 }
413
400 // This call must be done on a COM thread configured as MTA. 414 // This call must be done on a COM thread configured as MTA.
401 // TODO(tommi): http://code.google.com/p/chromium/issues/detail?id=103835. 415 // TODO(tommi): http://code.google.com/p/chromium/issues/detail?id=103835.
402 int mixing_sample_rate = 416 int mixing_sample_rate =
403 WASAPIAudioOutputStream::HardwareSampleRate(eConsole); 417 WASAPIAudioOutputStream::HardwareSampleRate(eConsole);
404 if (mixing_sample_rate == 48000) 418 if (mixing_sample_rate == 48000)
405 return 480; 419 return 480;
406 else if (mixing_sample_rate == 44100) 420 else if (mixing_sample_rate == 44100)
407 return 448; 421 return 448;
408 else 422 else
409 return 960; 423 return 960;
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 if ((base::SysInfo::NumberOfProcessors() < 2) || 544 if ((base::SysInfo::NumberOfProcessors() < 2) ||
531 (base::win::GetVersion() == base::win::VERSION_VISTA)) { 545 (base::win::GetVersion() == base::win::VERSION_VISTA)) {
532 return 3; 546 return 3;
533 } 547 }
534 return 2; 548 return 2;
535 } 549 }
536 550
537 #endif 551 #endif
538 552
539 } // namespace media 553 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698