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

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

Issue 1908423006: Allow content embedders to create AudioManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 <memory> 8 #include <memory>
9 #include <string> 9 #include <string>
10 10
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/sequenced_task_runner_helpers.h" 13 #include "base/sequenced_task_runner_helpers.h"
14 #include "base/strings/string16.h" 14 #include "base/strings/string16.h"
15 #include "build/build_config.h" 15 #include "build/build_config.h"
16 #include "media/audio/audio_device_name.h" 16 #include "media/audio/audio_device_name.h"
17 #include "media/audio/audio_logging.h" 17 #include "media/audio/audio_logging.h"
18 #include "media/base/audio_parameters.h" 18 #include "media/base/audio_parameters.h"
19 19
20 namespace base { 20 namespace base {
21 class SingleThreadTaskRunner; 21 class SingleThreadTaskRunner;
22 } 22 }
23 23
24 namespace media { 24 namespace media {
25 25
26 class AudioInputStream; 26 class AudioInputStream;
27 class AudioManager; 27 class AudioManager;
28 class AudioManagerFactory;
29 class AudioOutputStream; 28 class AudioOutputStream;
30 29
31 class MEDIA_EXPORT AudioManagerDeleter { 30 class MEDIA_EXPORT AudioManagerDeleter {
32 public: 31 public:
33 void operator()(const AudioManager* instance) const; 32 void operator()(const AudioManager* instance) const;
34 }; 33 };
35 using ScopedAudioManagerPtr = 34 using ScopedAudioManagerPtr =
36 std::unique_ptr<AudioManager, AudioManagerDeleter>; 35 std::unique_ptr<AudioManager, AudioManagerDeleter>;
37 36
38 // Manages all audio resources. Provides some convenience functions that avoid 37 // Manages all audio resources. Provides some convenience functions that avoid
39 // the need to provide iterators over the existing streams. 38 // the need to provide iterators over the existing streams.
40 // 39 //
41 // Except on OSX, a hang monitor for the audio thread is always created. When a 40 // Except on OSX, a hang monitor for the audio thread is always created. When a
42 // thread hang is detected, it is reported to UMA. Optionally, if called prior, 41 // thread hang is detected, it is reported to UMA. Optionally, if called prior,
43 // EnableCrashKeyLoggingForAudioThreadHangs() will cause a non-crash dump to be 42 // EnableCrashKeyLoggingForAudioThreadHangs() will cause a non-crash dump to be
44 // logged on Windows (this allows us to report driver hangs to Microsoft). 43 // logged on Windows (this allows us to report driver hangs to Microsoft).
45 class MEDIA_EXPORT AudioManager { 44 class MEDIA_EXPORT AudioManager {
46 public: 45 public:
47 // This provides an alternative to the statically linked factory method used
48 // to create AudioManager. This is useful for dynamically-linked third
49 // party clients seeking to provide a platform-specific implementation of
50 // AudioManager. After this is called, all static AudioManager::Create*
51 // methods will return an instance of AudioManager provided by |factory|. This
52 // call may be made at most once per process, and before any calls to static
53 // AudioManager::Create* methods. This method takes ownership of |factory|,
54 // which must not be NULL.
55 static void SetFactory(AudioManagerFactory* factory);
56
57 // Construct the audio manager; only one instance is allowed. 46 // Construct the audio manager; only one instance is allowed.
58 // The returned instance must be deleted on AudioManager::GetTaskRunnner(). 47 // The returned instance must be deleted on AudioManager::GetTaskRunnner().
59 // 48 //
60 // The manager will forward CreateAudioLog() calls to the provided 49 // The manager will forward CreateAudioLog() calls to the provided
61 // AudioLogFactory; as such |audio_log_factory| must outlive the AudioManager. 50 // AudioLogFactory; as such |audio_log_factory| must outlive the AudioManager.
62 // 51 //
63 // The manager will use |task_runner| for audio IO. This same task runner 52 // The manager will use |task_runner| for audio IO. This same task runner
64 // is returned by GetTaskRunner(). 53 // is returned by GetTaskRunner().
65 // On OS_MACOSX, CoreAudio requires that |task_runner| must belong to the 54 // On OS_MACOSX, CoreAudio requires that |task_runner| must belong to the
66 // main thread of the process, which in our case is sadly the browser UI 55 // main thread of the process, which in our case is sadly the browser UI
67 // thread. Failure to execute calls on the right thread leads to crashes and 56 // thread. Failure to execute calls on the right thread leads to crashes and
68 // odd behavior. See http://crbug.com/158170. 57 // odd behavior. See http://crbug.com/158170.
69 // 58 //
70 // The manager will use |worker_task_runner| for heavyweight tasks. 59 // The manager will use |worker_task_runner| for heavyweight tasks.
71 // The |worker_task_runner| may be the same as |task_runner|. This same 60 // The |worker_task_runner| may be the same as |task_runner|. This same
72 // task runner is returned by GetWorkerTaskRunner. 61 // task runner is returned by GetWorkerTaskRunner.
73 //
74 // If |monitor_task_runner| is not NULL, a monitor will be scheduled on
75 // |monitor_task_runner| to monitor |task_runner|. See EnableHangMonitor().
76 static ScopedAudioManagerPtr Create( 62 static ScopedAudioManagerPtr Create(
77 scoped_refptr<base::SingleThreadTaskRunner> task_runner, 63 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
78 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, 64 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner,
79 scoped_refptr<base::SingleThreadTaskRunner> monitor_task_runner,
80 AudioLogFactory* audio_log_factory); 65 AudioLogFactory* audio_log_factory);
81 66
82 // A convenience wrapper of AudioManager::Create for testing. 67 // A convenience wrapper of AudioManager::Create for testing.
83 // The given |task_runner| is shared for both audio io and heavyweight tasks. 68 // The given |task_runner| is shared for both audio io and heavyweight tasks.
84 static ScopedAudioManagerPtr CreateForTesting( 69 static ScopedAudioManagerPtr CreateForTesting(
85 scoped_refptr<base::SingleThreadTaskRunner> task_runner); 70 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
86 71
72 // Starts monitoring AudioManager task runner for hangs.
73 // Runs the monitor on the given |task_runner|, which must be different from
74 // AudioManager::GetTaskRunner to be meaningful.
75 // This must be called only after an AudioManager instance is created.
76 static void StartHangMonitor(
77 scoped_refptr<base::SingleThreadTaskRunner> task_runner);
78
87 // Enables non-crash dumps when audio thread hangs are detected. 79 // Enables non-crash dumps when audio thread hangs are detected.
88 // TODO(dalecurtis): There are no callers to this function at present. A list 80 // TODO(dalecurtis): There are no callers to this function at present. A list
89 // of bad drivers has been given to Microsoft. This should be re-enabled in 81 // of bad drivers has been given to Microsoft. This should be re-enabled in
90 // the future if Microsoft is able to triage third party drivers. 82 // the future if Microsoft is able to triage third party drivers.
91 // See http://crbug.com/422522 83 // See http://crbug.com/422522
92 static void EnableCrashKeyLoggingForAudioThreadHangs(); 84 static void EnableCrashKeyLoggingForAudioThreadHangs();
93 85
94 #if defined(OS_LINUX) 86 #if defined(OS_LINUX)
95 // Sets the name of the audio source as seen by external apps. Only actually 87 // Sets the name of the audio source as seen by external apps. Only actually
96 // used with PulseAudio as of this writing. 88 // used with PulseAudio as of this writing.
97 static void SetGlobalAppName(const std::string& app_name); 89 static void SetGlobalAppName(const std::string& app_name);
98 90
99 // Returns the app name or an empty string if it is not set. 91 // Returns the app name or an empty string if it is not set.
100 static const std::string& GetGlobalAppName(); 92 static const std::string& GetGlobalAppName();
101 #endif 93 #endif
102 94
103 // Should only be used for testing. Resets a previously-set
104 // AudioManagerFactory. The instance of AudioManager is not affected.
105 static void ResetFactoryForTesting();
106
107 // Returns the pointer to the last created instance, or NULL if not yet 95 // Returns the pointer to the last created instance, or NULL if not yet
108 // created. This is a utility method for the code outside of media directory, 96 // created. This is a utility method for the code outside of media directory,
109 // like src/chrome. 97 // like src/chrome.
110 static AudioManager* Get(); 98 static AudioManager* Get();
111 99
112 // Returns the localized name of the generic "default" device. 100 // Returns the localized name of the generic "default" device.
113 static std::string GetDefaultDeviceName(); 101 static std::string GetDefaultDeviceName();
114 102
115 // Returns the localized name of the generic default communications device. 103 // Returns the localized name of the generic default communications device.
116 // This device is not supported on all platforms. 104 // This device is not supported on all platforms.
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 friend class base::DeleteHelper<AudioManager>; 255 friend class base::DeleteHelper<AudioManager>;
268 256
269 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 257 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
270 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner_; 258 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner_;
271 DISALLOW_COPY_AND_ASSIGN(AudioManager); 259 DISALLOW_COPY_AND_ASSIGN(AudioManager);
272 }; 260 };
273 261
274 } // namespace media 262 } // namespace media
275 263
276 #endif // MEDIA_AUDIO_AUDIO_MANAGER_H_ 264 #endif // MEDIA_AUDIO_AUDIO_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698