Simplified MP4 input logic significantly, added DTSC::Meta::getPartTime() function, fixed issues with MP4 files with frame durations smaller than 1ms

This commit is contained in:
Thulinma 2022-11-25 02:27:13 +01:00
parent e69050224b
commit 4743769c15
4 changed files with 61 additions and 64 deletions

View file

@ -3168,6 +3168,31 @@ namespace DTSC{
return res;
}
/// Returns the part timestamp for the given index.
/// Assumes the Packet is for the given track, and assumes the metadata and track data are not out
/// of sync. Works by looking up the packet's key's timestamp, then walking through the
/// parts adding up durations until we reach the part we want. Returns zero if the track
/// index is invalid or if the timestamp cannot be found.
uint64_t Meta::getPartTime(uint32_t partIndex, size_t idx) const{
if (idx == INVALID_TRACK_ID){return 0;}
DTSC::Keys Keys(keys(idx));
DTSC::Parts Parts(parts(idx));
size_t kId = 0;
for (kId = 0; kId < Keys.getEndValid(); ++kId){
size_t keyPartId = Keys.getFirstPart(kId);
if (keyPartId+Keys.getParts(kId) > partIndex){
//It's inside this key. Step through.
uint64_t res = Keys.getTime(kId);
while (keyPartId < partIndex){
res += Parts.getDuration(keyPartId);
++keyPartId;
}
return res;
}
}
return 0;
}
/// Given the current page, check if the next page is available. Returns true if it is.
bool Meta::nextPageAvailable(uint32_t idx, size_t currentPage) const{
const Util::RelAccX &pages = tracks.at(idx).pages;

View file

@ -445,6 +445,7 @@ namespace DTSC{
uint32_t getKeyIndexForTime(uint32_t idx, uint64_t timestamp) const;
uint32_t getPartIndex(uint64_t timestamp, size_t idx) const;
uint64_t getPartTime(uint32_t partIndex, size_t idx) const;
bool nextPageAvailable(uint32_t idx, size_t currentPage) const;
size_t getPageNumberForTime(uint32_t idx, uint64_t time) const;