diff --git a/src/output/OutputPlugin.cxx b/src/output/OutputPlugin.cxx index e90ba12a0..0f0b81ccf 100644 --- a/src/output/OutputPlugin.cxx +++ b/src/output/OutputPlugin.cxx @@ -63,12 +63,12 @@ ao_plugin_close(AudioOutput *ao) ao->plugin.close(ao); } -unsigned +std::chrono::steady_clock::duration ao_plugin_delay(AudioOutput *ao) { return ao->plugin.delay != nullptr ? ao->plugin.delay(ao) - : 0; + : std::chrono::steady_clock::duration::zero(); } void diff --git a/src/output/OutputPlugin.hxx b/src/output/OutputPlugin.hxx index a079be366..b25ee5135 100644 --- a/src/output/OutputPlugin.hxx +++ b/src/output/OutputPlugin.hxx @@ -22,6 +22,8 @@ #include "Compiler.h" +#include + #include struct ConfigBlock; @@ -97,9 +99,9 @@ struct AudioOutputPlugin { * instead of doing a sleep inside the plugin, because this * allows MPD to listen to commands meanwhile. * - * @return the number of milliseconds to wait + * @return the duration to wait */ - unsigned (*delay)(AudioOutput *data); + std::chrono::steady_clock::duration (*delay)(AudioOutput *data); /** * Display metadata for the next chunk. Optional method, @@ -179,7 +181,7 @@ void ao_plugin_close(AudioOutput *ao); gcc_pure -unsigned +std::chrono::steady_clock::duration ao_plugin_delay(AudioOutput *ao); void diff --git a/src/output/OutputThread.cxx b/src/output/OutputThread.cxx index 53d4ccab4..a5b57af5f 100644 --- a/src/output/OutputThread.cxx +++ b/src/output/OutputThread.cxx @@ -237,8 +237,8 @@ inline bool AudioOutput::WaitForDelay() { while (true) { - unsigned delay = ao_plugin_delay(this); - if (delay == 0) + const auto delay = ao_plugin_delay(this); + if (delay <= std::chrono::steady_clock::duration::zero()) return true; (void)cond.timed_wait(mutex, delay); diff --git a/src/output/Wrapper.hxx b/src/output/Wrapper.hxx index 69e389762..9af0f5b5f 100644 --- a/src/output/Wrapper.hxx +++ b/src/output/Wrapper.hxx @@ -22,6 +22,8 @@ #include "util/Cast.hxx" +#include + struct ConfigBlock; template @@ -61,7 +63,7 @@ struct AudioOutputWrapper { } gcc_pure - static unsigned Delay(AudioOutput *ao) { + static std::chrono::steady_clock::duration Delay(AudioOutput *ao) { T &t = Cast(*ao); return t.Delay(); } diff --git a/src/output/plugins/FifoOutputPlugin.cxx b/src/output/plugins/FifoOutputPlugin.cxx index f9ee3e5ae..24105441b 100644 --- a/src/output/plugins/FifoOutputPlugin.cxx +++ b/src/output/plugins/FifoOutputPlugin.cxx @@ -66,7 +66,7 @@ public: void Open(AudioFormat &audio_format); void Close(); - unsigned Delay() const; + std::chrono::steady_clock::duration Delay() const; size_t Play(const void *chunk, size_t size); void Cancel(); }; @@ -204,12 +204,12 @@ FifoOutput::Cancel() } } -inline unsigned +inline std::chrono::steady_clock::duration FifoOutput::Delay() const { return timer->IsStarted() - ? timer->GetDelay() - : 0; + ? std::chrono::milliseconds(timer->GetDelay()) + : std::chrono::steady_clock::duration::zero(); } inline size_t diff --git a/src/output/plugins/HaikuOutputPlugin.cxx b/src/output/plugins/HaikuOutputPlugin.cxx index 337a880d8..5ba82815d 100644 --- a/src/output/plugins/HaikuOutputPlugin.cxx +++ b/src/output/plugins/HaikuOutputPlugin.cxx @@ -79,7 +79,7 @@ public: size_t Play(const void *chunk, size_t size); void Cancel(); - size_t Delay(); + std::chrono::steady_clock::duration Delay(); void FillBuffer(void* _buffer, size_t size, gcc_unused const media_raw_audio_format& _format); @@ -308,7 +308,7 @@ HaikuOutput::Play(const void *chunk, size_t size) return size; } -inline size_t +inline std::chrono::steady_clock::duration HaikuOutput::Delay() { unsigned delay = buffer_filled ? 0 : buffer_delay; @@ -319,7 +319,7 @@ HaikuOutput::Delay() //return (delay / 2) ? 1 : 0; (void)delay; - return 0; + return std::chrono::steady_clock::duration::zero(); } inline void diff --git a/src/output/plugins/JackOutputPlugin.cxx b/src/output/plugins/JackOutputPlugin.cxx index 171bae2cc..c6a1f8d18 100644 --- a/src/output/plugins/JackOutputPlugin.cxx +++ b/src/output/plugins/JackOutputPlugin.cxx @@ -128,10 +128,10 @@ struct JackOutput { */ size_t WriteSamples(const float *src, size_t n_frames); - unsigned Delay() const { + std::chrono::steady_clock::duration Delay() const { return base.pause && pause && !shutdown - ? 1000 - : 0; + ? std::chrono::seconds(1) + : std::chrono::steady_clock::duration::zero(); } size_t Play(const void *chunk, size_t size); diff --git a/src/output/plugins/NullOutputPlugin.cxx b/src/output/plugins/NullOutputPlugin.cxx index 650910e68..b2b3ec951 100644 --- a/src/output/plugins/NullOutputPlugin.cxx +++ b/src/output/plugins/NullOutputPlugin.cxx @@ -49,10 +49,10 @@ public: delete timer; } - unsigned Delay() const { + std::chrono::steady_clock::duration Delay() const { return sync && timer->IsStarted() - ? timer->GetDelay() - : 0; + ? std::chrono::milliseconds(timer->GetDelay()) + : std::chrono::steady_clock::duration::zero(); } size_t Play(gcc_unused const void *chunk, size_t size) { diff --git a/src/output/plugins/OSXOutputPlugin.cxx b/src/output/plugins/OSXOutputPlugin.cxx index 2d357635a..232a10b8c 100644 --- a/src/output/plugins/OSXOutputPlugin.cxx +++ b/src/output/plugins/OSXOutputPlugin.cxx @@ -669,11 +669,13 @@ osx_output_play(AudioOutput *ao, const void *chunk, size_t size) return od->ring_buffer->push((uint8_t *)chunk, size); } -static unsigned +static std::chrono::steady_clock::duration osx_output_delay(AudioOutput *ao) { OSXOutput *od = (OSXOutput *)ao; - return od->ring_buffer->write_available() ? 0 : 25; + return od->ring_buffer->write_available() + ? std::chrono::steady_clock::duration::zero() + : std::chrono::milliseconds(25); } const struct AudioOutputPlugin osx_output_plugin = { diff --git a/src/output/plugins/OpenALOutputPlugin.cxx b/src/output/plugins/OpenALOutputPlugin.cxx index 0db98a2cb..7b72adcf2 100644 --- a/src/output/plugins/OpenALOutputPlugin.cxx +++ b/src/output/plugins/OpenALOutputPlugin.cxx @@ -58,13 +58,13 @@ class OpenALOutput { void Close(); gcc_pure - unsigned Delay() const { + std::chrono::steady_clock::duration Delay() const { return filled < NUM_BUFFERS || HasProcessed() - ? 0 + ? std::chrono::steady_clock::duration::zero() /* we don't know exactly how long we must wait for the next buffer to finish, so this is a random guess: */ - : 50; + : std::chrono::milliseconds(50); } size_t Play(const void *chunk, size_t size); diff --git a/src/output/plugins/PulseOutputPlugin.cxx b/src/output/plugins/PulseOutputPlugin.cxx index f71e54a12..1ec277785 100644 --- a/src/output/plugins/PulseOutputPlugin.cxx +++ b/src/output/plugins/PulseOutputPlugin.cxx @@ -101,7 +101,7 @@ public: void Open(AudioFormat &audio_format); void Close(); - unsigned Delay(); + std::chrono::steady_clock::duration Delay(); size_t Play(const void *chunk, size_t size); void Cancel(); bool Pause(); @@ -740,16 +740,16 @@ PulseOutput::StreamPause(bool pause) "pa_stream_cork() has failed"); } -inline unsigned +inline std::chrono::steady_clock::duration PulseOutput::Delay() { Pulse::LockGuard lock(mainloop); - unsigned result = 0; + auto result = std::chrono::steady_clock::duration::zero(); if (base.pause && pa_stream_is_corked(stream) && pa_stream_get_state(stream) == PA_STREAM_READY) /* idle while paused */ - result = 1000; + result = std::chrono::seconds(1); return result; } diff --git a/src/output/plugins/ShoutOutputPlugin.cxx b/src/output/plugins/ShoutOutputPlugin.cxx index 2bad712ad..80c54b351 100644 --- a/src/output/plugins/ShoutOutputPlugin.cxx +++ b/src/output/plugins/ShoutOutputPlugin.cxx @@ -63,7 +63,7 @@ struct ShoutOutput final { void Open(AudioFormat &audio_format); void Close(); - unsigned Delay() const; + std::chrono::steady_clock::duration Delay() const; void SendTag(const Tag &tag); size_t Play(const void *chunk, size_t size); void Cancel(); @@ -360,14 +360,14 @@ ShoutOutput::Open(AudioFormat &audio_format) } } -unsigned +std::chrono::steady_clock::duration ShoutOutput::Delay() const { int delay = shout_delay(shout_conn); if (delay < 0) delay = 0; - return delay; + return std::chrono::milliseconds(delay); } size_t diff --git a/src/output/plugins/SndioOutputPlugin.cxx b/src/output/plugins/SndioOutputPlugin.cxx index 8af2d223b..f9a3d1b66 100644 --- a/src/output/plugins/SndioOutputPlugin.cxx +++ b/src/output/plugins/SndioOutputPlugin.cxx @@ -51,7 +51,6 @@ public: void Open(AudioFormat &audio_format); void Close(); - unsigned Delay() const; size_t Play(const void *chunk, size_t size); void Cancel(); }; diff --git a/src/output/plugins/httpd/HttpdInternal.hxx b/src/output/plugins/httpd/HttpdInternal.hxx index 864720917..74363110d 100644 --- a/src/output/plugins/httpd/HttpdInternal.hxx +++ b/src/output/plugins/httpd/HttpdInternal.hxx @@ -218,7 +218,7 @@ public: void SendHeader(HttpdClient &client) const; gcc_pure - unsigned Delay() const; + std::chrono::steady_clock::duration Delay() const; /** * Reads data from the encoder (as much as available) and diff --git a/src/output/plugins/httpd/HttpdOutputPlugin.cxx b/src/output/plugins/httpd/HttpdOutputPlugin.cxx index fdd4ba072..8d9c3112e 100644 --- a/src/output/plugins/httpd/HttpdOutputPlugin.cxx +++ b/src/output/plugins/httpd/HttpdOutputPlugin.cxx @@ -344,7 +344,7 @@ HttpdOutput::SendHeader(HttpdClient &client) const client.PushPage(header); } -inline unsigned +inline std::chrono::steady_clock::duration HttpdOutput::Delay() const { if (!LockHasClients() && base.pause) { @@ -357,15 +357,15 @@ HttpdOutput::Delay() const /* some arbitrary delay that is long enough to avoid consuming too much CPU, and short enough to notice new clients quickly enough */ - return 1000; + return std::chrono::seconds(1); } return timer->IsStarted() - ? timer->GetDelay() - : 0; + ? std::chrono::milliseconds(timer->GetDelay()) + : std::chrono::steady_clock::duration::zero(); } -static unsigned +static std::chrono::steady_clock::duration httpd_output_delay(AudioOutput *ao) { HttpdOutput *httpd = HttpdOutput::Cast(ao); diff --git a/src/output/plugins/sles/SlesOutputPlugin.cxx b/src/output/plugins/sles/SlesOutputPlugin.cxx index 01264aaa6..274af1864 100644 --- a/src/output/plugins/sles/SlesOutputPlugin.cxx +++ b/src/output/plugins/sles/SlesOutputPlugin.cxx @@ -96,8 +96,10 @@ public: void Open(AudioFormat &audio_format); void Close(); - unsigned Delay() { - return pause && !cancel ? 100 : 0; + std::chrono::steady_clock::duration Delay() { + return pause && !cancel + ? std::chrono::milliseconds(100) + : std::chrono::steady_clock::duration::zero(); } size_t Play(const void *chunk, size_t size);