Skip to content

Commit

Permalink
Refine code.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Jun 20, 2024
1 parent 28422bf commit 8cd4e92
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 25 deletions.
2 changes: 2 additions & 0 deletions trunk/src/app/srs_app_dash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,8 @@ srs_utime_t SrsDash::cleanup_delay()
if (!enabled) {
return 0;
}

// We use larger timeout to cleanup the HLS, after disposed it if required.
return _srs_config->get_dash_dispose(req->vhost) * 1.1;
}

Expand Down
2 changes: 2 additions & 0 deletions trunk/src/app/srs_app_hls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,8 @@ srs_utime_t SrsHls::cleanup_delay()
if (!enabled) {
return 0;
}

// We use larger timeout to cleanup the HLS, after disposed it if required.
return _srs_config->get_hls_dispose(req->vhost) * 1.1;
}

Expand Down
44 changes: 22 additions & 22 deletions trunk/src/app/srs_app_http_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -953,19 +953,19 @@ SrsHttpStreamServer::~SrsHttpStreamServer()

if (true) {
std::map<std::string, SrsLiveEntry*>::iterator it;
for (it = tflvs.begin(); it != tflvs.end(); ++it) {
for (it = templateHandlers.begin(); it != templateHandlers.end(); ++it) {
SrsLiveEntry* entry = it->second;
srs_freep(entry);
}
tflvs.clear();
templateHandlers.clear();
}
if (true) {
std::map<std::string, SrsLiveEntry*>::iterator it;
for (it = sflvs.begin(); it != sflvs.end(); ++it) {
for (it = streamHandlers.begin(); it != streamHandlers.end(); ++it) {
SrsLiveEntry* entry = it->second;
srs_freep(entry);
}
sflvs.clear();
streamHandlers.clear();
}
}

Expand All @@ -991,12 +991,12 @@ srs_error_t SrsHttpStreamServer::http_mount(SrsRequest* r)
SrsLiveEntry* entry = NULL;

// create stream from template when not found.
if (sflvs.find(sid) == sflvs.end()) {
if (tflvs.find(r->vhost) == tflvs.end()) {
if (streamHandlers.find(sid) == streamHandlers.end()) {
if (templateHandlers.find(r->vhost) == templateHandlers.end()) {
return err;
}

SrsLiveEntry* tmpl = tflvs[r->vhost];
SrsLiveEntry* tmpl = templateHandlers[r->vhost];

std::string mount = tmpl->mount;

Expand All @@ -1023,24 +1023,24 @@ srs_error_t SrsHttpStreamServer::http_mount(SrsRequest* r)
srs_freep(tmpl->req);

tmpl->req = r->copy()->as_http();
sflvs[sid] = entry;

streamHandlers[sid] = entry;

// mount the http flv stream.
// we must register the handler, then start the thread,
// for the thread will cause thread switch context.
if ((err = mux.handle(mount, entry->stream)) != srs_success) {
return srs_error_wrap(err, "http: mount flv stream for vhost=%s failed", sid.c_str());
}

// start http stream cache thread
if ((err = entry->cache->start()) != srs_success) {
return srs_error_wrap(err, "http: start stream cache failed");
}
srs_trace("http: mount flv stream for sid=%s, mount=%s", sid.c_str(), mount.c_str());
} else {
// The entry exists, we reuse it and update the request of stream and cache.
entry = sflvs[sid];
entry = streamHandlers[sid];
entry->stream->update_auth(r);
entry->cache->update_auth(r);
}
Expand All @@ -1057,15 +1057,15 @@ void SrsHttpStreamServer::http_unmount(SrsRequest* r)
{
std::string sid = r->get_stream_url();

std::map<std::string, SrsLiveEntry*>::iterator it = sflvs.find(sid);
if (it == sflvs.end()) {
std::map<std::string, SrsLiveEntry*>::iterator it = streamHandlers.find(sid);
if (it == streamHandlers.end()) {
return;
}

// Free all HTTP resources.
SrsLiveEntry* entry = it->second;
SrsAutoFree(SrsLiveEntry, entry);
sflvs.erase(it);
streamHandlers.erase(it);

SrsLiveStream* stream = entry->stream;
SrsAutoFree(SrsLiveStream, stream);
Expand Down Expand Up @@ -1118,8 +1118,8 @@ srs_error_t SrsHttpStreamServer::hijack(ISrsHttpMessage* request, ISrsHttpHandle
SrsLiveEntry* entry = NULL;
if (true) {
// no http streaming on vhost, ignore.
std::map<std::string, SrsLiveEntry*>::iterator it = tflvs.find(vhost->arg0());
if (it == tflvs.end()) {
std::map<std::string, SrsLiveEntry*>::iterator it = templateHandlers.find(vhost->arg0());
if (it == templateHandlers.end()) {
return err;
}

Expand Down Expand Up @@ -1175,8 +1175,8 @@ srs_error_t SrsHttpStreamServer::hijack(ISrsHttpMessage* request, ISrsHttpHandle
std::string sid = r->get_stream_url();
// check whether the http remux is enabled,
// for example, user disable the http flv then reload.
if (sflvs.find(sid) != sflvs.end()) {
SrsLiveEntry* s_entry = sflvs[sid];
if (streamHandlers.find(sid) != streamHandlers.end()) {
SrsLiveEntry* s_entry = streamHandlers[sid];
if (!s_entry->stream->entry->enabled) {
// only when the http entry is disabled, check the config whether http flv disable,
// for the http flv edge use hijack to trigger the edge ingester, we always mount it
Expand Down Expand Up @@ -1205,8 +1205,8 @@ srs_error_t SrsHttpStreamServer::hijack(ISrsHttpMessage* request, ISrsHttpHandle

// use the handler if exists.
if (ph) {
if (sflvs.find(sid) != sflvs.end()) {
entry = sflvs[sid];
if (streamHandlers.find(sid) != streamHandlers.end()) {
entry = streamHandlers[sid];
*ph = entry->stream;
}
}
Expand Down Expand Up @@ -1249,8 +1249,8 @@ srs_error_t SrsHttpStreamServer::initialize_flv_entry(std::string vhost)
}

SrsLiveEntry* entry = new SrsLiveEntry(_srs_config->get_vhost_http_remux_mount(vhost));
tflvs[vhost] = entry;

templateHandlers[vhost] = entry;
srs_trace("http flv live stream, vhost=%s, mount=%s", vhost.c_str(), entry->mount.c_str());

return err;
Expand Down
6 changes: 3 additions & 3 deletions trunk/src/app/srs_app_http_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ class SrsHttpStreamServer : public ISrsReloadHandler
public:
SrsHttpServeMux mux;
// The http live streaming template, to create streams.
std::map<std::string, SrsLiveEntry*> tflvs;
// The http live streaming streams, crote by template.
std::map<std::string, SrsLiveEntry*> sflvs;
std::map<std::string, SrsLiveEntry*> templateHandlers;
// The http live streaming streams, created by template.
std::map<std::string, SrsLiveEntry*> streamHandlers;
public:
SrsHttpStreamServer(SrsServer* svr);
virtual ~SrsHttpStreamServer();
Expand Down

0 comments on commit 8cd4e92

Please sign in to comment.