Split out jitter timer to be one per metadata, clear out jitter data when clearing as well

This commit is contained in:
Thulinma 2023-07-20 10:04:43 +02:00
parent 7d55a3f1c4
commit 0ec2800894
2 changed files with 71 additions and 66 deletions

View file

@ -2278,16 +2278,7 @@ namespace DTSC{
pack.getFlag("keyframe"), pack.getDataLen()); pack.getFlag("keyframe"), pack.getDataLen());
} }
/// Helper class that calculates inter-packet jitter jitterTimer::jitterTimer(){
class jitterTimer{
public:
uint64_t trueTime[8]; // Array of bootMS-based measurement points
uint64_t packTime[8]; // Array of corresponding packet times
uint64_t curJitter; // Maximum jitter measurement in past 10 seconds
unsigned int x; // Current indice within above two arrays
uint64_t maxJitter; // Highest jitter ever observed by this jitterTimer
uint64_t lastTime; // Last packet used for a measurement point
jitterTimer(){
for (int i = 0; i < 8; ++i){ for (int i = 0; i < 8; ++i){
trueTime[i] = 0; trueTime[i] = 0;
packTime[i] = 0; packTime[i] = 0;
@ -2296,7 +2287,8 @@ namespace DTSC{
lastTime = 0; lastTime = 0;
x = 0; x = 0;
} }
uint64_t addPack(uint64_t t){
uint64_t jitterTimer::addPack(uint64_t t){
if (veryUglyJitterOverride){return veryUglyJitterOverride;} if (veryUglyJitterOverride){return veryUglyJitterOverride;}
uint64_t curMs = Util::bootMS(); uint64_t curMs = Util::bootMS();
if (!x){ if (!x){
@ -2348,14 +2340,12 @@ namespace DTSC{
} }
return maxJitter; return maxJitter;
} }
};
/// Updates the metadata given the packet's properties. /// Updates the metadata given the packet's properties.
void Meta::update(uint64_t packTime, int64_t packOffset, uint32_t packTrack, uint64_t packDataSize, void Meta::update(uint64_t packTime, int64_t packOffset, uint32_t packTrack, uint64_t packDataSize,
uint64_t packBytePos, bool isKeyframe, uint64_t packSendSize){ uint64_t packBytePos, bool isKeyframe, uint64_t packSendSize){
///\todo warning Re-Implement Ivec ///\todo warning Re-Implement Ivec
if (getLive()){ if (getLive()){
static std::map<size_t, jitterTimer> theJitters;
setMinKeepAway(packTrack, theJitters[packTrack].addPack(packTime)); setMinKeepAway(packTrack, theJitters[packTrack].addPack(packTime));
} }
@ -2548,6 +2538,7 @@ namespace DTSC{
/// Wipes internal structures, also marking as outdated and deleting memory structures if in /// Wipes internal structures, also marking as outdated and deleting memory structures if in
/// master mode. /// master mode.
void Meta::clear(){ void Meta::clear(){
theJitters.clear();
if (isMemBuf){ if (isMemBuf){
isMemBuf = false; isMemBuf = false;
free(streamMemBuf); free(streamMemBuf);

View file

@ -268,6 +268,19 @@ namespace DTSC{
Util::RelAccXFieldData fragmentSizeField; Util::RelAccXFieldData fragmentSizeField;
}; };
class jitterTimer{
public:
uint64_t trueTime[8]; // Array of bootMS-based measurement points
uint64_t packTime[8]; // Array of corresponding packet times
uint64_t curJitter; // Maximum jitter measurement in past 10 seconds
unsigned int x; // Current indice within above two arrays
uint64_t maxJitter; // Highest jitter ever observed by this jitterTimer
uint64_t lastTime; // Last packet used for a measurement point
jitterTimer();
uint64_t addPack(uint64_t t);
};
class Meta{ class Meta{
public: public:
Meta(const std::string &_streamName, const DTSC::Scan &src); Meta(const std::string &_streamName, const DTSC::Scan &src);
@ -499,6 +512,7 @@ namespace DTSC{
std::map<size_t, size_t> sizeMemBuf; std::map<size_t, size_t> sizeMemBuf;
private: private:
std::map<size_t, jitterTimer> theJitters;
// Internal buffers so we don't always need to search for everything // Internal buffers so we don't always need to search for everything
Util::RelAccXFieldData streamVodField; Util::RelAccXFieldData streamVodField;
Util::RelAccXFieldData streamLiveField; Util::RelAccXFieldData streamLiveField;