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 | |
tommi (sloooow) - chröme
2013/11/21 19:52:03
Since AudioTrack isn't strictly speaking WebRTC sp
no longer working on chromium
2013/11/22 13:27:53
Changed it to webrtc::AudioProcessing, which is th
| |
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. | |
Henrik Grunell
2013/11/22 09:03:36
Are there any guarantees for how long the data poi
no longer working on chromium
2013/11/22 13:27:53
As explained in the comment, *|out| guarantees to
Henrik Grunell
2013/11/25 10:52:02
We talked about this offline too. I don't think th
no longer working on chromium
2013/11/25 16:46:35
I missed this one before, now it is done.
| |
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. | |
102 base::subtle::Atomic32 render_delay_ms_; | |
tommi (sloooow) - chröme
2013/11/21 19:52:03
can you add some comments on why it's an Atomic32
no longer working on chromium
2013/11/22 13:27:53
Done.
| |
103 | |
104 // WebRtc AudioProcessing module which does AEC, AGC, NS, HighPass filter, | |
105 // ..etc. | |
106 scoped_ptr<webrtc::AudioProcessing> audio_processing_; | |
107 | |
108 // Converter used for the down-mixing and resampling of the capture data. | |
109 scoped_ptr<WebRtcAudioConverter> capture_converter_; | |
110 | |
111 // AudioFrame used to hold the output of |capture_converter_|. | |
112 webrtc::AudioFrame capture_frame_; | |
113 | |
114 // Converter used for the down-mixing and resampling of the render data when | |
115 // the AEC is enabled. | |
116 scoped_ptr<WebRtcAudioConverter> render_converter_; | |
117 | |
118 // AudioFrame used to hold the output of |render_converter_|. | |
119 webrtc::AudioFrame render_frame_; | |
120 | |
121 // Data bus to help converting interleaved data to an AudioBus. | |
122 scoped_ptr<media::AudioBus> render_data_bus_; | |
123 | |
124 // Used to DCHECK that some methods are called on the main render thread. | |
125 base::ThreadChecker main_thread_checker_; | |
126 | |
127 // Used to DCHECK that some methods are called on the capture audio thread. | |
128 base::ThreadChecker capture_thread_checker_; | |
129 | |
130 // Used to DCHECK that PushRenderData() is called on the render audio thread. | |
131 base::ThreadChecker render_thread_checker_; | |
132 }; | |
133 | |
134 } // namespace content | |
135 | |
136 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_PROCESSOR_H_ | |
OLD | NEW |