rtpsourcedata.h

Go to the documentation of this file.
00001 /*
00002 
00003   This file is a part of JRTPLIB
00004   Copyright (c) 1999-2007 Jori Liesenborgs
00005 
00006   Contact: jori.liesenborgs@gmail.com
00007 
00008   This library was developed at the "Expertisecentrum Digitale Media"
00009   (http://www.edm.uhasselt.be), a research center of the Hasselt University
00010   (http://www.uhasselt.be). The library is based upon work done for 
00011   my thesis at the School for Knowledge Technology (Belgium/The Netherlands).
00012 
00013   Permission is hereby granted, free of charge, to any person obtaining a
00014   copy of this software and associated documentation files (the "Software"),
00015   to deal in the Software without restriction, including without limitation
00016   the rights to use, copy, modify, merge, publish, distribute, sublicense,
00017   and/or sell copies of the Software, and to permit persons to whom the
00018   Software is furnished to do so, subject to the following conditions:
00019 
00020   The above copyright notice and this permission notice shall be included
00021   in all copies or substantial portions of the Software.
00022 
00023   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00024   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00025   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00026   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00027   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
00028   FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
00029   IN THE SOFTWARE.
00030 
00031 */
00032 
00037 #ifndef RTPSOURCEDATA_H
00038 
00039 #define RTPSOURCEDATA_H
00040 
00041 #include "rtpconfig.h"
00042 #include "rtptimeutilities.h"
00043 #include "rtppacket.h"
00044 #include "rtcpsdesinfo.h"
00045 #include "rtptypes.h"
00046 #include "rtpsources.h"
00047 #include "rtpmemoryobject.h"
00048 #include <list>
00049 
00050 class RTPAddress;
00051 
00052 class RTCPSenderReportInfo
00053 {
00054 public:
00055         RTCPSenderReportInfo():ntptimestamp(0,0),receivetime(0,0)               { hasinfo = false; rtptimestamp = 0; packetcount = 0; bytecount = 0; }
00056         void Set(const RTPNTPTime &ntptime,uint32_t rtptime,uint32_t pcount,
00057                  uint32_t bcount,const RTPTime &rcvtime)                        { ntptimestamp = ntptime; rtptimestamp = rtptime; packetcount = pcount; bytecount = bcount; receivetime = rcvtime; hasinfo = true; }
00058         
00059         bool HasInfo() const                                                    { return hasinfo; }
00060         RTPNTPTime GetNTPTimestamp() const                                      { return ntptimestamp; }
00061         uint32_t GetRTPTimestamp() const                                        { return rtptimestamp; }
00062         uint32_t GetPacketCount() const                                         { return packetcount; }
00063         uint32_t GetByteCount() const                                           { return bytecount; }
00064         RTPTime GetReceiveTime() const                                          { return receivetime; }
00065 private:
00066         bool hasinfo;
00067         RTPNTPTime ntptimestamp;
00068         uint32_t rtptimestamp;
00069         uint32_t packetcount;
00070         uint32_t bytecount;
00071         RTPTime receivetime;
00072 };
00073 
00074 class RTCPReceiverReportInfo
00075 {
00076 public:
00077         RTCPReceiverReportInfo():receivetime(0,0)                               { hasinfo = false; fractionlost = 0; packetslost = 0; exthighseqnr = 0; jitter = 0; lsr = 0; dlsr = 0; } 
00078         void Set(uint8_t fraclost,int32_t plost,uint32_t exthigh,
00079                  uint32_t jit,uint32_t l,uint32_t dl,const RTPTime &rcvtime)    { fractionlost = ((double)fraclost)/256.0; packetslost = plost; exthighseqnr = exthigh; jitter = jit; lsr = l; dlsr = dl; receivetime = rcvtime; hasinfo = true; }
00080                 
00081         bool HasInfo() const                                                    { return hasinfo; }
00082         double GetFractionLost() const                                          { return fractionlost; }
00083         int32_t GetPacketsLost() const                                          { return packetslost; }
00084         uint32_t GetExtendedHighestSequenceNumber() const                       { return exthighseqnr; }
00085         uint32_t GetJitter() const                                              { return jitter; }
00086         uint32_t GetLastSRTimestamp() const                                     { return lsr; }
00087         uint32_t GetDelaySinceLastSR() const                                    { return dlsr; }
00088         RTPTime GetReceiveTime() const                                          { return receivetime; }
00089 private:
00090         bool hasinfo;
00091         double fractionlost;
00092         int32_t packetslost;
00093         uint32_t exthighseqnr;
00094         uint32_t jitter;
00095         uint32_t lsr;
00096         uint32_t dlsr;
00097         RTPTime receivetime;
00098 };
00099 
00100 class RTPSourceStats
00101 {
00102 public:
00103         RTPSourceStats();
00104         void ProcessPacket(RTPPacket *pack,const RTPTime &receivetime,double tsunit,bool ownpacket,bool *accept,bool applyprobation,bool *onprobation);
00105 
00106         bool HasSentData() const                                                { return sentdata; }
00107         uint32_t GetNumPacketsReceived() const                                  { return packetsreceived; }
00108         uint32_t GetBaseSequenceNumber() const                                  { return baseseqnr; }
00109         uint32_t GetExtendedHighestSequenceNumber() const                       { return exthighseqnr; }
00110         uint32_t GetJitter() const                                              { return jitter; }
00111 
00112         int32_t GetNumPacketsReceivedInInterval() const                         { return numnewpackets; }
00113         uint32_t GetSavedExtendedSequenceNumber() const                 { return savedextseqnr; }
00114         void StartNewInterval()                                                 { numnewpackets = 0; savedextseqnr = exthighseqnr; }
00115         
00116         void SetLastMessageTime(const RTPTime &t)                               { lastmsgtime = t; }
00117         RTPTime GetLastMessageTime() const                                      { return lastmsgtime; }
00118         void SetLastRTPPacketTime(const RTPTime &t)                             { lastrtptime = t; }
00119         RTPTime GetLastRTPPacketTime() const                                    { return lastrtptime; }
00120 
00121         void SetLastNoteTime(const RTPTime &t)                                  { lastnotetime = t; }
00122         RTPTime GetLastNoteTime() const                                         { return lastnotetime; }
00123 private:
00124         bool sentdata;
00125         uint32_t packetsreceived;
00126         uint32_t numcycles; // shifted left 16 bits
00127         uint32_t baseseqnr;
00128         uint32_t exthighseqnr,prevexthighseqnr;
00129         uint32_t jitter,prevtimestamp;
00130         double djitter;
00131         RTPTime prevpacktime;
00132         RTPTime lastmsgtime;
00133         RTPTime lastrtptime;
00134         RTPTime lastnotetime;
00135         uint32_t numnewpackets;
00136         uint32_t savedextseqnr;
00137 #ifdef RTP_SUPPORT_PROBATION
00138         uint16_t prevseqnr;
00139         int probation;
00140         RTPSources::ProbationType probationtype;
00141 #endif // RTP_SUPPORT_PROBATION
00142 };
00143         
00144 inline RTPSourceStats::RTPSourceStats():prevpacktime(0,0),lastmsgtime(0,0),lastrtptime(0,0),lastnotetime(0,0)
00145 { 
00146         sentdata = false; 
00147         packetsreceived = 0; 
00148         baseseqnr = 0; 
00149         exthighseqnr = 0; 
00150         prevexthighseqnr = 0; 
00151         jitter = 0; 
00152         numcycles = 0;
00153         numnewpackets = 0;
00154         prevtimestamp = 0;
00155         djitter = 0;
00156         savedextseqnr = 0;
00157 #ifdef RTP_SUPPORT_PROBATION
00158         probation = 0; 
00159         prevseqnr = 0; 
00160 #endif // RTP_SUPPORT_PROBATION
00161 }
00162 
00164 class RTPSourceData : public RTPMemoryObject
00165 {
00166 protected:
00167         RTPSourceData(uint32_t ssrc, RTPMemoryManager *mgr = 0);
00168         virtual ~RTPSourceData();
00169 public:
00171         RTPPacket *GetNextPacket();
00172 
00174         void FlushPackets();
00175 
00177         bool HasData() const                                                    { if (!validated) return false; return packetlist.empty()?false:true; }
00178 
00180         uint32_t GetSSRC() const                                                { return ssrc; }
00181 
00185         bool IsOwnSSRC() const                                                  { return ownssrc; }
00186 
00188         bool IsCSRC() const                                                     { return iscsrc; }
00189 
00191         bool IsSender() const                                                   { return issender; }
00192 
00197         bool IsValidated() const                                                { return validated; }
00198 
00200         bool IsActive() const                                                   { if (!validated) return false; if (receivedbye) return false; return true; }
00201 
00205         void SetProcessedInRTCP(bool v)                                         { processedinrtcp = v; }
00206         
00210         bool IsProcessedInRTCP() const                                          { return processedinrtcp; }
00211         
00215         bool IsRTPAddressSet() const                                            { return isrtpaddrset; }
00216 
00220         bool IsRTCPAddressSet() const                                           { return isrtcpaddrset; }
00221 
00227         const RTPAddress *GetRTPDataAddress() const                             { return rtpaddr; }
00228 
00234         const RTPAddress *GetRTCPDataAddress() const                            { return rtcpaddr; }
00235 
00237         bool ReceivedBYE() const                                                { return receivedbye; }
00238 
00243         uint8_t *GetBYEReason(size_t *len) const                                { *len = byereasonlen; return byereason; }
00244 
00246         RTPTime GetBYETime() const                                              { return byetime; }
00247                 
00254         void SetTimestampUnit(double tsu)                                       { timestampunit = tsu; }
00255 
00257         double GetTimestampUnit() const                                         { return timestampunit; }
00258 
00260         bool SR_HasInfo() const                                                         { return SRinf.HasInfo(); }
00261 
00263         RTPNTPTime SR_GetNTPTimestamp() const                           { return SRinf.GetNTPTimestamp(); }
00264 
00266         uint32_t SR_GetRTPTimestamp() const                                     { return SRinf.GetRTPTimestamp(); }
00267 
00269         uint32_t SR_GetPacketCount() const                                      { return SRinf.GetPacketCount(); }
00270 
00272         uint32_t SR_GetByteCount() const                                        { return SRinf.GetByteCount(); }
00273 
00275         RTPTime SR_GetReceiveTime() const                                       { return SRinf.GetReceiveTime(); }
00276         
00278         bool SR_Prev_HasInfo() const                                            { return SRprevinf.HasInfo(); }
00279 
00281         RTPNTPTime SR_Prev_GetNTPTimestamp() const                              { return SRprevinf.GetNTPTimestamp(); }
00282 
00284         uint32_t SR_Prev_GetRTPTimestamp() const                                { return SRprevinf.GetRTPTimestamp(); }
00285 
00287         uint32_t SR_Prev_GetPacketCount() const                         { return SRprevinf.GetPacketCount(); }
00288 
00290         uint32_t SR_Prev_GetByteCount() const                                   { return SRprevinf.GetByteCount(); }
00291 
00293         RTPTime SR_Prev_GetReceiveTime() const                                  { return SRprevinf.GetReceiveTime(); }
00294 
00296         bool RR_HasInfo() const                                                 { return RRinf.HasInfo(); }
00297 
00299         double RR_GetFractionLost() const                                       { return RRinf.GetFractionLost(); }
00300 
00302         int32_t RR_GetPacketsLost() const                                       { return RRinf.GetPacketsLost(); }
00303 
00305         uint32_t RR_GetExtendedHighestSequenceNumber() const                    { return RRinf.GetExtendedHighestSequenceNumber(); }
00306 
00308         uint32_t RR_GetJitter() const                                           { return RRinf.GetJitter(); }
00309 
00311         uint32_t RR_GetLastSRTimestamp() const                                  { return RRinf.GetLastSRTimestamp(); }
00312 
00314         uint32_t RR_GetDelaySinceLastSR() const                         { return RRinf.GetDelaySinceLastSR(); }
00315 
00317         RTPTime RR_GetReceiveTime() const                                       { return RRinf.GetReceiveTime(); }
00318         
00322         bool RR_Prev_HasInfo() const                                            { return RRprevinf.HasInfo(); }
00323 
00325         double RR_Prev_GetFractionLost() const                                  { return RRprevinf.GetFractionLost(); }
00326 
00328         int32_t RR_Prev_GetPacketsLost() const                                  { return RRprevinf.GetPacketsLost(); }
00329 
00331         uint32_t RR_Prev_GetExtendedHighestSequenceNumber() const               { return RRprevinf.GetExtendedHighestSequenceNumber(); }
00332 
00334         uint32_t RR_Prev_GetJitter() const                                      { return RRprevinf.GetJitter(); }
00335         
00337         uint32_t RR_Prev_GetLastSRTimestamp() const                             { return RRprevinf.GetLastSRTimestamp(); }
00338 
00340         uint32_t RR_Prev_GetDelaySinceLastSR() const                            { return RRprevinf.GetDelaySinceLastSR(); }
00341 
00343         RTPTime RR_Prev_GetReceiveTime() const                                  { return RRprevinf.GetReceiveTime(); }
00344 
00346         bool INF_HasSentData() const                                            { return stats.HasSentData(); }
00347 
00349         int32_t INF_GetNumPacketsReceived() const                               { return stats.GetNumPacketsReceived(); }
00350 
00352         uint32_t INF_GetBaseSequenceNumber() const                              { return stats.GetBaseSequenceNumber(); }
00353 
00355         uint32_t INF_GetExtendedHighestSequenceNumber() const                   { return stats.GetExtendedHighestSequenceNumber(); }
00356 
00358         uint32_t INF_GetJitter() const                                          { return stats.GetJitter(); }
00359 
00361         RTPTime INF_GetLastMessageTime() const                                  { return stats.GetLastMessageTime(); }
00362 
00364         RTPTime INF_GetLastRTPPacketTime() const                                { return stats.GetLastRTPPacketTime(); }
00365 
00367         double INF_GetEstimatedTimestampUnit() const;
00368 
00370         uint32_t INF_GetNumPacketsReceivedInInterval() const                    { return stats.GetNumPacketsReceivedInInterval(); }
00371 
00373         uint32_t INF_GetSavedExtendedSequenceNumber() const                     { return stats.GetSavedExtendedSequenceNumber(); }
00374 
00378         void INF_StartNewInterval()                                             { stats.StartNewInterval(); }
00379 
00381         RTPTime INF_GetRoundtripTime() const;
00382 
00384         RTPTime INF_GetLastSDESNoteTime() const                                 { return stats.GetLastNoteTime(); }
00385         
00387         uint8_t *SDES_GetCNAME(size_t *len) const                               { return SDESinf.GetCNAME(len); }
00388 
00390         uint8_t *SDES_GetName(size_t *len) const                                { return SDESinf.GetName(len); }
00391 
00393         uint8_t *SDES_GetEMail(size_t *len) const                               { return SDESinf.GetEMail(len); }
00394 
00396         uint8_t *SDES_GetPhone(size_t *len) const                               { return SDESinf.GetPhone(len); }
00397 
00399         uint8_t *SDES_GetLocation(size_t *len) const                    { return SDESinf.GetLocation(len); }
00400 
00402         uint8_t *SDES_GetTool(size_t *len) const                                { return SDESinf.GetTool(len); }
00403 
00405         uint8_t *SDES_GetNote(size_t *len) const                                { return SDESinf.GetNote(len); }
00406         
00407 #ifdef RTP_SUPPORT_SDESPRIV
00408 
00409         void SDES_GotoFirstPrivateValue()                                                                               { SDESinf.GotoFirstPrivateValue(); }
00410         
00414         bool SDES_GetNextPrivateValue(uint8_t **prefix,size_t *prefixlen,uint8_t **value,size_t *valuelen)              { return SDESinf.GetNextPrivateValue(prefix,prefixlen,value,valuelen); }
00415 
00420         bool SDES_GetPrivateValue(uint8_t *prefix,size_t prefixlen,uint8_t **value,size_t *valuelen) const              { return SDESinf.GetPrivateValue(prefix,prefixlen,value,valuelen); }
00421 #endif // RTP_SUPPORT_SDESPRIV
00422 
00423 #ifdef RTPDEBUG
00424         virtual void Dump();
00425 #endif // RTPDEBUG
00426 protected:
00427         std::list<RTPPacket *> packetlist;
00428 
00429         uint32_t ssrc;
00430         bool ownssrc;
00431         bool iscsrc;
00432         double timestampunit;
00433         bool receivedbye;
00434         bool validated;
00435         bool processedinrtcp;
00436         bool issender;
00437         
00438         RTCPSenderReportInfo SRinf,SRprevinf;
00439         RTCPReceiverReportInfo RRinf,RRprevinf;
00440         RTPSourceStats stats;
00441         RTCPSDESInfo SDESinf;
00442         
00443         bool isrtpaddrset,isrtcpaddrset;
00444         RTPAddress *rtpaddr,*rtcpaddr;
00445         
00446         RTPTime byetime;
00447         uint8_t *byereason;
00448         size_t byereasonlen;
00449 };
00450 
00451 inline RTPPacket *RTPSourceData::GetNextPacket()
00452 {
00453         if (!validated)
00454                 return 0;
00455 
00456         RTPPacket *p;
00457 
00458         if (packetlist.empty())
00459                 return 0;
00460         p = *(packetlist.begin());
00461         packetlist.pop_front();
00462         return p;
00463 }
00464 
00465 inline void RTPSourceData::FlushPackets()
00466 {
00467         std::list<RTPPacket *>::const_iterator it;
00468 
00469         for (it = packetlist.begin() ; it != packetlist.end() ; ++it)
00470                 RTPDelete(*it,GetMemoryManager());
00471         packetlist.clear();
00472 }
00473 #endif // RTPSOURCEDATA_H
00474 

Generated on Thu Feb 8 16:22:05 2007 for jrtplib by  doxygen 1.5.1