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

Side by Side Diff: media/audio/pulse/pulse_input.cc

Issue 15563004: Improved AGC update scheme for the audio backend in Chrome (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added Start/Stop APIs for the AGC part Created 7 years, 6 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
« no previous file with comments | « media/audio/pulse/pulse_input.h ('k') | media/audio/win/audio_low_latency_input_win.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "media/audio/pulse/pulse_input.h" 5 #include "media/audio/pulse/pulse_input.h"
6 6
7 #include <pulse/pulseaudio.h> 7 #include <pulse/pulseaudio.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "media/audio/pulse/audio_manager_pulse.h" 10 #include "media/audio/pulse/audio_manager_pulse.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 59
60 void PulseAudioInputStream::Start(AudioInputCallback* callback) { 60 void PulseAudioInputStream::Start(AudioInputCallback* callback) {
61 DCHECK(thread_checker_.CalledOnValidThread()); 61 DCHECK(thread_checker_.CalledOnValidThread());
62 DCHECK(callback); 62 DCHECK(callback);
63 DCHECK(handle_); 63 DCHECK(handle_);
64 AutoPulseLock auto_lock(pa_mainloop_); 64 AutoPulseLock auto_lock(pa_mainloop_);
65 65
66 if (stream_started_) 66 if (stream_started_)
67 return; 67 return;
68 68
69 StartAgc();
70
69 // Clean up the old buffer. 71 // Clean up the old buffer.
70 pa_stream_drop(handle_); 72 pa_stream_drop(handle_);
71 buffer_->Clear(); 73 buffer_->Clear();
72 74
73 // Start the streaming. 75 // Start the streaming.
74 callback_ = callback; 76 callback_ = callback;
75 pa_stream_set_read_callback(handle_, &ReadCallback, this); 77 pa_stream_set_read_callback(handle_, &ReadCallback, this);
76 pa_stream_readable_size(handle_); 78 pa_stream_readable_size(handle_);
77 stream_started_ = true; 79 stream_started_ = true;
78 80
79 pa_operation* operation = pa_stream_cork(handle_, 0, NULL, NULL); 81 pa_operation* operation = pa_stream_cork(handle_, 0, NULL, NULL);
80 WaitForOperationCompletion(pa_mainloop_, operation); 82 WaitForOperationCompletion(pa_mainloop_, operation);
81 } 83 }
82 84
83 void PulseAudioInputStream::Stop() { 85 void PulseAudioInputStream::Stop() {
84 DCHECK(thread_checker_.CalledOnValidThread()); 86 DCHECK(thread_checker_.CalledOnValidThread());
85 AutoPulseLock auto_lock(pa_mainloop_); 87 AutoPulseLock auto_lock(pa_mainloop_);
86 if (!stream_started_) 88 if (!stream_started_)
87 return; 89 return;
88 90
91 StopAgc();
92
89 // Set the flag to false to stop filling new data to soundcard. 93 // Set the flag to false to stop filling new data to soundcard.
90 stream_started_ = false; 94 stream_started_ = false;
91 95
92 pa_operation* operation = pa_stream_flush(handle_, 96 pa_operation* operation = pa_stream_flush(handle_,
93 &pulse::StreamSuccessCallback, 97 &pulse::StreamSuccessCallback,
94 pa_mainloop_); 98 pa_mainloop_);
95 WaitForOperationCompletion(pa_mainloop_, operation); 99 WaitForOperationCompletion(pa_mainloop_, operation);
96 100
97 // Stop the stream. 101 // Stop the stream.
98 pa_stream_set_read_callback(handle_, NULL, NULL); 102 pa_stream_set_read_callback(handle_, NULL, NULL);
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 pa_threaded_mainloop_signal(stream->pa_mainloop_, 0); 243 pa_threaded_mainloop_signal(stream->pa_mainloop_, 0);
240 } 244 }
241 245
242 void PulseAudioInputStream::ReadData() { 246 void PulseAudioInputStream::ReadData() {
243 uint32 hardware_delay = pulse::GetHardwareLatencyInBytes( 247 uint32 hardware_delay = pulse::GetHardwareLatencyInBytes(
244 handle_, params_.sample_rate(), params_.GetBytesPerFrame()); 248 handle_, params_.sample_rate(), params_.GetBytesPerFrame());
245 249
246 // Update the AGC volume level once every second. Note that, 250 // Update the AGC volume level once every second. Note that,
247 // |volume| is also updated each time SetVolume() is called 251 // |volume| is also updated each time SetVolume() is called
248 // through IPC by the render-side AGC. 252 // through IPC by the render-side AGC.
249 // QueryAgcVolume() will trigger a callback to asynchronously update the 253 // We disregard the |normalized_volume| from GetAgcVolume()
250 // |volume_|, we disregard the |normalized_volume| from QueryAgcVolume()
251 // and use the value calculated by |volume_|. 254 // and use the value calculated by |volume_|.
252 double normalized_volume = 0.0; 255 double normalized_volume = 0.0;
253 QueryAgcVolume(&normalized_volume); 256 GetAgcVolume(&normalized_volume);
254 normalized_volume = volume_ / GetMaxVolume(); 257 normalized_volume = volume_ / GetMaxVolume();
255 258
256 do { 259 do {
257 size_t length = 0; 260 size_t length = 0;
258 const void* data = NULL; 261 const void* data = NULL;
259 pa_stream_peek(handle_, &data, &length); 262 pa_stream_peek(handle_, &data, &length);
260 if (!data || length == 0) 263 if (!data || length == 0)
261 break; 264 break;
262 265
263 buffer_->Append(reinterpret_cast<const uint8*>(data), length); 266 buffer_->Append(reinterpret_cast<const uint8*>(data), length);
(...skipping 15 matching lines...) Expand all
279 // input side. 282 // input side.
280 DVLOG(1) << "OnData is being called consecutively, sleep 5ms to " 283 DVLOG(1) << "OnData is being called consecutively, sleep 5ms to "
281 << "wait until render consumes the data"; 284 << "wait until render consumes the data";
282 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(5)); 285 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(5));
283 } 286 }
284 287
285 pa_threaded_mainloop_signal(pa_mainloop_, 0); 288 pa_threaded_mainloop_signal(pa_mainloop_, 0);
286 } 289 }
287 290
288 } // namespace media 291 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/pulse/pulse_input.h ('k') | media/audio/win/audio_low_latency_input_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698