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

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

Issue 9702019: Adds Analog Gain Control (AGC) to the WebRTC client. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Improved AGC comments Created 8 years, 9 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_DEVICE_IMPL_H_ 5 #ifndef CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_DEVICE_IMPL_H_
6 #define CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_DEVICE_IMPL_H_ 6 #define CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_DEVICE_IMPL_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 // .---------------------. 84 // .---------------------.
85 // 85 //
86 // (*) Using SyncSocket for inter-process synchronization with low latency. 86 // (*) Using SyncSocket for inter-process synchronization with low latency.
87 // The actual data is transferred via SharedMemory. IPC is not involved 87 // The actual data is transferred via SharedMemory. IPC is not involved
88 // in the actual media transfer. 88 // in the actual media transfer.
89 // 89 //
90 // Implementation notes: 90 // Implementation notes:
91 // 91 //
92 // - This class must be created on the main render thread. 92 // - This class must be created on the main render thread.
93 // - The webrtc::AudioDeviceModule is reference counted. 93 // - The webrtc::AudioDeviceModule is reference counted.
94 // - Recording is currently not supported on Mac OS X. 94 // - Regarding the AGC: It aims at maintaining the same speech loudness level
tommi (sloooow) - chröme 2012/03/26 15:26:40 s/It aims at maintaining/It aims to maintain It's
henrika (OOO until Aug 14) 2012/03/27 09:20:38 Modified to "It aims to maintain a constant speech
95 // from the microphone. This is done by both controlling the analog
96 // microphone gain and applying a digital gain. The microphone gain on the
tommi (sloooow) - chröme 2012/03/26 15:26:40 s/a digital gain/digital gain
henrika (OOO until Aug 14) 2012/03/27 09:20:38 Done.
97 // sound card is slowly increased/decreased during speech only. By observing
98 // the microphone control slider you can see it move when you speak. If you
99 // scream, the slider moves downwards and then upwards again when you return
100 // to normal. It is not uncommon that the slider hits the maximum. This
101 // means that the maximum analog gain is not large enough to give the
102 // desired loudness. Nevertheless, we can in general still attain the
103 // desired loudness. If the microphone control slider is moved manually,
104 // the analog adaptation restarts and returns to roughly the same position
tommi (sloooow) - chröme 2012/03/26 15:26:40 s/analog adaptation/gain adaptation.
henrika (OOO until Aug 14) 2012/03/27 09:20:38 Actually, it is only the analog part that restarts
105 // as before the change if the circumstances are still the same. When the
106 // input microphone signal causes saturation, the level is decreased
107 // dramatically and has to re-adapt towards the old level. The adaptation
108 // is a slowly varying process and at the beginning of a call this is
tommi (sloooow) - chröme 2012/03/26 15:26:40 s/beginning of a call/beginning of capture (there
henrika (OOO until Aug 14) 2012/03/27 09:20:38 Done.
109 // noticed by a slow increase in volume. Smaller changes in microphone input
110 // level is leveled out by the built-in digital control. For larger
111 // differences we need to rely on the slow adaptation.
95 // 112 //
96 class CONTENT_EXPORT WebRtcAudioDeviceImpl 113 class CONTENT_EXPORT WebRtcAudioDeviceImpl
97 : NON_EXPORTED_BASE(public webrtc::AudioDeviceModule), 114 : NON_EXPORTED_BASE(public webrtc::AudioDeviceModule),
98 public media::AudioRendererSink::RenderCallback, 115 public media::AudioRendererSink::RenderCallback,
99 public AudioInputDevice::CaptureCallback, 116 public AudioInputDevice::CaptureCallback,
100 public AudioInputDevice::CaptureEventHandler { 117 public AudioInputDevice::CaptureEventHandler {
101 public: 118 public:
102 // Methods called on main render thread. 119 // Methods called on main render thread.
103 WebRtcAudioDeviceImpl(); 120 WebRtcAudioDeviceImpl();
104 121
105 // webrtc::RefCountedModule implementation. 122 // webrtc::RefCountedModule implementation.
106 // The creator must call AddRef() after construction and use Release() 123 // The creator must call AddRef() after construction and use Release()
107 // to release the reference and delete this object. 124 // to release the reference and delete this object.
108 virtual int32_t AddRef() OVERRIDE; 125 virtual int32_t AddRef() OVERRIDE;
109 virtual int32_t Release() OVERRIDE; 126 virtual int32_t Release() OVERRIDE;
110 127
111 // We need this one to support runnable method tasks. 128 // We need this one to support runnable method tasks.
112 static bool ImplementsThreadSafeReferenceCounting() { return true; } 129 static bool ImplementsThreadSafeReferenceCounting() { return true; }
113 130
114 // AudioDevice::RenderCallback implementation. 131 // AudioDevice::RenderCallback implementation.
115 virtual size_t Render(const std::vector<float*>& audio_data, 132 virtual size_t Render(const std::vector<float*>& audio_data,
116 size_t number_of_frames, 133 size_t number_of_frames,
117 size_t audio_delay_milliseconds) OVERRIDE; 134 size_t audio_delay_milliseconds) OVERRIDE;
118 virtual void OnRenderError() OVERRIDE; 135 virtual void OnRenderError() OVERRIDE;
119 136
120 // AudioInputDevice::CaptureCallback implementation. 137 // AudioInputDevice::CaptureCallback implementation.
121 virtual void Capture(const std::vector<float*>& audio_data, 138 virtual void Capture(const std::vector<float*>& audio_data,
122 size_t number_of_frames, 139 size_t number_of_frames,
123 size_t audio_delay_milliseconds) OVERRIDE; 140 size_t audio_delay_milliseconds,
141 double volume) OVERRIDE;
124 virtual void OnCaptureError() OVERRIDE; 142 virtual void OnCaptureError() OVERRIDE;
125 143
126 // AudioInputDevice::CaptureEventHandler implementation. 144 // AudioInputDevice::CaptureEventHandler implementation.
127 virtual void OnDeviceStarted(const std::string& device_id) OVERRIDE; 145 virtual void OnDeviceStarted(const std::string& device_id) OVERRIDE;
128 virtual void OnDeviceStopped() OVERRIDE; 146 virtual void OnDeviceStopped() OVERRIDE;
129 147
130 // webrtc::Module implementation. 148 // webrtc::Module implementation.
131 virtual int32_t ChangeUniqueId(const int32_t id) OVERRIDE; 149 virtual int32_t ChangeUniqueId(const int32_t id) OVERRIDE;
132 virtual int32_t TimeUntilNextProcess() OVERRIDE; 150 virtual int32_t TimeUntilNextProcess() OVERRIDE;
133 virtual int32_t Process() OVERRIDE; 151 virtual int32_t Process() OVERRIDE;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 virtual int32_t GetLoudspeakerStatus(bool* enabled) const OVERRIDE; 269 virtual int32_t GetLoudspeakerStatus(bool* enabled) const OVERRIDE;
252 270
253 // Sets the session id. 271 // Sets the session id.
254 void SetSessionId(int session_id); 272 void SetSessionId(int session_id);
255 273
256 // Accessors. 274 // Accessors.
257 size_t input_buffer_size() const { 275 size_t input_buffer_size() const {
258 return input_audio_parameters_.frames_per_buffer(); 276 return input_audio_parameters_.frames_per_buffer();
259 } 277 }
260 size_t output_buffer_size() const { 278 size_t output_buffer_size() const {
261 return input_audio_parameters_.frames_per_buffer(); 279 return output_audio_parameters_.frames_per_buffer();
262 } 280 }
263 int input_channels() const { 281 int input_channels() const {
264 return input_audio_parameters_.channels(); 282 return input_audio_parameters_.channels();
265 } 283 }
266 int output_channels() const { 284 int output_channels() const {
267 return output_audio_parameters_.channels(); 285 return output_audio_parameters_.channels();
268 } 286 }
269 int input_sample_rate() const { 287 int input_sample_rate() const {
270 return input_audio_parameters_.sample_rate(); 288 return input_audio_parameters_.sample_rate();
271 } 289 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 347
330 // Protects |recording_|, |output_delay_ms_|, |input_delay_ms_|. 348 // Protects |recording_|, |output_delay_ms_|, |input_delay_ms_|.
331 mutable base::Lock lock_; 349 mutable base::Lock lock_;
332 350
333 int bytes_per_sample_; 351 int bytes_per_sample_;
334 352
335 bool initialized_; 353 bool initialized_;
336 bool playing_; 354 bool playing_;
337 bool recording_; 355 bool recording_;
338 356
357 // Local copy of the current Automatic Gain Control state.
358 bool agc_is_enabled_;
359
339 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioDeviceImpl); 360 DISALLOW_COPY_AND_ASSIGN(WebRtcAudioDeviceImpl);
340 }; 361 };
341 362
342 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_DEVICE_IMPL_H_ 363 #endif // CONTENT_RENDERER_MEDIA_WEBRTC_AUDIO_DEVICE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698