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/user_media_client_impl.h" | 5 #include "content/renderer/media/user_media_client_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <utility> | 9 #include <utility> |
10 #include <vector> | |
10 | 11 |
11 #include "base/hash.h" | 12 #include "base/hash.h" |
12 #include "base/location.h" | 13 #include "base/location.h" |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
14 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
15 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
16 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
17 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
18 #include "base/strings/utf_string_conversions.h" | 19 #include "base/strings/utf_string_conversions.h" |
19 #include "base/thread_task_runner_handle.h" | 20 #include "base/thread_task_runner_handle.h" |
(...skipping 12 matching lines...) Expand all Loading... | |
32 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 33 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
33 #include "third_party/WebKit/public/platform/WebMediaDeviceInfo.h" | 34 #include "third_party/WebKit/public/platform/WebMediaDeviceInfo.h" |
34 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" | 35 #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" |
35 #include "third_party/WebKit/public/platform/WebMediaStreamTrackSourcesRequest.h " | 36 #include "third_party/WebKit/public/platform/WebMediaStreamTrackSourcesRequest.h " |
36 #include "third_party/WebKit/public/web/WebDocument.h" | 37 #include "third_party/WebKit/public/web/WebDocument.h" |
37 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 38 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
38 | 39 |
39 namespace content { | 40 namespace content { |
40 namespace { | 41 namespace { |
41 | 42 |
42 bool GetMandatory(const blink::WebMediaConstraints& constraints, | 43 void CopyVector(const blink::WebVector<blink::WebString>& source, |
43 const std::string& name, | 44 std::vector<std::string>* destination) { |
44 std::string* value) { | 45 for (const auto& web_string : source) { |
45 if (constraints.isNull()) | 46 destination->push_back(web_string.utf8()); |
46 return false; | |
47 blink::WebString temp; | |
48 bool found = | |
49 constraints.getMandatoryConstraintValue(base::UTF8ToUTF16(name), temp); | |
50 if (found) | |
51 *value = temp.utf8(); | |
52 return found; | |
53 } | |
54 | |
55 void GetMandatoryList(const blink::WebMediaConstraints& constraints, | |
56 const std::string& name, | |
57 std::vector<std::string>* values) { | |
58 if (constraints.isNull()) { | |
59 return; | |
60 } | |
61 blink::WebString temp; | |
62 bool found = | |
63 constraints.getMandatoryConstraintValue(base::UTF8ToUTF16(name), temp); | |
64 if (found) { | |
65 values->push_back(temp.utf8()); | |
66 } | 47 } |
67 } | 48 } |
68 | 49 |
69 void GetOptionalList(const blink::WebMediaConstraints constraints, | 50 void CopyFirstString(const blink::WebVector<blink::WebString>& source, |
70 const std::string& name, | 51 std::string* destination) { |
71 std::vector<std::string>* values) { | 52 if (!source.isEmpty()) |
72 if (constraints.isNull()) { | 53 *destination = source[0].utf8(); |
73 return; | |
74 } | |
75 blink::WebVector<blink::WebMediaConstraint> constraint_list; | |
76 constraints.getOptionalConstraints(constraint_list); | |
77 blink::WebString web_name = base::UTF8ToUTF16(name); | |
78 for (const auto& pair : constraint_list) { | |
79 if (pair.m_name == web_name) { | |
80 values->push_back(pair.m_value.utf8()); | |
81 } | |
82 } | |
83 } | 54 } |
84 | 55 |
85 void CopyBlinkRequestToStreamControls(const blink::WebUserMediaRequest& request, | 56 void CopyBlinkRequestToStreamControls(const blink::WebUserMediaRequest& request, |
86 StreamControls* controls) { | 57 StreamControls* controls) { |
87 if (request.isNull()) { | 58 if (request.isNull()) { |
88 return; | 59 return; |
89 } | 60 } |
90 GetMandatory(request.audioConstraints(), kMediaStreamSource, | 61 if (!request.audioConstraints().isNull()) { |
91 &controls->audio.stream_source); | 62 const blink::WebMediaTrackConstraintSet& audio_basic = |
92 GetMandatory(request.videoConstraints(), kMediaStreamSource, | 63 request.audioConstraints().basic(); |
93 &controls->video.stream_source); | 64 CopyFirstString(audio_basic.mediaStreamSource.exact(), |
94 GetMandatoryList(request.audioConstraints(), kMediaStreamSourceInfoId, | 65 &(controls->audio.stream_source)); |
tommi (sloooow) - chröme
2016/01/15 15:05:47
nit: skip the extra parenthesis (like in line 70)
| |
95 &controls->audio.device_ids); | 66 CopyVector(audio_basic.deviceId.exact(), &(controls->audio.device_ids)); |
tommi (sloooow) - chröme
2016/01/15 15:05:47
and here
| |
96 GetMandatoryList(request.videoConstraints(), kMediaStreamSourceInfoId, | 67 // Optionals. They may be either in ideal or in advanced.exact. |
97 &controls->video.device_ids); | 68 // TODO(hta): Get alternatives only mentioned in advanced array. |
98 GetOptionalList(request.audioConstraints(), kMediaStreamSourceInfoId, | 69 CopyVector(audio_basic.deviceId.ideal(), |
99 &controls->audio.alternate_device_ids); | 70 &controls->audio.alternate_device_ids); |
100 GetOptionalList(request.videoConstraints(), kMediaStreamSourceInfoId, | 71 if (!audio_basic.hotwordEnabled.matches(false)) |
101 &controls->video.alternate_device_ids); | 72 controls->hotword_enabled = true; |
102 GetMandatoryList(request.audioConstraints(), kMediaStreamSourceId, | 73 } |
103 &controls->audio.device_ids); | 74 if (!request.videoConstraints().isNull()) { |
104 GetMandatoryList(request.videoConstraints(), kMediaStreamSourceId, | 75 const blink::WebMediaTrackConstraintSet& video_basic = |
105 &controls->video.device_ids); | 76 request.videoConstraints().basic(); |
106 std::string hotword_string; | 77 CopyFirstString(video_basic.mediaStreamSource.exact(), |
107 GetMandatory(request.audioConstraints(), kMediaStreamAudioHotword, | 78 &(controls->video.stream_source)); |
108 &hotword_string); | 79 CopyVector(video_basic.deviceId.exact(), &(controls->video.device_ids)); |
109 if (hotword_string == "true") | 80 CopyVector(video_basic.deviceId.ideal(), |
110 controls->hotword_enabled = true; | 81 &(controls->video.alternate_device_ids)); |
111 // DCHECK for some combinations that seem to be unusual/useless | 82 } |
112 // It should not be possible to have both MediaStreamSourceId | |
113 // and MediaStreamSourceInfoId on the same request. | |
114 DCHECK(controls->video.device_ids.size() <= 1); | |
115 DCHECK(controls->audio.device_ids.size() <= 1); | |
116 } | 83 } |
117 | 84 |
118 static int g_next_request_id = 0; | 85 static int g_next_request_id = 0; |
119 | 86 |
120 } // namespace | 87 } // namespace |
121 | 88 |
122 struct UserMediaClientImpl::MediaDevicesRequestInfo { | 89 struct UserMediaClientImpl::MediaDevicesRequestInfo { |
123 MediaDevicesRequestInfo(const blink::WebMediaDevicesRequest& request, | 90 MediaDevicesRequestInfo(const blink::WebMediaDevicesRequest& request, |
124 int audio_input_request_id, | 91 int audio_input_request_id, |
125 int video_input_request_id, | 92 int video_input_request_id, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 // if it isNull. | 171 // if it isNull. |
205 if (user_media_request.isNull()) { | 172 if (user_media_request.isNull()) { |
206 // We are in a test. | 173 // We are in a test. |
207 controls.audio.requested = true; | 174 controls.audio.requested = true; |
208 controls.video.requested = true; | 175 controls.video.requested = true; |
209 } else { | 176 } else { |
210 if (user_media_request.audio()) { | 177 if (user_media_request.audio()) { |
211 controls.audio.requested = true; | 178 controls.audio.requested = true; |
212 // Check if this input device should be used to select a matching output | 179 // Check if this input device should be used to select a matching output |
213 // device for audio rendering. | 180 // device for audio rendering. |
214 std::string enable; | 181 if (!user_media_request.audioConstraints() |
215 if (GetMandatory(user_media_request.audioConstraints(), | 182 .basic() |
216 kMediaStreamRenderToAssociatedSink, &enable) && | 183 .renderToAssociatedSink.matches(false)) { |
217 base::LowerCaseEqualsASCII(enable, "true")) { | |
218 enable_automatic_output_device_selection = true; | 184 enable_automatic_output_device_selection = true; |
219 } | 185 } |
220 } | 186 } |
221 if (user_media_request.video()) { | 187 if (user_media_request.video()) { |
222 controls.video.requested = true; | 188 controls.video.requested = true; |
223 } | 189 } |
224 CopyBlinkRequestToStreamControls(user_media_request, &controls); | 190 CopyBlinkRequestToStreamControls(user_media_request, &controls); |
225 | 191 |
226 security_origin = GURL(user_media_request.securityOrigin().toString()); | 192 security_origin = GURL(user_media_request.securityOrigin().toString()); |
227 DCHECK(render_frame()->GetWebFrame() == | 193 DCHECK(render_frame()->GetWebFrame() == |
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1163 return; | 1129 return; |
1164 } | 1130 } |
1165 } | 1131 } |
1166 } | 1132 } |
1167 | 1133 |
1168 bool UserMediaClientImpl::UserMediaRequestInfo::HasPendingSources() const { | 1134 bool UserMediaClientImpl::UserMediaRequestInfo::HasPendingSources() const { |
1169 return !sources_waiting_for_callback_.empty(); | 1135 return !sources_waiting_for_callback_.empty(); |
1170 } | 1136 } |
1171 | 1137 |
1172 } // namespace content | 1138 } // namespace content |
OLD | NEW |