1
0
mirror of https://gitlab.xiph.org/xiph/icecast-server.git synced 2025-02-02 15:07:36 -05:00

Feature: Support sending idle/active events based on source count

This commit is contained in:
Philipp Schafft 2022-04-15 12:19:42 +00:00
parent 9bc4d9fe4d
commit cfb0d2dc38
7 changed files with 29 additions and 7 deletions

View File

@ -80,6 +80,8 @@
#define CONFIG_RANGE_SOURCE_TIMEOUT CONFIG_RANGE_CLIENT_TIMEOUT
#define CONFIG_DEFAULT_BODY_TIMEOUT (10 + CONFIG_DEFAULT_HEADER_TIMEOUT)
#define CONFIG_RANGE_BODY_TIMEOUT CONFIG_RANGE_CLIENT_TIMEOUT
#define CONFIG_DEFAULT_SERVER_IDLE_TIMEOUT 300
#define CONFIG_RANGE_SERVER_IDLE_TIMEOUT 15, 3600
#define CONFIG_DEFAULT_MASTER_USERNAME "relay"
#define CONFIG_DEFAULT_SHOUTCAST_MOUNT "/stream"
#define CONFIG_DEFAULT_SHOUTCAST_USER "source"
@ -1120,6 +1122,8 @@ static void _set_defaults(ice_config_t *configuration)
->source_timeout = CONFIG_DEFAULT_SOURCE_TIMEOUT;
configuration
->body_timeout = CONFIG_DEFAULT_BODY_TIMEOUT;
configuration
->server_idle_timeout = CONFIG_DEFAULT_SERVER_IDLE_TIMEOUT;
configuration
->shoutcast_mount = (char *) xmlCharStrdup(CONFIG_DEFAULT_SHOUTCAST_MOUNT);
configuration
@ -1469,6 +1473,8 @@ static void _parse_limits(xmlDocPtr doc,
__read_int(configuration, doc, node, &configuration->source_timeout, CONFIG_RANGE_SOURCE_TIMEOUT);
} else if (xmlStrcmp(node->name, XMLSTR("body-timeout")) == 0) {
__read_int(configuration, doc, node, &configuration->body_timeout, CONFIG_RANGE_BODY_TIMEOUT);
} else if (xmlStrcmp(node->name, XMLSTR("server-idle-timeout")) == 0) {
__read_int(configuration, doc, node, &configuration->server_idle_timeout, CONFIG_RANGE_SERVER_IDLE_TIMEOUT);
} else if (xmlStrcmp(node->name, XMLSTR("burst-on-connect")) == 0) {
__found_bad_tag(configuration, node, BTR_OBSOLETE, "Use <burst-size>.");
tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);

View File

@ -249,6 +249,7 @@ struct ice_config_tag {
int header_timeout;
int source_timeout;
int body_timeout;
int server_idle_timeout;
int fileserve;
int on_demand; /* global setting for all relays */

View File

@ -964,6 +964,7 @@ int connection_complete_source(source_t *source, int response)
}
global.sources++;
global.sources_update = time(NULL);
stats_event_args(NULL, "sources", "%d", global.sources);
global_unlock();

View File

@ -35,13 +35,8 @@ static mutex_t _global_mutex;
void global_initialize(void)
{
global.listensockets = NULL;
global.relays = NULL;
global.master_relays = NULL;
global.running = 0;
global.clients = 0;
global.sources = 0;
global.sources_legacy = 0;
memset(&global, 0, sizeof(global));
global.sources_update = time(NULL);
global.source_tree = avl_tree_new(source_compare_sources, NULL);
igloo_ro_new(&global.modulecontainer, module_container_t, igloo_instance);
thread_mutex_create(&_global_mutex);

View File

@ -34,6 +34,7 @@ typedef struct ice_global_tag
int running;
int sources;
time_t sources_update;
int sources_legacy;
int clients;
int schedule_config_reread;

View File

@ -58,6 +58,7 @@
#include "logging.h"
#include "source.h"
#include "format.h"
#include "event.h"
#define CATMODULE "slave"
@ -855,6 +856,7 @@ static void *_slave_thread(void *arg)
{
ice_config_t *config;
unsigned int interval = 0;
bool idlemode = false;
(void)arg;
@ -871,6 +873,12 @@ static void *_slave_thread(void *arg)
while (true) {
relay_t *cleanup_relays = NULL;
int skip_timer = 0;
bool active;
int server_idle_timeout;
config = config_get_config();
server_idle_timeout = config->server_idle_timeout;
config_release_config();
/* re-read xml file if requested */
global_lock();
@ -878,8 +886,17 @@ static void *_slave_thread(void *arg)
config_reread_config();
global.schedule_config_reread = 0;
}
active = global.sources || (global.sources_update + server_idle_timeout) > time(NULL);
global_unlock();
if (idlemode && active) {
event_emit_global("icecast-active");
idlemode = false;
} else if (!idlemode && !active) {
event_emit_global("icecast-idle");
idlemode = true;
}
thread_sleep(1000000);
thread_mutex_lock(&_slave_mutex);
if (slave_running == 0) {

View File

@ -936,6 +936,7 @@ static void source_shutdown (source_t *source)
global_lock();
global.sources--;
global.sources_update = time(NULL);
stats_event_args(NULL, "sources", "%d", global.sources);
global_unlock();