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 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 output_string += "No devices found."; | 138 output_string += "No devices found."; |
139 } else { | 139 } else { |
140 for (StreamDeviceInfoArray::const_iterator it = devices.begin(); | 140 for (StreamDeviceInfoArray::const_iterator it = devices.begin(); |
141 it != devices.end(); ++it) { | 141 it != devices.end(); ++it) { |
142 output_string += " " + it->device.name + "\n"; | 142 output_string += " " + it->device.name + "\n"; |
143 } | 143 } |
144 } | 144 } |
145 return output_string; | 145 return output_string; |
146 } | 146 } |
147 | 147 |
| 148 // Needed for MediaStreamManager::GenerateStream below. |
| 149 std::string ReturnEmptySalt() { |
| 150 return std::string(); |
| 151 } |
| 152 |
148 } // namespace | 153 } // namespace |
149 | 154 |
150 | 155 |
151 // MediaStreamManager::DeviceRequest represents a request to either enumerate | 156 // MediaStreamManager::DeviceRequest represents a request to either enumerate |
152 // available devices or open one or more devices. | 157 // available devices or open one or more devices. |
153 // TODO(perkj): MediaStreamManager still needs refactoring. I propose we create | 158 // TODO(perkj): MediaStreamManager still needs refactoring. I propose we create |
154 // several subclasses of DeviceRequest and move some of the responsibility of | 159 // several subclasses of DeviceRequest and move some of the responsibility of |
155 // the MediaStreamManager to the subclasses to get rid of the way too many if | 160 // the MediaStreamManager to the subclasses to get rid of the way too many if |
156 // statements in MediaStreamManager. | 161 // statements in MediaStreamManager. |
157 class MediaStreamManager::DeviceRequest { | 162 class MediaStreamManager::DeviceRequest { |
158 public: | 163 public: |
159 DeviceRequest(MediaStreamRequester* requester, | 164 DeviceRequest(MediaStreamRequester* requester, |
160 int requesting_process_id, | 165 int requesting_process_id, |
161 int requesting_view_id, | 166 int requesting_view_id, |
162 int page_request_id, | 167 int page_request_id, |
163 const GURL& security_origin, | 168 const GURL& security_origin, |
164 MediaStreamRequestType request_type, | 169 MediaStreamRequestType request_type, |
165 const StreamOptions& options, | 170 const StreamOptions& options, |
166 ResourceContext* resource_context) | 171 const ResourceContext::SaltCallback& salt_callback) |
167 : requester(requester), | 172 : requester(requester), |
168 requesting_process_id(requesting_process_id), | 173 requesting_process_id(requesting_process_id), |
169 requesting_view_id(requesting_view_id), | 174 requesting_view_id(requesting_view_id), |
170 page_request_id(page_request_id), | 175 page_request_id(page_request_id), |
171 security_origin(security_origin), | 176 security_origin(security_origin), |
172 request_type(request_type), | 177 request_type(request_type), |
173 options(options), | 178 options(options), |
174 resource_context(resource_context), | 179 salt_callback(salt_callback), |
175 state_(NUM_MEDIA_TYPES, MEDIA_REQUEST_STATE_NOT_REQUESTED), | 180 state_(NUM_MEDIA_TYPES, MEDIA_REQUEST_STATE_NOT_REQUESTED), |
176 audio_type_(MEDIA_NO_SERVICE), | 181 audio_type_(MEDIA_NO_SERVICE), |
177 video_type_(MEDIA_NO_SERVICE) { | 182 video_type_(MEDIA_NO_SERVICE) { |
178 } | 183 } |
179 | 184 |
180 ~DeviceRequest() {} | 185 ~DeviceRequest() {} |
181 | 186 |
182 void SetAudioType(MediaStreamType audio_type) { | 187 void SetAudioType(MediaStreamType audio_type) { |
183 DCHECK(IsAudioMediaType(audio_type) || audio_type == MEDIA_NO_SERVICE); | 188 DCHECK(IsAudioMediaType(audio_type) || audio_type == MEDIA_NO_SERVICE); |
184 audio_type_ = audio_type; | 189 audio_type_ = audio_type; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 | 289 |
285 // An ID the render view provided to identify this request. | 290 // An ID the render view provided to identify this request. |
286 const int page_request_id; | 291 const int page_request_id; |
287 | 292 |
288 const GURL security_origin; | 293 const GURL security_origin; |
289 | 294 |
290 const MediaStreamRequestType request_type; | 295 const MediaStreamRequestType request_type; |
291 | 296 |
292 const StreamOptions options; | 297 const StreamOptions options; |
293 | 298 |
294 ResourceContext* resource_context; | 299 ResourceContext::SaltCallback salt_callback; |
295 | 300 |
296 StreamDeviceInfoArray devices; | 301 StreamDeviceInfoArray devices; |
297 | 302 |
298 // Callback to the requester which audio/video devices have been selected. | 303 // Callback to the requester which audio/video devices have been selected. |
299 // It can be null if the requester has no interest to know the result. | 304 // It can be null if the requester has no interest to know the result. |
300 // Currently it is only used by |DEVICE_ACCESS| type. | 305 // Currently it is only used by |DEVICE_ACCESS| type. |
301 MediaStreamManager::MediaRequestResponseCallback callback; | 306 MediaStreamManager::MediaRequestResponseCallback callback; |
302 | 307 |
303 scoped_ptr<MediaStreamUIProxy> ui_proxy; | 308 scoped_ptr<MediaStreamUIProxy> ui_proxy; |
304 | 309 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 | 377 |
373 // TODO(perkj): The argument list with NULL parameters to DeviceRequest | 378 // TODO(perkj): The argument list with NULL parameters to DeviceRequest |
374 // suggests that this is the wrong design. Can this be refactored? | 379 // suggests that this is the wrong design. Can this be refactored? |
375 DeviceRequest* request = new DeviceRequest(NULL, | 380 DeviceRequest* request = new DeviceRequest(NULL, |
376 render_process_id, | 381 render_process_id, |
377 render_view_id, | 382 render_view_id, |
378 page_request_id, | 383 page_request_id, |
379 security_origin, | 384 security_origin, |
380 MEDIA_DEVICE_ACCESS, | 385 MEDIA_DEVICE_ACCESS, |
381 options, | 386 options, |
382 NULL); | 387 base::Bind(&ReturnEmptySalt)); |
383 | 388 |
384 const std::string& label = AddRequest(request); | 389 const std::string& label = AddRequest(request); |
385 | 390 |
386 request->callback = callback; | 391 request->callback = callback; |
387 // Post a task and handle the request asynchronously. The reason is that the | 392 // Post a task and handle the request asynchronously. The reason is that the |
388 // requester won't have a label for the request until this function returns | 393 // requester won't have a label for the request until this function returns |
389 // and thus can not handle a response. Using base::Unretained is safe since | 394 // and thus can not handle a response. Using base::Unretained is safe since |
390 // MediaStreamManager is deleted on the UI thread, after the IO thread has | 395 // MediaStreamManager is deleted on the UI thread, after the IO thread has |
391 // been stopped. | 396 // been stopped. |
392 BrowserThread::PostTask( | 397 BrowserThread::PostTask( |
393 BrowserThread::IO, FROM_HERE, | 398 BrowserThread::IO, FROM_HERE, |
394 base::Bind(&MediaStreamManager::SetupRequest, | 399 base::Bind(&MediaStreamManager::SetupRequest, |
395 base::Unretained(this), label)); | 400 base::Unretained(this), label)); |
396 return label; | 401 return label; |
397 } | 402 } |
398 | 403 |
399 void MediaStreamManager::GenerateStream(MediaStreamRequester* requester, | 404 void MediaStreamManager::GenerateStream(MediaStreamRequester* requester, |
400 int render_process_id, | 405 int render_process_id, |
401 int render_view_id, | 406 int render_view_id, |
402 ResourceContext* rc, | 407 const ResourceContext::SaltCallback& sc, |
403 int page_request_id, | 408 int page_request_id, |
404 const StreamOptions& options, | 409 const StreamOptions& options, |
405 const GURL& security_origin) { | 410 const GURL& security_origin) { |
406 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 411 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
407 DVLOG(1) << "GenerateStream()"; | 412 DVLOG(1) << "GenerateStream()"; |
408 if (CommandLine::ForCurrentProcess()->HasSwitch( | 413 if (CommandLine::ForCurrentProcess()->HasSwitch( |
409 switches::kUseFakeUIForMediaStream)) { | 414 switches::kUseFakeUIForMediaStream)) { |
410 UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy>()); | 415 UseFakeUI(scoped_ptr<FakeMediaStreamUIProxy>()); |
411 } | 416 } |
412 | 417 |
413 DeviceRequest* request = new DeviceRequest(requester, | 418 DeviceRequest* request = new DeviceRequest(requester, |
414 render_process_id, | 419 render_process_id, |
415 render_view_id, | 420 render_view_id, |
416 page_request_id, | 421 page_request_id, |
417 security_origin, | 422 security_origin, |
418 MEDIA_GENERATE_STREAM, | 423 MEDIA_GENERATE_STREAM, |
419 options, | 424 options, |
420 rc); | 425 sc); |
421 | 426 |
422 const std::string& label = AddRequest(request); | 427 const std::string& label = AddRequest(request); |
423 | 428 |
424 // Post a task and handle the request asynchronously. The reason is that the | 429 // Post a task and handle the request asynchronously. The reason is that the |
425 // requester won't have a label for the request until this function returns | 430 // requester won't have a label for the request until this function returns |
426 // and thus can not handle a response. Using base::Unretained is safe since | 431 // and thus can not handle a response. Using base::Unretained is safe since |
427 // MediaStreamManager is deleted on the UI thread, after the IO thread has | 432 // MediaStreamManager is deleted on the UI thread, after the IO thread has |
428 // been stopped. | 433 // been stopped. |
429 BrowserThread::PostTask( | 434 BrowserThread::PostTask( |
430 BrowserThread::IO, FROM_HERE, | 435 BrowserThread::IO, FROM_HERE, |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 request_it->second->SetState(type, MEDIA_REQUEST_STATE_CLOSING); | 591 request_it->second->SetState(type, MEDIA_REQUEST_STATE_CLOSING); |
587 } | 592 } |
588 } | 593 } |
589 } | 594 } |
590 } | 595 } |
591 | 596 |
592 std::string MediaStreamManager::EnumerateDevices( | 597 std::string MediaStreamManager::EnumerateDevices( |
593 MediaStreamRequester* requester, | 598 MediaStreamRequester* requester, |
594 int render_process_id, | 599 int render_process_id, |
595 int render_view_id, | 600 int render_view_id, |
596 ResourceContext* rc, | 601 const ResourceContext::SaltCallback& sc, |
597 int page_request_id, | 602 int page_request_id, |
598 MediaStreamType type, | 603 MediaStreamType type, |
599 const GURL& security_origin) { | 604 const GURL& security_origin) { |
600 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 605 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
601 DCHECK(requester); | 606 DCHECK(requester); |
602 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || | 607 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || |
603 type == MEDIA_DEVICE_VIDEO_CAPTURE); | 608 type == MEDIA_DEVICE_VIDEO_CAPTURE); |
604 | 609 |
605 DeviceRequest* request = new DeviceRequest(requester, | 610 DeviceRequest* request = new DeviceRequest(requester, |
606 render_process_id, | 611 render_process_id, |
607 render_view_id, | 612 render_view_id, |
608 page_request_id, | 613 page_request_id, |
609 security_origin, | 614 security_origin, |
610 MEDIA_ENUMERATE_DEVICES, | 615 MEDIA_ENUMERATE_DEVICES, |
611 StreamOptions(), | 616 StreamOptions(), |
612 rc); | 617 sc); |
613 if (IsAudioMediaType(type)) | 618 if (IsAudioMediaType(type)) |
614 request->SetAudioType(type); | 619 request->SetAudioType(type); |
615 else if (IsVideoMediaType(type)) | 620 else if (IsVideoMediaType(type)) |
616 request->SetVideoType(type); | 621 request->SetVideoType(type); |
617 | 622 |
618 const std::string& label = AddRequest(request); | 623 const std::string& label = AddRequest(request); |
619 // Post a task and handle the request asynchronously. The reason is that the | 624 // Post a task and handle the request asynchronously. The reason is that the |
620 // requester won't have a label for the request until this function returns | 625 // requester won't have a label for the request until this function returns |
621 // and thus can not handle a response. Using base::Unretained is safe since | 626 // and thus can not handle a response. Using base::Unretained is safe since |
622 // MediaStreamManager is deleted on the UI thread, after the IO thread has | 627 // MediaStreamManager is deleted on the UI thread, after the IO thread has |
(...skipping 30 matching lines...) Expand all Loading... |
653 FinalizeEnumerateDevices(label, request); | 658 FinalizeEnumerateDevices(label, request); |
654 } else { | 659 } else { |
655 StartEnumeration(request); | 660 StartEnumeration(request); |
656 } | 661 } |
657 DVLOG(1) << "Enumerate Devices ({label = " << label << "})"; | 662 DVLOG(1) << "Enumerate Devices ({label = " << label << "})"; |
658 } | 663 } |
659 | 664 |
660 void MediaStreamManager::OpenDevice(MediaStreamRequester* requester, | 665 void MediaStreamManager::OpenDevice(MediaStreamRequester* requester, |
661 int render_process_id, | 666 int render_process_id, |
662 int render_view_id, | 667 int render_view_id, |
663 ResourceContext* rc, | 668 const ResourceContext::SaltCallback& sc, |
664 int page_request_id, | 669 int page_request_id, |
665 const std::string& device_id, | 670 const std::string& device_id, |
666 MediaStreamType type, | 671 MediaStreamType type, |
667 const GURL& security_origin) { | 672 const GURL& security_origin) { |
668 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 673 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
669 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || | 674 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || |
670 type == MEDIA_DEVICE_VIDEO_CAPTURE); | 675 type == MEDIA_DEVICE_VIDEO_CAPTURE); |
671 DVLOG(1) << "OpenDevice ({page_request_id = " << page_request_id << "})"; | 676 DVLOG(1) << "OpenDevice ({page_request_id = " << page_request_id << "})"; |
672 StreamOptions options; | 677 StreamOptions options; |
673 if (IsAudioMediaType(type)) { | 678 if (IsAudioMediaType(type)) { |
674 options.audio_requested = true; | 679 options.audio_requested = true; |
675 options.mandatory_audio.push_back( | 680 options.mandatory_audio.push_back( |
676 StreamOptions::Constraint(kMediaStreamSourceInfoId, device_id)); | 681 StreamOptions::Constraint(kMediaStreamSourceInfoId, device_id)); |
677 } else if (IsVideoMediaType(type)) { | 682 } else if (IsVideoMediaType(type)) { |
678 options.video_requested = true; | 683 options.video_requested = true; |
679 options.mandatory_video.push_back( | 684 options.mandatory_video.push_back( |
680 StreamOptions::Constraint(kMediaStreamSourceInfoId, device_id)); | 685 StreamOptions::Constraint(kMediaStreamSourceInfoId, device_id)); |
681 } else { | 686 } else { |
682 NOTREACHED(); | 687 NOTREACHED(); |
683 } | 688 } |
684 DeviceRequest* request = new DeviceRequest(requester, | 689 DeviceRequest* request = new DeviceRequest(requester, |
685 render_process_id, | 690 render_process_id, |
686 render_view_id, | 691 render_view_id, |
687 page_request_id, | 692 page_request_id, |
688 security_origin, | 693 security_origin, |
689 MEDIA_OPEN_DEVICE, | 694 MEDIA_OPEN_DEVICE, |
690 options, | 695 options, |
691 rc); | 696 sc); |
692 | 697 |
693 const std::string& label = AddRequest(request); | 698 const std::string& label = AddRequest(request); |
694 // Post a task and handle the request asynchronously. The reason is that the | 699 // Post a task and handle the request asynchronously. The reason is that the |
695 // requester won't have a label for the request until this function returns | 700 // requester won't have a label for the request until this function returns |
696 // and thus can not handle a response. Using base::Unretained is safe since | 701 // and thus can not handle a response. Using base::Unretained is safe since |
697 // MediaStreamManager is deleted on the UI thread, after the IO thread has | 702 // MediaStreamManager is deleted on the UI thread, after the IO thread has |
698 // been stopped. | 703 // been stopped. |
699 BrowserThread::PostTask( | 704 BrowserThread::PostTask( |
700 BrowserThread::IO, FROM_HERE, | 705 BrowserThread::IO, FROM_HERE, |
701 base::Bind(&MediaStreamManager::SetupRequest, | 706 base::Bind(&MediaStreamManager::SetupRequest, |
702 base::Unretained(this), label)); | 707 base::Unretained(this), label)); |
703 } | 708 } |
704 | 709 |
705 void MediaStreamManager::EnsureDeviceMonitorStarted() { | 710 void MediaStreamManager::EnsureDeviceMonitorStarted() { |
706 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 711 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
707 StartMonitoring(); | 712 StartMonitoring(); |
708 } | 713 } |
709 | 714 |
710 void MediaStreamManager::StopRemovedDevices( | 715 void MediaStreamManager::StopRemovedDevices( |
711 const StreamDeviceInfoArray& old_devices, | 716 const StreamDeviceInfoArray& old_devices, |
712 const StreamDeviceInfoArray& new_devices) { | 717 const StreamDeviceInfoArray& new_devices) { |
713 DVLOG(1) << "StopRemovedDevices(" | 718 DVLOG(1) << "StopRemovedDevices(" |
714 << "{#old_devices = " << old_devices.size() << "} " | 719 << "{#old_devices = " << old_devices.size() << "} " |
715 << "{#new_devices = " << new_devices.size() << "})"; | 720 << "{#new_devices = " << new_devices.size() << "})"; |
716 for (StreamDeviceInfoArray::const_iterator old_dev_it = old_devices.begin(); | 721 for (StreamDeviceInfoArray::const_iterator old_dev_it = old_devices.begin(); |
717 old_dev_it != old_devices.end(); ++old_dev_it) { | 722 old_dev_it != old_devices.end(); ++old_dev_it) { |
718 bool device_found = false; | 723 bool device_found = false; |
719 for (StreamDeviceInfoArray::const_iterator new_dev_it = new_devices.begin(); | 724 StreamDeviceInfoArray::const_iterator new_dev_it = new_devices.begin(); |
720 new_dev_it != new_devices.end(); ++new_dev_it) { | 725 for (; new_dev_it != new_devices.end(); ++new_dev_it) { |
721 if (old_dev_it->device.id == new_dev_it->device.id) { | 726 if (old_dev_it->device.id == new_dev_it->device.id) { |
722 device_found = true; | 727 device_found = true; |
723 break; | 728 break; |
724 } | 729 } |
725 } | 730 } |
726 | 731 |
727 if (!device_found) { | 732 if (!device_found) { |
728 // A device has been removed. We need to check if it is used by a | 733 // A device has been removed. We need to check if it is used by a |
729 // MediaStream and in that case cleanup and notify the render process. | 734 // MediaStream and in that case cleanup and notify the render process. |
730 StopRemovedDevice(old_dev_it->device); | 735 StopRemovedDevice(old_dev_it->device); |
731 } | 736 } |
732 } | 737 } |
733 } | 738 } |
734 | 739 |
735 void MediaStreamManager::StopRemovedDevice(const MediaStreamDevice& device) { | 740 void MediaStreamManager::StopRemovedDevice(const MediaStreamDevice& device) { |
736 std::vector<int> session_ids; | 741 std::vector<int> session_ids; |
737 for (DeviceRequests::const_iterator it = requests_.begin(); | 742 for (DeviceRequests::const_iterator it = requests_.begin(); |
738 it != requests_.end() ; ++it) { | 743 it != requests_.end() ; ++it) { |
739 const DeviceRequest* request = it->second; | 744 const DeviceRequest* request = it->second; |
740 for (StreamDeviceInfoArray::const_iterator device_it = | 745 for (StreamDeviceInfoArray::const_iterator device_it = |
741 request->devices.begin(); | 746 request->devices.begin(); |
742 device_it != request->devices.end(); ++device_it) { | 747 device_it != request->devices.end(); ++device_it) { |
743 std::string source_id = content::GetHMACForMediaDeviceID( | 748 std::string source_id = content::GetHMACForMediaDeviceID( |
744 request->resource_context, | 749 request->salt_callback, |
745 request->security_origin, | 750 request->security_origin, |
746 device.id); | 751 device.id); |
747 if (device_it->device.id == source_id && | 752 if (device_it->device.id == source_id && |
748 device_it->device.type == device.type) { | 753 device_it->device.type == device.type) { |
749 session_ids.push_back(device_it->session_id); | 754 session_ids.push_back(device_it->session_id); |
750 if (it->second->requester) { | 755 if (it->second->requester) { |
751 it->second->requester->DeviceStopped( | 756 it->second->requester->DeviceStopped( |
752 it->second->requesting_view_id, | 757 it->second->requesting_view_id, |
753 it->first, | 758 it->first, |
754 *device_it); | 759 *device_it); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 kMediaStreamSourceInfoId, &source_ids); | 814 kMediaStreamSourceInfoId, &source_ids); |
810 if (source_ids.size() > 1) { | 815 if (source_ids.size() > 1) { |
811 LOG(ERROR) << "Only one mandatory " << kMediaStreamSourceInfoId | 816 LOG(ERROR) << "Only one mandatory " << kMediaStreamSourceInfoId |
812 << " is supported."; | 817 << " is supported."; |
813 return false; | 818 return false; |
814 } | 819 } |
815 // If a specific device has been requested we need to find the real device | 820 // If a specific device has been requested we need to find the real device |
816 // id. | 821 // id. |
817 if (source_ids.size() == 1 && | 822 if (source_ids.size() == 1 && |
818 !TranslateSourceIdToDeviceId(type, | 823 !TranslateSourceIdToDeviceId(type, |
819 request->resource_context, | 824 request->salt_callback, |
820 request->security_origin, | 825 request->security_origin, |
821 source_ids[0], device_id)) { | 826 source_ids[0], device_id)) { |
822 LOG(WARNING) << "Invalid mandatory " << kMediaStreamSourceInfoId | 827 LOG(WARNING) << "Invalid mandatory " << kMediaStreamSourceInfoId |
823 << " = " << source_ids[0] << "."; | 828 << " = " << source_ids[0] << "."; |
824 return false; | 829 return false; |
825 } | 830 } |
826 // Check for optional audio sourceIDs. | 831 // Check for optional audio sourceIDs. |
827 if (device_id->empty()) { | 832 if (device_id->empty()) { |
828 StreamOptions::GetConstraintsByName(*optional, | 833 StreamOptions::GetConstraintsByName(*optional, |
829 kMediaStreamSourceInfoId, | 834 kMediaStreamSourceInfoId, |
830 &source_ids); | 835 &source_ids); |
831 // Find the first sourceID that translates to device. Note that only one | 836 // Find the first sourceID that translates to device. Note that only one |
832 // device per type can call to GenerateStream is ever opened. | 837 // device per type can call to GenerateStream is ever opened. |
833 for (std::vector<std::string>::const_iterator it = source_ids.begin(); | 838 for (std::vector<std::string>::const_iterator it = source_ids.begin(); |
834 it != source_ids.end(); ++it) { | 839 it != source_ids.end(); ++it) { |
835 if (TranslateSourceIdToDeviceId(type, | 840 if (TranslateSourceIdToDeviceId(type, |
836 request->resource_context, | 841 request->salt_callback, |
837 request->security_origin, | 842 request->security_origin, |
838 *it, | 843 *it, |
839 device_id)) { | 844 device_id)) { |
840 break; | 845 break; |
841 } | 846 } |
842 } | 847 } |
843 } | 848 } |
844 return true; | 849 return true; |
845 } | 850 } |
846 | 851 |
847 void MediaStreamManager::TranslateDeviceIdToSourceId( | 852 void MediaStreamManager::TranslateDeviceIdToSourceId( |
848 DeviceRequest* request, | 853 DeviceRequest* request, |
849 MediaStreamDevice* device) { | 854 MediaStreamDevice* device) { |
850 if (request->audio_type() == MEDIA_DEVICE_AUDIO_CAPTURE || | 855 if (request->audio_type() == MEDIA_DEVICE_AUDIO_CAPTURE || |
851 request->video_type() == MEDIA_DEVICE_VIDEO_CAPTURE) { | 856 request->video_type() == MEDIA_DEVICE_VIDEO_CAPTURE) { |
852 device->id = content::GetHMACForMediaDeviceID( | 857 device->id = content::GetHMACForMediaDeviceID( |
853 request->resource_context, | 858 request->salt_callback, |
854 request->security_origin, | 859 request->security_origin, |
855 device->id); | 860 device->id); |
856 } | 861 } |
857 } | 862 } |
858 | 863 |
859 bool MediaStreamManager::TranslateSourceIdToDeviceId( | 864 bool MediaStreamManager::TranslateSourceIdToDeviceId( |
860 MediaStreamType stream_type, | 865 MediaStreamType stream_type, |
861 ResourceContext* rc, | 866 const ResourceContext::SaltCallback& sc, |
862 const GURL& security_origin, | 867 const GURL& security_origin, |
863 const std::string& source_id, | 868 const std::string& source_id, |
864 std::string* device_id) const { | 869 std::string* device_id) const { |
865 DCHECK(stream_type == MEDIA_DEVICE_AUDIO_CAPTURE || | 870 DCHECK(stream_type == MEDIA_DEVICE_AUDIO_CAPTURE || |
866 stream_type == MEDIA_DEVICE_VIDEO_CAPTURE); | 871 stream_type == MEDIA_DEVICE_VIDEO_CAPTURE); |
867 // The source_id can be empty if the constraint is set but empty. | 872 // The source_id can be empty if the constraint is set but empty. |
868 if (source_id.empty()) | 873 if (source_id.empty()) |
869 return false; | 874 return false; |
870 | 875 |
871 const EnumerationCache* cache = | 876 const EnumerationCache* cache = |
872 stream_type == MEDIA_DEVICE_AUDIO_CAPTURE ? | 877 stream_type == MEDIA_DEVICE_AUDIO_CAPTURE ? |
873 &audio_enumeration_cache_ : &video_enumeration_cache_; | 878 &audio_enumeration_cache_ : &video_enumeration_cache_; |
874 | 879 |
875 // If device monitoring hasn't started, the |device_guid| is not valid. | 880 // If device monitoring hasn't started, the |device_guid| is not valid. |
876 if (!cache->valid) | 881 if (!cache->valid) |
877 return false; | 882 return false; |
878 | 883 |
879 for (StreamDeviceInfoArray::const_iterator it = cache->devices.begin(); | 884 for (StreamDeviceInfoArray::const_iterator it = cache->devices.begin(); |
880 it != cache->devices.end(); | 885 it != cache->devices.end(); |
881 ++it) { | 886 ++it) { |
882 if (content::DoesMediaDeviceIDMatchHMAC(rc, security_origin, source_id, | 887 if (content::DoesMediaDeviceIDMatchHMAC(sc, security_origin, source_id, |
883 it->device.id)) { | 888 it->device.id)) { |
884 *device_id = it->device.id; | 889 *device_id = it->device.id; |
885 return true; | 890 return true; |
886 } | 891 } |
887 } | 892 } |
888 return false; | 893 return false; |
889 } | 894 } |
890 | 895 |
891 void MediaStreamManager::ClearEnumerationCache(EnumerationCache* cache) { | 896 void MediaStreamManager::ClearEnumerationCache(EnumerationCache* cache) { |
892 DCHECK_EQ(base::MessageLoop::current(), io_loop_); | 897 DCHECK_EQ(base::MessageLoop::current(), io_loop_); |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1209 | 1214 |
1210 bool MediaStreamManager::FindExistingRequestedDeviceInfo( | 1215 bool MediaStreamManager::FindExistingRequestedDeviceInfo( |
1211 const DeviceRequest& new_request, | 1216 const DeviceRequest& new_request, |
1212 const MediaStreamDevice& new_device_info, | 1217 const MediaStreamDevice& new_device_info, |
1213 StreamDeviceInfo* existing_device_info, | 1218 StreamDeviceInfo* existing_device_info, |
1214 MediaRequestState* existing_request_state) const { | 1219 MediaRequestState* existing_request_state) const { |
1215 DCHECK(existing_device_info); | 1220 DCHECK(existing_device_info); |
1216 DCHECK(existing_request_state); | 1221 DCHECK(existing_request_state); |
1217 | 1222 |
1218 std::string source_id = content::GetHMACForMediaDeviceID( | 1223 std::string source_id = content::GetHMACForMediaDeviceID( |
1219 new_request.resource_context, | 1224 new_request.salt_callback, |
1220 new_request.security_origin, | 1225 new_request.security_origin, |
1221 new_device_info.id); | 1226 new_device_info.id); |
1222 | 1227 |
1223 for (DeviceRequests::const_iterator it = requests_.begin(); | 1228 for (DeviceRequests::const_iterator it = requests_.begin(); |
1224 it != requests_.end() ; ++it) { | 1229 it != requests_.end() ; ++it) { |
1225 const DeviceRequest* request = it->second; | 1230 const DeviceRequest* request = it->second; |
1226 if (request->requesting_process_id == new_request.requesting_process_id && | 1231 if (request->requesting_process_id == new_request.requesting_process_id && |
1227 request->requesting_view_id == new_request.requesting_view_id && | 1232 request->requesting_view_id == new_request.requesting_view_id && |
1228 request->request_type == new_request.request_type) { | 1233 request->request_type == new_request.request_type) { |
1229 for (StreamDeviceInfoArray::const_iterator device_it = | 1234 for (StreamDeviceInfoArray::const_iterator device_it = |
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1811 } | 1816 } |
1812 | 1817 |
1813 // Always do enumeration even though some enumeration is in progress, | 1818 // Always do enumeration even though some enumeration is in progress, |
1814 // because those enumeration commands could be sent before these devices | 1819 // because those enumeration commands could be sent before these devices |
1815 // change. | 1820 // change. |
1816 ++active_enumeration_ref_count_[stream_type]; | 1821 ++active_enumeration_ref_count_[stream_type]; |
1817 GetDeviceManager(stream_type)->EnumerateDevices(stream_type); | 1822 GetDeviceManager(stream_type)->EnumerateDevices(stream_type); |
1818 } | 1823 } |
1819 | 1824 |
1820 } // namespace content | 1825 } // namespace content |
OLD | NEW |