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 constraints, processes the data and outputs it in a unit of 10 ms | |
Henrik Grunell
2013/11/12 12:46:37
What constraints? Please add that to the comment.
Henrik Grunell
2013/11/12 12:46:37
Nit: This class/object doesn't actually process th
no longer working on chromium
2013/11/12 13:31:56
Done with specifying getUserMedia constraints.
no longer working on chromium
2013/11/12 13:31:56
I think it is the implementation details that it i
| |
33 // 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 // Processes a block of 10 ms data from the internal FIFO and outputs it via | |
45 // |out|. |out| is the address of the pointer that will be pointed to | |
46 // the post-processed data if the method is returning a true. The lifetime | |
47 // of the data represeted by |out| is guaranteed to outlive the method call. | |
48 // Returns true if the internal FIFO has at least 10ms data for processing, | |
Henrik Grunell
2013/11/12 12:46:37
Nit: 10 ms (add space between)
no longer working on chromium
2013/11/12 13:31:56
Done.
| |
49 // otherwise false. | |
50 // Called on the capture audio thread. | |
51 bool ProcessAndConsumeData(base::TimeDelta capture_delay, | |
Henrik Grunell
2013/11/12 12:46:37
Nit: The parameters are just passed on to the webr
no longer working on chromium
2013/11/12 13:31:56
Done.
| |
52 int volume, | |
53 bool key_pressed, | |
54 int16** out); | |
55 | |
56 // Called when the format of the capture data has changed. | |
57 // Called on the main render thread. | |
58 void SetCaptureFormat(const media::AudioParameters& source_params); | |
59 | |
60 // Push the render audio to WebRtc::AudioProcessing for analysis. This is | |
61 // needed iff echo processing is enabled. | |
62 // |render_audio| is the pointer to the render audio data, its format | |
63 // is specified by |sample_rate|, |number_of_channels| and |number_of_frames|. | |
64 // Called on the render audio thread. | |
65 void PushRenderData(const int16* render_audio, | |
66 int sample_rate, | |
67 int number_of_channels, | |
68 int number_of_frames, | |
69 base::TimeDelta render_delay); | |
70 | |
71 // The audio format of the output from the processor. | |
72 const media::AudioParameters& OutputFormat() const; | |
73 | |
74 // Accessor to check if the audio processing is enabled or not. | |
75 bool has_audio_processing() const { return audio_processing_.get() != NULL; } | |
76 | |
77 private: | |
78 class WebRtcAudioConverter; | |
79 | |
80 // Helper to initialize the WebRtc AudioProcessing. | |
81 void InitializeAudioProcessingModule( | |
82 const webrtc::MediaConstraintsInterface* constraints); | |
83 | |
84 // Helper to initialize the render converter. | |
85 void InitializeRenderConverterIfNeeded(int sample_rate, | |
86 int number_of_channels, | |
87 int frames_per_buffer); | |
88 | |
89 // Called by ProcessAndConsumeData(). | |
90 void ProcessData(webrtc::AudioFrame* audio_frame, | |
91 base::TimeDelta capture_delay, | |
92 int volume, | |
93 bool key_pressed); | |
94 | |
95 // Called when the processor is going away. | |
96 void StopAudioProcessing(); | |
97 | |
98 // Cached value for the render delay latency. | |
99 volatile base::subtle::Atomic32 render_delay_ms_; | |
100 | |
101 // WebRtc AudioProcessing module which does AEC, AGC, NS, HighPass filter, | |
102 // ..etc. | |
103 scoped_ptr<webrtc::AudioProcessing> audio_processing_; | |
104 | |
105 // Converter used for the down-mixing and resampling of the capture data. | |
106 scoped_ptr<WebRtcAudioConverter> capture_converter_; | |
107 | |
108 // AudioFrame used to hold the output of |capture_converter_|. | |
109 webrtc::AudioFrame capture_frame_; | |
110 | |
111 // Converter used for the down-mixing and resampling of the render data when | |
112 // the AEC is enabled. | |
113 scoped_ptr<WebRtcAudioConverter> render_converter_; | |
114 | |
115 // AudioFrame used to hold the output of |render_converter_|. | |
116 webrtc::AudioFrame render_frame_; | |
117 | |
118 // Data bus to help converting interleaved data to an AudioBus. | |
119 scoped_ptr<media::AudioBus> render_data_bus_; | |
120 | |
121 // Used to DCHECK that some methods are called on the main render thread. | |
122 base::ThreadChecker main_thread_checker_; | |
123 | |
124 // Used to DCHECK that some methods are called on the capture audio thread. | |
125 base::ThreadChecker capture_thread_checker_; | |
126 | |
127 // Used to DCHECK that PushRenderData() is called on the render audio thread. | |
128 base::ThreadChecker render_thread_checker_; | |
129 }; | |
130 | |
131 } // namespace content | |
132 | |
133 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_PROCESSOR_H_ | |
OLD | NEW |