output/pulse: move code to virtual method Drain()

Drain only if it was requested explicitly.
This commit is contained in:
Max Kellermann 2021-02-15 14:27:19 +01:00
parent def120aca4
commit c2bc3704e1
1 changed files with 18 additions and 11 deletions

View File

@ -111,6 +111,7 @@ public:
[[nodiscard]] std::chrono::steady_clock::duration Delay() const noexcept override;
size_t Play(const void *chunk, size_t size) override;
void Drain() override;
void Cancel() noexcept override;
bool Pause() override;
@ -696,17 +697,6 @@ PulseOutput::Close() noexcept
Pulse::LockGuard lock(mainloop);
if (pa_stream_get_state(stream) == PA_STREAM_READY) {
pa_operation *o =
pa_stream_drain(stream,
pulse_output_stream_success_cb, this);
if (o == nullptr) {
LogPulseError(context,
"pa_stream_drain() has failed");
} else
pulse_wait_for_operation(mainloop, o);
}
DeleteStream();
if (context != nullptr &&
@ -835,6 +825,23 @@ PulseOutput::Play(const void *chunk, size_t size)
return size;
}
void
PulseOutput::Drain()
{
Pulse::LockGuard lock(mainloop);
if (pa_stream_get_state(stream) != PA_STREAM_READY)
return;
pa_operation *o =
pa_stream_drain(stream,
pulse_output_stream_success_cb, this);
if (o == nullptr)
throw MakePulseError(context, "pa_stream_drain() failed");
pulse_wait_for_operation(mainloop, o);
}
void
PulseOutput::Cancel() noexcept
{