blob: 2010400aa4e8c3b4ec378cfa80f96557fe0dcf9a [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellanderb24317b2016-02-10 07:54:43 -08002 * Copyright 2012 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellanderb24317b2016-02-10 07:54:43 -08004 * 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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00009 */
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +000010
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef API_TEST_FAKECONSTRAINTS_H_
12#define API_TEST_FAKECONSTRAINTS_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000013
14#include <string>
15#include <vector>
16
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "api/mediaconstraintsinterface.h"
18#include "rtc_base/stringencode.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000019
20namespace webrtc {
21
22class 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) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000037 mandatory_.push_back(Constraint(key, rtc::ToString<T>(value)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +000038 }
39
40 template <class T>
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000041 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 }
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000052 mandatory_.push_back(Constraint(key, rtc::ToString<T>(value)));
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000053 }
54
55 template <class T>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000056 void AddOptional(const std::string& key, const T& value) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +000057 optional_.push_back(Constraint(key, rtc::ToString<T>(value)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058 }
59
60 void SetMandatoryMinAspectRatio(double ratio) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000061 SetMandatory(MediaConstraintsInterface::kMinAspectRatio, ratio);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062 }
63
64 void SetMandatoryMinWidth(int width) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000065 SetMandatory(MediaConstraintsInterface::kMinWidth, width);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066 }
67
68 void SetMandatoryMinHeight(int height) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000069 SetMandatory(MediaConstraintsInterface::kMinHeight, height);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000070 }
71
72 void SetOptionalMaxWidth(int width) {
73 AddOptional(MediaConstraintsInterface::kMaxWidth, width);
74 }
75
76 void SetMandatoryMaxFrameRate(int frame_rate) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000077 SetMandatory(MediaConstraintsInterface::kMaxFrameRate, frame_rate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078 }
79
80 void SetMandatoryReceiveAudio(bool enable) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000081 SetMandatory(MediaConstraintsInterface::kOfferToReceiveAudio, enable);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000082 }
83
84 void SetMandatoryReceiveVideo(bool enable) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000085 SetMandatory(MediaConstraintsInterface::kOfferToReceiveVideo, enable);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000086 }
87
88 void SetMandatoryUseRtpMux(bool enable) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000089 SetMandatory(MediaConstraintsInterface::kUseRtpMux, enable);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090 }
91
92 void SetMandatoryIceRestart(bool enable) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000093 SetMandatory(MediaConstraintsInterface::kIceRestart, enable);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094 }
95
96 void SetAllowRtpDataChannels() {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000097 SetMandatory(MediaConstraintsInterface::kEnableRtpDataChannels, true);
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +000098 SetMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099 }
100
101 void SetOptionalVAD(bool enable) {
102 AddOptional(MediaConstraintsInterface::kVoiceActivityDetection, enable);
103 }
104
105 void SetAllowDtlsSctpDataChannels() {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000106 SetMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107 }
108
109 private:
110 Constraints mandatory_;
111 Constraints optional_;
112};
113
114} // namespace webrtc
115
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200116#endif // API_TEST_FAKECONSTRAINTS_H_