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/browser/renderer_host/media/media_stream_manager.h" | 5 #include "content/browser/renderer_host/media/media_stream_manager.h" |
6 | 6 |
7 #include <list> | 7 #include <list> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 // Helper to verify if a media stream type is part of options or not. | 57 // Helper to verify if a media stream type is part of options or not. |
58 static bool Requested(const StreamOptions& options, | 58 static bool Requested(const StreamOptions& options, |
59 MediaStreamType stream_type) { | 59 MediaStreamType stream_type) { |
60 return (options.audio_type == stream_type || | 60 return (options.audio_type == stream_type || |
61 options.video_type == stream_type); | 61 options.video_type == stream_type); |
62 } | 62 } |
63 | 63 |
64 // TODO(xians): Merge DeviceRequest with MediaStreamRequest. | 64 // TODO(xians): Merge DeviceRequest with MediaStreamRequest. |
65 class MediaStreamManager::DeviceRequest { | 65 class MediaStreamManager::DeviceRequest { |
66 public: | 66 public: |
67 enum RequestType { | |
68 DEVICE_ACCESS = 0, | |
69 GENERATE_STREAM, | |
70 ENUMERATE_DEVICES, | |
71 OPEN_DEVICE | |
72 }; | |
73 | |
74 DeviceRequest() | 67 DeviceRequest() |
75 : requester(NULL), | 68 : requester(NULL), |
76 type(GENERATE_STREAM), | 69 type(MEDIA_GENERATE_STREAM), |
77 render_process_id(-1), | 70 render_process_id(-1), |
78 render_view_id(-1), | 71 render_view_id(-1), |
79 state_(NUM_MEDIA_TYPES, MEDIA_REQUEST_STATE_NOT_REQUESTED) { | 72 state_(NUM_MEDIA_TYPES, MEDIA_REQUEST_STATE_NOT_REQUESTED) { |
80 } | 73 } |
81 | 74 |
82 DeviceRequest(MediaStreamRequester* requester, | 75 DeviceRequest(MediaStreamRequester* requester, |
83 const StreamOptions& request_options, | 76 const StreamOptions& request_options, |
84 RequestType request_type, | 77 MediaStreamRequestType request_type, |
85 int render_process_id, | 78 int render_process_id, |
86 int render_view_id, | 79 int render_view_id, |
87 const GURL& request_security_origin) | 80 const GURL& request_security_origin) |
88 : requester(requester), | 81 : requester(requester), |
89 options(request_options), | 82 options(request_options), |
90 type(request_type), | 83 type(request_type), |
91 render_process_id(render_process_id), | 84 render_process_id(render_process_id), |
92 render_view_id(render_view_id), | 85 render_view_id(render_view_id), |
93 security_origin(request_security_origin), | 86 security_origin(request_security_origin), |
94 state_(NUM_MEDIA_TYPES, MEDIA_REQUEST_STATE_NOT_REQUESTED) { | 87 state_(NUM_MEDIA_TYPES, MEDIA_REQUEST_STATE_NOT_REQUESTED) { |
(...skipping 27 matching lines...) Expand all Loading... |
122 MediaStreamDevice( | 115 MediaStreamDevice( |
123 stream_type, device_id, device_id), new_state); | 116 stream_type, device_id, device_id), new_state); |
124 } | 117 } |
125 | 118 |
126 MediaRequestState state(MediaStreamType stream_type) const { | 119 MediaRequestState state(MediaStreamType stream_type) const { |
127 return state_[stream_type]; | 120 return state_[stream_type]; |
128 } | 121 } |
129 | 122 |
130 MediaStreamRequester* requester; // Can be NULL. | 123 MediaStreamRequester* requester; // Can be NULL. |
131 StreamOptions options; | 124 StreamOptions options; |
132 RequestType type; | 125 MediaStreamRequestType type; |
133 int render_process_id; | 126 int render_process_id; |
134 int render_view_id; | 127 int render_view_id; |
135 GURL security_origin; | 128 GURL security_origin; |
136 std::string requested_device_id; | 129 std::string requested_device_id; |
137 StreamDeviceInfoArray devices; | 130 StreamDeviceInfoArray devices; |
138 | 131 |
139 // Callback to the requester which audio/video devices have been selected. | 132 // Callback to the requester which audio/video devices have been selected. |
140 // It can be null if the requester has no interest to know the result. | 133 // It can be null if the requester has no interest to know the result. |
141 // Currently it is only used by |DEVICE_ACCESS| type. | 134 // Currently it is only used by |DEVICE_ACCESS| type. |
142 MediaRequestResponseCallback callback; | 135 MediaRequestResponseCallback callback; |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 std::string MediaStreamManager::MakeMediaAccessRequest( | 188 std::string MediaStreamManager::MakeMediaAccessRequest( |
196 int render_process_id, | 189 int render_process_id, |
197 int render_view_id, | 190 int render_view_id, |
198 const StreamOptions& options, | 191 const StreamOptions& options, |
199 const GURL& security_origin, | 192 const GURL& security_origin, |
200 const MediaRequestResponseCallback& callback) { | 193 const MediaRequestResponseCallback& callback) { |
201 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 194 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
202 // Create a new request based on options. | 195 // Create a new request based on options. |
203 DeviceRequest* request = new DeviceRequest(NULL, | 196 DeviceRequest* request = new DeviceRequest(NULL, |
204 options, | 197 options, |
205 DeviceRequest::DEVICE_ACCESS, | 198 MEDIA_DEVICE_ACCESS, |
206 render_process_id, | 199 render_process_id, |
207 render_view_id, | 200 render_view_id, |
208 security_origin); | 201 security_origin); |
209 const std::string& label = AddRequest(request); | 202 const std::string& label = AddRequest(request); |
210 | 203 |
211 request->callback = callback; | 204 request->callback = callback; |
212 | 205 |
213 HandleRequest(label); | 206 HandleRequest(label); |
214 | 207 |
215 return label; | 208 return label; |
216 } | 209 } |
217 | 210 |
218 std::string MediaStreamManager::GenerateStream( | 211 std::string MediaStreamManager::GenerateStream( |
219 MediaStreamRequester* requester, | 212 MediaStreamRequester* requester, |
220 int render_process_id, | 213 int render_process_id, |
221 int render_view_id, | 214 int render_view_id, |
222 const StreamOptions& options, | 215 const StreamOptions& options, |
223 const GURL& security_origin) { | 216 const GURL& security_origin) { |
224 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 217 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
225 if (CommandLine::ForCurrentProcess()->HasSwitch( | 218 if (CommandLine::ForCurrentProcess()->HasSwitch( |
226 switches::kUseFakeDeviceForMediaStream)) { | 219 switches::kUseFakeDeviceForMediaStream)) { |
227 UseFakeDevice(); | 220 UseFakeDevice(); |
228 } | 221 } |
229 | 222 |
230 // Create a new request based on options. | 223 // Create a new request based on options. |
231 DeviceRequest* request = new DeviceRequest(requester, options, | 224 DeviceRequest* request = new DeviceRequest(requester, options, |
232 DeviceRequest::GENERATE_STREAM, | 225 MEDIA_GENERATE_STREAM, |
233 render_process_id, | 226 render_process_id, |
234 render_view_id, | 227 render_view_id, |
235 security_origin); | 228 security_origin); |
236 const std::string& label = AddRequest(request); | 229 const std::string& label = AddRequest(request); |
237 | 230 |
238 HandleRequest(label); | 231 HandleRequest(label); |
239 | 232 |
240 return label; | 233 return label; |
241 } | 234 } |
242 | 235 |
(...skipping 16 matching lines...) Expand all Loading... |
259 (options.audio_type != MEDIA_TAB_AUDIO_CAPTURE && | 252 (options.audio_type != MEDIA_TAB_AUDIO_CAPTURE && |
260 options.audio_type != MEDIA_NO_SERVICE) || | 253 options.audio_type != MEDIA_NO_SERVICE) || |
261 (options.video_type != MEDIA_TAB_VIDEO_CAPTURE && | 254 (options.video_type != MEDIA_TAB_VIDEO_CAPTURE && |
262 options.video_type != MEDIA_NO_SERVICE)) { | 255 options.video_type != MEDIA_NO_SERVICE)) { |
263 LOG(ERROR) << "Invalid request or used tab capture outside extension API."; | 256 LOG(ERROR) << "Invalid request or used tab capture outside extension API."; |
264 return std::string(); | 257 return std::string(); |
265 } | 258 } |
266 | 259 |
267 // Create a new request based on options. | 260 // Create a new request based on options. |
268 DeviceRequest* request = new DeviceRequest(requester, options, | 261 DeviceRequest* request = new DeviceRequest(requester, options, |
269 DeviceRequest::GENERATE_STREAM, | 262 MEDIA_GENERATE_STREAM, |
270 target_render_process_id, | 263 target_render_process_id, |
271 target_render_view_id, | 264 target_render_view_id, |
272 security_origin); | 265 security_origin); |
273 const std::string& label = AddRequest(request); | 266 const std::string& label = AddRequest(request); |
274 request->requested_device_id = device_id; | 267 request->requested_device_id = device_id; |
275 | 268 |
276 // Pass the request to UI to get user confirmation to use the capture device. | 269 // Pass the request to UI to get user confirmation to use the capture device. |
277 // Note, GenerateStreamForDevice does not need device enumeration. | 270 // Note, GenerateStreamForDevice does not need device enumeration. |
278 PostRequestToUI(label); | 271 PostRequestToUI(label); |
279 | 272 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 StopGeneratedStream(label); | 320 StopGeneratedStream(label); |
328 } | 321 } |
329 } | 322 } |
330 } | 323 } |
331 | 324 |
332 void MediaStreamManager::StopGeneratedStream(const std::string& label) { | 325 void MediaStreamManager::StopGeneratedStream(const std::string& label) { |
333 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 326 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
334 // Find the request and close all open devices for the request. | 327 // Find the request and close all open devices for the request. |
335 DeviceRequests::iterator it = requests_.find(label); | 328 DeviceRequests::iterator it = requests_.find(label); |
336 if (it != requests_.end()) { | 329 if (it != requests_.end()) { |
337 if (it->second->type == DeviceRequest::ENUMERATE_DEVICES) { | 330 if (it->second->type == MEDIA_ENUMERATE_DEVICES) { |
338 StopEnumerateDevices(label); | 331 StopEnumerateDevices(label); |
339 return; | 332 return; |
340 } | 333 } |
341 | 334 |
342 scoped_ptr<DeviceRequest> request(it->second); | 335 scoped_ptr<DeviceRequest> request(it->second); |
343 requests_.erase(it); | 336 requests_.erase(it); |
344 for (StreamDeviceInfoArray::const_iterator device_it = | 337 for (StreamDeviceInfoArray::const_iterator device_it = |
345 request->devices.begin(); | 338 request->devices.begin(); |
346 device_it != request->devices.end(); ++device_it) { | 339 device_it != request->devices.end(); ++device_it) { |
347 GetDeviceManager(device_it->stream_type)->Close(device_it->session_id); | 340 GetDeviceManager(device_it->stream_type)->Close(device_it->session_id); |
348 } | 341 } |
349 if (request->type == DeviceRequest::GENERATE_STREAM && | 342 if (request->type == MEDIA_GENERATE_STREAM && |
350 RequestDone(*request)) { | 343 RequestDone(*request)) { |
351 // Notify observers that this device is being closed. | 344 // Notify observers that this device is being closed. |
352 for (int i = MEDIA_NO_SERVICE + 1; i != NUM_MEDIA_TYPES; ++i) { | 345 for (int i = MEDIA_NO_SERVICE + 1; i != NUM_MEDIA_TYPES; ++i) { |
353 if (request->state(static_cast<MediaStreamType>(i)) != | 346 if (request->state(static_cast<MediaStreamType>(i)) != |
354 MEDIA_REQUEST_STATE_NOT_REQUESTED) { | 347 MEDIA_REQUEST_STATE_NOT_REQUESTED) { |
355 request->SetState(static_cast<MediaStreamType>(i), | 348 request->SetState(static_cast<MediaStreamType>(i), |
356 MEDIA_REQUEST_STATE_CLOSING); | 349 MEDIA_REQUEST_STATE_CLOSING); |
357 } | 350 } |
358 } | 351 } |
359 NotifyDevicesClosed(*request); | 352 NotifyDevicesClosed(*request); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 } else if (type == MEDIA_DEVICE_VIDEO_CAPTURE) { | 386 } else if (type == MEDIA_DEVICE_VIDEO_CAPTURE) { |
394 options.video_type = type; | 387 options.video_type = type; |
395 cache = &video_enumeration_cache_; | 388 cache = &video_enumeration_cache_; |
396 } else { | 389 } else { |
397 NOTREACHED(); | 390 NOTREACHED(); |
398 return std::string(); | 391 return std::string(); |
399 } | 392 } |
400 | 393 |
401 DeviceRequest* request = new DeviceRequest(requester, | 394 DeviceRequest* request = new DeviceRequest(requester, |
402 options, | 395 options, |
403 DeviceRequest::ENUMERATE_DEVICES, | 396 MEDIA_ENUMERATE_DEVICES, |
404 render_process_id, | 397 render_process_id, |
405 render_view_id, | 398 render_view_id, |
406 security_origin); | 399 security_origin); |
407 const std::string& label = AddRequest(request); | 400 const std::string& label = AddRequest(request); |
408 | 401 |
409 if (cache->valid) { | 402 if (cache->valid) { |
410 // Cached device list of this type exists. Just send it out. | 403 // Cached device list of this type exists. Just send it out. |
411 request->SetState(type, MEDIA_REQUEST_STATE_REQUESTED); | 404 request->SetState(type, MEDIA_REQUEST_STATE_REQUESTED); |
412 | 405 |
413 // Need to post a task since the requester won't have label till | 406 // Need to post a task since the requester won't have label till |
414 // this function returns. | 407 // this function returns. |
415 BrowserThread::PostTask( | 408 BrowserThread::PostTask( |
416 BrowserThread::IO, FROM_HERE, | 409 BrowserThread::IO, FROM_HERE, |
417 base::Bind(&MediaStreamManager::SendCachedDeviceList, | 410 base::Bind(&MediaStreamManager::SendCachedDeviceList, |
418 base::Unretained(this), cache, label)); | 411 base::Unretained(this), cache, label)); |
419 } else { | 412 } else { |
420 StartEnumeration(request); | 413 StartEnumeration(request); |
421 } | 414 } |
422 | 415 |
423 return label; | 416 return label; |
424 } | 417 } |
425 | 418 |
426 void MediaStreamManager::StopEnumerateDevices(const std::string& label) { | 419 void MediaStreamManager::StopEnumerateDevices(const std::string& label) { |
427 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 420 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
428 | 421 |
429 DeviceRequests::iterator it = requests_.find(label); | 422 DeviceRequests::iterator it = requests_.find(label); |
430 if (it != requests_.end()) { | 423 if (it != requests_.end()) { |
431 DCHECK_EQ(it->second->type, DeviceRequest::ENUMERATE_DEVICES); | 424 DCHECK_EQ(it->second->type, MEDIA_ENUMERATE_DEVICES); |
432 // Delete the DeviceRequest. | 425 // Delete the DeviceRequest. |
433 scoped_ptr<DeviceRequest> request(it->second); | 426 scoped_ptr<DeviceRequest> request(it->second); |
434 requests_.erase(it); | 427 requests_.erase(it); |
435 } | 428 } |
436 } | 429 } |
437 | 430 |
438 std::string MediaStreamManager::OpenDevice( | 431 std::string MediaStreamManager::OpenDevice( |
439 MediaStreamRequester* requester, | 432 MediaStreamRequester* requester, |
440 int render_process_id, | 433 int render_process_id, |
441 int render_view_id, | 434 int render_view_id, |
(...skipping 10 matching lines...) Expand all Loading... |
452 options.audio_type = type; | 445 options.audio_type = type; |
453 } else if (IsVideoMediaType(type)) { | 446 } else if (IsVideoMediaType(type)) { |
454 options.video_type = type; | 447 options.video_type = type; |
455 } else { | 448 } else { |
456 NOTREACHED(); | 449 NOTREACHED(); |
457 return std::string(); | 450 return std::string(); |
458 } | 451 } |
459 | 452 |
460 DeviceRequest* request = new DeviceRequest(requester, | 453 DeviceRequest* request = new DeviceRequest(requester, |
461 options, | 454 options, |
462 DeviceRequest::OPEN_DEVICE, | 455 MEDIA_OPEN_DEVICE, |
463 render_process_id, | 456 render_process_id, |
464 render_view_id, | 457 render_view_id, |
465 security_origin); | 458 security_origin); |
466 request->requested_device_id = device_id; | 459 request->requested_device_id = device_id; |
467 const std::string& label = AddRequest(request); | 460 const std::string& label = AddRequest(request); |
468 StartEnumeration(request); | 461 StartEnumeration(request); |
469 | 462 |
| 463 PostRequestToUI(label); |
| 464 |
470 return label; | 465 return label; |
471 } | 466 } |
472 | 467 |
473 void MediaStreamManager::NotifyUIDevicesOpened( | 468 void MediaStreamManager::NotifyUIDevicesOpened( |
474 int render_process_id, | 469 int render_process_id, |
475 int render_view_id, | 470 int render_view_id, |
476 const MediaStreamDevices& devices) { | 471 const MediaStreamDevices& devices) { |
477 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 472 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
478 ui_controller_->NotifyUIIndicatorDevicesOpened(render_process_id, | 473 ui_controller_->NotifyUIIndicatorDevicesOpened(render_process_id, |
479 render_view_id, | 474 render_view_id, |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 } | 575 } |
581 | 576 |
582 void MediaStreamManager::PostRequestToUI(const std::string& label) { | 577 void MediaStreamManager::PostRequestToUI(const std::string& label) { |
583 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 578 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
584 DeviceRequest* request = requests_[label]; | 579 DeviceRequest* request = requests_[label]; |
585 // Get user confirmation to use capture devices. | 580 // Get user confirmation to use capture devices. |
586 ui_controller_->MakeUIRequest(label, | 581 ui_controller_->MakeUIRequest(label, |
587 request->render_process_id, | 582 request->render_process_id, |
588 request->render_view_id, | 583 request->render_view_id, |
589 request->options, | 584 request->options, |
590 request->security_origin); | 585 request->security_origin, |
| 586 request->type); |
591 } | 587 } |
592 | 588 |
593 void MediaStreamManager::HandleRequest(const std::string& label) { | 589 void MediaStreamManager::HandleRequest(const std::string& label) { |
594 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 590 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
595 DeviceRequest* request = requests_[label]; | 591 DeviceRequest* request = requests_[label]; |
596 if ((IsAudioMediaType(request->options.audio_type) && | 592 if ((IsAudioMediaType(request->options.audio_type) && |
597 !audio_enumeration_cache_.valid) || | 593 !audio_enumeration_cache_.valid) || |
598 (IsVideoMediaType(request->options.video_type) && | 594 (IsVideoMediaType(request->options.video_type) && |
599 !video_enumeration_cache_.valid)) { | 595 !video_enumeration_cache_.valid)) { |
600 // Enumerate the devices if there is no valid device lists to be used. | 596 // Enumerate the devices if there is no valid device lists to be used. |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 } | 681 } |
686 | 682 |
687 request->SetState(stream_type, MEDIA_REQUEST_STATE_DONE); | 683 request->SetState(stream_type, MEDIA_REQUEST_STATE_DONE); |
688 | 684 |
689 if (!RequestDone(*request)) { | 685 if (!RequestDone(*request)) { |
690 // This stream_type is done, but not the other type. | 686 // This stream_type is done, but not the other type. |
691 return; | 687 return; |
692 } | 688 } |
693 | 689 |
694 switch (request->type) { | 690 switch (request->type) { |
695 case DeviceRequest::OPEN_DEVICE: | 691 case MEDIA_OPEN_DEVICE: |
696 request->requester->DeviceOpened(label, devices->front()); | 692 request->requester->DeviceOpened(label, devices->front()); |
697 break; | 693 break; |
698 case DeviceRequest::GENERATE_STREAM: { | 694 case MEDIA_GENERATE_STREAM: { |
699 // Partition the array of devices into audio vs video. | 695 // Partition the array of devices into audio vs video. |
700 StreamDeviceInfoArray audio_devices, video_devices; | 696 StreamDeviceInfoArray audio_devices, video_devices; |
701 for (StreamDeviceInfoArray::const_iterator device_it = devices->begin(); | 697 for (StreamDeviceInfoArray::const_iterator device_it = devices->begin(); |
702 device_it != devices->end(); ++device_it) { | 698 device_it != devices->end(); ++device_it) { |
703 if (IsAudioMediaType(device_it->stream_type)) { | 699 if (IsAudioMediaType(device_it->stream_type)) { |
704 audio_devices.push_back(*device_it); | 700 audio_devices.push_back(*device_it); |
705 } else if (IsVideoMediaType(device_it->stream_type)) { | 701 } else if (IsVideoMediaType(device_it->stream_type)) { |
706 video_devices.push_back(*device_it); | 702 video_devices.push_back(*device_it); |
707 } else { | 703 } else { |
708 NOTREACHED(); | 704 NOTREACHED(); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
748 // Publish the result for all requests waiting for device list(s). | 744 // Publish the result for all requests waiting for device list(s). |
749 // Find the requests waiting for this device list, store their labels and | 745 // Find the requests waiting for this device list, store their labels and |
750 // release the iterator before calling device settings. We might get a call | 746 // release the iterator before calling device settings. We might get a call |
751 // back from device_settings that will need to iterate through devices. | 747 // back from device_settings that will need to iterate through devices. |
752 std::list<std::string> label_list; | 748 std::list<std::string> label_list; |
753 for (DeviceRequests::iterator it = requests_.begin(); it != requests_.end(); | 749 for (DeviceRequests::iterator it = requests_.begin(); it != requests_.end(); |
754 ++it) { | 750 ++it) { |
755 if (it->second->state(stream_type) == | 751 if (it->second->state(stream_type) == |
756 MEDIA_REQUEST_STATE_REQUESTED && | 752 MEDIA_REQUEST_STATE_REQUESTED && |
757 Requested(it->second->options, stream_type)) { | 753 Requested(it->second->options, stream_type)) { |
758 if (it->second->type != DeviceRequest::ENUMERATE_DEVICES) | 754 if (it->second->type != MEDIA_ENUMERATE_DEVICES) |
759 it->second->SetState(stream_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); | 755 it->second->SetState(stream_type, MEDIA_REQUEST_STATE_PENDING_APPROVAL); |
760 label_list.push_back(it->first); | 756 label_list.push_back(it->first); |
761 } | 757 } |
762 } | 758 } |
763 for (std::list<std::string>::iterator it = label_list.begin(); | 759 for (std::list<std::string>::iterator it = label_list.begin(); |
764 it != label_list.end(); ++it) { | 760 it != label_list.end(); ++it) { |
765 DeviceRequest* request = requests_[*it]; | 761 DeviceRequest* request = requests_[*it]; |
766 switch (request->type) { | 762 switch (request->type) { |
767 case DeviceRequest::ENUMERATE_DEVICES: | 763 case MEDIA_ENUMERATE_DEVICES: |
768 if (need_update_clients && request->requester) | 764 if (need_update_clients && request->requester) |
769 request->requester->DevicesEnumerated(*it, devices); | 765 request->requester->DevicesEnumerated(*it, devices); |
770 break; | 766 break; |
771 case DeviceRequest::OPEN_DEVICE: | |
772 DCHECK(!request->requested_device_id.empty()); | |
773 for (StreamDeviceInfoArray::const_iterator device_it = devices.begin(); | |
774 device_it != devices.end(); ++device_it) { | |
775 if (request->requested_device_id == device_it->device_id) { | |
776 StreamDeviceInfo device = *device_it; | |
777 device.in_use = false; | |
778 device.session_id = | |
779 GetDeviceManager(device_it->stream_type)->Open(device); | |
780 request->SetState(device_it->stream_type, | |
781 MEDIA_REQUEST_STATE_OPENING); | |
782 request->devices.push_back(device); | |
783 break; | |
784 } | |
785 } | |
786 break; | |
787 default: | 767 default: |
788 if (request->state(request->options.audio_type) == | 768 if (request->state(request->options.audio_type) == |
789 MEDIA_REQUEST_STATE_REQUESTED || | 769 MEDIA_REQUEST_STATE_REQUESTED || |
790 request->state(request->options.video_type) == | 770 request->state(request->options.video_type) == |
791 MEDIA_REQUEST_STATE_REQUESTED) { | 771 MEDIA_REQUEST_STATE_REQUESTED) { |
792 // We are doing enumeration for other type of media, wait until it is | 772 // We are doing enumeration for other type of media, wait until it is |
793 // all done before posting the request to UI because UI needs | 773 // all done before posting the request to UI because UI needs |
794 // the device lists to handle the request. | 774 // the device lists to handle the request. |
795 break; | 775 break; |
796 } | 776 } |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
861 | 841 |
862 void MediaStreamManager::DevicesAccepted(const std::string& label, | 842 void MediaStreamManager::DevicesAccepted(const std::string& label, |
863 const StreamDeviceInfoArray& devices) { | 843 const StreamDeviceInfoArray& devices) { |
864 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 844 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
865 DCHECK(!devices.empty()); | 845 DCHECK(!devices.empty()); |
866 DeviceRequests::iterator request_it = requests_.find(label); | 846 DeviceRequests::iterator request_it = requests_.find(label); |
867 if (request_it == requests_.end()) { | 847 if (request_it == requests_.end()) { |
868 return; | 848 return; |
869 } | 849 } |
870 | 850 |
871 if (request_it->second->type == DeviceRequest::DEVICE_ACCESS) { | 851 if (request_it->second->type == MEDIA_DEVICE_ACCESS) { |
872 scoped_ptr<DeviceRequest> request(request_it->second); | 852 scoped_ptr<DeviceRequest> request(request_it->second); |
873 if (!request->callback.is_null()) { | 853 if (!request->callback.is_null()) { |
874 // Map the devices to MediaStreamDevices. | 854 // Map the devices to MediaStreamDevices. |
875 MediaStreamDevices selected_devices; | 855 MediaStreamDevices selected_devices; |
876 for (StreamDeviceInfoArray::const_iterator it = devices.begin(); | 856 for (StreamDeviceInfoArray::const_iterator it = devices.begin(); |
877 it != devices.end(); ++it) { | 857 it != devices.end(); ++it) { |
878 selected_devices.push_back(MediaStreamDevice( | 858 selected_devices.push_back(MediaStreamDevice( |
879 it->stream_type, it->device_id, it->name)); | 859 it->stream_type, it->device_id, it->name)); |
880 } | 860 } |
881 | 861 |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
932 // Erase this request and report an error. | 912 // Erase this request and report an error. |
933 DeviceRequests::iterator it = requests_.find(label); | 913 DeviceRequests::iterator it = requests_.find(label); |
934 if (it == requests_.end()) | 914 if (it == requests_.end()) |
935 return; | 915 return; |
936 | 916 |
937 // Notify the users about the request result. | 917 // Notify the users about the request result. |
938 scoped_ptr<DeviceRequest> request(it->second); | 918 scoped_ptr<DeviceRequest> request(it->second); |
939 if (request->requester) | 919 if (request->requester) |
940 request->requester->StreamGenerationFailed(label); | 920 request->requester->StreamGenerationFailed(label); |
941 | 921 |
942 if (request->type == DeviceRequest::DEVICE_ACCESS && | 922 if (request->type == MEDIA_DEVICE_ACCESS && |
943 !request->callback.is_null()) { | 923 !request->callback.is_null()) { |
944 request->callback.Run(label, MediaStreamDevices()); | 924 request->callback.Run(label, MediaStreamDevices()); |
945 } | 925 } |
946 | 926 |
947 requests_.erase(it); | 927 requests_.erase(it); |
948 } | 928 } |
949 | 929 |
950 void MediaStreamManager::GetAvailableDevices(MediaStreamDevices* devices) { | 930 void MediaStreamManager::GetAvailableDevices(MediaStreamDevices* devices) { |
951 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 931 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
952 DCHECK(audio_enumeration_cache_.valid || video_enumeration_cache_.valid); | 932 DCHECK(audio_enumeration_cache_.valid || video_enumeration_cache_.valid); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1118 } | 1098 } |
1119 | 1099 |
1120 // Always do enumeration even though some enumeration is in progress, | 1100 // Always do enumeration even though some enumeration is in progress, |
1121 // because those enumeration commands could be sent before these devices | 1101 // because those enumeration commands could be sent before these devices |
1122 // change. | 1102 // change. |
1123 ++active_enumeration_ref_count_[stream_type]; | 1103 ++active_enumeration_ref_count_[stream_type]; |
1124 GetDeviceManager(stream_type)->EnumerateDevices(); | 1104 GetDeviceManager(stream_type)->EnumerateDevices(); |
1125 } | 1105 } |
1126 | 1106 |
1127 } // namespace content | 1107 } // namespace content |
OLD | NEW |