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

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: Fix win build 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
« no previous file with comments | « media/audio/audio_util.h ('k') | media/audio/null_audio_sink.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 // use stereo by default. 420 // use stereo by default.
421 return CHANNEL_LAYOUT_STEREO; 421 return CHANNEL_LAYOUT_STEREO;
422 } 422 }
423 return WASAPIAudioInputStream::HardwareChannelCount(device_id) == 1 ? 423 return WASAPIAudioInputStream::HardwareChannelCount(device_id) == 1 ?
424 CHANNEL_LAYOUT_MONO : CHANNEL_LAYOUT_STEREO; 424 CHANNEL_LAYOUT_MONO : CHANNEL_LAYOUT_STEREO;
425 #else 425 #else
426 return CHANNEL_LAYOUT_STEREO; 426 return CHANNEL_LAYOUT_STEREO;
427 #endif 427 #endif
428 } 428 }
429 429
430 // Computes a buffer size based on the given |sample_rate|. Must be used in
431 // conjunction with AUDIO_PCM_LINEAR.
432 size_t GetHighLatencyOutputBufferSize(int sample_rate) {
433 // TODO(vrk/crogers): The buffer sizes that this function computes is probably
434 // overly conservative. However, reducing the buffer size to 2048-8192 bytes
435 // caused crbug.com/108396. This computation should be revisited while making
436 // sure crbug.com/108396 doesn't happen again.
437
438 // The minimum number of samples in a hardware packet.
439 // This value is selected so that we can handle down to 5khz sample rate.
440 static const size_t kMinSamplesPerHardwarePacket = 1024;
441
442 // The maximum number of samples in a hardware packet.
443 // This value is selected so that we can handle up to 192khz sample rate.
444 static const size_t kMaxSamplesPerHardwarePacket = 64 * 1024;
445
446 // This constant governs the hardware audio buffer size, this value should be
447 // chosen carefully.
448 // This value is selected so that we have 8192 samples for 48khz streams.
449 static const size_t kMillisecondsPerHardwarePacket = 170;
450
451 // Select the number of samples that can provide at least
452 // |kMillisecondsPerHardwarePacket| worth of audio data.
453 size_t samples = kMinSamplesPerHardwarePacket;
454 while (samples <= kMaxSamplesPerHardwarePacket &&
455 samples * base::Time::kMillisecondsPerSecond <
456 sample_rate * kMillisecondsPerHardwarePacket) {
457 samples *= 2;
458 }
459 return samples;
460 }
461
430 // When transferring data in the shared memory, first word is size of data 462 // When transferring data in the shared memory, first word is size of data
431 // in bytes. Actual data starts immediately after it. 463 // in bytes. Actual data starts immediately after it.
432 464
433 uint32 TotalSharedMemorySizeInBytes(uint32 packet_size) { 465 uint32 TotalSharedMemorySizeInBytes(uint32 packet_size) {
434 // Need to reserve extra 4 bytes for size of data. 466 // Need to reserve extra 4 bytes for size of data.
435 return packet_size + sizeof(Atomic32); 467 return packet_size + sizeof(Atomic32);
436 } 468 }
437 469
438 uint32 PacketSizeSizeInBytes(uint32 shared_memory_created_size) { 470 uint32 PacketSizeSizeInBytes(uint32 shared_memory_created_size) {
439 return shared_memory_created_size - sizeof(Atomic32); 471 return shared_memory_created_size - sizeof(Atomic32);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 513
482 bool IsWASAPISupported() { 514 bool IsWASAPISupported() {
483 // Note: that function correctly returns that Windows Server 2003 does not 515 // Note: that function correctly returns that Windows Server 2003 does not
484 // support WASAPI. 516 // support WASAPI.
485 return base::win::GetVersion() >= base::win::VERSION_VISTA; 517 return base::win::GetVersion() >= base::win::VERSION_VISTA;
486 } 518 }
487 519
488 #endif 520 #endif
489 521
490 } // namespace media 522 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_util.h ('k') | media/audio/null_audio_sink.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698