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
|
|
|
/*
|
2011-01-29 10:13:54 +01:00
|
|
|
* Copyright (C) 2003-2011 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
*
|
|
|
|
* Internal declarations for the "httpd" audio output plugin.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MPD_OUTPUT_HTTPD_INTERNAL_H
|
|
|
|
#define MPD_OUTPUT_HTTPD_INTERNAL_H
|
|
|
|
|
2013-01-15 18:22:17 +01:00
|
|
|
#include "HttpdClient.hxx"
|
2011-09-16 23:31:48 +02:00
|
|
|
#include "output_internal.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
|
|
|
#include "timer.h"
|
2013-01-15 18:22:17 +01:00
|
|
|
#include "thread/Mutex.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 <glib.h>
|
|
|
|
|
2013-01-15 18:22:17 +01:00
|
|
|
#include <forward_list>
|
|
|
|
|
2013-01-30 13:29:21 +01:00
|
|
|
struct config_param;
|
|
|
|
class EventLoop;
|
2013-01-30 12:56:23 +01:00
|
|
|
class ServerSocket;
|
2013-01-15 18:22:17 +01:00
|
|
|
class HttpdClient;
|
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:21:39 +01:00
|
|
|
struct HttpdOutput {
|
2011-09-16 23:31:48 +02:00
|
|
|
struct audio_output base;
|
|
|
|
|
2009-11-05 23:47:29 +01:00
|
|
|
/**
|
|
|
|
* True if the audio output is open and accepts client
|
|
|
|
* connections.
|
|
|
|
*/
|
|
|
|
bool 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
|
|
|
/**
|
|
|
|
* The configured encoder plugin.
|
|
|
|
*/
|
|
|
|
struct encoder *encoder;
|
|
|
|
|
2010-08-06 22:18:01 +02:00
|
|
|
/**
|
|
|
|
* Number of bytes which were fed into the encoder, without
|
|
|
|
* ever receiving new output. This is used to estimate
|
|
|
|
* whether MPD should manually flush the encoder, to avoid
|
|
|
|
* buffer underruns in the client.
|
|
|
|
*/
|
|
|
|
size_t unflushed_input;
|
|
|
|
|
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 MIME type produced by the #encoder.
|
|
|
|
*/
|
|
|
|
const char *content_type;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This mutex protects the listener socket and the client
|
|
|
|
* list.
|
|
|
|
*/
|
2013-01-15 18:22:17 +01:00
|
|
|
mutable Mutex mutex;
|
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
|
|
|
|
|
|
|
/**
|
2011-07-25 21:55:43 +02:00
|
|
|
* A #timer object to synchronize this output with the
|
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
|
|
|
* wallclock.
|
|
|
|
*/
|
2011-07-25 21:55:43 +02:00
|
|
|
struct timer *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
|
|
|
|
|
|
|
/**
|
|
|
|
* The listener socket.
|
|
|
|
*/
|
2013-01-30 12:56:23 +01:00
|
|
|
ServerSocket *server_socket;
|
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 header page, which is sent to every client on connect.
|
|
|
|
*/
|
2013-01-30 09:18:52 +01:00
|
|
|
Page *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
|
|
|
|
2009-04-13 19:35:02 +02:00
|
|
|
/**
|
|
|
|
* The metadata, which is sent to every client.
|
|
|
|
*/
|
2013-01-30 09:18:52 +01:00
|
|
|
Page *metadata;
|
2009-04-13 19:35:02 +02:00
|
|
|
|
2010-04-05 13:11:10 +02:00
|
|
|
/**
|
|
|
|
* The configured name.
|
|
|
|
*/
|
|
|
|
char const *name;
|
|
|
|
/**
|
|
|
|
* The configured genre.
|
|
|
|
*/
|
|
|
|
char const *genre;
|
|
|
|
/**
|
|
|
|
* The configured website address.
|
|
|
|
*/
|
|
|
|
char const *website;
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* A linked list containing all clients which are currently
|
|
|
|
* connected.
|
|
|
|
*/
|
2013-01-15 18:22:17 +01:00
|
|
|
std::forward_list<HttpdClient> clients;
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* A temporary buffer for the httpd_output_read_page()
|
|
|
|
* function.
|
|
|
|
*/
|
|
|
|
char buffer[32768];
|
2009-10-29 22:38:18 +01:00
|
|
|
|
|
|
|
/**
|
2011-02-04 10:39:21 +01:00
|
|
|
* The maximum and current number of clients connected
|
2009-10-29 22:38:18 +01:00
|
|
|
* at the same time.
|
|
|
|
*/
|
|
|
|
guint clients_max, clients_cnt;
|
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
|
|
|
HttpdOutput(EventLoop &_loop);
|
|
|
|
~HttpdOutput();
|
|
|
|
|
|
|
|
bool Configure(const config_param *param, GError **error_r);
|
|
|
|
|
2013-01-27 23:23:46 +01:00
|
|
|
bool Bind(GError **error_r);
|
|
|
|
void Unbind();
|
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
|
|
|
/**
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
*/
|
|
|
|
bool OpenEncoder(struct audio_format *audio_format,
|
|
|
|
GError **error_r);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
*/
|
|
|
|
bool Open(struct audio_format *audio_format, GError **error_r);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
*/
|
|
|
|
void Close();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether there is at least one client.
|
|
|
|
*
|
|
|
|
* Caller must lock the mutex.
|
|
|
|
*/
|
|
|
|
gcc_pure
|
|
|
|
bool HasClients() const {
|
|
|
|
return !clients.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether there is at least one client.
|
|
|
|
*/
|
|
|
|
gcc_pure
|
|
|
|
bool LockHasClients() const {
|
|
|
|
const ScopeLock protect(mutex);
|
|
|
|
return HasClients();
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddClient(int fd);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes a client from the httpd_output.clients linked list.
|
|
|
|
*/
|
|
|
|
void RemoveClient(HttpdClient &client);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sends the encoder header to the client. This is called
|
|
|
|
* right after the response headers have been sent.
|
|
|
|
*/
|
|
|
|
void SendHeader(HttpdClient &client) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reads data from the encoder (as much as available) and
|
|
|
|
* returns it as a new #page object.
|
|
|
|
*/
|
2013-01-30 09:18:52 +01:00
|
|
|
Page *ReadPage();
|
2013-01-27 23:23:46 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Broadcasts a page struct to all clients.
|
|
|
|
*
|
|
|
|
* Mutext must not be locked.
|
|
|
|
*/
|
2013-01-30 09:18:52 +01:00
|
|
|
void BroadcastPage(Page *page);
|
2013-01-27 23:23:46 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Broadcasts data from the encoder to all clients.
|
|
|
|
*/
|
|
|
|
void BroadcastFromEncoder();
|
|
|
|
|
|
|
|
bool EncodeAndPlay(const void *chunk, size_t size, GError **error_r);
|
|
|
|
|
|
|
|
void SendTag(const struct 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
|
|
|
|
|
|
|
#endif
|