mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Refine get_hls_fragment in time unit
This commit is contained in:
parent
402e614471
commit
ca705a6f62
6 changed files with 20 additions and 20 deletions
|
@ -6093,9 +6093,9 @@ bool SrsConfig::get_hls_ts_floor(string vhost)
|
||||||
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
||||||
}
|
}
|
||||||
|
|
||||||
double SrsConfig::get_hls_fragment(string vhost)
|
srs_utime_t SrsConfig::get_hls_fragment(string vhost)
|
||||||
{
|
{
|
||||||
static double DEFAULT = 10;
|
static srs_utime_t DEFAULT = 10 * SRS_UTIME_SECONDS;
|
||||||
|
|
||||||
SrsConfDirective* conf = get_hls(vhost);
|
SrsConfDirective* conf = get_hls(vhost);
|
||||||
if (!conf) {
|
if (!conf) {
|
||||||
|
@ -6107,7 +6107,7 @@ double SrsConfig::get_hls_fragment(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_hls_td_ratio(string vhost)
|
double SrsConfig::get_hls_td_ratio(string vhost)
|
||||||
|
|
|
@ -1192,9 +1192,9 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual bool get_hls_ts_floor(std::string vhost);
|
virtual bool get_hls_ts_floor(std::string vhost);
|
||||||
/**
|
/**
|
||||||
* get the hls fragment time, in seconds.
|
* get the hls fragment time, in srs_utime_t.
|
||||||
*/
|
*/
|
||||||
virtual double get_hls_fragment(std::string vhost);
|
virtual srs_utime_t get_hls_fragment(std::string vhost);
|
||||||
/**
|
/**
|
||||||
* get the hls td(target duration) ratio.
|
* get the hls td(target duration) ratio.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -279,7 +279,7 @@ srs_error_t SrsHlsMuxer::initialize()
|
||||||
}
|
}
|
||||||
|
|
||||||
srs_error_t SrsHlsMuxer::update_config(SrsRequest* r, string entry_prefix,
|
srs_error_t SrsHlsMuxer::update_config(SrsRequest* r, string entry_prefix,
|
||||||
string path, string m3u8_file, string ts_file, double fragment, double window,
|
string path, string m3u8_file, string ts_file, srs_utime_t fragment, double window,
|
||||||
bool ts_floor, double aof_ratio, bool cleanup, bool wait_keyframe, bool keys,
|
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)
|
int fragments_per_key, string key_file ,string key_file_path, string key_url)
|
||||||
{
|
{
|
||||||
|
@ -391,7 +391,7 @@ srs_error_t SrsHlsMuxer::segment_open()
|
||||||
ts_file = srs_path_build_stream(ts_file, req->vhost, req->app, req->stream);
|
ts_file = srs_path_build_stream(ts_file, req->vhost, req->app, req->stream);
|
||||||
if (hls_ts_floor) {
|
if (hls_ts_floor) {
|
||||||
// accept the floor ts for the first piece.
|
// accept the floor ts for the first piece.
|
||||||
int64_t current_floor_ts = (int64_t)(srsu2ms(srs_update_system_time()) / (1000 * hls_fragment));
|
int64_t current_floor_ts = srs_update_system_time() / hls_fragment;
|
||||||
if (!accept_floor_ts) {
|
if (!accept_floor_ts) {
|
||||||
accept_floor_ts = current_floor_ts - 1;
|
accept_floor_ts = current_floor_ts - 1;
|
||||||
} else {
|
} else {
|
||||||
|
@ -489,9 +489,8 @@ bool SrsHlsMuxer::is_segment_overflow()
|
||||||
}
|
}
|
||||||
|
|
||||||
// use N% deviation, to smoother.
|
// use N% deviation, to smoother.
|
||||||
double deviation = hls_ts_floor? SRS_HLS_FLOOR_REAP_PERCENT * deviation_ts * hls_fragment : 0.0;
|
srs_utime_t deviation = hls_ts_floor? SRS_HLS_FLOOR_REAP_PERCENT * deviation_ts * hls_fragment : 0;
|
||||||
|
return current->duration() >= hls_fragment + deviation;
|
||||||
return srsu2msi(current->duration()) >= (hls_fragment + deviation) * 1000;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SrsHlsMuxer::wait_keyframe()
|
bool SrsHlsMuxer::wait_keyframe()
|
||||||
|
@ -510,9 +509,8 @@ bool SrsHlsMuxer::is_segment_absolutely_overflow()
|
||||||
}
|
}
|
||||||
|
|
||||||
// use N% deviation, to smoother.
|
// use N% deviation, to smoother.
|
||||||
double deviation = hls_ts_floor? SRS_HLS_FLOOR_REAP_PERCENT * deviation_ts * hls_fragment : 0.0;
|
srs_utime_t deviation = hls_ts_floor? SRS_HLS_FLOOR_REAP_PERCENT * deviation_ts * hls_fragment : 0;
|
||||||
|
return current->duration() >= hls_aof_ratio * hls_fragment + deviation;
|
||||||
return srsu2msi(current->duration()) >= (hls_aof_ratio * hls_fragment + deviation) * 1000;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SrsHlsMuxer::pure_audio()
|
bool SrsHlsMuxer::pure_audio()
|
||||||
|
@ -856,7 +854,7 @@ srs_error_t SrsHlsController::on_publish(SrsRequest* req)
|
||||||
std::string stream = req->stream;
|
std::string stream = req->stream;
|
||||||
std::string app = req->app;
|
std::string app = req->app;
|
||||||
|
|
||||||
double hls_fragment = _srs_config->get_hls_fragment(vhost);
|
srs_utime_t hls_fragment = _srs_config->get_hls_fragment(vhost);
|
||||||
double hls_window = _srs_config->get_hls_window(vhost);
|
double hls_window = _srs_config->get_hls_window(vhost);
|
||||||
|
|
||||||
// get the hls m3u8 ts list entry prefix config
|
// get the hls m3u8 ts list entry prefix config
|
||||||
|
@ -893,8 +891,8 @@ srs_error_t SrsHlsController::on_publish(SrsRequest* req)
|
||||||
if ((err = muxer->segment_open()) != srs_success) {
|
if ((err = muxer->segment_open()) != srs_success) {
|
||||||
return srs_error_wrap(err, "hls: segment open");
|
return srs_error_wrap(err, "hls: segment open");
|
||||||
}
|
}
|
||||||
srs_trace("hls: win=%.2f, frag=%.2f, prefix=%s, path=%s, m3u8=%s, ts=%s, aof=%.2f, floor=%d, clean=%d, waitk=%d, dispose=%dms",
|
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, hls_fragment, entry_prefix.c_str(), path.c_str(), m3u8_file.c_str(),
|
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));
|
ts_file.c_str(), hls_aof_ratio, ts_floor, cleanup, wait_keyframe, srsu2msi(hls_dispose));
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
|
|
|
@ -139,7 +139,7 @@ private:
|
||||||
std::string m3u8_dir;
|
std::string m3u8_dir;
|
||||||
double hls_aof_ratio;
|
double hls_aof_ratio;
|
||||||
// TODO: FIXME: Use TBN 1000.
|
// TODO: FIXME: Use TBN 1000.
|
||||||
double hls_fragment;
|
srs_utime_t hls_fragment;
|
||||||
double hls_window;
|
double hls_window;
|
||||||
SrsAsyncCallWorker* async;
|
SrsAsyncCallWorker* async;
|
||||||
private:
|
private:
|
||||||
|
@ -201,7 +201,7 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual srs_error_t update_config(SrsRequest* r, std::string entry_prefix,
|
virtual srs_error_t update_config(SrsRequest* r, std::string entry_prefix,
|
||||||
std::string path, std::string m3u8_file, std::string ts_file,
|
std::string path, std::string m3u8_file, std::string ts_file,
|
||||||
double fragment, double window, bool ts_floor, double aof_ratio,
|
srs_utime_t fragment, double window, bool ts_floor, double aof_ratio,
|
||||||
bool cleanup, bool wait_keyframe, bool keys, int fragments_per_key,
|
bool cleanup, bool wait_keyframe, bool keys, int fragments_per_key,
|
||||||
std::string key_file, std::string key_file_path, std::string key_url);
|
std::string key_file, std::string key_file_path, std::string key_url);
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -90,7 +90,7 @@ srs_error_t SrsStatisticVhost::dumps(SrsJsonObject* obj)
|
||||||
|
|
||||||
hls->set("enabled", SrsJsonAny::boolean(hls_enabled));
|
hls->set("enabled", SrsJsonAny::boolean(hls_enabled));
|
||||||
if (hls_enabled) {
|
if (hls_enabled) {
|
||||||
hls->set("fragment", SrsJsonAny::number(_srs_config->get_hls_fragment(vhost)));
|
hls->set("fragment", SrsJsonAny::number(srsu2msi(_srs_config->get_hls_fragment(vhost))/1000.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
|
|
|
@ -1870,9 +1870,11 @@ VOID TEST(ConfigUnitTest, CheckDefaultValuesVhost)
|
||||||
if (true) {
|
if (true) {
|
||||||
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF));
|
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF));
|
||||||
EXPECT_EQ(0, conf.get_hls_dispose(""));
|
EXPECT_EQ(0, conf.get_hls_dispose(""));
|
||||||
|
EXPECT_EQ(10 * SRS_UTIME_SECONDS, conf.get_hls_fragment(""));
|
||||||
|
|
||||||
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{hls{hls_dispose 10;}}"));
|
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{hls{hls_dispose 10;hls_fragment 20;}}"));
|
||||||
EXPECT_EQ(10 * SRS_UTIME_SECONDS, conf.get_hls_dispose("v"));
|
EXPECT_EQ(10 * SRS_UTIME_SECONDS, conf.get_hls_dispose("v"));
|
||||||
|
EXPECT_EQ(20 * SRS_UTIME_SECONDS, conf.get_hls_fragment("v"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (true) {
|
if (true) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue