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"
18 class AudioProcessing
;
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 kGoogHighpassFilter
[];
46 static const char kGoogTypingNoiseDetection
[];
47 static const char kGoogAudioMirroring
[];
48 static const char kGoogAudioProcessing48kHzSupport
[];
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 echo cancellation defined in |constraints_|. The
72 // returned value depends on a combination of |effects_|, |kEchoCancellation|
73 // and |kGoogEchoCancellation| in |constraints_|.
74 bool GetEchoCancellationProperty() const;
76 // Returns true if all the mandatory constraints in |constraints_| are valid;
77 // Otherwise return false.
81 // Gets the default value of constraint named by |key| in |constraints|.
82 bool GetDefaultValueForConstraint(
83 const blink::WebMediaConstraints
& constraints
,
84 const std::string
& key
) const;
86 const blink::WebMediaConstraints constraints_
;
88 bool default_audio_processing_constraint_value_
;
91 // A helper class to log echo information in general and Echo Cancellation
92 // quality in particular.
93 class CONTENT_EXPORT EchoInformation
{
96 virtual ~EchoInformation();
98 void UpdateAecDelayStats(webrtc::EchoCancellation
* echo_cancellation
);
101 // Counter to track 5 seconds of processed 10 ms chunks in order to query a
102 // new metric from webrtc::EchoCancellation::GetEchoDelayMetrics().
105 DISALLOW_COPY_AND_ASSIGN(EchoInformation
);
108 // Enables the echo cancellation in |audio_processing|.
109 void EnableEchoCancellation(AudioProcessing
* audio_processing
);
111 // Enables the noise suppression in |audio_processing|.
112 void EnableNoiseSuppression(AudioProcessing
* audio_processing
);
114 // Enables the high pass filter in |audio_processing|.
115 void EnableHighPassFilter(AudioProcessing
* audio_processing
);
117 // Enables the typing detection in |audio_processing|.
118 void EnableTypingDetection(AudioProcessing
* audio_processing
,
119 webrtc::TypingDetection
* typing_detector
);
121 // Starts the echo cancellation dump in |audio_processing|.
122 void StartEchoCancellationDump(AudioProcessing
* audio_processing
,
123 base::File aec_dump_file
);
125 // Stops the echo cancellation dump in |audio_processing|.
126 // This method has no impact if echo cancellation dump has not been started on
127 // |audio_processing|.
128 void StopEchoCancellationDump(AudioProcessing
* audio_processing
);
130 void EnableAutomaticGainControl(AudioProcessing
* audio_processing
);
132 void GetAecStats(webrtc::EchoCancellation
* echo_cancellation
,
133 webrtc::AudioProcessorInterface::AudioProcessorStats
* stats
);
135 } // namespace content
137 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_PROCESSOR_OPTIONS_H_