Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: media/audio/audio_manager.h

Issue 1806313003: Pass task runners to AudioManager constructor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Pass task runners into AudioManager::Create Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/macros.h" 10 #include "base/macros.h"
(...skipping 28 matching lines...) Expand all
39 // This provides an alternative to the statically linked factory method used 39 // This provides an alternative to the statically linked factory method used
40 // to create AudioManager. This is useful for dynamically-linked third 40 // to create AudioManager. This is useful for dynamically-linked third
41 // party clients seeking to provide a platform-specific implementation of 41 // party clients seeking to provide a platform-specific implementation of
42 // AudioManager. After this is called, all static AudioManager::Create* 42 // AudioManager. After this is called, all static AudioManager::Create*
43 // methods will return an instance of AudioManager provided by |factory|. This 43 // methods will return an instance of AudioManager provided by |factory|. This
44 // call may be made at most once per process, and before any calls to static 44 // call may be made at most once per process, and before any calls to static
45 // AudioManager::Create* methods. This method takes ownership of |factory|, 45 // AudioManager::Create* methods. This method takes ownership of |factory|,
46 // which must not be NULL. 46 // which must not be NULL.
47 static void SetFactory(AudioManagerFactory* factory); 47 static void SetFactory(AudioManagerFactory* factory);
48 48
49 // Construct the audio manager; only one instance is allowed. The manager 49 // Construct the audio manager; only one instance is allowed.
50 // will forward CreateAudioLog() calls to the provided AudioLogFactory; as 50 // The returned instance must be deleted on AudioManager::GetTaskRunnner().
51 // such |audio_log_factory| must outlive the AudioManager. 51 //
52 static AudioManager* Create(AudioLogFactory* audio_log_factory); 52 // The manager will forward CreateAudioLog() calls to the provided
53 // AudioLogFactory; as such |audio_log_factory| must outlive the AudioManager.
54 //
55 // The manager will use |task_runner| for audio IO. If the given |task_runner|
alokp 2016/03/18 16:27:25 We could make the task_runner arguments mandatory
DaleCurtis 2016/03/18 20:11:49 Hmm, if you take the scoped_ptr w/ custom deleter
56 // is NULL, the implementation will choose a default task runner, which can
57 // be obtained by calling GetTaskRunner().
58 //
59 // The manager will use |worker_task_runner| for heavyweight tasks.
60 // The |worker_task_runner| may be the same as |task_runner| or NULL, in
61 // which case the implementation will choose a default one.
62 //
63 // If |monitor_task_runner| is not NULL, a monitor will be scheduled on
DaleCurtis 2016/03/18 17:48:18 This should just say that a UMA will be logged now
alokp 2016/03/18 18:40:06 Done.
64 // to ensure that |task_runner| is not stuck for more than 60 seconds; if
65 // a hang is detected, the process will be crashed. See EnableHangMonitor().
66 static AudioManager* Create(
DaleCurtis 2016/03/18 17:48:18 Could we just have this return a scoped_ptr w/ cus
alokp 2016/03/18 18:40:07 Acknowledged.
67 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
DaleCurtis 2016/03/18 17:48:18 Per recent chromium-dev discussion, now that we ha
alokp 2016/03/18 18:40:07 Done.
68 const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner,
69 const scoped_refptr<base::SingleThreadTaskRunner>& monitor_task_runner,
70 AudioLogFactory* audio_log_factory);
53 71
54 // Similar to Create() except also schedules a monitor on the given task 72 // Helper function to ensure that AudioManager is properly shutdown
55 // runner to ensure the audio thread is not stuck for more than 60 seconds; if 73 // and destroyed on the audio thread.
56 // a hang is detected, the process will be crashed. See EnableHangMonitor(). 74 static void Destroy(AudioManager* instance);
57 static AudioManager* CreateWithHangTimer(
58 AudioLogFactory* audio_log_factory,
59 const scoped_refptr<base::SingleThreadTaskRunner>& monitor_task_runner);
60
61 // Similar to Create() except uses a FakeAudioLogFactory for testing.
62 static AudioManager* CreateForTesting();
DaleCurtis 2016/03/18 17:48:18 As mentioned elsewhere this might be worth keeping
alokp 2016/03/18 18:40:07 Just one task_runner should be sufficient - no wor
DaleCurtis 2016/03/18 20:11:49 Correct.
63 75
64 // Enables non-crash dumps when audio thread hangs are detected. 76 // Enables non-crash dumps when audio thread hangs are detected.
65 // TODO(dalecurtis): There are no callers to this function at present. A list 77 // TODO(dalecurtis): There are no callers to this function at present. A list
66 // of bad drivers has been given to Microsoft. This should be re-enabled in 78 // of bad drivers has been given to Microsoft. This should be re-enabled in
67 // the future if Microsoft is able to triage third party drivers. 79 // the future if Microsoft is able to triage third party drivers.
68 // See http://crbug.com/422522 80 // See http://crbug.com/422522
69 static void EnableCrashKeyLoggingForAudioThreadHangs(); 81 static void EnableCrashKeyLoggingForAudioThreadHangs();
70 82
71 #if defined(OS_LINUX) 83 #if defined(OS_LINUX)
72 // Sets the name of the audio source as seen by external apps. Only actually 84 // Sets the name of the audio source as seen by external apps. Only actually
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 // Returns NULL if the combination of the parameters is not supported, or if 183 // Returns NULL if the combination of the parameters is not supported, or if
172 // we have reached some other platform specific limit. 184 // we have reached some other platform specific limit.
173 // 185 //
174 // Do not free the returned AudioInputStream. It is owned by AudioManager. 186 // Do not free the returned AudioInputStream. It is owned by AudioManager.
175 // When you are done with it, call |Stop()| and |Close()| to release it. 187 // When you are done with it, call |Stop()| and |Close()| to release it.
176 virtual AudioInputStream* MakeAudioInputStream( 188 virtual AudioInputStream* MakeAudioInputStream(
177 const AudioParameters& params, 189 const AudioParameters& params,
178 const std::string& device_id) = 0; 190 const std::string& device_id) = 0;
179 191
180 // Returns the task runner used for audio IO. 192 // Returns the task runner used for audio IO.
181 virtual scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() = 0; 193 // TODO(alokp): Rename to task_runner().
194 scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() const {
195 return task_runner_;
196 }
182 197
183 // Heavyweight tasks should use GetWorkerTaskRunner() instead of 198 // Heavyweight tasks should use GetWorkerTaskRunner() instead of
184 // GetTaskRunner(). On most platforms they are the same, but some share the 199 // GetTaskRunner(). On most platforms they are the same, but some share the
185 // UI loop with the audio IO loop. 200 // UI loop with the audio IO loop.
186 virtual scoped_refptr<base::SingleThreadTaskRunner> GetWorkerTaskRunner() = 0; 201 // TODO(alokp): Rename to worker_task_runner().
202 scoped_refptr<base::SingleThreadTaskRunner> GetWorkerTaskRunner() const {
203 return worker_task_runner_;
204 }
187 205
188 // Allows clients to listen for device state changes; e.g. preferred sample 206 // Allows clients to listen for device state changes; e.g. preferred sample
189 // rate or channel layout changes. The typical response to receiving this 207 // rate or channel layout changes. The typical response to receiving this
190 // callback is to recreate the stream. 208 // callback is to recreate the stream.
191 class AudioDeviceListener { 209 class AudioDeviceListener {
192 public: 210 public:
193 virtual void OnDeviceChange() = 0; 211 virtual void OnDeviceChange() = 0;
194 }; 212 };
195 213
196 virtual void AddOutputDeviceChangeListener(AudioDeviceListener* listener) = 0; 214 virtual void AddOutputDeviceChangeListener(AudioDeviceListener* listener) = 0;
(...skipping 26 matching lines...) Expand all
223 // GetWorkerTaskRunner()). 241 // GetWorkerTaskRunner()).
224 virtual std::string GetAssociatedOutputDeviceID( 242 virtual std::string GetAssociatedOutputDeviceID(
225 const std::string& input_device_id) = 0; 243 const std::string& input_device_id) = 0;
226 244
227 // Create a new AudioLog object for tracking the behavior for one or more 245 // Create a new AudioLog object for tracking the behavior for one or more
228 // instances of the given component. See AudioLogFactory for more details. 246 // instances of the given component. See AudioLogFactory for more details.
229 virtual scoped_ptr<AudioLog> CreateAudioLog( 247 virtual scoped_ptr<AudioLog> CreateAudioLog(
230 AudioLogFactory::AudioComponent component) = 0; 248 AudioLogFactory::AudioComponent component) = 0;
231 249
232 protected: 250 protected:
233 AudioManager(); 251 AudioManager(
252 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
253 const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner);
234 254
235 private: 255 private:
256 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
257 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner_;
236 DISALLOW_COPY_AND_ASSIGN(AudioManager); 258 DISALLOW_COPY_AND_ASSIGN(AudioManager);
237 }; 259 };
238 260
239 } // namespace media 261 } // namespace media
240 262
241 #endif // MEDIA_AUDIO_AUDIO_MANAGER_H_ 263 #endif // MEDIA_AUDIO_AUDIO_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698