正在显示
7 个修改的文件
包含
60 行增加
和
3 行删除
| @@ -557,6 +557,12 @@ int SrsHlsMuxer::segment_open(int64_t segment_start_dts) | @@ -557,6 +557,12 @@ int SrsHlsMuxer::segment_open(int64_t segment_start_dts) | ||
| 557 | current->uri += hls_entry_prefix; | 557 | current->uri += hls_entry_prefix; |
| 558 | if (!hls_entry_prefix.empty() && !srs_string_ends_with(hls_entry_prefix, "/")) { | 558 | if (!hls_entry_prefix.empty() && !srs_string_ends_with(hls_entry_prefix, "/")) { |
| 559 | current->uri += "/"; | 559 | current->uri += "/"; |
| 560 | + | ||
| 561 | + // add the http dir to uri. | ||
| 562 | + string http_dir = srs_path_dirname(m3u8_url); | ||
| 563 | + if (!http_dir.empty()) { | ||
| 564 | + current->uri += http_dir + "/"; | ||
| 565 | + } | ||
| 560 | } | 566 | } |
| 561 | current->uri += ts_url; | 567 | current->uri += ts_url; |
| 562 | 568 |
| @@ -38,6 +38,7 @@ using namespace std; | @@ -38,6 +38,7 @@ using namespace std; | ||
| 38 | #include <srs_app_config.hpp> | 38 | #include <srs_app_config.hpp> |
| 39 | #include <srs_kernel_utility.hpp> | 39 | #include <srs_kernel_utility.hpp> |
| 40 | #include <srs_app_http_conn.hpp> | 40 | #include <srs_app_http_conn.hpp> |
| 41 | +#include <srs_app_utility.hpp> | ||
| 41 | 42 | ||
| 42 | #define SRS_HTTP_RESPONSE_OK SRS_XSTR(ERROR_SUCCESS) | 43 | #define SRS_HTTP_RESPONSE_OK SRS_XSTR(ERROR_SUCCESS) |
| 43 | 44 | ||
| @@ -300,6 +301,12 @@ int SrsHttpHooks::on_hls(int cid, string url, SrsRequest* req, string file, stri | @@ -300,6 +301,12 @@ int SrsHttpHooks::on_hls(int cid, string url, SrsRequest* req, string file, stri | ||
| 300 | int client_id = cid; | 301 | int client_id = cid; |
| 301 | std::string cwd = _srs_config->cwd(); | 302 | std::string cwd = _srs_config->cwd(); |
| 302 | 303 | ||
| 304 | + // the ts_url is under the same dir of m3u8_url. | ||
| 305 | + string prefix = srs_path_dirname(m3u8_url); | ||
| 306 | + if (!prefix.empty() && !srs_string_is_http(ts_url)) { | ||
| 307 | + ts_url = prefix + "/" + ts_url; | ||
| 308 | + } | ||
| 309 | + | ||
| 303 | std::stringstream ss; | 310 | std::stringstream ss; |
| 304 | ss << SRS_JOBJECT_START | 311 | ss << SRS_JOBJECT_START |
| 305 | << SRS_JFIELD_STR("action", "on_hls") << SRS_JFIELD_CONT | 312 | << 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:: | @@ -341,7 +348,7 @@ int SrsHttpHooks::on_hls_notify(int cid, std::string url, SrsRequest* req, std:: | ||
| 341 | int client_id = cid; | 348 | int client_id = cid; |
| 342 | std::string cwd = _srs_config->cwd(); | 349 | std::string cwd = _srs_config->cwd(); |
| 343 | 350 | ||
| 344 | - if (srs_string_starts_with(ts_url, "http://") || srs_string_starts_with(ts_url, "https://")) { | 351 | + if (srs_string_is_http(ts_url)) { |
| 345 | url = ts_url; | 352 | url = ts_url; |
| 346 | } | 353 | } |
| 347 | 354 |
| @@ -29,6 +29,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -29,6 +29,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 29 | #include <arpa/inet.h> | 29 | #include <arpa/inet.h> |
| 30 | #include <signal.h> | 30 | #include <signal.h> |
| 31 | #include <sys/wait.h> | 31 | #include <sys/wait.h> |
| 32 | +#include <math.h> | ||
| 32 | 33 | ||
| 33 | #ifdef SRS_OSX | 34 | #ifdef SRS_OSX |
| 34 | #include <sys/sysctl.h> | 35 | #include <sys/sysctl.h> |
| @@ -45,6 +46,7 @@ using namespace std; | @@ -45,6 +46,7 @@ using namespace std; | ||
| 45 | #include <srs_protocol_kbps.hpp> | 46 | #include <srs_protocol_kbps.hpp> |
| 46 | #include <srs_protocol_json.hpp> | 47 | #include <srs_protocol_json.hpp> |
| 47 | #include <srs_kernel_stream.hpp> | 48 | #include <srs_kernel_stream.hpp> |
| 49 | +#include <srs_kernel_utility.hpp> | ||
| 48 | 50 | ||
| 49 | // the longest time to wait for a process to quit. | 51 | // the longest time to wait for a process to quit. |
| 50 | #define SRS_PROCESS_QUIT_TIMEOUT_MS 1000 | 52 | #define SRS_PROCESS_QUIT_TIMEOUT_MS 1000 |
| @@ -1349,6 +1351,27 @@ string srs_get_peer_ip(int fd) | @@ -1349,6 +1351,27 @@ string srs_get_peer_ip(int fd) | ||
| 1349 | return ip; | 1351 | return ip; |
| 1350 | } | 1352 | } |
| 1351 | 1353 | ||
| 1354 | +bool srs_string_is_http(string url) | ||
| 1355 | +{ | ||
| 1356 | + return srs_string_starts_with(url, "http://", "https://"); | ||
| 1357 | +} | ||
| 1358 | + | ||
| 1359 | +bool srs_is_digit_number(const string& str) | ||
| 1360 | +{ | ||
| 1361 | + if (str.empty()) { | ||
| 1362 | + return false; | ||
| 1363 | + } | ||
| 1364 | + | ||
| 1365 | + int v = ::atoi(str.c_str()); | ||
| 1366 | + int powv = (int)pow(10, str.length() - 1); | ||
| 1367 | + return v / powv >= 1 && v / powv <= 9; | ||
| 1368 | +} | ||
| 1369 | + | ||
| 1370 | +bool srs_is_boolean(const string& str) | ||
| 1371 | +{ | ||
| 1372 | + return str == "true" || str == "false"; | ||
| 1373 | +} | ||
| 1374 | + | ||
| 1352 | void srs_api_dump_summaries(std::stringstream& ss) | 1375 | void srs_api_dump_summaries(std::stringstream& ss) |
| 1353 | { | 1376 | { |
| 1354 | SrsRusage* r = srs_get_system_rusage(); | 1377 | SrsRusage* r = srs_get_system_rusage(); |
| @@ -668,6 +668,21 @@ extern int srs_get_local_port(int fd); | @@ -668,6 +668,21 @@ extern int srs_get_local_port(int fd); | ||
| 668 | // where peer ip is the client public ip which connected to server. | 668 | // where peer ip is the client public ip which connected to server. |
| 669 | extern std::string srs_get_peer_ip(int fd); | 669 | extern std::string srs_get_peer_ip(int fd); |
| 670 | 670 | ||
| 671 | +// whether the url is starts with http:// or https:// | ||
| 672 | +extern bool srs_string_is_http(std::string url); | ||
| 673 | + | ||
| 674 | +// whether string is digit number | ||
| 675 | +// is_digit("1234567890") === true | ||
| 676 | +// is_digit("0123456789") === false | ||
| 677 | +// is_digit("1234567890a") === false | ||
| 678 | +// is_digit("a1234567890") === false | ||
| 679 | +extern bool srs_is_digit_number(const std::string& str); | ||
| 680 | +// whether string is boolean | ||
| 681 | +// is_bool("true") == true | ||
| 682 | +// is_bool("false") == true | ||
| 683 | +// otherwise, false. | ||
| 684 | +extern bool srs_is_boolean(const std::string& str); | ||
| 685 | + | ||
| 671 | // dump summaries for /api/v1/summaries. | 686 | // dump summaries for /api/v1/summaries. |
| 672 | extern void srs_api_dump_summaries(std::stringstream& ss); | 687 | extern void srs_api_dump_summaries(std::stringstream& ss); |
| 673 | 688 |
| @@ -279,6 +279,11 @@ bool srs_string_starts_with(string str, string flag) | @@ -279,6 +279,11 @@ bool srs_string_starts_with(string str, string flag) | ||
| 279 | return str.find(flag) == 0; | 279 | return str.find(flag) == 0; |
| 280 | } | 280 | } |
| 281 | 281 | ||
| 282 | +bool srs_string_starts_with(string str, string flag0, string flag1) | ||
| 283 | +{ | ||
| 284 | + return srs_string_starts_with(str, flag0) || srs_string_starts_with(str, flag1); | ||
| 285 | +} | ||
| 286 | + | ||
| 282 | bool srs_string_contains(string str, string flag) | 287 | bool srs_string_contains(string str, string flag) |
| 283 | { | 288 | { |
| 284 | return str.find(flag) != string::npos; | 289 | return str.find(flag) != string::npos; |
| @@ -67,6 +67,7 @@ extern std::string srs_string_remove(std::string str, std::string remove_chars); | @@ -67,6 +67,7 @@ extern std::string srs_string_remove(std::string str, std::string remove_chars); | ||
| 67 | extern bool srs_string_ends_with(std::string str, std::string flag); | 67 | extern bool srs_string_ends_with(std::string str, std::string flag); |
| 68 | // whether string starts with | 68 | // whether string starts with |
| 69 | extern bool srs_string_starts_with(std::string str, std::string flag); | 69 | extern bool srs_string_starts_with(std::string str, std::string flag); |
| 70 | +extern bool srs_string_starts_with(std::string str, std::string flag0, std::string flag1); | ||
| 70 | // whether string contains with | 71 | // whether string contains with |
| 71 | extern bool srs_string_contains(std::string str, std::string flag); | 72 | extern bool srs_string_contains(std::string str, std::string flag); |
| 72 | 73 |
| @@ -459,7 +459,7 @@ int SrsIngestSrsInput::parseM3u8(SrsHttpUri* url, double& td, double& duration) | @@ -459,7 +459,7 @@ int SrsIngestSrsInput::parseM3u8(SrsHttpUri* url, double& td, double& duration) | ||
| 459 | std::string m3u8_url = body.substr(0, pos); | 459 | std::string m3u8_url = body.substr(0, pos); |
| 460 | body = body.substr(pos + 1); | 460 | body = body.substr(pos + 1); |
| 461 | 461 | ||
| 462 | - if (!srs_string_starts_with(m3u8_url, "http://")) { | 462 | + if (!srs_string_is_http(m3u8_url)) { |
| 463 | m3u8_url = srs_path_dirname(url->get_url()) + "/" + m3u8_url; | 463 | m3u8_url = srs_path_dirname(url->get_url()) + "/" + m3u8_url; |
| 464 | } | 464 | } |
| 465 | srs_trace("parse sub m3u8, url=%s", m3u8_url.c_str()); | 465 | srs_trace("parse sub m3u8, url=%s", m3u8_url.c_str()); |
| @@ -593,7 +593,7 @@ int SrsIngestSrsInput::SrsTsPiece::fetch(string m3u8) | @@ -593,7 +593,7 @@ int SrsIngestSrsInput::SrsTsPiece::fetch(string m3u8) | ||
| 593 | SrsHttpClient client; | 593 | SrsHttpClient client; |
| 594 | 594 | ||
| 595 | std::string ts_url = url; | 595 | std::string ts_url = url; |
| 596 | - if (!srs_string_starts_with(ts_url, "http://")) { | 596 | + if (!srs_string_is_http(ts_url)) { |
| 597 | ts_url = srs_path_dirname(m3u8) + "/" + url; | 597 | ts_url = srs_path_dirname(m3u8) + "/" + url; |
| 598 | } | 598 | } |
| 599 | 599 |
-
请 注册 或 登录 后发表评论