1 // Copyright 2013 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 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_PROCESSOR_OPTIONS_H_
6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_PROCESSOR_OPTIONS_H_
10 #include "base/files/file.h"
11 #include "content/common/content_export.h"
12 #include "third_party/WebKit/public/platform/WebMediaConstraints.h"
13 #include "third_party/libjingle/source/talk/app/webrtc/mediastreaminterface.h"
14 #include "third_party/webrtc/modules/audio_processing/include/audio_processing.h"
19 class EchoCancellation
;
20 class MediaConstraintsInterface
;
21 class TypingDetection
;
27 class RTCMediaConstraints
;
29 using webrtc::AudioProcessing
;
30 using webrtc::MediaConstraintsInterface
;
32 // A helper class to parse audio constraints from a blink::WebMediaConstraints
34 class CONTENT_EXPORT MediaAudioConstraints
{
36 // Constraint keys used by audio processing.
37 static const char kEchoCancellation
[];
38 static const char kGoogEchoCancellation
[];
39 static const char kGoogExperimentalEchoCancellation
[];
40 static const char kGoogAutoGainControl
[];
41 static const char kGoogExperimentalAutoGainControl
[];
42 static const char kGoogNoiseSuppression
[];
43 static const char kGoogExperimentalNoiseSuppression
[];
44 static const char kGoogBeamforming
[];
45 static const char kGoogArrayGeometry
[];
46 static const char kGoogHighpassFilter
[];
47 static const char kGoogTypingNoiseDetection
[];
48 static const char kGoogAudioMirroring
[];
50 // Merge |constraints| with |kDefaultAudioConstraints|. For any key which
51 // exists in both, the value from |constraints| is maintained, including its
52 // mandatory/optional status. New values from |kDefaultAudioConstraints| will
53 // be added with optional status.
54 static void ApplyFixedAudioConstraints(RTCMediaConstraints
* constraints
);
56 // |effects| is the bitmasks telling whether certain platform
57 // hardware audio effects are enabled, like hardware echo cancellation. If
58 // some hardware effect is enabled, the corresponding software audio
59 // processing will be disabled.
60 MediaAudioConstraints(const blink::WebMediaConstraints
& constraints
,
62 virtual ~MediaAudioConstraints();
64 // Gets the property of the constraint named by |key| in |constraints_|.
65 // Returns the constraint's value if the key is found; otherwise returns the
66 // default value of the constraint.
67 // Note, for constraint of |kEchoCancellation| or |kGoogEchoCancellation|,
68 // clients should use GetEchoCancellationProperty().
69 bool GetProperty(const std::string
& key
) const;
71 // Gets the property of the constraint named by |key| in |constraints_| as a
72 // string. Returns the constraint's string value if the key is found;
73 // otherwise returns an empty string.
74 std::string
GetPropertyAsString(const std::string
& key
) const;
76 // Gets the property of echo cancellation defined in |constraints_|. The
77 // returned value depends on a combination of |effects_|, |kEchoCancellation|
78 // and |kGoogEchoCancellation| in |constraints_|.
79 bool GetEchoCancellationProperty() const;
81 // Returns true if all the mandatory constraints in |constraints_| are valid;
82 // Otherwise return false.
86 // Gets the default value of constraint named by |key| in |constraints|.
87 bool GetDefaultValueForConstraint(
88 const blink::WebMediaConstraints
& constraints
,
89 const std::string
& key
) const;
91 const blink::WebMediaConstraints constraints_
;
93 bool default_audio_processing_constraint_value_
;
96 // A helper class to log echo information in general and Echo Cancellation
97 // quality in particular.
98 class CONTENT_EXPORT EchoInformation
{
101 virtual ~EchoInformation();
103 void UpdateAecDelayStats(webrtc::EchoCancellation
* echo_cancellation
);
106 // Counter to track 5 seconds of processed 10 ms chunks in order to query a
107 // new metric from webrtc::EchoCancellation::GetEchoDelayMetrics().
109 bool echo_frames_received_
;
111 DISALLOW_COPY_AND_ASSIGN(EchoInformation
);
114 // Enables the echo cancellation in |audio_processing|.
115 void EnableEchoCancellation(AudioProcessing
* audio_processing
);
117 // Enables the noise suppression in |audio_processing|.
118 void EnableNoiseSuppression(AudioProcessing
* audio_processing
,
119 webrtc::NoiseSuppression::Level ns_level
);
121 // Enables the high pass filter in |audio_processing|.
122 void EnableHighPassFilter(AudioProcessing
* audio_processing
);
124 // Enables the typing detection in |audio_processing|.
125 void EnableTypingDetection(AudioProcessing
* audio_processing
,
126 webrtc::TypingDetection
* typing_detector
);
128 // Starts the echo cancellation dump in |audio_processing|.
129 void StartEchoCancellationDump(AudioProcessing
* audio_processing
,
130 base::File aec_dump_file
);
132 // Stops the echo cancellation dump in |audio_processing|.
133 // This method has no impact if echo cancellation dump has not been started on
134 // |audio_processing|.
135 void StopEchoCancellationDump(AudioProcessing
* audio_processing
);
137 void EnableAutomaticGainControl(AudioProcessing
* audio_processing
);
139 void GetAecStats(webrtc::EchoCancellation
* echo_cancellation
,
140 webrtc::AudioProcessorInterface::AudioProcessorStats
* stats
);
142 // Parses the microphone array geometry from |geometry_string| formatted as
143 // "x1 y1 z1 ... xn yn zn" for an n-microphone array. See
144 // switches::kMicrophonePositions for more detail.
146 // Returns a zero-sized vector if |geometry_string| isn't a parseable geometry.
147 CONTENT_EXPORT
std::vector
<webrtc::Point
> ParseArrayGeometry(
148 const std::string
& geometry_string
);
150 } // namespace content
152 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_PROCESSOR_OPTIONS_H_