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_LT(content::MEDIA_NO_SERVICE, type); |
121 type == content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE); | 139 DCHECK_GT(content::NUM_MEDIA_TYPES, type); |
wjia(left Chromium)
2012/09/07 17:16:30
For now, EnumerateDevices are still restricted to
miu
2012/09/07 23:14:28
Done. Also, reverted EnumerateDevices/StopEnumera
| |
122 DVLOG(1) << "MediaStreamDispatcher::EnumerateDevices(" | 140 DVLOG(1) << "MediaStreamDispatcher::EnumerateDevices(" |
123 << request_id << ")"; | 141 << request_id << ")"; |
124 | 142 |
125 EnumerationState* state = | 143 EnumerationState& state = enumeration_state_[type]; |
126 (type == content::MEDIA_STREAM_DEVICE_TYPE_AUDIO_CAPTURE ? | 144 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 | 145 |
131 if (state->cached_devices.get()) { | 146 if (state.cached_devices.get()) { |
132 event_handler->OnDevicesEnumerated( | 147 event_handler->OnDevicesEnumerated( |
133 request_id, state->cached_devices->devices); | 148 request_id, state.cached_devices->devices); |
134 } else if (state->ipc_id < 0) { | 149 } else if (state.ipc_id < 0) { |
135 Send(new MediaStreamHostMsg_EnumerateDevices(routing_id(), | 150 Send(new MediaStreamHostMsg_EnumerateDevices(routing_id(), |
136 next_ipc_id_, | 151 next_ipc_id_, |
137 type, | 152 type, |
138 security_origin)); | 153 security_origin)); |
139 state->ipc_id = next_ipc_id_++; | 154 state.ipc_id = next_ipc_id_++; |
140 } | 155 } |
141 } | 156 } |
142 | 157 |
143 void MediaStreamDispatcher::StopEnumerateDevices( | 158 void MediaStreamDispatcher::StopEnumerateDevices( |
144 int request_id, | 159 int request_id, |
145 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler) { | 160 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler) { |
146 DCHECK(main_loop_->BelongsToCurrentThread()); | 161 DCHECK(main_loop_->BelongsToCurrentThread()); |
147 DVLOG(1) << "MediaStreamDispatcher::StopEnumerateDevices(" | 162 DVLOG(1) << "MediaStreamDispatcher::StopEnumerateDevices(" |
148 << request_id << ")"; | 163 << request_id << ")"; |
149 | 164 |
150 // Remove the request. | 165 // Remove the request. |
151 RemoveEnumerationRequest( | 166 for (int i = content::MEDIA_NO_SERVICE + 1; i < content::NUM_MEDIA_TYPES; |
152 request_id, event_handler, &audio_enumeration_state_); | 167 ++i) { |
153 RemoveEnumerationRequest( | 168 RemoveEnumerationRequest(request_id, event_handler, &enumeration_state_[i]); |
154 request_id, event_handler, &video_enumeration_state_); | 169 } |
155 } | 170 } |
156 | 171 |
157 void MediaStreamDispatcher::RemoveEnumerationRequest( | 172 void MediaStreamDispatcher::RemoveEnumerationRequest( |
158 int request_id, | 173 int request_id, |
159 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, | 174 const base::WeakPtr<MediaStreamDispatcherEventHandler>& event_handler, |
160 EnumerationState* state) { | 175 EnumerationState* state) { |
161 EnumerationRequestList* requests = &state->requests; | 176 EnumerationRequestList* requests = &state->requests; |
162 for (EnumerationRequestList::iterator it = requests->begin(); | 177 for (EnumerationRequestList::iterator it = requests->begin(); |
163 it != requests->end(); ++it) { | 178 it != requests->end(); ++it) { |
164 if (it->request_id == request_id && it->handler == event_handler) { | 179 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); | 317 it->second.handler->OnAudioDeviceFailed(label, index); |
303 } | 318 } |
304 | 319 |
305 void MediaStreamDispatcher::OnDevicesEnumerated( | 320 void MediaStreamDispatcher::OnDevicesEnumerated( |
306 int request_id, | 321 int request_id, |
307 const std::string& label, | 322 const std::string& label, |
308 const media_stream::StreamDeviceInfoArray& device_array) { | 323 const media_stream::StreamDeviceInfoArray& device_array) { |
309 DCHECK(main_loop_->BelongsToCurrentThread()); | 324 DCHECK(main_loop_->BelongsToCurrentThread()); |
310 DCHECK_GE(request_id, 0); | 325 DCHECK_GE(request_id, 0); |
311 | 326 |
312 EnumerationState* state; | 327 EnumerationState* state = NULL; |
313 if (request_id == audio_enumeration_state_.ipc_id) { | 328 for (int i = content::MEDIA_NO_SERVICE + 1; i < content::NUM_MEDIA_TYPES; |
314 state = &audio_enumeration_state_; | 329 ++i) { |
315 } else if (request_id == video_enumeration_state_.ipc_id) { | 330 if (request_id == enumeration_state_[i].ipc_id) { |
316 state = &video_enumeration_state_; | 331 state = &enumeration_state_[i]; |
317 } else { | 332 break; |
333 } | |
334 } | |
335 if (state == NULL) { | |
318 // This could happen when requester has stopped enumeration while some | 336 // This could happen when requester has stopped enumeration while some |
319 // enumerated response is on the way. Have to stop the |label| because | 337 // 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 | 338 // this might be the first enumerated device list is received. This also |
321 // lead to same label being stopped multiple times. | 339 // lead to same label being stopped multiple times. |
322 Send(new MediaStreamHostMsg_StopGeneratedStream(routing_id(), label)); | 340 Send(new MediaStreamHostMsg_StopGeneratedStream(routing_id(), label)); |
323 return; | 341 return; |
324 } | 342 } |
325 | 343 |
326 DCHECK(!label.empty()); | 344 DCHECK(!label.empty()); |
327 state->cached_devices.reset(new EnumerationState::CachedDevices( | 345 state->cached_devices.reset(new EnumerationState::CachedDevices( |
(...skipping 30 matching lines...) Expand all Loading... | |
358 int request_id, | 376 int request_id, |
359 const std::string& label, | 377 const std::string& label, |
360 const media_stream::StreamDeviceInfo& device_info) { | 378 const media_stream::StreamDeviceInfo& device_info) { |
361 DCHECK(main_loop_->BelongsToCurrentThread()); | 379 DCHECK(main_loop_->BelongsToCurrentThread()); |
362 for (RequestList::iterator it = requests_.begin(); | 380 for (RequestList::iterator it = requests_.begin(); |
363 it != requests_.end(); ++it) { | 381 it != requests_.end(); ++it) { |
364 Request& request = *it; | 382 Request& request = *it; |
365 if (request.ipc_request == request_id) { | 383 if (request.ipc_request == request_id) { |
366 Stream new_stream; | 384 Stream new_stream; |
367 new_stream.handler = request.handler; | 385 new_stream.handler = request.handler; |
368 if (device_info.stream_type == | 386 if (content::IsAudioMediaType(device_info.stream_type)) { |
369 content::MEDIA_STREAM_DEVICE_TYPE_VIDEO_CAPTURE) { | 387 new_stream.audio_array.push_back(device_info); |
388 } else if (content::IsVideoMediaType(device_info.stream_type)) { | |
370 new_stream.video_array.push_back(device_info); | 389 new_stream.video_array.push_back(device_info); |
371 } else { | 390 } else { |
372 new_stream.audio_array.push_back(device_info); | 391 NOTREACHED(); |
373 } | 392 } |
374 label_stream_map_[label] = new_stream; | 393 label_stream_map_[label] = new_stream; |
375 if (request.handler) { | 394 if (request.handler) { |
376 request.handler->OnDeviceOpened(request.request_id, label, | 395 request.handler->OnDeviceOpened(request.request_id, label, |
377 device_info); | 396 device_info); |
378 DVLOG(1) << "MediaStreamDispatcher::OnDeviceOpened(" | 397 DVLOG(1) << "MediaStreamDispatcher::OnDeviceOpened(" |
379 << request.request_id << ", " << label << ")"; | 398 << request.request_id << ", " << label << ")"; |
380 } | 399 } |
381 requests_.erase(it); | 400 requests_.erase(it); |
382 break; | 401 break; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
417 | 436 |
418 int MediaStreamDispatcher::video_session_id(const std::string& label, | 437 int MediaStreamDispatcher::video_session_id(const std::string& label, |
419 int index) { | 438 int index) { |
420 LabelStreamMap::iterator it = label_stream_map_.find(label); | 439 LabelStreamMap::iterator it = label_stream_map_.find(label); |
421 if (it == label_stream_map_.end()) | 440 if (it == label_stream_map_.end()) |
422 return media_stream::StreamDeviceInfo::kNoId; | 441 return media_stream::StreamDeviceInfo::kNoId; |
423 | 442 |
424 DCHECK_GT(it->second.video_array.size(), static_cast<size_t>(index)); | 443 DCHECK_GT(it->second.video_array.size(), static_cast<size_t>(index)); |
425 return it->second.video_array[index].session_id; | 444 return it->second.video_array[index].session_id; |
426 } | 445 } |
OLD | NEW |