diff options
author | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-25 21:31:35 +0000 |
---|---|---|
committer | sergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-08-25 21:31:35 +0000 |
commit | e1ab81168b2a30d2f9910c2803efaf97d7d39738 (patch) | |
tree | a0cf01a022fdada16395e7f5b0ac948eb57e17c7 /media/audio/audio_manager.h | |
parent | c637e529eafdffbc97a4760376975ea21a414cee (diff) | |
download | chromium_src-e1ab81168b2a30d2f9910c2803efaf97d7d39738.zip chromium_src-e1ab81168b2a30d2f9910c2803efaf97d7d39738.tar.gz chromium_src-e1ab81168b2a30d2f9910c2803efaf97d7d39738.tar.bz2 |
Share one thread between all AudioOutputControllers instead of creating one per stream.
TEST=unittests
BUG=39825
Review URL: http://codereview.chromium.org/3185022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57392 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/audio/audio_manager.h')
-rw-r--r-- | media/audio/audio_manager.h | 101 |
1 files changed, 101 insertions, 0 deletions
diff --git a/media/audio/audio_manager.h b/media/audio/audio_manager.h new file mode 100644 index 0000000..2185950 --- /dev/null +++ b/media/audio/audio_manager.h @@ -0,0 +1,101 @@ +// Copyright (c) 2010 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. + +#ifndef MEDIA_AUDIO_AUDIO_MANAGER_H_ +#define MEDIA_AUDIO_AUDIO_MANAGER_H_ + +#include "base/basictypes.h" + +class AudioInputStream; +class AudioOutputStream; +class MessageLoop; + +// Manages all audio resources. In particular it owns the AudioOutputStream +// objects. Provides some convenience functions that avoid the need to provide +// iterators over the existing streams. +class AudioManager { + public: + enum Format { + AUDIO_PCM_LINEAR = 0, // PCM is 'raw' amplitude samples. + AUDIO_PCM_LOW_LATENCY, // Linear PCM, low latency requested. + AUDIO_MOCK, // Creates a dummy AudioOutputStream object. + AUDIO_LAST_FORMAT // Only used for validation of format. + }; + + // Telephone quality sample rate, mostly for speech-only audio. + static const uint32 kTelephoneSampleRate = 8000; + // CD sampling rate is 44.1 KHz or conveniently 2x2x3x3x5x5x7x7. + static const uint32 kAudioCDSampleRate = 44100; + // Digital Audio Tape sample rate. + static const uint32 kAudioDATSampleRate = 48000; + + // Returns true if the OS reports existence of audio devices. This does not + // guarantee that the existing devices support all formats and sample rates. + virtual bool HasAudioOutputDevices() = 0; + + // Returns true if the OS reports existence of audio recording devices. This + // does not guarantee that the existing devices support all formats and + // sample rates. + virtual bool HasAudioInputDevices() = 0; + + // Factory for all the supported stream formats. The |channels| can be 1 to 5. + // The |sample_rate| is in hertz and can be any value supported by the + // platform. For some future formats the |sample_rate| and |bits_per_sample| + // can take special values. + // Returns NULL if the combination of the parameters is not supported, or if + // we have reached some other platform specific limit. + // + // AUDIO_PCM_LOW_LATENCY can be passed to this method and it has two effects: + // 1- Instead of triple buffered the audio will be double buffered. + // 2- A low latency driver or alternative audio subsystem will be used when + // available. + // + // Do not free the returned AudioOutputStream. It is owned by AudioManager. + virtual AudioOutputStream* MakeAudioOutputStream(Format format, int channels, + int sample_rate, + char bits_per_sample) = 0; + + // Factory to create audio recording streams. + // |channels| can be 1 or 2. + // |sample_rate| is in hertz and can be any value supported by the platform. + // |bits_per_sample| can be any value supported by the platform. + // |samples_per_packet| is in hertz as well and can be 0 to |sample_rate|, + // with 0 suggesting that the implementation use a default value for that + // platform. + // Returns NULL if the combination of the parameters is not supported, or if + // we have reached some other platform specific limit. + // + // Do not free the returned AudioInputStream. It is owned by AudioManager. + // When you are done with it, call |Stop()| and |Close()| to release it. + virtual AudioInputStream* MakeAudioInputStream(Format format, int channels, + int sample_rate, + char bits_per_sample, + uint32 samples_per_packet) = 0; + + // Muting continues playback but effectively the volume is set to zero. + // Un-muting returns the volume to the previous level. + virtual void MuteAll() = 0; + virtual void UnMuteAll() = 0; + + // Returns message loop used for audio IO. + virtual MessageLoop* GetMessageLoop() = 0; + + // Get AudioManager singleton. + // TODO(cpu): Define threading requirements for interacting with AudioManager. + static AudioManager* GetAudioManager(); + + protected: + virtual ~AudioManager() {} + + // Called from GetAudioManager() to initialiaze the instance. + virtual void Init() = 0; + + private: + static void Destroy(void*); + + // Called by GetAudioManager() to create platform-specific audio manager. + static AudioManager* CreateAudioManager(); +}; + +#endif // MEDIA_AUDIO_AUDIO_MANAGER_H_ |