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 enumerate/open/close from | 7 // browser IO thread, handles queries like enumerate/open/close from |
8 // MediaStreamManager and start/stop from AudioInputRendererHost. | 8 // MediaStreamManager and start/stop from AudioInputRendererHost. |
9 // The work for enumerate/open/close is handled asynchronously on Media Stream | 9 // The work for enumerate/open/close is handled asynchronously on Media Stream |
10 // device thread, while start/stop are synchronous on the IO thread. | 10 // device thread, while start/stop are synchronous on the IO thread. |
11 | 11 |
12 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_DEVICE_MANAGER_H_ | 12 #ifndef CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_DEVICE_MANAGER_H_ |
13 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_DEVICE_MANAGER_H_ | 13 #define CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_DEVICE_MANAGER_H_ |
14 | 14 |
15 #include <map> | 15 #include <map> |
16 | 16 |
17 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
18 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
19 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
20 #include "content/browser/renderer_host/media/media_stream_provider.h" | 20 #include "content/browser/renderer_host/media/media_stream_provider.h" |
21 #include "content/common/content_export.h" | 21 #include "content/common/content_export.h" |
22 #include "content/common/media/media_stream_options.h" | 22 #include "content/common/media/media_stream_options.h" |
23 #include "media/audio/audio_device_name.h" | 23 #include "content/public/common/media_stream_request.h" |
24 | 24 |
25 namespace media { | 25 namespace media { |
26 class AudioManager; | 26 class AudioManager; |
27 } | 27 } |
28 | 28 |
29 namespace media_stream { | 29 namespace media_stream { |
30 | 30 |
31 class AudioInputDeviceManagerEventHandler; | 31 class AudioInputDeviceManagerEventHandler; |
32 | 32 |
33 class CONTENT_EXPORT AudioInputDeviceManager | 33 class CONTENT_EXPORT AudioInputDeviceManager : public MediaStreamProvider { |
34 : public base::RefCountedThreadSafe<AudioInputDeviceManager>, | |
35 public MediaStreamProvider { | |
36 public: | 34 public: |
37 // Calling Start() with this kFakeOpenSessionId will open the default device, | 35 // 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 | 36 // even though Open() has not been called. This is used to be able to use the |
39 // AudioInputDeviceManager before MediaStream is implemented. | 37 // AudioInputDeviceManager before MediaStream is implemented. |
40 static const int kFakeOpenSessionId; | 38 static const int kFakeOpenSessionId; |
41 | 39 |
42 explicit AudioInputDeviceManager(media::AudioManager* audio_manager); | 40 explicit AudioInputDeviceManager(media::AudioManager* audio_manager); |
43 | 41 |
44 // MediaStreamProvider implementation, called on IO thread. | 42 // MediaStreamProvider implementation, called on IO thread. |
45 virtual void Register(MediaStreamProviderListener* listener, | 43 virtual void Register(MediaStreamProviderListener* listener, |
46 base::MessageLoopProxy* device_thread_loop) OVERRIDE; | 44 base::MessageLoopProxy* device_thread_loop) OVERRIDE; |
47 virtual void Unregister() OVERRIDE; | 45 virtual void Unregister() OVERRIDE; |
48 virtual void EnumerateDevices() OVERRIDE; | 46 virtual void EnumerateDevices() OVERRIDE; |
49 virtual int Open(const StreamDeviceInfo& device) OVERRIDE; | 47 virtual int Open(const StreamDeviceInfo& device) OVERRIDE; |
50 virtual void Close(int session_id) OVERRIDE; | 48 virtual void Close(int session_id) OVERRIDE; |
51 | 49 |
52 // Functions used by AudioInputRenderHost, called on IO thread. | 50 // Functions used by AudioInputRenderHost, called on IO thread. |
53 // Starts the device referenced by the session id. | 51 // Starts the device referenced by the session id. |
54 void Start(int session_id, AudioInputDeviceManagerEventHandler* handler); | 52 void Start(int session_id, AudioInputDeviceManagerEventHandler* handler); |
55 // Stops the device referenced by the session id. | 53 // Stops the device referenced by the session id. |
56 void Stop(int session_id); | 54 void Stop(int session_id); |
57 | 55 |
58 private: | 56 private: |
59 typedef std::map<int, AudioInputDeviceManagerEventHandler*> EventHandlerMap; | 57 typedef std::map<int, AudioInputDeviceManagerEventHandler*> EventHandlerMap; |
60 typedef std::map<int, media::AudioDeviceName> AudioInputDeviceMap; | 58 typedef std::map<int, StreamDeviceInfo> StreamDeviceMap; |
61 | |
62 friend class base::RefCountedThreadSafe<AudioInputDeviceManager>; | |
63 virtual ~AudioInputDeviceManager(); | 59 virtual ~AudioInputDeviceManager(); |
64 | 60 |
65 // Enumerates audio input devices on media stream device thread. | 61 // Enumerates audio input devices on media stream device thread. |
66 void EnumerateOnDeviceThread(); | 62 void EnumerateOnDeviceThread(); |
67 // Opens the device on media stream device thread. | 63 // Opens the device on media stream device thread. |
68 void OpenOnDeviceThread(int session_id, const StreamDeviceInfo& device); | 64 void OpenOnDeviceThread(int session_id, const StreamDeviceInfo& device); |
69 // Closes the deivce on the media stream device thread. | 65 // Closes the deivce on the media stream device thread. |
70 void CloseOnDeviceThread(int session_id); | 66 void CloseOnDeviceThread(int session_id); |
71 | 67 |
72 // Callback used by EnumerateOnDeviceThread(), called with a list of | 68 // Callback used by EnumerateOnDeviceThread(), called with a list of |
73 // enumerated devices on IO thread. | 69 // enumerated devices on IO thread. |
74 void DevicesEnumeratedOnIOThread(StreamDeviceInfoArray* devices); | 70 void DevicesEnumeratedOnIOThread(StreamDeviceInfoArray* devices); |
75 // Callback used by OpenOnDeviceThread(), called with the session_id | 71 // Callback used by OpenOnDeviceThread(), called with the session_id |
76 // referencing the opened device on IO thread. | 72 // referencing the opened device on IO thread. |
77 void OpenedOnIOThread(int session_id); | 73 void OpenedOnIOThread(content::MediaStreamDeviceType type, int session_id); |
78 // Callback used by CloseOnDeviceThread(), called with the session_id | 74 // Callback used by CloseOnDeviceThread(), called with the session_id |
79 // referencing the closed device on IO thread. | 75 // referencing the closed device on IO thread. |
80 void ClosedOnIOThread(int session_id); | 76 void ClosedOnIOThread(content::MediaStreamDeviceType type, int session_id); |
81 | 77 |
82 // Verifies that the calling thread is media stream device thread. | 78 // Verifies that the calling thread is media stream device thread. |
83 bool IsOnDeviceThread() const; | 79 bool IsOnDeviceThread() const; |
84 | 80 |
85 // Only accessed on Browser::IO thread. | 81 // Only accessed on Browser::IO thread. |
86 MediaStreamProviderListener* listener_; | 82 MediaStreamProviderListener* listener_; |
87 int next_capture_session_id_; | 83 int next_capture_session_id_; |
88 EventHandlerMap event_handlers_; | 84 EventHandlerMap event_handlers_; |
89 | 85 |
90 // Only accessed from media stream device thread. | 86 // Only accessed from media stream device thread. |
91 AudioInputDeviceMap devices_; | 87 StreamDeviceMap devices_; |
92 media::AudioManager* audio_manager_; | 88 media::AudioManager* const audio_manager_; |
93 | 89 |
94 // The message loop of media stream device thread that this object runs on. | 90 // The message loop of media stream device thread that this object runs on. |
95 scoped_refptr<base::MessageLoopProxy> device_loop_; | 91 scoped_refptr<base::MessageLoopProxy> device_loop_; |
96 | 92 |
97 DISALLOW_COPY_AND_ASSIGN(AudioInputDeviceManager); | 93 DISALLOW_COPY_AND_ASSIGN(AudioInputDeviceManager); |
98 }; | 94 }; |
99 | 95 |
100 } // namespace media_stream | 96 } // namespace media_stream |
101 | 97 |
102 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_DEVICE_MANAGER_H_ | 98 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_DEVICE_MANAGER_H_ |
OLD | NEW |