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 <memory> | 8 #include <memory> |
9 #include <string> | 9 #include <string> |
10 #include <unordered_set> | 10 #include <unordered_set> |
11 #include <utility> | 11 #include <utility> |
12 | 12 |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 14 #include "base/files/file_path.h" |
14 #include "base/macros.h" | 15 #include "base/macros.h" |
15 #include "base/memory/scoped_vector.h" | 16 #include "base/memory/scoped_vector.h" |
16 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
17 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
18 #include "build/build_config.h" | 19 #include "build/build_config.h" |
19 #include "media/audio/audio_device_name.h" | 20 #include "media/audio/audio_device_name.h" |
20 #include "media/audio/audio_manager.h" | 21 #include "media/audio/audio_manager.h" |
21 #include "media/audio/audio_output_dispatcher.h" | 22 #include "media/audio/audio_output_dispatcher.h" |
22 | 23 |
23 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 | 61 |
61 AudioParameters GetDefaultOutputStreamParameters() override; | 62 AudioParameters GetDefaultOutputStreamParameters() override; |
62 AudioParameters GetOutputStreamParameters( | 63 AudioParameters GetOutputStreamParameters( |
63 const std::string& device_id) override; | 64 const std::string& device_id) override; |
64 AudioParameters GetInputStreamParameters( | 65 AudioParameters GetInputStreamParameters( |
65 const std::string& device_id) override; | 66 const std::string& device_id) override; |
66 std::string GetAssociatedOutputDeviceID( | 67 std::string GetAssociatedOutputDeviceID( |
67 const std::string& input_device_id) override; | 68 const std::string& input_device_id) override; |
68 std::unique_ptr<AudioLog> CreateAudioLog( | 69 std::unique_ptr<AudioLog> CreateAudioLog( |
69 AudioLogFactory::AudioComponent component) override; | 70 AudioLogFactory::AudioComponent component) override; |
| 71 std::unique_ptr<AudioFileWriter> CreateAudioFileWriter( |
| 72 const AudioParameters& params) override; |
| 73 void EnableOutputDebugRecording( |
| 74 const base::FilePath& base_file_name) override; |
| 75 void DisableOutputDebugRecording() override; |
70 | 76 |
71 void SetMaxStreamCountForTesting(int max_input, int max_output) final; | 77 void SetMaxStreamCountForTesting(int max_input, int max_output) final; |
72 | 78 |
73 // AudioManagerBase: | 79 // AudioManagerBase: |
74 | 80 |
75 // Called internally by the audio stream when it has been closed. | 81 // Called internally by the audio stream when it has been closed. |
76 virtual void ReleaseOutputStream(AudioOutputStream* stream); | 82 virtual void ReleaseOutputStream(AudioOutputStream* stream); |
77 virtual void ReleaseInputStream(AudioInputStream* stream); | 83 virtual void ReleaseInputStream(AudioInputStream* stream); |
78 | 84 |
79 // Creates the output stream for the |AUDIO_PCM_LINEAR| format. The legacy | 85 // Creates the output stream for the |AUDIO_PCM_LINEAR| format. The legacy |
(...skipping 18 matching lines...) Expand all Loading... |
98 // Creates the input stream for the |AUDIO_PCM_LOW_LATENCY| format. | 104 // Creates the input stream for the |AUDIO_PCM_LOW_LATENCY| format. |
99 virtual AudioInputStream* MakeLowLatencyInputStream( | 105 virtual AudioInputStream* MakeLowLatencyInputStream( |
100 const AudioParameters& params, | 106 const AudioParameters& params, |
101 const std::string& device_id, | 107 const std::string& device_id, |
102 const LogCallback& log_callback) = 0; | 108 const LogCallback& log_callback) = 0; |
103 | 109 |
104 // Get number of input or output streams. | 110 // Get number of input or output streams. |
105 int input_stream_count() const { | 111 int input_stream_count() const { |
106 return static_cast<int>(input_streams_.size()); | 112 return static_cast<int>(input_streams_.size()); |
107 } | 113 } |
108 int output_stream_count() const { return num_output_streams_; } | 114 int output_stream_count() const { |
| 115 return static_cast<int>(output_streams_.size()); |
| 116 } |
109 | 117 |
110 protected: | 118 protected: |
111 AudioManagerBase( | 119 AudioManagerBase( |
112 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 120 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
113 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, | 121 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, |
114 AudioLogFactory* audio_log_factory); | 122 AudioLogFactory* audio_log_factory, |
| 123 CreateAudioFileWriterCallback create_audio_file_writer_callback); |
115 | 124 |
116 // Releases all the audio output dispatchers. | 125 // Releases all the audio output dispatchers. |
117 // All audio streams should be closed before Shutdown() is called. | 126 // All audio streams should be closed before Shutdown() is called. |
118 // This must be called in the destructor of every AudioManagerBase | 127 // This must be called in the destructor of every AudioManagerBase |
119 // implementation. | 128 // implementation. |
120 void Shutdown(); | 129 void Shutdown(); |
121 | 130 |
122 void SetMaxOutputStreamsAllowed(int max) { max_num_output_streams_ = max; } | 131 void SetMaxOutputStreamsAllowed(int max) { max_num_output_streams_ = max; } |
123 | 132 |
124 // Called by each platform specific AudioManager to notify output state change | 133 // Called by each platform specific AudioManager to notify output state change |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 | 168 |
160 class CompareByParams; | 169 class CompareByParams; |
161 | 170 |
162 // These functions assign group ids to devices based on their device ids. | 171 // These functions assign group ids to devices based on their device ids. |
163 // The default implementation is an attempt to do this based on | 172 // The default implementation is an attempt to do this based on |
164 // GetAssociatedOutputDeviceID. Must be called on the audio worker thread | 173 // GetAssociatedOutputDeviceID. Must be called on the audio worker thread |
165 // (see GetTaskRunner()). | 174 // (see GetTaskRunner()). |
166 std::string GetGroupIDOutput(const std::string& output_device_id); | 175 std::string GetGroupIDOutput(const std::string& output_device_id); |
167 std::string GetGroupIDInput(const std::string& input_device_id); | 176 std::string GetGroupIDInput(const std::string& input_device_id); |
168 | 177 |
| 178 base::FilePath GetDebugRecordingFileNameWithExtensions( |
| 179 const base::FilePath& file_name); |
| 180 |
169 // Max number of open output streams, modified by | 181 // Max number of open output streams, modified by |
170 // SetMaxOutputStreamsAllowed(). | 182 // SetMaxOutputStreamsAllowed(). |
171 int max_num_output_streams_; | 183 int max_num_output_streams_; |
172 | 184 |
173 // Max number of open input streams. | 185 // Max number of open input streams. |
174 int max_num_input_streams_; | 186 int max_num_input_streams_; |
175 | 187 |
176 // Number of currently open output streams. | |
177 int num_output_streams_; | |
178 | |
179 // Track output state change listeners. | 188 // Track output state change listeners. |
180 base::ObserverList<AudioDeviceListener> output_listeners_; | 189 base::ObserverList<AudioDeviceListener> output_listeners_; |
181 | 190 |
| 191 // Contains currently open output streams. |
| 192 std::unordered_set<AudioOutputStream*> output_streams_; |
| 193 |
182 // Contains currently open input streams. | 194 // Contains currently open input streams. |
183 std::unordered_set<AudioInputStream*> input_streams_; | 195 std::unordered_set<AudioInputStream*> input_streams_; |
184 | 196 |
185 // Map of cached AudioOutputDispatcher instances. Must only be touched | 197 // Map of cached AudioOutputDispatcher instances. Must only be touched |
186 // from the audio thread (no locking). | 198 // from the audio thread (no locking). |
187 AudioOutputDispatchers output_dispatchers_; | 199 AudioOutputDispatchers output_dispatchers_; |
188 | 200 |
189 // Proxy for creating AudioLog objects. | 201 // Proxy for creating AudioLog objects. |
190 AudioLogFactory* const audio_log_factory_; | 202 AudioLogFactory* const audio_log_factory_; |
191 | 203 |
| 204 // Callback for creating AudioFileWriter objects. |
| 205 CreateAudioFileWriterCallback create_audio_file_writer_callback_; |
| 206 |
| 207 // The base file name for debug recording files. If this is non-empty, debug |
| 208 // recording is enabled, otherwise disabled. |
| 209 base::FilePath debug_recording_base_file_name_; |
| 210 |
| 211 // Running id to append to the base filename. |
| 212 int next_filename_id_; |
| 213 |
192 DISALLOW_COPY_AND_ASSIGN(AudioManagerBase); | 214 DISALLOW_COPY_AND_ASSIGN(AudioManagerBase); |
193 }; | 215 }; |
194 | 216 |
195 } // namespace media | 217 } // namespace media |
196 | 218 |
197 #endif // MEDIA_AUDIO_AUDIO_MANAGER_BASE_H_ | 219 #endif // MEDIA_AUDIO_AUDIO_MANAGER_BASE_H_ |
OLD | NEW |