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

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

Issue 2763383002: Switching AudioInputDeviceManager from using AudioManager interface to AudioSystem one. (Closed)
Patch Set: Created 3 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 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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_SYSTEM_H_ 5 #ifndef MEDIA_AUDIO_AUDIO_SYSTEM_H_
6 #define MEDIA_AUDIO_AUDIO_SYSTEM_H_ 6 #define MEDIA_AUDIO_AUDIO_SYSTEM_H_
7 7
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/memory/weak_ptr.h"
9 #include "media/audio/audio_device_description.h" 10 #include "media/audio/audio_device_description.h"
10 #include "media/base/audio_parameters.h" 11 #include "media/base/audio_parameters.h"
11 #include "media/base/media_export.h" 12 #include "media/base/media_export.h"
12 13
13 namespace base { 14 namespace base {
14 class SingleThreadTaskRunner; 15 class SingleThreadTaskRunner;
15 } 16 }
16 17
17 namespace media { 18 namespace media {
18 class AudioManager; 19 class AudioManager;
19 20
20 // Work in progress: Provides asynchronous interface to AudioManager. All the 21 // Work in progress: Provides asynchronous interface to AudioManager. All the
21 // AudioManager clients will be switched to it, in preparation for moving 22 // AudioManager clients will be switched to it, in preparation for moving
22 // to Mojo audio service. 23 // to Mojo audio service.
23 class MEDIA_EXPORT AudioSystem { 24 class MEDIA_EXPORT AudioSystem {
24 public: 25 public:
26 class OnAudioThreadDeleter {
27 public:
28 void operator()(const AudioSystem* instance) const;
29 };
30
31 using UniquePtr = std::unique_ptr<AudioSystem, OnAudioThreadDeleter>;
32
25 // Replies are asynchronously sent from audio system thread to the thread the 33 // Replies are asynchronously sent from audio system thread to the thread the
26 // call is issued on. Attention! Since audio system thread may outlive all the 34 // call is issued on. Attention! Since audio system thread may outlive all the
27 // others, callbacks must always be bound to weak pointers! 35 // others, callbacks must always be bound to weak pointers!
28 using OnAudioParamsCallback = base::Callback<void(const AudioParameters&)>; 36 using OnAudioParamsCallback = base::Callback<void(const AudioParameters&)>;
29 using OnBoolCallback = base::Callback<void(bool)>; 37 using OnBoolCallback = base::Callback<void(bool)>;
30 using OnDeviceDescriptionsCallback = 38 using OnDeviceDescriptionsCallback =
31 base::Callback<void(AudioDeviceDescriptions)>; 39 base::Callback<void(AudioDeviceDescriptions)>;
40 using OnDeviceIdCallback = base::Callback<void(const std::string&)>;
32 41
42 // Must not be called on audio thread, since it outlives the global pointer.
33 static AudioSystem* Get(); 43 static AudioSystem* Get();
34 44
35 virtual ~AudioSystem(); 45 virtual ~AudioSystem();
36 46
37 // Callback may receive invalid parameters, it means the specified device is 47 // Callback may receive invalid parameters, it means the specified device is
38 // not found. This is best-effort: valid parameters do not guarantee existance 48 // not found. This is best-effort: valid parameters do not guarantee existance
39 // of the device. 49 // of the device.
40 // TODO(olka,tommi): fix all AudioManager implementations to return invalid 50 // TODO(olka,tommi): fix all AudioManager implementations to return invalid
41 // parameters if the device is not found. 51 // parameters if the device is not found.
42 virtual void GetInputStreamParameters( 52 virtual void GetInputStreamParameters(
43 const std::string& device_id, 53 const std::string& device_id,
44 OnAudioParamsCallback on_params_cb) const = 0; 54 OnAudioParamsCallback on_params_cb) const = 0;
45 55
46 // If media::AudioDeviceDescription::IsDefaultDevice(device_id) is true, 56 // If media::AudioDeviceDescription::IsDefaultDevice(device_id) is true,
47 // callback will receive the parameters of the default output device. 57 // callback will receive the parameters of the default output device.
48 // Callback may receive invalid parameters, it means the specified device is 58 // Callback may receive invalid parameters, it means the specified device is
49 // not found. This is best-effort: valid parameters do not guarantee existance 59 // not found. This is best-effort: valid parameters do not guarantee existance
50 // of the device. 60 // of the device.
51 // TODO(olka,tommi): fix all AudioManager implementations to return invalid 61 // TODO(olka,tommi): fix all AudioManager implementations to return invalid
52 // parameters if the device is not found. 62 // parameters if the device is not found.
53 virtual void GetOutputStreamParameters( 63 virtual void GetOutputStreamParameters(
54 const std::string& device_id, 64 const std::string& device_id,
55 OnAudioParamsCallback on_params_cb) const = 0; 65 OnAudioParamsCallback on_params_cb) const = 0;
56 66
57 virtual void HasInputDevices(OnBoolCallback on_has_devices_cb) const = 0; 67 virtual void HasInputDevices(OnBoolCallback on_has_devices_cb) const = 0;
58 68
59 // Replies with device descriptions of input audio devices if |for_input| is 69 // Replies with device descriptions of input audio devices if |for_input| is
60 // true, and of output audio devices otherwise. 70 // true, and of output audio devices otherwise.
61 virtual void GetDeviceDescriptions( 71 virtual void GetDeviceDescriptions(
62 OnDeviceDescriptionsCallback on_descriptions_cp, 72 OnDeviceDescriptionsCallback on_descriptions_cb,
63 bool for_input) = 0; 73 bool for_input) = 0;
64 74
75 virtual void GetAssociatedOutputDeviceID(
76 const std::string& input_device_id,
77 OnDeviceIdCallback on_device_id_cb) = 0;
78
79 // To be used on audio thread only.
DaleCurtis 2017/03/22 19:08:34 Sorry, this is bad practice, can you find another
80 // AudioSystem instance must be posted to its task runner in form of a weak
81 // pointer, since the task runner outlives it.
82 virtual base::WeakPtr<AudioSystem> GetWeakPtr() = 0;
83
65 virtual base::SingleThreadTaskRunner* GetTaskRunner() const = 0; 84 virtual base::SingleThreadTaskRunner* GetTaskRunner() const = 0;
66 85
67 // Must not be used for anything but stream creation. 86 // Must not be used for anything but stream creation.
68 virtual AudioManager* GetAudioManager() const = 0; 87 virtual AudioManager* GetAudioManager() const = 0;
69 88
70 protected: 89 protected:
71 // Sets the global AudioSystem pointer to the specified non-null value. 90 // Sets the global AudioSystem pointer to the specified non-null value.
72 static void SetInstance(AudioSystem* audio_system); 91 static void SetInstance(AudioSystem* audio_system);
73 92
74 // Sets the global AudioSystem pointer to null if it equals the specified one. 93 // Sets the global AudioSystem pointer to null if it equals the specified one.
75 static void ClearInstance(const AudioSystem* audio_system); 94 static void ClearInstance(const AudioSystem* audio_system);
76 }; 95 };
77 96
78 } // namespace media 97 } // namespace media
79 98
80 #endif // MEDIA_AUDIO_AUDIO_SYSTEM_H_ 99 #endif // MEDIA_AUDIO_AUDIO_SYSTEM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698