| 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" |
| 11 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
| 12 | 12 |
| 13 namespace content { |
| 14 |
| 13 struct MediaStreamDispatcher::Request { | 15 struct MediaStreamDispatcher::Request { |
| 14 Request(const base::WeakPtr<MediaStreamDispatcherEventHandler>& handler, | 16 Request(const base::WeakPtr<MediaStreamDispatcherEventHandler>& handler, |
| 15 int request_id, | 17 int request_id, |
| 16 int ipc_request) | 18 int ipc_request) |
| 17 : handler(handler), | 19 : handler(handler), |
| 18 request_id(request_id), | 20 request_id(request_id), |
| 19 ipc_request(ipc_request) { | 21 ipc_request(ipc_request) { |
| 20 } | 22 } |
| 21 base::WeakPtr<MediaStreamDispatcherEventHandler> handler; | 23 base::WeakPtr<MediaStreamDispatcherEventHandler> handler; |
| 22 int request_id; | 24 int request_id; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 52 : label(label), | 54 : label(label), |
| 53 devices(device_array) { | 55 devices(device_array) { |
| 54 } | 56 } |
| 55 ~CachedDevices() {} | 57 ~CachedDevices() {} |
| 56 | 58 |
| 57 std::string label; | 59 std::string label; |
| 58 media_stream::StreamDeviceInfoArray devices; | 60 media_stream::StreamDeviceInfoArray devices; |
| 59 }; | 61 }; |
| 60 | 62 |
| 61 MediaStreamDispatcher::MediaStreamDispatcher(RenderViewImpl* render_view) | 63 MediaStreamDispatcher::MediaStreamDispatcher(RenderViewImpl* render_view) |
| 62 : content::RenderViewObserver(render_view), | 64 : RenderViewObserver(render_view), |
| 63 main_loop_(base::MessageLoopProxy::current()), | 65 main_loop_(base::MessageLoopProxy::current()), |
| 64 next_ipc_id_(0) { | 66 next_ipc_id_(0) { |
| 65 } | 67 } |
| 66 | 68 |
| 67 MediaStreamDispatcher::~MediaStreamDispatcher() {} | 69 MediaStreamDispatcher::~MediaStreamDispatcher() {} |
| 68 | 70 |
| 69 void MediaStreamDispatcher::GenerateStream( | 71 void MediaStreamDispatcher::GenerateStream( |
| 70 int request_id, | 72 int request_id, |
| 71 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | 73 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, |
| 72 const media_stream::StreamOptions& components, | 74 const media_stream::StreamOptions& components, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 Send(new MediaStreamHostMsg_StopGeneratedStream(routing_id(), label)); | 112 Send(new MediaStreamHostMsg_StopGeneratedStream(routing_id(), label)); |
| 111 label_stream_map_.erase(it); | 113 label_stream_map_.erase(it); |
| 112 } | 114 } |
| 113 | 115 |
| 114 void MediaStreamDispatcher::EnumerateDevices( | 116 void MediaStreamDispatcher::EnumerateDevices( |
| 115 int request_id, | 117 int request_id, |
| 116 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | 118 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, |
| 117 media_stream::MediaStreamType type, | 119 media_stream::MediaStreamType type, |
| 118 const GURL& security_origin) { | 120 const GURL& security_origin) { |
| 119 DCHECK(main_loop_->BelongsToCurrentThread()); | 121 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 120 DCHECK(type == content::MEDIA_DEVICE_AUDIO_CAPTURE || | 122 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || |
| 121 type == content::MEDIA_DEVICE_VIDEO_CAPTURE); | 123 type == MEDIA_DEVICE_VIDEO_CAPTURE); |
| 122 DVLOG(1) << "MediaStreamDispatcher::EnumerateDevices(" | 124 DVLOG(1) << "MediaStreamDispatcher::EnumerateDevices(" |
| 123 << request_id << ")"; | 125 << request_id << ")"; |
| 124 | 126 |
| 125 EnumerationState* state = | 127 EnumerationState* state = |
| 126 (type == content::MEDIA_DEVICE_AUDIO_CAPTURE ? | 128 (type == MEDIA_DEVICE_AUDIO_CAPTURE ? |
| 127 &audio_enumeration_state_ : &video_enumeration_state_); | 129 &audio_enumeration_state_ : &video_enumeration_state_); |
| 128 state->requests.push_back(EnumerationRequest(event_handler, request_id)); | 130 state->requests.push_back(EnumerationRequest(event_handler, request_id)); |
| 129 | 131 |
| 130 if (state->cached_devices.get()) { | 132 if (state->cached_devices.get()) { |
| 131 event_handler->OnDevicesEnumerated( | 133 event_handler->OnDevicesEnumerated( |
| 132 request_id, state->cached_devices->devices); | 134 request_id, state->cached_devices->devices); |
| 133 } else if (state->ipc_id < 0) { | 135 } else if (state->ipc_id < 0) { |
| 134 Send(new MediaStreamHostMsg_EnumerateDevices(routing_id(), | 136 Send(new MediaStreamHostMsg_EnumerateDevices(routing_id(), |
| 135 next_ipc_id_, | 137 next_ipc_id_, |
| 136 type, | 138 type, |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 int request_id, | 323 int request_id, |
| 322 const std::string& label, | 324 const std::string& label, |
| 323 const media_stream::StreamDeviceInfo& device_info) { | 325 const media_stream::StreamDeviceInfo& device_info) { |
| 324 DCHECK(main_loop_->BelongsToCurrentThread()); | 326 DCHECK(main_loop_->BelongsToCurrentThread()); |
| 325 for (RequestList::iterator it = requests_.begin(); | 327 for (RequestList::iterator it = requests_.begin(); |
| 326 it != requests_.end(); ++it) { | 328 it != requests_.end(); ++it) { |
| 327 Request& request = *it; | 329 Request& request = *it; |
| 328 if (request.ipc_request == request_id) { | 330 if (request.ipc_request == request_id) { |
| 329 Stream new_stream; | 331 Stream new_stream; |
| 330 new_stream.handler = request.handler; | 332 new_stream.handler = request.handler; |
| 331 if (content::IsAudioMediaType(device_info.stream_type)) { | 333 if (IsAudioMediaType(device_info.stream_type)) { |
| 332 new_stream.audio_array.push_back(device_info); | 334 new_stream.audio_array.push_back(device_info); |
| 333 } else if (content::IsVideoMediaType(device_info.stream_type)) { | 335 } else if (IsVideoMediaType(device_info.stream_type)) { |
| 334 new_stream.video_array.push_back(device_info); | 336 new_stream.video_array.push_back(device_info); |
| 335 } else { | 337 } else { |
| 336 NOTREACHED(); | 338 NOTREACHED(); |
| 337 } | 339 } |
| 338 label_stream_map_[label] = new_stream; | 340 label_stream_map_[label] = new_stream; |
| 339 if (request.handler) { | 341 if (request.handler) { |
| 340 request.handler->OnDeviceOpened(request.request_id, label, | 342 request.handler->OnDeviceOpened(request.request_id, label, |
| 341 device_info); | 343 device_info); |
| 342 DVLOG(1) << "MediaStreamDispatcher::OnDeviceOpened(" | 344 DVLOG(1) << "MediaStreamDispatcher::OnDeviceOpened(" |
| 343 << request.request_id << ", " << label << ")"; | 345 << request.request_id << ", " << label << ")"; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 | 383 |
| 382 int MediaStreamDispatcher::video_session_id(const std::string& label, | 384 int MediaStreamDispatcher::video_session_id(const std::string& label, |
| 383 int index) { | 385 int index) { |
| 384 LabelStreamMap::iterator it = label_stream_map_.find(label); | 386 LabelStreamMap::iterator it = label_stream_map_.find(label); |
| 385 if (it == label_stream_map_.end()) | 387 if (it == label_stream_map_.end()) |
| 386 return media_stream::StreamDeviceInfo::kNoId; | 388 return media_stream::StreamDeviceInfo::kNoId; |
| 387 | 389 |
| 388 DCHECK_GT(it->second.video_array.size(), static_cast<size_t>(index)); | 390 DCHECK_GT(it->second.video_array.size(), static_cast<size_t>(index)); |
| 389 return it->second.video_array[index].session_id; | 391 return it->second.video_array[index].session_id; |
| 390 } | 392 } |
| 393 |
| 394 } // namespace content |
| OLD | NEW |