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

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

Issue 2763383002: Switching AudioInputDeviceManager from using AudioManager interface to AudioSystem one. (Closed)
Patch Set: rebase 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 (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);
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,
71 const MediaStreamDevice& device,
72 base::TimeTicks start_time,
73 const media::AudioParameters& input_params,
74 const media::AudioParameters& matched_output_params,
75 const std::string& matched_output_device_id);
71 76
72 // Callback used by OpenOnDeviceThread(), called with the session_id 77 // Callback called on IO thread with the session_id referencing the closed
73 // referencing the opened device on IO thread. 78 // 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); 79 void ClosedOnIOThread(MediaStreamType type, int session_id);
78 80
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 81 // Helper to return iterator to the device referenced by |session_id|. If no
83 // device is found, it will return devices_.end(). 82 // device is found, it will return devices_.end().
84 StreamDeviceList::iterator GetDevice(int session_id); 83 StreamDeviceList::iterator GetDevice(int session_id);
85 84
86 #if defined(OS_CHROMEOS) 85 #if defined(OS_CHROMEOS)
87 // Calls Cras audio handler and sets keyboard mic active status. 86 // Calls Cras audio handler and sets keyboard mic active status.
88 void SetKeyboardMicStreamActiveOnUIThread(bool active); 87 void SetKeyboardMicStreamActiveOnUIThread(bool active);
89 #endif 88 #endif
90 89
91 // Only accessed on Browser::IO thread. 90 // Only accessed on Browser::IO thread.
92 base::ObserverList<MediaStreamProviderListener> listeners_; 91 base::ObserverList<MediaStreamProviderListener> listeners_;
93 int next_capture_session_id_; 92 int next_capture_session_id_;
94 StreamDeviceList devices_; 93 StreamDeviceList devices_;
95 94
96 #if defined(OS_CHROMEOS) 95 #if defined(OS_CHROMEOS)
97 // Keeps count of how many streams are using keyboard mic. 96 // Keeps count of how many streams are using keyboard mic.
98 int keyboard_mic_streams_count_; 97 int keyboard_mic_streams_count_;
99 #endif 98 #endif
100 99
101 media::AudioManager* const audio_manager_; // Weak. 100 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 101
106 DISALLOW_COPY_AND_ASSIGN(AudioInputDeviceManager); 102 DISALLOW_COPY_AND_ASSIGN(AudioInputDeviceManager);
107 }; 103 };
108 104
109 } // namespace content 105 } // namespace content
110 106
111 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_DEVICE_MANAGER_H_ 107 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_DEVICE_MANAGER_H_
OLDNEW
« no previous file with comments | « content/browser/browser_main_loop.h ('k') | content/browser/renderer_host/media/audio_input_device_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698