OPAL  Version 3.18.8
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 
23 #ifndef OPAL_RTP_METRICS_H
24 #define OPAL_RTP_METRICS_H
25 
26 #ifdef P_USE_PRAGMA
27 #pragma interface
28 #endif
29 
30 #include <opal_config.h>
31 
32 #if OPAL_RTCP_XR
33 
34 #include <rtp/rtp_session.h>
35 
36 #include <list>
37 
38 class RTP_Session;
39 class RTP_DataFrame;
40 
42 // RTCP-XR - VoIP Metrics Report Block
43 
44 class RTP_MetricsReport : public PObject
45 {
46  PCLASSINFO(RTP_MetricsReport, PObject);
47  public:
48  RTP_MetricsReport(const RTP_ControlFrame::MetricsReport & mr);
49 #if PTRACING
50  void PrintOn(ostream &) const;
51 #endif
52 
53  RTP_SyncSourceId sourceIdentifier;
54  float lossRate; /* percentage of RTP data packets lost */
55  float discardRate; /* percentage of RTP data packets discarded */
56  float burstDensity; /* percentage of RTP data packets within burst periods */
57  float gapDensity; /* percentage of RTP data packets within inter-burst gaps */
58  unsigned roundTripDelay; /* the most recently calculated round trip time */
59  unsigned RFactor; /* voice quality metric of the call */
60  unsigned mosLQ; /* MOS for listen quality */
61  unsigned mosCQ; /* MOS for conversational quality */
62  unsigned jbNominal; /* current nominal jitter buffer delay, in ms */
63  unsigned jbMaximum; /* current maximum jitter buffer delay, in ms */
64  unsigned jbAbsolute; /* current absolute maximum jitter buffer delay, in ms */
65 };
66 
67 
71 class RTCP_XR_Metrics : public PObject
72 {
73  PCLASSINFO(RTCP_XR_Metrics, PObject);
74  protected:
75  RTCP_XR_Metrics(
76  float Ie,
77  float Bpl,
78  float lookAheadTime,
79  PINDEX payloadSize,
80  unsigned payloadBitrate
81  );
82 
83  public:
84  static RTCP_XR_Metrics * Create(const RTP_DataFrame & frame);
85 
86  ~RTCP_XR_Metrics();
87 
88  enum PacketEvent {
89  PACKET_RECEIVED,
90  PACKET_DISCARDED,
91  PACKET_LOST
92  };
93 
94  enum PeriodType {
95  GAP, /* a period of low packet losses and/or discards */
96  BURST, /* a period of a high proportion of packet losses and/or discards */
97  };
98 
99  /* A period of time, which can be a burst or a gap */
100  typedef struct TimePeriod {
101  PeriodType type;
102  PTimeInterval duration;
103  } TimePeriod;
104 
108  typedef struct IdPeriod {
109  PTimeInterval duration;
110  float Id;
111  } IdPeriod;
112 
116  typedef struct IePeriod {
117  PeriodType type;
118  PTimeInterval duration;
119  float Ieff;
120  } IePeriod;
121 
122  enum QualityType {
123  LQ, /* Listening Quality, not include the effects of delay */
124  CQ /* Conversational Quality, include the effects of delay */
125  };
126 
130  void SetJitterDelay(
131  unsigned delay
132  );
133 
136  void OnPacketReceived();
137 
140  void OnPacketDiscarded();
141 
144  void OnPacketLost();
145 
148  void OnPacketLost(
149  unsigned dropped
150  );
151 
154  void OnRxSenderReport(
155  const PTime & lastTimestamp,
156  const PTimeInterval & delay
157  );
158 
161  unsigned GetLossRate() const;
162 
165  unsigned GetDiscardRate() const;
166 
170  unsigned GetBurstDensity() const;
171 
175  unsigned GetGapDensity() const;
176 
180  unsigned GetBurstDuration() const;
181 
185  unsigned GetGapDuration() const;
186 
190  unsigned GetRoundTripDelay() const;
191 
194  unsigned GetEndSystemDelay() const;
195 
198  unsigned GetRFactor() const;
199 
204  unsigned GetMOS_LQ() const;
205 
210  unsigned GetMOS_CQ() const;
211 
212  // Internal functions
213  void InsertMetricsReport(
214  RTP_ControlFrame & report,
215  const OpalRTPSession & session,
216  RTP_SyncSourceId syncSourceOut,
217  OpalJitterBuffer * jitter
218  );
219 
220 
221  protected:
230  void Markov(
231  PacketEvent event
232  );
233 
236  void ResetCounters();
237 
240  unsigned GetRFactor(
241  QualityType qt
242  ) const;
243 
246  unsigned GetEndOfCallRFactor() const;
247 
251  float GetMOS(
252  QualityType qt
253  ) const;
254 
258  float GetEndOfCallMOS() const;
259 
262  float GetIdFactor() const;
263 
266  float GetPonderateId() const;
267 
270  float GetIeff(
271  PeriodType type
272  ) const;
273 
276  float GetEndOfCallIe() const;
277 
280  float GetPonderateIe() const;
281 
284  TimePeriod CreateTimePeriod(
285  PeriodType type,
286  const PTime & beginTimestamp,
287  const PTime & endTimestamp
288  );
289 
292  IdPeriod CreateIdPeriod(
293  const PTime & beginTimestamp,
294  const PTime & endTimestamp
295  );
296 
299  IePeriod CreateIePeriod(
300  const TimePeriod & timePeriod
301  );
302 
303  /* data associated with the payload */
304  float m_Ie; /* equipment impairment factor for the codec utilized */
305  float m_Bpl; /* robustness factor for the codec utilized */
306  float m_lookAheadTime; /* codec lookahead time */
307  PINDEX m_payloadSize;
308  unsigned m_payloadBitrate;
309 
310  unsigned m_gmin; /* gap threshold */
311  unsigned m_lostInBurst; /* number of lost packets within the current burst */
312  unsigned m_packetsReceived; /* packets received since the beggining of the reception */
313  unsigned m_packetsSinceLastLoss; /* packets received since the last loss or discard event */
314  unsigned m_packetsLost; /* packets lost since the beggining of the reception */
315  unsigned m_packetsDiscarded; /* packets discarded since the beggining of the receptions */
316  unsigned m_srPacketsReceived; /* count of SR packets received */
317 
318  unsigned m_packetsReceivedInGap; /* packets received within gap periods */
319  unsigned m_packetsLostInGap; /* packets lost within gap periods */
320 
321  unsigned m_packetsReceivedInBurst; /* packets received within burst periods */
322  unsigned m_packetsLostInBurst; /* packets lost within burst periods */
323 
333  unsigned c5;
334  unsigned c11;
335  unsigned c13;
336  unsigned c14;
337  unsigned c22;
338  unsigned c23;
339  unsigned c31;
340  unsigned c32;
341  unsigned c33;
342 
343  /* variables to calculate round trip delay */
344  PTime m_lsrTime;
345  PTimeInterval m_dlsrTime;
346  PTime m_arrivalTime;
347 
348  unsigned m_jitterDelay; /* jitter buffer delay, in milliseconds */
349  float m_lastId; /* last Id calculated */
350  float m_lastIe; /* last Ie calculated */
351 
352  std::list<TimePeriod> m_timePeriods;
353  std::list<IePeriod> m_iePeriods;
354  std::list<IdPeriod> m_idPeriods;
355 
356  PeriodType m_currentPeriodType; /* indicates if we are within a gap or burst */
357  PTime m_periodBeginTimestamp; /* timestamp of the beginning of the gap or burst period */
358  PTime m_lastLossTimestamp; /* timestamp of the last loss */
359  PTime m_lastLossInBurstTimestamp; /* timestamp of the last loss within a burst period */
360  PTime m_lastJitterBufferChangeTimestamp; /* timestamp of the last change in jitter buffer size */
361 
362 };
363 
364 
365 #endif // OPAL_RTCP_XR
366 
367 #endif // OPAL_METRICS_H
368 
369 
Definition: rtp.h:540
Definition: jitter.h:51
Definition: rtp_session.h:90
Definition: rtp.h:101
uint32_t RTP_SyncSourceId
Definition: rtp.h:46