Created
March 20, 2014 23:43
-
-
Save okumura/9676450 to your computer and use it in GitHub Desktop.
MutableConstraints class for webrtc.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef WEBRTC_SANDBOX_MUTABLE_CONSTRAINTS_H | |
#define WEBRTC_SANDBOX_MUTABLE_CONSTRAINTS_H | |
#pragma once | |
#include <string> | |
#include <vector> | |
#include "talk/app/webrtc/mediaconstraintsinterface.h" | |
#include "talk/base/stringencode.h" | |
class MutableConstraints : public webrtc::MediaConstraintsInterface { | |
public: | |
MutableConstraints() { } | |
virtual ~MutableConstraints() { } | |
virtual const Constraints& GetMandatory() const { | |
return mandatory_; | |
} | |
virtual const Constraints& GetOptional() const { | |
return optional_; | |
} | |
template <class T> | |
void AddMandatory(const std::string& key, const T& value) { | |
mandatory_.push_back(Constraint(key, talk_base::ToString<T>(value))); | |
} | |
template <class T> | |
void SetMandatory(const std::string& key, const T& value) { | |
std::string value_str; | |
if (mandatory_.FindFirst(key, &value_str)) { | |
for (Constraints::iterator iter = mandatory_.begin(); | |
iter != mandatory_.end(); ++iter) { | |
if (iter->key == key) { | |
mandatory_.erase(iter); | |
break; | |
} | |
} | |
} | |
mandatory_.push_back(Constraint(key, talk_base::ToString<T>(value))); | |
} | |
template <class T> | |
void AddOptional(const std::string& key, const T& value) { | |
optional_.push_back(Constraint(key, talk_base::ToString<T>(value))); | |
} | |
// sdp constraints. | |
// for CreateOffer/CreateAnswer. | |
void SetMandatoryReceiveAudio(bool enable) { | |
SetMandatory(MediaConstraintsInterface::kOfferToReceiveAudio, enable); | |
} | |
void SetMandatoryReceiveVideo(bool enable) { | |
SetMandatory(MediaConstraintsInterface::kOfferToReceiveVideo, enable); | |
} | |
void SetOptionalVAD(bool enable) { | |
AddOptional(MediaConstraintsInterface::kVoiceActivityDetection, enable); | |
} | |
void SetMandatoryIceRestart(bool enable) { | |
SetMandatory(MediaConstraintsInterface::kIceRestart, enable); | |
} | |
// sdp constraints (google specific). | |
// for CreateOffer/CreateAnswer. | |
void SetMandatoryUseRtpMux(bool enable) { | |
SetMandatory(MediaConstraintsInterface::kUseRtpMux, enable); | |
} | |
// audio constraints (google specific). | |
// for CreateAudioSource. | |
void SetMandatoryEchoCancellation(bool enable) { | |
SetMandatory(MediaConstraintsInterface::kEchoCancellation, enable); | |
} | |
void SetOptionalExperimentalEchoCancellation(bool enable) { | |
AddOptional(MediaConstraintsInterface::kExperimentalEchoCancellation, enable); | |
} | |
void SetOptionalAutoGainControl(bool enable) { | |
AddOptional(MediaConstraintsInterface::kAutoGainControl, enable); | |
} | |
void SetOptionalExperimentalAutoGainControl(bool enable) { | |
AddOptional(MediaConstraintsInterface::kExperimentalAutoGainControl, enable); | |
} | |
void SetMandatoryNoiseSuppression(bool enable) { | |
AddMandatory(MediaConstraintsInterface::kNoiseSuppression, enable); | |
} | |
void SetOptionalExperimentalNoiseSuppression(bool enable) { | |
AddOptional(MediaConstraintsInterface::kExperimentalNoiseSuppression, enable); | |
} | |
void SetOptionalHighpassFilter(bool enable) { | |
AddOptional(MediaConstraintsInterface::kHighpassFilter, enable); | |
} | |
void SetOptionalTypingNoiseDetection(bool enable) { | |
AddOptional(MediaConstraintsInterface::kTypingNoiseDetection, enable); | |
} | |
void SetOptionalAudioMirroring(bool enable) { | |
AddOptional(MediaConstraintsInterface::kAudioMirroring, enable); | |
} | |
// video (draft-alvestrand-constraints-resolution-00b). | |
// for CreateVideoSource. | |
void SetMandatoryMinAspectRatio(double ratio) { | |
SetMandatory(MediaConstraintsInterface::kMinAspectRatio, ratio); | |
} | |
void SetMandatoryMaxAspectRatio(double ratio) { | |
SetMandatory(MediaConstraintsInterface::kMaxAspectRatio, ratio); | |
} | |
void SetMandatoryMaxWidth(int width) { | |
SetMandatory(MediaConstraintsInterface::kMaxWidth, width); | |
} | |
void SetMandatoryMinWidth(int width) { | |
SetMandatory(MediaConstraintsInterface::kMinWidth, width); | |
} | |
void SetOptionalMaxWidth(int width) { | |
AddOptional(MediaConstraintsInterface::kMaxWidth, width); | |
} | |
void SetMandatoryMinHeight(int height) { | |
SetMandatory(MediaConstraintsInterface::kMinHeight, height); | |
} | |
void SetMandatoryMaxFrameRate(int frame_rate) { | |
SetMandatory(MediaConstraintsInterface::kMaxFrameRate, frame_rate); | |
} | |
void SetMandatoryMinFrameRate(int frame_rate) { | |
SetMandatory(MediaConstraintsInterface::kMinFrameRate, frame_rate); | |
} | |
// video (google). | |
// for CreateVideoSource. | |
void SetOptionalNoiseReduction(bool enable) { | |
AddOptional(MediaConstraintsInterface::kNoiseReduction, true); | |
} | |
void SetOptionalLeakyBucket(bool enable) { | |
AddOptional(MediaConstraintsInterface::kLeakyBucket, true); | |
} | |
void SetOptionaTemporalLayeredScreencast(bool enable) { | |
AddOptional(MediaConstraintsInterface::kTemporalLayeredScreencast, true); | |
} | |
void SetOptionaCpuOveruseDetection(bool enable) { | |
AddOptional(MediaConstraintsInterface::kCpuOveruseDetection, true); | |
} | |
// peer connection constraints. | |
// for CreatePeerConnection. | |
void SetAllowDtlsSctpDataChannels() { | |
SetMandatory(MediaConstraintsInterface::kEnableDtlsSrtp, true); | |
} | |
void SetAllowRtpDataChannels() { | |
SetMandatory(MediaConstraintsInterface::kEnableRtpDataChannels, true); | |
} | |
void SetAllowDscp() { | |
SetMandatory(MediaConstraintsInterface::kEnableDscp, true); | |
} | |
void SetAllowIPv6() { | |
SetMandatory(MediaConstraintsInterface::kEnableIPv6, true); | |
} | |
private: | |
Constraints mandatory_; | |
Constraints optional_; | |
}; | |
#endif /* WEBRTC_SANDBOX_MUTABLE_CONSTRAINTS_H */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment