From 2830ee12c144dba3c7036acc086182891d351270 Mon Sep 17 00:00:00 2001 From: winlin Date: Fri, 11 Dec 2015 11:29:10 +0800 Subject: [PATCH 1/2] fix the on_hls.ts_url bug. --- trunk/src/app/srs_app_hls.cpp | 6 ++++++ trunk/src/app/srs_app_http_hooks.cpp | 9 ++++++++- trunk/src/app/srs_app_utility.cpp | 23 +++++++++++++++++++++++ trunk/src/app/srs_app_utility.hpp | 15 +++++++++++++++ trunk/src/kernel/srs_kernel_utility.cpp | 5 +++++ trunk/src/kernel/srs_kernel_utility.hpp | 1 + trunk/src/main/srs_main_ingest_hls.cpp | 4 ++-- 7 files changed, 60 insertions(+), 3 deletions(-) diff --git a/trunk/src/app/srs_app_hls.cpp b/trunk/src/app/srs_app_hls.cpp index c4da6e69d..02e0ba53e 100644 --- a/trunk/src/app/srs_app_hls.cpp +++ b/trunk/src/app/srs_app_hls.cpp @@ -557,6 +557,12 @@ int SrsHlsMuxer::segment_open(int64_t segment_start_dts) current->uri += hls_entry_prefix; if (!hls_entry_prefix.empty() && !srs_string_ends_with(hls_entry_prefix, "/")) { current->uri += "/"; + + // add the http dir to uri. + string http_dir = srs_path_dirname(m3u8_url); + if (!http_dir.empty()) { + current->uri += http_dir + "/"; + } } current->uri += ts_url; diff --git a/trunk/src/app/srs_app_http_hooks.cpp b/trunk/src/app/srs_app_http_hooks.cpp index 9395c1cfe..4a8b24d3d 100644 --- a/trunk/src/app/srs_app_http_hooks.cpp +++ b/trunk/src/app/srs_app_http_hooks.cpp @@ -38,6 +38,7 @@ using namespace std; #include #include #include +#include #define SRS_HTTP_RESPONSE_OK SRS_XSTR(ERROR_SUCCESS) @@ -300,6 +301,12 @@ int SrsHttpHooks::on_hls(int cid, string url, SrsRequest* req, string file, stri int client_id = cid; std::string cwd = _srs_config->cwd(); + // the ts_url is under the same dir of m3u8_url. + string prefix = srs_path_dirname(m3u8_url); + if (!prefix.empty() && !srs_string_is_http(ts_url)) { + ts_url = prefix + "/" + ts_url; + } + std::stringstream ss; ss << SRS_JOBJECT_START << SRS_JFIELD_STR("action", "on_hls") << SRS_JFIELD_CONT @@ -341,7 +348,7 @@ int SrsHttpHooks::on_hls_notify(int cid, std::string url, SrsRequest* req, std:: int client_id = cid; std::string cwd = _srs_config->cwd(); - if (srs_string_starts_with(ts_url, "http://") || srs_string_starts_with(ts_url, "https://")) { + if (srs_string_is_http(ts_url)) { url = ts_url; } diff --git a/trunk/src/app/srs_app_utility.cpp b/trunk/src/app/srs_app_utility.cpp index bc9dc9ee2..23bd2333f 100644 --- a/trunk/src/app/srs_app_utility.cpp +++ b/trunk/src/app/srs_app_utility.cpp @@ -29,6 +29,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include #include #include +#include #ifdef SRS_OSX #include @@ -45,6 +46,7 @@ using namespace std; #include #include #include +#include // the longest time to wait for a process to quit. #define SRS_PROCESS_QUIT_TIMEOUT_MS 1000 @@ -1349,6 +1351,27 @@ string srs_get_peer_ip(int fd) return ip; } +bool srs_string_is_http(string url) +{ + return srs_string_starts_with(url, "http://", "https://"); +} + +bool srs_is_digit_number(const string& str) +{ + if (str.empty()) { + return false; + } + + int v = ::atoi(str.c_str()); + int powv = (int)pow(10, str.length() - 1); + return v / powv >= 1 && v / powv <= 9; +} + +bool srs_is_boolean(const string& str) +{ + return str == "true" || str == "false"; +} + void srs_api_dump_summaries(std::stringstream& ss) { SrsRusage* r = srs_get_system_rusage(); diff --git a/trunk/src/app/srs_app_utility.hpp b/trunk/src/app/srs_app_utility.hpp index 0e2f6d426..e7548cdbd 100644 --- a/trunk/src/app/srs_app_utility.hpp +++ b/trunk/src/app/srs_app_utility.hpp @@ -668,6 +668,21 @@ extern int srs_get_local_port(int fd); // where peer ip is the client public ip which connected to server. extern std::string srs_get_peer_ip(int fd); +// whether the url is starts with http:// or https:// +extern bool srs_string_is_http(std::string url); + +// whether string is digit number +// is_digit("1234567890") === true +// is_digit("0123456789") === false +// is_digit("1234567890a") === false +// is_digit("a1234567890") === false +extern bool srs_is_digit_number(const std::string& str); +// whether string is boolean +// is_bool("true") == true +// is_bool("false") == true +// otherwise, false. +extern bool srs_is_boolean(const std::string& str); + // dump summaries for /api/v1/summaries. extern void srs_api_dump_summaries(std::stringstream& ss); diff --git a/trunk/src/kernel/srs_kernel_utility.cpp b/trunk/src/kernel/srs_kernel_utility.cpp index c37ad3b40..d51ca2817 100644 --- a/trunk/src/kernel/srs_kernel_utility.cpp +++ b/trunk/src/kernel/srs_kernel_utility.cpp @@ -279,6 +279,11 @@ bool srs_string_starts_with(string str, string flag) return str.find(flag) == 0; } +bool srs_string_starts_with(string str, string flag0, string flag1) +{ + return srs_string_starts_with(str, flag0) || srs_string_starts_with(str, flag1); +} + bool srs_string_contains(string str, string flag) { return str.find(flag) != string::npos; diff --git a/trunk/src/kernel/srs_kernel_utility.hpp b/trunk/src/kernel/srs_kernel_utility.hpp index 9202d1e43..a51772bb8 100644 --- a/trunk/src/kernel/srs_kernel_utility.hpp +++ b/trunk/src/kernel/srs_kernel_utility.hpp @@ -67,6 +67,7 @@ extern std::string srs_string_remove(std::string str, std::string remove_chars); extern bool srs_string_ends_with(std::string str, std::string flag); // whether string starts with extern bool srs_string_starts_with(std::string str, std::string flag); +extern bool srs_string_starts_with(std::string str, std::string flag0, std::string flag1); // whether string contains with extern bool srs_string_contains(std::string str, std::string flag); diff --git a/trunk/src/main/srs_main_ingest_hls.cpp b/trunk/src/main/srs_main_ingest_hls.cpp index 3df36200e..db3e88e4f 100644 --- a/trunk/src/main/srs_main_ingest_hls.cpp +++ b/trunk/src/main/srs_main_ingest_hls.cpp @@ -459,7 +459,7 @@ int SrsIngestSrsInput::parseM3u8(SrsHttpUri* url, double& td, double& duration) std::string m3u8_url = body.substr(0, pos); body = body.substr(pos + 1); - if (!srs_string_starts_with(m3u8_url, "http://")) { + if (!srs_string_is_http(m3u8_url)) { m3u8_url = srs_path_dirname(url->get_url()) + "/" + m3u8_url; } srs_trace("parse sub m3u8, url=%s", m3u8_url.c_str()); @@ -593,7 +593,7 @@ int SrsIngestSrsInput::SrsTsPiece::fetch(string m3u8) SrsHttpClient client; std::string ts_url = url; - if (!srs_string_starts_with(ts_url, "http://")) { + if (!srs_string_is_http(ts_url)) { ts_url = srs_path_dirname(m3u8) + "/" + url; } From 5660e2495364ea018492d292021644b9f240bdf5 Mon Sep 17 00:00:00 2001 From: winlin Date: Fri, 11 Dec 2015 10:30:13 +0800 Subject: [PATCH 2/2] fast stop server. --- trunk/src/app/srs_app_listener.cpp | 4 +++- trunk/src/app/srs_app_server.cpp | 18 +++++------------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/trunk/src/app/srs_app_listener.cpp b/trunk/src/app/srs_app_listener.cpp index 183343168..c1309e781 100644 --- a/trunk/src/app/srs_app_listener.cpp +++ b/trunk/src/app/srs_app_listener.cpp @@ -270,7 +270,9 @@ int SrsTcpListener::cycle() if(client_stfd == NULL){ // ignore error. - srs_error("ignore accept thread stoppped for accept client error"); + if (errno != EINTR) { + srs_error("ignore accept thread stoppped for accept client error"); + } return ret; } srs_verbose("get a client. fd=%d", st_netfd_fileno(client_stfd)); diff --git a/trunk/src/app/srs_app_server.cpp b/trunk/src/app/srs_app_server.cpp index ab0ea76ca..4d6876b2d 100755 --- a/trunk/src/app/srs_app_server.cpp +++ b/trunk/src/app/srs_app_server.cpp @@ -553,22 +553,13 @@ void SrsServer::dispose() close_listeners(SrsListenerRtsp); close_listeners(SrsListenerFlv); -#ifdef SRS_AUTO_INGEST - ingester->dispose(); -#endif + // @remark don't dispose ingesters, for too slow. + // dispose the source for hls and dvr. SrsSource::dispose_all(); - while (!conns.empty()) { - std::vector::iterator it; - for (it = conns.begin(); it != conns.end(); ++it) { - SrsConnection* conn = *it; - conn->dispose(); - } - - st_usleep(100 * 1000); - } - + // @remark don't dispose all connections, for too slow. + #ifdef SRS_AUTO_MEM_WATCH srs_memory_report(); #endif @@ -871,6 +862,7 @@ int SrsServer::cycle() st_usleep(3 * 1000 * 1000); srs_warn("system quit"); #else + // normally quit with neccessary cleanup by dispose(). srs_warn("main cycle terminated, system quit normally."); dispose(); srs_trace("srs terminated");