1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

DASH: Fix number mode bug to make it run. v5.0.96 (#3240)

* Add utc time utility
* Fix calculate duration in fmp4
* Refine dash code, use segment template timeline
* Shrink m4s file and cleanup
* Support play by dash.js
* Use SegmentTemplate timeline mode with $Number$

Co-authored-by: winlin <winlin@vip.126.com>
This commit is contained in:
john 2022-11-24 18:09:50 +08:00 committed by GitHub
parent af192d6184
commit 271afbbf82
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 506 additions and 105 deletions

View file

@ -48,7 +48,7 @@ public:
virtual ~SrsFragmentedMp4();
public:
// Initialize the fragment, create the home dir, open the file.
virtual srs_error_t initialize(SrsRequest* r, bool video, SrsMpdWriter* mpd, uint32_t tid);
virtual srs_error_t initialize(SrsRequest* r, bool video, int64_t time, SrsMpdWriter* mpd, uint32_t tid);
// Write media message to fragment.
virtual srs_error_t write(SrsSharedPtrMessage* shared_msg, SrsFormat* format);
// Reap the fragment, close the fd and rename tmp to official file.
@ -60,7 +60,6 @@ class SrsMpdWriter
{
private:
SrsRequest* req;
srs_utime_t last_update_mpd;
private:
// The duration of fragment in srs_utime_t.
srs_utime_t fragment;
@ -72,22 +71,35 @@ private:
std::string home;
// The MPD path template, from which to build the file path.
std::string mpd_file;
// The number of fragments in MPD file.
int window_size_;
// The availabilityStartTime in MPD file.
srs_utime_t availability_start_time_;
// The number of current video segment.
uint64_t video_number_;
// The number of current audio segment.
uint64_t audio_number_;
private:
// The home for fragment, relative to home.
std::string fragment_home;
public:
SrsMpdWriter();
virtual ~SrsMpdWriter();
public:
virtual void dispose();
public:
virtual srs_error_t initialize(SrsRequest* r);
virtual srs_error_t on_publish();
virtual void on_unpublish();
// Write MPD according to parsed format of stream.
virtual srs_error_t write(SrsFormat* format);
virtual srs_error_t write(SrsFormat* format, SrsFragmentWindow* afragments, SrsFragmentWindow* vfragments);
public:
// Get the fragment relative home and filename.
// The basetime is the absolute time in srs_utime_t, while the sn(sequence number) is basetime/fragment.
virtual srs_error_t get_fragment(bool video, std::string& home, std::string& filename, int64_t& sn, srs_utime_t& basetime);
virtual srs_error_t get_fragment(bool video, std::string& home, std::string& filename, int64_t time, int64_t& sn);
// Set the availabilityStartTime once, map the timestamp in media to utc time.
virtual void set_availability_start_time(srs_utime_t t);
virtual srs_utime_t get_availability_start_time();
};
// The controller for DASH, control the MPD and FMP4 generating system.
@ -95,24 +107,33 @@ class SrsDashController
{
private:
SrsRequest* req;
SrsFormat* format_;
SrsMpdWriter* mpd;
private:
SrsFragmentedMp4* vcurrent;
SrsFragmentWindow* vfragments;
SrsFragmentedMp4* acurrent;
SrsFragmentWindow* afragments;
// Current audio dts.
uint64_t audio_dts;
// Current video dts.
uint64_t video_dts;
// First dts of the stream, use to calculate the availabilityStartTime in MPD.
int64_t first_dts_;
// Had the video reaped, use to align audio/video segment's timestamp.
bool video_reaped_;
private:
// The fragment duration in srs_utime_t to reap it.
srs_utime_t fragment;
private:
std::string home;
int video_tack_id;
int video_track_id;
int audio_track_id;
public:
SrsDashController();
virtual ~SrsDashController();
public:
virtual void dispose();
public:
virtual srs_error_t initialize(SrsRequest* r);
virtual srs_error_t on_publish();
@ -129,6 +150,8 @@ class SrsDash
{
private:
bool enabled;
bool disposable_;
srs_utime_t last_update_time_;
private:
SrsRequest* req;
SrsOriginHub* hub;
@ -136,6 +159,9 @@ private:
public:
SrsDash();
virtual ~SrsDash();
public:
virtual void dispose();
virtual srs_error_t cycle();
public:
// Initalize the encoder.
virtual srs_error_t initialize(SrsOriginHub* h, SrsRequest* r);