1 /* 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. 3 * 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. 9 */ 10 11 #ifndef WEBRTC_API_TEST_FAKECONSTRAINTS_H_ 12 #define WEBRTC_API_TEST_FAKECONSTRAINTS_H_ 13 14 #include <string> 15 #include <vector> 16 17 #include "webrtc/api/mediaconstraintsinterface.h" 18 #include "webrtc/base/stringencode.h" 19 20 namespace webrtc { 21 22 class FakeConstraints : public webrtc::MediaConstraintsInterface { 23 public: FakeConstraints()24 FakeConstraints() { } ~FakeConstraints()25 virtual ~FakeConstraints() { } 26 GetMandatory()27 virtual const Constraints& GetMandatory() const { 28 return mandatory_; 29 } 30 GetOptional()31 virtual const Constraints& GetOptional() const { 32 return optional_; 33 } 34 35 template <class T> AddMandatory(const std::string & key,const T & value)36 void AddMandatory(const std::string& key, const T& value) { 37 mandatory_.push_back(Constraint(key, rtc::ToString<T>(value))); 38 } 39 40 template <class T> SetMandatory(const std::string & key,const T & value)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 } 52 mandatory_.push_back(Constraint(key, rtc::ToString<T>(value))); 53 } 54 55 template <class T> AddOptional(const std::string & key,const T & value)56 void AddOptional(const std::string& key, const T& value) { 57 optional_.push_back(Constraint(key, rtc::ToString<T>(value))); 58 } 59 SetMandatoryMinAspectRatio(double ratio)60 void SetMandatoryMinAspectRatio(double ratio) { 61 SetMandatory(MediaConstraintsInterface::kMinAspectRatio, ratio); 62 } 63 SetMandatoryMinWidth(int width)64 void SetMandatoryMinWidth(int width) { 65 SetMandatory(MediaConstraintsInterface::kMinWidth, width); 66 } 67 SetMandatoryMinHeight(int height)68 void SetMandatoryMinHeight(int height) { 69 SetMandatory(MediaConstraintsInterface::kMinHeight, height); 70 } 71 SetOptionalMaxWidth(int width)72 void SetOptionalMaxWidth(int width) { 73 AddOptional(MediaConstraintsInterface::kMaxWidth, width); 74 } 75 SetMandatoryMaxFrameRate(int frame_rate)76 void SetMandatoryMaxFrameRate(int frame_rate) { 77 SetMandatory(MediaConstraintsInterface::kMaxFrameRate, frame_rate); 78 } 79 SetMandatoryReceiveAudio(bool enable)80 void SetMandatoryReceiveAudio(bool enable) { 81 SetMandatory(MediaConstraintsInterface::kOfferToReceiveAudio, enable); 82 } 83 SetMandatoryReceiveVideo(bool enable)84 void SetMandatoryReceiveVideo(bool enable) { 85 SetMandatory(MediaConstraintsInterface::kOfferToReceiveVideo, enable); 86 } 87 SetMandatoryUseRtpMux(bool enable)88 void SetMandatoryUseRtpMux(bool enable) { 89 SetMandatory(MediaConstraintsInterface::kUseRtpMux, enable); 90 } 91 SetMandatoryIceRestart(bool enable)92 void SetMandatoryIceRestart(bool enable) { 93 SetMandatory(MediaConstraintsInterface::kIceRestart, enable); 94 } 95 SetAllowRtpDataChannels()96 void SetAllowRtpDataChannels() { 97 SetMandatory(MediaConstraintsInterface::kEnableRtpDataChannels, true); 98 SetMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, false); 99 } 100 SetOptionalVAD(bool enable)101 void SetOptionalVAD(bool enable) { 102 AddOptional(MediaConstraintsInterface::kVoiceActivityDetection, enable); 103 } 104 SetAllowDtlsSctpDataChannels()105 void SetAllowDtlsSctpDataChannels() { 106 SetMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, true); 107 } 108 109 private: 110 Constraints mandatory_; 111 Constraints optional_; 112 }; 113 114 } // namespace webrtc 115 116 #endif // WEBRTC_API_TEST_FAKECONSTRAINTS_H_ 117