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

Side by Side Diff: content/browser/renderer_host/media/audio_input_device_manager.h

Issue 2350693002: Remove device enumeration, caching and monitoring from MediaStreamManager. (Closed)
Patch Set: Created 4 years, 3 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 // AudioInputDeviceManager manages the audio input devices. In particular it 5 // AudioInputDeviceManager manages the audio input devices. In particular it
6 // communicates with MediaStreamManager and AudioInputRendererHost on the 6 // communicates with MediaStreamManager and AudioInputRendererHost on the
7 // browser IO thread, handles queries like 7 // browser IO thread, handles queries like
8 // enumerate/open/close/GetOpenedDeviceInfoById from MediaStreamManager and 8 // enumerate/open/close/GetOpenedDeviceInfoById from MediaStreamManager and
9 // GetOpenedDeviceInfoById from AudioInputRendererHost. 9 // GetOpenedDeviceInfoById from AudioInputRendererHost.
10 // The work for enumerate/open/close is handled asynchronously on Media Stream 10 // The work for enumerate/open/close is handled asynchronously on Media Stream
11 // device thread, while GetOpenedDeviceInfoById is synchronous on the IO thread. 11 // device thread, while GetOpenedDeviceInfoById is synchronous on the IO thread.
12 12
13 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_DEVICE_MANAGER_H_ 13 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_DEVICE_MANAGER_H_
14 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_DEVICE_MANAGER_H_ 14 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_DEVICE_MANAGER_H_
15 15
16 #include <map> 16 #include <map>
17 #include <vector>
Guido Urdaneta 2016/09/19 13:12:25 This is a drive-by lint fix.
17 18
18 #include "base/macros.h" 19 #include "base/macros.h"
19 #include "base/memory/ref_counted.h" 20 #include "base/memory/ref_counted.h"
20 #include "base/threading/thread.h" 21 #include "base/threading/thread.h"
21 #include "build/build_config.h" 22 #include "build/build_config.h"
22 #include "content/browser/renderer_host/media/media_stream_provider.h" 23 #include "content/browser/renderer_host/media/media_stream_provider.h"
23 #include "content/common/content_export.h" 24 #include "content/common/content_export.h"
24 #include "content/common/media/media_stream_options.h" 25 #include "content/common/media/media_stream_options.h"
25 #include "content/public/common/media_stream_request.h" 26 #include "content/public/common/media_stream_request.h"
26 #include "media/audio/audio_device_name.h"
27 27
28 namespace media { 28 namespace media {
29 class AudioManager; 29 class AudioManager;
30 } 30 }
31 31
32 namespace content { 32 namespace content {
33 33
34 class CONTENT_EXPORT AudioInputDeviceManager : public MediaStreamProvider { 34 class CONTENT_EXPORT AudioInputDeviceManager : public MediaStreamProvider {
35 public: 35 public:
36 // Calling Start() with this kFakeOpenSessionId will open the default device, 36 // Calling Start() with this kFakeOpenSessionId will open the default device,
37 // even though Open() has not been called. This is used to be able to use the 37 // even though Open() has not been called. This is used to be able to use the
38 // AudioInputDeviceManager before MediaStream is implemented. 38 // AudioInputDeviceManager before MediaStream is implemented.
39 // TODO(xians): Remove it when the webrtc unittest does not need it any more. 39 // TODO(xians): Remove it when the webrtc unittest does not need it any more.
40 static const int kFakeOpenSessionId; 40 static const int kFakeOpenSessionId;
41 41
42 explicit AudioInputDeviceManager(media::AudioManager* audio_manager); 42 explicit AudioInputDeviceManager(media::AudioManager* audio_manager);
43 43
44 // Gets the opened device info by |session_id|. Returns NULL if the device 44 // Gets the opened device info by |session_id|. Returns NULL if the device
45 // is not opened, otherwise the opened device. Called on IO thread. 45 // is not opened, otherwise the opened device. Called on IO thread.
46 const StreamDeviceInfo* GetOpenedDeviceInfoById(int session_id); 46 const StreamDeviceInfo* GetOpenedDeviceInfoById(int session_id);
47 47
48 void Unregister(); 48 void Unregister();
49 49
50 // MediaStreamProvider implementation, called on IO thread. 50 // MediaStreamProvider implementation, called on IO thread.
51 void Register(MediaStreamProviderListener* listener, 51 void Register(MediaStreamProviderListener* listener,
52 const scoped_refptr<base::SingleThreadTaskRunner>& 52 const scoped_refptr<base::SingleThreadTaskRunner>&
53 device_task_runner) override; 53 device_task_runner) override;
54 void EnumerateDevices(MediaStreamType stream_type) override;
55 int Open(const StreamDeviceInfo& device) override; 54 int Open(const StreamDeviceInfo& device) override;
56 void Close(int session_id) override; 55 void Close(int session_id) override;
57 56
58 void UseFakeDevice();
59 bool ShouldUseFakeDevice() const;
60
61 #if defined(OS_CHROMEOS) 57 #if defined(OS_CHROMEOS)
62 // Registers and unregisters that a stream using keyboard mic has been opened 58 // Registers and unregisters that a stream using keyboard mic has been opened
63 // or closed. Keeps count of how many such streams are open and activates and 59 // or closed. Keeps count of how many such streams are open and activates and
64 // inactivates the keyboard mic accordingly. The (in)activation is done on the 60 // inactivates the keyboard mic accordingly. The (in)activation is done on the
65 // UI thread and for the register case a callback must therefor be provided 61 // UI thread and for the register case a callback must therefor be provided
66 // which is called when activated. 62 // which is called when activated.
67 // Called on the IO thread. 63 // Called on the IO thread.
68 void RegisterKeyboardMicStream(const base::Closure& callback); 64 void RegisterKeyboardMicStream(const base::Closure& callback);
69 void UnregisterKeyboardMicStream(); 65 void UnregisterKeyboardMicStream();
70 #endif 66 #endif
71 67
72 private: 68 private:
73 // Used by the unittests to get a list of fake devices.
74 friend class MediaStreamDispatcherHostTest;
75 void GetFakeDeviceNames(media::AudioDeviceNames* device_names);
76
77 typedef std::vector<StreamDeviceInfo> StreamDeviceList; 69 typedef std::vector<StreamDeviceInfo> StreamDeviceList;
78 ~AudioInputDeviceManager() override; 70 ~AudioInputDeviceManager() override;
79 71
80 // Enumerates audio input devices on media stream device thread.
81 void EnumerateOnDeviceThread(MediaStreamType stream_type);
82 // Opens the device on media stream device thread. 72 // Opens the device on media stream device thread.
83 void OpenOnDeviceThread(int session_id, const StreamDeviceInfo& info); 73 void OpenOnDeviceThread(int session_id, const StreamDeviceInfo& info);
84 74
85 // Callback used by EnumerateOnDeviceThread(), called with a list of
86 // enumerated devices on IO thread.
87 void DevicesEnumeratedOnIOThread(
88 MediaStreamType stream_type,
89 std::unique_ptr<StreamDeviceInfoArray> devices);
90 // Callback used by OpenOnDeviceThread(), called with the session_id 75 // Callback used by OpenOnDeviceThread(), called with the session_id
91 // referencing the opened device on IO thread. 76 // referencing the opened device on IO thread.
92 void OpenedOnIOThread(int session_id, const StreamDeviceInfo& info); 77 void OpenedOnIOThread(int session_id, const StreamDeviceInfo& info);
93 // Callback used by CloseOnDeviceThread(), called with the session_id 78 // Callback used by CloseOnDeviceThread(), called with the session_id
94 // referencing the closed device on IO thread. 79 // referencing the closed device on IO thread.
95 void ClosedOnIOThread(MediaStreamType type, int session_id); 80 void ClosedOnIOThread(MediaStreamType type, int session_id);
96 81
97 // Verifies that the calling thread is media stream device thread. 82 // Verifies that the calling thread is media stream device thread.
98 bool IsOnDeviceThread() const; 83 bool IsOnDeviceThread() const;
99 84
100 // Helper to return iterator to the device referenced by |session_id|. If no 85 // Helper to return iterator to the device referenced by |session_id|. If no
101 // device is found, it will return devices_.end(). 86 // device is found, it will return devices_.end().
102 StreamDeviceList::iterator GetDevice(int session_id); 87 StreamDeviceList::iterator GetDevice(int session_id);
103 88
104 #if defined(OS_CHROMEOS) 89 #if defined(OS_CHROMEOS)
105 // Calls Cras audio handler and sets keyboard mic active status. 90 // Calls Cras audio handler and sets keyboard mic active status.
106 void SetKeyboardMicStreamActiveOnUIThread(bool active); 91 void SetKeyboardMicStreamActiveOnUIThread(bool active);
107 #endif 92 #endif
108 93
109 // Only accessed on Browser::IO thread. 94 // Only accessed on Browser::IO thread.
110 MediaStreamProviderListener* listener_; 95 MediaStreamProviderListener* listener_;
111 int next_capture_session_id_; 96 int next_capture_session_id_;
112 bool use_fake_device_;
113 StreamDeviceList devices_; 97 StreamDeviceList devices_;
114 98
115 #if defined(OS_CHROMEOS) 99 #if defined(OS_CHROMEOS)
116 // Keeps count of how many streams are using keyboard mic. 100 // Keeps count of how many streams are using keyboard mic.
117 int keyboard_mic_streams_count_; 101 int keyboard_mic_streams_count_;
118 #endif 102 #endif
119 103
120 media::AudioManager* const audio_manager_; // Weak. 104 media::AudioManager* const audio_manager_; // Weak.
121 105
122 // The message loop of media stream device thread that this object runs on. 106 // The message loop of media stream device thread that this object runs on.
123 scoped_refptr<base::SingleThreadTaskRunner> device_task_runner_; 107 scoped_refptr<base::SingleThreadTaskRunner> device_task_runner_;
124 108
125 DISALLOW_COPY_AND_ASSIGN(AudioInputDeviceManager); 109 DISALLOW_COPY_AND_ASSIGN(AudioInputDeviceManager);
126 }; 110 };
127 111
128 } // namespace content 112 } // namespace content
129 113
130 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_DEVICE_MANAGER_H_ 114 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_DEVICE_MANAGER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698