mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 03:41:55 +00:00
support reload http_stream
This commit is contained in:
parent
c33ff4fdb8
commit
dc3c3cff8e
6 changed files with 212 additions and 1 deletions
|
@ -572,6 +572,11 @@ int SrsConfig::reload()
|
|||
if ((ret = reload_http_api(old_root)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// merge config: http_stream
|
||||
if ((ret = reload_http_stream(old_root)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
// merge config: vhost
|
||||
if ((ret = reload_vhost(old_root)) != ERROR_SUCCESS) {
|
||||
|
@ -646,6 +651,71 @@ int SrsConfig::reload_http_api(SrsConfDirective* old_root)
|
|||
return ret;
|
||||
}
|
||||
|
||||
int SrsConfig::reload_http_stream(SrsConfDirective* old_root)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
// merge config.
|
||||
std::vector<ISrsReloadHandler*>::iterator it;
|
||||
|
||||
// state graph
|
||||
// old_http_stream new_http_stream
|
||||
// DISABLED => ENABLED
|
||||
// ENABLED => DISABLED
|
||||
// ENABLED => ENABLED (modified)
|
||||
|
||||
SrsConfDirective* new_http_stream = root->get("http_stream");
|
||||
SrsConfDirective* old_http_stream = old_root->get("http_stream");
|
||||
|
||||
// DISABLED => ENABLED
|
||||
if (!get_http_stream_enabled(old_http_stream) && get_http_stream_enabled(new_http_stream)) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_http_stream_enabled()) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes http_stream disabled=>enabled failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("reload disabled=>enabled http_stream success.");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ENABLED => DISABLED
|
||||
if (get_http_stream_enabled(old_http_stream) && !get_http_stream_enabled(new_http_stream)) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_http_stream_disabled()) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes http_stream enabled=>disabled failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("reload enabled=>disabled http_stream success.");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// ENABLED => ENABLED (modified)
|
||||
if (get_http_stream_enabled(old_http_stream) && get_http_stream_enabled(new_http_stream)
|
||||
&& !srs_directive_equals(old_http_stream, new_http_stream)
|
||||
) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_http_stream_updated()) != ERROR_SUCCESS) {
|
||||
srs_error("notify subscribes http_stream enabled modified failed. ret=%d", ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("reload enabled modified http_stream success.");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
srs_trace("reload http_stream not changed success.");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SrsConfig::reload_vhost(SrsConfDirective* old_root)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
@ -774,6 +844,17 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root)
|
|||
}
|
||||
srs_trace("vhost %s reload hls success.", vhost.c_str());
|
||||
}
|
||||
// http, only one per vhost.
|
||||
if (!srs_directive_equals(new_vhost->get("http"), old_vhost->get("http"))) {
|
||||
for (it = subscribes.begin(); it != subscribes.end(); ++it) {
|
||||
ISrsReloadHandler* subscribe = *it;
|
||||
if ((ret = subscribe->on_reload_vhost_http_updated()) != ERROR_SUCCESS) {
|
||||
srs_error("vhost %s notify subscribes http failed. ret=%d", vhost.c_str(), ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
srs_trace("vhost %s reload http success.", vhost.c_str());
|
||||
}
|
||||
// transcode, many per vhost.
|
||||
if ((ret = reload_transcode(new_vhost, old_vhost)) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
|
@ -2232,6 +2313,11 @@ SrsConfDirective* SrsConfig::get_http_stream()
|
|||
bool SrsConfig::get_http_stream_enabled()
|
||||
{
|
||||
SrsConfDirective* conf = get_http_stream();
|
||||
return get_http_stream_enabled(conf);
|
||||
}
|
||||
|
||||
bool SrsConfig::get_http_stream_enabled(SrsConfDirective* conf)
|
||||
{
|
||||
if (!conf) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -125,6 +125,7 @@ public:
|
|||
virtual int reload();
|
||||
private:
|
||||
virtual int reload_http_api(SrsConfDirective* old_root);
|
||||
virtual int reload_http_stream(SrsConfDirective* old_root);
|
||||
virtual int reload_vhost(SrsConfDirective* old_root);
|
||||
virtual int reload_transcode(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost);
|
||||
virtual int reload_ingest(SrsConfDirective* new_vhost, SrsConfDirective* old_vhost);
|
||||
|
@ -231,6 +232,7 @@ private:
|
|||
virtual SrsConfDirective* get_http_stream();
|
||||
public:
|
||||
virtual bool get_http_stream_enabled();
|
||||
virtual bool get_http_stream_enabled(SrsConfDirective* conf);
|
||||
virtual int get_http_stream_listen();
|
||||
virtual std::string get_http_stream_dir();
|
||||
public:
|
||||
|
|
|
@ -75,6 +75,26 @@ int ISrsReloadHandler::on_reload_http_api_disabled()
|
|||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
int ISrsReloadHandler::on_reload_http_stream_enabled()
|
||||
{
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
int ISrsReloadHandler::on_reload_http_stream_disabled()
|
||||
{
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
int ISrsReloadHandler::on_reload_http_stream_updated()
|
||||
{
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
int ISrsReloadHandler::on_reload_vhost_http_updated()
|
||||
{
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
int ISrsReloadHandler::on_reload_vhost_added(string /*vhost*/)
|
||||
{
|
||||
return ERROR_SUCCESS;
|
||||
|
|
|
@ -49,6 +49,10 @@ public:
|
|||
virtual int on_reload_pithy_print();
|
||||
virtual int on_reload_http_api_enabled();
|
||||
virtual int on_reload_http_api_disabled();
|
||||
virtual int on_reload_http_stream_enabled();
|
||||
virtual int on_reload_http_stream_disabled();
|
||||
virtual int on_reload_http_stream_updated();
|
||||
virtual int on_reload_vhost_http_updated();
|
||||
virtual int on_reload_vhost_added(std::string vhost);
|
||||
virtual int on_reload_vhost_removed(std::string vhost);
|
||||
virtual int on_reload_atc(std::string vhost);
|
||||
|
|
|
@ -618,16 +618,109 @@ int SrsServer::on_reload_pid()
|
|||
return acquire_pid_file();
|
||||
}
|
||||
|
||||
int SrsServer::on_reload_vhost_added(std::string vhost)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
#ifdef SRS_HTTP_SERVER
|
||||
if (!_srs_config->get_vhost_http_enabled(vhost)) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((ret = on_reload_vhost_http_updated()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SrsServer::on_reload_vhost_removed(std::string vhost)
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
#ifdef SRS_HTTP_SERVER
|
||||
if ((ret = on_reload_vhost_http_updated()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SrsServer::on_reload_vhost_http_updated()
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
#ifdef SRS_HTTP_SERVER
|
||||
srs_freep(http_stream_handler);
|
||||
http_stream_handler = SrsHttpHandler::create_http_stream();
|
||||
|
||||
if ((ret = http_stream_handler->initialize()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SrsServer::on_reload_http_api_enabled()
|
||||
{
|
||||
return listen_http_api();
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
#ifdef SRS_HTTP_API
|
||||
ret = listen_http_api();
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SrsServer::on_reload_http_api_disabled()
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
#ifdef SRS_HTTP_API
|
||||
close_listeners(SrsListenerHttpApi);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SrsServer::on_reload_http_stream_enabled()
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
#ifdef SRS_HTTP_SERVER
|
||||
ret = listen_http_stream();
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SrsServer::on_reload_http_stream_disabled()
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
#ifdef SRS_HTTP_SERVER
|
||||
close_listeners(SrsListenerHttpStream);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int SrsServer::on_reload_http_stream_updated()
|
||||
{
|
||||
int ret = ERROR_SUCCESS;
|
||||
|
||||
#ifdef SRS_HTTP_SERVER
|
||||
if ((ret = on_reload_http_stream_enabled()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((ret = on_reload_vhost_http_updated()) != ERROR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -116,8 +116,14 @@ private:
|
|||
public:
|
||||
virtual int on_reload_listen();
|
||||
virtual int on_reload_pid();
|
||||
virtual int on_reload_vhost_added(std::string vhost);
|
||||
virtual int on_reload_vhost_removed(std::string vhost);
|
||||
virtual int on_reload_vhost_http_updated();
|
||||
virtual int on_reload_http_api_enabled();
|
||||
virtual int on_reload_http_api_disabled();
|
||||
virtual int on_reload_http_stream_enabled();
|
||||
virtual int on_reload_http_stream_disabled();
|
||||
virtual int on_reload_http_stream_updated();
|
||||
};
|
||||
|
||||
#endif
|
Loading…
Reference in a new issue