mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 03:41:55 +00:00
Refine get_hls_window in time unit
This commit is contained in:
parent
ca705a6f62
commit
917f6d066d
7 changed files with 18 additions and 16 deletions
|
@ -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)
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
/**
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue