OLD | NEW |
---|---|
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> | 17 #include <vector> |
18 | 18 |
19 #include "base/macros.h" | 19 #include "base/macros.h" |
20 #include "base/memory/ref_counted.h" | 20 #include "base/memory/ref_counted.h" |
21 #include "base/threading/thread.h" | 21 #include "base/threading/thread.h" |
22 #include "build/build_config.h" | 22 #include "build/build_config.h" |
23 #include "content/browser/renderer_host/media/media_stream_provider.h" | 23 #include "content/browser/renderer_host/media/media_stream_provider.h" |
24 #include "content/common/content_export.h" | 24 #include "content/common/content_export.h" |
25 #include "content/common/media/media_stream_options.h" | 25 #include "content/common/media/media_stream_options.h" |
26 #include "content/public/common/media_stream_request.h" | 26 #include "content/public/common/media_stream_request.h" |
27 | 27 |
28 namespace media { | 28 namespace media { |
29 class AudioManager; | 29 class AudioSystem; |
30 } | 30 } |
31 | 31 |
32 namespace content { | 32 namespace content { |
33 | 33 |
34 // Should be used on IO thread only. | 34 // Should be used on IO thread only. |
35 class CONTENT_EXPORT AudioInputDeviceManager : public MediaStreamProvider { | 35 class CONTENT_EXPORT AudioInputDeviceManager : public MediaStreamProvider { |
36 public: | 36 public: |
37 // Calling Start() with this kFakeOpenSessionId will open the default device, | 37 // Calling Start() with this kFakeOpenSessionId will open the default device, |
38 // even though Open() has not been called. This is used to be able to use the | 38 // even though Open() has not been called. This is used to be able to use the |
39 // AudioInputDeviceManager before MediaStream is implemented. | 39 // AudioInputDeviceManager before MediaStream is implemented. |
40 // TODO(xians): Remove it when the webrtc unittest does not need it any more. | 40 // TODO(xians): Remove it when the webrtc unittest does not need it any more. |
41 static const int kFakeOpenSessionId; | 41 static const int kFakeOpenSessionId; |
42 | 42 |
43 explicit AudioInputDeviceManager(media::AudioManager* audio_manager); | 43 explicit AudioInputDeviceManager(media::AudioSystem* audio_system); |
DaleCurtis
2017/03/22 19:08:34
Document lifetime.
| |
44 | 44 |
45 // Gets the opened device info by |session_id|. Returns NULL if the device | 45 // Gets the opened device info by |session_id|. Returns NULL if the device |
46 // is not opened, otherwise the opened device. Called on IO thread. | 46 // is not opened, otherwise the opened device. Called on IO thread. |
47 const StreamDeviceInfo* GetOpenedDeviceInfoById(int session_id); | 47 const StreamDeviceInfo* GetOpenedDeviceInfoById(int session_id); |
48 | 48 |
49 // MediaStreamProvider implementation. | 49 // MediaStreamProvider implementation. |
50 void RegisterListener(MediaStreamProviderListener* listener) override; | 50 void RegisterListener(MediaStreamProviderListener* listener) override; |
51 void UnregisterListener(MediaStreamProviderListener* listener) override; | 51 void UnregisterListener(MediaStreamProviderListener* listener) override; |
52 int Open(const MediaStreamDevice& device) override; | 52 int Open(const MediaStreamDevice& device) override; |
53 void Close(int session_id) override; | 53 void Close(int session_id) override; |
54 | 54 |
55 #if defined(OS_CHROMEOS) | 55 #if defined(OS_CHROMEOS) |
56 // Registers and unregisters that a stream using keyboard mic has been opened | 56 // Registers and unregisters that a stream using keyboard mic has been opened |
57 // or closed. Keeps count of how many such streams are open and activates and | 57 // or closed. Keeps count of how many such streams are open and activates and |
58 // inactivates the keyboard mic accordingly. The (in)activation is done on the | 58 // inactivates the keyboard mic accordingly. The (in)activation is done on the |
59 // UI thread and for the register case a callback must therefor be provided | 59 // UI thread and for the register case a callback must therefor be provided |
60 // which is called when activated. | 60 // which is called when activated. |
61 void RegisterKeyboardMicStream(const base::Closure& callback); | 61 void RegisterKeyboardMicStream(const base::Closure& callback); |
62 void UnregisterKeyboardMicStream(); | 62 void UnregisterKeyboardMicStream(); |
63 #endif | 63 #endif |
64 | 64 |
65 private: | 65 private: |
66 typedef std::vector<StreamDeviceInfo> StreamDeviceList; | 66 typedef std::vector<StreamDeviceInfo> StreamDeviceList; |
67 ~AudioInputDeviceManager() override; | 67 ~AudioInputDeviceManager() override; |
68 | 68 |
69 // Opens the device on media stream device thread. | 69 // Callback called on IO thread when device is opened. |
70 void OpenOnDeviceThread(int session_id, const MediaStreamDevice& device); | 70 void OpenedOnIOThread(int session_id, const StreamDeviceInfo& info); |
71 | 71 |
72 // Callback used by OpenOnDeviceThread(), called with the session_id | 72 // Callback called on IO thread with the session_id referencing the closed |
73 // referencing the opened device on IO thread. | 73 // device. |
74 void OpenedOnIOThread(int session_id, const StreamDeviceInfo& info); | |
75 // Callback used by CloseOnDeviceThread(), called with the session_id | |
76 // referencing the closed device on IO thread. | |
77 void ClosedOnIOThread(MediaStreamType type, int session_id); | 74 void ClosedOnIOThread(MediaStreamType type, int session_id); |
78 | 75 |
79 // Verifies that the calling thread is media stream device thread. | |
80 bool IsOnDeviceThread() const; | |
81 | |
82 // Helper to return iterator to the device referenced by |session_id|. If no | 76 // Helper to return iterator to the device referenced by |session_id|. If no |
83 // device is found, it will return devices_.end(). | 77 // device is found, it will return devices_.end(). |
84 StreamDeviceList::iterator GetDevice(int session_id); | 78 StreamDeviceList::iterator GetDevice(int session_id); |
85 | 79 |
86 #if defined(OS_CHROMEOS) | 80 #if defined(OS_CHROMEOS) |
87 // Calls Cras audio handler and sets keyboard mic active status. | 81 // Calls Cras audio handler and sets keyboard mic active status. |
88 void SetKeyboardMicStreamActiveOnUIThread(bool active); | 82 void SetKeyboardMicStreamActiveOnUIThread(bool active); |
89 #endif | 83 #endif |
90 | 84 |
91 // Only accessed on Browser::IO thread. | 85 // Only accessed on Browser::IO thread. |
92 base::ObserverList<MediaStreamProviderListener> listeners_; | 86 base::ObserverList<MediaStreamProviderListener> listeners_; |
93 int next_capture_session_id_; | 87 int next_capture_session_id_; |
94 StreamDeviceList devices_; | 88 StreamDeviceList devices_; |
95 | 89 |
96 #if defined(OS_CHROMEOS) | 90 #if defined(OS_CHROMEOS) |
97 // Keeps count of how many streams are using keyboard mic. | 91 // Keeps count of how many streams are using keyboard mic. |
98 int keyboard_mic_streams_count_; | 92 int keyboard_mic_streams_count_; |
99 #endif | 93 #endif |
100 | 94 |
101 media::AudioManager* const audio_manager_; // Weak. | 95 media::AudioSystem* const audio_system_; |
102 | |
103 // The message loop of media stream device thread that this object runs on. | |
104 scoped_refptr<base::SingleThreadTaskRunner> device_task_runner_; | |
105 | 96 |
106 DISALLOW_COPY_AND_ASSIGN(AudioInputDeviceManager); | 97 DISALLOW_COPY_AND_ASSIGN(AudioInputDeviceManager); |
107 }; | 98 }; |
108 | 99 |
109 } // namespace content | 100 } // namespace content |
110 | 101 |
111 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_DEVICE_MANAGER_H_ | 102 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_DEVICE_MANAGER_H_ |
OLD | NEW |