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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 Send(new MediaStreamHostMsg_StopGeneratedStream(routing_id(), label)); | 110 Send(new MediaStreamHostMsg_StopGeneratedStream(routing_id(), label)); |
111 label_stream_map_.erase(it); | 111 label_stream_map_.erase(it); |
112 } | 112 } |
113 | 113 |
114 void MediaStreamDispatcher::EnumerateDevices( | 114 void MediaStreamDispatcher::EnumerateDevices( |
115 int request_id, | 115 int request_id, |
116 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | 116 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, |
117 media_stream::MediaStreamType type, | 117 media_stream::MediaStreamType type, |
118 const GURL& security_origin) { | 118 const GURL& security_origin) { |
119 DCHECK(main_loop_->BelongsToCurrentThread()); | 119 DCHECK(main_loop_->BelongsToCurrentThread()); |
120 DCHECK(type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE || | 120 DCHECK_LT(content::MEDIA_NO_SERVICE, type); |
121 type == content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE); | 121 DCHECK_GT(content::NUM_MEDIA_TYPES, type); |
122 DVLOG(1) << "MediaStreamDispatcher::EnumerateDevices(" | 122 DVLOG(1) << "MediaStreamDispatcher::EnumerateDevices(" |
123 << request_id << ")"; | 123 << request_id << ")"; |
124 | 124 |
125 EnumerationState* state = | 125 EnumerationState& state = enumeration_state_[type]; |
126 (type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE ? | 126 state.requests.push_back(EnumerationRequest(event_handler, request_id)); |
127 &audio_enumeration_state_ : &video_enumeration_state_); | |
128 state->requests.push_back( | |
129 EnumerationRequest(event_handler, request_id)); | |
130 | 127 |
131 if (state->cached_devices.get()) { | 128 if (state.cached_devices.get()) { |
132 event_handler->OnDevicesEnumerated( | 129 event_handler->OnDevicesEnumerated( |
133 request_id, state->cached_devices->devices); | 130 request_id, state.cached_devices->devices); |
134 } else if (state->ipc_id < 0) { | 131 } else if (state.ipc_id < 0) { |
135 Send(new MediaStreamHostMsg_EnumerateDevices(routing_id(), | 132 Send(new MediaStreamHostMsg_EnumerateDevices(routing_id(), |
136 next_ipc_id_, | 133 next_ipc_id_, |
137 type, | 134 type, |
138 security_origin)); | 135 security_origin)); |
139 state->ipc_id = next_ipc_id_++; | 136 state.ipc_id = next_ipc_id_++; |
140 } | 137 } |
141 } | 138 } |
142 | 139 |
143 void MediaStreamDispatcher::StopEnumerateDevices( | 140 void MediaStreamDispatcher::StopEnumerateDevices( |
144 int request_id, | 141 int request_id, |
145 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler) { | 142 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler) { |
146 DCHECK(main_loop_->BelongsToCurrentThread()); | 143 DCHECK(main_loop_->BelongsToCurrentThread()); |
147 DVLOG(1) << "MediaStreamDispatcher::StopEnumerateDevices(" | 144 DVLOG(1) << "MediaStreamDispatcher::StopEnumerateDevices(" |
148 << request_id << ")"; | 145 << request_id << ")"; |
149 | 146 |
150 // Remove the request. | 147 // Remove the request. |
151 RemoveEnumerationRequest( | 148 for (int i = content::MEDIA_NO_SERVICE + 1; i < content::NUM_MEDIA_TYPES; |
152 request_id, event_handler, &audio_enumeration_state_); | 149 ++i) { |
153 RemoveEnumerationRequest( | 150 RemoveEnumerationRequest(request_id, event_handler, &enumeration_state_[i]); |
154 request_id, event_handler, &video_enumeration_state_); | 151 } |
155 } | 152 } |
156 | 153 |
157 void MediaStreamDispatcher::RemoveEnumerationRequest( | 154 void MediaStreamDispatcher::RemoveEnumerationRequest( |
158 int request_id, | 155 int request_id, |
159 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | 156 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, |
160 EnumerationState* state) { | 157 EnumerationState* state) { |
161 EnumerationRequestList* requests = &state->requests; | 158 EnumerationRequestList* requests = &state->requests; |
162 for (EnumerationRequestList::iterator it = requests->begin(); | 159 for (EnumerationRequestList::iterator it = requests->begin(); |
163 it != requests->end(); ++it) { | 160 it != requests->end(); ++it) { |
164 if (it->request_id == request_id && it->handler == event_handler) { | 161 if (it->request_id == request_id && it->handler == event_handler) { |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 it->second.handler->OnAudioDeviceFailed(label, index); | 299 it->second.handler->OnAudioDeviceFailed(label, index); |
303 } | 300 } |
304 | 301 |
305 void MediaStreamDispatcher::OnDevicesEnumerated( | 302 void MediaStreamDispatcher::OnDevicesEnumerated( |
306 int request_id, | 303 int request_id, |
307 const std::string& label, | 304 const std::string& label, |
308 const media_stream::StreamDeviceInfoArray& device_array) { | 305 const media_stream::StreamDeviceInfoArray& device_array) { |
309 DCHECK(main_loop_->BelongsToCurrentThread()); | 306 DCHECK(main_loop_->BelongsToCurrentThread()); |
310 DCHECK_GE(request_id, 0); | 307 DCHECK_GE(request_id, 0); |
311 | 308 |
312 EnumerationState* state; | 309 EnumerationState* state = NULL; |
313 if (request_id == audio_enumeration_state_.ipc_id) { | 310 for (int i = content::MEDIA_NO_SERVICE + 1; i < content::NUM_MEDIA_TYPES; |
314 state = &audio_enumeration_state_; | 311 ++i) { |
315 } else if (request_id == video_enumeration_state_.ipc_id) { | 312 if (request_id == enumeration_state_[i].ipc_id) { |
316 state = &video_enumeration_state_; | 313 state = &enumeration_state_[i]; |
317 } else { | 314 break; |
| 315 } |
| 316 } |
| 317 if (state == NULL) { |
318 // This could happen when requester has stopped enumeration while some | 318 // This could happen when requester has stopped enumeration while some |
319 // enumerated response is on the way. Have to stop the |label| because | 319 // enumerated response is on the way. Have to stop the |label| because |
320 // this might be the first enumerated device list is received. This also | 320 // this might be the first enumerated device list is received. This also |
321 // lead to same label being stopped multiple times. | 321 // lead to same label being stopped multiple times. |
322 Send(new MediaStreamHostMsg_StopGeneratedStream(routing_id(), label)); | 322 Send(new MediaStreamHostMsg_StopGeneratedStream(routing_id(), label)); |
323 return; | 323 return; |
324 } | 324 } |
325 | 325 |
326 DCHECK(!label.empty()); | 326 DCHECK(!label.empty()); |
327 state->cached_devices.reset(new EnumerationState::CachedDevices( | 327 state->cached_devices.reset(new EnumerationState::CachedDevices( |
(...skipping 30 matching lines...) Expand all Loading... |
358 int request_id, | 358 int request_id, |
359 const std::string& label, | 359 const std::string& label, |
360 const media_stream::StreamDeviceInfo& device_info) { | 360 const media_stream::StreamDeviceInfo& device_info) { |
361 DCHECK(main_loop_->BelongsToCurrentThread()); | 361 DCHECK(main_loop_->BelongsToCurrentThread()); |
362 for (RequestList::iterator it = requests_.begin(); | 362 for (RequestList::iterator it = requests_.begin(); |
363 it != requests_.end(); ++it) { | 363 it != requests_.end(); ++it) { |
364 Request& request = *it; | 364 Request& request = *it; |
365 if (request.ipc_request == request_id) { | 365 if (request.ipc_request == request_id) { |
366 Stream new_stream; | 366 Stream new_stream; |
367 new_stream.handler = request.handler; | 367 new_stream.handler = request.handler; |
368 if (device_info.stream_type == | 368 if (content::IsAudioMediaType(device_info.stream_type)) { |
369 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE) { | 369 new_stream.audio_array.push_back(device_info); |
| 370 } else if (content::IsVideoMediaType(device_info.stream_type)) { |
370 new_stream.video_array.push_back(device_info); | 371 new_stream.video_array.push_back(device_info); |
371 } else { | 372 } else { |
372 new_stream.audio_array.push_back(device_info); | 373 NOTREACHED(); |
373 } | 374 } |
374 label_stream_map_[label] = new_stream; | 375 label_stream_map_[label] = new_stream; |
375 if (request.handler) { | 376 if (request.handler) { |
376 request.handler->OnDeviceOpened(request.request_id, label, | 377 request.handler->OnDeviceOpened(request.request_id, label, |
377 device_info); | 378 device_info); |
378 DVLOG(1) << "MediaStreamDispatcher::OnDeviceOpened(" | 379 DVLOG(1) << "MediaStreamDispatcher::OnDeviceOpened(" |
379 << request.request_id << ", " << label << ")"; | 380 << request.request_id << ", " << label << ")"; |
380 } | 381 } |
381 requests_.erase(it); | 382 requests_.erase(it); |
382 break; | 383 break; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 | 418 |
418 int MediaStreamDispatcher::video_session_id(const std::string& label, | 419 int MediaStreamDispatcher::video_session_id(const std::string& label, |
419 int index) { | 420 int index) { |
420 LabelStreamMap::iterator it = label_stream_map_.find(label); | 421 LabelStreamMap::iterator it = label_stream_map_.find(label); |
421 if (it == label_stream_map_.end()) | 422 if (it == label_stream_map_.end()) |
422 return media_stream::StreamDeviceInfo::kNoId; | 423 return media_stream::StreamDeviceInfo::kNoId; |
423 | 424 |
424 DCHECK_GT(it->second.video_array.size(), static_cast<size_t>(index)); | 425 DCHECK_GT(it->second.video_array.size(), static_cast<size_t>(index)); |
425 return it->second.video_array[index].session_id; | 426 return it->second.video_array[index].session_id; |
426 } | 427 } |
OLD | NEW |