henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 2 | * Copyright 2012 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | b24317b | 2016-02-10 07:54:43 -0800 | [diff] [blame] | 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 |
| 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef API_TEST_FAKECONSTRAINTS_H_ |
| 12 | #define API_TEST_FAKECONSTRAINTS_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 13 | |
| 14 | #include <string> |
| 15 | #include <vector> |
| 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "api/mediaconstraintsinterface.h" |
| 18 | #include "rtc_base/stringencode.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 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) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 37 | mandatory_.push_back(Constraint(key, rtc::ToString<T>(value))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | template <class T> |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 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 | } |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 52 | mandatory_.push_back(Constraint(key, rtc::ToString<T>(value))); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | template <class T> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 56 | void AddOptional(const std::string& key, const T& value) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 57 | optional_.push_back(Constraint(key, rtc::ToString<T>(value))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | void SetMandatoryMinAspectRatio(double ratio) { |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 61 | SetMandatory(MediaConstraintsInterface::kMinAspectRatio, ratio); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | void SetMandatoryMinWidth(int width) { |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 65 | SetMandatory(MediaConstraintsInterface::kMinWidth, width); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | void SetMandatoryMinHeight(int height) { |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 69 | SetMandatory(MediaConstraintsInterface::kMinHeight, height); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | void SetOptionalMaxWidth(int width) { |
| 73 | AddOptional(MediaConstraintsInterface::kMaxWidth, width); |
| 74 | } |
| 75 | |
| 76 | void SetMandatoryMaxFrameRate(int frame_rate) { |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 77 | SetMandatory(MediaConstraintsInterface::kMaxFrameRate, frame_rate); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | void SetMandatoryReceiveAudio(bool enable) { |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 81 | SetMandatory(MediaConstraintsInterface::kOfferToReceiveAudio, enable); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | void SetMandatoryReceiveVideo(bool enable) { |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 85 | SetMandatory(MediaConstraintsInterface::kOfferToReceiveVideo, enable); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | void SetMandatoryUseRtpMux(bool enable) { |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 89 | SetMandatory(MediaConstraintsInterface::kUseRtpMux, enable); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | void SetMandatoryIceRestart(bool enable) { |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 93 | SetMandatory(MediaConstraintsInterface::kIceRestart, enable); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | void SetAllowRtpDataChannels() { |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 97 | SetMandatory(MediaConstraintsInterface::kEnableRtpDataChannels, true); |
jiayl@webrtc.org | 61e00b0 | 2015-03-04 22:17:38 +0000 | [diff] [blame] | 98 | SetMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | void SetOptionalVAD(bool enable) { |
| 102 | AddOptional(MediaConstraintsInterface::kVoiceActivityDetection, enable); |
| 103 | } |
| 104 | |
| 105 | void SetAllowDtlsSctpDataChannels() { |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 106 | SetMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | private: |
| 110 | Constraints mandatory_; |
| 111 | Constraints optional_; |
| 112 | }; |
| 113 | |
| 114 | } // namespace webrtc |
| 115 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 116 | #endif // API_TEST_FAKECONSTRAINTS_H_ |