From 12cf17ef6b207fd2871cd66d683160b32b11c3b1 Mon Sep 17 00:00:00 2001 From: winlin Date: Mon, 8 Apr 2019 09:10:06 +0800 Subject: [PATCH] Refine get_dash_update_period in time unit --- trunk/src/app/srs_app_config.cpp | 6 +++--- trunk/src/app/srs_app_config.hpp | 6 +++--- trunk/src/app/srs_app_dash.cpp | 6 +++--- trunk/src/app/srs_app_dash.hpp | 6 +++--- trunk/src/utest/srs_utest_config.cpp | 4 +++- 5 files changed, 15 insertions(+), 13 deletions(-) diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index c79cd4f48..4b9c076d3 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -5912,9 +5912,9 @@ srs_utime_t SrsConfig::get_dash_fragment(string vhost) return (srs_utime_t)(::atof(conf->arg0().c_str()) * SRS_UTIME_SECONDS); } -int SrsConfig::get_dash_update_period(string vhost) +srs_utime_t SrsConfig::get_dash_update_period(string vhost) { - static int DEFAULT = 30 * 1000; + static srs_utime_t DEFAULT = 30 * SRS_UTIME_SECONDS; SrsConfDirective* conf = get_dash(vhost); if (!conf) { @@ -5926,7 +5926,7 @@ int SrsConfig::get_dash_update_period(string vhost) return DEFAULT; } - return (int)(1000 * ::atof(conf->arg0().c_str())); + return (srs_utime_t)(::atof(conf->arg0().c_str()) * SRS_UTIME_SECONDS); } int SrsConfig::get_dash_timeshift(string vhost) diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index 266fdf476..c78cbf0fa 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -1151,10 +1151,10 @@ private: public: // Whether DASH is enabled. virtual bool get_dash_enabled(std::string vhost); - // Get the duration of segment in milliseconds. + // Get the duration of segment in srs_utime_t. virtual srs_utime_t get_dash_fragment(std::string vhost); - // Get the period to update MPD in milliseconds. - virtual int get_dash_update_period(std::string vhost); + // Get the period to update MPD in srs_utime_t. + virtual srs_utime_t get_dash_update_period(std::string vhost); // Get the depth of timeshift buffer in milliseconds. virtual int get_dash_timeshift(std::string vhost); // Get the base/home dir/path for dash, into which write files. diff --git a/trunk/src/app/srs_app_dash.cpp b/trunk/src/app/srs_app_dash.cpp index 3956cb73b..67c7916f0 100644 --- a/trunk/src/app/srs_app_dash.cpp +++ b/trunk/src/app/srs_app_dash.cpp @@ -181,7 +181,7 @@ srs_error_t SrsMpdWriter::initialize(SrsRequest* r) string mpd_path = srs_path_build_stream(mpd_file, req->vhost, req->app, req->stream); fragment_home = srs_path_dirname(mpd_path) + "/" + req->stream; - srs_trace("DASH: Config fragment=%d, period=%d", fragment, update_period); + srs_trace("DASH: Config fragment=%" PRId64 ", period=%" PRId64, fragment, update_period); return srs_success; } @@ -190,7 +190,7 @@ srs_error_t SrsMpdWriter::write(SrsFormat* format) srs_error_t err = srs_success; // MPD is not expired? - if (last_update_mpd != -1 && srs_get_system_time_ms() - last_update_mpd < update_period) { + if (last_update_mpd != -1 && srs_get_system_time_ms() - last_update_mpd < update_period / SRS_UTIME_MILLISECONDS) { return err; } last_update_mpd = srs_get_system_time_ms(); @@ -210,7 +210,7 @@ srs_error_t SrsMpdWriter::write(SrsFormat* format) << "" << endl << " " << req->stream << "/" << "" << endl diff --git a/trunk/src/app/srs_app_dash.hpp b/trunk/src/app/srs_app_dash.hpp index 5073a683b..45a9a335d 100644 --- a/trunk/src/app/srs_app_dash.hpp +++ b/trunk/src/app/srs_app_dash.hpp @@ -86,10 +86,10 @@ private: SrsRequest* req; int64_t last_update_mpd; private: - // The duration of fragment in ms. + // The duration of fragment in srs_utime_t. srs_utime_t fragment; - // The period to update the mpd in ms. - int update_period; + // The period to update the mpd in srs_utime_t. + srs_utime_t update_period; // The timeshift buffer depth. int timeshit; // The base or home dir for dash to write files. diff --git a/trunk/src/utest/srs_utest_config.cpp b/trunk/src/utest/srs_utest_config.cpp index be3f47c9c..43d3fc2c4 100644 --- a/trunk/src/utest/srs_utest_config.cpp +++ b/trunk/src/utest/srs_utest_config.cpp @@ -1818,9 +1818,11 @@ VOID TEST(ConfigUnitTest, CheckDefaultValues) if (true) { EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF)); EXPECT_EQ(3 * SRS_UTIME_SECONDS, conf.get_dash_fragment("")); + EXPECT_EQ(30 * SRS_UTIME_SECONDS, conf.get_dash_update_period("")); - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{dash{dash_fragment 4;}}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{dash{dash_fragment 4;dash_update_period 40;}}")); EXPECT_EQ(4 * SRS_UTIME_SECONDS, conf.get_dash_fragment("v")); + EXPECT_EQ(40 * SRS_UTIME_SECONDS, conf.get_dash_update_period("v")); } }