Commit 9da57e74 authored by Pete Beardmore's avatar Pete Beardmore

PulseOutputPlugin: avoid locking mainloop object from within mainloop thread

-fixes regression introduced by: '8d6fedf8 [PATCH] Mixer: add class MixerListener' -listener.OnMixerVolumeChanged() called GetVolume() which attempted to acquire the lock but as per 'pa_threaded_mainloop_lock()' documentation: This function may not be called inside the event loop thread. Events that are dispatched from the event loop thread are executed with this lock held -this patch seperates the underlying action of GetVolume() into a new GetVolumeInternal() function, to be called only when the lock is already held, as is the case for the listener.OnMixerVolumeChanged() call
parent 3a3fb98f
...@@ -52,6 +52,7 @@ public: ...@@ -52,6 +52,7 @@ public:
void Offline(); void Offline();
void VolumeCallback(const pa_sink_input_info *i, int eol); void VolumeCallback(const pa_sink_input_info *i, int eol);
void Update(pa_context *context, pa_stream *stream); void Update(pa_context *context, pa_stream *stream);
int GetVolumeInternal(Error &error);
/* virtual methods from class Mixer */ /* virtual methods from class Mixer */
virtual bool Open(gcc_unused Error &error) override { virtual bool Open(gcc_unused Error &error) override {
...@@ -92,7 +93,7 @@ PulseMixer::VolumeCallback(const pa_sink_input_info *i, int eol) ...@@ -92,7 +93,7 @@ PulseMixer::VolumeCallback(const pa_sink_input_info *i, int eol)
online = true; online = true;
volume = i->volume; volume = i->volume;
listener.OnMixerVolumeChanged(*this, GetVolume(IgnoreError())); listener.OnMixerVolumeChanged(*this, GetVolumeInternal(IgnoreError()));
} }
/** /**
...@@ -187,15 +188,23 @@ PulseMixer::GetVolume(gcc_unused Error &error) ...@@ -187,15 +188,23 @@ PulseMixer::GetVolume(gcc_unused Error &error)
{ {
pulse_output_lock(output); pulse_output_lock(output);
int result = online int result = GetVolumeInternal(error);
? (int)((100 * (pa_cvolume_avg(&volume) + 1)) / PA_VOLUME_NORM)
: -1;
pulse_output_unlock(output); pulse_output_unlock(output);
return result; return result;
} }
/**
* Pulse mainloop lock must be held by caller
*/
int
PulseMixer::GetVolumeInternal(gcc_unused Error &error)
{
return online ?
(int)((100 * (pa_cvolume_avg(&volume) + 1)) / PA_VOLUME_NORM)
: -1;
}
bool bool
PulseMixer::SetVolume(unsigned new_volume, Error &error) PulseMixer::SetVolume(unsigned new_volume, Error &error)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment