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"
8 #include "base/logging.h"
9 #include "base/strings/string_util.h"
10 #include "content/common/media/media_stream_options.h"
11 #include "third_party/WebKit/public/platform/WebMediaConstraints.h"
12 #include "third_party/WebKit/public/platform/WebCString.h"
13 #include "third_party/WebKit/public/platform/WebString.h"
18 void GetNativeMediaConstraints(
19 const blink::WebVector<blink::WebMediaConstraint>& constraints,
20 webrtc::MediaConstraintsInterface::Constraints* native_constraints) {
21 DCHECK(native_constraints);
22 for (size_t i = 0; i < constraints.size(); ++i) {
23 webrtc::MediaConstraintsInterface::Constraint new_constraint;
24 new_constraint.key = constraints[i].m_name.utf8();
25 new_constraint.value = constraints[i].m_value.utf8();
27 // Ignore Chrome specific Tab capture constraints.
28 if (new_constraint.key == kMediaStreamSource ||
29 new_constraint.key == kMediaStreamSourceId)
32 // Ignore sourceId constraint since that has nothing to do with webrtc.
33 if (new_constraint.key == kMediaStreamSourceInfoId)
36 DVLOG(3) << "MediaStreamConstraints:" << new_constraint.key
37 << " : " << new_constraint.value;
38 native_constraints->push_back(new_constraint);
44 RTCMediaConstraints::RTCMediaConstraints() {}
46 RTCMediaConstraints::RTCMediaConstraints(
47 const blink::WebMediaConstraints& constraints) {
48 if (constraints.isNull())
49 return; // Will happen in unit tests.
50 blink::WebVector<blink::WebMediaConstraint> mandatory;
51 constraints.getMandatoryConstraints(mandatory);
52 GetNativeMediaConstraints(mandatory, &mandatory_);
53 blink::WebVector<blink::WebMediaConstraint> optional;
54 constraints.getOptionalConstraints(optional);
55 GetNativeMediaConstraints(optional, &optional_);
58 RTCMediaConstraints::~RTCMediaConstraints() {}
60 const webrtc::MediaConstraintsInterface::Constraints&
61 RTCMediaConstraints::GetMandatory() const {
65 const webrtc::MediaConstraintsInterface::Constraints&
66 RTCMediaConstraints::GetOptional() const {
70 void RTCMediaConstraints::AddOptional(const std::string& key,
71 const std::string& value) {
72 optional_.push_back(Constraint(key, value));
75 bool RTCMediaConstraints::AddMandatory(const std::string& key,
76 const std::string& value,
77 bool override_if_exists) {
78 for (Constraints::iterator iter = mandatory_.begin();
79 iter != mandatory_.end();
81 if (iter->key == key) {
82 if (override_if_exists)
84 return override_if_exists;
87 // The key wasn't found, add it.
88 mandatory_.push_back(Constraint(key, value));
92 } // namespace content