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