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_H_ | 5 #ifndef MEDIA_AUDIO_AUDIO_MANAGER_H_ |
6 #define MEDIA_AUDIO_AUDIO_MANAGER_H_ | 6 #define MEDIA_AUDIO_AUDIO_MANAGER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
13 #include "media/audio/audio_device_name.h" | 13 #include "media/audio/audio_device_name.h" |
14 #include "media/audio/audio_logging.h" | 14 #include "media/audio/audio_logging.h" |
15 #include "media/audio/audio_parameters.h" | 15 #include "media/audio/audio_parameters.h" |
16 | 16 |
17 namespace base { | 17 namespace base { |
18 class MessageLoop; | 18 class SingleThreadTaskRunner; |
19 class MessageLoopProxy; | |
20 } | 19 } |
21 | 20 |
22 namespace media { | 21 namespace media { |
23 | 22 |
24 class AudioInputStream; | 23 class AudioInputStream; |
25 class AudioOutputStream; | 24 class AudioOutputStream; |
26 | 25 |
27 // Manages all audio resources. Provides some convenience functions that avoid | 26 // Manages all audio resources. Provides some convenience functions that avoid |
28 // the need to provide iterators over the existing streams. | 27 // the need to provide iterators over the existing streams. |
29 class MEDIA_EXPORT AudioManager { | 28 class MEDIA_EXPORT AudioManager { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 // ideally must not be called from the UI thread or other time sensitive | 60 // ideally must not be called from the UI thread or other time sensitive |
62 // threads to avoid blocking the rest of the application. | 61 // threads to avoid blocking the rest of the application. |
63 virtual void ShowAudioInputSettings() = 0; | 62 virtual void ShowAudioInputSettings() = 0; |
64 | 63 |
65 // Appends a list of available input devices to |device_names|, | 64 // Appends a list of available input devices to |device_names|, |
66 // which must initially be empty. It is not guaranteed that all the | 65 // which must initially be empty. It is not guaranteed that all the |
67 // devices in the list support all formats and sample rates for | 66 // devices in the list support all formats and sample rates for |
68 // recording. | 67 // recording. |
69 // | 68 // |
70 // Not threadsafe; in production this should only be called from the | 69 // Not threadsafe; in production this should only be called from the |
71 // Audio IO thread (see GetMessageLoop). | 70 // Audio IO thread (see GetTaskRunner()). |
72 virtual void GetAudioInputDeviceNames(AudioDeviceNames* device_names) = 0; | 71 virtual void GetAudioInputDeviceNames(AudioDeviceNames* device_names) = 0; |
73 | 72 |
74 // Appends a list of available output devices to |device_names|, | 73 // Appends a list of available output devices to |device_names|, |
75 // which must initially be empty. | 74 // which must initially be empty. |
76 // | 75 // |
77 // Not threadsafe; in production this should only be called from the | 76 // Not threadsafe; in production this should only be called from the |
78 // Audio IO thread (see GetMessageLoop). | 77 // Audio IO thread (see GetTaskRunner()). |
79 virtual void GetAudioOutputDeviceNames(AudioDeviceNames* device_names) = 0; | 78 virtual void GetAudioOutputDeviceNames(AudioDeviceNames* device_names) = 0; |
80 | 79 |
81 // Factory for all the supported stream formats. |params| defines parameters | 80 // Factory for all the supported stream formats. |params| defines parameters |
82 // of the audio stream to be created. | 81 // of the audio stream to be created. |
83 // | 82 // |
84 // |params.sample_per_packet| is the requested buffer allocation which the | 83 // |params.sample_per_packet| is the requested buffer allocation which the |
85 // audio source thinks it can usually fill without blocking. Internally two | 84 // audio source thinks it can usually fill without blocking. Internally two |
86 // or three buffers are created, one will be locked for playback and one will | 85 // or three buffers are created, one will be locked for playback and one will |
87 // be ready to be filled in the call to AudioSourceCallback::OnMoreData(). | 86 // be ready to be filled in the call to AudioSourceCallback::OnMoreData(). |
88 // | 87 // |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
126 // with 0 suggesting that the implementation use a default value for that | 125 // with 0 suggesting that the implementation use a default value for that |
127 // platform. | 126 // platform. |
128 // Returns NULL if the combination of the parameters is not supported, or if | 127 // Returns NULL if the combination of the parameters is not supported, or if |
129 // we have reached some other platform specific limit. | 128 // we have reached some other platform specific limit. |
130 // | 129 // |
131 // Do not free the returned AudioInputStream. It is owned by AudioManager. | 130 // Do not free the returned AudioInputStream. It is owned by AudioManager. |
132 // When you are done with it, call |Stop()| and |Close()| to release it. | 131 // When you are done with it, call |Stop()| and |Close()| to release it. |
133 virtual AudioInputStream* MakeAudioInputStream( | 132 virtual AudioInputStream* MakeAudioInputStream( |
134 const AudioParameters& params, const std::string& device_id) = 0; | 133 const AudioParameters& params, const std::string& device_id) = 0; |
135 | 134 |
136 // Returns message loop used for audio IO. | 135 // Returns the task runner used for audio IO. |
137 virtual scoped_refptr<base::MessageLoopProxy> GetMessageLoop() = 0; | 136 virtual scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() = 0; |
138 | 137 |
139 // Heavyweight tasks should use GetWorkerLoop() instead of GetMessageLoop(). | 138 // Heavyweight tasks should use GetWorkerTaskRunner() instead of |
140 // On most platforms they are the same, but some share the UI loop with the | 139 // GetTaskRunner(). On most platforms they are the same, but some share the |
141 // audio IO loop. | 140 // UI loop with the audio IO loop. |
142 virtual scoped_refptr<base::MessageLoopProxy> GetWorkerLoop() = 0; | 141 virtual scoped_refptr<base::SingleThreadTaskRunner> GetWorkerTaskRunner() = 0; |
143 | 142 |
144 // Allows clients to listen for device state changes; e.g. preferred sample | 143 // Allows clients to listen for device state changes; e.g. preferred sample |
145 // rate or channel layout changes. The typical response to receiving this | 144 // rate or channel layout changes. The typical response to receiving this |
146 // callback is to recreate the stream. | 145 // callback is to recreate the stream. |
147 class AudioDeviceListener { | 146 class AudioDeviceListener { |
148 public: | 147 public: |
149 virtual void OnDeviceChange() = 0; | 148 virtual void OnDeviceChange() = 0; |
150 }; | 149 }; |
151 | 150 |
152 virtual void AddOutputDeviceChangeListener(AudioDeviceListener* listener) = 0; | 151 virtual void AddOutputDeviceChangeListener(AudioDeviceListener* listener) = 0; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 protected: | 191 protected: |
193 AudioManager(); | 192 AudioManager(); |
194 | 193 |
195 private: | 194 private: |
196 DISALLOW_COPY_AND_ASSIGN(AudioManager); | 195 DISALLOW_COPY_AND_ASSIGN(AudioManager); |
197 }; | 196 }; |
198 | 197 |
199 } // namespace media | 198 } // namespace media |
200 | 199 |
201 #endif // MEDIA_AUDIO_AUDIO_MANAGER_H_ | 200 #endif // MEDIA_AUDIO_AUDIO_MANAGER_H_ |
OLD | NEW |