Home | History | Annotate | Download | only in media
      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.
      4 
      5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_PROCESSOR_OPTIONS_H_
      6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_PROCESSOR_OPTIONS_H_
      7 
      8 #include <string>
      9 
     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 
     15 namespace webrtc {
     16 
     17 class AudioFrame;
     18 class AudioProcessing;
     19 class MediaConstraintsInterface;
     20 class TypingDetection;
     21 
     22 }
     23 
     24 namespace content {
     25 
     26 class RTCMediaConstraints;
     27 
     28 using webrtc::AudioProcessing;
     29 using webrtc::MediaConstraintsInterface;
     30 
     31 // A helper class to parse audio constraints from a blink::WebMediaConstraints
     32 // object.
     33 class CONTENT_EXPORT MediaAudioConstraints {
     34  public:
     35   // Constraint keys used by audio processing.
     36   static const char kEchoCancellation[];
     37   static const char kGoogEchoCancellation[];
     38   static const char kGoogExperimentalEchoCancellation[];
     39   static const char kGoogAutoGainControl[];
     40   static const char kGoogExperimentalAutoGainControl[];
     41   static const char kGoogNoiseSuppression[];
     42   static const char kGoogExperimentalNoiseSuppression[];
     43   static const char kGoogHighpassFilter[];
     44   static const char kGoogTypingNoiseDetection[];
     45   static const char kGoogAudioMirroring[];
     46 
     47   // Merge |constraints| with |kDefaultAudioConstraints|. For any key which
     48   // exists in both, the value from |constraints| is maintained, including its
     49   // mandatory/optional status. New values from |kDefaultAudioConstraints| will
     50   // be added with optional status.
     51   static void ApplyFixedAudioConstraints(RTCMediaConstraints* constraints);
     52 
     53   // |effects| is the bitmasks telling whether certain platform
     54   // hardware audio effects are enabled, like hardware echo cancellation. If
     55   // some hardware effect is enabled, the corresponding software audio
     56   // processing will be disabled.
     57   MediaAudioConstraints(const blink::WebMediaConstraints& constraints,
     58                         int effects);
     59   virtual ~MediaAudioConstraints();
     60 
     61   // Checks if any audio constraints are set that requires audio processing to
     62   // be applied.
     63   bool NeedsAudioProcessing();
     64 
     65   // Gets the property of the constraint named by |key| in |constraints_|.
     66   // Returns the constraint's value if the key is found; Otherwise returns the
     67   // default value of the constraint.
     68   // Note, for constraint of |kEchoCancellation| or |kGoogEchoCancellation|,
     69   // clients should use GetEchoCancellationProperty().
     70   bool GetProperty(const std::string& key);
     71 
     72   // Gets the property of echo cancellation defined in |constraints_|. The
     73   // returned value depends on a combination of |effects_|, |kEchoCancellation|
     74   // and |kGoogEchoCancellation| in |constraints_|.
     75   bool GetEchoCancellationProperty();
     76 
     77   // Returns true if all the mandatory constraints in |constraints_| are valid;
     78   // Otherwise return false.
     79   bool IsValid();
     80 
     81  private:
     82   // Gets the default value of constraint named by |key| in |constraints|.
     83   bool GetDefaultValueForConstraint(
     84       const blink::WebMediaConstraints& constraints, const std::string& key);
     85 
     86   const blink::WebMediaConstraints constraints_;
     87   const int effects_;
     88   bool default_audio_processing_constraint_value_;
     89 };
     90 
     91 // Enables the echo cancellation in |audio_processing|.
     92 void EnableEchoCancellation(AudioProcessing* audio_processing);
     93 
     94 // Enables the noise suppression in |audio_processing|.
     95 void EnableNoiseSuppression(AudioProcessing* audio_processing);
     96 
     97 // Enables the experimental noise suppression in |audio_processing|.
     98 void EnableExperimentalNoiseSuppression(AudioProcessing* audio_processing);
     99 
    100 // Enables the high pass filter in |audio_processing|.
    101 void EnableHighPassFilter(AudioProcessing* audio_processing);
    102 
    103 // Enables the typing detection in |audio_processing|.
    104 void EnableTypingDetection(AudioProcessing* audio_processing,
    105                            webrtc::TypingDetection* typing_detector);
    106 
    107 // Enables the experimental echo cancellation in |audio_processing|.
    108 void EnableExperimentalEchoCancellation(AudioProcessing* audio_processing);
    109 
    110 // Starts the echo cancellation dump in |audio_processing|.
    111 void StartEchoCancellationDump(AudioProcessing* audio_processing,
    112                                base::File aec_dump_file);
    113 
    114 // Stops the echo cancellation dump in |audio_processing|.
    115 // This method has no impact if echo cancellation dump has not been started on
    116 // |audio_processing|.
    117 void StopEchoCancellationDump(AudioProcessing* audio_processing);
    118 
    119 void EnableAutomaticGainControl(AudioProcessing* audio_processing);
    120 
    121 void GetAecStats(AudioProcessing* audio_processing,
    122                  webrtc::AudioProcessorInterface::AudioProcessorStats* stats);
    123 
    124 }  // namespace content
    125 
    126 #endif  // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_PROCESSOR_OPTIONS_H_
    127