diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index 4b9c076d3..86d1d2dc0 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -5929,9 +5929,9 @@ srs_utime_t SrsConfig::get_dash_update_period(string vhost) return (srs_utime_t)(::atof(conf->arg0().c_str()) * SRS_UTIME_SECONDS); } -int SrsConfig::get_dash_timeshift(string vhost) +srs_utime_t SrsConfig::get_dash_timeshift(string vhost) { - static int DEFAULT = 60 * 1000; + static srs_utime_t DEFAULT = 60 * SRS_UTIME_SECONDS; SrsConfDirective* conf = get_dash(vhost); if (!conf) { @@ -5943,7 +5943,7 @@ int SrsConfig::get_dash_timeshift(string vhost) return DEFAULT; } - return (int)(1000 * ::atof(conf->arg0().c_str())); + return (srs_utime_t)(::atof(conf->arg0().c_str()) * SRS_UTIME_SECONDS); } string SrsConfig::get_dash_path(string vhost) diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index c78cbf0fa..b7c2e0ab5 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -1155,8 +1155,8 @@ public: virtual srs_utime_t get_dash_fragment(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 depth of timeshift buffer in srs_utime_t. + virtual srs_utime_t get_dash_timeshift(std::string vhost); // Get the base/home dir/path for dash, into which write files. virtual std::string get_dash_path(std::string vhost); // Get the path for DASH MPD, to generate the MPD file. diff --git a/trunk/src/app/srs_app_dash.cpp b/trunk/src/app/srs_app_dash.cpp index 67c7916f0..81501bbbe 100644 --- a/trunk/src/app/srs_app_dash.cpp +++ b/trunk/src/app/srs_app_dash.cpp @@ -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 / SRS_UTIME_MILLISECONDS) { + if (last_update_mpd != -1 && srs_get_system_time_ms() - last_update_mpd < int64_t(update_period / SRS_UTIME_MILLISECONDS)) { return err; } last_update_mpd = srs_get_system_time_ms(); @@ -211,7 +211,7 @@ srs_error_t SrsMpdWriter::write(SrsFormat* format) << " ns1:schemaLocation=\"urn:mpeg:dash:schema:mpd:2011 DASH-MPD.xsd\" " << endl << " xmlns=\"urn:mpeg:dash:schema:mpd:2011\" xmlns:ns1=\"http://www.w3.org/2001/XMLSchema-instance\" " << endl << " type=\"dynamic\" minimumUpdatePeriod=\"PT" << update_period / SRS_UTIME_SECONDS << "S\" " << endl - << " timeShiftBufferDepth=\"PT" << timeshit / 1000 << "S\" availabilityStartTime=\"1970-01-01T00:00:00Z\" " << endl + << " timeShiftBufferDepth=\"PT" << timeshit / SRS_UTIME_SECONDS << "S\" availabilityStartTime=\"1970-01-01T00:00:00Z\" " << endl << " maxSegmentDuration=\"PT" << fragment / SRS_UTIME_SECONDS << "S\" minBufferTime=\"PT" << fragment / SRS_UTIME_SECONDS << "S\" >" << endl << " " << req->stream << "/" << "" << endl << " " << endl; @@ -335,7 +335,7 @@ srs_error_t SrsDashController::on_audio(SrsSharedPtrMessage* shared_audio, SrsFo return refresh_init_mp4(shared_audio, format); } - if (acurrent->duration() >= fragment / SRS_UTIME_MILLISECONDS) { + if (acurrent->duration() >= int64_t(fragment / SRS_UTIME_MILLISECONDS)) { if ((err = acurrent->reap(audio_dts)) != srs_success) { return srs_error_wrap(err, "reap current"); } @@ -367,7 +367,7 @@ srs_error_t SrsDashController::on_video(SrsSharedPtrMessage* shared_video, SrsFo return refresh_init_mp4(shared_video, format); } - bool reopen = format->video->frame_type == SrsVideoAvcFrameTypeKeyFrame && vcurrent->duration() >= fragment / SRS_UTIME_MILLISECONDS; + bool reopen = format->video->frame_type == SrsVideoAvcFrameTypeKeyFrame && vcurrent->duration() >= int64_t(fragment / SRS_UTIME_MILLISECONDS); if (reopen) { if ((err = vcurrent->reap(video_dts)) != srs_success) { return srs_error_wrap(err, "reap current"); diff --git a/trunk/src/app/srs_app_dash.hpp b/trunk/src/app/srs_app_dash.hpp index 45a9a335d..743875375 100644 --- a/trunk/src/app/srs_app_dash.hpp +++ b/trunk/src/app/srs_app_dash.hpp @@ -90,8 +90,8 @@ private: srs_utime_t fragment; // The period to update the mpd in srs_utime_t. srs_utime_t update_period; - // The timeshift buffer depth. - int timeshit; + // The timeshift buffer depth in srs_utime_t. + srs_utime_t timeshit; // The base or home dir for dash to write files. std::string home; // The MPD path template, from which to build the file path. diff --git a/trunk/src/utest/srs_utest_config.cpp b/trunk/src/utest/srs_utest_config.cpp index 43d3fc2c4..07d0c733b 100644 --- a/trunk/src/utest/srs_utest_config.cpp +++ b/trunk/src/utest/srs_utest_config.cpp @@ -1819,10 +1819,12 @@ VOID TEST(ConfigUnitTest, CheckDefaultValues) 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_EQ(60 * SRS_UTIME_SECONDS, conf.get_dash_timeshift("")); - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{dash{dash_fragment 4;dash_update_period 40;}}")); + EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{dash{dash_fragment 4;dash_update_period 40;dash_timeshift 70;}}")); EXPECT_EQ(4 * SRS_UTIME_SECONDS, conf.get_dash_fragment("v")); EXPECT_EQ(40 * SRS_UTIME_SECONDS, conf.get_dash_update_period("v")); + EXPECT_EQ(70 * SRS_UTIME_SECONDS, conf.get_dash_timeshift("v")); } }