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

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

Powered by Google App Engine
This is Rietveld 408576698