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

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

Issue 2763383002: Switching AudioInputDeviceManager from using AudioManager interface to AudioSystem one. (Closed)
Patch Set: WeakPtr removed; combined GetInputDeviceInfo operation introduced Created 3 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 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:
25 // Replies are asynchronously sent from audio system thread to the thread the 26 // 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 27 // call is issued on. Attention! Audio system thread may outlive the client
27 // others, callbacks must always be bound to weak pointers! 28 // objects; bind callbacks with care.
28 using OnAudioParamsCallback = base::Callback<void(const AudioParameters&)>; 29 using OnAudioParamsCallback = base::Callback<void(const AudioParameters&)>;
29 using OnBoolCallback = base::Callback<void(bool)>; 30 using OnBoolCallback = base::Callback<void(bool)>;
30 using OnDeviceDescriptionsCallback = 31 using OnDeviceDescriptionsCallback =
31 base::Callback<void(AudioDeviceDescriptions)>; 32 base::Callback<void(AudioDeviceDescriptions)>;
33 using OnDeviceIdCallback = base::Callback<void(const std::string&)>;
34 using OnInputDeviceInfoCallback = base::Callback<
35 void(const AudioParameters&, const AudioParameters&, const std::string&)>;
32 36
37 // Must not be called on audio system thread if it differs from the one
38 // AudioSystem is destroyed on.
o1ka 2017/03/28 16:40:16 See also this comment https://cs.chromium.org/chro
DaleCurtis 2017/03/28 18:22:11 This comment will need resolution and removal befo
o1ka 2017/03/30 15:11:53 Agree. This is a problem shared between AM and AS.
33 static AudioSystem* Get(); 39 static AudioSystem* Get();
34 40
35 virtual ~AudioSystem(); 41 virtual ~AudioSystem();
36 42
37 // Callback may receive invalid parameters, it means the specified device is 43 // Callback may receive invalid parameters, it means the specified device is
38 // not found. This is best-effort: valid parameters do not guarantee existance 44 // not found. This is best-effort: valid parameters do not guarantee existance
39 // of the device. 45 // of the device.
40 // TODO(olka,tommi): fix all AudioManager implementations to return invalid 46 // TODO(olka,tommi): fix all AudioManager implementations to return invalid
41 // parameters if the device is not found. 47 // parameters if the device is not found.
42 virtual void GetInputStreamParameters( 48 virtual void GetInputStreamParameters(
43 const std::string& device_id, 49 const std::string& device_id,
44 OnAudioParamsCallback on_params_cb) const = 0; 50 OnAudioParamsCallback on_params_cb) const = 0;
45 51
46 // If media::AudioDeviceDescription::IsDefaultDevice(device_id) is true, 52 // If media::AudioDeviceDescription::IsDefaultDevice(device_id) is true,
47 // callback will receive the parameters of the default output device. 53 // callback will receive the parameters of the default output device.
48 // Callback may receive invalid parameters, it means the specified device is 54 // Callback may receive invalid parameters, it means the specified device is
49 // not found. This is best-effort: valid parameters do not guarantee existance 55 // not found. This is best-effort: valid parameters do not guarantee existance
50 // of the device. 56 // of the device.
51 // TODO(olka,tommi): fix all AudioManager implementations to return invalid 57 // TODO(olka,tommi): fix all AudioManager implementations to return invalid
52 // parameters if the device is not found. 58 // parameters if the device is not found.
53 virtual void GetOutputStreamParameters( 59 virtual void GetOutputStreamParameters(
54 const std::string& device_id, 60 const std::string& device_id,
55 OnAudioParamsCallback on_params_cb) const = 0; 61 OnAudioParamsCallback on_params_cb) const = 0;
56 62
57 virtual void HasInputDevices(OnBoolCallback on_has_devices_cb) const = 0; 63 virtual void HasInputDevices(OnBoolCallback on_has_devices_cb) const = 0;
58 64
59 // Replies with device descriptions of input audio devices if |for_input| is 65 // Replies with device descriptions of input audio devices if |for_input| is
60 // true, and of output audio devices otherwise. 66 // true, and of output audio devices otherwise.
61 virtual void GetDeviceDescriptions( 67 virtual void GetDeviceDescriptions(
62 OnDeviceDescriptionsCallback on_descriptions_cp, 68 OnDeviceDescriptionsCallback on_descriptions_cb,
63 bool for_input) = 0; 69 bool for_input) = 0;
64 70
71 // Replies with an empty string if there is no associated output device found.
72 virtual void GetAssociatedOutputDeviceID(
73 const std::string& input_device_id,
74 OnDeviceIdCallback on_device_id_cb) = 0;
o1ka 2017/03/28 16:40:16 This method will be used by WebRTC private API as
75
76 // Replies with audio parameters for the specified input device and audio
77 // parameters and device ID of the associated output device, if any (otherwise
78 // it's AudioParameters() and an empty string).
79 virtual void GetInputDeviceInfo(
80 const std::string& input_device_id,
81 OnInputDeviceInfoCallback on_input_device_info_cb) = 0;
o1ka 2017/03/28 16:40:16 I do not really like it because it's basically a c
DaleCurtis 2017/03/28 18:22:11 I guess it depends on how callers end up using thi
o1ka 2017/03/30 15:11:53 Each of the operations has multiple users. AudioIn
82
65 virtual base::SingleThreadTaskRunner* GetTaskRunner() const = 0; 83 virtual base::SingleThreadTaskRunner* GetTaskRunner() const = 0;
66 84
67 // Must not be used for anything but stream creation. 85 // Must not be used for anything but stream creation.
68 virtual AudioManager* GetAudioManager() const = 0; 86 virtual AudioManager* GetAudioManager() const = 0;
69 87
70 protected: 88 protected:
71 // Sets the global AudioSystem pointer to the specified non-null value. 89 // Sets the global AudioSystem pointer to the specified non-null value.
72 static void SetInstance(AudioSystem* audio_system); 90 static void SetInstance(AudioSystem* audio_system);
73 91
74 // Sets the global AudioSystem pointer to null if it equals the specified one. 92 // Sets the global AudioSystem pointer to null if it equals the specified one.
75 static void ClearInstance(const AudioSystem* audio_system); 93 static void ClearInstance(const AudioSystem* audio_system);
76 }; 94 };
77 95
78 } // namespace media 96 } // namespace media
79 97
80 #endif // MEDIA_AUDIO_AUDIO_SYSTEM_H_ 98 #endif // MEDIA_AUDIO_AUDIO_SYSTEM_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698