forked from bluenviron/gortsplib
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsession_stats.go
More file actions
207 lines (188 loc) · 6.79 KB
/
session_stats.go
File metadata and controls
207 lines (188 loc) · 6.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
package gortsplib
import (
"time"
"github.com/bluenviron/gortsplib/v5/pkg/description"
"github.com/bluenviron/gortsplib/v5/pkg/format"
)
// SessionStatsFormat are session format statistics.
type SessionStatsFormat struct {
// inbound RTP packets correctly received and processed
InboundRTPPackets uint64
// lost inbound RTP packets
InboundRTPPacketsLost uint64
// mean jitter of inbound RTP packets
InboundRTPPacketsJitter float64
// last sequence number of inbound RTP packets
InboundRTPPacketsLastSequenceNumber uint16
// last RTP time of inbound RTP packets
InboundRTPPacketsLastRTP uint32
// last NTP time of inbound RTP packets
InboundRTPPacketsLastNTP time.Time
// outbound RTP packets
OutboundRTPPackets uint64
// outbound RTP packets reported as lost by the remote receiver
OutboundRTPPacketsReportedLost uint64
// last sequence number of outbound RTP packets
OutboundRTPPacketsLastSequenceNumber uint16
// last RTP time of outbound RTP packets
OutboundRTPPacketsLastRTP uint32
// last NTP time of outbound RTP packets
OutboundRTPPacketsLastNTP time.Time
// local SSRC
LocalSSRC uint32
// remote SSRC
RemoteSSRC uint32
// Deprecated: use InboundRTPPacketsLastSequenceNumber or OutboundRTPPacketsLastSequenceNumber.
RTPPacketsLastSequenceNumber uint16
// Deprecated: use InboundRTPPacketsLastRTP or OutboundRTPPacketsLastRTP.
RTPPacketsLastRTP uint32
// Deprecated: use InboundRTPPacketsLastNTP or OutboundRTPPacketsLastNTP.
RTPPacketsLastNTP time.Time
// Deprecated: use InboundRTPPackets.
RTPPacketsReceived uint64
// Deprecated: use OutboundRTPPackets.
RTPPacketsSent uint64
// Deprecated: use OutboundRTPPacketsReportedLost.
RTPPacketsReportedLost uint64
// Deprecated: use InboundRTPPacketsLost.
RTPPacketsLost uint64
// Deprecated: use InboundRTPPacketsJitter.
RTPPacketsJitter float64
}
// SessionStatsMedia are session media statistics.
type SessionStatsMedia struct {
// inbound bytes
InboundBytes uint64
// inbound RTP packets that could not be processed
InboundRTPPacketsInError uint64
// inbound RTCP packets correctly received and processed
InboundRTCPPackets uint64
// inbound RTCP packets that could not be processed
InboundRTCPPacketsInError uint64
// outbound bytes
OutboundBytes uint64
// outbound RTCP packets
OutboundRTCPPackets uint64
// format statistics
Formats map[format.Format]SessionStatsFormat
// Deprecated: use InboundBytes.
BytesReceived uint64
// Deprecated: use OutboundBytes.
BytesSent uint64
// Deprecated: use InboundRTPPacketsInError.
RTPPacketsInError uint64
// Deprecated: use InboundRTCPPackets.
RTCPPacketsReceived uint64
// Deprecated: use OutboundRTCPPackets.
RTCPPacketsSent uint64
// Deprecated: use InboundRTCPPacketsInError.
RTCPPacketsInError uint64
}
// SessionStats are session statistics.
type SessionStats struct {
// inbound bytes
InboundBytes uint64
// inbound RTP packets correctly received and processed
InboundRTPPackets uint64
// lost inbound RTP packets
InboundRTPPacketsLost uint64
// inbound RTP packets that could not be processed
InboundRTPPacketsInError uint64
// mean jitter of inbound RTP packets
InboundRTPPacketsJitter float64
// inbound RTCP packets correctly received and processed
InboundRTCPPackets uint64
// inbound RTCP packets that could not be processed
InboundRTCPPacketsInError uint64
// outbound bytes
OutboundBytes uint64
// outbound RTP packets
OutboundRTPPackets uint64
// outbound RTP packets reported as lost by the remote receiver
OutboundRTPPacketsReportedLost uint64
// outbound RTCP packets
OutboundRTCPPackets uint64
// media statistics
Medias map[*description.Media]SessionStatsMedia
// Deprecated: use InboundBytes.
BytesReceived uint64
// Deprecated: use OutboundBytes.
BytesSent uint64
// Deprecated: use InboundRTPPackets.
RTPPacketsReceived uint64
// Deprecated: use OutboundRTPPackets.
RTPPacketsSent uint64
// Deprecated: use OutboundRTPPacketsReportedLost.
RTPPacketsReportedLost uint64
// Deprecated: use InboundRTPPacketsLost.
RTPPacketsLost uint64
// Deprecated: use InboundRTPPacketsInError.
RTPPacketsInError uint64
// Deprecated: use InboundRTPPacketsJitter.
RTPPacketsJitter float64
// Deprecated: use InboundRTCPPackets.
RTCPPacketsReceived uint64
// Deprecated: use OutboundRTCPPackets.
RTCPPacketsSent uint64
// Deprecated: use InboundRTCPPacketsInError.
RTCPPacketsInError uint64
}
func sessionStatsFromMedias(mediaStats map[*description.Media]SessionStatsMedia) SessionStats {
inboundBytes := uint64(0)
outboundBytes := uint64(0)
inboundRTPPackets := uint64(0)
outboundRTPPackets := uint64(0)
outboundRTPPacketsReportedLost := uint64(0)
inboundRTPPacketsLost := uint64(0)
inboundRTPPacketsInError := uint64(0)
inboundRTPPacketsJitter := float64(0)
inboundRTPPacketsJitterCount := float64(0)
inboundRTCPPackets := uint64(0)
outboundRTCPPackets := uint64(0)
inboundRTCPPacketsInError := uint64(0)
for _, ms := range mediaStats {
inboundBytes += ms.InboundBytes
outboundBytes += ms.OutboundBytes
inboundRTPPacketsInError += ms.InboundRTPPacketsInError
inboundRTCPPackets += ms.InboundRTCPPackets
outboundRTCPPackets += ms.OutboundRTCPPackets
inboundRTCPPacketsInError += ms.InboundRTCPPacketsInError
for _, fs := range ms.Formats {
inboundRTPPackets += fs.InboundRTPPackets
outboundRTPPackets += fs.OutboundRTPPackets
outboundRTPPacketsReportedLost += fs.OutboundRTPPacketsReportedLost
inboundRTPPacketsLost += fs.InboundRTPPacketsLost
inboundRTPPacketsJitter += fs.InboundRTPPacketsJitter
inboundRTPPacketsJitterCount++
}
}
if inboundRTPPacketsJitterCount != 0 {
inboundRTPPacketsJitter /= inboundRTPPacketsJitterCount
}
return SessionStats{
InboundBytes: inboundBytes,
InboundRTPPackets: inboundRTPPackets,
InboundRTPPacketsLost: inboundRTPPacketsLost,
InboundRTPPacketsInError: inboundRTPPacketsInError,
InboundRTPPacketsJitter: inboundRTPPacketsJitter,
InboundRTCPPackets: inboundRTCPPackets,
InboundRTCPPacketsInError: inboundRTCPPacketsInError,
OutboundBytes: outboundBytes,
OutboundRTPPackets: outboundRTPPackets,
OutboundRTPPacketsReportedLost: outboundRTPPacketsReportedLost,
OutboundRTCPPackets: outboundRTCPPackets,
Medias: mediaStats,
// deprecated
BytesReceived: inboundBytes,
BytesSent: outboundBytes,
RTPPacketsReceived: inboundRTPPackets,
RTPPacketsSent: outboundRTPPackets,
RTPPacketsReportedLost: outboundRTPPacketsReportedLost,
RTPPacketsLost: inboundRTPPacketsLost,
RTPPacketsInError: inboundRTPPacketsInError,
RTPPacketsJitter: inboundRTPPacketsJitter,
RTCPPacketsReceived: inboundRTCPPackets,
RTCPPacketsSent: outboundRTCPPackets,
RTCPPacketsInError: inboundRTCPPacketsInError,
}
}