OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_PROCESSOR_H_ | 5 #ifndef CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_PROCESSOR_H_ |
6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_PROCESSOR_H_ | 6 #define CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_PROCESSOR_H_ |
7 | 7 |
8 #include "base/atomicops.h" | 8 #include "base/atomicops.h" |
9 #include "base/synchronization/lock.h" | 9 #include "base/synchronization/lock.h" |
10 #include "base/threading/thread_checker.h" | 10 #include "base/threading/thread_checker.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 int sample_rate, | 56 int sample_rate, |
57 int number_of_channels, | 57 int number_of_channels, |
58 int number_of_frames, | 58 int number_of_frames, |
59 base::TimeDelta render_delay); | 59 base::TimeDelta render_delay); |
60 | 60 |
61 // Processes a block of 10 ms data from the internal FIFO and outputs it via | 61 // Processes a block of 10 ms data from the internal FIFO and outputs it via |
62 // |out|. |out| is the address of the pointer that will be pointed to | 62 // |out|. |out| is the address of the pointer that will be pointed to |
63 // the post-processed data if the method is returning a true. The lifetime | 63 // the post-processed data if the method is returning a true. The lifetime |
64 // of the data represeted by |out| is guaranteed to outlive the method call. | 64 // of the data represeted by |out| is guaranteed to outlive the method call. |
65 // That also says *|out| won't change until this method is called again. | 65 // That also says *|out| won't change until this method is called again. |
| 66 // |new_volume| receives the new microphone volume from the AGC. |
| 67 // The new microphoen volume range is [0, 255], and the value will be 0 if |
| 68 // the microphone volume should not be adjusted. |
66 // Returns true if the internal FIFO has at least 10 ms data for processing, | 69 // Returns true if the internal FIFO has at least 10 ms data for processing, |
67 // otherwise false. | 70 // otherwise false. |
68 // |capture_delay|, |volume| and |key_pressed| will be passed to | 71 // |capture_delay|, |volume| and |key_pressed| will be passed to |
69 // webrtc::AudioProcessing to help processing the data. | 72 // webrtc::AudioProcessing to help processing the data. |
70 // Called on the capture audio thread. | 73 // Called on the capture audio thread. |
71 bool ProcessAndConsumeData(base::TimeDelta capture_delay, | 74 bool ProcessAndConsumeData(base::TimeDelta capture_delay, |
72 int volume, | 75 int volume, |
73 bool key_pressed, | 76 bool key_pressed, |
| 77 int* new_volume, |
74 int16** out); | 78 int16** out); |
75 | 79 |
76 | 80 |
77 // The audio format of the input to the processor. | 81 // The audio format of the input to the processor. |
78 const media::AudioParameters& InputFormat() const; | 82 const media::AudioParameters& InputFormat() const; |
79 | 83 |
80 // The audio format of the output from the processor. | 84 // The audio format of the output from the processor. |
81 const media::AudioParameters& OutputFormat() const; | 85 const media::AudioParameters& OutputFormat() const; |
82 | 86 |
83 // Accessor to check if the audio processing is enabled or not. | 87 // Accessor to check if the audio processing is enabled or not. |
84 bool has_audio_processing() const { return audio_processing_ != NULL; } | 88 bool has_audio_processing() const { return audio_processing_ != NULL; } |
85 | 89 |
86 protected: | 90 protected: |
87 friend class base::RefCountedThreadSafe<MediaStreamAudioProcessor>; | 91 friend class base::RefCountedThreadSafe<MediaStreamAudioProcessor>; |
88 virtual ~MediaStreamAudioProcessor(); | 92 virtual ~MediaStreamAudioProcessor(); |
89 | 93 |
90 private: | 94 private: |
| 95 friend class MediaStreamAudioProcessorTest; |
| 96 |
91 class MediaStreamAudioConverter; | 97 class MediaStreamAudioConverter; |
92 | 98 |
93 // Helper to initialize the WebRtc AudioProcessing. | 99 // Helper to initialize the WebRtc AudioProcessing. |
94 void InitializeAudioProcessingModule( | 100 void InitializeAudioProcessingModule( |
95 const blink::WebMediaConstraints& constraints, int effects); | 101 const blink::WebMediaConstraints& constraints, int effects); |
96 | 102 |
97 // Helper to initialize the capture converter. | 103 // Helper to initialize the capture converter. |
98 void InitializeCaptureConverter(const media::AudioParameters& source_params); | 104 void InitializeCaptureConverter(const media::AudioParameters& source_params); |
99 | 105 |
100 // Helper to initialize the render converter. | 106 // Helper to initialize the render converter. |
101 void InitializeRenderConverterIfNeeded(int sample_rate, | 107 void InitializeRenderConverterIfNeeded(int sample_rate, |
102 int number_of_channels, | 108 int number_of_channels, |
103 int frames_per_buffer); | 109 int frames_per_buffer); |
104 | 110 |
105 // Called by ProcessAndConsumeData(). | 111 // Called by ProcessAndConsumeData(). |
106 void ProcessData(webrtc::AudioFrame* audio_frame, | 112 // Returns the new microphone volume in the range of |0, 255]. |
107 base::TimeDelta capture_delay, | 113 // When the volume does not need to be updated, it returns 0. |
108 int volume, | 114 int ProcessData(webrtc::AudioFrame* audio_frame, |
109 bool key_pressed); | 115 base::TimeDelta capture_delay, |
| 116 int volume, |
| 117 bool key_pressed); |
110 | 118 |
111 // Called when the processor is going away. | 119 // Called when the processor is going away. |
112 void StopAudioProcessing(); | 120 void StopAudioProcessing(); |
113 | 121 |
114 // Cached value for the render delay latency. This member is accessed by | 122 // Cached value for the render delay latency. This member is accessed by |
115 // both the capture audio thread and the render audio thread. | 123 // both the capture audio thread and the render audio thread. |
116 base::subtle::Atomic32 render_delay_ms_; | 124 base::subtle::Atomic32 render_delay_ms_; |
117 | 125 |
118 // webrtc::AudioProcessing module which does AEC, AGC, NS, HighPass filter, | 126 // webrtc::AudioProcessing module which does AEC, AGC, NS, HighPass filter, |
119 // ..etc. | 127 // ..etc. |
(...skipping 16 matching lines...) Expand all Loading... |
136 scoped_ptr<media::AudioBus> render_data_bus_; | 144 scoped_ptr<media::AudioBus> render_data_bus_; |
137 | 145 |
138 // Used to DCHECK that some methods are called on the main render thread. | 146 // Used to DCHECK that some methods are called on the main render thread. |
139 base::ThreadChecker main_thread_checker_; | 147 base::ThreadChecker main_thread_checker_; |
140 | 148 |
141 // Used to DCHECK that some methods are called on the capture audio thread. | 149 // Used to DCHECK that some methods are called on the capture audio thread. |
142 base::ThreadChecker capture_thread_checker_; | 150 base::ThreadChecker capture_thread_checker_; |
143 | 151 |
144 // Used to DCHECK that PushRenderData() is called on the render audio thread. | 152 // Used to DCHECK that PushRenderData() is called on the render audio thread. |
145 base::ThreadChecker render_thread_checker_; | 153 base::ThreadChecker render_thread_checker_; |
| 154 |
| 155 // Flag to enable the stereo channels mirroring. |
| 156 bool audio_mirroring_; |
146 }; | 157 }; |
147 | 158 |
148 } // namespace content | 159 } // namespace content |
149 | 160 |
150 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_PROCESSOR_H_ | 161 #endif // CONTENT_RENDERER_MEDIA_MEDIA_STREAM_AUDIO_PROCESSOR_H_ |
OLD | NEW |