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

Side by Side Diff: webrtc/api/test/fakeconstraints.h

Issue 2514883002: Create //webrtc/api:libjingle_peerconnection_api + refactorings. (Closed)
Patch Set: Rebase Created 4 years 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
1 /* 1 /*
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_API_TEST_FAKECONSTRAINTS_H_ 11 #ifndef WEBRTC_API_TEST_FAKECONSTRAINTS_H_
12 #define WEBRTC_API_TEST_FAKECONSTRAINTS_H_ 12 #define WEBRTC_API_TEST_FAKECONSTRAINTS_H_
13 13
14 #include <string> 14 // Including this file is deprecated. It is no longer part of the public API.
15 #include <vector> 15 // This only includes the file in its new location for backwards compatibility.
16 16 #include "webrtc/pc/test/fakeconstraints.h"
17 #include "webrtc/api/mediaconstraintsinterface.h"
18 #include "webrtc/base/stringencode.h"
19
20 namespace webrtc {
21
22 class FakeConstraints : public webrtc::MediaConstraintsInterface {
23 public:
24 FakeConstraints() { }
25 virtual ~FakeConstraints() { }
26
27 virtual const Constraints& GetMandatory() const {
28 return mandatory_;
29 }
30
31 virtual const Constraints& GetOptional() const {
32 return optional_;
33 }
34
35 template <class T>
36 void AddMandatory(const std::string& key, const T& value) {
37 mandatory_.push_back(Constraint(key, rtc::ToString<T>(value)));
38 }
39
40 template <class T>
41 void SetMandatory(const std::string& key, const T& value) {
42 std::string value_str;
43 if (mandatory_.FindFirst(key, &value_str)) {
44 for (Constraints::iterator iter = mandatory_.begin();
45 iter != mandatory_.end(); ++iter) {
46 if (iter->key == key) {
47 mandatory_.erase(iter);
48 break;
49 }
50 }
51 }
52 mandatory_.push_back(Constraint(key, rtc::ToString<T>(value)));
53 }
54
55 template <class T>
56 void AddOptional(const std::string& key, const T& value) {
57 optional_.push_back(Constraint(key, rtc::ToString<T>(value)));
58 }
59
60 void SetMandatoryMinAspectRatio(double ratio) {
61 SetMandatory(MediaConstraintsInterface::kMinAspectRatio, ratio);
62 }
63
64 void SetMandatoryMinWidth(int width) {
65 SetMandatory(MediaConstraintsInterface::kMinWidth, width);
66 }
67
68 void SetMandatoryMinHeight(int height) {
69 SetMandatory(MediaConstraintsInterface::kMinHeight, height);
70 }
71
72 void SetOptionalMaxWidth(int width) {
73 AddOptional(MediaConstraintsInterface::kMaxWidth, width);
74 }
75
76 void SetMandatoryMaxFrameRate(int frame_rate) {
77 SetMandatory(MediaConstraintsInterface::kMaxFrameRate, frame_rate);
78 }
79
80 void SetMandatoryReceiveAudio(bool enable) {
81 SetMandatory(MediaConstraintsInterface::kOfferToReceiveAudio, enable);
82 }
83
84 void SetMandatoryReceiveVideo(bool enable) {
85 SetMandatory(MediaConstraintsInterface::kOfferToReceiveVideo, enable);
86 }
87
88 void SetMandatoryUseRtpMux(bool enable) {
89 SetMandatory(MediaConstraintsInterface::kUseRtpMux, enable);
90 }
91
92 void SetMandatoryIceRestart(bool enable) {
93 SetMandatory(MediaConstraintsInterface::kIceRestart, enable);
94 }
95
96 void SetAllowRtpDataChannels() {
97 SetMandatory(MediaConstraintsInterface::kEnableRtpDataChannels, true);
98 SetMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, false);
99 }
100
101 void SetOptionalVAD(bool enable) {
102 AddOptional(MediaConstraintsInterface::kVoiceActivityDetection, enable);
103 }
104
105 void SetAllowDtlsSctpDataChannels() {
106 SetMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, true);
107 }
108
109 private:
110 Constraints mandatory_;
111 Constraints optional_;
112 };
113
114 } // namespace webrtc
115 17
116 #endif // WEBRTC_API_TEST_FAKECONSTRAINTS_H_ 18 #endif // WEBRTC_API_TEST_FAKECONSTRAINTS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698