| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 const std::string& device_id, | 697 const std::string& device_id, |
| 698 MediaStreamType type, | 698 MediaStreamType type, |
| 699 const url::Origin& security_origin) { | 699 const url::Origin& security_origin) { |
| 700 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 700 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 701 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || | 701 DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || |
| 702 type == MEDIA_DEVICE_VIDEO_CAPTURE); | 702 type == MEDIA_DEVICE_VIDEO_CAPTURE); |
| 703 DVLOG(1) << "OpenDevice ({page_request_id = " << page_request_id << "})"; | 703 DVLOG(1) << "OpenDevice ({page_request_id = " << page_request_id << "})"; |
| 704 StreamControls controls; | 704 StreamControls controls; |
| 705 if (IsAudioInputMediaType(type)) { | 705 if (IsAudioInputMediaType(type)) { |
| 706 controls.audio.requested = true; | 706 controls.audio.requested = true; |
| 707 controls.audio.device_ids.push_back(device_id); | 707 controls.audio.device_id = device_id; |
| 708 } else if (IsVideoMediaType(type)) { | 708 } else if (IsVideoMediaType(type)) { |
| 709 controls.video.requested = true; | 709 controls.video.requested = true; |
| 710 controls.video.device_ids.push_back(device_id); | 710 controls.video.device_id = device_id; |
| 711 } else { | 711 } else { |
| 712 NOTREACHED(); | 712 NOTREACHED(); |
| 713 } | 713 } |
| 714 DeviceRequest* request = | 714 DeviceRequest* request = |
| 715 new DeviceRequest(requester, render_process_id, render_frame_id, | 715 new DeviceRequest(requester, render_process_id, render_frame_id, |
| 716 page_request_id, security_origin, | 716 page_request_id, security_origin, |
| 717 false, // user gesture | 717 false, // user gesture |
| 718 MEDIA_OPEN_DEVICE_PEPPER_ONLY, controls, salt); | 718 MEDIA_OPEN_DEVICE_PEPPER_ONLY, controls, salt); |
| 719 | 719 |
| 720 const std::string& label = AddRequest(request); | 720 const std::string& label = AddRequest(request); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 (stream_type == MEDIA_DEVICE_AUDIO_CAPTURE ? "audio" : "video"), | 786 (stream_type == MEDIA_DEVICE_AUDIO_CAPTURE ? "audio" : "video"), |
| 787 device.device_id.c_str(), device.label.c_str()) | 787 device.device_id.c_str(), device.label.c_str()) |
| 788 .c_str()); | 788 .c_str()); |
| 789 } | 789 } |
| 790 | 790 |
| 791 bool MediaStreamManager::PickDeviceId(const std::string& salt, | 791 bool MediaStreamManager::PickDeviceId(const std::string& salt, |
| 792 const url::Origin& security_origin, | 792 const url::Origin& security_origin, |
| 793 const TrackControls& controls, | 793 const TrackControls& controls, |
| 794 const MediaDeviceInfoArray& devices, | 794 const MediaDeviceInfoArray& devices, |
| 795 std::string* device_id) const { | 795 std::string* device_id) const { |
| 796 if (!controls.device_ids.empty()) { | 796 if (controls.device_id.empty()) |
| 797 if (controls.device_ids.size() > 1) { | |
| 798 LOG(ERROR) << "Only one required device ID is supported"; | |
| 799 return false; | |
| 800 } | |
| 801 const std::string& candidate_id = controls.device_ids[0]; | |
| 802 if (!GetDeviceIDFromHMAC(salt, security_origin, candidate_id, devices, | |
| 803 device_id)) { | |
| 804 LOG(WARNING) << "Invalid mandatory capture ID = " << candidate_id; | |
| 805 return false; | |
| 806 } | |
| 807 return true; | 797 return true; |
| 798 |
| 799 if (!GetDeviceIDFromHMAC(salt, security_origin, controls.device_id, devices, |
| 800 device_id)) { |
| 801 LOG(WARNING) << "Invalid device ID = " << controls.device_id; |
| 802 return false; |
| 808 } | 803 } |
| 809 // We don't have a required ID. Look at the alternates. | 804 return true; |
| 810 for (const std::string& candidate_id : controls.alternate_device_ids) { | |
| 811 if (GetDeviceIDFromHMAC(salt, security_origin, candidate_id, devices, | |
| 812 device_id)) { | |
| 813 return true; | |
| 814 } else { | |
| 815 LOG(WARNING) << "Invalid optional capture ID = " << candidate_id; | |
| 816 } | |
| 817 } | |
| 818 return true; // If we get here, device_id is empty. | |
| 819 } | 805 } |
| 820 | 806 |
| 821 bool MediaStreamManager::GetRequestedDeviceCaptureId( | 807 bool MediaStreamManager::GetRequestedDeviceCaptureId( |
| 822 const DeviceRequest* request, | 808 const DeviceRequest* request, |
| 823 MediaStreamType type, | 809 MediaStreamType type, |
| 824 const MediaDeviceInfoArray& devices, | 810 const MediaDeviceInfoArray& devices, |
| 825 std::string* device_id) const { | 811 std::string* device_id) const { |
| 826 if (type == MEDIA_DEVICE_AUDIO_CAPTURE) { | 812 if (type == MEDIA_DEVICE_AUDIO_CAPTURE) { |
| 827 return PickDeviceId(request->salt, request->security_origin, | 813 return PickDeviceId(request->salt, request->security_origin, |
| 828 request->controls.audio, devices, device_id); | 814 request->controls.audio, devices, device_id); |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1055 << request->controls.video.requested | 1041 << request->controls.video.requested |
| 1056 << " device id = " << video_device_id; | 1042 << " device id = " << video_device_id; |
| 1057 return true; | 1043 return true; |
| 1058 } | 1044 } |
| 1059 | 1045 |
| 1060 bool MediaStreamManager::SetupTabCaptureRequest(DeviceRequest* request) { | 1046 bool MediaStreamManager::SetupTabCaptureRequest(DeviceRequest* request) { |
| 1061 DCHECK(request->audio_type() == MEDIA_TAB_AUDIO_CAPTURE || | 1047 DCHECK(request->audio_type() == MEDIA_TAB_AUDIO_CAPTURE || |
| 1062 request->video_type() == MEDIA_TAB_VIDEO_CAPTURE); | 1048 request->video_type() == MEDIA_TAB_VIDEO_CAPTURE); |
| 1063 | 1049 |
| 1064 std::string capture_device_id; | 1050 std::string capture_device_id; |
| 1065 if (!request->controls.audio.device_ids.empty()) { | 1051 if (!request->controls.audio.device_id.empty()) { |
| 1066 capture_device_id = request->controls.audio.device_ids[0]; | 1052 capture_device_id = request->controls.audio.device_id; |
| 1067 } else if (!request->controls.video.device_ids.empty()) { | 1053 } else if (!request->controls.video.device_id.empty()) { |
| 1068 capture_device_id = request->controls.video.device_ids[0]; | 1054 capture_device_id = request->controls.video.device_id; |
| 1069 } else { | 1055 } else { |
| 1070 return false; | 1056 return false; |
| 1071 } | 1057 } |
| 1072 | 1058 |
| 1073 // Customize controls for a WebContents based capture. | 1059 // Customize controls for a WebContents based capture. |
| 1074 content::WebContentsMediaCaptureId web_id; | 1060 content::WebContentsMediaCaptureId web_id; |
| 1075 bool has_valid_device_id = | 1061 bool has_valid_device_id = |
| 1076 WebContentsMediaCaptureId::Parse(capture_device_id, &web_id); | 1062 WebContentsMediaCaptureId::Parse(capture_device_id, &web_id); |
| 1077 if (!has_valid_device_id || | 1063 if (!has_valid_device_id || |
| 1078 (request->audio_type() != MEDIA_TAB_AUDIO_CAPTURE && | 1064 (request->audio_type() != MEDIA_TAB_AUDIO_CAPTURE && |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1110 LOG(ERROR) << "Invalid screen capture request."; | 1096 LOG(ERROR) << "Invalid screen capture request."; |
| 1111 return false; | 1097 return false; |
| 1112 } | 1098 } |
| 1113 | 1099 |
| 1114 std::string video_device_id; | 1100 std::string video_device_id; |
| 1115 if (request->video_type() == MEDIA_DESKTOP_VIDEO_CAPTURE) { | 1101 if (request->video_type() == MEDIA_DESKTOP_VIDEO_CAPTURE) { |
| 1116 const std::string& video_stream_source = | 1102 const std::string& video_stream_source = |
| 1117 request->controls.video.stream_source; | 1103 request->controls.video.stream_source; |
| 1118 | 1104 |
| 1119 if (video_stream_source == kMediaStreamSourceDesktop && | 1105 if (video_stream_source == kMediaStreamSourceDesktop && |
| 1120 !request->controls.video.device_ids.empty()) { | 1106 !request->controls.video.device_id.empty()) { |
| 1121 video_device_id = request->controls.video.device_ids[0]; | 1107 video_device_id = request->controls.video.device_id; |
| 1122 } | 1108 } |
| 1123 } | 1109 } |
| 1124 | 1110 |
| 1125 const std::string audio_device_id = | 1111 const std::string audio_device_id = |
| 1126 request->audio_type() == MEDIA_DESKTOP_AUDIO_CAPTURE ? video_device_id | 1112 request->audio_type() == MEDIA_DESKTOP_AUDIO_CAPTURE ? video_device_id |
| 1127 : ""; | 1113 : ""; |
| 1128 | 1114 |
| 1129 request->CreateUIRequest(audio_device_id, video_device_id); | 1115 request->CreateUIRequest(audio_device_id, video_device_id); |
| 1130 return true; | 1116 return true; |
| 1131 } | 1117 } |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1751 } | 1737 } |
| 1752 } | 1738 } |
| 1753 } | 1739 } |
| 1754 | 1740 |
| 1755 void MediaStreamManager::SetGenerateStreamCallbackForTesting( | 1741 void MediaStreamManager::SetGenerateStreamCallbackForTesting( |
| 1756 GenerateStreamTestCallback test_callback) { | 1742 GenerateStreamTestCallback test_callback) { |
| 1757 generate_stream_test_callback_ = test_callback; | 1743 generate_stream_test_callback_ = test_callback; |
| 1758 } | 1744 } |
| 1759 | 1745 |
| 1760 } // namespace content | 1746 } // namespace content |
| OLD | NEW |