OLD | NEW |
(Empty) | |
| 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_WEBRTC_AUDIO_PROCESSOR_H_ |
| 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_PROCESSOR_H_ |
| 7 |
| 8 #include "base/atomicops.h" |
| 9 #include "base/synchronization/lock.h" |
| 10 #include "base/threading/thread_checker.h" |
| 11 #include "base/time/time.h" |
| 12 #include "content/common/content_export.h" |
| 13 #include "media/base/audio_converter.h" |
| 14 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface
.h" |
| 15 #include "third_party/webrtc/modules/audio_processing/include/audio_processing.h
" |
| 16 #include "third_party/webrtc/modules/interface/module_common_types.h" |
| 17 |
| 18 namespace media { |
| 19 class AudioBus; |
| 20 class AudioFifo; |
| 21 class AudioParameters; |
| 22 } // namespace media |
| 23 |
| 24 namespace webrtc { |
| 25 class AudioFrame; |
| 26 } |
| 27 |
| 28 namespace content { |
| 29 |
| 30 // This class owns an object of webrtc::AudioProcessing which contains signal |
| 31 // processing components like AGC, AEC and NS. It enables the components based |
| 32 // on the getUserMedia constraints, processes the data and outputs it in a unit |
| 33 // of 10 ms data chunk. |
| 34 class CONTENT_EXPORT WebRtcAudioProcessor { |
| 35 public: |
| 36 explicit WebRtcAudioProcessor( |
| 37 const webrtc::MediaConstraintsInterface* constraints); |
| 38 ~WebRtcAudioProcessor(); |
| 39 |
| 40 // Pushes capture data in |audio_source| to the internal FIFO. |
| 41 // Called on the capture audio thread. |
| 42 void PushCaptureData(media::AudioBus* audio_source); |
| 43 |
| 44 // Push the render audio to webrtc::AudioProcessing for analysis. This is |
| 45 // needed iff echo processing is enabled. |
| 46 // |render_audio| is the pointer to the render audio data, its format |
| 47 // is specified by |sample_rate|, |number_of_channels| and |number_of_frames|. |
| 48 // Called on the render audio thread. |
| 49 void PushRenderData(const int16* render_audio, |
| 50 int sample_rate, |
| 51 int number_of_channels, |
| 52 int number_of_frames, |
| 53 base::TimeDelta render_delay); |
| 54 |
| 55 // Processes a block of 10 ms data from the internal FIFO and outputs it via |
| 56 // |out|. |out| is the address of the pointer that will be pointed to |
| 57 // the post-processed data if the method is returning a true. The lifetime |
| 58 // of the data represeted by |out| is guaranteed to outlive the method call. |
| 59 // Returns true if the internal FIFO has at least 10 ms data for processing, |
| 60 // otherwise false. |
| 61 // |capture_delay|, |volume| and |key_pressed| will be passed to |
| 62 // webrtc::AudioProcessing to help processing the data. |
| 63 // Called on the capture audio thread. |
| 64 bool ProcessAndConsumeData(base::TimeDelta capture_delay, |
| 65 int volume, |
| 66 bool key_pressed, |
| 67 int16** out); |
| 68 |
| 69 // Called when the format of the capture data has changed. |
| 70 // This has to be called before PushCaptureData() and ProcessAndConsumeData(). |
| 71 // Called on the main render thread. |
| 72 void SetCaptureFormat(const media::AudioParameters& source_params); |
| 73 |
| 74 // The audio format of the output from the processor. |
| 75 const media::AudioParameters& OutputFormat() const; |
| 76 |
| 77 // Accessor to check if the audio processing is enabled or not. |
| 78 bool has_audio_processing() const { return audio_processing_.get() != NULL; } |
| 79 |
| 80 private: |
| 81 class WebRtcAudioConverter; |
| 82 |
| 83 // Helper to initialize the WebRtc AudioProcessing. |
| 84 void InitializeAudioProcessingModule( |
| 85 const webrtc::MediaConstraintsInterface* constraints); |
| 86 |
| 87 // Helper to initialize the render converter. |
| 88 void InitializeRenderConverterIfNeeded(int sample_rate, |
| 89 int number_of_channels, |
| 90 int frames_per_buffer); |
| 91 |
| 92 // Called by ProcessAndConsumeData(). |
| 93 void ProcessData(webrtc::AudioFrame* audio_frame, |
| 94 base::TimeDelta capture_delay, |
| 95 int volume, |
| 96 bool key_pressed); |
| 97 |
| 98 // Called when the processor is going away. |
| 99 void StopAudioProcessing(); |
| 100 |
| 101 // Cached value for the render delay latency. This member is accessed by |
| 102 // both the capture audio thread and the render audio thread. |
| 103 base::subtle::Atomic32 render_delay_ms_; |
| 104 |
| 105 // webrtc::AudioProcessing module which does AEC, AGC, NS, HighPass filter, |
| 106 // ..etc. |
| 107 scoped_ptr<webrtc::AudioProcessing> audio_processing_; |
| 108 |
| 109 // Converter used for the down-mixing and resampling of the capture data. |
| 110 scoped_ptr<WebRtcAudioConverter> capture_converter_; |
| 111 |
| 112 // AudioFrame used to hold the output of |capture_converter_|. |
| 113 webrtc::AudioFrame capture_frame_; |
| 114 |
| 115 // Converter used for the down-mixing and resampling of the render data when |
| 116 // the AEC is enabled. |
| 117 scoped_ptr<WebRtcAudioConverter> render_converter_; |
| 118 |
| 119 // AudioFrame used to hold the output of |render_converter_|. |
| 120 webrtc::AudioFrame render_frame_; |
| 121 |
| 122 // Data bus to help converting interleaved data to an AudioBus. |
| 123 scoped_ptr<media::AudioBus> render_data_bus_; |
| 124 |
| 125 // Used to DCHECK that some methods are called on the main render thread. |
| 126 base::ThreadChecker main_thread_checker_; |
| 127 |
| 128 // Used to DCHECK that some methods are called on the capture audio thread. |
| 129 base::ThreadChecker capture_thread_checker_; |
| 130 |
| 131 // Used to DCHECK that PushRenderData() is called on the render audio thread. |
| 132 base::ThreadChecker render_thread_checker_; |
| 133 }; |
| 134 |
| 135 } // namespace content |
| 136 |
| 137 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_PROCESSOR_H_ |
OLD | NEW |