From 917f6d066df95aba3fd497cda98f13b0124d886d Mon Sep 17 00:00:00 2001 From: winlin Date: Tue, 16 Apr 2019 08:20:32 +0800 Subject: [PATCH] Refine get_hls_window in time unit --- trunk/src/app/srs_app_config.cpp | 6 +++--- trunk/src/app/srs_app_config.hpp | 4 ++-- trunk/src/app/srs_app_fragment.cpp | 4 ++-- trunk/src/app/srs_app_fragment.hpp | 2 +- trunk/src/app/srs_app_hls.cpp | 10 +++++----- trunk/src/app/srs_app_hls.hpp | 4 ++-- trunk/src/utest/srs_utest_config.cpp | 4 +++- 7 files changed, 18 insertions(+), 16 deletions(-) diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index f18e727bc..92ba24982 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -6144,9 +6144,9 @@ double SrsConfig::get_hls_aof_ratio(string vhost) return ::atof(conf->arg0().c_str()); } -double SrsConfig::get_hls_window(string vhost) +srs_utime_t SrsConfig::get_hls_window(string vhost) { - static double DEFAULT = 60; + static srs_utime_t DEFAULT = (60 * SRS_UTIME_SECONDS); SrsConfDirective* conf = get_hls(vhost); if (!conf) { @@ -6158,7 +6158,7 @@ double SrsConfig::get_hls_window(string vhost) return DEFAULT; } - return ::atof(conf->arg0().c_str()); + return srs_utime_t(::atof(conf->arg0().c_str()) * SRS_UTIME_SECONDS); } string SrsConfig::get_hls_on_error(string vhost) diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index 1ba9f197a..235bb715f 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -1204,11 +1204,11 @@ public: */ virtual double get_hls_aof_ratio(std::string vhost); /** - * get the hls window time, in seconds. + * get the hls window time, in srs_utime_t. * a window is a set of ts, the ts collection in m3u8. * @remark SRS will delete the ts exceed the window. */ - virtual double get_hls_window(std::string vhost); + virtual srs_utime_t get_hls_window(std::string vhost); /** * get the hls hls_on_error config. * the ignore will ignore error and disable hls. diff --git a/trunk/src/app/srs_app_fragment.cpp b/trunk/src/app/srs_app_fragment.cpp index ee7df6eb2..9bc778886 100644 --- a/trunk/src/app/srs_app_fragment.cpp +++ b/trunk/src/app/srs_app_fragment.cpp @@ -201,7 +201,7 @@ void SrsFragmentWindow::append(SrsFragment* fragment) fragments.push_back(fragment); } -void SrsFragmentWindow::shrink(int64_t window) +void SrsFragmentWindow::shrink(srs_utime_t window) { srs_utime_t duration = 0; @@ -211,7 +211,7 @@ void SrsFragmentWindow::shrink(int64_t window) SrsFragment* fragment = fragments[i]; duration += fragment->duration(); - if (srsu2ms(duration) > window) { + if (duration > window) { remove_index = i; break; } diff --git a/trunk/src/app/srs_app_fragment.hpp b/trunk/src/app/srs_app_fragment.hpp index b1aa15f60..b64c87e2e 100644 --- a/trunk/src/app/srs_app_fragment.hpp +++ b/trunk/src/app/srs_app_fragment.hpp @@ -93,7 +93,7 @@ public: // Append a new fragment, which is ready to delivery to client. virtual void append(SrsFragment* fragment); // Shrink the window, push the expired fragment to a queue. - virtual void shrink(int64_t window); + virtual void shrink(srs_utime_t window); // Clear the expired fragments. virtual void clear_expired(bool delete_files); // Get the max duration in ms of all fragments. diff --git a/trunk/src/app/srs_app_hls.cpp b/trunk/src/app/srs_app_hls.cpp index 8813722ac..4a3697d12 100644 --- a/trunk/src/app/srs_app_hls.cpp +++ b/trunk/src/app/srs_app_hls.cpp @@ -279,7 +279,7 @@ srs_error_t SrsHlsMuxer::initialize() } srs_error_t SrsHlsMuxer::update_config(SrsRequest* r, string entry_prefix, - string path, string m3u8_file, string ts_file, srs_utime_t fragment, double window, + string path, string m3u8_file, string ts_file, srs_utime_t fragment, srs_utime_t window, bool ts_floor, double aof_ratio, bool cleanup, bool wait_keyframe, bool keys, int fragments_per_key, string key_file ,string key_file_path, string key_url) { @@ -627,7 +627,7 @@ srs_error_t SrsHlsMuxer::segment_close() } // shrink the segments. - segments->shrink(hls_window * 1000); + segments->shrink(hls_window); // refresh the m3u8, donot contains the removed ts err = refresh_m3u8(); @@ -855,7 +855,7 @@ srs_error_t SrsHlsController::on_publish(SrsRequest* req) std::string app = req->app; srs_utime_t hls_fragment = _srs_config->get_hls_fragment(vhost); - double hls_window = _srs_config->get_hls_window(vhost); + srs_utime_t hls_window = _srs_config->get_hls_window(vhost); // get the hls m3u8 ts list entry prefix config std::string entry_prefix = _srs_config->get_hls_entry_prefix(vhost); @@ -891,8 +891,8 @@ srs_error_t SrsHlsController::on_publish(SrsRequest* req) if ((err = muxer->segment_open()) != srs_success) { return srs_error_wrap(err, "hls: segment open"); } - srs_trace("hls: win=%.2f, frag=%dms, prefix=%s, path=%s, m3u8=%s, ts=%s, aof=%.2f, floor=%d, clean=%d, waitk=%d, dispose=%dms", - hls_window, srsu2msi(hls_fragment), entry_prefix.c_str(), path.c_str(), m3u8_file.c_str(), + srs_trace("hls: win=%dms, frag=%dms, prefix=%s, path=%s, m3u8=%s, ts=%s, aof=%.2f, floor=%d, clean=%d, waitk=%d, dispose=%dms", + srsu2msi(hls_window), srsu2msi(hls_fragment), entry_prefix.c_str(), path.c_str(), m3u8_file.c_str(), ts_file.c_str(), hls_aof_ratio, ts_floor, cleanup, wait_keyframe, srsu2msi(hls_dispose)); return err; diff --git a/trunk/src/app/srs_app_hls.hpp b/trunk/src/app/srs_app_hls.hpp index 8f953ca43..bedf6aa13 100644 --- a/trunk/src/app/srs_app_hls.hpp +++ b/trunk/src/app/srs_app_hls.hpp @@ -140,7 +140,7 @@ private: double hls_aof_ratio; // TODO: FIXME: Use TBN 1000. srs_utime_t hls_fragment; - double hls_window; + srs_utime_t hls_window; SrsAsyncCallWorker* async; private: // whether use floor algorithm for timestamp. @@ -201,7 +201,7 @@ public: */ virtual srs_error_t update_config(SrsRequest* r, std::string entry_prefix, std::string path, std::string m3u8_file, std::string ts_file, - srs_utime_t fragment, double window, bool ts_floor, double aof_ratio, + srs_utime_t fragment, srs_utime_t window, bool ts_floor, double aof_ratio, bool cleanup, bool wait_keyframe, bool keys, int fragments_per_key, std::string key_file, std::string key_file_path, std::string key_url); /** diff --git a/trunk/src/utest/srs_utest_config.cpp b/trunk/src/utest/srs_utest_config.cpp index 5421dafaa..90f2d4099 100644 --- a/trunk/src/utest/srs_utest_config.cpp +++ b/trunk/src/utest/srs_utest_config.cpp @@ -1871,10 +1871,12 @@ VOID TEST(ConfigUnitTest, CheckDefaultValuesVhost) EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF)); EXPECT_EQ(0, conf.get_hls_dispose("")); EXPECT_EQ(10 * SRS_UTIME_SECONDS, conf.get_hls_fragment("")); + EXPECT_EQ(60 * SRS_UTIME_SECONDS, conf.get_hls_window("")); - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{hls{hls_dispose 10;hls_fragment 20;}}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{hls{hls_dispose 10;hls_fragment 20;hls_window 30;}}")); EXPECT_EQ(10 * SRS_UTIME_SECONDS, conf.get_hls_dispose("v")); EXPECT_EQ(20 * SRS_UTIME_SECONDS, conf.get_hls_fragment("v")); + EXPECT_EQ(30 * SRS_UTIME_SECONDS, conf.get_hls_window("v")); } if (true) {