httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
/*
|
2020-01-18 19:22:19 +01:00
|
|
|
* Copyright 2003-2020 The Music Player Daemon Project
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
* http://www.musicpd.org
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2013-01-15 18:22:17 +01:00
|
|
|
#include "HttpdOutputPlugin.hxx"
|
|
|
|
#include "HttpdInternal.hxx"
|
|
|
|
#include "HttpdClient.hxx"
|
2014-02-19 09:08:29 +01:00
|
|
|
#include "output/OutputAPI.hxx"
|
2015-01-08 19:31:57 +01:00
|
|
|
#include "encoder/EncoderInterface.hxx"
|
2017-11-10 21:37:56 +01:00
|
|
|
#include "encoder/Configured.hxx"
|
2017-08-10 19:13:18 +02:00
|
|
|
#include "net/UniqueSocketDescriptor.hxx"
|
2015-02-10 20:30:10 +01:00
|
|
|
#include "net/SocketAddress.hxx"
|
2013-01-30 09:18:52 +01:00
|
|
|
#include "Page.hxx"
|
2013-01-30 09:08:50 +01:00
|
|
|
#include "IcyMetaDataServer.hxx"
|
2013-12-31 16:31:36 +01:00
|
|
|
#include "event/Call.hxx"
|
2013-08-10 18:02:44 +02:00
|
|
|
#include "util/Domain.hxx"
|
2015-10-19 15:18:47 +02:00
|
|
|
#include "util/DeleteDisposer.hxx"
|
2018-08-07 19:28:29 +02:00
|
|
|
#include "config/Net.hxx"
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
2013-07-30 20:11:57 +02:00
|
|
|
#include <string.h>
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
|
2013-09-27 22:31:24 +02:00
|
|
|
const Domain httpd_output_domain("httpd_output");
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
|
2013-01-30 13:29:21 +01:00
|
|
|
inline
|
2016-10-28 21:27:29 +02:00
|
|
|
HttpdOutput::HttpdOutput(EventLoop &_loop, const ConfigBlock &block)
|
2017-08-09 16:58:44 +02:00
|
|
|
:AudioOutput(FLAG_ENABLE_DISABLE|FLAG_PAUSE),
|
2017-11-10 21:14:52 +01:00
|
|
|
ServerSocket(_loop),
|
2017-11-10 21:37:56 +01:00
|
|
|
prepared_encoder(CreateConfiguredEncoder(block)),
|
2017-11-10 21:14:52 +01:00
|
|
|
defer_broadcast(_loop, BIND_THIS_METHOD(OnDeferredBroadcast))
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
{
|
|
|
|
/* read configuration */
|
2015-01-21 22:13:44 +01:00
|
|
|
name = block.GetBlockValue("name", "Set name in config");
|
|
|
|
genre = block.GetBlockValue("genre", "Set genre in config");
|
|
|
|
website = block.GetBlockValue("website", "Set website in config");
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
|
2020-02-02 23:31:45 +01:00
|
|
|
clients_max = block.GetBlockValue("max_clients", 0U);
|
2009-10-29 22:38:18 +01:00
|
|
|
|
2010-09-25 15:00:43 +02:00
|
|
|
/* set up bind_to_address */
|
2010-10-05 20:37:18 +02:00
|
|
|
|
2020-02-02 23:31:45 +01:00
|
|
|
ServerSocketAddGeneric(*this, block.GetBlockValue("bind_to_address"), block.GetBlockValue("port", 8000U));
|
2009-04-13 19:35:02 +02:00
|
|
|
|
2009-12-03 20:27:08 +01:00
|
|
|
/* determine content type */
|
2016-05-04 18:29:31 +02:00
|
|
|
content_type = prepared_encoder->GetMimeType();
|
2013-01-30 13:29:21 +01:00
|
|
|
if (content_type == nullptr)
|
|
|
|
content_type = "application/octet-stream";
|
2016-10-28 21:27:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
|
|
|
HttpdOutput::Bind()
|
2013-12-31 16:55:26 +01:00
|
|
|
{
|
2016-10-28 21:27:29 +02:00
|
|
|
open = false;
|
|
|
|
|
|
|
|
BlockingCall(GetEventLoop(), [this](){
|
|
|
|
ServerSocket::Open();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void
|
2018-12-28 17:02:39 +01:00
|
|
|
HttpdOutput::Unbind() noexcept
|
2016-10-28 21:27:29 +02:00
|
|
|
{
|
|
|
|
assert(!open);
|
|
|
|
|
|
|
|
BlockingCall(GetEventLoop(), [this](){
|
|
|
|
ServerSocket::Close();
|
|
|
|
});
|
2013-12-31 16:55:26 +01:00
|
|
|
}
|
|
|
|
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
/**
|
2013-01-15 18:22:17 +01:00
|
|
|
* Creates a new #HttpdClient object and adds it into the
|
2013-01-27 23:21:39 +01:00
|
|
|
* HttpdOutput.clients linked list.
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
*/
|
2013-01-27 23:23:46 +01:00
|
|
|
inline void
|
2018-12-28 17:02:39 +01:00
|
|
|
HttpdOutput::AddClient(UniqueSocketDescriptor fd) noexcept
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
{
|
2017-08-10 19:13:18 +02:00
|
|
|
auto *client = new HttpdClient(*this, std::move(fd), GetEventLoop(),
|
2016-05-04 09:31:21 +02:00
|
|
|
!encoder->ImplementsTag());
|
2015-10-19 15:18:47 +02:00
|
|
|
clients.push_front(*client);
|
2009-04-13 19:35:02 +02:00
|
|
|
|
|
|
|
/* pass metadata to client */
|
2013-01-27 23:23:46 +01:00
|
|
|
if (metadata != nullptr)
|
|
|
|
clients.front().PushMetaData(metadata);
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
}
|
|
|
|
|
2013-12-31 16:31:36 +01:00
|
|
|
void
|
2017-11-10 21:14:52 +01:00
|
|
|
HttpdOutput::OnDeferredBroadcast() noexcept
|
2013-12-31 16:31:36 +01:00
|
|
|
{
|
|
|
|
/* this method runs in the IOThread; it broadcasts pages from
|
|
|
|
our own queue to all clients */
|
|
|
|
|
2017-01-03 07:11:57 +01:00
|
|
|
const std::lock_guard<Mutex> protect(mutex);
|
2013-12-31 16:31:36 +01:00
|
|
|
|
|
|
|
while (!pages.empty()) {
|
2017-02-19 20:12:30 +01:00
|
|
|
PagePtr page = std::move(pages.front());
|
2013-12-31 16:31:36 +01:00
|
|
|
pages.pop();
|
|
|
|
|
|
|
|
for (auto &client : clients)
|
|
|
|
client.PushPage(page);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* wake up the client that may be waiting for the queue to be
|
|
|
|
flushed */
|
2019-04-25 18:33:09 +02:00
|
|
|
cond.notify_all();
|
2013-12-31 16:31:36 +01:00
|
|
|
}
|
|
|
|
|
2013-01-30 13:20:27 +01:00
|
|
|
void
|
2017-11-10 20:43:14 +01:00
|
|
|
HttpdOutput::OnAccept(UniqueSocketDescriptor fd,
|
2018-12-28 14:16:02 +01:00
|
|
|
SocketAddress, gcc_unused int uid) noexcept
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
{
|
|
|
|
/* the listener socket has become readable - a client has
|
|
|
|
connected */
|
|
|
|
|
2017-01-03 07:11:57 +01:00
|
|
|
const std::lock_guard<Mutex> protect(mutex);
|
2010-10-05 20:37:18 +02:00
|
|
|
|
2017-08-10 19:19:53 +02:00
|
|
|
/* can we allow additional client */
|
|
|
|
if (open && (clients_max == 0 || clients.size() < clients_max))
|
2017-08-10 19:13:18 +02:00
|
|
|
AddClient(std::move(fd));
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
}
|
|
|
|
|
2017-02-19 20:12:30 +01:00
|
|
|
PagePtr
|
2013-01-27 23:23:46 +01:00
|
|
|
HttpdOutput::ReadPage()
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
{
|
2013-01-27 23:23:46 +01:00
|
|
|
if (unflushed_input >= 65536) {
|
2010-08-06 22:18:01 +02:00
|
|
|
/* we have fed a lot of input into the encoder, but it
|
|
|
|
didn't give anything back yet - flush now to avoid
|
|
|
|
buffer underruns */
|
2016-11-07 09:20:12 +01:00
|
|
|
try {
|
|
|
|
encoder->Flush();
|
2017-12-19 10:56:23 +01:00
|
|
|
} catch (...) {
|
2016-11-07 09:20:12 +01:00
|
|
|
/* ignore */
|
|
|
|
}
|
|
|
|
|
2013-01-27 23:23:46 +01:00
|
|
|
unflushed_input = 0;
|
2010-08-06 22:18:01 +02:00
|
|
|
}
|
|
|
|
|
2012-10-01 23:52:40 +02:00
|
|
|
size_t size = 0;
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
do {
|
2016-05-04 09:31:21 +02:00
|
|
|
size_t nbytes = encoder->Read(buffer + size,
|
|
|
|
sizeof(buffer) - size);
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
if (nbytes == 0)
|
|
|
|
break;
|
|
|
|
|
2013-01-27 23:23:46 +01:00
|
|
|
unflushed_input = 0;
|
2010-08-06 22:18:01 +02:00
|
|
|
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
size += nbytes;
|
2013-01-27 23:23:46 +01:00
|
|
|
} while (size < sizeof(buffer));
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
|
|
|
|
if (size == 0)
|
2013-10-28 23:58:17 +01:00
|
|
|
return nullptr;
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
|
2017-02-19 20:12:30 +01:00
|
|
|
return std::make_shared<Page>(buffer, size);
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
}
|
|
|
|
|
2016-11-07 09:20:12 +01:00
|
|
|
inline void
|
|
|
|
HttpdOutput::OpenEncoder(AudioFormat &audio_format)
|
2013-01-27 23:23:46 +01:00
|
|
|
{
|
2016-11-07 09:20:12 +01:00
|
|
|
encoder = prepared_encoder->Open(audio_format);
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
|
|
|
|
/* we have to remember the encoder header, i.e. the first
|
|
|
|
bytes of encoder output after opening it, because it has to
|
|
|
|
be sent to every new client */
|
2013-01-27 23:23:46 +01:00
|
|
|
header = ReadPage();
|
2010-08-06 22:18:01 +02:00
|
|
|
|
2013-01-27 23:23:46 +01:00
|
|
|
unflushed_input = 0;
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
}
|
|
|
|
|
2017-08-09 16:58:44 +02:00
|
|
|
void
|
2016-11-09 11:56:01 +01:00
|
|
|
HttpdOutput::Open(AudioFormat &audio_format)
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
{
|
2013-01-27 23:23:46 +01:00
|
|
|
assert(!open);
|
|
|
|
assert(clients.empty());
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
|
2017-01-25 10:03:17 +01:00
|
|
|
const std::lock_guard<Mutex> protect(mutex);
|
|
|
|
|
2016-11-07 09:20:12 +01:00
|
|
|
OpenEncoder(audio_format);
|
2013-01-27 23:23:46 +01:00
|
|
|
|
|
|
|
/* initialize other attributes */
|
|
|
|
|
2013-08-03 21:00:50 +02:00
|
|
|
timer = new Timer(audio_format);
|
2009-11-05 23:47:29 +01:00
|
|
|
|
2013-01-27 23:23:46 +01:00
|
|
|
open = true;
|
2017-05-23 11:13:41 +02:00
|
|
|
pause = false;
|
2009-11-05 23:47:29 +01:00
|
|
|
}
|
|
|
|
|
2017-08-09 16:58:44 +02:00
|
|
|
void
|
|
|
|
HttpdOutput::Close() noexcept
|
2013-01-27 23:23:46 +01:00
|
|
|
{
|
2017-01-25 10:03:17 +01:00
|
|
|
assert(open);
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
|
2013-05-12 15:03:42 +02:00
|
|
|
delete timer;
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
|
2014-01-05 02:12:29 +01:00
|
|
|
BlockingCall(GetEventLoop(), [this](){
|
2017-11-10 21:14:52 +01:00
|
|
|
defer_broadcast.Cancel();
|
2017-02-19 20:41:34 +01:00
|
|
|
|
2017-02-19 20:40:06 +01:00
|
|
|
const std::lock_guard<Mutex> protect(mutex);
|
|
|
|
open = false;
|
2015-10-19 15:18:47 +02:00
|
|
|
clients.clear_and_dispose(DeleteDisposer());
|
2014-01-05 02:12:29 +01:00
|
|
|
});
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
|
2017-02-19 20:12:30 +01:00
|
|
|
header.reset();
|
2009-11-05 23:47:29 +01:00
|
|
|
|
2016-05-04 09:31:21 +02:00
|
|
|
delete encoder;
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-12-28 17:02:39 +01:00
|
|
|
HttpdOutput::RemoveClient(HttpdClient &client) noexcept
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
{
|
2015-10-19 15:18:47 +02:00
|
|
|
assert(!clients.empty());
|
|
|
|
|
|
|
|
clients.erase_and_dispose(clients.iterator_to(client),
|
|
|
|
DeleteDisposer());
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2018-12-28 17:02:39 +01:00
|
|
|
HttpdOutput::SendHeader(HttpdClient &client) const noexcept
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
{
|
2013-10-28 23:58:17 +01:00
|
|
|
if (header != nullptr)
|
2013-01-27 23:23:46 +01:00
|
|
|
client.PushPage(header);
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
}
|
|
|
|
|
2017-08-09 16:58:44 +02:00
|
|
|
std::chrono::steady_clock::duration
|
2017-05-08 14:44:49 +02:00
|
|
|
HttpdOutput::Delay() const noexcept
|
2010-11-05 09:42:14 +01:00
|
|
|
{
|
2017-05-23 11:13:41 +02:00
|
|
|
if (!LockHasClients() && pause) {
|
2012-08-14 21:39:33 +02:00
|
|
|
/* 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 */
|
2013-12-31 17:01:08 +01:00
|
|
|
timer->Reset();
|
2012-08-14 21:46:43 +02:00
|
|
|
|
|
|
|
/* some arbitrary delay that is long enough to avoid
|
|
|
|
consuming too much CPU, and short enough to notice
|
|
|
|
new clients quickly enough */
|
2016-12-28 21:44:18 +01:00
|
|
|
return std::chrono::seconds(1);
|
2012-08-14 21:39:33 +02:00
|
|
|
}
|
|
|
|
|
2013-12-31 17:01:08 +01:00
|
|
|
return timer->IsStarted()
|
2016-12-28 10:11:07 +01:00
|
|
|
? timer->GetDelay()
|
2016-12-28 21:44:18 +01:00
|
|
|
: std::chrono::steady_clock::duration::zero();
|
2010-11-05 09:42:14 +01:00
|
|
|
}
|
|
|
|
|
2013-01-27 23:23:46 +01:00
|
|
|
void
|
2018-12-28 17:02:39 +01:00
|
|
|
HttpdOutput::BroadcastPage(PagePtr page) noexcept
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
{
|
2013-10-28 23:58:17 +01:00
|
|
|
assert(page != nullptr);
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
|
2017-02-19 20:32:21 +01:00
|
|
|
{
|
|
|
|
const std::lock_guard<Mutex> lock(mutex);
|
|
|
|
pages.emplace(std::move(page));
|
|
|
|
}
|
2013-12-31 16:31:36 +01:00
|
|
|
|
2017-11-10 21:14:52 +01:00
|
|
|
defer_broadcast.Schedule();
|
2009-05-05 22:43:28 +02:00
|
|
|
}
|
|
|
|
|
2013-01-27 23:23:46 +01:00
|
|
|
void
|
|
|
|
HttpdOutput::BroadcastFromEncoder()
|
2009-05-05 22:43:28 +02:00
|
|
|
{
|
2013-12-31 16:31:36 +01:00
|
|
|
/* synchronize with the IOThread */
|
2017-02-19 20:32:21 +01:00
|
|
|
{
|
2019-04-25 18:53:38 +02:00
|
|
|
std::unique_lock<Mutex> lock(mutex);
|
2019-05-07 20:01:45 +02:00
|
|
|
cond.wait(lock, [this]{ return pages.empty(); });
|
2017-02-19 20:45:16 +01:00
|
|
|
}
|
2017-02-19 20:32:21 +01:00
|
|
|
|
2017-02-19 20:46:20 +01:00
|
|
|
bool empty = true;
|
|
|
|
|
2017-02-19 20:45:16 +01:00
|
|
|
PagePtr page;
|
|
|
|
while ((page = ReadPage()) != nullptr) {
|
|
|
|
const std::lock_guard<Mutex> lock(mutex);
|
2017-02-19 20:48:17 +01:00
|
|
|
pages.emplace(std::move(page));
|
2017-02-19 20:46:20 +01:00
|
|
|
empty = false;
|
2017-02-19 20:32:21 +01:00
|
|
|
}
|
2013-12-31 16:31:36 +01:00
|
|
|
|
2017-02-19 20:46:20 +01:00
|
|
|
if (!empty)
|
2017-11-10 21:14:52 +01:00
|
|
|
defer_broadcast.Schedule();
|
2009-05-05 22:43:28 +02:00
|
|
|
}
|
|
|
|
|
2016-11-07 09:20:12 +01:00
|
|
|
inline void
|
|
|
|
HttpdOutput::EncodeAndPlay(const void *chunk, size_t size)
|
2009-05-05 22:43:28 +02:00
|
|
|
{
|
2016-11-07 09:20:12 +01:00
|
|
|
encoder->Write(chunk, size);
|
2009-05-05 22:43:28 +02:00
|
|
|
|
2013-01-27 23:23:46 +01:00
|
|
|
unflushed_input += size;
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
|
2013-01-27 23:23:46 +01:00
|
|
|
BroadcastFromEncoder();
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
}
|
|
|
|
|
2017-08-09 16:58:44 +02:00
|
|
|
size_t
|
2016-11-09 08:40:10 +01:00
|
|
|
HttpdOutput::Play(const void *chunk, size_t size)
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
{
|
2017-05-23 11:13:41 +02:00
|
|
|
pause = false;
|
|
|
|
|
2016-11-07 09:20:12 +01:00
|
|
|
if (LockHasClients())
|
|
|
|
EncodeAndPlay(chunk, size);
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
|
2013-12-31 17:01:08 +01:00
|
|
|
if (!timer->IsStarted())
|
|
|
|
timer->Start();
|
|
|
|
timer->Add(size);
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2017-01-25 10:03:17 +01:00
|
|
|
bool
|
2017-09-08 14:45:53 +02:00
|
|
|
HttpdOutput::Pause()
|
2010-08-06 07:23:17 +02:00
|
|
|
{
|
2017-05-23 11:13:41 +02:00
|
|
|
pause = true;
|
|
|
|
|
2017-01-25 10:03:17 +01:00
|
|
|
if (LockHasClients()) {
|
2013-01-15 18:22:17 +01:00
|
|
|
static const char silence[1020] = { 0 };
|
2017-01-25 10:03:17 +01:00
|
|
|
Play(silence, sizeof(silence));
|
2010-08-06 07:23:17 +02:00
|
|
|
}
|
2016-11-09 08:40:10 +01:00
|
|
|
|
|
|
|
return true;
|
2010-08-06 07:23:17 +02:00
|
|
|
}
|
|
|
|
|
2017-08-09 16:58:44 +02:00
|
|
|
void
|
2014-12-26 22:27:01 +01:00
|
|
|
HttpdOutput::SendTag(const Tag &tag)
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
{
|
2016-05-04 09:31:21 +02:00
|
|
|
if (encoder->ImplementsTag()) {
|
2009-05-05 22:41:36 +02:00
|
|
|
/* embed encoder tags */
|
2009-05-05 22:51:17 +02:00
|
|
|
|
|
|
|
/* flush the current stream, and end it */
|
|
|
|
|
2016-11-07 09:20:12 +01:00
|
|
|
try {
|
|
|
|
encoder->PreTag();
|
2017-12-19 10:56:23 +01:00
|
|
|
} catch (...) {
|
2016-11-07 09:20:12 +01:00
|
|
|
/* ignore */
|
|
|
|
}
|
|
|
|
|
2013-01-27 23:23:46 +01:00
|
|
|
BroadcastFromEncoder();
|
2009-05-05 22:51:17 +02:00
|
|
|
|
|
|
|
/* send the tag to the encoder - which starts a new
|
|
|
|
stream now */
|
2009-05-05 22:41:36 +02:00
|
|
|
|
2016-11-07 09:20:12 +01:00
|
|
|
try {
|
|
|
|
encoder->SendTag(tag);
|
2017-11-14 12:00:14 +01:00
|
|
|
encoder->Flush();
|
2017-12-19 10:56:23 +01:00
|
|
|
} catch (...) {
|
2016-11-07 09:20:12 +01:00
|
|
|
/* ignore */
|
|
|
|
}
|
2009-05-05 22:51:17 +02:00
|
|
|
|
|
|
|
/* the first page generated by the encoder will now be
|
|
|
|
used as the new "header" page, which is sent to all
|
|
|
|
new clients */
|
|
|
|
|
2017-02-19 20:12:30 +01:00
|
|
|
auto page = ReadPage();
|
2013-10-28 23:58:17 +01:00
|
|
|
if (page != nullptr) {
|
2017-03-29 20:17:09 +02:00
|
|
|
header = page;
|
2013-01-27 23:23:46 +01:00
|
|
|
BroadcastPage(page);
|
2009-05-05 22:51:17 +02:00
|
|
|
}
|
2009-05-05 22:41:36 +02:00
|
|
|
} else {
|
|
|
|
/* use Icy-Metadata */
|
|
|
|
|
2013-10-20 13:32:59 +02:00
|
|
|
static constexpr TagType types[] = {
|
2013-01-30 09:13:46 +01:00
|
|
|
TAG_ALBUM, TAG_ARTIST, TAG_TITLE,
|
|
|
|
TAG_NUM_OF_ITEM_TYPES
|
|
|
|
};
|
|
|
|
|
2014-12-26 22:27:01 +01:00
|
|
|
metadata = icy_server_metadata_page(tag, &types[0]);
|
2013-10-28 23:58:17 +01:00
|
|
|
if (metadata != nullptr) {
|
2017-01-03 07:11:57 +01:00
|
|
|
const std::lock_guard<Mutex> protect(mutex);
|
2013-01-27 23:23:46 +01:00
|
|
|
for (auto &client : clients)
|
|
|
|
client.PushMetaData(metadata);
|
2009-05-05 22:41:36 +02:00
|
|
|
}
|
2009-04-13 19:35:02 +02:00
|
|
|
}
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
}
|
|
|
|
|
2013-12-31 17:01:08 +01:00
|
|
|
inline void
|
2018-12-28 17:02:39 +01:00
|
|
|
HttpdOutput::CancelAllClients() noexcept
|
2013-12-31 17:01:08 +01:00
|
|
|
{
|
2017-01-03 07:11:57 +01:00
|
|
|
const std::lock_guard<Mutex> protect(mutex);
|
2013-12-31 16:31:36 +01:00
|
|
|
|
|
|
|
while (!pages.empty()) {
|
2017-02-19 20:12:30 +01:00
|
|
|
PagePtr page = std::move(pages.front());
|
2013-12-31 16:31:36 +01:00
|
|
|
pages.pop();
|
|
|
|
}
|
|
|
|
|
2013-12-31 17:01:08 +01:00
|
|
|
for (auto &client : clients)
|
|
|
|
client.CancelQueue();
|
2013-12-31 16:31:36 +01:00
|
|
|
|
2019-04-25 18:33:09 +02:00
|
|
|
cond.notify_all();
|
2013-12-31 17:01:08 +01:00
|
|
|
}
|
|
|
|
|
2017-01-25 10:03:17 +01:00
|
|
|
void
|
2017-08-09 16:58:44 +02:00
|
|
|
HttpdOutput::Cancel() noexcept
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
{
|
2017-01-25 09:47:43 +01:00
|
|
|
BlockingCall(GetEventLoop(), [this](){
|
2017-01-25 10:03:17 +01:00
|
|
|
CancelAllClients();
|
2013-12-31 16:31:36 +01:00
|
|
|
});
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
}
|
|
|
|
|
2014-01-28 11:22:27 +01:00
|
|
|
const struct AudioOutputPlugin httpd_output_plugin = {
|
2013-01-15 18:22:17 +01:00
|
|
|
"httpd",
|
|
|
|
nullptr,
|
2017-08-09 16:58:44 +02:00
|
|
|
&HttpdOutput::Create,
|
2013-01-15 18:22:17 +01:00
|
|
|
nullptr,
|
httpd: new output plugin to replace "shout"
Let's get rid of the "shout" plugin, and the awfully complicated
icecast daemon setup! MPD can do better if it's doing the HTTP server
stuff on its own. This new plugin has several advantages:
- easier to set up - only one daemon, no password settings, no mount
settings
- MPD controls the encoder and thus already knows the packet
boundaries - icecast has to parse them
- MPD doesn't bother to encode data while nobody is listening
This implementation is very experimental (no header parsing, ignores
request URI, no icy-metadata, ...). It should be able to suport
several encoders in parallel in the future (with different bit rates,
different codec, ...), to make MPD the perfect streaming server. Once
MPD gets multi-player support, we can even mount several different
radio stations on one server.
2009-03-15 03:32:34 +01:00
|
|
|
};
|