output/Plugin: delay() returns std::chrono::steady_clock::duration

This commit is contained in:
Max Kellermann 2016-12-28 21:44:18 +01:00
parent 871ba5a488
commit d5e422970c
16 changed files with 49 additions and 42 deletions

View File

@ -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

View File

@ -22,6 +22,8 @@
#include "Compiler.h"
#include <chrono>
#include <stddef.h>
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

View File

@ -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);

View File

@ -22,6 +22,8 @@
#include "util/Cast.hxx"
#include <chrono>
struct ConfigBlock;
template<class T>
@ -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();
}

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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) {

View File

@ -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 = {

View File

@ -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);

View File

@ -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;
}

View File

@ -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

View File

@ -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();
};

View File

@ -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

View File

@ -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);

View File

@ -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);