Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(508)

Side by Side Diff: content/renderer/media/rtc_media_constraints.cc

Issue 1729683002: Remove old-style constraints from Chrome internals (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Complete the interface change Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 <stddef.h>
7
8 #include <string>
9
10 #include "base/logging.h"
11 #include "base/strings/string_util.h"
12 #include "content/common/media/media_stream_options.h"
13 #include "content/renderer/media/media_stream_video_source.h"
14 #include "third_party/WebKit/public/platform/WebCString.h"
15 #include "third_party/WebKit/public/platform/WebMediaConstraints.h"
16 #include "third_party/WebKit/public/platform/WebString.h"
17
18 namespace content {
19 namespace {
20
21 void GetNativeMediaConstraints(
22 const blink::WebVector<blink::WebMediaConstraint>& constraints,
23 webrtc::MediaConstraintsInterface::Constraints* native_constraints) {
24 DCHECK(native_constraints);
25 for (size_t i = 0; i < constraints.size(); ++i) {
26 webrtc::MediaConstraintsInterface::Constraint new_constraint;
27 new_constraint.key = constraints[i].m_name.utf8();
28 new_constraint.value = constraints[i].m_value.utf8();
29
30 // Ignore Chrome specific Tab capture constraints.
31 if (new_constraint.key == kMediaStreamSource ||
32 new_constraint.key == kMediaStreamSourceId)
33 continue;
34
35 // Ignore sourceId constraint since that has nothing to do with webrtc.
36 if (new_constraint.key == kMediaStreamSourceInfoId)
37 continue;
38
39 // Ignore constraints that are handled by Chrome in MediaStreamVideoSource.
40 if (MediaStreamVideoSource::IsConstraintSupported(new_constraint.key))
41 continue;
42
43 DVLOG(3) << "MediaStreamConstraints:" << new_constraint.key
44 << " : " << new_constraint.value;
45 native_constraints->push_back(new_constraint);
46 }
47 }
48
49 } // namespace
50
51 RTCMediaConstraints::RTCMediaConstraints() {}
52
53 RTCMediaConstraints::RTCMediaConstraints(
54 const blink::WebMediaConstraints& constraints) {
55 if (constraints.isNull())
56 return; // Will happen in unit tests.
57 blink::WebVector<blink::WebMediaConstraint> mandatory;
58 constraints.getMandatoryConstraints(mandatory);
59 GetNativeMediaConstraints(mandatory, &mandatory_);
60 blink::WebVector<blink::WebMediaConstraint> optional;
61 constraints.getOptionalConstraints(optional);
62 GetNativeMediaConstraints(optional, &optional_);
63 }
64
65 RTCMediaConstraints::~RTCMediaConstraints() {}
66
67 const webrtc::MediaConstraintsInterface::Constraints&
68 RTCMediaConstraints::GetMandatory() const {
69 return mandatory_;
70 }
71
72 const webrtc::MediaConstraintsInterface::Constraints&
73 RTCMediaConstraints::GetOptional() const {
74 return optional_;
75 }
76
77 bool RTCMediaConstraints::AddOptional(const std::string& key,
78 const std::string& value,
79 bool override_if_exists) {
80 return AddConstraint(&optional_, key, value, override_if_exists);
81 }
82
83 bool RTCMediaConstraints::AddMandatory(const std::string& key,
84 const std::string& value,
85 bool override_if_exists) {
86 return AddConstraint(&mandatory_, key, value, override_if_exists);
87 }
88
89 bool RTCMediaConstraints::AddConstraint(Constraints* constraints,
90 const std::string& key,
91 const std::string& value,
92 bool override_if_exists) {
93 for (Constraints::iterator iter = constraints->begin();
94 iter != constraints->end();
95 ++iter) {
96 if (iter->key == key) {
97 if (override_if_exists)
98 iter->value = value;
99 return override_if_exists;
100 }
101 }
102 // The key wasn't found, add it.
103 constraints->push_back(Constraint(key, value));
104 return true;
105 }
106
107 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/rtc_media_constraints.h ('k') | content/renderer/media/rtc_peer_connection_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698