forked from zillevdr/vdr-plugin-softhddevice-drm
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathjittertracker.cpp
More file actions
76 lines (59 loc) · 1.79 KB
/
jittertracker.cpp
File metadata and controls
76 lines (59 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// SPDX-License-Identifier: AGPL-3.0-or-later
/**
* @file jittertracker.cpp
* Jitter Tracking of Incoming Packets
*
* @license{AGPL-3.0-or-later}
*/
#include <algorithm>
#include <cmath>
#include "jittertracker.h"
#include "logger.h"
/**
* Called each time a packet is received.
*
* Calculates the diff in PTS to the last received packet and compares that
* to the diff of the wall clock time of the last received packet to now.
*/
void cJitterTracker::PacketReceived(void)
{
auto now = std::chrono::steady_clock::now();
m_packetCounter++;
if (m_firstPacket) {
m_lastTime = now;
m_firstPacket = false;
return;
}
auto diffMs = std::chrono::duration_cast<std::chrono::milliseconds>(now - m_lastTime).count();
if (m_secondPacket) {
m_lastDiffMs = diffMs;
m_lastTime = now;
m_secondPacket = false;
return;
}
int jitterMs = std::abs(m_lastDiffMs - diffMs);
if (jitterMs > m_longTermMaxJitterMs)
m_longTermMaxJitterMs = jitterMs;
if (jitterMs > m_shortTermMaxJitterMs)
m_shortTermMaxJitterMs = jitterMs;
// if (jitterMs > 35 && strcmp(m_identifier, "video") == 0)
// LOGDEBUG2(L_SOUND, "jittertracker: %s: %s: high jitter detected: packet no.: %d: %dms (last diff: %dms, time diff: %dms)", __FUNCTION__, m_identifier, m_packetCounter, jitterMs, m_lastDiffMs, diffMs);
if (m_packetCounter % 1000 == 0) {
// LOGDEBUG2(L_SOUND, "jittertracker: %s: %s: max jitter: last 1000 packets: %dms, overall: %dms,", __FUNCTION__, m_identifier, m_shortTermMaxJitterMs, m_longTermMaxJitterMs);
m_shortTermMaxJitterMs = 0;
}
m_lastDiffMs = diffMs;
m_lastTime = now;
}
/**
* Resets the jitter tracker.
*/
void cJitterTracker::Reset(void)
{
m_lastDiffMs = 0;
m_shortTermMaxJitterMs = 0;
m_packetCounter = 0;
m_longTermMaxJitterMs = 0;
m_firstPacket = true;
m_secondPacket = true;
}