mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Refine get_dash_fragment to time unit
This commit is contained in:
parent
bb6389143f
commit
4302ab7708
10 changed files with 99 additions and 21 deletions
|
@ -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)
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
#include <srs_app_reload.hpp>
|
||||
#include <srs_app_async_call.hpp>
|
||||
#include <srs_app_thread.hpp>
|
||||
#include <srs_service_st.hpp>
|
||||
#include <srs_service_time.hpp>
|
||||
|
||||
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.
|
||||
|
|
|
@ -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
|
||||
<< " <BaseURL>" << req->stream << "/" << "</BaseURL>" << endl
|
||||
<< " <Period start=\"PT0S\">" << endl;
|
||||
if (format->acodec) {
|
||||
ss << " <AdaptationSet mimeType=\"audio/mp4\" segmentAlignment=\"true\" startWithSAP=\"1\">" << endl;
|
||||
ss << " <SegmentTemplate duration=\"" << fragment / 1000 << "\" "
|
||||
ss << " <SegmentTemplate duration=\"" << fragment / SRS_UTIME_SECONDS << "\" "
|
||||
<< "initialization=\"$RepresentationID$-init.mp4\" "
|
||||
<< "media=\"$RepresentationID$-$Number$.m4s\" />" << endl;
|
||||
ss << " <Representation id=\"audio\" bandwidth=\"48000\" codecs=\"mp4a.40.2\" />" << endl;
|
||||
|
@ -227,7 +227,7 @@ srs_error_t SrsMpdWriter::write(SrsFormat* format)
|
|||
int w = format->vcodec->width;
|
||||
int h = format->vcodec->height;
|
||||
ss << " <AdaptationSet mimeType=\"video/mp4\" segmentAlignment=\"true\" startWithSAP=\"1\">" << endl;
|
||||
ss << " <SegmentTemplate duration=\"" << fragment / 1000 << "\" "
|
||||
ss << " <SegmentTemplate duration=\"" << fragment / SRS_UTIME_SECONDS << "\" "
|
||||
<< "initialization=\"$RepresentationID$-init.mp4\" "
|
||||
<< "media=\"$RepresentationID$-$Number$.m4s\" />" << endl;
|
||||
ss << " <Representation id=\"video\" bandwidth=\"800000\" codecs=\"avc1.64001e\" "
|
||||
|
@ -265,8 +265,8 @@ srs_error_t SrsMpdWriter::get_fragment(bool video, std::string& home, std::strin
|
|||
|
||||
home = fragment_home;
|
||||
|
||||
sn = srs_update_system_time_ms() / fragment;
|
||||
basetime = sn * fragment;
|
||||
sn = srs_update_system_time_ms() * SRS_UTIME_MILLISECONDS / fragment;
|
||||
basetime = sn * fragment / SRS_UTIME_MILLISECONDS;
|
||||
|
||||
if (video) {
|
||||
file_name = "video-" + srs_int2str(sn) + ".m4s";
|
||||
|
@ -335,7 +335,7 @@ srs_error_t SrsDashController::on_audio(SrsSharedPtrMessage* shared_audio, SrsFo
|
|||
return refresh_init_mp4(shared_audio, format);
|
||||
}
|
||||
|
||||
if (acurrent->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");
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include <srs_app_fragment.hpp>
|
||||
#include <srs_service_time.hpp>
|
||||
|
||||
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;
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue