blob: d9c767de3350a362f311c6195df5fa8632aaf992 [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:
Yves Gerey665174f2018-06-19 15:03:05 +020024 FakeConstraints() {}
25 virtual ~FakeConstraints() {}
henrike@webrtc.org28e20752013-07-10 00:45:36 +000026
Yves Gerey665174f2018-06-19 15:03:05 +020027 virtual const Constraints& GetMandatory() const { return mandatory_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000028
Yves Gerey665174f2018-06-19 15:03:05 +020029 virtual const Constraints& GetOptional() const { return optional_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +000030
31 template <class T>
32 void AddMandatory(const std::string& key, const T& value) {
Jonas Olsson6b1985d2018-07-05 11:59:48 +020033 mandatory_.push_back(Constraint(key, rtc::ToString(value)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +000034 }
35
36 template <class T>
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000037 void SetMandatory(const std::string& key, const T& value) {
38 std::string value_str;
39 if (mandatory_.FindFirst(key, &value_str)) {
40 for (Constraints::iterator iter = mandatory_.begin();
41 iter != mandatory_.end(); ++iter) {
42 if (iter->key == key) {
43 mandatory_.erase(iter);
44 break;
45 }
46 }
47 }
Jonas Olsson6b1985d2018-07-05 11:59:48 +020048 mandatory_.push_back(Constraint(key, rtc::ToString(value)));
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000049 }
50
51 template <class T>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000052 void AddOptional(const std::string& key, const T& value) {
Jonas Olsson6b1985d2018-07-05 11:59:48 +020053 optional_.push_back(Constraint(key, rtc::ToString(value)));
henrike@webrtc.org28e20752013-07-10 00:45:36 +000054 }
55
56 void SetMandatoryMinAspectRatio(double ratio) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000057 SetMandatory(MediaConstraintsInterface::kMinAspectRatio, ratio);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000058 }
59
60 void SetMandatoryMinWidth(int width) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000061 SetMandatory(MediaConstraintsInterface::kMinWidth, width);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000062 }
63
64 void SetMandatoryMinHeight(int height) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000065 SetMandatory(MediaConstraintsInterface::kMinHeight, height);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000066 }
67
68 void SetOptionalMaxWidth(int width) {
69 AddOptional(MediaConstraintsInterface::kMaxWidth, width);
70 }
71
72 void SetMandatoryMaxFrameRate(int frame_rate) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000073 SetMandatory(MediaConstraintsInterface::kMaxFrameRate, frame_rate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000074 }
75
76 void SetMandatoryReceiveAudio(bool enable) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000077 SetMandatory(MediaConstraintsInterface::kOfferToReceiveAudio, enable);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000078 }
79
80 void SetMandatoryReceiveVideo(bool enable) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000081 SetMandatory(MediaConstraintsInterface::kOfferToReceiveVideo, enable);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000082 }
83
84 void SetMandatoryUseRtpMux(bool enable) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000085 SetMandatory(MediaConstraintsInterface::kUseRtpMux, enable);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000086 }
87
88 void SetMandatoryIceRestart(bool enable) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000089 SetMandatory(MediaConstraintsInterface::kIceRestart, enable);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090 }
91
92 void SetAllowRtpDataChannels() {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000093 SetMandatory(MediaConstraintsInterface::kEnableRtpDataChannels, true);
jiayl@webrtc.org61e00b02015-03-04 22:17:38 +000094 SetMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, false);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095 }
96
97 void SetOptionalVAD(bool enable) {
98 AddOptional(MediaConstraintsInterface::kVoiceActivityDetection, enable);
99 }
100
101 void SetAllowDtlsSctpDataChannels() {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000102 SetMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103 }
104
105 private:
106 Constraints mandatory_;
107 Constraints optional_;
108};
109
110} // namespace webrtc
111
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200112#endif // API_TEST_FAKECONSTRAINTS_H_