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 #include "content/renderer/media/media_stream_dispatcher.h" | 5 #include "content/renderer/media/media_stream_dispatcher.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/message_loop/message_loop_proxy.h" | |
9 #include "content/common/media/media_stream_messages.h" | 8 #include "content/common/media/media_stream_messages.h" |
10 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" | 9 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" |
11 #include "content/renderer/render_thread_impl.h" | 10 #include "content/renderer/render_thread_impl.h" |
12 #include "content/renderer/render_view_impl.h" | |
13 #include "media/audio/audio_parameters.h" | 11 #include "media/audio/audio_parameters.h" |
14 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" | 12 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
15 #include "url/gurl.h" | 13 #include "url/gurl.h" |
16 | 14 |
17 namespace content { | 15 namespace content { |
18 | 16 |
19 namespace { | 17 namespace { |
20 | 18 |
21 bool RemoveStreamDeviceFromArray(const StreamDeviceInfo device_info, | 19 bool RemoveStreamDeviceFromArray(const StreamDeviceInfo device_info, |
22 StreamDeviceInfoArray* array) { | 20 StreamDeviceInfoArray* array) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 }; | 54 }; |
57 | 55 |
58 struct MediaStreamDispatcher::Stream { | 56 struct MediaStreamDispatcher::Stream { |
59 Stream() {} | 57 Stream() {} |
60 ~Stream() {} | 58 ~Stream() {} |
61 base::WeakPtr<MediaStreamDispatcherEventHandler> handler; | 59 base::WeakPtr<MediaStreamDispatcherEventHandler> handler; |
62 StreamDeviceInfoArray audio_array; | 60 StreamDeviceInfoArray audio_array; |
63 StreamDeviceInfoArray video_array; | 61 StreamDeviceInfoArray video_array; |
64 }; | 62 }; |
65 | 63 |
66 MediaStreamDispatcher::MediaStreamDispatcher(RenderViewImpl* render_view) | 64 MediaStreamDispatcher::MediaStreamDispatcher(RenderFrame* render_frame) |
67 : RenderViewObserver(render_view), | 65 : RenderFrameObserver(render_frame), |
68 main_loop_(base::MessageLoopProxy::current()), | |
69 next_ipc_id_(0) { | 66 next_ipc_id_(0) { |
70 } | 67 } |
71 | 68 |
72 MediaStreamDispatcher::~MediaStreamDispatcher() {} | 69 MediaStreamDispatcher::~MediaStreamDispatcher() {} |
73 | 70 |
74 void MediaStreamDispatcher::GenerateStream( | 71 void MediaStreamDispatcher::GenerateStream( |
75 int request_id, | 72 int request_id, |
76 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | 73 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, |
77 const StreamOptions& components, | 74 const StreamOptions& components, |
78 const GURL& security_origin) { | 75 const GURL& security_origin) { |
79 DCHECK(main_loop_->BelongsToCurrentThread()); | 76 DCHECK(thread_checker_.CalledOnValidThread()); |
80 DVLOG(1) << "MediaStreamDispatcher::GenerateStream(" << request_id << ")"; | 77 DVLOG(1) << "MediaStreamDispatcher::GenerateStream(" << request_id << ")"; |
81 | 78 |
82 requests_.push_back(Request(event_handler, request_id, next_ipc_id_)); | 79 requests_.push_back(Request(event_handler, request_id, next_ipc_id_)); |
83 Send(new MediaStreamHostMsg_GenerateStream( | 80 Send(new MediaStreamHostMsg_GenerateStream( |
84 routing_id(), next_ipc_id_++, components, security_origin, | 81 routing_id(), next_ipc_id_++, components, security_origin, |
85 blink::WebUserGestureIndicator::isProcessingUserGesture())); | 82 blink::WebUserGestureIndicator::isProcessingUserGesture())); |
86 } | 83 } |
87 | 84 |
88 void MediaStreamDispatcher::CancelGenerateStream( | 85 void MediaStreamDispatcher::CancelGenerateStream( |
89 int request_id, | 86 int request_id, |
90 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler) { | 87 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler) { |
91 DCHECK(main_loop_->BelongsToCurrentThread()); | 88 DCHECK(thread_checker_.CalledOnValidThread()); |
92 DVLOG(1) << "MediaStreamDispatcher::CancelGenerateStream" | 89 DVLOG(1) << "MediaStreamDispatcher::CancelGenerateStream" |
93 << ", {request_id = " << request_id << "}"; | 90 << ", {request_id = " << request_id << "}"; |
94 | 91 |
95 RequestList::iterator it = requests_.begin(); | 92 RequestList::iterator it = requests_.begin(); |
96 for (; it != requests_.end(); ++it) { | 93 for (; it != requests_.end(); ++it) { |
97 if (it->IsThisRequest(request_id, event_handler)) { | 94 if (it->IsThisRequest(request_id, event_handler)) { |
98 int ipc_request = it->ipc_request; | 95 int ipc_request = it->ipc_request; |
99 requests_.erase(it); | 96 requests_.erase(it); |
100 Send(new MediaStreamHostMsg_CancelGenerateStream(routing_id(), | 97 Send(new MediaStreamHostMsg_CancelGenerateStream(routing_id(), |
101 ipc_request)); | 98 ipc_request)); |
102 break; | 99 break; |
103 } | 100 } |
104 } | 101 } |
105 } | 102 } |
106 | 103 |
107 void MediaStreamDispatcher::StopStreamDevice( | 104 void MediaStreamDispatcher::StopStreamDevice( |
108 const StreamDeviceInfo& device_info) { | 105 const StreamDeviceInfo& device_info) { |
109 DCHECK(main_loop_->BelongsToCurrentThread()); | 106 DCHECK(thread_checker_.CalledOnValidThread()); |
110 DVLOG(1) << "MediaStreamDispatcher::StopStreamDevice" | 107 DVLOG(1) << "MediaStreamDispatcher::StopStreamDevice" |
111 << ", {device_id = " << device_info.device.id << "}"; | 108 << ", {device_id = " << device_info.device.id << "}"; |
112 // Remove |device_info| from all streams in |label_stream_map_|. | 109 // Remove |device_info| from all streams in |label_stream_map_|. |
113 bool device_found = false; | 110 bool device_found = false; |
114 LabelStreamMap::iterator stream_it = label_stream_map_.begin(); | 111 LabelStreamMap::iterator stream_it = label_stream_map_.begin(); |
115 while (stream_it != label_stream_map_.end()) { | 112 while (stream_it != label_stream_map_.end()) { |
116 StreamDeviceInfoArray& audio_array = stream_it->second.audio_array; | 113 StreamDeviceInfoArray& audio_array = stream_it->second.audio_array; |
117 StreamDeviceInfoArray& video_array = stream_it->second.video_array; | 114 StreamDeviceInfoArray& video_array = stream_it->second.video_array; |
118 | 115 |
119 if (RemoveStreamDeviceFromArray(device_info, &audio_array) || | 116 if (RemoveStreamDeviceFromArray(device_info, &audio_array) || |
120 RemoveStreamDeviceFromArray(device_info, &video_array)) { | 117 RemoveStreamDeviceFromArray(device_info, &video_array)) { |
121 device_found = true; | 118 device_found = true; |
122 if (audio_array.empty() && video_array.empty()) { | 119 if (audio_array.empty() && video_array.empty()) { |
123 label_stream_map_.erase(stream_it++); | 120 label_stream_map_.erase(stream_it++); |
124 continue; | 121 continue; |
125 } | 122 } |
126 } | 123 } |
127 ++stream_it; | 124 ++stream_it; |
128 } | 125 } |
129 | 126 |
130 if (!device_found) { | 127 if (!device_found) { |
131 // TODO(perkj): This can currently happen since there is one | 128 // TODO(perkj): Revisit this. It used to be true (but isn't anymore) that |
132 // MediaStreamDispatcher per RenderView but there is one MediaStreamImpl | 129 // there was one MediaStreamDispatcher per RenderView, but one |
133 // per RenderFrame. http://crbug/368030. | 130 // MediaStreamImpl per RenderFrame. Now both MediaStreamDispatcher and |
| 131 // MediaStreamImpl are 1:1 per RenderFrame. http://crbug/368030. |
134 return; | 132 return; |
135 } | 133 } |
136 | 134 |
137 Send(new MediaStreamHostMsg_StopStreamDevice(routing_id(), | 135 Send(new MediaStreamHostMsg_StopStreamDevice(routing_id(), |
138 device_info.device.id)); | 136 device_info.device.id)); |
139 } | 137 } |
140 | 138 |
141 void MediaStreamDispatcher::EnumerateDevices( | 139 void MediaStreamDispatcher::EnumerateDevices( |
142 int request_id, | 140 int request_id, |
143 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | 141 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, |
144 MediaStreamType type, | 142 MediaStreamType type, |
145 const GURL& security_origin, | 143 const GURL& security_origin, |
146 bool hide_labels_if_no_access) { | 144 bool hide_labels_if_no_access) { |
147 DCHECK(main_loop_->BelongsToCurrentThread()); | 145 DCHECK(thread_checker_.CalledOnValidThread()); |
148 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || | 146 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || |
149 type == MEDIA_DEVICE_VIDEO_CAPTURE || | 147 type == MEDIA_DEVICE_VIDEO_CAPTURE || |
150 type == MEDIA_DEVICE_AUDIO_OUTPUT); | 148 type == MEDIA_DEVICE_AUDIO_OUTPUT); |
151 DVLOG(1) << "MediaStreamDispatcher::EnumerateDevices(" | 149 DVLOG(1) << "MediaStreamDispatcher::EnumerateDevices(" |
152 << request_id << ")"; | 150 << request_id << ")"; |
153 | 151 |
154 for (RequestList::iterator it = requests_.begin(); it != requests_.end(); | 152 for (RequestList::iterator it = requests_.begin(); it != requests_.end(); |
155 ++it) { | 153 ++it) { |
156 DCHECK(!it->IsThisRequest(request_id, event_handler)); | 154 DCHECK(!it->IsThisRequest(request_id, event_handler)); |
157 } | 155 } |
158 | 156 |
159 requests_.push_back(Request(event_handler, request_id, next_ipc_id_)); | 157 requests_.push_back(Request(event_handler, request_id, next_ipc_id_)); |
160 Send(new MediaStreamHostMsg_EnumerateDevices(routing_id(), | 158 Send(new MediaStreamHostMsg_EnumerateDevices(routing_id(), |
161 next_ipc_id_++, | 159 next_ipc_id_++, |
162 type, | 160 type, |
163 security_origin, | 161 security_origin, |
164 hide_labels_if_no_access)); | 162 hide_labels_if_no_access)); |
165 } | 163 } |
166 | 164 |
167 void MediaStreamDispatcher::StopEnumerateDevices( | 165 void MediaStreamDispatcher::StopEnumerateDevices( |
168 int request_id, | 166 int request_id, |
169 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler) { | 167 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler) { |
170 DCHECK(main_loop_->BelongsToCurrentThread()); | 168 DCHECK(thread_checker_.CalledOnValidThread()); |
171 DVLOG(1) << "MediaStreamDispatcher::StopEnumerateDevices(" | 169 DVLOG(1) << "MediaStreamDispatcher::StopEnumerateDevices(" |
172 << request_id << ")"; | 170 << request_id << ")"; |
173 for (RequestList::iterator it = requests_.begin(); it != requests_.end(); | 171 for (RequestList::iterator it = requests_.begin(); it != requests_.end(); |
174 ++it) { | 172 ++it) { |
175 if (it->IsThisRequest(request_id, event_handler)) { | 173 if (it->IsThisRequest(request_id, event_handler)) { |
176 Send(new MediaStreamHostMsg_CancelEnumerateDevices(routing_id(), | 174 Send(new MediaStreamHostMsg_CancelEnumerateDevices(routing_id(), |
177 it->ipc_request)); | 175 it->ipc_request)); |
178 requests_.erase(it); | 176 requests_.erase(it); |
179 break; | 177 break; |
180 } | 178 } |
181 } | 179 } |
182 } | 180 } |
183 | 181 |
184 void MediaStreamDispatcher::OpenDevice( | 182 void MediaStreamDispatcher::OpenDevice( |
185 int request_id, | 183 int request_id, |
186 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | 184 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, |
187 const std::string& device_id, | 185 const std::string& device_id, |
188 MediaStreamType type, | 186 MediaStreamType type, |
189 const GURL& security_origin) { | 187 const GURL& security_origin) { |
190 DCHECK(main_loop_->BelongsToCurrentThread()); | 188 DCHECK(thread_checker_.CalledOnValidThread()); |
191 DVLOG(1) << "MediaStreamDispatcher::OpenDevice(" << request_id << ")"; | 189 DVLOG(1) << "MediaStreamDispatcher::OpenDevice(" << request_id << ")"; |
192 | 190 |
193 requests_.push_back(Request(event_handler, request_id, next_ipc_id_)); | 191 requests_.push_back(Request(event_handler, request_id, next_ipc_id_)); |
194 Send(new MediaStreamHostMsg_OpenDevice(routing_id(), | 192 Send(new MediaStreamHostMsg_OpenDevice(routing_id(), |
195 next_ipc_id_++, | 193 next_ipc_id_++, |
196 device_id, | 194 device_id, |
197 type, | 195 type, |
198 security_origin)); | 196 security_origin)); |
199 } | 197 } |
200 | 198 |
201 void MediaStreamDispatcher::CancelOpenDevice( | 199 void MediaStreamDispatcher::CancelOpenDevice( |
202 int request_id, | 200 int request_id, |
203 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler) { | 201 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler) { |
204 CancelGenerateStream(request_id, event_handler); | 202 CancelGenerateStream(request_id, event_handler); |
205 } | 203 } |
206 | 204 |
207 void MediaStreamDispatcher::CloseDevice(const std::string& label) { | 205 void MediaStreamDispatcher::CloseDevice(const std::string& label) { |
208 DCHECK(main_loop_->BelongsToCurrentThread()); | 206 DCHECK(thread_checker_.CalledOnValidThread()); |
209 DCHECK(!label.empty()); | 207 DCHECK(!label.empty()); |
210 DVLOG(1) << "MediaStreamDispatcher::CloseDevice" | 208 DVLOG(1) << "MediaStreamDispatcher::CloseDevice" |
211 << ", {label = " << label << "}"; | 209 << ", {label = " << label << "}"; |
212 | 210 |
213 LabelStreamMap::iterator it = label_stream_map_.find(label); | 211 LabelStreamMap::iterator it = label_stream_map_.find(label); |
214 if (it == label_stream_map_.end()) | 212 if (it == label_stream_map_.end()) |
215 return; | 213 return; |
216 label_stream_map_.erase(it); | 214 label_stream_map_.erase(it); |
217 | 215 |
218 Send(new MediaStreamHostMsg_CloseDevice(routing_id(), label)); | 216 Send(new MediaStreamHostMsg_CloseDevice(routing_id(), label)); |
219 } | 217 } |
220 | 218 |
| 219 void MediaStreamDispatcher::OnDestruct() { |
| 220 // Do not self-destruct. MediaStreamImpl owns |this|. |
| 221 } |
| 222 |
221 bool MediaStreamDispatcher::Send(IPC::Message* message) { | 223 bool MediaStreamDispatcher::Send(IPC::Message* message) { |
222 if (!RenderThread::Get()) { | 224 if (!RenderThread::Get()) { |
223 delete message; | 225 delete message; |
224 return false; | 226 return false; |
225 } | 227 } |
226 | 228 |
227 return RenderThread::Get()->Send(message); | 229 return RenderThread::Get()->Send(message); |
228 } | 230 } |
229 | 231 |
230 bool MediaStreamDispatcher::OnMessageReceived(const IPC::Message& message) { | 232 bool MediaStreamDispatcher::OnMessageReceived(const IPC::Message& message) { |
(...skipping 14 matching lines...) Expand all Loading... |
245 IPC_MESSAGE_UNHANDLED(handled = false) | 247 IPC_MESSAGE_UNHANDLED(handled = false) |
246 IPC_END_MESSAGE_MAP() | 248 IPC_END_MESSAGE_MAP() |
247 return handled; | 249 return handled; |
248 } | 250 } |
249 | 251 |
250 void MediaStreamDispatcher::OnStreamGenerated( | 252 void MediaStreamDispatcher::OnStreamGenerated( |
251 int request_id, | 253 int request_id, |
252 const std::string& label, | 254 const std::string& label, |
253 const StreamDeviceInfoArray& audio_array, | 255 const StreamDeviceInfoArray& audio_array, |
254 const StreamDeviceInfoArray& video_array) { | 256 const StreamDeviceInfoArray& video_array) { |
255 DCHECK(main_loop_->BelongsToCurrentThread()); | 257 DCHECK(thread_checker_.CalledOnValidThread()); |
256 | 258 |
257 for (RequestList::iterator it = requests_.begin(); | 259 for (RequestList::iterator it = requests_.begin(); |
258 it != requests_.end(); ++it) { | 260 it != requests_.end(); ++it) { |
259 Request& request = *it; | 261 Request& request = *it; |
260 if (request.ipc_request == request_id) { | 262 if (request.ipc_request == request_id) { |
261 Stream new_stream; | 263 Stream new_stream; |
262 new_stream.handler = request.handler; | 264 new_stream.handler = request.handler; |
263 new_stream.audio_array = audio_array; | 265 new_stream.audio_array = audio_array; |
264 new_stream.video_array = video_array; | 266 new_stream.video_array = video_array; |
265 label_stream_map_[label] = new_stream; | 267 label_stream_map_[label] = new_stream; |
266 if (request.handler.get()) { | 268 if (request.handler.get()) { |
267 request.handler->OnStreamGenerated( | 269 request.handler->OnStreamGenerated( |
268 request.request_id, label, audio_array, video_array); | 270 request.request_id, label, audio_array, video_array); |
269 DVLOG(1) << "MediaStreamDispatcher::OnStreamGenerated(" | 271 DVLOG(1) << "MediaStreamDispatcher::OnStreamGenerated(" |
270 << request.request_id << ", " << label << ")"; | 272 << request.request_id << ", " << label << ")"; |
271 } | 273 } |
272 requests_.erase(it); | 274 requests_.erase(it); |
273 break; | 275 break; |
274 } | 276 } |
275 } | 277 } |
276 } | 278 } |
277 | 279 |
278 void MediaStreamDispatcher::OnStreamGenerationFailed( | 280 void MediaStreamDispatcher::OnStreamGenerationFailed( |
279 int request_id, | 281 int request_id, |
280 content::MediaStreamRequestResult result) { | 282 content::MediaStreamRequestResult result) { |
281 DCHECK(main_loop_->BelongsToCurrentThread()); | 283 DCHECK(thread_checker_.CalledOnValidThread()); |
282 for (RequestList::iterator it = requests_.begin(); | 284 for (RequestList::iterator it = requests_.begin(); |
283 it != requests_.end(); ++it) { | 285 it != requests_.end(); ++it) { |
284 Request& request = *it; | 286 Request& request = *it; |
285 if (request.ipc_request == request_id) { | 287 if (request.ipc_request == request_id) { |
286 if (request.handler.get()) { | 288 if (request.handler.get()) { |
287 request.handler->OnStreamGenerationFailed(request.request_id, result); | 289 request.handler->OnStreamGenerationFailed(request.request_id, result); |
288 DVLOG(1) << "MediaStreamDispatcher::OnStreamGenerationFailed(" | 290 DVLOG(1) << "MediaStreamDispatcher::OnStreamGenerationFailed(" |
289 << request.request_id << ")\n"; | 291 << request.request_id << ")\n"; |
290 } | 292 } |
291 requests_.erase(it); | 293 requests_.erase(it); |
292 break; | 294 break; |
293 } | 295 } |
294 } | 296 } |
295 } | 297 } |
296 | 298 |
297 void MediaStreamDispatcher::OnDeviceStopped( | 299 void MediaStreamDispatcher::OnDeviceStopped( |
298 const std::string& label, | 300 const std::string& label, |
299 const StreamDeviceInfo& device_info) { | 301 const StreamDeviceInfo& device_info) { |
300 DCHECK(main_loop_->BelongsToCurrentThread()); | 302 DCHECK(thread_checker_.CalledOnValidThread()); |
301 DVLOG(1) << "MediaStreamDispatcher::OnDeviceStopped(" | 303 DVLOG(1) << "MediaStreamDispatcher::OnDeviceStopped(" |
302 << "{label = " << label << "})" | 304 << "{label = " << label << "})" |
303 << ", {device_id = " << device_info.device.id << "})"; | 305 << ", {device_id = " << device_info.device.id << "})"; |
304 | 306 |
305 LabelStreamMap::iterator it = label_stream_map_.find(label); | 307 LabelStreamMap::iterator it = label_stream_map_.find(label); |
306 if (it == label_stream_map_.end()) { | 308 if (it == label_stream_map_.end()) { |
307 // This can happen if a user happen stop a the device from JS at the same | 309 // This can happen if a user happen stop a the device from JS at the same |
308 // time as the underlying media device is unplugged from the system. | 310 // time as the underlying media device is unplugged from the system. |
309 return; | 311 return; |
310 } | 312 } |
311 Stream* stream = &it->second; | 313 Stream* stream = &it->second; |
312 if (IsAudioInputMediaType(device_info.device.type)) | 314 if (IsAudioInputMediaType(device_info.device.type)) |
313 RemoveStreamDeviceFromArray(device_info, &stream->audio_array); | 315 RemoveStreamDeviceFromArray(device_info, &stream->audio_array); |
314 else | 316 else |
315 RemoveStreamDeviceFromArray(device_info, &stream->video_array); | 317 RemoveStreamDeviceFromArray(device_info, &stream->video_array); |
316 | 318 |
317 if (stream->handler.get()) | 319 if (stream->handler.get()) |
318 stream->handler->OnDeviceStopped(label, device_info); | 320 stream->handler->OnDeviceStopped(label, device_info); |
319 | 321 |
320 if (stream->audio_array.empty() && stream->video_array.empty()) | 322 if (stream->audio_array.empty() && stream->video_array.empty()) |
321 label_stream_map_.erase(it); | 323 label_stream_map_.erase(it); |
322 } | 324 } |
323 | 325 |
324 void MediaStreamDispatcher::OnDevicesEnumerated( | 326 void MediaStreamDispatcher::OnDevicesEnumerated( |
325 int request_id, | 327 int request_id, |
326 const StreamDeviceInfoArray& device_array) { | 328 const StreamDeviceInfoArray& device_array) { |
327 DCHECK(main_loop_->BelongsToCurrentThread()); | 329 DCHECK(thread_checker_.CalledOnValidThread()); |
328 DCHECK_GE(request_id, 0); | 330 DCHECK_GE(request_id, 0); |
329 | 331 |
330 for (RequestList::iterator it = requests_.begin(); it != requests_.end(); | 332 for (RequestList::iterator it = requests_.begin(); it != requests_.end(); |
331 ++it) { | 333 ++it) { |
332 if (it->ipc_request == request_id && it->handler.get()) { | 334 if (it->ipc_request == request_id && it->handler.get()) { |
333 it->handler->OnDevicesEnumerated(it->request_id, device_array); | 335 it->handler->OnDevicesEnumerated(it->request_id, device_array); |
334 break; | 336 break; |
335 } | 337 } |
336 } | 338 } |
337 } | 339 } |
338 | 340 |
339 void MediaStreamDispatcher::OnDeviceOpened( | 341 void MediaStreamDispatcher::OnDeviceOpened( |
340 int request_id, | 342 int request_id, |
341 const std::string& label, | 343 const std::string& label, |
342 const StreamDeviceInfo& device_info) { | 344 const StreamDeviceInfo& device_info) { |
343 DCHECK(main_loop_->BelongsToCurrentThread()); | 345 DCHECK(thread_checker_.CalledOnValidThread()); |
344 for (RequestList::iterator it = requests_.begin(); | 346 for (RequestList::iterator it = requests_.begin(); |
345 it != requests_.end(); ++it) { | 347 it != requests_.end(); ++it) { |
346 Request& request = *it; | 348 Request& request = *it; |
347 if (request.ipc_request == request_id) { | 349 if (request.ipc_request == request_id) { |
348 Stream new_stream; | 350 Stream new_stream; |
349 new_stream.handler = request.handler; | 351 new_stream.handler = request.handler; |
350 if (IsAudioInputMediaType(device_info.device.type)) { | 352 if (IsAudioInputMediaType(device_info.device.type)) { |
351 new_stream.audio_array.push_back(device_info); | 353 new_stream.audio_array.push_back(device_info); |
352 } else if (IsVideoMediaType(device_info.device.type)) { | 354 } else if (IsVideoMediaType(device_info.device.type)) { |
353 new_stream.video_array.push_back(device_info); | 355 new_stream.video_array.push_back(device_info); |
354 } else { | 356 } else { |
355 NOTREACHED(); | 357 NOTREACHED(); |
356 } | 358 } |
357 label_stream_map_[label] = new_stream; | 359 label_stream_map_[label] = new_stream; |
358 if (request.handler.get()) { | 360 if (request.handler.get()) { |
359 request.handler->OnDeviceOpened(request.request_id, label, device_info); | 361 request.handler->OnDeviceOpened(request.request_id, label, device_info); |
360 DVLOG(1) << "MediaStreamDispatcher::OnDeviceOpened(" | 362 DVLOG(1) << "MediaStreamDispatcher::OnDeviceOpened(" |
361 << request.request_id << ", " << label << ")"; | 363 << request.request_id << ", " << label << ")"; |
362 } | 364 } |
363 requests_.erase(it); | 365 requests_.erase(it); |
364 break; | 366 break; |
365 } | 367 } |
366 } | 368 } |
367 } | 369 } |
368 | 370 |
369 void MediaStreamDispatcher::OnDeviceOpenFailed(int request_id) { | 371 void MediaStreamDispatcher::OnDeviceOpenFailed(int request_id) { |
370 DCHECK(main_loop_->BelongsToCurrentThread()); | 372 DCHECK(thread_checker_.CalledOnValidThread()); |
371 for (RequestList::iterator it = requests_.begin(); | 373 for (RequestList::iterator it = requests_.begin(); |
372 it != requests_.end(); ++it) { | 374 it != requests_.end(); ++it) { |
373 Request& request = *it; | 375 Request& request = *it; |
374 if (request.ipc_request == request_id) { | 376 if (request.ipc_request == request_id) { |
375 if (request.handler.get()) { | 377 if (request.handler.get()) { |
376 request.handler->OnDeviceOpenFailed(request.request_id); | 378 request.handler->OnDeviceOpenFailed(request.request_id); |
377 DVLOG(1) << "MediaStreamDispatcher::OnDeviceOpenFailed(" | 379 DVLOG(1) << "MediaStreamDispatcher::OnDeviceOpenFailed(" |
378 << request.request_id << ")\n"; | 380 << request.request_id << ")\n"; |
379 } | 381 } |
380 requests_.erase(it); | 382 requests_.erase(it); |
381 break; | 383 break; |
382 } | 384 } |
383 } | 385 } |
384 } | 386 } |
385 | 387 |
386 int MediaStreamDispatcher::audio_session_id(const std::string& label, | 388 int MediaStreamDispatcher::audio_session_id(const std::string& label, |
387 int index) { | 389 int index) { |
388 DCHECK(main_loop_->BelongsToCurrentThread()); | 390 DCHECK(thread_checker_.CalledOnValidThread()); |
389 LabelStreamMap::iterator it = label_stream_map_.find(label); | 391 LabelStreamMap::iterator it = label_stream_map_.find(label); |
390 if (it == label_stream_map_.end() || | 392 if (it == label_stream_map_.end() || |
391 it->second.audio_array.size() <= static_cast<size_t>(index)) { | 393 it->second.audio_array.size() <= static_cast<size_t>(index)) { |
392 return StreamDeviceInfo::kNoId; | 394 return StreamDeviceInfo::kNoId; |
393 } | 395 } |
394 return it->second.audio_array[index].session_id; | 396 return it->second.audio_array[index].session_id; |
395 } | 397 } |
396 | 398 |
397 bool MediaStreamDispatcher::IsStream(const std::string& label) { | 399 bool MediaStreamDispatcher::IsStream(const std::string& label) { |
398 DCHECK(main_loop_->BelongsToCurrentThread()); | 400 DCHECK(thread_checker_.CalledOnValidThread()); |
399 return label_stream_map_.find(label) != label_stream_map_.end(); | 401 return label_stream_map_.find(label) != label_stream_map_.end(); |
400 } | 402 } |
401 | 403 |
402 int MediaStreamDispatcher::video_session_id(const std::string& label, | 404 int MediaStreamDispatcher::video_session_id(const std::string& label, |
403 int index) { | 405 int index) { |
404 DCHECK(main_loop_->BelongsToCurrentThread()); | 406 DCHECK(thread_checker_.CalledOnValidThread()); |
405 LabelStreamMap::iterator it = label_stream_map_.find(label); | 407 LabelStreamMap::iterator it = label_stream_map_.find(label); |
406 if (it == label_stream_map_.end() || | 408 if (it == label_stream_map_.end() || |
407 it->second.video_array.size() <= static_cast<size_t>(index)) { | 409 it->second.video_array.size() <= static_cast<size_t>(index)) { |
408 return StreamDeviceInfo::kNoId; | 410 return StreamDeviceInfo::kNoId; |
409 } | 411 } |
410 return it->second.video_array[index].session_id; | 412 return it->second.video_array[index].session_id; |
411 } | 413 } |
412 | 414 |
413 bool MediaStreamDispatcher::IsAudioDuckingActive() const { | 415 bool MediaStreamDispatcher::IsAudioDuckingActive() const { |
414 DCHECK(main_loop_->BelongsToCurrentThread()); | 416 DCHECK(thread_checker_.CalledOnValidThread()); |
415 LabelStreamMap::const_iterator stream_it = label_stream_map_.begin(); | 417 LabelStreamMap::const_iterator stream_it = label_stream_map_.begin(); |
416 while (stream_it != label_stream_map_.end()) { | 418 while (stream_it != label_stream_map_.end()) { |
417 const StreamDeviceInfoArray& audio_array = stream_it->second.audio_array; | 419 const StreamDeviceInfoArray& audio_array = stream_it->second.audio_array; |
418 for (StreamDeviceInfoArray::const_iterator device_it = audio_array.begin(); | 420 for (StreamDeviceInfoArray::const_iterator device_it = audio_array.begin(); |
419 device_it != audio_array.end(); ++device_it) { | 421 device_it != audio_array.end(); ++device_it) { |
420 if (device_it->device.input.effects & media::AudioParameters::DUCKING) | 422 if (device_it->device.input.effects & media::AudioParameters::DUCKING) |
421 return true; | 423 return true; |
422 } | 424 } |
423 ++stream_it; | 425 ++stream_it; |
424 } | 426 } |
425 return false; | 427 return false; |
426 } | 428 } |
427 | 429 |
428 } // namespace content | 430 } // namespace content |
OLD | NEW |