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" | 8 #include "base/message_loop/message_loop_proxy.h" |
9 #include "content/common/media/media_stream_messages.h" | 9 #include "content/common/media/media_stream_messages.h" |
10 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" | 10 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 device_info.device.id)); | 130 device_info.device.id)); |
131 } | 131 } |
132 | 132 |
133 void MediaStreamDispatcher::EnumerateDevices( | 133 void MediaStreamDispatcher::EnumerateDevices( |
134 int request_id, | 134 int request_id, |
135 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | 135 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, |
136 MediaStreamType type, | 136 MediaStreamType type, |
137 const GURL& security_origin) { | 137 const GURL& security_origin) { |
138 DCHECK(main_loop_->BelongsToCurrentThread()); | 138 DCHECK(main_loop_->BelongsToCurrentThread()); |
139 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || | 139 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || |
140 type == MEDIA_DEVICE_VIDEO_CAPTURE); | 140 type == MEDIA_DEVICE_VIDEO_CAPTURE || |
| 141 type == MEDIA_DEVICE_AUDIO_OUTPUT); |
141 DVLOG(1) << "MediaStreamDispatcher::EnumerateDevices(" | 142 DVLOG(1) << "MediaStreamDispatcher::EnumerateDevices(" |
142 << request_id << ")"; | 143 << request_id << ")"; |
143 | 144 |
144 for (RequestList::iterator it = requests_.begin(); it != requests_.end(); | 145 for (RequestList::iterator it = requests_.begin(); it != requests_.end(); |
145 ++it) { | 146 ++it) { |
146 DCHECK(!it->IsThisRequest(request_id, event_handler)); | 147 DCHECK(!it->IsThisRequest(request_id, event_handler)); |
147 } | 148 } |
148 | 149 |
149 requests_.push_back(Request(event_handler, request_id, next_ipc_id_)); | 150 requests_.push_back(Request(event_handler, request_id, next_ipc_id_)); |
150 Send(new MediaStreamHostMsg_EnumerateDevices(routing_id(), | 151 Send(new MediaStreamHostMsg_EnumerateDevices(routing_id(), |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 << "{label = " << label << "})" | 292 << "{label = " << label << "})" |
292 << ", {device_id = " << device_info.device.id << "})"; | 293 << ", {device_id = " << device_info.device.id << "})"; |
293 | 294 |
294 LabelStreamMap::iterator it = label_stream_map_.find(label); | 295 LabelStreamMap::iterator it = label_stream_map_.find(label); |
295 if (it == label_stream_map_.end()) { | 296 if (it == label_stream_map_.end()) { |
296 // This can happen if a user happen stop a the device from JS at the same | 297 // This can happen if a user happen stop a the device from JS at the same |
297 // time as the underlying media device is unplugged from the system. | 298 // time as the underlying media device is unplugged from the system. |
298 return; | 299 return; |
299 } | 300 } |
300 Stream* stream = &it->second; | 301 Stream* stream = &it->second; |
301 if (IsAudioMediaType(device_info.device.type)) | 302 if (IsAudioInputMediaType(device_info.device.type)) |
302 RemoveStreamDeviceFromArray(device_info, &stream->audio_array); | 303 RemoveStreamDeviceFromArray(device_info, &stream->audio_array); |
303 else | 304 else |
304 RemoveStreamDeviceFromArray(device_info, &stream->video_array); | 305 RemoveStreamDeviceFromArray(device_info, &stream->video_array); |
305 | 306 |
306 if (stream->handler.get()) | 307 if (stream->handler.get()) |
307 stream->handler->OnDeviceStopped(label, device_info); | 308 stream->handler->OnDeviceStopped(label, device_info); |
308 | 309 |
309 if (stream->audio_array.empty() && stream->video_array.empty()) | 310 if (stream->audio_array.empty() && stream->video_array.empty()) |
310 label_stream_map_.erase(it); | 311 label_stream_map_.erase(it); |
311 } | 312 } |
(...skipping 17 matching lines...) Expand all Loading... |
329 int request_id, | 330 int request_id, |
330 const std::string& label, | 331 const std::string& label, |
331 const StreamDeviceInfo& device_info) { | 332 const StreamDeviceInfo& device_info) { |
332 DCHECK(main_loop_->BelongsToCurrentThread()); | 333 DCHECK(main_loop_->BelongsToCurrentThread()); |
333 for (RequestList::iterator it = requests_.begin(); | 334 for (RequestList::iterator it = requests_.begin(); |
334 it != requests_.end(); ++it) { | 335 it != requests_.end(); ++it) { |
335 Request& request = *it; | 336 Request& request = *it; |
336 if (request.ipc_request == request_id) { | 337 if (request.ipc_request == request_id) { |
337 Stream new_stream; | 338 Stream new_stream; |
338 new_stream.handler = request.handler; | 339 new_stream.handler = request.handler; |
339 if (IsAudioMediaType(device_info.device.type)) { | 340 if (IsAudioInputMediaType(device_info.device.type)) { |
340 new_stream.audio_array.push_back(device_info); | 341 new_stream.audio_array.push_back(device_info); |
341 } else if (IsVideoMediaType(device_info.device.type)) { | 342 } else if (IsVideoMediaType(device_info.device.type)) { |
342 new_stream.video_array.push_back(device_info); | 343 new_stream.video_array.push_back(device_info); |
343 } else { | 344 } else { |
344 NOTREACHED(); | 345 NOTREACHED(); |
345 } | 346 } |
346 label_stream_map_[label] = new_stream; | 347 label_stream_map_[label] = new_stream; |
347 if (request.handler.get()) { | 348 if (request.handler.get()) { |
348 request.handler->OnDeviceOpened(request.request_id, label, device_info); | 349 request.handler->OnDeviceOpened(request.request_id, label, device_info); |
349 DVLOG(1) << "MediaStreamDispatcher::OnDeviceOpened(" | 350 DVLOG(1) << "MediaStreamDispatcher::OnDeviceOpened(" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 int index) { | 391 int index) { |
391 LabelStreamMap::iterator it = label_stream_map_.find(label); | 392 LabelStreamMap::iterator it = label_stream_map_.find(label); |
392 if (it == label_stream_map_.end() || | 393 if (it == label_stream_map_.end() || |
393 it->second.video_array.size() <= static_cast<size_t>(index)) { | 394 it->second.video_array.size() <= static_cast<size_t>(index)) { |
394 return StreamDeviceInfo::kNoId; | 395 return StreamDeviceInfo::kNoId; |
395 } | 396 } |
396 return it->second.video_array[index].session_id; | 397 return it->second.video_array[index].session_id; |
397 } | 398 } |
398 | 399 |
399 } // namespace content | 400 } // namespace content |
OLD | NEW |