# 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: 27699 $
    00023  * $Author: rjongbloed $
    00024  * $Date: 2012-05-24 20:35:37 -0500 (Thu, 24 May 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.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
    00052 {
    00053   protected:
    00054     RTCP_XR_Metrics(
    00055       float    Ie,
    00056       float    Bpl,
    00057       float    lookAheadTime,
    00058       PINDEX   payloadSize,
    00059       unsigned payloadBitrate
    00060     );
    00061
    00062   public:
    00063     static RTCP_XR_Metrics * Create(const RTP_DataFrame & frame);
    00064
    00065     ~RTCP_XR_Metrics();
    00066
    00067     enum PacketEvent {
    00068       PACKET_RECEIVED,
    00069       PACKET_DISCARDED,
    00070       PACKET_LOST
    00071     };
    00072
    00073     enum PeriodType {
    00074       GAP,     /* a period of low packet losses and/or discards */
    00075       BURST,   /* a period of a high proportion of packet losses and/or discards */
    00076     };
    00077
    00078     /* A period of time, which can be a burst or a gap */
    00079     typedef struct TimePeriod {
    00080       PeriodType      type;
    00081       PTimeInterval   duration;
    00082     } TimePeriod;
    00083
    00087     typedef struct IdPeriod {
    00088       PTimeInterval duration;
    00089       float         Id;
    00090     } IdPeriod;
    00091
    00095     typedef struct IePeriod {
    00096       PeriodType    type;
    00097       PTimeInterval duration;
    00098       float         Ieff;
    00099     } IePeriod;
    00100
    00101     enum QualityType {
    00102       LQ,  /* Listening Quality, not include the effects of delay */
    00103       CQ   /* Conversational Quality, include the effects of delay */
    00104     };
    00105
    00109     void SetJitterDelay(
    00110       DWORD delay
    00111     );
    00112
    00115     void OnPacketReceived();
    00116
    00119     void OnPacketDiscarded();
    00120
    00123     void OnPacketLost();
    00124
    00127     void OnPacketLost(
    00128       DWORD dropped
    00129     );
    00130
    00133     void OnRxSenderReport(
    00134       PUInt32b lsr,
    00135       PUInt32b dlsr
    00136     );
    00137
    00140     BYTE GetLossRate();
    00141
    00144     BYTE GetDiscardRate();
    00145
    00149     BYTE GetBurstDensity();
    00150
    00154     BYTE GetGapDensity();
    00155
    00159     PUInt16b GetBurstDuration();
    00160
    00164     PUInt16b GetGapDuration();
    00165
    00169     PUInt16b GetRoundTripDelay ();
    00170
    00173     PUInt16b GetEndSystemDelay();
    00174
    00177     BYTE RFactor();
    00178
    00183     BYTE MOS_LQ();
    00184
    00189     BYTE MOS_CQ();
    00190
    00191     // Internal functions
    00192     void InsertExtendedReportPacket(
    00193       unsigned sessionID,
    00194       DWORD syncSourceOut,
    00195       RTP_Session::JitterBufferPtr jitter, // Note do not make JitterBufferPtr a reference, needs to be a copy
    00196       RTP_ControlFrame & report
    00197     );
    00198
    00199     static RTP_Session::ExtendedReportArray
    00200     BuildExtendedReportArray(const RTP_ControlFrame & frame, PINDEX offset);
    00201
    00202
    00203   protected:
    00212     void markov(
    00213       PacketEvent event
    00214     );
    00215
    00218     void ResetCounters();
    00219
    00222     BYTE RFactor(
    00223       QualityType qt
    00224     );
    00225
    00228     BYTE EndOfCallRFactor();
    00229
    00233     float MOS(
    00234       QualityType qt
    00235     );
    00236
    00240     float EndOfCallMOS();
    00241
    00244     float IdFactor();
    00245
    00248     float GetPonderateId();
    00249
    00252     float Ieff(
    00253       PeriodType type
    00254     );
    00255
    00258     float GetEndOfCallIe();
    00259
    00262     float GetPonderateIe();
    00263
    00266     TimePeriod createTimePeriod(
    00267       PeriodType type,
    00268       PTime beginTimestamp,
    00269       PTime endTimestamp
    00270     );
    00271
    00274     IdPeriod createIdPeriod(
    00275       PTime beginTimestamp,
    00276       PTime endTimestamp
    00277     );
    00278
    00281     IePeriod createIePeriod(
    00282       TimePeriod timePeriod
    00283     );
    00284
    00285     /* data associated with the payload */
    00286     float    m_Ie;              /* equipment impairment factor for the codec utilized */
    00287     float    m_Bpl;             /* robustness factor for the codec utilized */
    00288     float    m_lookAheadTime;   /* codec lookahead time */
    00289     PINDEX   m_payloadSize;
    00290     unsigned m_payloadBitrate;
    00291
    00292     DWORD m_gmin;                    /* gap threshold */
    00293     DWORD m_lostInBurst;             /* number of lost packets within the current burst */
    00294     DWORD m_packetsReceived;         /* packets received since the beggining of the reception */
    00295     DWORD m_packetsSinceLastLoss;    /* packets received since the last loss or discard event */
    00296     DWORD m_packetsLost;             /* packets lost since the beggining of the reception */
    00297     DWORD m_packetsDiscarded;        /* packets discarded since the beggining of the receptions */
    00298     DWORD m_srPacketsReceived;       /* count of SR packets received */
    00299
    00300     DWORD m_packetsReceivedInGap;    /* packets received within gap periods */
    00301     DWORD m_packetsLostInGap;        /* packets lost within gap periods */
    00302
    00303     DWORD m_packetsReceivedInBurst;  /* packets received within burst periods */
    00304     DWORD m_packetsLostInBurst;      /* packets lost within burst periods */
    00305
    00315     DWORD c5;
    00316     DWORD c11;
    00317     DWORD c13;
    00318     DWORD c14;
    00319     DWORD c22;
    00320     DWORD c23;
    00321     DWORD c31;
    00322     DWORD c32;
    00323     DWORD c33;
    00324
    00325     /* variables to calculate round trip delay */
    00326     PTime         m_lsrTime;
    00327     PTimeInterval m_dlsrTime;
    00328     PTime         m_arrivalTime;
    00329
    00330     DWORD m_jitterDelay;  /* jitter buffer delay, in milliseconds */
    00331     float m_lastId;       /* last Id calculated */
    00332     float m_lastIe;       /* last Ie calculated */
    00333
    00334     std::list<TimePeriod> m_timePeriods;
    00335     std::list<IePeriod>   m_iePeriods;
    00336     std::list<IdPeriod>   m_idPeriods;
    00337
    00338     PeriodType m_currentPeriodType;           /* indicates if we are within a gap or burst */
    00339     PTime m_periodBeginTimestamp;             /* timestamp of the beginning of the gap or burst period */
    00340     PTime m_lastLossTimestamp;                /* timestamp of the last loss */
    00341     PTime m_lastLossInBurstTimestamp;         /* timestamp of the last loss within a burst period */
    00342     PTime m_lastJitterBufferChangeTimestamp;  /* timestamp of the last change in jitter buffer size */
    00343
    00344 };
    00345
    00346
    00347 #endif // OPAL_RTCP_XR
    00348
    00349 #endif // OPAL_METRICS_H
    00350
    00351