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();
|
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;}
|
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;}
|
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;}
|
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;
|
size_t trackIDToIndex(size_t trackID, size_t pid = 0) const;
|
||||||
|
|
||||||
std::string getTrackIdentifier(size_t idx, bool unique = false) 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 std::string &init);
|
||||||
void setInit(size_t trackIdx, const char *init, size_t initLen);
|
void setInit(size_t trackIdx, const char *init, size_t initLen);
|
||||||
|
|
|
@ -589,7 +589,7 @@ namespace Mist{
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (targetAge && curDateString.size() > 25){
|
if (targetAge && curTime && curDateString.size() > 25){
|
||||||
uint64_t segmentDiff = Util::getUTCTimeDiff(curDateString.substr(25), curTime);
|
uint64_t segmentDiff = Util::getUTCTimeDiff(curDateString.substr(25), curTime);
|
||||||
if (segmentDiff > targetAge){
|
if (segmentDiff > targetAge){
|
||||||
HIGH_MSG("Dropping segment #%" PRIu64 " from the playlist due to old age (%" PRIu64 " s)", segmentsRemoved, segmentDiff);
|
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
|
// Initialises the playlist if we are segmenting the output with a playlist
|
||||||
if (targetParams.count("m3u8")){
|
if (targetParams.count("m3u8")){
|
||||||
if (reInitPlaylist){
|
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);
|
reinitPlaylist(playlistBuffer, targetAge, maxEntries, segmentCount, segmentsRemoved, unixMs, targetDuration, playlistLocation);
|
||||||
}
|
}
|
||||||
// Do not open the playlist just yet if this is a non-live source
|
// Do not open the playlist just yet if this is a non-live source
|
||||||
|
@ -1757,9 +1757,12 @@ namespace Mist{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
std::string segment = HTTP::localURIResolver().link(currentTarget).getLinkFrom(playlistLocation);
|
std::string segment = HTTP::localURIResolver().link(currentTarget).getLinkFrom(playlistLocation);
|
||||||
if (M.getLive()){
|
{
|
||||||
uint64_t unixMs = M.getBootMsOffset() + systemBoot + currentStartTime;
|
uint64_t unixMs = M.packetTimeToUnixMs(currentStartTime, systemBoot);
|
||||||
playlistBuffer += "#EXT-X-PROGRAM-DATE-TIME:" + Util::getUTCStringMillis(unixMs) + "\n";
|
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());
|
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
|
// Append duration & TS filename to playlist file
|
||||||
|
@ -1778,7 +1781,7 @@ namespace Mist{
|
||||||
targetDuration = JSON::Value((uint64_t)segmentDuration + 1).asString();
|
targetDuration = JSON::Value((uint64_t)segmentDuration + 1).asString();
|
||||||
// Modify the buffer to contain the new targetDuration
|
// Modify the buffer to contain the new targetDuration
|
||||||
if (!M.getLive()){
|
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);
|
reinitPlaylist(playlistBuffer, targetAge, maxEntries, segmentCount, segmentsRemoved, unixMs, targetDuration, playlistLocation);
|
||||||
}else if (!maxEntries && !targetAge && playlistLocation.isLocalPath()){
|
}else if (!maxEntries && !targetAge && playlistLocation.isLocalPath()){
|
||||||
// If we are appending to an existing playlist, we need to recover the playlistBuffer and reopen the playlist
|
// 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);
|
inFile.readAll(newBuffer, bytesRead);
|
||||||
playlistBuffer = std::string(newBuffer, bytesRead) + playlistBuffer;
|
playlistBuffer = std::string(newBuffer, bytesRead) + playlistBuffer;
|
||||||
// Reinit the playlist with the new targetDuration
|
// 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);
|
reinitPlaylist(playlistBuffer, targetAge, maxEntries, segmentCount, segmentsRemoved, unixMs, targetDuration, playlistLocation);
|
||||||
connectToFile(playlistLocationString, false, &plsConn);
|
connectToFile(playlistLocationString, false, &plsConn);
|
||||||
}
|
}
|
||||||
|
@ -1796,7 +1799,7 @@ namespace Mist{
|
||||||
}
|
}
|
||||||
// Remove older entries in the playlist
|
// Remove older entries in the playlist
|
||||||
if (maxEntries || targetAge){
|
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);
|
reinitPlaylist(playlistBuffer, targetAge, maxEntries, segmentCount, segmentsRemoved, unixMs, targetDuration, playlistLocation);
|
||||||
}
|
}
|
||||||
// Do not write to the playlist intermediately if we are outputting a VOD playlist
|
// Do not write to the playlist intermediately if we are outputting a VOD playlist
|
||||||
|
@ -1892,9 +1895,9 @@ namespace Mist{
|
||||||
if (lastPacketTime - currentStartTime > 0){
|
if (lastPacketTime - currentStartTime > 0){
|
||||||
std::string segment = HTTP::localURIResolver().link(currentTarget).getLinkFrom(playlistLocation);
|
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());
|
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;
|
uint64_t unixMs = M.packetTimeToUnixMs(currentStartTime, systemBoot);
|
||||||
playlistBuffer += "#EXT-X-PROGRAM-DATE-TIME:" + Util::getUTCStringMillis(unixMs) + "\n";
|
if (unixMs){playlistBuffer += "#EXT-X-PROGRAM-DATE-TIME:" + Util::getUTCStringMillis(unixMs) + "\n";}
|
||||||
}
|
}
|
||||||
// Append duration & TS filename to playlist file
|
// Append duration & TS filename to playlist file
|
||||||
std::stringstream tmp;
|
std::stringstream tmp;
|
||||||
|
@ -1905,7 +1908,7 @@ namespace Mist{
|
||||||
if ((!M.getLive() || (!maxEntries && !targetAge)) && addEndlist){playlistBuffer += "#EXT-X-ENDLIST\n";}
|
if ((!M.getLive() || (!maxEntries && !targetAge)) && addEndlist){playlistBuffer += "#EXT-X-ENDLIST\n";}
|
||||||
// Remove older entries in the playlist
|
// Remove older entries in the playlist
|
||||||
if (maxEntries || targetAge){
|
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);
|
reinitPlaylist(playlistBuffer, targetAge, maxEntries, segmentCount, segmentsRemoved, unixMs, targetDuration, playlistLocation);
|
||||||
}
|
}
|
||||||
// Append the final contents to the playlist
|
// Append the final contents to the playlist
|
||||||
|
|
Loading…
Add table
Reference in a new issue