RTP Audio System  2.0.0
seqnumvalidator.h
Go to the documentation of this file.
00001 // ##########################################################################
00002 // ####                                                                  ####
00003 // ####                      RTP Audio Server Project                    ####
00004 // ####                    ============================                  ####
00005 // ####                                                                  ####
00006 // #### Sequence Number Validator                                        ####
00007 // ####                                                                  ####
00008 // ####           Copyright (C) 1999-2012 by Thomas Dreibholz            ####
00009 // ####                                                                  ####
00010 // #### Contact:                                                         ####
00011 // ####    EMail: dreibh@iem.uni-due.de                                  ####
00012 // ####    WWW:   https://www.nntb.no/~dreibh/rtpaudio                ####
00013 // ####                                                                  ####
00014 // #### ---------------------------------------------------------------- ####
00015 // ####                                                                  ####
00016 // #### This program is free software: you can redistribute it and/or    ####
00017 // #### modify it under the terms of the GNU General Public License as   ####
00018 // #### published by the Free Software Foundation, either version 3 of   ####
00019 // #### the License, or (at your option) any later version.              ####
00020 // ####                                                                  ####
00021 // #### This program is distributed in the hope that it will be useful,  ####
00022 // #### but WITHOUT ANY WARRANTY; without even the implied warranty of   ####
00023 // #### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    ####
00024 // #### GNU General Public License for more details.                     ####
00025 // ####                                                                  ####
00026 // #### You should have received a copy of the GNU General Public        ####
00027 // #### License along with this program.  If not, see                    ####
00028 // #### <http://www.gnu.org/licenses/>.                                  ####
00029 // ####                                                                  ####
00030 // ##########################################################################
00031 // $Id: seqnumvalidator.h 1286 2011-12-18 13:43:16Z dreibh $
00032 
00033 
00034 #ifndef SEQNUMVALIDATOR_H
00035 #define SEQNUMVALIDATOR_H
00036 
00037 
00038 #include "tdsystem.h"
00039 
00040 
00050 class SeqNumValidator
00051 {
00052    // ====== Constructor ====================================================
00053    public:
00062    SeqNumValidator(const cardinal minSequential = 2,
00063                    const cardinal maxMisorder   = 100,
00064                    const cardinal maxDropout    = 3000,
00065                    const card64   seqMod        = (1 << 16));
00066 
00067 
00068    // ====== Status functions ===============================================
00074    inline card64 getPacketsReceived() const;
00075 
00082    inline card64 getPacketsLost() const;
00083 
00090    inline card64 getLastSeqNum() const;
00091 
00101    inline double getFractionLost() const;
00102 
00108    inline double getJitter() const;
00109 
00110 
00111    // ====== Sequence number validation =====================================
00112    enum ValidationResult {
00113       Valid           = 0,
00114       SourceProbation = 1,
00115       Jumped          = 2,
00116       Invalid         = 10,
00117       DuplicatePacket = Invalid + 0,
00118       InvalidSeqNum   = Invalid + 1
00119    };
00129    ValidationResult validate(const card64 sequenceNumber,
00130                              const card32 packetTimeStamp = 0);
00131 
00135    void reset();
00136 
00142    double calculateFractionLost();
00143 
00144 
00145    // ====== Private data ===================================================
00146    private:
00147    inline void init(const card64 sequenceNumber);
00148 
00149 
00150    card64   SeqMod;                // Constants.
00151    cardinal MaxDropout;
00152    cardinal MaxMisorder;
00153    cardinal MinSequential;
00154 
00155    card64   PrevPacketTimeStamp;   // Time stamp of previous packet.
00156    card64   PrevPacketArrivalTime; // Arrival time of previous packet.
00157    double   Jitter;                // Estimated jitter.
00158    double   FractionLost;          // Fraction lost.
00159 
00160    card64   MaxSeq;                // Highest seq. number seen.
00161    card64   BaseSeq;               // Base seq. number.
00162    card64   BadSeq;                // Last 'bad' seq. number + 1.
00163    card32   Probation;             // Sequential packets till source is valid.
00164 
00165    card64   Cycles;                // Shifted count of seq. number cycles.
00166    card64   Received;              // Packets received.
00167    card64   ReceivedPrior;         // Packet received at last interval.
00168    card64   ExpectedPrior;         // Packet expected at last interval.
00169 
00170    bool     Uninitialized;         // Waiting for the first valid seq. number.
00171 };
00172 
00173 
00174 #include "seqnumvalidator.icc"
00175 
00176 
00177 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines