output/Plugin: delay() returns std::chrono::steady_clock::duration
This commit is contained in:
parent
871ba5a488
commit
d5e422970c
@ -63,12 +63,12 @@ ao_plugin_close(AudioOutput *ao)
|
|||||||
ao->plugin.close(ao);
|
ao->plugin.close(ao);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned
|
std::chrono::steady_clock::duration
|
||||||
ao_plugin_delay(AudioOutput *ao)
|
ao_plugin_delay(AudioOutput *ao)
|
||||||
{
|
{
|
||||||
return ao->plugin.delay != nullptr
|
return ao->plugin.delay != nullptr
|
||||||
? ao->plugin.delay(ao)
|
? ao->plugin.delay(ao)
|
||||||
: 0;
|
: std::chrono::steady_clock::duration::zero();
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#include "Compiler.h"
|
#include "Compiler.h"
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
struct ConfigBlock;
|
struct ConfigBlock;
|
||||||
@ -97,9 +99,9 @@ struct AudioOutputPlugin {
|
|||||||
* instead of doing a sleep inside the plugin, because this
|
* instead of doing a sleep inside the plugin, because this
|
||||||
* allows MPD to listen to commands meanwhile.
|
* 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,
|
* Display metadata for the next chunk. Optional method,
|
||||||
@ -179,7 +181,7 @@ void
|
|||||||
ao_plugin_close(AudioOutput *ao);
|
ao_plugin_close(AudioOutput *ao);
|
||||||
|
|
||||||
gcc_pure
|
gcc_pure
|
||||||
unsigned
|
std::chrono::steady_clock::duration
|
||||||
ao_plugin_delay(AudioOutput *ao);
|
ao_plugin_delay(AudioOutput *ao);
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -237,8 +237,8 @@ inline bool
|
|||||||
AudioOutput::WaitForDelay()
|
AudioOutput::WaitForDelay()
|
||||||
{
|
{
|
||||||
while (true) {
|
while (true) {
|
||||||
unsigned delay = ao_plugin_delay(this);
|
const auto delay = ao_plugin_delay(this);
|
||||||
if (delay == 0)
|
if (delay <= std::chrono::steady_clock::duration::zero())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
(void)cond.timed_wait(mutex, delay);
|
(void)cond.timed_wait(mutex, delay);
|
||||||
|
@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
#include "util/Cast.hxx"
|
#include "util/Cast.hxx"
|
||||||
|
|
||||||
|
#include <chrono>
|
||||||
|
|
||||||
struct ConfigBlock;
|
struct ConfigBlock;
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
@ -61,7 +63,7 @@ struct AudioOutputWrapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
gcc_pure
|
gcc_pure
|
||||||
static unsigned Delay(AudioOutput *ao) {
|
static std::chrono::steady_clock::duration Delay(AudioOutput *ao) {
|
||||||
T &t = Cast(*ao);
|
T &t = Cast(*ao);
|
||||||
return t.Delay();
|
return t.Delay();
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ public:
|
|||||||
void Open(AudioFormat &audio_format);
|
void Open(AudioFormat &audio_format);
|
||||||
void Close();
|
void Close();
|
||||||
|
|
||||||
unsigned Delay() const;
|
std::chrono::steady_clock::duration Delay() const;
|
||||||
size_t Play(const void *chunk, size_t size);
|
size_t Play(const void *chunk, size_t size);
|
||||||
void Cancel();
|
void Cancel();
|
||||||
};
|
};
|
||||||
@ -204,12 +204,12 @@ FifoOutput::Cancel()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline unsigned
|
inline std::chrono::steady_clock::duration
|
||||||
FifoOutput::Delay() const
|
FifoOutput::Delay() const
|
||||||
{
|
{
|
||||||
return timer->IsStarted()
|
return timer->IsStarted()
|
||||||
? timer->GetDelay()
|
? std::chrono::milliseconds(timer->GetDelay())
|
||||||
: 0;
|
: std::chrono::steady_clock::duration::zero();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline size_t
|
inline size_t
|
||||||
|
@ -79,7 +79,7 @@ public:
|
|||||||
size_t Play(const void *chunk, size_t size);
|
size_t Play(const void *chunk, size_t size);
|
||||||
void Cancel();
|
void Cancel();
|
||||||
|
|
||||||
size_t Delay();
|
std::chrono::steady_clock::duration Delay();
|
||||||
|
|
||||||
void FillBuffer(void* _buffer, size_t size,
|
void FillBuffer(void* _buffer, size_t size,
|
||||||
gcc_unused const media_raw_audio_format& _format);
|
gcc_unused const media_raw_audio_format& _format);
|
||||||
@ -308,7 +308,7 @@ HaikuOutput::Play(const void *chunk, size_t size)
|
|||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline size_t
|
inline std::chrono::steady_clock::duration
|
||||||
HaikuOutput::Delay()
|
HaikuOutput::Delay()
|
||||||
{
|
{
|
||||||
unsigned delay = buffer_filled ? 0 : buffer_delay;
|
unsigned delay = buffer_filled ? 0 : buffer_delay;
|
||||||
@ -319,7 +319,7 @@ HaikuOutput::Delay()
|
|||||||
//return (delay / 2) ? 1 : 0;
|
//return (delay / 2) ? 1 : 0;
|
||||||
(void)delay;
|
(void)delay;
|
||||||
|
|
||||||
return 0;
|
return std::chrono::steady_clock::duration::zero();
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
|
@ -128,10 +128,10 @@ struct JackOutput {
|
|||||||
*/
|
*/
|
||||||
size_t WriteSamples(const float *src, size_t n_frames);
|
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
|
return base.pause && pause && !shutdown
|
||||||
? 1000
|
? std::chrono::seconds(1)
|
||||||
: 0;
|
: std::chrono::steady_clock::duration::zero();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Play(const void *chunk, size_t size);
|
size_t Play(const void *chunk, size_t size);
|
||||||
|
@ -49,10 +49,10 @@ public:
|
|||||||
delete timer;
|
delete timer;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned Delay() const {
|
std::chrono::steady_clock::duration Delay() const {
|
||||||
return sync && timer->IsStarted()
|
return sync && timer->IsStarted()
|
||||||
? timer->GetDelay()
|
? std::chrono::milliseconds(timer->GetDelay())
|
||||||
: 0;
|
: std::chrono::steady_clock::duration::zero();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Play(gcc_unused const void *chunk, size_t size) {
|
size_t Play(gcc_unused const void *chunk, size_t size) {
|
||||||
|
@ -669,11 +669,13 @@ osx_output_play(AudioOutput *ao, const void *chunk, size_t size)
|
|||||||
return od->ring_buffer->push((uint8_t *)chunk, size);
|
return od->ring_buffer->push((uint8_t *)chunk, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned
|
static std::chrono::steady_clock::duration
|
||||||
osx_output_delay(AudioOutput *ao)
|
osx_output_delay(AudioOutput *ao)
|
||||||
{
|
{
|
||||||
OSXOutput *od = (OSXOutput *)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 = {
|
const struct AudioOutputPlugin osx_output_plugin = {
|
||||||
|
@ -58,13 +58,13 @@ class OpenALOutput {
|
|||||||
void Close();
|
void Close();
|
||||||
|
|
||||||
gcc_pure
|
gcc_pure
|
||||||
unsigned Delay() const {
|
std::chrono::steady_clock::duration Delay() const {
|
||||||
return filled < NUM_BUFFERS || HasProcessed()
|
return filled < NUM_BUFFERS || HasProcessed()
|
||||||
? 0
|
? std::chrono::steady_clock::duration::zero()
|
||||||
/* we don't know exactly how long we must wait
|
/* we don't know exactly how long we must wait
|
||||||
for the next buffer to finish, so this is a
|
for the next buffer to finish, so this is a
|
||||||
random guess: */
|
random guess: */
|
||||||
: 50;
|
: std::chrono::milliseconds(50);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Play(const void *chunk, size_t size);
|
size_t Play(const void *chunk, size_t size);
|
||||||
|
@ -101,7 +101,7 @@ public:
|
|||||||
void Open(AudioFormat &audio_format);
|
void Open(AudioFormat &audio_format);
|
||||||
void Close();
|
void Close();
|
||||||
|
|
||||||
unsigned Delay();
|
std::chrono::steady_clock::duration Delay();
|
||||||
size_t Play(const void *chunk, size_t size);
|
size_t Play(const void *chunk, size_t size);
|
||||||
void Cancel();
|
void Cancel();
|
||||||
bool Pause();
|
bool Pause();
|
||||||
@ -740,16 +740,16 @@ PulseOutput::StreamPause(bool pause)
|
|||||||
"pa_stream_cork() has failed");
|
"pa_stream_cork() has failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
inline unsigned
|
inline std::chrono::steady_clock::duration
|
||||||
PulseOutput::Delay()
|
PulseOutput::Delay()
|
||||||
{
|
{
|
||||||
Pulse::LockGuard lock(mainloop);
|
Pulse::LockGuard lock(mainloop);
|
||||||
|
|
||||||
unsigned result = 0;
|
auto result = std::chrono::steady_clock::duration::zero();
|
||||||
if (base.pause && pa_stream_is_corked(stream) &&
|
if (base.pause && pa_stream_is_corked(stream) &&
|
||||||
pa_stream_get_state(stream) == PA_STREAM_READY)
|
pa_stream_get_state(stream) == PA_STREAM_READY)
|
||||||
/* idle while paused */
|
/* idle while paused */
|
||||||
result = 1000;
|
result = std::chrono::seconds(1);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,7 @@ struct ShoutOutput final {
|
|||||||
void Open(AudioFormat &audio_format);
|
void Open(AudioFormat &audio_format);
|
||||||
void Close();
|
void Close();
|
||||||
|
|
||||||
unsigned Delay() const;
|
std::chrono::steady_clock::duration Delay() const;
|
||||||
void SendTag(const Tag &tag);
|
void SendTag(const Tag &tag);
|
||||||
size_t Play(const void *chunk, size_t size);
|
size_t Play(const void *chunk, size_t size);
|
||||||
void Cancel();
|
void Cancel();
|
||||||
@ -360,14 +360,14 @@ ShoutOutput::Open(AudioFormat &audio_format)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned
|
std::chrono::steady_clock::duration
|
||||||
ShoutOutput::Delay() const
|
ShoutOutput::Delay() const
|
||||||
{
|
{
|
||||||
int delay = shout_delay(shout_conn);
|
int delay = shout_delay(shout_conn);
|
||||||
if (delay < 0)
|
if (delay < 0)
|
||||||
delay = 0;
|
delay = 0;
|
||||||
|
|
||||||
return delay;
|
return std::chrono::milliseconds(delay);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
|
@ -51,7 +51,6 @@ public:
|
|||||||
|
|
||||||
void Open(AudioFormat &audio_format);
|
void Open(AudioFormat &audio_format);
|
||||||
void Close();
|
void Close();
|
||||||
unsigned Delay() const;
|
|
||||||
size_t Play(const void *chunk, size_t size);
|
size_t Play(const void *chunk, size_t size);
|
||||||
void Cancel();
|
void Cancel();
|
||||||
};
|
};
|
||||||
|
@ -218,7 +218,7 @@ public:
|
|||||||
void SendHeader(HttpdClient &client) const;
|
void SendHeader(HttpdClient &client) const;
|
||||||
|
|
||||||
gcc_pure
|
gcc_pure
|
||||||
unsigned Delay() const;
|
std::chrono::steady_clock::duration Delay() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads data from the encoder (as much as available) and
|
* Reads data from the encoder (as much as available) and
|
||||||
|
@ -344,7 +344,7 @@ HttpdOutput::SendHeader(HttpdClient &client) const
|
|||||||
client.PushPage(header);
|
client.PushPage(header);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline unsigned
|
inline std::chrono::steady_clock::duration
|
||||||
HttpdOutput::Delay() const
|
HttpdOutput::Delay() const
|
||||||
{
|
{
|
||||||
if (!LockHasClients() && base.pause) {
|
if (!LockHasClients() && base.pause) {
|
||||||
@ -357,15 +357,15 @@ HttpdOutput::Delay() const
|
|||||||
/* some arbitrary delay that is long enough to avoid
|
/* some arbitrary delay that is long enough to avoid
|
||||||
consuming too much CPU, and short enough to notice
|
consuming too much CPU, and short enough to notice
|
||||||
new clients quickly enough */
|
new clients quickly enough */
|
||||||
return 1000;
|
return std::chrono::seconds(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
return timer->IsStarted()
|
return timer->IsStarted()
|
||||||
? timer->GetDelay()
|
? std::chrono::milliseconds(timer->GetDelay())
|
||||||
: 0;
|
: std::chrono::steady_clock::duration::zero();
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned
|
static std::chrono::steady_clock::duration
|
||||||
httpd_output_delay(AudioOutput *ao)
|
httpd_output_delay(AudioOutput *ao)
|
||||||
{
|
{
|
||||||
HttpdOutput *httpd = HttpdOutput::Cast(ao);
|
HttpdOutput *httpd = HttpdOutput::Cast(ao);
|
||||||
|
@ -96,8 +96,10 @@ public:
|
|||||||
void Open(AudioFormat &audio_format);
|
void Open(AudioFormat &audio_format);
|
||||||
void Close();
|
void Close();
|
||||||
|
|
||||||
unsigned Delay() {
|
std::chrono::steady_clock::duration Delay() {
|
||||||
return pause && !cancel ? 100 : 0;
|
return pause && !cancel
|
||||||
|
? std::chrono::milliseconds(100)
|
||||||
|
: std::chrono::steady_clock::duration::zero();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t Play(const void *chunk, size_t size);
|
size_t Play(const void *chunk, size_t size);
|
||||||
|
Loading…
Reference in New Issue
Block a user