• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * libjingle
3  * Copyright 2012 Google Inc.
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.
26  */
27 
28 #ifndef TALK_APP_WEBRTC_TEST_FAKECONSTRAINTS_H_
29 #define TALK_APP_WEBRTC_TEST_FAKECONSTRAINTS_H_
30 
31 #include <string>
32 #include <vector>
33 
34 #include "talk/app/webrtc/mediaconstraintsinterface.h"
35 #include "webrtc/base/stringencode.h"
36 
37 namespace webrtc {
38 
39 class FakeConstraints : public webrtc::MediaConstraintsInterface {
40  public:
FakeConstraints()41   FakeConstraints() { }
~FakeConstraints()42   virtual ~FakeConstraints() { }
43 
GetMandatory()44   virtual const Constraints& GetMandatory() const {
45     return mandatory_;
46   }
47 
GetOptional()48   virtual const Constraints& GetOptional() const {
49     return optional_;
50   }
51 
52   template <class T>
AddMandatory(const std::string & key,const T & value)53   void AddMandatory(const std::string& key, const T& value) {
54     mandatory_.push_back(Constraint(key, rtc::ToString<T>(value)));
55   }
56 
57   template <class T>
SetMandatory(const std::string & key,const T & value)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     }
69     mandatory_.push_back(Constraint(key, rtc::ToString<T>(value)));
70   }
71 
72   template <class T>
AddOptional(const std::string & key,const T & value)73   void AddOptional(const std::string& key, const T& value) {
74     optional_.push_back(Constraint(key, rtc::ToString<T>(value)));
75   }
76 
SetMandatoryMinAspectRatio(double ratio)77   void SetMandatoryMinAspectRatio(double ratio) {
78     SetMandatory(MediaConstraintsInterface::kMinAspectRatio, ratio);
79   }
80 
SetMandatoryMinWidth(int width)81   void SetMandatoryMinWidth(int width) {
82     SetMandatory(MediaConstraintsInterface::kMinWidth, width);
83   }
84 
SetMandatoryMinHeight(int height)85   void SetMandatoryMinHeight(int height) {
86     SetMandatory(MediaConstraintsInterface::kMinHeight, height);
87   }
88 
SetOptionalMaxWidth(int width)89   void SetOptionalMaxWidth(int width) {
90     AddOptional(MediaConstraintsInterface::kMaxWidth, width);
91   }
92 
SetMandatoryMaxFrameRate(int frame_rate)93   void SetMandatoryMaxFrameRate(int frame_rate) {
94     SetMandatory(MediaConstraintsInterface::kMaxFrameRate, frame_rate);
95   }
96 
SetMandatoryReceiveAudio(bool enable)97   void SetMandatoryReceiveAudio(bool enable) {
98     SetMandatory(MediaConstraintsInterface::kOfferToReceiveAudio, enable);
99   }
100 
SetMandatoryReceiveVideo(bool enable)101   void SetMandatoryReceiveVideo(bool enable) {
102     SetMandatory(MediaConstraintsInterface::kOfferToReceiveVideo, enable);
103   }
104 
SetMandatoryUseRtpMux(bool enable)105   void SetMandatoryUseRtpMux(bool enable) {
106     SetMandatory(MediaConstraintsInterface::kUseRtpMux, enable);
107   }
108 
SetMandatoryIceRestart(bool enable)109   void SetMandatoryIceRestart(bool enable) {
110     SetMandatory(MediaConstraintsInterface::kIceRestart, enable);
111   }
112 
SetAllowRtpDataChannels()113   void SetAllowRtpDataChannels() {
114     SetMandatory(MediaConstraintsInterface::kEnableRtpDataChannels, true);
115     SetMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, false);
116   }
117 
SetOptionalVAD(bool enable)118   void SetOptionalVAD(bool enable) {
119     AddOptional(MediaConstraintsInterface::kVoiceActivityDetection, enable);
120   }
121 
SetAllowDtlsSctpDataChannels()122   void SetAllowDtlsSctpDataChannels() {
123     SetMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, true);
124   }
125 
126  private:
127   Constraints mandatory_;
128   Constraints optional_;
129 };
130 
131 }  // namespace webrtc
132 
133 #endif  // TALK_APP_WEBRTC_TEST_FAKECONSTRAINTS_H_
134