blob: 155e5ea3fdc529e46f1e402383086f28ac8f8dd9 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
2 * libjingle
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +00003 * Copyright 2012 Google Inc.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000026 */
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +000027
Henrik Kjellander15583c12016-02-10 10:53:12 +010028#ifndef WEBRTC_API_TEST_FAKECONSTRAINTS_H_
29#define WEBRTC_API_TEST_FAKECONSTRAINTS_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030
31#include <string>
32#include <vector>
33
Henrik Kjellander15583c12016-02-10 10:53:12 +010034#include "webrtc/api/mediaconstraintsinterface.h"
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000035#include "webrtc/base/stringencode.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000036
37namespace webrtc {
38
39class FakeConstraints : public webrtc::MediaConstraintsInterface {
40 public:
41 FakeConstraints() { }
42 virtual ~FakeConstraints() { }
43
44 virtual const Constraints& GetMandatory() const {
45 return mandatory_;
46 }
47
48 virtual const Constraints& GetOptional() const {
49 return optional_;
50 }
51
52 template <class T>
53 void AddMandatory(const std::string& key, const T& value) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000054 mandatory_.push_back(Constraint(key, rtc::ToString<T>(value)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +000055 }
56
57 template <class T>
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000058 void SetMandatory(const std::string& key, const T& value) {
59 std::string value_str;
60 if (mandatory_.FindFirst(key, &value_str)) {
61 for (Constraints::iterator iter = mandatory_.begin();
62 iter != mandatory_.end(); ++iter) {
63 if (iter->key == key) {
64 mandatory_.erase(iter);
65 break;
66 }
67 }
68 }
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000069 mandatory_.push_back(Constraint(key, rtc::ToString<T>(value)));
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000070 }
71
72 template <class T>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073 void AddOptional(const std::string& key, const T& value) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000074 optional_.push_back(Constraint(key, rtc::ToString<T>(value)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +000075 }
76
77 void SetMandatoryMinAspectRatio(double ratio) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000078 SetMandatory(MediaConstraintsInterface::kMinAspectRatio, ratio);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079 }
80
81 void SetMandatoryMinWidth(int width) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000082 SetMandatory(MediaConstraintsInterface::kMinWidth, width);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000083 }
84
85 void SetMandatoryMinHeight(int height) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000086 SetMandatory(MediaConstraintsInterface::kMinHeight, height);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087 }
88
89 void SetOptionalMaxWidth(int width) {
90 AddOptional(MediaConstraintsInterface::kMaxWidth, width);
91 }
92
93 void SetMandatoryMaxFrameRate(int frame_rate) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000094 SetMandatory(MediaConstraintsInterface::kMaxFrameRate, frame_rate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095 }
96
97 void SetMandatoryReceiveAudio(bool enable) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000098 SetMandatory(MediaConstraintsInterface::kOfferToReceiveAudio, enable);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099 }
100
101 void SetMandatoryReceiveVideo(bool enable) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000102 SetMandatory(MediaConstraintsInterface::kOfferToReceiveVideo, enable);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103 }
104
105 void SetMandatoryUseRtpMux(bool enable) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000106 SetMandatory(MediaConstraintsInterface::kUseRtpMux, enable);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107 }
108
109 void SetMandatoryIceRestart(bool enable) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000110 SetMandatory(MediaConstraintsInterface::kIceRestart, enable);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000111 }
112
113 void SetAllowRtpDataChannels() {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000114 SetMandatory(MediaConstraintsInterface::kEnableRtpDataChannels, true);
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +0000115 SetMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000116 }
117
118 void SetOptionalVAD(bool enable) {
119 AddOptional(MediaConstraintsInterface::kVoiceActivityDetection, enable);
120 }
121
122 void SetAllowDtlsSctpDataChannels() {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000123 SetMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000124 }
125
126 private:
127 Constraints mandatory_;
128 Constraints optional_;
129};
130
131} // namespace webrtc
132
Henrik Kjellander15583c12016-02-10 10:53:12 +0100133#endif // WEBRTC_API_TEST_FAKECONSTRAINTS_H_