diff --git a/trunk/configure b/trunk/configure index a072789b6..8a963b9bf 100755 --- a/trunk/configure +++ b/trunk/configure @@ -203,7 +203,7 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then MODULE_ID="SERVICE" MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL") ModuleLibIncs=(${LibSTRoot} ${SRS_OBJS_DIR} ${LibSSLRoot}) - MODULE_FILES=("srs_service_log" "srs_service_st" "srs_service_http_client" + MODULE_FILES=("srs_service_log" "srs_service_time" "srs_service_st" "srs_service_http_client" "srs_service_http_conn" "srs_service_rtmp_conn" "srs_service_utility" "srs_service_conn") DEFINES="" diff --git a/trunk/src/app/srs_app_config.cpp b/trunk/src/app/srs_app_config.cpp index b1ba652bf..c79cd4f48 100644 --- a/trunk/src/app/srs_app_config.cpp +++ b/trunk/src/app/srs_app_config.cpp @@ -5895,9 +5895,9 @@ bool SrsConfig::get_dash_enabled(string vhost) return SRS_CONF_PERFER_FALSE(conf->arg0()); } -int SrsConfig::get_dash_fragment(string vhost) +srs_utime_t SrsConfig::get_dash_fragment(string vhost) { - static int DEFAULT = 3 * 1000; + static int DEFAULT = 3 * SRS_UTIME_SECONDS; SrsConfDirective* conf = get_dash(vhost); if (!conf) { @@ -5909,7 +5909,7 @@ int SrsConfig::get_dash_fragment(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_update_period(string vhost) diff --git a/trunk/src/app/srs_app_config.hpp b/trunk/src/app/srs_app_config.hpp index 8fa591ace..266fdf476 100644 --- a/trunk/src/app/srs_app_config.hpp +++ b/trunk/src/app/srs_app_config.hpp @@ -34,7 +34,7 @@ #include #include #include -#include +#include class SrsRequest; class SrsFileWriter; @@ -1152,7 +1152,7 @@ public: // Whether DASH is enabled. virtual bool get_dash_enabled(std::string vhost); // Get the duration of segment in milliseconds. - virtual int get_dash_fragment(std::string vhost); + 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 depth of timeshift buffer in milliseconds. diff --git a/trunk/src/app/srs_app_dash.cpp b/trunk/src/app/srs_app_dash.cpp index 7061cfb99..3956cb73b 100644 --- a/trunk/src/app/srs_app_dash.cpp +++ b/trunk/src/app/srs_app_dash.cpp @@ -212,12 +212,12 @@ srs_error_t SrsMpdWriter::write(SrsFormat* format) << " xmlns=\"urn:mpeg:dash:schema:mpd:2011\" xmlns:ns1=\"http://www.w3.org/2001/XMLSchema-instance\" " << endl << " type=\"dynamic\" minimumUpdatePeriod=\"PT" << update_period / 1000 << "S\" " << endl << " timeShiftBufferDepth=\"PT" << timeshit / 1000 << "S\" availabilityStartTime=\"1970-01-01T00:00:00Z\" " << endl - << " maxSegmentDuration=\"PT" << fragment / 1000 << "S\" minBufferTime=\"PT" << fragment / 1000 << "S\" >" << endl + << " maxSegmentDuration=\"PT" << fragment / SRS_UTIME_SECONDS << "S\" minBufferTime=\"PT" << fragment / SRS_UTIME_SECONDS << "S\" >" << endl << " " << req->stream << "/" << "" << endl << " " << endl; if (format->acodec) { ss << " " << endl; - ss << " " << endl; ss << " " << endl; @@ -227,7 +227,7 @@ srs_error_t SrsMpdWriter::write(SrsFormat* format) int w = format->vcodec->width; int h = format->vcodec->height; ss << " " << endl; - ss << " " << endl; ss << " duration() >= fragment) { + if (acurrent->duration() >= 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; + bool reopen = format->video->frame_type == SrsVideoAvcFrameTypeKeyFrame && vcurrent->duration() >= 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 ea675ffca..5073a683b 100644 --- a/trunk/src/app/srs_app_dash.hpp +++ b/trunk/src/app/srs_app_dash.hpp @@ -30,6 +30,7 @@ #include #include +#include class SrsRequest; class SrsOriginHub; @@ -86,7 +87,7 @@ private: int64_t last_update_mpd; private: // The duration of fragment in ms. - int fragment; + srs_utime_t fragment; // The period to update the mpd in ms. int update_period; // The timeshift buffer depth. @@ -128,7 +129,7 @@ private: uint64_t video_dts; private: // The fragment duration in ms to reap it. - int fragment; + srs_utime_t fragment; private: std::string home; int video_tack_id; diff --git a/trunk/src/app/srs_app_fragment.hpp b/trunk/src/app/srs_app_fragment.hpp index 2bd5843aa..2495e9fc1 100644 --- a/trunk/src/app/srs_app_fragment.hpp +++ b/trunk/src/app/srs_app_fragment.hpp @@ -52,6 +52,7 @@ public: // @dts The dts of frame in ms. virtual void append(int64_t dts); // Get the duration of fragment in ms. + // TODO: FIXME: Refine to time unit. virtual int64_t duration(); // Whether the fragment contains any sequence header. virtual bool is_sequence_header(); diff --git a/trunk/src/service/srs_service_st.hpp b/trunk/src/service/srs_service_st.hpp index 4a6998517..c1f2bfcc7 100644 --- a/trunk/src/service/srs_service_st.hpp +++ b/trunk/src/service/srs_service_st.hpp @@ -29,6 +29,7 @@ #include #include +#include // Wrap for coroutine. typedef void* srs_netfd_t; diff --git a/trunk/src/service/srs_service_time.cpp b/trunk/src/service/srs_service_time.cpp new file mode 100644 index 000000000..4cbaa8ead --- /dev/null +++ b/trunk/src/service/srs_service_time.cpp @@ -0,0 +1,25 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2013-2019 Winlin + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include + diff --git a/trunk/src/service/srs_service_time.hpp b/trunk/src/service/srs_service_time.hpp new file mode 100644 index 000000000..481fbc44b --- /dev/null +++ b/trunk/src/service/srs_service_time.hpp @@ -0,0 +1,48 @@ +/** + * The MIT License (MIT) + * + * Copyright (c) 2013-2019 Winlin + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of + * this software and associated documentation files (the "Software"), to deal in + * the Software without restriction, including without limitation the rights to + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + * the Software, and to permit persons to whom the Software is furnished to do so, + * subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef SRS_SERVICE_TIME_HPP +#define SRS_SERVICE_TIME_HPP + +#include + +// Wrap for coroutine. +typedef uint64_t srs_utime_t; + +// The time unit in ms, for example 100 * SRS_UTIME_MILLISECONDS means 100ms. +#define SRS_UTIME_MILLISECONDS 1000 + +// The time unit in ms, for example 120 * SRS_UTIME_SECONDS means 120s. +#define SRS_UTIME_SECONDS 1000000 + +// The time unit in minutes, for example 3 * SRS_UTIME_MINUTES means 3m. +#define SRS_UTIME_MINUTES 60000000LL + +// The time unit in hours, for example 2 * SRS_UTIME_HOURS means 2h. +#define SRS_UTIME_HOURS 3600000000LL + +// Never timeout. +#define SRS_UTIME_NO_TIMEOUT ((srs_utime_t) -1LL) + +#endif + diff --git a/trunk/src/utest/srs_utest_config.cpp b/trunk/src/utest/srs_utest_config.cpp index 7e44c238d..be3f47c9c 100644 --- a/trunk/src/utest/srs_utest_config.cpp +++ b/trunk/src/utest/srs_utest_config.cpp @@ -1811,14 +1811,16 @@ VOID TEST(ConfigUnitTest, CheckDefaultValues) EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF)); EXPECT_EQ(30 * SRS_UTIME_SECONDS, conf.get_bw_check_interval("")); - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{}")); - EXPECT_EQ(30 * SRS_UTIME_SECONDS, conf.get_bw_check_interval("v")); + EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{bandcheck{interval 4;}}")); + EXPECT_EQ(4 * SRS_UTIME_SECONDS, conf.get_bw_check_interval("v")); + } - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{bandcheck{}}")); - EXPECT_EQ(30 * SRS_UTIME_SECONDS, conf.get_bw_check_interval("v")); + if (true) { + EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF)); + EXPECT_EQ(3 * SRS_UTIME_SECONDS, conf.get_dash_fragment("")); - EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{bandcheck{interval 1.1;}}")); - EXPECT_EQ(srs_utime_t(1.1 * SRS_UTIME_SECONDS), conf.get_bw_check_interval("v")); + EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{dash{dash_fragment 4;}}")); + EXPECT_EQ(4 * SRS_UTIME_SECONDS, conf.get_dash_fragment("v")); } }