-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFrameStats.cs
More file actions
69 lines (57 loc) · 2.41 KB
/
FrameStats.cs
File metadata and controls
69 lines (57 loc) · 2.41 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
namespace MotionJpegLatencyTest
{
public class FrameStats
{
private FrameHeader _header;
private double _frameRateWindowTimeMs;
private int _frameCount;
private long _byteCount;
private Duration _renderDurations;
private Duration _compressDuration;
private Duration _transmitDuration;
private Duration _frameDuration;
public FrameHeader Update(long frameId, Duration frameTime)
{
lock (this)
{
var frameTimeMs = frameTime.TotalMilliseconds;
_header.FrameId = frameId;
_header.FrameTime = frameTimeMs;
if (++_frameCount == 30)
{
var dt = (frameTimeMs - _frameRateWindowTimeMs) / 1000.0;
double fc = _frameCount;
_header.FrameRate = _frameCount / dt;
_header.BandWidth = (_byteCount / dt) * 10 / 1e6; // roughly estimate 10 bits per byte for transmission
_header.RenderDuration = _renderDurations.TotalMilliseconds / fc;
_header.CompressDuration = _compressDuration.TotalMilliseconds / fc;
_header.TransmitDuration = _transmitDuration.TotalMilliseconds / fc;
_header.FrameDuration = _frameDuration.TotalMilliseconds / fc;
_frameDuration = _renderDurations = _compressDuration = _transmitDuration = default;
_frameRateWindowTimeMs = frameTimeMs;
_frameCount = 0;
_byteCount = 0;
}
return _header;
}
}
private void Add(ref Duration field, in Duration value)
{
lock (this)
{
field += value;
}
}
public void AddCompressedSize(long compressedSize)
{
lock (this)
{
_byteCount += compressedSize;
}
}
public void AddRenderDuration(in Duration ts) => Add(ref _renderDurations, ts);
public void AddCompressDuration(in Duration ts) => Add(ref _compressDuration, ts);
public void AddTransmitDuration(in Duration ts) => Add(ref _transmitDuration, ts);
public void AddFrameDuration(in Duration ts) => Add(ref _frameDuration, ts);
}
}