| 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 "content/common/media/media_stream_messages.h" | 8 #include "content/common/media/media_stream_messages.h" |
| 9 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" | 9 #include "content/renderer/media/media_stream_dispatcher_eventhandler.h" |
| 10 #include "content/renderer/render_view_impl.h" | 10 #include "content/renderer/render_view_impl.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 DCHECK(main_loop_->BelongsToCurrentThread()); | 74 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 75 DVLOG(1) << "MediaStreamDispatcher::GenerateStream(" << request_id << ")"; | 75 DVLOG(1) << "MediaStreamDispatcher::GenerateStream(" << request_id << ")"; |
| 76 | 76 |
| 77 requests_.push_back(Request(event_handler, request_id, next_ipc_id_)); | 77 requests_.push_back(Request(event_handler, request_id, next_ipc_id_)); |
| 78 Send(new MediaStreamHostMsg_GenerateStream(routing_id(), | 78 Send(new MediaStreamHostMsg_GenerateStream(routing_id(), |
| 79 next_ipc_id_++, | 79 next_ipc_id_++, |
| 80 components, | 80 components, |
| 81 security_origin)); | 81 security_origin)); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void MediaStreamDispatcher::GenerateStreamForDevice( |
| 85 int request_id, |
| 86 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, |
| 87 media_stream::StreamOptions components, |
| 88 const std::string& device_id, |
| 89 const GURL& security_origin) { |
| 90 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 91 DVLOG(1) << "MediaStreamDispatcher::GenerateStreamForDevice(" |
| 92 << request_id << ")"; |
| 93 |
| 94 requests_.push_back(Request(event_handler, request_id, next_ipc_id_)); |
| 95 Send(new MediaStreamHostMsg_GenerateStreamForDevice(routing_id(), |
| 96 next_ipc_id_++, |
| 97 components, |
| 98 device_id, |
| 99 security_origin)); |
| 100 } |
| 101 |
| 84 void MediaStreamDispatcher::CancelGenerateStream(int request_id) { | 102 void MediaStreamDispatcher::CancelGenerateStream(int request_id) { |
| 85 DCHECK(main_loop_->BelongsToCurrentThread()); | 103 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 86 DVLOG(1) << "MediaStreamDispatcher::CancelGenerateStream" | 104 DVLOG(1) << "MediaStreamDispatcher::CancelGenerateStream" |
| 87 << ", {request_id = " << request_id << "}"; | 105 << ", {request_id = " << request_id << "}"; |
| 88 | 106 |
| 89 RequestList::iterator it = requests_.begin(); | 107 RequestList::iterator it = requests_.begin(); |
| 90 for (; it != requests_.end(); ++it) { | 108 for (; it != requests_.end(); ++it) { |
| 91 Request& request = *it; | 109 Request& request = *it; |
| 92 if (request.request_id == request_id) { | 110 if (request.request_id == request_id) { |
| 93 requests_.erase(it); | 111 requests_.erase(it); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 110 Send(new MediaStreamHostMsg_StopGeneratedStream(routing_id(), label)); | 128 Send(new MediaStreamHostMsg_StopGeneratedStream(routing_id(), label)); |
| 111 label_stream_map_.erase(it); | 129 label_stream_map_.erase(it); |
| 112 } | 130 } |
| 113 | 131 |
| 114 void MediaStreamDispatcher::EnumerateDevices( | 132 void MediaStreamDispatcher::EnumerateDevices( |
| 115 int request_id, | 133 int request_id, |
| 116 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | 134 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, |
| 117 media_stream::MediaStreamType type, | 135 media_stream::MediaStreamType type, |
| 118 const GURL& security_origin) { | 136 const GURL& security_origin) { |
| 119 DCHECK(main_loop_->BelongsToCurrentThread()); | 137 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 120 DCHECK(type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE || | 138 DCHECK(type == content::MEDIA_DEVICE_AUDIO_CAPTURE || |
| 121 type == content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE); | 139 type == content::MEDIA_DEVICE_VIDEO_CAPTURE); |
| 122 DVLOG(1) << "MediaStreamDispatcher::EnumerateDevices(" | 140 DVLOG(1) << "MediaStreamDispatcher::EnumerateDevices(" |
| 123 << request_id << ")"; | 141 << request_id << ")"; |
| 124 | 142 |
| 125 EnumerationState* state = | 143 EnumerationState* state = |
| 126 (type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE ? | 144 (type == content::MEDIA_DEVICE_AUDIO_CAPTURE ? |
| 127 &audio_enumeration_state_ : &video_enumeration_state_); | 145 &audio_enumeration_state_ : &video_enumeration_state_); |
| 128 state->requests.push_back( | 146 state->requests.push_back(EnumerationRequest(event_handler, request_id)); |
| 129 EnumerationRequest(event_handler, request_id)); | |
| 130 | 147 |
| 131 if (state->cached_devices.get()) { | 148 if (state->cached_devices.get()) { |
| 132 event_handler->OnDevicesEnumerated( | 149 event_handler->OnDevicesEnumerated( |
| 133 request_id, state->cached_devices->devices); | 150 request_id, state->cached_devices->devices); |
| 134 } else if (state->ipc_id < 0) { | 151 } else if (state->ipc_id < 0) { |
| 135 Send(new MediaStreamHostMsg_EnumerateDevices(routing_id(), | 152 Send(new MediaStreamHostMsg_EnumerateDevices(routing_id(), |
| 136 next_ipc_id_, | 153 next_ipc_id_, |
| 137 type, | 154 type, |
| 138 security_origin)); | 155 security_origin)); |
| 139 state->ipc_id = next_ipc_id_++; | 156 state->ipc_id = next_ipc_id_++; |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 int request_id, | 375 int request_id, |
| 359 const std::string& label, | 376 const std::string& label, |
| 360 const media_stream::StreamDeviceInfo& device_info) { | 377 const media_stream::StreamDeviceInfo& device_info) { |
| 361 DCHECK(main_loop_->BelongsToCurrentThread()); | 378 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 362 for (RequestList::iterator it = requests_.begin(); | 379 for (RequestList::iterator it = requests_.begin(); |
| 363 it != requests_.end(); ++it) { | 380 it != requests_.end(); ++it) { |
| 364 Request& request = *it; | 381 Request& request = *it; |
| 365 if (request.ipc_request == request_id) { | 382 if (request.ipc_request == request_id) { |
| 366 Stream new_stream; | 383 Stream new_stream; |
| 367 new_stream.handler = request.handler; | 384 new_stream.handler = request.handler; |
| 368 if (device_info.stream_type == | 385 if (content::IsAudioMediaType(device_info.stream_type)) { |
| 369 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE) { | 386 new_stream.audio_array.push_back(device_info); |
| 387 } else if (content::IsVideoMediaType(device_info.stream_type)) { |
| 370 new_stream.video_array.push_back(device_info); | 388 new_stream.video_array.push_back(device_info); |
| 371 } else { | 389 } else { |
| 372 new_stream.audio_array.push_back(device_info); | 390 NOTREACHED(); |
| 373 } | 391 } |
| 374 label_stream_map_[label] = new_stream; | 392 label_stream_map_[label] = new_stream; |
| 375 if (request.handler) { | 393 if (request.handler) { |
| 376 request.handler->OnDeviceOpened(request.request_id, label, | 394 request.handler->OnDeviceOpened(request.request_id, label, |
| 377 device_info); | 395 device_info); |
| 378 DVLOG(1) << "MediaStreamDispatcher::OnDeviceOpened(" | 396 DVLOG(1) << "MediaStreamDispatcher::OnDeviceOpened(" |
| 379 << request.request_id << ", " << label << ")"; | 397 << request.request_id << ", " << label << ")"; |
| 380 } | 398 } |
| 381 requests_.erase(it); | 399 requests_.erase(it); |
| 382 break; | 400 break; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 | 435 |
| 418 int MediaStreamDispatcher::video_session_id(const std::string& label, | 436 int MediaStreamDispatcher::video_session_id(const std::string& label, |
| 419 int index) { | 437 int index) { |
| 420 LabelStreamMap::iterator it = label_stream_map_.find(label); | 438 LabelStreamMap::iterator it = label_stream_map_.find(label); |
| 421 if (it == label_stream_map_.end()) | 439 if (it == label_stream_map_.end()) |
| 422 return media_stream::StreamDeviceInfo::kNoId; | 440 return media_stream::StreamDeviceInfo::kNoId; |
| 423 | 441 |
| 424 DCHECK_GT(it->second.video_array.size(), static_cast<size_t>(index)); | 442 DCHECK_GT(it->second.video_array.size(), static_cast<size_t>(index)); |
| 425 return it->second.video_array[index].session_id; | 443 return it->second.video_array[index].session_id; |
| 426 } | 444 } |
| OLD | NEW |