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> |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 | 76 |
77 // Creates the input stream for the |AUDIO_PCM_LINEAR| format. The legacy | 77 // Creates the input stream for the |AUDIO_PCM_LINEAR| format. The legacy |
78 // name is also from |AUDIO_PCM_LINEAR|. | 78 // name is also from |AUDIO_PCM_LINEAR|. |
79 virtual AudioInputStream* MakeLinearInputStream( | 79 virtual AudioInputStream* MakeLinearInputStream( |
80 const AudioParameters& params, const std::string& device_id) = 0; | 80 const AudioParameters& params, const std::string& device_id) = 0; |
81 | 81 |
82 // Creates the input stream for the |AUDIO_PCM_LOW_LATENCY| format. | 82 // Creates the input stream for the |AUDIO_PCM_LOW_LATENCY| format. |
83 virtual AudioInputStream* MakeLowLatencyInputStream( | 83 virtual AudioInputStream* MakeLowLatencyInputStream( |
84 const AudioParameters& params, const std::string& device_id) = 0; | 84 const AudioParameters& params, const std::string& device_id) = 0; |
85 | 85 |
86 // Returns the preferred hardware audio output parameters for opening output | |
87 // streams in the |AUDIO_PCM_LOW_LATENCY| format. | |
88 // TODO(dalecurtis): Retrieve the |channel_layout| value from hardware instead | |
89 // of accepting the value. | |
90 // TODO(dalecurtis): Each AudioManager should implement their own version, see | |
91 // http://crbug.com/137326 | |
92 virtual AudioParameters GetPreferredLowLatencyOutputStreamParameters( | |
93 const AudioParameters& input_params); | |
94 | |
95 // Listeners will be notified on the AudioManager::GetMessageLoop() loop. | 86 // Listeners will be notified on the AudioManager::GetMessageLoop() loop. |
96 virtual void AddOutputDeviceChangeListener( | 87 virtual void AddOutputDeviceChangeListener( |
97 AudioDeviceListener* listener) OVERRIDE; | 88 AudioDeviceListener* listener) OVERRIDE; |
98 virtual void RemoveOutputDeviceChangeListener( | 89 virtual void RemoveOutputDeviceChangeListener( |
99 AudioDeviceListener* listener) OVERRIDE; | 90 AudioDeviceListener* listener) OVERRIDE; |
100 | 91 |
| 92 virtual AudioParameters GetDefaultOutputStreamParameters() OVERRIDE; |
| 93 virtual AudioParameters GetInputStreamParameters( |
| 94 const std::string& device_id) OVERRIDE; |
| 95 |
101 protected: | 96 protected: |
102 AudioManagerBase(); | 97 AudioManagerBase(); |
103 | 98 |
104 // 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 |
105 // 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 |
106 // the exact same invalid dispatcher. | 101 // the exact same invalid dispatcher. |
107 typedef std::map<std::pair<AudioParameters, AudioParameters>, | 102 typedef std::map<std::pair<AudioParameters, AudioParameters>, |
108 scoped_refptr<AudioOutputDispatcher> > | 103 scoped_refptr<AudioOutputDispatcher> > |
109 AudioOutputDispatchersMap; | 104 AudioOutputDispatchersMap; |
110 | 105 |
111 // Shuts down the audio thread and releases all the audio output dispatchers | 106 // Shuts down the audio thread and releases all the audio output dispatchers |
112 // on the audio thread. All audio streams should be freed before Shutdown() | 107 // on the audio thread. All audio streams should be freed before Shutdown() |
113 // is called. This must be called in the destructor of every AudioManagerBase | 108 // is called. This must be called in the destructor of every AudioManagerBase |
114 // implementation. | 109 // implementation. |
115 void Shutdown(); | 110 void Shutdown(); |
116 | 111 |
117 void SetMaxOutputStreamsAllowed(int max) { max_num_output_streams_ = max; } | 112 void SetMaxOutputStreamsAllowed(int max) { max_num_output_streams_ = max; } |
118 | 113 |
119 // Called by each platform specific AudioManager to notify output state change | 114 // Called by each platform specific AudioManager to notify output state change |
120 // listeners that a state change has occurred. Must be called from the audio | 115 // listeners that a state change has occurred. Must be called from the audio |
121 // thread. | 116 // thread. |
122 void NotifyAllOutputDeviceChangeListeners(); | 117 void NotifyAllOutputDeviceChangeListeners(); |
123 | 118 |
| 119 // Returns the preferred hardware audio output parameters for opening output |
| 120 // streams. If the users inject a valid |input_params|, each AudioManager |
| 121 // will decide if they should return the values from |input_params| or the |
| 122 // default hardware values. If the |input_params| is invalid, it will return |
| 123 // the default hardware audio parameters. |
| 124 virtual AudioParameters GetPreferredOutputStreamParameters( |
| 125 const AudioParameters& input_params) = 0; |
| 126 |
124 // Map of cached AudioOutputDispatcher instances. Must only be touched | 127 // Map of cached AudioOutputDispatcher instances. Must only be touched |
125 // from the audio thread (no locking). | 128 // from the audio thread (no locking). |
126 AudioOutputDispatchersMap output_dispatchers_; | 129 AudioOutputDispatchersMap output_dispatchers_; |
127 | 130 |
128 private: | 131 private: |
129 // Called by Shutdown(). | 132 // Called by Shutdown(). |
130 void ShutdownOnAudioThread(); | 133 void ShutdownOnAudioThread(); |
131 | 134 |
132 // Counts the number of active input streams to find out if something else | 135 // Counts the number of active input streams to find out if something else |
133 // is currently recording in Chrome. | 136 // is currently recording in Chrome. |
(...skipping 23 matching lines...) Expand all Loading... |
157 // tasks which run on the audio thread even after Shutdown() has been started | 160 // tasks which run on the audio thread even after Shutdown() has been started |
158 // and GetMessageLoop() starts returning NULL. | 161 // and GetMessageLoop() starts returning NULL. |
159 scoped_refptr<base::MessageLoopProxy> message_loop_; | 162 scoped_refptr<base::MessageLoopProxy> message_loop_; |
160 | 163 |
161 DISALLOW_COPY_AND_ASSIGN(AudioManagerBase); | 164 DISALLOW_COPY_AND_ASSIGN(AudioManagerBase); |
162 }; | 165 }; |
163 | 166 |
164 } // namespace media | 167 } // namespace media |
165 | 168 |
166 #endif // MEDIA_AUDIO_AUDIO_MANAGER_BASE_H_ | 169 #endif // MEDIA_AUDIO_AUDIO_MANAGER_BASE_H_ |
OLD | NEW |