aboutsummaryrefslogtreecommitdiffstats
path: root/src/output/HttpdOutputPlugin.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-12-31 17:01:08 +0100
committerMax Kellermann <max@duempel.org>2013-12-31 17:01:08 +0100
commit69a9d2919070c2564d6e573220df71c179b57246 (patch)
treef0b772f02806d467fb6d7b2e5b169631ef2832b6 /src/output/HttpdOutputPlugin.cxx
parente2425592b6fba5c739576e7d5f7d3a2777055e6f (diff)
downloadmpd-69a9d2919070c2564d6e573220df71c179b57246.tar.gz
mpd-69a9d2919070c2564d6e573220df71c179b57246.tar.xz
mpd-69a9d2919070c2564d6e573220df71c179b57246.zip
output/httpd: move code to methods Delay(), Play(), Cancel()
Diffstat (limited to 'src/output/HttpdOutputPlugin.cxx')
-rw-r--r--src/output/HttpdOutputPlugin.cxx61
1 files changed, 39 insertions, 22 deletions
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 = {