Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(534)

Side by Side Diff: webrtc/api/localaudiosource.cc

Issue 2514883002: Create //webrtc/api:libjingle_peerconnection_api + refactorings. (Closed)
Patch Set: Big move! Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright 2013 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/api/localaudiosource.h"
12
13 #include <vector>
14
15 #include "webrtc/api/mediaconstraintsinterface.h"
16 #include "webrtc/media/base/mediaengine.h"
17
18 using webrtc::MediaConstraintsInterface;
19 using webrtc::MediaSourceInterface;
20
21 namespace webrtc {
22
23 namespace {
24
25 // Convert constraints to audio options. Return false if constraints are
26 // invalid.
27 void FromConstraints(const MediaConstraintsInterface::Constraints& constraints,
28 cricket::AudioOptions* options) {
29 // This design relies on the fact that all the audio constraints are actually
30 // "options", i.e. boolean-valued and always satisfiable. If the constraints
31 // are extended to include non-boolean values or actual format constraints,
32 // a different algorithm will be required.
33 struct {
34 const char* name;
35 rtc::Optional<bool>& value;
36 } key_to_value[] = {
37 {MediaConstraintsInterface::kGoogEchoCancellation,
38 options->echo_cancellation},
39 {MediaConstraintsInterface::kExtendedFilterEchoCancellation,
40 options->extended_filter_aec},
41 {MediaConstraintsInterface::kDAEchoCancellation,
42 options->delay_agnostic_aec},
43 {MediaConstraintsInterface::kAutoGainControl, options->auto_gain_control},
44 {MediaConstraintsInterface::kExperimentalAutoGainControl,
45 options->experimental_agc},
46 {MediaConstraintsInterface::kNoiseSuppression,
47 options->noise_suppression},
48 {MediaConstraintsInterface::kExperimentalNoiseSuppression,
49 options->experimental_ns},
50 {MediaConstraintsInterface::kIntelligibilityEnhancer,
51 options->intelligibility_enhancer},
52 {MediaConstraintsInterface::kLevelControl, options->level_control},
53 {MediaConstraintsInterface::kHighpassFilter, options->highpass_filter},
54 {MediaConstraintsInterface::kTypingNoiseDetection,
55 options->typing_detection},
56 {MediaConstraintsInterface::kAudioMirroring, options->stereo_swapping}
57 };
58
59 for (const auto& constraint : constraints) {
60 bool value = false;
61 if (!rtc::FromString(constraint.value, &value))
62 continue;
63
64 for (auto& entry : key_to_value) {
65 if (constraint.key.compare(entry.name) == 0)
66 entry.value = rtc::Optional<bool>(value);
67 }
68 }
69
70 // Set non-boolean constraints.
71 std::string value;
72 if (constraints.FindFirst(
73 MediaConstraintsInterface::kLevelControlInitialPeakLevelDBFS,
74 &value)) {
75 float level_control_initial_peak_level_dbfs;
76 if (rtc::FromString(value, &level_control_initial_peak_level_dbfs)) {
77 options->level_control_initial_peak_level_dbfs =
78 rtc::Optional<float>(level_control_initial_peak_level_dbfs);
79 }
80 }
81 }
82
83 } // namespace
84
85 rtc::scoped_refptr<LocalAudioSource> LocalAudioSource::Create(
86 const PeerConnectionFactoryInterface::Options& options,
87 const MediaConstraintsInterface* constraints) {
88 rtc::scoped_refptr<LocalAudioSource> source(
89 new rtc::RefCountedObject<LocalAudioSource>());
90 source->Initialize(options, constraints);
91 return source;
92 }
93
94 rtc::scoped_refptr<LocalAudioSource> LocalAudioSource::Create(
95 const PeerConnectionFactoryInterface::Options& options,
96 const cricket::AudioOptions* audio_options) {
97 rtc::scoped_refptr<LocalAudioSource> source(
98 new rtc::RefCountedObject<LocalAudioSource>());
99 source->Initialize(options, audio_options);
100 return source;
101 }
102
103 void LocalAudioSource::Initialize(
104 const PeerConnectionFactoryInterface::Options& options,
105 const MediaConstraintsInterface* constraints) {
106 if (!constraints)
107 return;
108
109 // Apply optional constraints first, they will be overwritten by mandatory
110 // constraints.
111 FromConstraints(constraints->GetOptional(), &options_);
112
113 cricket::AudioOptions mandatory_options;
114 FromConstraints(constraints->GetMandatory(), &mandatory_options);
115 options_.SetAll(mandatory_options);
116 }
117
118 void LocalAudioSource::Initialize(
119 const PeerConnectionFactoryInterface::Options& options,
120 const cricket::AudioOptions* audio_options) {
121 if (!audio_options)
122 return;
123
124 options_ = *audio_options;
125 }
126
127 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698