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