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 3 // found in the LICENSE file. 4 #include "content/renderer/media/rtc_media_constraints.h" 5 6 #include "base/logging.h" 7 #include "base/strings/string_util.h" 8 #include "content/common/media/media_stream_options.h" 9 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" 10 #include "third_party/WebKit/public/platform/WebCString.h" 11 #include "third_party/WebKit/public/platform/WebString.h" 12 13 namespace content { 14 namespace { 15 16 void GetNativeMediaConstraints( 17 const WebKit::WebVector<WebKit::WebMediaConstraint>& constraints, 18 webrtc::MediaConstraintsInterface::Constraints* native_constraints) { 19 DCHECK(native_constraints); 20 for (size_t i = 0; i < constraints.size(); ++i) { 21 webrtc::MediaConstraintsInterface::Constraint new_constraint; 22 new_constraint.key = constraints[i].m_name.utf8(); 23 new_constraint.value = constraints[i].m_value.utf8(); 24 25 // Ignore Chrome specific Tab capture constraints. 26 if (new_constraint.key == kMediaStreamSource || 27 new_constraint.key == kMediaStreamSourceId) 28 continue; 29 30 // Ignore internal constraints set by JS. 31 // TODO(jiayl): replace the hard coded string with 32 // webrtc::MediaConstraintsInterface::kInternalConstraintPrefix when 33 // the Libjingle change is rolled. 34 if (StartsWithASCII(new_constraint.key, "internal", true)) 35 continue; 36 37 DVLOG(3) << "MediaStreamConstraints:" << new_constraint.key 38 << " : " << new_constraint.value; 39 native_constraints->push_back(new_constraint); 40 } 41 } 42 43 } // namespace 44 45 RTCMediaConstraints::RTCMediaConstraints( 46 const WebKit::WebMediaConstraints& constraints) { 47 if (constraints.isNull()) 48 return; // Will happen in unit tests. 49 WebKit::WebVector<WebKit::WebMediaConstraint> mandatory; 50 constraints.getMandatoryConstraints(mandatory); 51 GetNativeMediaConstraints(mandatory, &mandatory_); 52 WebKit::WebVector<WebKit::WebMediaConstraint> optional; 53 constraints.getOptionalConstraints(optional); 54 GetNativeMediaConstraints(optional, &optional_); 55 } 56 57 RTCMediaConstraints::~RTCMediaConstraints() {} 58 59 const webrtc::MediaConstraintsInterface::Constraints& 60 RTCMediaConstraints::GetMandatory() const { 61 return mandatory_; 62 } 63 64 const webrtc::MediaConstraintsInterface::Constraints& 65 RTCMediaConstraints::GetOptional() const { 66 return optional_; 67 } 68 69 void RTCMediaConstraints::AddOptional(const std::string& key, 70 const std::string& value) { 71 optional_.push_back(Constraint(key, value)); 72 } 73 74 } // namespace content 75