Home | History | Annotate | Download | only in test
      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 "talk/base/stringencode.h"
     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) {
     54     mandatory_.push_back(Constraint(key, talk_base::ToString<T>(value)));
     55   }
     56 
     57   template <class T>
     58   void AddOptional(const std::string& key, const T& value) {
     59     optional_.push_back(Constraint(key, talk_base::ToString<T>(value)));
     60   }
     61 
     62   void SetMandatoryMinAspectRatio(double ratio) {
     63     AddMandatory(MediaConstraintsInterface::kMinAspectRatio, ratio);
     64   }
     65 
     66   void SetMandatoryMinWidth(int width) {
     67     AddMandatory(MediaConstraintsInterface::kMinWidth, width);
     68   }
     69 
     70   void SetMandatoryMinHeight(int height) {
     71     AddMandatory(MediaConstraintsInterface::kMinHeight, height);
     72   }
     73 
     74   void SetOptionalMaxWidth(int width) {
     75     AddOptional(MediaConstraintsInterface::kMaxWidth, width);
     76   }
     77 
     78   void SetMandatoryMaxFrameRate(int frame_rate) {
     79     AddMandatory(MediaConstraintsInterface::kMaxFrameRate, frame_rate);
     80   }
     81 
     82   void SetMandatoryReceiveAudio(bool enable) {
     83     AddMandatory(MediaConstraintsInterface::kOfferToReceiveAudio, enable);
     84   }
     85 
     86   void SetMandatoryReceiveVideo(bool enable) {
     87     AddMandatory(MediaConstraintsInterface::kOfferToReceiveVideo, enable);
     88   }
     89 
     90   void SetMandatoryUseRtpMux(bool enable) {
     91     AddMandatory(MediaConstraintsInterface::kUseRtpMux, enable);
     92   }
     93 
     94   void SetMandatoryIceRestart(bool enable) {
     95     AddMandatory(MediaConstraintsInterface::kIceRestart, enable);
     96   }
     97 
     98   void SetAllowRtpDataChannels() {
     99     AddMandatory(MediaConstraintsInterface::kEnableRtpDataChannels, true);
    100   }
    101 
    102   void SetOptionalVAD(bool enable) {
    103     AddOptional(MediaConstraintsInterface::kVoiceActivityDetection, enable);
    104   }
    105 
    106   void SetAllowDtlsSctpDataChannels() {
    107     AddMandatory(MediaConstraintsInterface::kEnableSctpDataChannels, true);
    108     AddMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, true);
    109   }
    110 
    111  private:
    112   Constraints mandatory_;
    113   Constraints optional_;
    114 };
    115 
    116 }  // namespace webrtc
    117 
    118 #endif  // TALK_APP_WEBRTC_TEST_FAKECONSTRAINTS_H_
    119