mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Refine get_dash_timeshift in time unit
This commit is contained in:
parent
12cf17ef6b
commit
5937304717
5 changed files with 14 additions and 12 deletions
|
@ -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);
|
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);
|
SrsConfDirective* conf = get_dash(vhost);
|
||||||
if (!conf) {
|
if (!conf) {
|
||||||
|
@ -5943,7 +5943,7 @@ int SrsConfig::get_dash_timeshift(string vhost)
|
||||||
return DEFAULT;
|
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)
|
string SrsConfig::get_dash_path(string vhost)
|
||||||
|
|
|
@ -1155,8 +1155,8 @@ public:
|
||||||
virtual srs_utime_t get_dash_fragment(std::string vhost);
|
virtual srs_utime_t get_dash_fragment(std::string vhost);
|
||||||
// Get the period to update MPD in srs_utime_t.
|
// Get the period to update MPD in srs_utime_t.
|
||||||
virtual srs_utime_t get_dash_update_period(std::string vhost);
|
virtual srs_utime_t get_dash_update_period(std::string vhost);
|
||||||
// Get the depth of timeshift buffer in milliseconds.
|
// Get the depth of timeshift buffer in srs_utime_t.
|
||||||
virtual int get_dash_timeshift(std::string vhost);
|
virtual srs_utime_t get_dash_timeshift(std::string vhost);
|
||||||
// Get the base/home dir/path for dash, into which write files.
|
// Get the base/home dir/path for dash, into which write files.
|
||||||
virtual std::string get_dash_path(std::string vhost);
|
virtual std::string get_dash_path(std::string vhost);
|
||||||
// Get the path for DASH MPD, to generate the MPD file.
|
// Get the path for DASH MPD, to generate the MPD file.
|
||||||
|
|
|
@ -190,7 +190,7 @@ srs_error_t SrsMpdWriter::write(SrsFormat* format)
|
||||||
srs_error_t err = srs_success;
|
srs_error_t err = srs_success;
|
||||||
|
|
||||||
// MPD is not expired?
|
// 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;
|
return err;
|
||||||
}
|
}
|
||||||
last_update_mpd = srs_get_system_time_ms();
|
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
|
<< " 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
|
<< " 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
|
<< " 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
|
<< " maxSegmentDuration=\"PT" << fragment / SRS_UTIME_SECONDS << "S\" minBufferTime=\"PT" << fragment / SRS_UTIME_SECONDS << "S\" >" << endl
|
||||||
<< " <BaseURL>" << req->stream << "/" << "</BaseURL>" << endl
|
<< " <BaseURL>" << req->stream << "/" << "</BaseURL>" << endl
|
||||||
<< " <Period start=\"PT0S\">" << endl;
|
<< " <Period start=\"PT0S\">" << endl;
|
||||||
|
@ -335,7 +335,7 @@ srs_error_t SrsDashController::on_audio(SrsSharedPtrMessage* shared_audio, SrsFo
|
||||||
return refresh_init_mp4(shared_audio, format);
|
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) {
|
if ((err = acurrent->reap(audio_dts)) != srs_success) {
|
||||||
return srs_error_wrap(err, "reap current");
|
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);
|
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 (reopen) {
|
||||||
if ((err = vcurrent->reap(video_dts)) != srs_success) {
|
if ((err = vcurrent->reap(video_dts)) != srs_success) {
|
||||||
return srs_error_wrap(err, "reap current");
|
return srs_error_wrap(err, "reap current");
|
||||||
|
|
|
@ -90,8 +90,8 @@ private:
|
||||||
srs_utime_t fragment;
|
srs_utime_t fragment;
|
||||||
// The period to update the mpd in srs_utime_t.
|
// The period to update the mpd in srs_utime_t.
|
||||||
srs_utime_t update_period;
|
srs_utime_t update_period;
|
||||||
// The timeshift buffer depth.
|
// The timeshift buffer depth in srs_utime_t.
|
||||||
int timeshit;
|
srs_utime_t timeshit;
|
||||||
// The base or home dir for dash to write files.
|
// The base or home dir for dash to write files.
|
||||||
std::string home;
|
std::string home;
|
||||||
// The MPD path template, from which to build the file path.
|
// The MPD path template, from which to build the file path.
|
||||||
|
|
|
@ -1819,10 +1819,12 @@ VOID TEST(ConfigUnitTest, CheckDefaultValues)
|
||||||
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF));
|
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF));
|
||||||
EXPECT_EQ(3 * SRS_UTIME_SECONDS, conf.get_dash_fragment(""));
|
EXPECT_EQ(3 * SRS_UTIME_SECONDS, conf.get_dash_fragment(""));
|
||||||
EXPECT_EQ(30 * SRS_UTIME_SECONDS, conf.get_dash_update_period(""));
|
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(4 * SRS_UTIME_SECONDS, conf.get_dash_fragment("v"));
|
||||||
EXPECT_EQ(40 * SRS_UTIME_SECONDS, conf.get_dash_update_period("v"));
|
EXPECT_EQ(40 * SRS_UTIME_SECONDS, conf.get_dash_update_period("v"));
|
||||||
|
EXPECT_EQ(70 * SRS_UTIME_SECONDS, conf.get_dash_timeshift("v"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue