1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "base/strings/string_number_conversions.h" 6 #include "base/strings/utf_string_conversions.h" 7 #include "content/renderer/media/mock_media_constraint_factory.h" 8 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface.h" 9 10 namespace content { 11 12 namespace { 13 14 static const char kValueTrue[] = "true"; 15 static const char kValueFalse[] = "false"; 16 17 } // namespace 18 19 MockMediaConstraintFactory::MockMediaConstraintFactory() { 20 } 21 22 MockMediaConstraintFactory::~MockMediaConstraintFactory() { 23 } 24 25 blink::WebMediaConstraints 26 MockMediaConstraintFactory::CreateWebMediaConstraints() { 27 blink::WebVector<blink::WebMediaConstraint> mandatory(mandatory_); 28 blink::WebVector<blink::WebMediaConstraint> optional(optional_); 29 blink::WebMediaConstraints constraints; 30 constraints.initialize(optional, mandatory); 31 return constraints; 32 } 33 34 void MockMediaConstraintFactory::AddMandatory(const std::string& key, 35 int value) { 36 mandatory_.push_back(blink::WebMediaConstraint(base::UTF8ToUTF16(key), 37 base::IntToString16(value))); 38 } 39 40 void MockMediaConstraintFactory::AddMandatory(const std::string& key, 41 double value) { 42 mandatory_.push_back(blink::WebMediaConstraint( 43 base::UTF8ToUTF16(key), 44 base::UTF8ToUTF16(base::DoubleToString(value)))); 45 } 46 47 void MockMediaConstraintFactory::AddMandatory(const std::string& key, 48 const std::string& value) { 49 mandatory_.push_back(blink::WebMediaConstraint( 50 base::UTF8ToUTF16(key), base::UTF8ToUTF16(value))); 51 } 52 53 void MockMediaConstraintFactory::AddMandatory(const std::string& key, 54 bool value) { 55 const std::string string_value = value ? kValueTrue : kValueFalse; 56 AddMandatory(key, string_value); 57 } 58 59 void MockMediaConstraintFactory::AddOptional(const std::string& key, 60 int value) { 61 optional_.push_back(blink::WebMediaConstraint(base::UTF8ToUTF16(key), 62 base::IntToString16(value))); 63 } 64 65 void MockMediaConstraintFactory::AddOptional(const std::string& key, 66 double value) { 67 optional_.push_back(blink::WebMediaConstraint( 68 base::UTF8ToUTF16(key), 69 base::UTF8ToUTF16(base::DoubleToString(value)))); 70 } 71 72 void MockMediaConstraintFactory::AddOptional(const std::string& key, 73 const std::string& value) { 74 optional_.push_back(blink::WebMediaConstraint( 75 base::UTF8ToUTF16(key), base::UTF8ToUTF16(value))); 76 } 77 78 void MockMediaConstraintFactory::AddOptional(const std::string& key, 79 bool value) { 80 const std::string string_value = value ? kValueTrue : kValueFalse; 81 AddOptional(key, string_value); 82 } 83 84 void MockMediaConstraintFactory::DisableDefaultAudioConstraints() { 85 static const char* kDefaultAudioConstraints[] = { 86 webrtc::MediaConstraintsInterface::kEchoCancellation, 87 webrtc::MediaConstraintsInterface::kExperimentalEchoCancellation, 88 webrtc::MediaConstraintsInterface::kAutoGainControl, 89 webrtc::MediaConstraintsInterface::kExperimentalAutoGainControl, 90 webrtc::MediaConstraintsInterface::kNoiseSuppression, 91 webrtc::MediaConstraintsInterface::kHighpassFilter, 92 webrtc::MediaConstraintsInterface::kTypingNoiseDetection, 93 webrtc::MediaConstraintsInterface::kExperimentalNoiseSuppression 94 }; 95 MockMediaConstraintFactory factory; 96 for (size_t i = 0; i < arraysize(kDefaultAudioConstraints); ++i) { 97 AddMandatory(kDefaultAudioConstraints[i], false); 98 } 99 } 100 101 } // namespace content 102