Added Meta::packetTimeToUnixMs, fixed datetimes in m3u8 recordings
This commit is contained in:
parent
3fb92a01d3
commit
ac58015e02
3 changed files with 30 additions and 12 deletions
14
lib/dtsc.cpp
14
lib/dtsc.cpp
|
@ -2593,6 +2593,20 @@ namespace DTSC{
|
|||
return result.str();
|
||||
}
|
||||
|
||||
uint64_t Meta::packetTimeToUnixMs(uint64_t pktTime, uint64_t systemBoot) const{
|
||||
if (getUTCOffset()){
|
||||
return pktTime + getUTCOffset();
|
||||
}
|
||||
if (getLive()){
|
||||
// Grab system boot time from global config file if possible
|
||||
if (!systemBoot){systemBoot = Util::getGlobalConfig("systemBoot").asInt();}
|
||||
// fall back to local calculation if loading from global config fails
|
||||
if (!systemBoot){systemBoot = (Util::unixMS() - Util::bootMS());}
|
||||
return pktTime + systemBoot + getBootMsOffset();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const Util::RelAccX &Meta::parts(size_t idx) const{return tracks.at(idx).parts;}
|
||||
Util::RelAccX &Meta::keys(size_t idx){return tracks.at(idx).keys;}
|
||||
const Util::RelAccX &Meta::keys(size_t idx) const{return tracks.at(idx).keys;}
|
||||
|
|
|
@ -350,6 +350,7 @@ namespace DTSC{
|
|||
size_t trackIDToIndex(size_t trackID, size_t pid = 0) const;
|
||||
|
||||
std::string getTrackIdentifier(size_t idx, bool unique = false) const;
|
||||
uint64_t packetTimeToUnixMs(uint64_t pktTime, uint64_t systemBoot = 0) const;
|
||||
|
||||
void setInit(size_t trackIdx, const std::string &init);
|
||||
void setInit(size_t trackIdx, const char *init, size_t initLen);
|
||||
|
|
|
@ -589,7 +589,7 @@ namespace Mist{
|
|||
}
|
||||
continue;
|
||||
}
|
||||
if (targetAge && curDateString.size() > 25){
|
||||
if (targetAge && curTime && curDateString.size() > 25){
|
||||
uint64_t segmentDiff = Util::getUTCTimeDiff(curDateString.substr(25), curTime);
|
||||
if (segmentDiff > targetAge){
|
||||
HIGH_MSG("Dropping segment #%" PRIu64 " from the playlist due to old age (%" PRIu64 " s)", segmentsRemoved, segmentDiff);
|
||||
|
@ -1613,7 +1613,7 @@ namespace Mist{
|
|||
// Initialises the playlist if we are segmenting the output with a playlist
|
||||
if (targetParams.count("m3u8")){
|
||||
if (reInitPlaylist){
|
||||
uint64_t unixMs = M.getBootMsOffset() + systemBoot + currentStartTime;
|
||||
uint64_t unixMs = M.packetTimeToUnixMs(currentStartTime, systemBoot);
|
||||
reinitPlaylist(playlistBuffer, targetAge, maxEntries, segmentCount, segmentsRemoved, unixMs, targetDuration, playlistLocation);
|
||||
}
|
||||
// Do not open the playlist just yet if this is a non-live source
|
||||
|
@ -1757,9 +1757,12 @@ namespace Mist{
|
|||
break;
|
||||
}
|
||||
std::string segment = HTTP::localURIResolver().link(currentTarget).getLinkFrom(playlistLocation);
|
||||
if (M.getLive()){
|
||||
uint64_t unixMs = M.getBootMsOffset() + systemBoot + currentStartTime;
|
||||
playlistBuffer += "#EXT-X-PROGRAM-DATE-TIME:" + Util::getUTCStringMillis(unixMs) + "\n";
|
||||
{
|
||||
uint64_t unixMs = M.packetTimeToUnixMs(currentStartTime, systemBoot);
|
||||
if (unixMs){
|
||||
INFO_MSG("Adding segment #%" PRIu64 " @ %" PRIu64 " => %s", segmentCount, currentStartTime, Util::getUTCStringMillis(unixMs).c_str());
|
||||
playlistBuffer += "#EXT-X-PROGRAM-DATE-TIME:" + Util::getUTCStringMillis(unixMs) + "\n";
|
||||
}
|
||||
}
|
||||
INFO_MSG("Adding new segment `%s` of %" PRIu64 "ms to playlist '%s'", segment.c_str(), lastPacketTime - currentStartTime, playlistLocationString.c_str());
|
||||
// Append duration & TS filename to playlist file
|
||||
|
@ -1778,7 +1781,7 @@ namespace Mist{
|
|||
targetDuration = JSON::Value((uint64_t)segmentDuration + 1).asString();
|
||||
// Modify the buffer to contain the new targetDuration
|
||||
if (!M.getLive()){
|
||||
uint64_t unixMs = M.getBootMsOffset() + systemBoot + currentStartTime;
|
||||
uint64_t unixMs = M.packetTimeToUnixMs(currentStartTime, systemBoot);
|
||||
reinitPlaylist(playlistBuffer, targetAge, maxEntries, segmentCount, segmentsRemoved, unixMs, targetDuration, playlistLocation);
|
||||
}else if (!maxEntries && !targetAge && playlistLocation.isLocalPath()){
|
||||
// If we are appending to an existing playlist, we need to recover the playlistBuffer and reopen the playlist
|
||||
|
@ -1788,7 +1791,7 @@ namespace Mist{
|
|||
inFile.readAll(newBuffer, bytesRead);
|
||||
playlistBuffer = std::string(newBuffer, bytesRead) + playlistBuffer;
|
||||
// Reinit the playlist with the new targetDuration
|
||||
uint64_t unixMs = M.getBootMsOffset() + systemBoot + currentStartTime;
|
||||
uint64_t unixMs = M.packetTimeToUnixMs(currentStartTime, systemBoot);
|
||||
reinitPlaylist(playlistBuffer, targetAge, maxEntries, segmentCount, segmentsRemoved, unixMs, targetDuration, playlistLocation);
|
||||
connectToFile(playlistLocationString, false, &plsConn);
|
||||
}
|
||||
|
@ -1796,7 +1799,7 @@ namespace Mist{
|
|||
}
|
||||
// Remove older entries in the playlist
|
||||
if (maxEntries || targetAge){
|
||||
uint64_t unixMs = M.getBootMsOffset() + systemBoot + currentStartTime;
|
||||
uint64_t unixMs = M.packetTimeToUnixMs(currentStartTime, systemBoot);
|
||||
reinitPlaylist(playlistBuffer, targetAge, maxEntries, segmentCount, segmentsRemoved, unixMs, targetDuration, playlistLocation);
|
||||
}
|
||||
// Do not write to the playlist intermediately if we are outputting a VOD playlist
|
||||
|
@ -1892,9 +1895,9 @@ namespace Mist{
|
|||
if (lastPacketTime - currentStartTime > 0){
|
||||
std::string segment = HTTP::localURIResolver().link(currentTarget).getLinkFrom(playlistLocation);
|
||||
INFO_MSG("Adding final segment `%s` of %" PRIu64 "ms to playlist '%s'", segment.c_str(), lastPacketTime - currentStartTime, playlistLocationString.c_str());
|
||||
if (M.getLive()){
|
||||
uint64_t unixMs = M.getBootMsOffset() + systemBoot + currentStartTime;
|
||||
playlistBuffer += "#EXT-X-PROGRAM-DATE-TIME:" + Util::getUTCStringMillis(unixMs) + "\n";
|
||||
{
|
||||
uint64_t unixMs = M.packetTimeToUnixMs(currentStartTime, systemBoot);
|
||||
if (unixMs){playlistBuffer += "#EXT-X-PROGRAM-DATE-TIME:" + Util::getUTCStringMillis(unixMs) + "\n";}
|
||||
}
|
||||
// Append duration & TS filename to playlist file
|
||||
std::stringstream tmp;
|
||||
|
@ -1905,7 +1908,7 @@ namespace Mist{
|
|||
if ((!M.getLive() || (!maxEntries && !targetAge)) && addEndlist){playlistBuffer += "#EXT-X-ENDLIST\n";}
|
||||
// Remove older entries in the playlist
|
||||
if (maxEntries || targetAge){
|
||||
uint64_t unixMs = M.getBootMsOffset() + systemBoot + currentStartTime;
|
||||
uint64_t unixMs = M.packetTimeToUnixMs(currentStartTime, systemBoot);
|
||||
reinitPlaylist(playlistBuffer, targetAge, maxEntries, segmentCount, segmentsRemoved, unixMs, targetDuration, playlistLocation);
|
||||
}
|
||||
// Append the final contents to the playlist
|
||||
|
|
Loading…
Add table
Reference in a new issue