EMIPLIB

miprtpmessage.h

Go to the documentation of this file.
00001 /*
00002     
00003   This file is a part of EMIPLIB, the EDM Media over IP Library.
00004   
00005   Copyright (C) 2006-2011  Hasselt University - Expertise Centre for
00006                       Digital Media (EDM) (http://www.edm.uhasselt.be)
00007 
00008   This library is free software; you can redistribute it and/or
00009   modify it under the terms of the GNU Lesser General Public
00010   License as published by the Free Software Foundation; either
00011   version 2.1 of the License, or (at your option) any later version.
00012 
00013   This library is distributed in the hope that it will be useful,
00014   but WITHOUT ANY WARRANTY; without even the implied warranty of
00015   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016   Lesser General Public License for more details.
00017 
00018   You should have received a copy of the GNU Lesser General Public
00019   License along with this library; if not, write to the Free Software
00020   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  
00021   USA
00022 
00023 */
00024 
00029 #ifndef MIPRTPMESSAGE_H
00030 
00031 #define MIPRTPMESSAGE_H
00032 
00033 #include "mipconfig.h"
00034 #include "mipmessage.h"
00035 #include "miptime.h"
00036 #include <jrtplib3/rtpsession.h>
00037 #include <jrtplib3/rtppacket.h>
00038 #include <string.h>
00039 
00047 #define MIPRTPMESSAGE_TYPE_SEND                                                                         0x00000001
00048 #define MIPRTPMESSAGE_TYPE_RECEIVE                                                                      0x00000002
00049 
00054 class EMIPLIB_IMPORTEXPORT MIPRTPSendMessage : public MIPMessage
00055 {
00056 public:
00067         MIPRTPSendMessage(uint8_t *pData, size_t dataLength, uint8_t payloadType, bool marker,
00068                           uint32_t tsInc, bool deleteData = true) : MIPMessage(MIPMESSAGE_TYPE_RTP, MIPRTPMESSAGE_TYPE_SEND)
00069                                                                                                         { m_pData = pData; m_dataLength = dataLength; m_payloadType = payloadType; m_marker = marker; m_tsInc = tsInc; m_deleteData = deleteData; }
00070         ~MIPRTPSendMessage()                                                                            { if (m_deleteData) delete [] m_pData; }
00071 
00073         const uint8_t *getPayload() const                                                               { return m_pData; }
00074 
00076         size_t getPayloadLength() const                                                                 { return m_dataLength; }
00077 
00079         uint8_t getPayloadType() const                                                                  { return m_payloadType; }
00080 
00082         bool getMarker() const                                                                          { return m_marker; }
00083 
00085         uint32_t getTimestampIncrement() const                                                          { return m_tsInc; }
00086 
00088         void setSamplingInstant(MIPTime t)                                                              { m_samplingInstant = t; }
00089 
00091         MIPTime getSamplingInstant() const                                                              { return m_samplingInstant; }
00092 private:
00093         uint8_t *m_pData;
00094         size_t m_dataLength;
00095         uint8_t m_payloadType;
00096         bool m_marker;
00097         uint32_t m_tsInc;
00098         bool m_deleteData;
00099         MIPTime m_samplingInstant;
00100 };
00101 
00102 #define MIPRTPMESSAGE_MAXCNAMELENGTH                                                                    256     
00103 
00108 class EMIPLIB_IMPORTEXPORT MIPRTPReceiveMessage : public MIPMessage
00109 {
00110 public:
00124         MIPRTPReceiveMessage(jrtplib::RTPPacket *pPack, const uint8_t *pCName, size_t cnameLength, bool deletePacket = true, jrtplib::RTPSession *pSess = 0) : MIPMessage(MIPMESSAGE_TYPE_RTP, MIPRTPMESSAGE_TYPE_RECEIVE), m_jitter(0)
00125                                                                                                         { m_deletePacket = deletePacket; m_pPack = pPack; if (cnameLength > MIPRTPMESSAGE_MAXCNAMELENGTH) m_cnameLength = MIPRTPMESSAGE_MAXCNAMELENGTH; else m_cnameLength = cnameLength; if (cnameLength > 0) memcpy(m_cname,pCName,m_cnameLength); m_tsUnit = -1; m_tsUnitEstimate = -1; m_timingInfoSet = false; m_sourceID = 0; m_pSession = pSess; }
00126         ~MIPRTPReceiveMessage()                                                                         { if (m_deletePacket) { if (m_pSession) m_pSession->DeletePacket(m_pPack); else delete m_pPack; } }
00127 
00129         const jrtplib::RTPPacket *getPacket() const                                                     { return m_pPack; }
00130 
00132         const uint8_t *getCName() const                                                                 { return m_cname; }
00133 
00135         size_t getCNameLength() const                                                                   { return m_cnameLength; }
00136 
00138         MIPTime getJitter() const                                                                       { return m_jitter; }
00139 
00141         void setJitter(MIPTime t)                                                                       { m_jitter = t; }
00142 
00144         real_t getTimestampUnit() const                                                                 { return m_tsUnit; }
00145 
00147         void setTimestampUnit(real_t unit)                                                              { m_tsUnit = unit; }
00148 
00150         real_t getTimestampUnitEstimate() const                                                         { return m_tsUnitEstimate; }
00151 
00153         void setTimestampUnitEstimate(real_t unit)                                                      { m_tsUnitEstimate = unit; }
00154 
00156         bool isTimingInfoSet() const                                                                    { return m_timingInfoSet; }
00157 
00159         void setTimingInfo(MIPTime t, uint32_t timestamp)                                               { m_timingInfWallclock = t; m_timingInfTimestamp = timestamp; m_timingInfoSet = true; }
00160         
00162         bool getTimingInfo(MIPTime *t, uint32_t *timestamp) const                                       { if (!m_timingInfoSet) return false; *t = m_timingInfWallclock; *timestamp = m_timingInfTimestamp; return true; }
00163 
00165         void setSourceID(uint64_t sourceID)                                                             { m_sourceID = sourceID; }
00166         
00168         uint64_t getSourceID() const                                                                    { return m_sourceID; }
00169 private:
00170         jrtplib::RTPPacket *m_pPack;
00171         jrtplib::RTPSession *m_pSession;
00172         uint8_t m_cname[MIPRTPMESSAGE_MAXCNAMELENGTH];
00173         size_t m_cnameLength;
00174         bool m_deletePacket;
00175         MIPTime m_jitter;
00176         real_t m_tsUnit, m_tsUnitEstimate;
00177         bool m_timingInfoSet;
00178         MIPTime m_timingInfWallclock;
00179         uint32_t m_timingInfTimestamp;
00180         uint64_t m_sourceID;
00181 };
00182 
00183 #endif // MIPRTPMESSAGE_H
00184