Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "media/audio/audio_device_description.h" | 10 #include "media/audio/audio_device_description.h" |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 263 | 263 |
| 264 if (s && stream->callback_ && | 264 if (s && stream->callback_ && |
| 265 pa_stream_get_state(s) == PA_STREAM_FAILED) { | 265 pa_stream_get_state(s) == PA_STREAM_FAILED) { |
| 266 stream->callback_->OnError(stream); | 266 stream->callback_->OnError(stream); |
| 267 } | 267 } |
| 268 | 268 |
| 269 pa_threaded_mainloop_signal(stream->pa_mainloop_, 0); | 269 pa_threaded_mainloop_signal(stream->pa_mainloop_, 0); |
| 270 } | 270 } |
| 271 | 271 |
| 272 void PulseAudioInputStream::ReadData() { | 272 void PulseAudioInputStream::ReadData() { |
| 273 uint32_t hardware_delay = pulse::GetHardwareLatencyInBytes( | 273 base::TimeDelta hardware_delay = pulse::GetHardwareLatency(handle_); |
| 274 handle_, params_.sample_rate(), params_.GetBytesPerFrame()); | |
| 275 | 274 |
| 276 // Update the AGC volume level once every second. Note that, | 275 // Update the AGC volume level once every second. Note that, |
| 277 // |volume| is also updated each time SetVolume() is called | 276 // |volume| is also updated each time SetVolume() is called |
| 278 // through IPC by the render-side AGC. | 277 // through IPC by the render-side AGC. |
| 279 // We disregard the |normalized_volume| from GetAgcVolume() | 278 // We disregard the |normalized_volume| from GetAgcVolume() |
| 280 // and use the value calculated by |volume_|. | 279 // and use the value calculated by |volume_|. |
| 281 double normalized_volume = 0.0; | 280 double normalized_volume = 0.0; |
| 282 GetAgcVolume(&normalized_volume); | 281 GetAgcVolume(&normalized_volume); |
| 283 normalized_volume = volume_ / GetMaxVolume(); | 282 normalized_volume = volume_ / GetMaxVolume(); |
| 284 | 283 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 302 fifo_.Push(data, number_of_frames, params_.bits_per_sample() / 8); | 301 fifo_.Push(data, number_of_frames, params_.bits_per_sample() / 8); |
| 303 | 302 |
| 304 // Checks if we still have data. | 303 // Checks if we still have data. |
| 305 pa_stream_drop(handle_); | 304 pa_stream_drop(handle_); |
| 306 } while (pa_stream_readable_size(handle_) > 0); | 305 } while (pa_stream_readable_size(handle_) > 0); |
| 307 | 306 |
| 308 while (fifo_.available_blocks()) { | 307 while (fifo_.available_blocks()) { |
| 309 const AudioBus* audio_bus = fifo_.Consume(); | 308 const AudioBus* audio_bus = fifo_.Consume(); |
| 310 | 309 |
| 311 // Compensate the audio delay caused by the FIFO. | 310 // Compensate the audio delay caused by the FIFO. |
| 312 hardware_delay += fifo_.GetAvailableFrames() * params_.GetBytesPerFrame(); | 311 hardware_delay += base::TimeDelta::FromSecondsD( |
| 313 callback_->OnData(this, audio_bus, hardware_delay, normalized_volume); | 312 fifo_.GetAvailableFrames() / |
| 313 static_cast<double>(params_.sample_rate())); | |
|
o1ka
2017/02/10 13:28:50
I'm not sure if this is a good enough approximatio
DaleCurtis
2017/02/11 01:43:13
It's a good question, the answer is they don't. I'
| |
| 314 callback_->OnData(this, audio_bus, hardware_delay, base::TimeTicks::Now(), | |
| 315 normalized_volume); | |
| 314 | 316 |
| 315 // Sleep 5ms to wait until render consumes the data in order to avoid | 317 // Sleep 5ms to wait until render consumes the data in order to avoid |
| 316 // back to back OnData() method. | 318 // back to back OnData() method. |
| 317 if (fifo_.available_blocks()) | 319 if (fifo_.available_blocks()) |
| 318 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(5)); | 320 base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(5)); |
| 319 } | 321 } |
| 320 | 322 |
| 321 pa_threaded_mainloop_signal(pa_mainloop_, 0); | 323 pa_threaded_mainloop_signal(pa_mainloop_, 0); |
| 322 } | 324 } |
| 323 | 325 |
| 324 bool PulseAudioInputStream::GetSourceInformation(pa_source_info_cb_t callback) { | 326 bool PulseAudioInputStream::GetSourceInformation(pa_source_info_cb_t callback) { |
| 325 AutoPulseLock auto_lock(pa_mainloop_); | 327 AutoPulseLock auto_lock(pa_mainloop_); |
| 326 if (!handle_) | 328 if (!handle_) |
| 327 return false; | 329 return false; |
| 328 | 330 |
| 329 size_t index = pa_stream_get_device_index(handle_); | 331 size_t index = pa_stream_get_device_index(handle_); |
| 330 pa_operation* operation = | 332 pa_operation* operation = |
| 331 pa_context_get_source_info_by_index(pa_context_, index, callback, this); | 333 pa_context_get_source_info_by_index(pa_context_, index, callback, this); |
| 332 WaitForOperationCompletion(pa_mainloop_, operation); | 334 WaitForOperationCompletion(pa_mainloop_, operation); |
| 333 return true; | 335 return true; |
| 334 } | 336 } |
| 335 | 337 |
| 336 } // namespace media | 338 } // namespace media |
| OLD | NEW |