OPAL  Version 3.10.10
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: 27699 $
23  * $Author: rjongbloed $
24  * $Date: 2012-05-24 20:35:37 -0500 (Thu, 24 May 2012) $
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/buildopts.h>
35 
36 #if OPAL_RTCP_XR
37 
38 #include <rtp/rtp.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
52 {
53  protected:
54  RTCP_XR_Metrics(
55  float Ie,
56  float Bpl,
57  float lookAheadTime,
58  PINDEX payloadSize,
59  unsigned payloadBitrate
60  );
61 
62  public:
63  static RTCP_XR_Metrics * Create(const RTP_DataFrame & frame);
64 
65  ~RTCP_XR_Metrics();
66 
67  enum PacketEvent {
68  PACKET_RECEIVED,
69  PACKET_DISCARDED,
70  PACKET_LOST
71  };
72 
73  enum PeriodType {
74  GAP, /* a period of low packet losses and/or discards */
75  BURST, /* a period of a high proportion of packet losses and/or discards */
76  };
77 
78  /* A period of time, which can be a burst or a gap */
79  typedef struct TimePeriod {
80  PeriodType type;
81  PTimeInterval duration;
82  } TimePeriod;
83 
87  typedef struct IdPeriod {
88  PTimeInterval duration;
89  float Id;
90  } IdPeriod;
91 
95  typedef struct IePeriod {
96  PeriodType type;
97  PTimeInterval duration;
98  float Ieff;
99  } IePeriod;
100 
101  enum QualityType {
102  LQ, /* Listening Quality, not include the effects of delay */
103  CQ /* Conversational Quality, include the effects of delay */
104  };
105 
109  void SetJitterDelay(
110  DWORD delay
111  );
112 
115  void OnPacketReceived();
116 
119  void OnPacketDiscarded();
120 
123  void OnPacketLost();
124 
127  void OnPacketLost(
128  DWORD dropped
129  );
130 
133  void OnRxSenderReport(
134  PUInt32b lsr,
135  PUInt32b dlsr
136  );
137 
140  BYTE GetLossRate();
141 
144  BYTE GetDiscardRate();
145 
149  BYTE GetBurstDensity();
150 
154  BYTE GetGapDensity();
155 
159  PUInt16b GetBurstDuration();
160 
164  PUInt16b GetGapDuration();
165 
169  PUInt16b GetRoundTripDelay ();
170 
173  PUInt16b GetEndSystemDelay();
174 
177  BYTE RFactor();
178 
183  BYTE MOS_LQ();
184 
189  BYTE MOS_CQ();
190 
191  // Internal functions
192  void InsertExtendedReportPacket(
193  unsigned sessionID,
194  DWORD syncSourceOut,
195  RTP_Session::JitterBufferPtr jitter, // Note do not make JitterBufferPtr a reference, needs to be a copy
196  RTP_ControlFrame & report
197  );
198 
199  static RTP_Session::ExtendedReportArray
200  BuildExtendedReportArray(const RTP_ControlFrame & frame, PINDEX offset);
201 
202 
203  protected:
212  void markov(
213  PacketEvent event
214  );
215 
218  void ResetCounters();
219 
222  BYTE RFactor(
223  QualityType qt
224  );
225 
228  BYTE EndOfCallRFactor();
229 
233  float MOS(
234  QualityType qt
235  );
236 
240  float EndOfCallMOS();
241 
244  float IdFactor();
245 
248  float GetPonderateId();
249 
252  float Ieff(
253  PeriodType type
254  );
255 
258  float GetEndOfCallIe();
259 
262  float GetPonderateIe();
263 
266  TimePeriod createTimePeriod(
267  PeriodType type,
268  PTime beginTimestamp,
269  PTime endTimestamp
270  );
271 
274  IdPeriod createIdPeriod(
275  PTime beginTimestamp,
276  PTime endTimestamp
277  );
278 
281  IePeriod createIePeriod(
282  TimePeriod timePeriod
283  );
284 
285  /* data associated with the payload */
286  float m_Ie; /* equipment impairment factor for the codec utilized */
287  float m_Bpl; /* robustness factor for the codec utilized */
288  float m_lookAheadTime; /* codec lookahead time */
289  PINDEX m_payloadSize;
290  unsigned m_payloadBitrate;
291 
292  DWORD m_gmin; /* gap threshold */
293  DWORD m_lostInBurst; /* number of lost packets within the current burst */
294  DWORD m_packetsReceived; /* packets received since the beggining of the reception */
295  DWORD m_packetsSinceLastLoss; /* packets received since the last loss or discard event */
296  DWORD m_packetsLost; /* packets lost since the beggining of the reception */
297  DWORD m_packetsDiscarded; /* packets discarded since the beggining of the receptions */
298  DWORD m_srPacketsReceived; /* count of SR packets received */
299 
300  DWORD m_packetsReceivedInGap; /* packets received within gap periods */
301  DWORD m_packetsLostInGap; /* packets lost within gap periods */
302 
303  DWORD m_packetsReceivedInBurst; /* packets received within burst periods */
304  DWORD m_packetsLostInBurst; /* packets lost within burst periods */
305 
315  DWORD c5;
316  DWORD c11;
317  DWORD c13;
318  DWORD c14;
319  DWORD c22;
320  DWORD c23;
321  DWORD c31;
322  DWORD c32;
323  DWORD c33;
324 
325  /* variables to calculate round trip delay */
326  PTime m_lsrTime;
327  PTimeInterval m_dlsrTime;
328  PTime m_arrivalTime;
329 
330  DWORD m_jitterDelay; /* jitter buffer delay, in milliseconds */
331  float m_lastId; /* last Id calculated */
332  float m_lastIe; /* last Ie calculated */
333 
334  std::list<TimePeriod> m_timePeriods;
335  std::list<IePeriod> m_iePeriods;
336  std::list<IdPeriod> m_idPeriods;
337 
338  PeriodType m_currentPeriodType; /* indicates if we are within a gap or burst */
339  PTime m_periodBeginTimestamp; /* timestamp of the beginning of the gap or burst period */
340  PTime m_lastLossTimestamp; /* timestamp of the last loss */
341  PTime m_lastLossInBurstTimestamp; /* timestamp of the last loss within a burst period */
342  PTime m_lastJitterBufferChangeTimestamp; /* timestamp of the last change in jitter buffer size */
343 
344 };
345 
346 
347 #endif // OPAL_RTCP_XR
348 
349 #endif // OPAL_METRICS_H
350 
351