# metrics.h

Go to the documentation of this file.

    00001 /*
    00002  * metrics.h
    00003  *
    00004  * E-Model implementation
    00005  *
    00006  * Open Phone Abstraction Library (OPAL)
    00007  *
    00008  * Copyright (c) 2010 Universidade Federal do Amazonas
    00009  *
    00010  * The contents of this file are subject to the Mozilla Public License
    00011  * Version 1.0 (the "License"); you may not use this file except in
    00012  * compliance with the License. You may obtain a copy of the License at
    00013  * http://www.mozilla.org/MPL/
    00014  *
    00015  * Software distributed under the License is distributed on an "AS IS"
    00016  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
    00017  * the License for the specific language governing rights and limitations
    00018  * under the License.
    00019  *
    00020  * Contributor(s): ______________________________________.
    00021  *
    00022  * $Revision: 28016 $
    00023  * $Author: rjongbloed $
    00024  * $Date: 2012-07-12 23:07:31 -0500 (Thu, 12 Jul 2012) $
    00025  */
    00026
    00027 #ifndef OPAL_RTP_METRICS_H
    00028 #define OPAL_RTP_METRICS_H
    00029
    00030 #ifdef P_USE_PRAGMA
    00031 #pragma interface
    00032 #endif
    00033
    00034 #include <opal/buildopts.h>
    00035
    00036 #if OPAL_RTCP_XR
    00037
    00038 #include <rtp/rtp_session.h>
    00039
    00040 #include <list>
    00041
    00042 class RTP_Session;
    00043 class RTP_DataFrame;
    00044
    00046 // RTCP-XR - VoIP Metrics Report Block
    00047
    00051 class RTCP_XR_Metrics : public PObject
    00052 {
    00053     PCLASSINFO(RTCP_XR_Metrics, PObject);
    00054   protected:
    00055     RTCP_XR_Metrics(
    00056       float    Ie,
    00057       float    Bpl,
    00058       float    lookAheadTime,
    00059       PINDEX   payloadSize,
    00060       unsigned payloadBitrate
    00061     );
    00062
    00063   public:
    00064     static RTCP_XR_Metrics * Create(const RTP_DataFrame & frame);
    00065
    00066     ~RTCP_XR_Metrics();
    00067
    00068     enum PacketEvent {
    00069       PACKET_RECEIVED,
    00070       PACKET_DISCARDED,
    00071       PACKET_LOST
    00072     };
    00073
    00074     enum PeriodType {
    00075       GAP,     /* a period of low packet losses and/or discards */
    00076       BURST,   /* a period of a high proportion of packet losses and/or discards */
    00077     };
    00078
    00079     /* A period of time, which can be a burst or a gap */
    00080     typedef struct TimePeriod {
    00081       PeriodType      type;
    00082       PTimeInterval   duration;
    00083     } TimePeriod;
    00084
    00088     typedef struct IdPeriod {
    00089       PTimeInterval duration;
    00090       float         Id;
    00091     } IdPeriod;
    00092
    00096     typedef struct IePeriod {
    00097       PeriodType    type;
    00098       PTimeInterval duration;
    00099       float         Ieff;
    00100     } IePeriod;
    00101
    00102     enum QualityType {
    00103       LQ,  /* Listening Quality, not include the effects of delay */
    00104       CQ   /* Conversational Quality, include the effects of delay */
    00105     };
    00106
    00110     void SetJitterDelay(
    00111       DWORD delay
    00112     );
    00113
    00116     void OnPacketReceived();
    00117
    00120     void OnPacketDiscarded();
    00121
    00124     void OnPacketLost();
    00125
    00128     void OnPacketLost(
    00129       DWORD dropped
    00130     );
    00131
    00134     void OnRxSenderReport(
    00135       PUInt32b lsr,
    00136       PUInt32b dlsr
    00137     );
    00138
    00141     BYTE GetLossRate();
    00142
    00145     BYTE GetDiscardRate();
    00146
    00150     BYTE GetBurstDensity();
    00151
    00155     BYTE GetGapDensity();
    00156
    00160     PUInt16b GetBurstDuration();
    00161
    00165     PUInt16b GetGapDuration();
    00166
    00170     PUInt16b GetRoundTripDelay ();
    00171
    00174     PUInt16b GetEndSystemDelay();
    00175
    00178     BYTE RFactor();
    00179
    00184     BYTE MOS_LQ();
    00185
    00190     BYTE MOS_CQ();
    00191
    00192     // Internal functions
    00193     void InsertExtendedReportPacket(
    00194       unsigned sessionID,
    00195       DWORD syncSourceOut,
    00196       OpalRTPSession::JitterBufferPtr jitter, // Note do not make JitterBufferPtr a reference, needs to be a copy
    00197       RTP_ControlFrame & report
    00198     );
    00199
    00200     static OpalRTPSession::ExtendedReportArray
    00201     BuildExtendedReportArray(const RTP_ControlFrame & frame, PINDEX offset);
    00202
    00203
    00204   protected:
    00213     void markov(
    00214       PacketEvent event
    00215     );
    00216
    00219     void ResetCounters();
    00220
    00223     BYTE RFactor(
    00224       QualityType qt
    00225     );
    00226
    00229     BYTE EndOfCallRFactor();
    00230
    00234     float MOS(
    00235       QualityType qt
    00236     );
    00237
    00241     float EndOfCallMOS();
    00242
    00245     float IdFactor();
    00246
    00249     float GetPonderateId();
    00250
    00253     float Ieff(
    00254       PeriodType type
    00255     );
    00256
    00259     float GetEndOfCallIe();
    00260
    00263     float GetPonderateIe();
    00264
    00267     TimePeriod createTimePeriod(
    00268       PeriodType type,
    00269       PTime beginTimestamp,
    00270       PTime endTimestamp
    00271     );
    00272
    00275     IdPeriod createIdPeriod(
    00276       PTime beginTimestamp,
    00277       PTime endTimestamp
    00278     );
    00279
    00282     IePeriod createIePeriod(
    00283       TimePeriod timePeriod
    00284     );
    00285
    00286     /* data associated with the payload */
    00287     float    m_Ie;              /* equipment impairment factor for the codec utilized */
    00288     float    m_Bpl;             /* robustness factor for the codec utilized */
    00289     float    m_lookAheadTime;   /* codec lookahead time */
    00290     PINDEX   m_payloadSize;
    00291     unsigned m_payloadBitrate;
    00292
    00293     DWORD m_gmin;                    /* gap threshold */
    00294     DWORD m_lostInBurst;             /* number of lost packets within the current burst */
    00295     DWORD m_packetsReceived;         /* packets received since the beggining of the reception */
    00296     DWORD m_packetsSinceLastLoss;    /* packets received since the last loss or discard event */
    00297     DWORD m_packetsLost;             /* packets lost since the beggining of the reception */
    00298     DWORD m_packetsDiscarded;        /* packets discarded since the beggining of the receptions */
    00299     DWORD m_srPacketsReceived;       /* count of SR packets received */
    00300
    00301     DWORD m_packetsReceivedInGap;    /* packets received within gap periods */
    00302     DWORD m_packetsLostInGap;        /* packets lost within gap periods */
    00303
    00304     DWORD m_packetsReceivedInBurst;  /* packets received within burst periods */
    00305     DWORD m_packetsLostInBurst;      /* packets lost within burst periods */
    00306
    00316     DWORD c5;
    00317     DWORD c11;
    00318     DWORD c13;
    00319     DWORD c14;
    00320     DWORD c22;
    00321     DWORD c23;
    00322     DWORD c31;
    00323     DWORD c32;
    00324     DWORD c33;
    00325
    00326     /* variables to calculate round trip delay */
    00327     PTime         m_lsrTime;
    00328     PTimeInterval m_dlsrTime;
    00329     PTime         m_arrivalTime;
    00330
    00331     DWORD m_jitterDelay;  /* jitter buffer delay, in milliseconds */
    00332     float m_lastId;       /* last Id calculated */
    00333     float m_lastIe;       /* last Ie calculated */
    00334
    00335     std::list<TimePeriod> m_timePeriods;
    00336     std::list<IePeriod>   m_iePeriods;
    00337     std::list<IdPeriod>   m_idPeriods;
    00338
    00339     PeriodType m_currentPeriodType;           /* indicates if we are within a gap or burst */
    00340     PTime m_periodBeginTimestamp;             /* timestamp of the beginning of the gap or burst period */
    00341     PTime m_lastLossTimestamp;                /* timestamp of the last loss */
    00342     PTime m_lastLossInBurstTimestamp;         /* timestamp of the last loss within a burst period */
    00343     PTime m_lastJitterBufferChangeTimestamp;  /* timestamp of the last change in jitter buffer size */
    00344
    00345 };
    00346
    00347
    00348 #endif // OPAL_RTCP_XR
    00349
    00350 #endif // OPAL_METRICS_H
    00351
    00352