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 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_DISPATCHER_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_DISPATCHER_H_ |
6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_DISPATCHER_H_ | 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_DISPATCHER_H_ |
7 | 7 |
8 #include <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/gtest_prod_util.h" | 13 #include "base/gtest_prod_util.h" |
14 #include "base/message_loop.h" | 14 #include "base/memory/weak_ptr.h" |
15 #include "base/memory/scoped_ptr.h" | |
scherkus (not reviewing)
2012/08/02 22:45:18
a->z ordering
wjia(left Chromium)
2012/08/03 21:53:45
Done.
| |
15 #include "content/common/content_export.h" | 16 #include "content/common/content_export.h" |
16 #include "content/common/media/media_stream_options.h" | 17 #include "content/common/media/media_stream_options.h" |
17 #include "content/public/renderer/render_view_observer.h" | 18 #include "content/public/renderer/render_view_observer.h" |
18 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" | 19 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" |
19 | 20 |
21 namespace base { | |
22 class MessageLoopProxy; | |
23 } | |
24 | |
20 class RenderViewImpl; | 25 class RenderViewImpl; |
21 | 26 |
22 // MediaStreamDispatcher is a delegate for the Media Stream API messages. | 27 // MediaStreamDispatcher is a delegate for the Media Stream API messages. |
23 // MediaStreams are used by WebKit to open media devices such as Video Capture | 28 // MediaStreams are used by WebKit to open media devices such as Video Capture |
24 // and Audio input devices. | 29 // and Audio input devices. |
25 // It's the complement of MediaStreamDispatcherHost (owned by | 30 // It's the complement of MediaStreamDispatcherHost (owned by |
26 // BrowserRenderProcessHost). | 31 // BrowserRenderProcessHost). |
27 class CONTENT_EXPORT MediaStreamDispatcher | 32 class CONTENT_EXPORT MediaStreamDispatcher |
28 : public content::RenderViewObserver { | 33 : public content::RenderViewObserver { |
29 public: | 34 public: |
(...skipping 15 matching lines...) Expand all Loading... | |
45 // Stop a started stream. Label is the label provided in OnStreamGenerated. | 50 // Stop a started stream. Label is the label provided in OnStreamGenerated. |
46 virtual void StopStream(const std::string& label); | 51 virtual void StopStream(const std::string& label); |
47 | 52 |
48 // Request to enumerate devices. | 53 // Request to enumerate devices. |
49 void EnumerateDevices( | 54 void EnumerateDevices( |
50 int request_id, | 55 int request_id, |
51 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | 56 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, |
52 media_stream::MediaStreamType type, | 57 media_stream::MediaStreamType type, |
53 const GURL& security_origin); | 58 const GURL& security_origin); |
54 | 59 |
60 // Request to stop enumerating devices. | |
61 void StopEnumerateDevices( | |
62 int request_id, | |
63 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler); | |
64 | |
55 // Request to open a device. | 65 // Request to open a device. |
56 void OpenDevice( | 66 void OpenDevice( |
57 int request_id, | 67 int request_id, |
58 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | 68 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, |
59 const std::string& device_id, | 69 const std::string& device_id, |
60 media_stream::MediaStreamType type, | 70 media_stream::MediaStreamType type, |
61 const GURL& security_origin); | 71 const GURL& security_origin); |
62 | 72 |
63 // Close a started device. |label| is provided in OnDeviceOpened. | 73 // Close a started device. |label| is provided in OnDeviceOpened. |
64 void CloseDevice(const std::string& label); | 74 void CloseDevice(const std::string& label); |
(...skipping 11 matching lines...) Expand all Loading... | |
76 FRIEND_TEST_ALL_PREFIXES(MediaStreamDispatcherTest, BasicVideoDevice); | 86 FRIEND_TEST_ALL_PREFIXES(MediaStreamDispatcherTest, BasicVideoDevice); |
77 FRIEND_TEST_ALL_PREFIXES(MediaStreamDispatcherTest, TestFailure); | 87 FRIEND_TEST_ALL_PREFIXES(MediaStreamDispatcherTest, TestFailure); |
78 FRIEND_TEST_ALL_PREFIXES(MediaStreamDispatcherTest, CancelGenerateStream); | 88 FRIEND_TEST_ALL_PREFIXES(MediaStreamDispatcherTest, CancelGenerateStream); |
79 | 89 |
80 struct Request; | 90 struct Request; |
81 | 91 |
82 // Private class for keeping track of opened devices and who have | 92 // Private class for keeping track of opened devices and who have |
83 // opened it. | 93 // opened it. |
84 struct Stream; | 94 struct Stream; |
85 | 95 |
96 struct EnumerationRequest { | |
97 EnumerationRequest( | |
98 const base::WeakPtr<MediaStreamDispatcherEventHandler>& handler, | |
99 int request_id); | |
100 ~EnumerationRequest(); | |
101 | |
102 base::WeakPtr<MediaStreamDispatcherEventHandler> handler; | |
103 int request_id; | |
104 }; | |
105 | |
106 // List of requests made to EnumerateDevices. | |
107 typedef std::list<EnumerationRequest> EnumerationRequestList; | |
108 | |
109 struct EnumerationState { | |
110 EnumerationState(); | |
111 ~EnumerationState(); | |
112 | |
113 struct CachedDevices; | |
114 | |
115 // If |ipc_id| >= 0, then we've started. | |
116 int ipc_id; | |
117 scoped_ptr<CachedDevices> cached_devices; | |
118 EnumerationRequestList requests; | |
119 }; | |
120 | |
86 // Messages from the browser. | 121 // Messages from the browser. |
87 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 122 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
88 void OnStreamGenerated( | 123 void OnStreamGenerated( |
89 int request_id, | 124 int request_id, |
90 const std::string& label, | 125 const std::string& label, |
91 const media_stream::StreamDeviceInfoArray& audio_array, | 126 const media_stream::StreamDeviceInfoArray& audio_array, |
92 const media_stream::StreamDeviceInfoArray& video_array); | 127 const media_stream::StreamDeviceInfoArray& video_array); |
93 void OnStreamGenerationFailed(int request_id); | 128 void OnStreamGenerationFailed(int request_id); |
94 void OnVideoDeviceFailed(const std::string& label, int index); | 129 void OnVideoDeviceFailed(const std::string& label, int index); |
95 void OnAudioDeviceFailed(const std::string& label, int index); | 130 void OnAudioDeviceFailed(const std::string& label, int index); |
96 void OnDevicesEnumerated( | 131 void OnDevicesEnumerated( |
97 int request_id, | 132 int request_id, |
133 const std::string& label, | |
98 const media_stream::StreamDeviceInfoArray& device_array); | 134 const media_stream::StreamDeviceInfoArray& device_array); |
99 void OnDevicesEnumerationFailed(int request_id); | 135 void OnDevicesEnumerationFailed(int request_id); |
100 void OnDeviceOpened( | 136 void OnDeviceOpened( |
101 int request_id, | 137 int request_id, |
102 const std::string& label, | 138 const std::string& label, |
103 const media_stream::StreamDeviceInfo& device_info); | 139 const media_stream::StreamDeviceInfo& device_info); |
104 void OnDeviceOpenFailed(int request_id); | 140 void OnDeviceOpenFailed(int request_id); |
105 | 141 |
142 bool RemoveEnumerationRequest( | |
143 int request_id, | |
144 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | |
145 EnumerationState* state); | |
146 | |
147 // Used for DCHECKs so methods calls won't execute in the wrong thread. | |
148 scoped_refptr<base::MessageLoopProxy> main_loop_; | |
149 | |
106 int next_ipc_id_; | 150 int next_ipc_id_; |
107 typedef std::map<std::string, Stream> LabelStreamMap; | 151 typedef std::map<std::string, Stream> LabelStreamMap; |
108 LabelStreamMap label_stream_map_; | 152 LabelStreamMap label_stream_map_; |
109 | 153 |
154 EnumerationState audio_enumeration_state_; | |
155 EnumerationState video_enumeration_state_; | |
156 | |
110 // List of calls made to GenerateStream that has not yet completed. | 157 // List of calls made to GenerateStream that has not yet completed. |
111 typedef std::list<Request> RequestList; | 158 typedef std::list<Request> RequestList; |
112 RequestList requests_; | 159 RequestList requests_; |
113 | 160 |
114 DISALLOW_COPY_AND_ASSIGN(MediaStreamDispatcher); | 161 DISALLOW_COPY_AND_ASSIGN(MediaStreamDispatcher); |
115 }; | 162 }; |
116 | 163 |
117 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_DISPATCHER_H_ | 164 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_DISPATCHER_H_ |
OLD | NEW |