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

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

Issue 9826023: Merge AudioRendererImpl and AudioRendererBase; add NullAudioSink (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase ToT + address CR comments Created 8 years, 8 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
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 // use stereo by default. 386 // use stereo by default.
387 return CHANNEL_LAYOUT_STEREO; 387 return CHANNEL_LAYOUT_STEREO;
388 } 388 }
389 return WASAPIAudioInputStream::HardwareChannelCount(device_id) == 1 ? 389 return WASAPIAudioInputStream::HardwareChannelCount(device_id) == 1 ?
390 CHANNEL_LAYOUT_MONO : CHANNEL_LAYOUT_STEREO; 390 CHANNEL_LAYOUT_MONO : CHANNEL_LAYOUT_STEREO;
391 #else 391 #else
392 return CHANNEL_LAYOUT_STEREO; 392 return CHANNEL_LAYOUT_STEREO;
393 #endif 393 #endif
394 } 394 }
395 395
396 // Computes a buffer size based on the given |sample_rate|. Must be used in
397 // conjunction with AUDIO_PCM_LINEAR.
398 size_t GetHighLatencyOutputBufferSize(int sample_rate) {
399 // TODO(vrk/crogers): The buffer sizes that this function computes is probably
400 // overly conservative. However, reducing the buffer size to 2048-8192 bytes
401 // caused crbug.com/108396. This computation should be revisited while making
402 // sure crbug.com/108396 doesn't happen again.
403
404 // The minimum number of samples in a hardware packet.
405 // This value is selected so that we can handle down to 5khz sample rate.
406 static const size_t kMinSamplesPerHardwarePacket = 1024;
407
408 // The maximum number of samples in a hardware packet.
409 // This value is selected so that we can handle up to 192khz sample rate.
410 static const size_t kMaxSamplesPerHardwarePacket = 64 * 1024;
411
412 // This constant governs the hardware audio buffer size, this value should be
413 // chosen carefully.
414 // This value is selected so that we have 8192 samples for 48khz streams.
415 static const size_t kMillisecondsPerHardwarePacket = 170;
416
417 // Select the number of samples that can provide at least
418 // |kMillisecondsPerHardwarePacket| worth of audio data.
419 size_t samples = kMinSamplesPerHardwarePacket;
420 while (samples <= kMaxSamplesPerHardwarePacket &&
421 samples * base::Time::kMillisecondsPerSecond <
422 sample_rate * kMillisecondsPerHardwarePacket) {
423 samples *= 2;
424 }
425 return samples;
426 }
427
396 // When transferring data in the shared memory, first word is size of data 428 // When transferring data in the shared memory, first word is size of data
397 // in bytes. Actual data starts immediately after it. 429 // in bytes. Actual data starts immediately after it.
398 430
399 uint32 TotalSharedMemorySizeInBytes(uint32 packet_size) { 431 uint32 TotalSharedMemorySizeInBytes(uint32 packet_size) {
400 // Need to reserve extra 4 bytes for size of data. 432 // Need to reserve extra 4 bytes for size of data.
401 return packet_size + sizeof(Atomic32); 433 return packet_size + sizeof(Atomic32);
402 } 434 }
403 435
404 uint32 PacketSizeSizeInBytes(uint32 shared_memory_created_size) { 436 uint32 PacketSizeSizeInBytes(uint32 shared_memory_created_size) {
405 return shared_memory_created_size - sizeof(Atomic32); 437 return shared_memory_created_size - sizeof(Atomic32);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 479
448 bool IsWASAPISupported() { 480 bool IsWASAPISupported() {
449 // Note: that function correctly returns that Windows Server 2003 does not 481 // Note: that function correctly returns that Windows Server 2003 does not
450 // support WASAPI. 482 // support WASAPI.
451 return base::win::GetVersion() >= base::win::VERSION_VISTA; 483 return base::win::GetVersion() >= base::win::VERSION_VISTA;
452 } 484 }
453 485
454 #endif 486 #endif
455 487
456 } // namespace media 488 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698