output/httpd: move Cast() into the class
This commit is contained in:
parent
964b2661d8
commit
e2425592b6
@ -129,6 +129,19 @@ struct HttpdOutput final : private ServerSocket {
|
|||||||
HttpdOutput(EventLoop &_loop);
|
HttpdOutput(EventLoop &_loop);
|
||||||
~HttpdOutput();
|
~HttpdOutput();
|
||||||
|
|
||||||
|
#if GCC_CHECK_VERSION(4,6) || defined(__clang__)
|
||||||
|
#pragma GCC diagnostic push
|
||||||
|
#pragma GCC diagnostic ignored "-Winvalid-offsetof"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static constexpr HttpdOutput *Cast(audio_output *ao) {
|
||||||
|
return (HttpdOutput *)((char *)ao - offsetof(HttpdOutput, base));
|
||||||
|
}
|
||||||
|
|
||||||
|
#if GCC_CHECK_VERSION(4,6) || defined(__clang__)
|
||||||
|
#pragma GCC diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
bool Init(const config_param ¶m, Error &error);
|
bool Init(const config_param ¶m, Error &error);
|
||||||
|
|
||||||
void Finish() {
|
void Finish() {
|
||||||
|
@ -146,25 +146,10 @@ httpd_output_init(const config_param ¶m, Error &error)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if GCC_CHECK_VERSION(4,6) || defined(__clang__)
|
|
||||||
#pragma GCC diagnostic push
|
|
||||||
#pragma GCC diagnostic ignored "-Winvalid-offsetof"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static inline constexpr HttpdOutput *
|
|
||||||
Cast(audio_output *ao)
|
|
||||||
{
|
|
||||||
return (HttpdOutput *)((char *)ao - offsetof(HttpdOutput, base));
|
|
||||||
}
|
|
||||||
|
|
||||||
#if GCC_CHECK_VERSION(4,6) || defined(__clang__)
|
|
||||||
#pragma GCC diagnostic pop
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
httpd_output_finish(struct audio_output *ao)
|
httpd_output_finish(struct audio_output *ao)
|
||||||
{
|
{
|
||||||
HttpdOutput *httpd = Cast(ao);
|
HttpdOutput *httpd = HttpdOutput::Cast(ao);
|
||||||
|
|
||||||
httpd->Finish();
|
httpd->Finish();
|
||||||
delete httpd;
|
delete httpd;
|
||||||
@ -265,7 +250,7 @@ HttpdOutput::ReadPage()
|
|||||||
static bool
|
static bool
|
||||||
httpd_output_enable(struct audio_output *ao, Error &error)
|
httpd_output_enable(struct audio_output *ao, Error &error)
|
||||||
{
|
{
|
||||||
HttpdOutput *httpd = Cast(ao);
|
HttpdOutput *httpd = HttpdOutput::Cast(ao);
|
||||||
|
|
||||||
return httpd->Bind(error);
|
return httpd->Bind(error);
|
||||||
}
|
}
|
||||||
@ -273,7 +258,7 @@ httpd_output_enable(struct audio_output *ao, Error &error)
|
|||||||
static void
|
static void
|
||||||
httpd_output_disable(struct audio_output *ao)
|
httpd_output_disable(struct audio_output *ao)
|
||||||
{
|
{
|
||||||
HttpdOutput *httpd = Cast(ao);
|
HttpdOutput *httpd = HttpdOutput::Cast(ao);
|
||||||
|
|
||||||
httpd->Unbind();
|
httpd->Unbind();
|
||||||
}
|
}
|
||||||
@ -319,7 +304,7 @@ static bool
|
|||||||
httpd_output_open(struct audio_output *ao, AudioFormat &audio_format,
|
httpd_output_open(struct audio_output *ao, AudioFormat &audio_format,
|
||||||
Error &error)
|
Error &error)
|
||||||
{
|
{
|
||||||
HttpdOutput *httpd = Cast(ao);
|
HttpdOutput *httpd = HttpdOutput::Cast(ao);
|
||||||
|
|
||||||
assert(httpd->clients.empty());
|
assert(httpd->clients.empty());
|
||||||
|
|
||||||
@ -347,7 +332,7 @@ HttpdOutput::Close()
|
|||||||
static void
|
static void
|
||||||
httpd_output_close(struct audio_output *ao)
|
httpd_output_close(struct audio_output *ao)
|
||||||
{
|
{
|
||||||
HttpdOutput *httpd = Cast(ao);
|
HttpdOutput *httpd = HttpdOutput::Cast(ao);
|
||||||
|
|
||||||
const ScopeLock protect(httpd->mutex);
|
const ScopeLock protect(httpd->mutex);
|
||||||
httpd->Close();
|
httpd->Close();
|
||||||
@ -379,7 +364,7 @@ HttpdOutput::SendHeader(HttpdClient &client) const
|
|||||||
static unsigned
|
static unsigned
|
||||||
httpd_output_delay(struct audio_output *ao)
|
httpd_output_delay(struct audio_output *ao)
|
||||||
{
|
{
|
||||||
HttpdOutput *httpd = Cast(ao);
|
HttpdOutput *httpd = HttpdOutput::Cast(ao);
|
||||||
|
|
||||||
if (!httpd->LockHasClients() && httpd->base.pause) {
|
if (!httpd->LockHasClients() && httpd->base.pause) {
|
||||||
/* if there's no client and this output is paused,
|
/* if there's no client and this output is paused,
|
||||||
@ -445,7 +430,7 @@ static size_t
|
|||||||
httpd_output_play(struct audio_output *ao, const void *chunk, size_t size,
|
httpd_output_play(struct audio_output *ao, const void *chunk, size_t size,
|
||||||
Error &error)
|
Error &error)
|
||||||
{
|
{
|
||||||
HttpdOutput *httpd = Cast(ao);
|
HttpdOutput *httpd = HttpdOutput::Cast(ao);
|
||||||
|
|
||||||
if (httpd->LockHasClients()) {
|
if (httpd->LockHasClients()) {
|
||||||
if (!httpd->EncodeAndPlay(chunk, size, error))
|
if (!httpd->EncodeAndPlay(chunk, size, error))
|
||||||
@ -462,7 +447,7 @@ httpd_output_play(struct audio_output *ao, const void *chunk, size_t size,
|
|||||||
static bool
|
static bool
|
||||||
httpd_output_pause(struct audio_output *ao)
|
httpd_output_pause(struct audio_output *ao)
|
||||||
{
|
{
|
||||||
HttpdOutput *httpd = Cast(ao);
|
HttpdOutput *httpd = HttpdOutput::Cast(ao);
|
||||||
|
|
||||||
if (httpd->LockHasClients()) {
|
if (httpd->LockHasClients()) {
|
||||||
static const char silence[1020] = { 0 };
|
static const char silence[1020] = { 0 };
|
||||||
@ -525,7 +510,7 @@ HttpdOutput::SendTag(const Tag *tag)
|
|||||||
static void
|
static void
|
||||||
httpd_output_tag(struct audio_output *ao, const Tag *tag)
|
httpd_output_tag(struct audio_output *ao, const Tag *tag)
|
||||||
{
|
{
|
||||||
HttpdOutput *httpd = Cast(ao);
|
HttpdOutput *httpd = HttpdOutput::Cast(ao);
|
||||||
|
|
||||||
httpd->SendTag(tag);
|
httpd->SendTag(tag);
|
||||||
}
|
}
|
||||||
@ -533,7 +518,7 @@ httpd_output_tag(struct audio_output *ao, const Tag *tag)
|
|||||||
static void
|
static void
|
||||||
httpd_output_cancel(struct audio_output *ao)
|
httpd_output_cancel(struct audio_output *ao)
|
||||||
{
|
{
|
||||||
HttpdOutput *httpd = Cast(ao);
|
HttpdOutput *httpd = HttpdOutput::Cast(ao);
|
||||||
|
|
||||||
const ScopeLock protect(httpd->mutex);
|
const ScopeLock protect(httpd->mutex);
|
||||||
for (auto &client : httpd->clients)
|
for (auto &client : httpd->clients)
|
||||||
|
Loading…
Reference in New Issue
Block a user