diff options
author | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-12 20:11:04 +0000 |
---|---|---|
committer | satish@chromium.org <satish@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-12 20:11:04 +0000 |
commit | d3dd31fb151f067389f3423ee6de09f8c5251ed9 (patch) | |
tree | 9d71cc5598bdfad7b3c0b7398002c5f4895ad1a1 /media/audio/win/audio_manager_win.cc | |
parent | 1ff23609a28bf25c97219b29e1ca3ca5b0d5c699 (diff) | |
download | chromium_src-d3dd31fb151f067389f3423ee6de09f8c5251ed9.zip chromium_src-d3dd31fb151f067389f3423ee6de09f8c5251ed9.tar.gz chromium_src-d3dd31fb151f067389f3423ee6de09f8c5251ed9.tar.bz2 |
Rename a header and some methods to make way for subsequent audio recording additions.
Renaming audio_output.h to audio_io.h as future patches will add audio recording code to this file.
Also renamed a couple of methods to make it clear that these are for audio playback/output and similar methods will be added for audio capture/recording soon.
BUG=none
TEST=no change in functionality.
Review URL: http://codereview.chromium.org/2962006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52125 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio/win/audio_manager_win.cc')
-rw-r--r-- | media/audio/win/audio_manager_win.cc | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/media/audio/win/audio_manager_win.cc b/media/audio/win/audio_manager_win.cc new file mode 100644 index 0000000..81a59f5 --- /dev/null +++ b/media/audio/win/audio_manager_win.cc @@ -0,0 +1,94 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "media/audio/audio_io.h" + +#include <windows.h> +#include <mmsystem.h> + +#include "base/at_exit.h" +#include "base/basictypes.h" +#include "media/audio/fake_audio_output_stream.h" +#include "media/audio/win/audio_manager_win.h" +#include "media/audio/win/waveout_output_win.h" + +namespace { + +// The next 3 constants are some sensible limits to prevent integer overflow +// at this layer. +// Up to 6 channels can be passed to the driver. +// This should work, given the right drivers, but graceful error handling is +// needed. +// In theory 7.1 could also be supported, but it has not been tested. +// The 192 Khz constant is the frequency of quicktime lossless audio codec. +// MP4 is limited to 96 Khz, and mp3 is limited to 48 Khz. +// OGG vorbis was initially limited to 96 Khz, but recent tools are unlimited. +// 192 Khz is also the limit on most PC audio hardware. The minimum is 100 Hz. +// Humans range is 20 to 20000 Hz. Below 20 can be felt (woofer). + +const int kMaxChannels = 6; +const int kMaxSampleRate = 192000; +const int kMaxBitsPerSample = 64; + +AudioManagerWin* g_audio_manager = NULL; + +} // namespace. + +bool AudioManagerWin::HasAudioOutputDevices() { + return (::waveOutGetNumDevs() != 0); +} + +// Factory for the implementations of AudioOutputStream. Two implementations +// should suffice most windows user's needs. +// - PCMWaveOutAudioOutputStream: Based on the waveOutWrite API (in progress) +// - PCMDXSoundAudioOutputStream: Based on DirectSound or XAudio (future work). +AudioOutputStream* AudioManagerWin::MakeAudioOutputStream( + Format format, + int channels, + int sample_rate, + char bits_per_sample) { + if ((channels > kMaxChannels) || (channels <= 0) || + (sample_rate > kMaxSampleRate) || (sample_rate <= 0) || + (bits_per_sample > kMaxBitsPerSample) || (bits_per_sample <= 0)) + return NULL; + + if (format == AUDIO_MOCK) { + return FakeAudioOutputStream::MakeFakeStream(); + } else if (format == AUDIO_PCM_LINEAR) { + return new PCMWaveOutAudioOutputStream(this, channels, sample_rate, 3, + bits_per_sample, WAVE_MAPPER); + } else if (format == AUDIO_PCM_LOW_LATENCY) { + // TODO(cpu): waveout cannot hit 20ms latency. Use other method. + return new PCMWaveOutAudioOutputStream(this, channels, sample_rate, 2, + bits_per_sample, WAVE_MAPPER); + } + return NULL; +} + +void AudioManagerWin::ReleaseOutputStream(PCMWaveOutAudioOutputStream* stream) { + if (stream) + delete stream; +} + +void AudioManagerWin::MuteAll() { +} + +void AudioManagerWin::UnMuteAll() { +} + +AudioManagerWin::~AudioManagerWin() { +} + +void DestroyAudioManagerWin(void* param) { + delete g_audio_manager; + g_audio_manager = NULL; +} + +AudioManager* AudioManager::GetAudioManager() { + if (!g_audio_manager) { + g_audio_manager = new AudioManagerWin(); + base::AtExitManager::RegisterCallback(&DestroyAudioManagerWin, NULL); + } + return g_audio_manager; +} |