henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 3 | * Copyright 2012 Google Inc. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 4 | * |
| 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.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 26 | */ |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 +0000 | [diff] [blame] | 27 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 28 | #ifndef WEBRTC_API_TEST_FAKECONSTRAINTS_H_ |
| 29 | #define WEBRTC_API_TEST_FAKECONSTRAINTS_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 30 | |
| 31 | #include <string> |
| 32 | #include <vector> |
| 33 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 34 | #include "webrtc/api/mediaconstraintsinterface.h" |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 35 | #include "webrtc/base/stringencode.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 36 | |
| 37 | namespace webrtc { |
| 38 | |
| 39 | class 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.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 54 | mandatory_.push_back(Constraint(key, rtc::ToString<T>(value))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | template <class T> |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 58 | 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.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 69 | mandatory_.push_back(Constraint(key, rtc::ToString<T>(value))); |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | template <class T> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 73 | void AddOptional(const std::string& key, const T& value) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 74 | optional_.push_back(Constraint(key, rtc::ToString<T>(value))); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | void SetMandatoryMinAspectRatio(double ratio) { |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 78 | SetMandatory(MediaConstraintsInterface::kMinAspectRatio, ratio); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | void SetMandatoryMinWidth(int width) { |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 82 | SetMandatory(MediaConstraintsInterface::kMinWidth, width); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | void SetMandatoryMinHeight(int height) { |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 86 | SetMandatory(MediaConstraintsInterface::kMinHeight, height); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | void SetOptionalMaxWidth(int width) { |
| 90 | AddOptional(MediaConstraintsInterface::kMaxWidth, width); |
| 91 | } |
| 92 | |
| 93 | void SetMandatoryMaxFrameRate(int frame_rate) { |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 94 | SetMandatory(MediaConstraintsInterface::kMaxFrameRate, frame_rate); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | void SetMandatoryReceiveAudio(bool enable) { |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 98 | SetMandatory(MediaConstraintsInterface::kOfferToReceiveAudio, enable); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | void SetMandatoryReceiveVideo(bool enable) { |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 102 | SetMandatory(MediaConstraintsInterface::kOfferToReceiveVideo, enable); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | void SetMandatoryUseRtpMux(bool enable) { |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 106 | SetMandatory(MediaConstraintsInterface::kUseRtpMux, enable); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | void SetMandatoryIceRestart(bool enable) { |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 110 | SetMandatory(MediaConstraintsInterface::kIceRestart, enable); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | void SetAllowRtpDataChannels() { |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 114 | SetMandatory(MediaConstraintsInterface::kEnableRtpDataChannels, true); |
jiayl@webrtc.org | 61e00b0 | 2015-03-04 22:17:38 +0000 | [diff] [blame] | 115 | SetMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, false); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | void SetOptionalVAD(bool enable) { |
| 119 | AddOptional(MediaConstraintsInterface::kVoiceActivityDetection, enable); |
| 120 | } |
| 121 | |
| 122 | void SetAllowDtlsSctpDataChannels() { |
mallinath@webrtc.org | 19f27e6 | 2013-10-13 17:18:27 +0000 | [diff] [blame] | 123 | SetMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, true); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | private: |
| 127 | Constraints mandatory_; |
| 128 | Constraints optional_; |
| 129 | }; |
| 130 | |
| 131 | } // namespace webrtc |
| 132 | |
Henrik Kjellander | 15583c1 | 2016-02-10 10:53:12 +0100 | [diff] [blame] | 133 | #endif // WEBRTC_API_TEST_FAKECONSTRAINTS_H_ |