diff options
author | Max Kellermann <max@duempel.org> | 2013-12-31 17:01:08 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2013-12-31 17:01:08 +0100 |
commit | 69a9d2919070c2564d6e573220df71c179b57246 (patch) | |
tree | f0b772f02806d467fb6d7b2e5b169631ef2832b6 /src/output | |
parent | e2425592b6fba5c739576e7d5f7d3a2777055e6f (diff) | |
download | mpd-69a9d2919070c2564d6e573220df71c179b57246.tar.gz mpd-69a9d2919070c2564d6e573220df71c179b57246.tar.xz mpd-69a9d2919070c2564d6e573220df71c179b57246.zip |
output/httpd: move code to methods Delay(), Play(), Cancel()
Diffstat (limited to 'src/output')
-rw-r--r-- | src/output/HttpdInternal.hxx | 7 | ||||
-rw-r--r-- | src/output/HttpdOutputPlugin.cxx | 61 |
2 files changed, 46 insertions, 22 deletions
diff --git a/src/output/HttpdInternal.hxx b/src/output/HttpdInternal.hxx index a9d24e840..5c9e9233e 100644 --- a/src/output/HttpdInternal.hxx +++ b/src/output/HttpdInternal.hxx @@ -213,6 +213,9 @@ struct HttpdOutput final : private ServerSocket { */ void SendHeader(HttpdClient &client) const; + gcc_pure + unsigned Delay() const; + /** * Reads data from the encoder (as much as available) and * returns it as a new #page object. @@ -235,6 +238,10 @@ struct HttpdOutput final : private ServerSocket { void SendTag(const Tag *tag); + size_t Play(const void *chunk, size_t size, Error &error); + + void CancelAllClients(); + private: virtual void OnAccept(int fd, const sockaddr &address, size_t address_length, int uid) override; diff --git a/src/output/HttpdOutputPlugin.cxx b/src/output/HttpdOutputPlugin.cxx index f3b86d2a8..7da91e58d 100644 --- a/src/output/HttpdOutputPlugin.cxx +++ b/src/output/HttpdOutputPlugin.cxx @@ -361,17 +361,15 @@ HttpdOutput::SendHeader(HttpdClient &client) const client.PushPage(header); } -static unsigned -httpd_output_delay(struct audio_output *ao) +inline unsigned +HttpdOutput::Delay() const { - HttpdOutput *httpd = HttpdOutput::Cast(ao); - - if (!httpd->LockHasClients() && httpd->base.pause) { + if (!LockHasClients() && base.pause) { /* if there's no client and this output is paused, then httpd_output_pause() will not do anything, it will not fill the buffer and it will not update the timer; therefore, we reset the timer here */ - httpd->timer->Reset(); + timer->Reset(); /* some arbitrary delay that is long enough to avoid consuming too much CPU, and short enough to notice @@ -379,11 +377,19 @@ httpd_output_delay(struct audio_output *ao) return 1000; } - return httpd->timer->IsStarted() - ? httpd->timer->GetDelay() + return timer->IsStarted() + ? timer->GetDelay() : 0; } +static unsigned +httpd_output_delay(struct audio_output *ao) +{ + HttpdOutput *httpd = HttpdOutput::Cast(ao); + + return httpd->Delay(); +} + void HttpdOutput::BroadcastPage(Page *page) { @@ -426,24 +432,30 @@ HttpdOutput::EncodeAndPlay(const void *chunk, size_t size, Error &error) return true; } -static size_t -httpd_output_play(struct audio_output *ao, const void *chunk, size_t size, - Error &error) +inline size_t +HttpdOutput::Play(const void *chunk, size_t size, Error &error) { - HttpdOutput *httpd = HttpdOutput::Cast(ao); - - if (httpd->LockHasClients()) { - if (!httpd->EncodeAndPlay(chunk, size, error)) + if (LockHasClients()) { + if (!EncodeAndPlay(chunk, size, error)) return 0; } - if (!httpd->timer->IsStarted()) - httpd->timer->Start(); - httpd->timer->Add(size); + if (!timer->IsStarted()) + timer->Start(); + timer->Add(size); return size; } +static size_t +httpd_output_play(struct audio_output *ao, const void *chunk, size_t size, + Error &error) +{ + HttpdOutput *httpd = HttpdOutput::Cast(ao); + + return httpd->Play(chunk, size, error); +} + static bool httpd_output_pause(struct audio_output *ao) { @@ -515,14 +527,19 @@ httpd_output_tag(struct audio_output *ao, const Tag *tag) httpd->SendTag(tag); } +inline void +HttpdOutput::CancelAllClients() +{ + const ScopeLock protect(mutex); + for (auto &client : clients) + client.CancelQueue(); +} + static void httpd_output_cancel(struct audio_output *ao) { HttpdOutput *httpd = HttpdOutput::Cast(ao); - - const ScopeLock protect(httpd->mutex); - for (auto &client : httpd->clients) - client.CancelQueue(); + httpd->CancelAllClients(); } const struct audio_output_plugin httpd_output_plugin = { |