blob: b23007eafcf32843abf8b98703a6bea5a63e8e2b [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
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 "talk/base/stringencode.h"
36
37namespace webrtc {
38
39class 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) {
54 mandatory_.push_back(Constraint(key, talk_base::ToString<T>(value)));
55 }
56
57 template <class T>
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000058 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, talk_base::ToString<T>(value)));
70 }
71
72 template <class T>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073 void AddOptional(const std::string& key, const T& value) {
74 optional_.push_back(Constraint(key, talk_base::ToString<T>(value)));
75 }
76
77 void SetMandatoryMinAspectRatio(double ratio) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000078 SetMandatory(MediaConstraintsInterface::kMinAspectRatio, ratio);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000079 }
80
81 void SetMandatoryMinWidth(int width) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000082 SetMandatory(MediaConstraintsInterface::kMinWidth, width);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000083 }
84
85 void SetMandatoryMinHeight(int height) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000086 SetMandatory(MediaConstraintsInterface::kMinHeight, height);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000087 }
88
89 void SetOptionalMaxWidth(int width) {
90 AddOptional(MediaConstraintsInterface::kMaxWidth, width);
91 }
92
93 void SetMandatoryMaxFrameRate(int frame_rate) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000094 SetMandatory(MediaConstraintsInterface::kMaxFrameRate, frame_rate);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000095 }
96
97 void SetMandatoryReceiveAudio(bool enable) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +000098 SetMandatory(MediaConstraintsInterface::kOfferToReceiveAudio, enable);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000099 }
100
101 void SetMandatoryReceiveVideo(bool enable) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000102 SetMandatory(MediaConstraintsInterface::kOfferToReceiveVideo, enable);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000103 }
104
105 void SetMandatoryUseRtpMux(bool enable) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000106 SetMandatory(MediaConstraintsInterface::kUseRtpMux, enable);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000107 }
108
109 void SetMandatoryIceRestart(bool enable) {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000110 SetMandatory(MediaConstraintsInterface::kIceRestart, enable);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000111 }
112
113 void SetAllowRtpDataChannels() {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000114 SetMandatory(MediaConstraintsInterface::kEnableRtpDataChannels, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000115 }
116
117 void SetOptionalVAD(bool enable) {
118 AddOptional(MediaConstraintsInterface::kVoiceActivityDetection, enable);
119 }
120
121 void SetAllowDtlsSctpDataChannels() {
mallinath@webrtc.org19f27e62013-10-13 17:18:27 +0000122 SetMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, true);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000123 }
124
125 private:
126 Constraints mandatory_;
127 Constraints optional_;
128};
129
130} // namespace webrtc
131
132#endif // TALK_APP_WEBRTC_TEST_FAKECONSTRAINTS_H_