Chromium Code Reviews| Index: content/renderer/media/user_media_client_impl.cc |
| diff --git a/content/renderer/media/user_media_client_impl.cc b/content/renderer/media/user_media_client_impl.cc |
| index 204e631a90d1ae58ae047178755b3abc4b73136b..35dd5fb84cf7e7cd917ffaa631c9a74b391ff2e0 100644 |
| --- a/content/renderer/media/user_media_client_impl.cc |
| +++ b/content/renderer/media/user_media_client_impl.cc |
| @@ -7,6 +7,7 @@ |
| #include <stddef.h> |
| #include <utility> |
| +#include <vector> |
| #include "base/hash.h" |
| #include "base/location.h" |
| @@ -39,80 +40,58 @@ |
| namespace content { |
| namespace { |
| -bool GetMandatory(const blink::WebMediaConstraints& constraints, |
| - const std::string& name, |
| - std::string* value) { |
| - if (constraints.isNull()) |
| - return false; |
| - blink::WebString temp; |
| - bool found = |
| - constraints.getMandatoryConstraintValue(base::UTF8ToUTF16(name), temp); |
| - if (found) |
| - *value = temp.utf8(); |
| - return found; |
| -} |
| - |
| -void GetMandatoryList(const blink::WebMediaConstraints& constraints, |
| - const std::string& name, |
| - std::vector<std::string>* values) { |
| - if (constraints.isNull()) { |
| - return; |
| - } |
| - blink::WebString temp; |
| - bool found = |
| - constraints.getMandatoryConstraintValue(base::UTF8ToUTF16(name), temp); |
| - if (found) { |
| - values->push_back(temp.utf8()); |
| +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.
|
| + std::vector<std::string>* destination) { |
| + for (const auto& web_string : source) { |
| + destination->push_back(web_string.utf8()); |
| } |
| } |
| -void GetOptionalList(const blink::WebMediaConstraints constraints, |
| - const std::string& name, |
| - std::vector<std::string>* values) { |
| - if (constraints.isNull()) { |
| - return; |
| - } |
| - blink::WebVector<blink::WebMediaConstraint> constraint_list; |
| - constraints.getOptionalConstraints(constraint_list); |
| - blink::WebString web_name = base::UTF8ToUTF16(name); |
| - for (const auto& pair : constraint_list) { |
| - if (pair.m_name == web_name) { |
| - values->push_back(pair.m_value.utf8()); |
| - } |
| - } |
| +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.
|
| + std::string* destination) { |
| + if (!source.isEmpty()) |
| + *destination = source[0].utf8(); |
| } |
| + |
| void CopyBlinkRequestToStreamControls(const blink::WebUserMediaRequest& request, |
| StreamControls* controls) { |
| if (request.isNull()) { |
| return; |
| } |
| - GetMandatory(request.audioConstraints(), kMediaStreamSource, |
| - &controls->audio.stream_source); |
| - GetMandatory(request.videoConstraints(), kMediaStreamSource, |
| - &controls->video.stream_source); |
| - GetMandatoryList(request.audioConstraints(), kMediaStreamSourceInfoId, |
| - &controls->audio.device_ids); |
| - GetMandatoryList(request.videoConstraints(), kMediaStreamSourceInfoId, |
| - &controls->video.device_ids); |
| - GetOptionalList(request.audioConstraints(), kMediaStreamSourceInfoId, |
| - &controls->audio.alternate_device_ids); |
| - GetOptionalList(request.videoConstraints(), kMediaStreamSourceInfoId, |
| - &controls->video.alternate_device_ids); |
| - GetMandatoryList(request.audioConstraints(), kMediaStreamSourceId, |
| - &controls->audio.device_ids); |
| - GetMandatoryList(request.videoConstraints(), kMediaStreamSourceId, |
| - &controls->video.device_ids); |
| - std::string hotword_string; |
| - GetMandatory(request.audioConstraints(), kMediaStreamAudioHotword, |
| - &hotword_string); |
| - if (hotword_string == "true") |
| - controls->hotword_enabled = true; |
| - // DCHECK for some combinations that seem to be unusual/useless |
| - // It should not be possible to have both MediaStreamSourceId |
| - // and MediaStreamSourceInfoId on the same request. |
| - DCHECK(controls->video.device_ids.size() <= 1); |
| - DCHECK(controls->audio.device_ids.size() <= 1); |
| + if (!request.audioConstraints().isNull()) { |
| + 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.
|
| + const blink::WebMediaTrackConstraintSet& audio_basic = |
| + request.audioConstraints().basic(); |
| + CopyFirstString(audio_basic.mediaStreamSource.exact(), |
| + &(controls->audio.stream_source)); |
| + DLOG(WARNING) << "Size of audio device ID list:" |
| + << audio_basic.deviceId.exact().size(); |
| + CopyVector(audio_basic.deviceId.exact(), &(controls->audio.device_ids)); |
| + // Optionals. They may be either in ideal or in advanced.exact. |
| + // 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
|
| + CopyVector(audio_basic.deviceId.ideal(), |
| + &(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.
|
| + 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
|
| + controls->hotword_enabled = true; |
| + } |
| + if (!request.videoConstraints().isNull()) { |
| + const blink::WebMediaTrackConstraintSet& video_basic = |
| + request.videoConstraints().basic(); |
| + CopyFirstString(video_basic.mediaStreamSource.exact(), |
| + &(controls->video.stream_source)); |
| + CopyVector(video_basic.deviceId.exact(), &(controls->video.device_ids)); |
| + CopyVector(video_basic.deviceId.ideal(), |
| + &(controls->video.alternate_device_ids)); |
| + } |
| + 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.
|
| + DLOG(WARNING) << "Video device id = " << controls->video.device_ids[0]; |
| + else |
| + DLOG(WARNING) << "No video device id"; |
| + if (controls->audio.device_ids.size() > 0) |
| + DLOG(WARNING) << "Audio device id = " << controls->audio.device_ids[0]; |
| + else |
| + DLOG(WARNING) << "No audio device id"; |
| } |
| static int g_next_request_id = 0; |
| @@ -211,10 +190,8 @@ void UserMediaClientImpl::requestUserMedia( |
| controls.audio.requested = true; |
| // Check if this input device should be used to select a matching output |
| // device for audio rendering. |
| - std::string enable; |
| - if (GetMandatory(user_media_request.audioConstraints(), |
| - kMediaStreamRenderToAssociatedSink, &enable) && |
| - base::LowerCaseEqualsASCII(enable, "true")) { |
| + if (!user_media_request.audioConstraints().basic() |
| + .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
|
| enable_automatic_output_device_selection = true; |
| } |
| } |