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 14ef242759a68d48db6da943ebb899b1089c3cf6..3043f6a96902c748f62b5ef4fcc37ef5863294cb 100644 |
| --- a/media/audio/pulse/pulse_input.cc |
| +++ b/media/audio/pulse/pulse_input.cc |
| @@ -4,8 +4,6 @@ |
| #include "media/audio/pulse/pulse_input.h" |
| -#include <pulse/pulseaudio.h> |
| - |
| #include "base/logging.h" |
| #include "media/audio/pulse/audio_manager_pulse.h" |
| #include "media/audio/pulse/pulse_util.h" |
| @@ -30,6 +28,7 @@ PulseAudioInputStream::PulseAudioInputStream(AudioManagerPulse* audio_manager, |
| channels_(0), |
| volume_(0.0), |
| stream_started_(false), |
| + muted_(false), |
| fifo_(params.channels(), |
| params.frames_per_buffer(), |
| kNumberOfBlocksBufferInFifo), |
| @@ -185,20 +184,17 @@ double PulseAudioInputStream::GetVolume() { |
| // 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); |
| - |
| + GetSourceInformation(&VolumeCallback); |
| return volume_; |
| } |
| } |
| +bool PulseAudioInputStream::IsMuted() { |
| + DCHECK(thread_checker_.CalledOnValidThread()); |
| + GetSourceInformation(&MuteCallback); |
| + return muted_; |
| +} |
| + |
| // static, used by pa_stream_set_read_callback. |
| void PulseAudioInputStream::ReadCallback(pa_stream* handle, |
| size_t length, |
| @@ -236,6 +232,22 @@ void PulseAudioInputStream::VolumeCallback(pa_context* context, |
| stream->volume_ = static_cast<double>(volume); |
| } |
| +// static, used by pa_context_get_source_info_by_index. |
| +void PulseAudioInputStream::MuteCallback(pa_context* context, |
|
tommi (sloooow) - chröme
2014/10/15 17:00:48
on which thread does this callback run? Is it saf
henrika (OOO until Aug 14)
2014/10/16 09:58:00
Done.
henrika (OOO until Aug 14)
2014/10/16 09:58:00
Based on off-line discussion. Will add comment.
|
| + const pa_source_info* info, |
| + int error, |
| + void* user_data) { |
| + PulseAudioInputStream* stream = |
| + reinterpret_cast<PulseAudioInputStream*>(user_data); |
| + |
| + if (error) { |
| + pa_threaded_mainloop_signal(stream->pa_mainloop_, 0); |
|
tommi (sloooow) - chröme
2014/10/15 17:00:48
Can you document why we need to call this here and
henrika (OOO until Aug 14)
2014/10/16 09:58:00
Discussed off-line.
|
| + return; |
| + } |
| + |
| + stream->muted_ = static_cast<bool>(info->mute); |
|
tommi (sloooow) - chröme
2014/10/15 17:00:48
stream->muted_ = info->mute != 0;
henrika (OOO until Aug 14)
2014/10/16 09:58:00
Done.
|
| +} |
| + |
| // static, used by pa_stream_set_state_callback. |
| void PulseAudioInputStream::StreamNotifyCallback(pa_stream* s, |
| void* user_data) { |
| @@ -301,4 +313,16 @@ void PulseAudioInputStream::ReadData() { |
| pa_threaded_mainloop_signal(pa_mainloop_, 0); |
| } |
| +bool PulseAudioInputStream::GetSourceInformation(pa_source_info_cb_t callback) { |
| + AutoPulseLock auto_lock(pa_mainloop_); |
| + if (!handle_) |
| + return false; |
| + |
| + size_t index = pa_stream_get_device_index(handle_); |
| + pa_operation* operation = |
| + pa_context_get_source_info_by_index(pa_context_, index, callback, this); |
| + WaitForOperationCompletion(pa_mainloop_, operation); |
| + return true; |
| +} |
| + |
| } // namespace media |