Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(634)

Side by Side Diff: content/renderer/media/webrtc_audio_capturer.h

Issue 37793005: move the APM to chrome. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_WEBRTC_AUDIO_CAPTURER_H_ 5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_ 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_
7 7
8 #include <list> 8 #include <list>
9 #include <string> 9 #include <string>
10 10
11 #include "base/callback.h" 11 #include "base/callback.h"
12 #include "base/memory/ref_counted.h" 12 #include "base/memory/ref_counted.h"
13 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
14 #include "base/threading/thread_checker.h" 14 #include "base/threading/thread_checker.h"
15 #include "content/renderer/media/webrtc_audio_device_impl.h" 15 #include "content/renderer/media/webrtc_audio_device_impl.h"
16 #include "content/renderer/media/webrtc_local_audio_source_provider.h" 16 #include "content/renderer/media/webrtc_local_audio_source_provider.h"
17 #include "media/audio/audio_input_device.h" 17 #include "media/audio/audio_input_device.h"
18 #include "media/base/audio_capturer_source.h" 18 #include "media/base/audio_capturer_source.h"
19 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface .h"
19 20
20 namespace media { 21 namespace media {
21 class AudioBus; 22 class AudioBus;
22 } 23 }
23 24
24 namespace content { 25 namespace content {
25 26
27 class WebRtcAudioProcessingWrapper;
26 class WebRtcLocalAudioRenderer; 28 class WebRtcLocalAudioRenderer;
27 class WebRtcLocalAudioTrack; 29 class WebRtcLocalAudioTrack;
28 30
29 // This class manages the capture data flow by getting data from its 31 // This class manages the capture data flow by getting data from its
30 // |source_|, and passing it to its |tracks_|. 32 // |source_|, and passing it to its |tracks_|.
31 // It allows clients to inject their own capture data source by calling 33 // It allows clients to inject their own capture data source by calling
32 // SetCapturerSource(). 34 // SetCapturerSource().
33 // The threading model for this class is rather complex since it will be 35 // The threading model for this class is rather complex since it will be
34 // created on the main render thread, captured data is provided on a dedicated 36 // created on the main render thread, captured data is provided on a dedicated
35 // AudioInputDevice thread, and methods can be called either on the Libjingle 37 // AudioInputDevice thread, and methods can be called either on the Libjingle
(...skipping 12 matching lines...) Expand all
48 // consuming audio for capture. |session_id| is passed to the browser to 50 // consuming audio for capture. |session_id| is passed to the browser to
49 // decide which device to use. |device_id| is used to identify which device 51 // decide which device to use. |device_id| is used to identify which device
50 // the capturer is created for. Called on the main render thread. 52 // the capturer is created for. Called on the main render thread.
51 bool Initialize(int render_view_id, 53 bool Initialize(int render_view_id,
52 media::ChannelLayout channel_layout, 54 media::ChannelLayout channel_layout,
53 int sample_rate, 55 int sample_rate,
54 int buffer_size, 56 int buffer_size,
55 int session_id, 57 int session_id,
56 const std::string& device_id, 58 const std::string& device_id,
57 int paired_output_sample_rate, 59 int paired_output_sample_rate,
58 int paired_output_frames_per_buffer); 60 int paired_output_frames_per_buffer,
61 const webrtc::MediaConstraintsInterface* constraints);
59 62
60 // Add a audio track to the sinks of the capturer. 63 // Add a audio track to the sinks of the capturer.
61 // WebRtcAudioDeviceImpl calls this method on the main render thread but 64 // WebRtcAudioDeviceImpl calls this method on the main render thread but
62 // other clients may call it from other threads. The current implementation 65 // other clients may call it from other threads. The current implementation
63 // does not support multi-thread calling. 66 // does not support multi-thread calling.
64 // Called on the main render thread or libjingle working thread. 67 // Called on the main render thread or libjingle working thread.
65 void AddTrack(WebRtcLocalAudioTrack* track); 68 void AddTrack(WebRtcLocalAudioTrack* track);
66 69
67 // Remove a audio track from the sinks of the capturer. 70 // Remove a audio track from the sinks of the capturer.
68 // Called on the main render thread or libjingle working thread. 71 // Called on the main render thread or libjingle working thread.
69 void RemoveTrack(WebRtcLocalAudioTrack* track); 72 void RemoveTrack(WebRtcLocalAudioTrack* track);
70 73
71 // SetCapturerSource() is called if the client on the source side desires to 74 // InitializeCapturerSource() is called if the client on the source side
72 // provide their own captured audio data. Client is responsible for calling 75 // desires to provide their own captured audio data. Client is responsible
73 // Start() on its own source to have the ball rolling. 76 // for calling Start() on its own source to have the ball rolling.
74 // Called on the main render thread. 77 // Called on the main render thread.
75 void SetCapturerSource( 78 void InitializeCapturerSource(
76 const scoped_refptr<media::AudioCapturerSource>& source, 79 const scoped_refptr<media::AudioCapturerSource>& source,
77 media::ChannelLayout channel_layout, 80 media::ChannelLayout channel_layout,
78 float sample_rate); 81 float sample_rate,
82 const webrtc::MediaConstraintsInterface* constraints);
79 83
80 // Called when a stream is connecting to a peer connection. This will set 84 // Called when a stream is connecting to a peer connection. This will set
81 // up the native buffer size for the stream in order to optimize the 85 // up the native buffer size for the stream in order to optimize the
82 // performance for peer connection. 86 // performance for peer connection.
83 void EnablePeerConnectionMode(); 87 void EnablePeerConnectionMode();
84 88
89 void FeedRenderDataToAudioProcessing(const int16* render_audio,
90 int sample_rate,
91 int number_of_channels,
92 int number_of_frames,
93 int render_delay_ms);
94
85 // Volume APIs used by WebRtcAudioDeviceImpl. 95 // Volume APIs used by WebRtcAudioDeviceImpl.
86 // Called on the AudioInputDevice audio thread. 96 // Called on the AudioInputDevice audio thread.
87 void SetVolume(int volume); 97 void SetVolume(int volume);
88 int Volume() const; 98 int Volume() const;
89 int MaxVolume() const; 99 int MaxVolume() const;
90 100
91 // Enables or disables the WebRtc AGC control. 101 // Enables or disables the WebRtc AGC control.
92 // Called from a Libjingle working thread. 102 // Called from a Libjingle working thread.
93 void SetAutomaticGainControl(bool enable); 103 void SetAutomaticGainControl(bool enable);
94 104
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 // AudioCapturerSource::CaptureCallback implementation. 136 // AudioCapturerSource::CaptureCallback implementation.
127 // Called on the AudioInputDevice audio thread. 137 // Called on the AudioInputDevice audio thread.
128 virtual void Capture(media::AudioBus* audio_source, 138 virtual void Capture(media::AudioBus* audio_source,
129 int audio_delay_milliseconds, 139 int audio_delay_milliseconds,
130 double volume, 140 double volume,
131 bool key_pressed) OVERRIDE; 141 bool key_pressed) OVERRIDE;
132 virtual void OnCaptureError() OVERRIDE; 142 virtual void OnCaptureError() OVERRIDE;
133 143
134 // Reconfigures the capturer with a new capture parameters. 144 // Reconfigures the capturer with a new capture parameters.
135 // Must be called without holding the lock. 145 // Must be called without holding the lock.
136 void Reconfigure(int sample_rate, media::ChannelLayout channel_layout); 146 void Reconfigure(int sample_rate, media::ChannelLayout channel_layout,
147 const webrtc::MediaConstraintsInterface* constraints);
137 148
138 // Starts recording audio. 149 // Starts recording audio.
139 // Triggered by AddSink() on the main render thread or a Libjingle working 150 // Triggered by AddSink() on the main render thread or a Libjingle working
140 // thread. It should NOT be called under |lock_|. 151 // thread. It should NOT be called under |lock_|.
141 void Start(); 152 void Start();
142 153
143 // Stops recording audio. 154 // Stops recording audio.
144 // Triggered by RemoveSink() on the main render thread or a Libjingle working 155 // Triggered by RemoveSink() on the main render thread or a Libjingle working
145 // thread. It should NOT be called under |lock_|. 156 // thread. It should NOT be called under |lock_|.
146 void Stop(); 157 void Stop();
147 158
148 // Helper function to get the buffer size based on |peer_connection_mode_| 159 // Helper function to get the buffer size based on |peer_connection_mode_|
149 // and sample rate; 160 // and sample rate;
150 int GetBufferSize(int sample_rate) const; 161 int GetBufferSize(int sample_rate) const;
151 162
152 // Used to DCHECK that we are called on the correct thread. 163 // Used to DCHECK that we are called on the correct thread.
153 base::ThreadChecker thread_checker_; 164 base::ThreadChecker thread_checker_;
154 165
155 // Protects |source_|, |audio_tracks_|, |running_|, |loopback_fifo_|, 166 // Protects |source_|, |audio_tracks_|, |running_|, |loopback_fifo_|,
156 // |params_|, |buffering_| and |agc_is_enabled_|. 167 // |source_params_|, |buffering_| and |agc_is_enabled_|.
157 mutable base::Lock lock_; 168 mutable base::Lock lock_;
158 169
159 // A list of audio tracks that the audio data is fed to. 170 // A list of audio tracks that the audio data is fed to.
160 TrackList tracks_; 171 TrackList tracks_;
161 172
162 // The audio data source from the browser process. 173 // The audio data source from the browser process.
163 scoped_refptr<media::AudioCapturerSource> source_; 174 scoped_refptr<media::AudioCapturerSource> source_;
164 175
165 // Cached audio parameters for output. 176 // Cached audio parameters for the source.
166 media::AudioParameters params_; 177 media::AudioParameters source_params_;
178
179 // Cached audio parameters for the sinks.
180 media::AudioParameters sink_params_;
167 181
168 bool running_; 182 bool running_;
169 183
170 // True when automatic gain control is enabled, false otherwise. 184 // True when automatic gain control is enabled, false otherwise.
171 bool agc_is_enabled_; 185 bool agc_is_enabled_;
172 186
173 int render_view_id_; 187 int render_view_id_;
174 188
175 // Cached value for the hardware native buffer size, used when 189 // Cached value for the hardware native buffer size, used when
176 // |peer_connection_mode_| is set to false. 190 // |peer_connection_mode_| is set to false.
(...skipping 15 matching lines...) Expand all
192 // TODO(xians): Move the source provider to track once we don't need to feed 206 // TODO(xians): Move the source provider to track once we don't need to feed
193 // delay, volume, key_pressed information to WebAudioCapturerSource. 207 // delay, volume, key_pressed information to WebAudioCapturerSource.
194 const scoped_ptr<WebRtcLocalAudioSourceProvider> source_provider_; 208 const scoped_ptr<WebRtcLocalAudioSourceProvider> source_provider_;
195 209
196 // Flag which affects the buffer size used by the capturer. 210 // Flag which affects the buffer size used by the capturer.
197 bool peer_connection_mode_; 211 bool peer_connection_mode_;
198 212
199 int output_sample_rate_; 213 int output_sample_rate_;
200 int output_frames_per_buffer_; 214 int output_frames_per_buffer_;
201 215
216 scoped_ptr<WebRtcAudioProcessingWrapper> audio_processing_;
217
202 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioCapturer); 218 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioCapturer);
203 }; 219 };
204 220
205 } // namespace content 221 } // namespace content
206 222
207 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_ 223 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_CAPTURER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698