Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / renderer / media / mock_media_constraint_factory.cc
blobad70b9c8d6e2ba5707fba11fe74328a82817aab4
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.
5 #include "base/strings/string_number_conversions.h"
6 #include "base/strings/utf_string_conversions.h"
7 #include "content/renderer/media/media_stream_audio_processor_options.h"
8 #include "content/renderer/media/mock_media_constraint_factory.h"
9 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface.h"
11 namespace content {
13 namespace {
15 static const char kValueTrue[] = "true";
16 static const char kValueFalse[] = "false";
18 } // namespace
20 MockMediaConstraintFactory::MockMediaConstraintFactory() {
23 MockMediaConstraintFactory::~MockMediaConstraintFactory() {
26 blink::WebMediaConstraints
27 MockMediaConstraintFactory::CreateWebMediaConstraints() const {
28 blink::WebVector<blink::WebMediaConstraint> mandatory(mandatory_);
29 blink::WebVector<blink::WebMediaConstraint> optional(optional_);
30 blink::WebMediaConstraints constraints;
31 constraints.initialize(optional, mandatory);
32 return constraints;
35 void MockMediaConstraintFactory::AddMandatory(const std::string& key,
36 int value) {
37 mandatory_.push_back(blink::WebMediaConstraint(base::UTF8ToUTF16(key),
38 base::IntToString16(value)));
41 void MockMediaConstraintFactory::AddMandatory(const std::string& key,
42 double value) {
43 mandatory_.push_back(blink::WebMediaConstraint(
44 base::UTF8ToUTF16(key),
45 base::UTF8ToUTF16(base::DoubleToString(value))));
48 void MockMediaConstraintFactory::AddMandatory(const std::string& key,
49 const std::string& value) {
50 mandatory_.push_back(blink::WebMediaConstraint(
51 base::UTF8ToUTF16(key), base::UTF8ToUTF16(value)));
54 void MockMediaConstraintFactory::AddMandatory(const std::string& key,
55 bool value) {
56 const std::string string_value = value ? kValueTrue : kValueFalse;
57 AddMandatory(key, string_value);
60 void MockMediaConstraintFactory::AddOptional(const std::string& key,
61 int value) {
62 optional_.push_back(blink::WebMediaConstraint(base::UTF8ToUTF16(key),
63 base::IntToString16(value)));
66 void MockMediaConstraintFactory::AddOptional(const std::string& key,
67 double value) {
68 optional_.push_back(blink::WebMediaConstraint(
69 base::UTF8ToUTF16(key),
70 base::UTF8ToUTF16(base::DoubleToString(value))));
73 void MockMediaConstraintFactory::AddOptional(const std::string& key,
74 const std::string& value) {
75 optional_.push_back(blink::WebMediaConstraint(
76 base::UTF8ToUTF16(key), base::UTF8ToUTF16(value)));
79 void MockMediaConstraintFactory::AddOptional(const std::string& key,
80 bool value) {
81 const std::string string_value = value ? kValueTrue : kValueFalse;
82 AddOptional(key, string_value);
85 void MockMediaConstraintFactory::DisableDefaultAudioConstraints() {
86 static const char* kDefaultAudioConstraints[] = {
87 webrtc::MediaConstraintsInterface::kGoogEchoCancellation,
88 webrtc::MediaConstraintsInterface::kExtendedFilterEchoCancellation,
89 webrtc::MediaConstraintsInterface::kAutoGainControl,
90 webrtc::MediaConstraintsInterface::kExperimentalAutoGainControl,
91 webrtc::MediaConstraintsInterface::kNoiseSuppression,
92 webrtc::MediaConstraintsInterface::kHighpassFilter,
93 webrtc::MediaConstraintsInterface::kTypingNoiseDetection,
94 webrtc::MediaConstraintsInterface::kExperimentalNoiseSuppression,
95 // This isn't part of the MediaConstraintsInterface.
96 MediaAudioConstraints::kGoogBeamforming
98 MockMediaConstraintFactory factory;
99 for (size_t i = 0; i < arraysize(kDefaultAudioConstraints); ++i) {
100 AddMandatory(kDefaultAudioConstraints[i], false);
104 } // namespace content