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, |
tommi (sloooow) - chröme
2016/01/14 15:31:27
const &?
hta - Chromium
2016/01/17 12:41:41
Done.
| |
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, |
tommi (sloooow) - chröme
2016/01/14 15:31:27
const &
hta - Chromium
2016/01/17 12:41:40
Done.
| |
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 |
56 | |
85 void CopyBlinkRequestToStreamControls(const blink::WebUserMediaRequest& request, | 57 void CopyBlinkRequestToStreamControls(const blink::WebUserMediaRequest& request, |
86 StreamControls* controls) { | 58 StreamControls* controls) { |
87 if (request.isNull()) { | 59 if (request.isNull()) { |
88 return; | 60 return; |
89 } | 61 } |
90 GetMandatory(request.audioConstraints(), kMediaStreamSource, | 62 if (!request.audioConstraints().isNull()) { |
91 &controls->audio.stream_source); | 63 DLOG(WARNING) << "Copying audio constraints"; |
tommi (sloooow) - chröme
2016/01/14 15:31:27
clean up? (and below)
hta - Chromium
2016/01/17 12:41:41
Done.
| |
92 GetMandatory(request.videoConstraints(), kMediaStreamSource, | 64 const blink::WebMediaTrackConstraintSet& audio_basic = |
93 &controls->video.stream_source); | 65 request.audioConstraints().basic(); |
94 GetMandatoryList(request.audioConstraints(), kMediaStreamSourceInfoId, | 66 CopyFirstString(audio_basic.mediaStreamSource.exact(), |
95 &controls->audio.device_ids); | 67 &(controls->audio.stream_source)); |
96 GetMandatoryList(request.videoConstraints(), kMediaStreamSourceInfoId, | 68 DLOG(WARNING) << "Size of audio device ID list:" |
97 &controls->video.device_ids); | 69 << audio_basic.deviceId.exact().size(); |
98 GetOptionalList(request.audioConstraints(), kMediaStreamSourceInfoId, | 70 CopyVector(audio_basic.deviceId.exact(), &(controls->audio.device_ids)); |
99 &controls->audio.alternate_device_ids); | 71 // Optionals. They may be either in ideal or in advanced.exact. |
100 GetOptionalList(request.videoConstraints(), kMediaStreamSourceInfoId, | 72 // TODO: Get alternatives only mentioned in advanced array. |
tommi (sloooow) - chröme
2016/01/14 15:31:27
assign todo to someone (did git cl presubmit compl
| |
101 &controls->video.alternate_device_ids); | 73 CopyVector(audio_basic.deviceId.ideal(), |
102 GetMandatoryList(request.audioConstraints(), kMediaStreamSourceId, | 74 &(controls->audio.alternate_device_ids)); |
tommi (sloooow) - chröme
2016/01/14 15:31:27
nit: no need for ()
hta - Chromium
2016/01/17 12:41:41
Done.
| |
103 &controls->audio.device_ids); | 75 if (!audio_basic.hotwordEnabled.matches(false)) |
tommi (sloooow) - chröme
2016/01/14 15:31:27
if not matches false... is that right?
tommi (sloooow) - chröme
2016/01/15 15:05:47
ah, nevermind, makes sense now. To make sure hotw
hta - Chromium
2016/01/17 12:41:41
It seemed the simplest way to say "if I'm allowed
| |
104 GetMandatoryList(request.videoConstraints(), kMediaStreamSourceId, | 76 controls->hotword_enabled = true; |
105 &controls->video.device_ids); | 77 } |
106 std::string hotword_string; | 78 if (!request.videoConstraints().isNull()) { |
107 GetMandatory(request.audioConstraints(), kMediaStreamAudioHotword, | 79 const blink::WebMediaTrackConstraintSet& video_basic = |
108 &hotword_string); | 80 request.videoConstraints().basic(); |
109 if (hotword_string == "true") | 81 CopyFirstString(video_basic.mediaStreamSource.exact(), |
110 controls->hotword_enabled = true; | 82 &(controls->video.stream_source)); |
111 // DCHECK for some combinations that seem to be unusual/useless | 83 CopyVector(video_basic.deviceId.exact(), &(controls->video.device_ids)); |
112 // It should not be possible to have both MediaStreamSourceId | 84 CopyVector(video_basic.deviceId.ideal(), |
113 // and MediaStreamSourceInfoId on the same request. | 85 &(controls->video.alternate_device_ids)); |
114 DCHECK(controls->video.device_ids.size() <= 1); | 86 } |
115 DCHECK(controls->audio.device_ids.size() <= 1); | 87 if (controls->video.device_ids.size() > 0) |
tommi (sloooow) - chröme
2016/01/14 15:31:27
I guess you'll clean these up too?
hta - Chromium
2016/01/17 12:41:41
Done.
| |
88 DLOG(WARNING) << "Video device id = " << controls->video.device_ids[0]; | |
89 else | |
90 DLOG(WARNING) << "No video device id"; | |
91 if (controls->audio.device_ids.size() > 0) | |
92 DLOG(WARNING) << "Audio device id = " << controls->audio.device_ids[0]; | |
93 else | |
94 DLOG(WARNING) << "No audio device id"; | |
116 } | 95 } |
117 | 96 |
118 static int g_next_request_id = 0; | 97 static int g_next_request_id = 0; |
119 | 98 |
120 } // namespace | 99 } // namespace |
121 | 100 |
122 struct UserMediaClientImpl::MediaDevicesRequestInfo { | 101 struct UserMediaClientImpl::MediaDevicesRequestInfo { |
123 MediaDevicesRequestInfo(const blink::WebMediaDevicesRequest& request, | 102 MediaDevicesRequestInfo(const blink::WebMediaDevicesRequest& request, |
124 int audio_input_request_id, | 103 int audio_input_request_id, |
125 int video_input_request_id, | 104 int video_input_request_id, |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
204 // if it isNull. | 183 // if it isNull. |
205 if (user_media_request.isNull()) { | 184 if (user_media_request.isNull()) { |
206 // We are in a test. | 185 // We are in a test. |
207 controls.audio.requested = true; | 186 controls.audio.requested = true; |
208 controls.video.requested = true; | 187 controls.video.requested = true; |
209 } else { | 188 } else { |
210 if (user_media_request.audio()) { | 189 if (user_media_request.audio()) { |
211 controls.audio.requested = true; | 190 controls.audio.requested = true; |
212 // Check if this input device should be used to select a matching output | 191 // Check if this input device should be used to select a matching output |
213 // device for audio rendering. | 192 // device for audio rendering. |
214 std::string enable; | 193 if (!user_media_request.audioConstraints().basic() |
215 if (GetMandatory(user_media_request.audioConstraints(), | 194 .renderToAssociatedSink.matches(false)) { |
tommi (sloooow) - chröme
2016/01/14 15:31:27
indent 4 spaces.... actually, I'd be curious to se
hta - Chromium
2016/01/17 12:41:41
It said
+ if (!user_media_request.audioConst
| |
216 kMediaStreamRenderToAssociatedSink, &enable) && | |
217 base::LowerCaseEqualsASCII(enable, "true")) { | |
218 enable_automatic_output_device_selection = true; | 195 enable_automatic_output_device_selection = true; |
219 } | 196 } |
220 } | 197 } |
221 if (user_media_request.video()) { | 198 if (user_media_request.video()) { |
222 controls.video.requested = true; | 199 controls.video.requested = true; |
223 } | 200 } |
224 CopyBlinkRequestToStreamControls(user_media_request, &controls); | 201 CopyBlinkRequestToStreamControls(user_media_request, &controls); |
225 | 202 |
226 security_origin = GURL(user_media_request.securityOrigin().toString()); | 203 security_origin = GURL(user_media_request.securityOrigin().toString()); |
227 DCHECK(render_frame()->GetWebFrame() == | 204 DCHECK(render_frame()->GetWebFrame() == |
(...skipping 935 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1163 return; | 1140 return; |
1164 } | 1141 } |
1165 } | 1142 } |
1166 } | 1143 } |
1167 | 1144 |
1168 bool UserMediaClientImpl::UserMediaRequestInfo::HasPendingSources() const { | 1145 bool UserMediaClientImpl::UserMediaRequestInfo::HasPendingSources() const { |
1169 return !sources_waiting_for_callback_.empty(); | 1146 return !sources_waiting_for_callback_.empty(); |
1170 } | 1147 } |
1171 | 1148 |
1172 } // namespace content | 1149 } // namespace content |
OLD | NEW |