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 | 9 // The work for enumerate/open/close is handled asynchronously on Media Stream |
10 // All the queries and work are handled on the IO thread. | 10 // device thread, while start/stop are synchronous API on IO thread. |
tommi (sloooow) - chröme
2012/07/02 13:36:36
are synchronous on the IO thread.
no longer working on chromium
2012/07/04 12:35:25
Done.
| |
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/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
18 #include "base/threading/thread.h" | 18 #include "base/threading/thread.h" |
19 #include "content/browser/renderer_host/media/media_stream_provider.h" | 19 #include "content/browser/renderer_host/media/media_stream_provider.h" |
20 #include "content/common/content_export.h" | 20 #include "content/common/content_export.h" |
21 #include "content/common/media/media_stream_options.h" | 21 #include "content/common/media/media_stream_options.h" |
22 #include "media/audio/audio_device_name.h" | 22 #include "media/audio/audio_device_name.h" |
23 | 23 |
24 namespace media { | |
25 class AudioManager; | |
26 } | |
27 | |
28 namespace media_stream { | 24 namespace media_stream { |
29 | 25 |
30 class AudioInputDeviceManagerEventHandler; | 26 class AudioInputDeviceManagerEventHandler; |
31 | 27 |
32 class CONTENT_EXPORT AudioInputDeviceManager | 28 class CONTENT_EXPORT AudioInputDeviceManager |
33 : public base::RefCountedThreadSafe<AudioInputDeviceManager>, | 29 : public base::RefCountedThreadSafe<AudioInputDeviceManager>, |
34 public MediaStreamProvider { | 30 public MediaStreamProvider { |
35 public: | 31 public: |
36 // Calling Start() with this kFakeOpenSessionId will open the default device, | 32 // 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 | 33 // even though Open() has not been called. This is used to be able to use the |
38 // AudioInputDeviceManager before MediaStream is implemented. | 34 // AudioInputDeviceManager before MediaStream is implemented. |
39 static const int kFakeOpenSessionId; | 35 static const int kFakeOpenSessionId; |
40 | 36 |
41 static const int kInvalidSessionId; | 37 static const int kInvalidSessionId; |
42 static const char kInvalidDeviceId[]; | 38 static const char kInvalidDeviceId[]; |
43 | 39 |
44 explicit AudioInputDeviceManager(media::AudioManager* audio_manager); | 40 explicit AudioInputDeviceManager( |
41 scoped_refptr<base::MessageLoopProxy> message_loop); | |
tommi (sloooow) - chröme
2012/07/02 13:36:36
why scoped_refptr<> here? instead just do:
explic
tommi (sloooow) - chröme
2012/07/02 13:36:36
add a comment here about what message loop this is
no longer working on chromium
2012/07/04 12:35:25
Done with changing the name to device_loop.
I hav
no longer working on chromium
2012/07/04 12:35:25
Done.
| |
45 | 42 |
46 // MediaStreamProvider implementation, called on IO thread. | 43 // MediaStreamProvider implementation, called on IO thread. |
47 virtual void Register(MediaStreamProviderListener* listener) OVERRIDE; | 44 virtual void Register(MediaStreamProviderListener* listener) OVERRIDE; |
48 virtual void Unregister() OVERRIDE; | 45 virtual void Unregister() OVERRIDE; |
49 virtual void EnumerateDevices() OVERRIDE; | 46 virtual void EnumerateDevices() OVERRIDE; |
50 virtual int Open(const StreamDeviceInfo& device) OVERRIDE; | 47 virtual int Open(const StreamDeviceInfo& device) OVERRIDE; |
51 virtual void Close(int session_id) OVERRIDE; | 48 virtual void Close(int session_id) OVERRIDE; |
52 | 49 |
53 // Functions used by AudioInputRenderHost, called on IO thread. | 50 // Functions used by AudioInputRenderHost, called on IO thread. |
54 // Start the device referenced by the session id. | 51 // Start the device referenced by the session id. |
55 void Start(int session_id, | 52 void Start(int session_id, |
56 AudioInputDeviceManagerEventHandler* event_handler); | 53 AudioInputDeviceManagerEventHandler* event_handler); |
57 // Stop the device referenced by the session id. | 54 // Stop the device referenced by the session id. |
58 void Stop(int session_id); | 55 void Stop(int session_id); |
59 | 56 |
60 private: | 57 private: |
61 friend class base::RefCountedThreadSafe<AudioInputDeviceManager>; | 58 friend class base::RefCountedThreadSafe<AudioInputDeviceManager>; |
62 virtual ~AudioInputDeviceManager(); | 59 virtual ~AudioInputDeviceManager(); |
63 | 60 |
61 // Executed on media stream device thread. | |
62 void EnumerateOnDeviceThread(); | |
63 void OpenOnDeviceThread(int session_id, const StreamDeviceInfo& device); | |
64 void CloseOnDeviceThread(int session_id); | |
65 | |
64 // Executed on IO thread to call Listener. | 66 // Executed on IO thread to call Listener. |
65 void DevicesEnumeratedOnIOThread(StreamDeviceInfoArray* devices); | 67 void DevicesEnumeratedOnIOThread(StreamDeviceInfoArray* devices); |
66 void OpenedOnIOThread(int session_id); | 68 void OpenedOnIOThread(int session_id); |
67 void ClosedOnIOThread(int session_id); | 69 void ClosedOnIOThread(int session_id); |
68 void ErrorOnIOThread(int session_id, MediaStreamProviderError error); | 70 void ErrorOnIOThread(int session_id, MediaStreamProviderError error); |
69 | 71 |
72 // Helpers. | |
tommi (sloooow) - chröme
2012/07/02 13:36:36
this comment doesn't really add anything so just r
no longer working on chromium
2012/07/04 12:35:25
Done.
| |
73 bool IsOnDeviceThread() const; | |
74 | |
75 // Only accessed on Browser::IO thread. | |
70 MediaStreamProviderListener* listener_; | 76 MediaStreamProviderListener* listener_; |
71 int next_capture_session_id_; | 77 int next_capture_session_id_; |
72 typedef std::map<int, AudioInputDeviceManagerEventHandler*> EventHandlerMap; | 78 typedef std::map<int, AudioInputDeviceManagerEventHandler*> EventHandlerMap; |
73 EventHandlerMap event_handlers_; | 79 EventHandlerMap event_handlers_; |
80 | |
81 // Only accessed from media stream device thread. | |
74 typedef std::map<int, media::AudioDeviceName> AudioInputDeviceMap; | 82 typedef std::map<int, media::AudioDeviceName> AudioInputDeviceMap; |
75 AudioInputDeviceMap devices_; | 83 AudioInputDeviceMap devices_; |
76 // TODO(tommi): Is it necessary to store this as a member? | 84 |
77 media::AudioManager* audio_manager_; | 85 // The message loop of media stream device thread that this object runs on. |
86 scoped_refptr<base::MessageLoopProxy> message_loop_; | |
tommi (sloooow) - chröme
2012/07/02 13:36:36
device_loop_ or media_stream_loop_?
no longer working on chromium
2012/07/04 12:35:25
Done.
| |
78 | 87 |
79 DISALLOW_COPY_AND_ASSIGN(AudioInputDeviceManager); | 88 DISALLOW_COPY_AND_ASSIGN(AudioInputDeviceManager); |
80 }; | 89 }; |
81 | 90 |
82 } // namespace media_stream | 91 } // namespace media_stream |
83 | 92 |
84 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_DEVICE_MANAGER_H_ | 93 #endif // CONTENT_BROWSER_RENDERER_HOST_MEDIA_AUDIO_INPUT_DEVICE_MANAGER_H_ |
OLD | NEW |