Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #ifndef MEDIA_AUDIO_AUDIO_MANAGER_BASE_H_ | 5 #ifndef MEDIA_AUDIO_AUDIO_MANAGER_BASE_H_ |
| 6 #define MEDIA_AUDIO_AUDIO_MANAGER_BASE_H_ | 6 #define MEDIA_AUDIO_AUDIO_MANAGER_BASE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "base/atomic_ref_count.h" | 12 #include "base/atomic_ref_count.h" |
| 13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
| 16 #include "base/synchronization/lock.h" | 16 #include "base/synchronization/lock.h" |
| 17 #include "media/audio/audio_manager.h" | 17 #include "media/audio/audio_manager.h" |
| 18 | 18 |
| 19 #if defined(OS_WIN) | 19 #if defined(OS_WIN) |
| 20 #include "base/win/scoped_com_initializer.h" | 20 #include "base/win/scoped_com_initializer.h" |
| 21 #endif | 21 #endif |
| 22 | 22 |
| 23 #if defined(OS_ANDROID) | |
| 24 #include "base/android/jni_android.h" | |
| 25 #endif | |
| 26 | |
| 27 namespace base { | 23 namespace base { |
| 28 class Thread; | 24 class Thread; |
| 29 } | 25 } |
| 30 | 26 |
| 31 namespace media { | 27 namespace media { |
| 32 | 28 |
| 33 class AudioOutputDispatcher; | 29 class AudioOutputDispatcher; |
| 34 | 30 |
| 35 // AudioManagerBase provides AudioManager functions common for all platforms. | 31 // AudioManagerBase provides AudioManager functions common for all platforms. |
| 36 class MEDIA_EXPORT AudioManagerBase : public AudioManager { | 32 class MEDIA_EXPORT AudioManagerBase : public AudioManager { |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 90 // Listeners will be notified on the AudioManager::GetMessageLoop() loop. | 86 // Listeners will be notified on the AudioManager::GetMessageLoop() loop. |
| 91 virtual void AddOutputDeviceChangeListener( | 87 virtual void AddOutputDeviceChangeListener( |
| 92 AudioDeviceListener* listener) OVERRIDE; | 88 AudioDeviceListener* listener) OVERRIDE; |
| 93 virtual void RemoveOutputDeviceChangeListener( | 89 virtual void RemoveOutputDeviceChangeListener( |
| 94 AudioDeviceListener* listener) OVERRIDE; | 90 AudioDeviceListener* listener) OVERRIDE; |
| 95 | 91 |
| 96 virtual AudioParameters GetDefaultOutputStreamParameters() OVERRIDE; | 92 virtual AudioParameters GetDefaultOutputStreamParameters() OVERRIDE; |
| 97 virtual AudioParameters GetInputStreamParameters( | 93 virtual AudioParameters GetInputStreamParameters( |
| 98 const std::string& device_id) OVERRIDE; | 94 const std::string& device_id) OVERRIDE; |
| 99 | 95 |
| 100 #if defined(OS_ANDROID) | |
| 101 static bool RegisterAudioManager(JNIEnv* env); | |
| 102 #endif | |
| 103 | |
| 104 protected: | 96 protected: |
| 105 AudioManagerBase(); | 97 AudioManagerBase(); |
| 106 | 98 |
| 107 // TODO(dalecurtis): This must change to map both input and output parameters | 99 // TODO(dalecurtis): This must change to map both input and output parameters |
| 108 // to a single dispatcher, otherwise on a device state change we'll just get | 100 // to a single dispatcher, otherwise on a device state change we'll just get |
| 109 // the exact same invalid dispatcher. | 101 // the exact same invalid dispatcher. |
| 110 typedef std::map<std::pair<AudioParameters, AudioParameters>, | 102 typedef std::map<std::pair<AudioParameters, AudioParameters>, |
| 111 scoped_refptr<AudioOutputDispatcher> > | 103 scoped_refptr<AudioOutputDispatcher> > |
| 112 AudioOutputDispatchersMap; | 104 AudioOutputDispatchersMap; |
| 113 | 105 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 129 // will decide if they should return the values from |input_params| or the | 121 // will decide if they should return the values from |input_params| or the |
| 130 // default hardware values. If the |input_params| is invalid, it will return | 122 // default hardware values. If the |input_params| is invalid, it will return |
| 131 // the default hardware audio parameters. | 123 // the default hardware audio parameters. |
| 132 virtual AudioParameters GetPreferredOutputStreamParameters( | 124 virtual AudioParameters GetPreferredOutputStreamParameters( |
| 133 const AudioParameters& input_params) = 0; | 125 const AudioParameters& input_params) = 0; |
| 134 | 126 |
| 135 // Map of cached AudioOutputDispatcher instances. Must only be touched | 127 // Map of cached AudioOutputDispatcher instances. Must only be touched |
| 136 // from the audio thread (no locking). | 128 // from the audio thread (no locking). |
| 137 AudioOutputDispatchersMap output_dispatchers_; | 129 AudioOutputDispatchersMap output_dispatchers_; |
| 138 | 130 |
| 131 // Get number of input or output streams. | |
| 132 int GetNumInputStreams(); | |
|
DaleCurtis
2013/04/15 21:02:30
Since these aren't virtual you can just hacker_sty
leozwang1
2013/04/15 21:12:15
Done.
| |
| 133 int GetNumOutputStreams(); | |
| 134 | |
| 139 private: | 135 private: |
| 140 // Called by Shutdown(). | 136 // Called by Shutdown(). |
| 141 void ShutdownOnAudioThread(); | 137 void ShutdownOnAudioThread(); |
| 142 | 138 |
| 143 #if defined(OS_ANDROID) | |
| 144 void SetAudioMode(int mode); | |
| 145 void RegisterHeadsetReceiver(); | |
| 146 void UnregisterHeadsetReceiver(); | |
| 147 #endif | |
| 148 | |
| 149 // Counts the number of active input streams to find out if something else | 139 // Counts the number of active input streams to find out if something else |
| 150 // is currently recording in Chrome. | 140 // is currently recording in Chrome. |
| 151 base::AtomicRefCount num_active_input_streams_; | 141 base::AtomicRefCount num_active_input_streams_; |
| 152 | 142 |
| 153 // Max number of open output streams, modified by | 143 // Max number of open output streams, modified by |
| 154 // SetMaxOutputStreamsAllowed(). | 144 // SetMaxOutputStreamsAllowed(). |
| 155 int max_num_output_streams_; | 145 int max_num_output_streams_; |
| 156 | 146 |
| 157 // Max number of open input streams. | 147 // Max number of open input streams. |
| 158 int max_num_input_streams_; | 148 int max_num_input_streams_; |
| 159 | 149 |
| 160 // Number of currently open output streams. | 150 // Number of currently open output streams. |
| 161 int num_output_streams_; | 151 int num_output_streams_; |
| 162 | 152 |
| 163 // Number of currently open input streams. | 153 // Number of currently open input streams. |
| 164 int num_input_streams_; | 154 int num_input_streams_; |
| 165 | 155 |
| 166 // Track output state change listeners. | 156 // Track output state change listeners. |
| 167 ObserverList<AudioDeviceListener> output_listeners_; | 157 ObserverList<AudioDeviceListener> output_listeners_; |
| 168 | 158 |
| 169 // Thread used to interact with audio streams created by this audio manager. | 159 // Thread used to interact with audio streams created by this audio manager. |
| 170 scoped_ptr<base::Thread> audio_thread_; | 160 scoped_ptr<base::Thread> audio_thread_; |
| 171 mutable base::Lock audio_thread_lock_; | 161 mutable base::Lock audio_thread_lock_; |
| 172 | 162 |
| 173 // The message loop of the audio thread this object runs on. Used for internal | 163 // The message loop of the audio thread this object runs on. Used for internal |
| 174 // tasks which run on the audio thread even after Shutdown() has been started | 164 // tasks which run on the audio thread even after Shutdown() has been started |
| 175 // and GetMessageLoop() starts returning NULL. | 165 // and GetMessageLoop() starts returning NULL. |
| 176 scoped_refptr<base::MessageLoopProxy> message_loop_; | 166 scoped_refptr<base::MessageLoopProxy> message_loop_; |
| 177 | 167 |
| 178 #if defined(OS_ANDROID) | |
| 179 // Java AudioManager instance. | |
| 180 base::android::ScopedJavaGlobalRef<jobject> j_audio_manager_; | |
| 181 #endif | |
| 182 | |
| 183 DISALLOW_COPY_AND_ASSIGN(AudioManagerBase); | 168 DISALLOW_COPY_AND_ASSIGN(AudioManagerBase); |
| 184 }; | 169 }; |
| 185 | 170 |
| 186 } // namespace media | 171 } // namespace media |
| 187 | 172 |
| 188 #endif // MEDIA_AUDIO_AUDIO_MANAGER_BASE_H_ | 173 #endif // MEDIA_AUDIO_AUDIO_MANAGER_BASE_H_ |
| OLD | NEW |