SimpleRtp.hpp

00001 #ifndef WINCE 00002 00003 #ifndef _PS_SIMPLERTP_HPP_ 00004 #define _PS_SIMPLERTP_HPP_ 00005 00006 #include "IO.hpp" 00007 #include "ESInfo.hpp" 00008 #include "net/SyncLayer.hpp" 00009 #include "net/PacketizationLayer.hpp" 00010 #include "net/PortGenerator.hpp" 00011 00012 #ifndef WIN32 00013 #include "uclconf.h" //for endian 00014 #endif 00015 #ifdef WINCE 00016 #include "3rdparty/commonucl/rtp.h" // UCL library 00017 #else 00018 #include "commonucl/rtp.h" // UCL library 00019 #endif 00020 00021 class Frame; 00022 class SimpleStatistics; 00023 #include "FastPointerHashTable.hpp" 00024 extern PortGenerator portGen; 00025 00026 class SimpleRtp:public IO { 00027 00028 public: 00029 enum Delay { NO_DELAY,CTS_BASED,BITRATE_BASED,MIXED_CTS_BITRATE,AGGRESSIVE_MIXED_CTS_BITRATE}; 00030 00044 SimpleRtp(const char *url, int remotePort, int localPort, const char *clientaddress, ESInfo * es, 00045 PacketizationLayer * packetization, bool writeOnly, 00046 const char* statsFileName=NULL, bool overwriteExistingStatFile=true, 00047 Delay delay=MIXED_CTS_BITRATE, 00048 bool updateVopTimeIncrement=true, bool enableSwitching=true); 00049 virtual ~ SimpleRtp(); 00051 Frame *getFrame(); 00053 int writeFrame(Frame * frm, ESInfo *out_es=NULL); 00057 bool open(); 00058 bool close(bool immediate=false); 00059 00060 State getState() const { 00061 return state; 00062 }; 00063 int getLocalPort() const { 00064 return localPort; 00065 }; 00068 int getBufferFillLevel() const { 00069 return 50; 00070 }; 00072 bool destroy() { return true;} 00073 /* is this Rtp object for reading from network? (eg. client side) */ 00074 bool isInput() { return !writeOnly; }; 00075 /* is this Rtp object for writing to network? (eg. server side) */ 00076 bool isOutput() { return writeOnly; }; 00077 const char *getURL() const { return url; }; 00078 00081 char *getSSRC(); 00082 00084 void update(); 00085 00086 void setESInfo(ESInfo * es) { this->es=es;}; 00087 00088 virtual ESInfo* getESInfo() { return es;}; 00089 00090 IO::State play(double prefetchTime=0.0); 00091 00092 IO::State pause(); 00097 void preBufferPackets(long millisecs); 00099 bool setToFrameNumber(u32 frameNumber); 00100 const SimpleStatistics* getSimpleStatistics() const { return stats;}; 00101 00102 u32 getctsForFirstPlay() 00103 { 00104 return this->ctsForFirstPlay; 00105 } 00106 00107 protected: 00108 u32 frameToStart; 00109 00110 static void RtpCallback(struct rtp *session, rtp_event * e); 00111 00113 void syncToCts(u32 cts); 00114 00118 void stripHeaderFromFrame(Frame* frm); 00119 long calcSleepTimeInMs(u32 cts); 00120 long calcSleepTimeCTSBased(u32 cts); 00124 long calcSleepTimeBitRateBased(u32 cts, u32 speedScaleFactor=115); 00125 long calcSleepTimeMixedBased(u32 cts,u32 clientPreBufferTime); 00126 long getElapsedTimeInMSSinceLastPlay(); 00127 00128 bool sendPacket(u8 * data, u32 size, u32 rtpTimestamp, bool last); 00129 00130 Frame* extractCompleteFrame(u32 rtpSeqNr); 00131 00132 void insertPacket(AU* p, u32 seqNr); 00133 void removeIncompleteFrame(u32 seqNr); 00134 struct rtp *session; 00135 int clientPort; 00136 int localPort; 00137 char *clientAddress; 00138 00139 #ifndef WIN32 00140 static const int TTL = 16; 00141 static const int MAX_PAYLOAD_SIZE = 65000; 00142 static const int RTP_PAYLOAD_TYPE = 96; 00143 static const int UPDATE_INTERVAL_MS=20; 00144 static const int MINI_PREBUFFER_INTERVALL=500; 00145 static const unsigned int MAX_NULL_FRAMES=10; 00146 #endif 00147 00148 bool writeOnly; 00149 bool firstFrame; 00150 bool packetInsertedDuringLastCallback; 00151 bool firstPacket; 00152 PacketizationLayer *pLayer; 00153 ESInfo *es; 00154 char *url; 00156 struct timeval lastTimeStamp; 00158 u32 ctsForFirstPlay; 00160 u32 lastCTSReturned; 00162 u32 rtpSeqNrStart; 00164 u32 rtpSeqNrEnd; 00166 u32 overflow; 00168 u32 sendPacketCounter; 00170 bool resetPlayTime; 00172 FastPointerHashTable<AU*>* packetBuffer; 00174 VMutex lockPacketBuffer; 00176 long prefetchTimeInMs; 00179 bool updateESInfo; 00181 bool enableSwitching; 00183 u32 nullFrameCounter; 00185 u64 bytesTransferred; 00186 int intermediateMiniSleep; 00187 Delay delayType; 00188 SimpleStatistics *stats; 00189 }; 00190 00191 #endif 00192 00193 00194 #endif //wince