Chromium Code Reviews| Index: media/audio/pulse/pulse_input.cc |
| diff --git a/media/audio/pulse/pulse_input.cc b/media/audio/pulse/pulse_input.cc |
| index 6f241fbaff761ce50298bb382876a0184f730f73..6945fbc4d8b2127d1baa14e2e96864abf16f3d16 100644 |
| --- a/media/audio/pulse/pulse_input.cc |
| +++ b/media/audio/pulse/pulse_input.cc |
| @@ -217,16 +217,33 @@ void PulseAudioInputStream::SetVolume(double volume) { |
| } |
| double PulseAudioInputStream::GetVolume() { |
| - AutoPulseLock auto_lock(pa_mainloop_); |
| - if (!handle_) |
| + if (pa_threaded_mainloop_in_thread(pa_mainloop_)) { |
| + // When being called by the pulse thread, GetVolume() is asynchronous and |
| + // called under AutoPulseLock. |
| + if (!handle_) |
| + return 0.0; |
| + |
| + size_t index = pa_stream_get_device_index(handle_); |
| + pa_operation* operation = pa_context_get_source_info_by_index( |
| + pa_context_, index, &VolumeCallback, this); |
| + // Do not wait for the operation since we can't block the pulse thread. |
| + pa_operation_unref(operation); |
| + |
| + // Return zero and the callback will asynchronously update the |volume_|. |
| return 0.0; |
| + } else { |
| + // Called by other thread, put an AutoPulseLock and wait for the operation. |
| + AutoPulseLock auto_lock(pa_mainloop_); |
| + if (!handle_) |
| + return 0.0; |
| - size_t index = pa_stream_get_device_index(handle_); |
| - pa_operation* operation = pa_context_get_source_info_by_index( |
| - pa_context_, index, &VolumeCallback, this); |
| - WaitForOperationCompletion(pa_mainloop_, operation); |
| + size_t index = pa_stream_get_device_index(handle_); |
| + pa_operation* operation = pa_context_get_source_info_by_index( |
| + pa_context_, index, &VolumeCallback, this); |
| + WaitForOperationCompletion(pa_mainloop_, operation); |
| - return volume_; |
| + return volume_; |
| + } |
| } |
| // static, used by pa_stream_set_read_callback. |
| @@ -284,8 +301,11 @@ void PulseAudioInputStream::ReadData() { |
| // Update the AGC volume level once every second. Note that, |
| // |volume| is also updated each time SetVolume() is called |
| // through IPC by the render-side AGC. |
| + // QueryAgcVolume() will trigger a callback to asynchronously update the |
| + // |volume_|. |
|
DaleCurtis
2013/02/25 18:52:18
This needs some mention of the fact that the |norm
no longer working on chromium
2013/02/26 12:02:51
Done.
|
| double normalized_volume = 0.0; |
| QueryAgcVolume(&normalized_volume); |
| + normalized_volume = volume_ / GetMaxVolume(); |
| do { |
| size_t length = 0; |