Refine get_hds_fragment and get_hds_window in time unit

pull/1651/head
winlin 6 years ago
parent 917f6d066d
commit 010e35bec2

@ -6413,9 +6413,9 @@ string SrsConfig::get_hds_path(const string &vhost)
return conf->arg0(); return conf->arg0();
} }
double SrsConfig::get_hds_fragment(const string &vhost) srs_utime_t SrsConfig::get_hds_fragment(const string &vhost)
{ {
static double DEFAULT = 10; static srs_utime_t DEFAULT = (10 * SRS_UTIME_SECONDS);
SrsConfDirective* conf = get_hds(vhost); SrsConfDirective* conf = get_hds(vhost);
if (!conf) { if (!conf) {
@ -6427,12 +6427,12 @@ double SrsConfig::get_hds_fragment(const string &vhost)
return DEFAULT; return DEFAULT;
} }
return ::atof(conf->arg0().c_str()); return srs_utime_t(::atof(conf->arg0().c_str()) * SRS_UTIME_SECONDS);
} }
double SrsConfig::get_hds_window(const string &vhost) srs_utime_t SrsConfig::get_hds_window(const string &vhost)
{ {
static double DEFAULT = 60; static srs_utime_t DEFAULT = (60 * SRS_UTIME_SECONDS);
SrsConfDirective* conf = get_hds(vhost); SrsConfDirective* conf = get_hds(vhost);
if (!conf) { if (!conf) {
@ -6444,7 +6444,7 @@ double SrsConfig::get_hds_window(const string &vhost)
return DEFAULT; return DEFAULT;
} }
return ::atof(conf->arg0().c_str()); return srs_utime_t(::atof(conf->arg0().c_str()) * SRS_UTIME_SECONDS);
} }
SrsConfDirective* SrsConfig::get_dvr(string vhost) SrsConfDirective* SrsConfig::get_dvr(string vhost)

@ -1277,15 +1277,14 @@ public:
*/ */
virtual std::string get_hds_path(const std::string &vhost); virtual std::string get_hds_path(const std::string &vhost);
/** /**
* get the hds fragment time, in seconds. * get the hds fragment time, in srs_utime_t.
*/ */
// TODO: FIXME: Refine to time unit. virtual srs_utime_t get_hds_fragment(const std::string &vhost);
virtual double get_hds_fragment(const std::string &vhost);
/** /**
* get the hds window time, in seconds. * get the hds window time, in srs_utime_t.
* a window is a set of hds fragments. * a window is a set of hds fragments.
*/ */
virtual double get_hds_window(const std::string &vhost); virtual srs_utime_t get_hds_window(const std::string &vhost);
// dvr section // dvr section
private: private:
/** /**

@ -348,7 +348,7 @@ srs_error_t SrsHds::on_video(SrsSharedPtrMessage* msg)
currentSegment->on_video(msg); currentSegment->on_video(msg);
double fragment_duration = _srs_config->get_hds_fragment(hds_req->vhost) * 1000; double fragment_duration = srsu2ms(_srs_config->get_hds_fragment(hds_req->vhost));
if (currentSegment->duration() >= fragment_duration) { if (currentSegment->duration() >= fragment_duration) {
// flush segment // flush segment
if ((err = currentSegment->flush()) != srs_success) { if ((err = currentSegment->flush()) != srs_success) {
@ -398,7 +398,7 @@ srs_error_t SrsHds::on_audio(SrsSharedPtrMessage* msg)
currentSegment->on_audio(msg); currentSegment->on_audio(msg);
double fragment_duration = _srs_config->get_hds_fragment(hds_req->vhost) * 1000; double fragment_duration = srsu2ms(_srs_config->get_hds_fragment(hds_req->vhost));
if (currentSegment->duration() >= fragment_duration) { if (currentSegment->duration() >= fragment_duration) {
// flush segment // flush segment
if ((err = currentSegment->flush()) != srs_success) { if ((err = currentSegment->flush()) != srs_success) {
@ -718,7 +718,7 @@ void SrsHds::adjust_windows()
windows_size += fragment->duration(); windows_size += fragment->duration();
} }
double windows_size_limit = _srs_config->get_hds_window(hds_req->vhost) * 1000; double windows_size_limit = srsu2ms(_srs_config->get_hds_window(hds_req->vhost));
if (windows_size > windows_size_limit ) { if (windows_size > windows_size_limit ) {
SrsHdsFragment *fragment = fragments.front(); SrsHdsFragment *fragment = fragments.front();
unlink(fragment->fragment_path().c_str()); unlink(fragment->fragment_path().c_str());

@ -1879,6 +1879,16 @@ VOID TEST(ConfigUnitTest, CheckDefaultValuesVhost)
EXPECT_EQ(30 * SRS_UTIME_SECONDS, conf.get_hls_window("v")); EXPECT_EQ(30 * SRS_UTIME_SECONDS, conf.get_hls_window("v"));
} }
if (true) {
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF));
EXPECT_EQ(10 * SRS_UTIME_SECONDS, conf.get_hds_fragment(""));
EXPECT_EQ(60 * SRS_UTIME_SECONDS, conf.get_hds_window(""));
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{hds{hds_fragment 20;hds_window 30;}}"));
EXPECT_EQ(20 * SRS_UTIME_SECONDS, conf.get_hds_fragment("v"));
EXPECT_EQ(30 * SRS_UTIME_SECONDS, conf.get_hds_window("v"));
}
if (true) { if (true) {
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF)); EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF));
EXPECT_EQ(30 * SRS_UTIME_SECONDS, conf.get_queue_length("")); EXPECT_EQ(30 * SRS_UTIME_SECONDS, conf.get_queue_length(""));

Loading…
Cancel
Save