OPAL  Version 3.14.3
metrics.h
Go to the documentation of this file.
1 /*
2  * metrics.h
3  *
4  * E-Model implementation
5  *
6  * Open Phone Abstraction Library (OPAL)
7  *
8  * Copyright (c) 2010 Universidade Federal do Amazonas
9  *
10  * The contents of this file are subject to the Mozilla Public License
11  * Version 1.0 (the "License"); you may not use this file except in
12  * compliance with the License. You may obtain a copy of the License at
13  * http://www.mozilla.org/MPL/
14  *
15  * Software distributed under the License is distributed on an "AS IS"
16  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
17  * the License for the specific language governing rights and limitations
18  * under the License.
19  *
20  * Contributor(s): ______________________________________.
21  *
22  * $Revision: 29536 $
23  * $Author: rjongbloed $
24  * $Date: 2013-04-19 18:55:15 +1000 (Fri, 19 Apr 2013) $
25  */
26 
27 #ifndef OPAL_RTP_METRICS_H
28 #define OPAL_RTP_METRICS_H
29 
30 #ifdef P_USE_PRAGMA
31 #pragma interface
32 #endif
33 
34 #include <opal_config.h>
35 
36 #if OPAL_RTCP_XR
37 
38 #include <rtp/rtp_session.h>
39 
40 #include <list>
41 
42 class RTP_Session;
43 class RTP_DataFrame;
44 
46 // RTCP-XR - VoIP Metrics Report Block
47 
51 class RTCP_XR_Metrics : public PObject
52 {
53  PCLASSINFO(RTCP_XR_Metrics, PObject);
54  protected:
55  RTCP_XR_Metrics(
56  float Ie,
57  float Bpl,
58  float lookAheadTime,
59  PINDEX payloadSize,
60  unsigned payloadBitrate
61  );
62 
63  public:
64  static RTCP_XR_Metrics * Create(const RTP_DataFrame & frame);
65 
66  ~RTCP_XR_Metrics();
67 
68  enum PacketEvent {
69  PACKET_RECEIVED,
70  PACKET_DISCARDED,
71  PACKET_LOST
72  };
73 
74  enum PeriodType {
75  GAP, /* a period of low packet losses and/or discards */
76  BURST, /* a period of a high proportion of packet losses and/or discards */
77  };
78 
79  /* A period of time, which can be a burst or a gap */
80  typedef struct TimePeriod {
81  PeriodType type;
82  PTimeInterval duration;
83  } TimePeriod;
84 
88  typedef struct IdPeriod {
89  PTimeInterval duration;
90  float Id;
91  } IdPeriod;
92 
96  typedef struct IePeriod {
97  PeriodType type;
98  PTimeInterval duration;
99  float Ieff;
100  } IePeriod;
101 
102  enum QualityType {
103  LQ, /* Listening Quality, not include the effects of delay */
104  CQ /* Conversational Quality, include the effects of delay */
105  };
106 
110  void SetJitterDelay(
111  DWORD delay
112  );
113 
116  void OnPacketReceived();
117 
120  void OnPacketDiscarded();
121 
124  void OnPacketLost();
125 
128  void OnPacketLost(
129  DWORD dropped
130  );
131 
134  void OnRxSenderReport(
135  PUInt32b lsr,
136  PUInt32b dlsr
137  );
138 
141  BYTE GetLossRate();
142 
145  BYTE GetDiscardRate();
146 
150  BYTE GetBurstDensity();
151 
155  BYTE GetGapDensity();
156 
160  PUInt16b GetBurstDuration();
161 
165  PUInt16b GetGapDuration();
166 
170  PUInt16b GetRoundTripDelay ();
171 
174  PUInt16b GetEndSystemDelay();
175 
178  BYTE RFactor();
179 
184  BYTE MOS_LQ();
185 
190  BYTE MOS_CQ();
191 
192  // Internal functions
193  void InsertExtendedReportPacket(
194  unsigned sessionID,
195  DWORD syncSourceOut,
196  OpalRTPSession::JitterBufferPtr jitter, // Note do not make JitterBufferPtr a reference, needs to be a copy
197  RTP_ControlFrame & report
198  );
199 
200  static OpalRTPSession::ExtendedReportArray
201  BuildExtendedReportArray(const RTP_ControlFrame & frame, PINDEX offset);
202 
203 
204  protected:
213  void markov(
214  PacketEvent event
215  );
216 
219  void ResetCounters();
220 
223  BYTE RFactor(
224  QualityType qt
225  );
226 
229  BYTE EndOfCallRFactor();
230 
234  float MOS(
235  QualityType qt
236  );
237 
241  float EndOfCallMOS();
242 
245  float IdFactor();
246 
249  float GetPonderateId();
250 
253  float Ieff(
254  PeriodType type
255  );
256 
259  float GetEndOfCallIe();
260 
263  float GetPonderateIe();
264 
267  TimePeriod createTimePeriod(
268  PeriodType type,
269  PTime beginTimestamp,
270  PTime endTimestamp
271  );
272 
275  IdPeriod createIdPeriod(
276  PTime beginTimestamp,
277  PTime endTimestamp
278  );
279 
282  IePeriod createIePeriod(
283  TimePeriod timePeriod
284  );
285 
286  /* data associated with the payload */
287  float m_Ie; /* equipment impairment factor for the codec utilized */
288  float m_Bpl; /* robustness factor for the codec utilized */
289  float m_lookAheadTime; /* codec lookahead time */
290  PINDEX m_payloadSize;
291  unsigned m_payloadBitrate;
292 
293  DWORD m_gmin; /* gap threshold */
294  DWORD m_lostInBurst; /* number of lost packets within the current burst */
295  DWORD m_packetsReceived; /* packets received since the beggining of the reception */
296  DWORD m_packetsSinceLastLoss; /* packets received since the last loss or discard event */
297  DWORD m_packetsLost; /* packets lost since the beggining of the reception */
298  DWORD m_packetsDiscarded; /* packets discarded since the beggining of the receptions */
299  DWORD m_srPacketsReceived; /* count of SR packets received */
300 
301  DWORD m_packetsReceivedInGap; /* packets received within gap periods */
302  DWORD m_packetsLostInGap; /* packets lost within gap periods */
303 
304  DWORD m_packetsReceivedInBurst; /* packets received within burst periods */
305  DWORD m_packetsLostInBurst; /* packets lost within burst periods */
306 
316  DWORD c5;
317  DWORD c11;
318  DWORD c13;
319  DWORD c14;
320  DWORD c22;
321  DWORD c23;
322  DWORD c31;
323  DWORD c32;
324  DWORD c33;
325 
326  /* variables to calculate round trip delay */
327  PTime m_lsrTime;
328  PTimeInterval m_dlsrTime;
329  PTime m_arrivalTime;
330 
331  DWORD m_jitterDelay; /* jitter buffer delay, in milliseconds */
332  float m_lastId; /* last Id calculated */
333  float m_lastIe; /* last Ie calculated */
334 
335  std::list<TimePeriod> m_timePeriods;
336  std::list<IePeriod> m_iePeriods;
337  std::list<IdPeriod> m_idPeriods;
338 
339  PeriodType m_currentPeriodType; /* indicates if we are within a gap or burst */
340  PTime m_periodBeginTimestamp; /* timestamp of the beginning of the gap or burst period */
341  PTime m_lastLossTimestamp; /* timestamp of the last loss */
342  PTime m_lastLossInBurstTimestamp; /* timestamp of the last loss within a burst period */
343  PTime m_lastJitterBufferChangeTimestamp; /* timestamp of the last change in jitter buffer size */
344 
345 };
346 
347 
348 #endif // OPAL_RTCP_XR
349 
350 #endif // OPAL_METRICS_H
351 
352