00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #ifndef OPAL_RTP_RTP_H
00035 #define OPAL_RTP_RTP_H
00036
00037 #ifdef P_USE_PRAGMA
00038 #pragma interface
00039 #endif
00040
00041 #include <opal/buildopts.h>
00042
00043 #include <ptlib/sockets.h>
00044 #include <ptlib/safecoll.h>
00045
00046
00047 class RTP_JitterBuffer;
00048 class PNatMethod;
00049 class OpalSecurityMode;
00050
00052
00053
00054
00055 class RTP_QOS : public PObject
00056 {
00057 PCLASSINFO(RTP_QOS,PObject);
00058 public:
00059 PQoS dataQoS;
00060 PQoS ctrlQoS;
00061 };
00062
00064
00065
00068 class RTP_DataFrame : public PBYTEArray
00069 {
00070 PCLASSINFO(RTP_DataFrame, PBYTEArray);
00071
00072 public:
00073 RTP_DataFrame(PINDEX payloadSize = 0, PINDEX bufferSize = 0);
00074 RTP_DataFrame(const BYTE * data, PINDEX len, PBoolean dynamic = PTrue);
00075
00076 enum {
00077 ProtocolVersion = 2,
00078 MinHeaderSize = 12,
00079
00080 MaxMtuPayloadSize = (576-20-16-12)
00081 };
00082
00083 enum PayloadTypes {
00084 PCMU,
00085 FS1016,
00086 G721,
00087 G726 = G721,
00088 GSM,
00089 G7231,
00090 DVI4_8k,
00091 DVI4_16k,
00092 LPC,
00093 PCMA,
00094 G722,
00095 L16_Stereo,
00096 L16_Mono,
00097 G723,
00098 CN,
00099 MPA,
00100 G728,
00101 DVI4_11k,
00102 DVI4_22k,
00103 G729,
00104 Cisco_CN,
00105
00106 CelB = 25,
00107 JPEG,
00108 H261 = 31,
00109 MPV,
00110 MP2T,
00111 H263,
00112
00113 LastKnownPayloadType,
00114
00115 DynamicBase = 96,
00116 MaxPayloadType = 127,
00117 IllegalPayloadType
00118 };
00119
00120 unsigned GetVersion() const { return (theArray[0]>>6)&3; }
00121
00122 PBoolean GetExtension() const { return (theArray[0]&0x10) != 0; }
00123 void SetExtension(PBoolean ext);
00124
00125 PBoolean GetMarker() const { return (theArray[1]&0x80) != 0; }
00126 void SetMarker(PBoolean m);
00127
00128 bool GetPadding() const { return (theArray[0]&0x20) != 0; }
00129 void SetPadding(bool v) { if (v) theArray[0] |= 0x20; else theArray[0] &= 0xdf; }
00130
00131 unsigned GetPaddingSize() const;
00132
00133 PayloadTypes GetPayloadType() const { return (PayloadTypes)(theArray[1]&0x7f); }
00134 void SetPayloadType(PayloadTypes t);
00135
00136 WORD GetSequenceNumber() const { return *(PUInt16b *)&theArray[2]; }
00137 void SetSequenceNumber(WORD n) { *(PUInt16b *)&theArray[2] = n; }
00138
00139 DWORD GetTimestamp() const { return *(PUInt32b *)&theArray[4]; }
00140 void SetTimestamp(DWORD t) { *(PUInt32b *)&theArray[4] = t; }
00141
00142 DWORD GetSyncSource() const { return *(PUInt32b *)&theArray[8]; }
00143 void SetSyncSource(DWORD s) { *(PUInt32b *)&theArray[8] = s; }
00144
00145 PINDEX GetContribSrcCount() const { return theArray[0]&0xf; }
00146 DWORD GetContribSource(PINDEX idx) const;
00147 void SetContribSource(PINDEX idx, DWORD src);
00148
00149 PINDEX GetHeaderSize() const;
00150
00151 int GetExtensionType() const;
00152 void SetExtensionType(int type);
00153 PINDEX GetExtensionSize() const;
00154 PBoolean SetExtensionSize(PINDEX sz);
00155 BYTE * GetExtensionPtr() const;
00156
00157 PINDEX GetPayloadSize() const { return payloadSize - GetPaddingSize(); }
00158 PBoolean SetPayloadSize(PINDEX sz);
00159 BYTE * GetPayloadPtr() const { return (BYTE *)(theArray+GetHeaderSize()); }
00160
00161 virtual void PrintOn(ostream & strm) const;
00162
00163 protected:
00164 PINDEX payloadSize;
00165
00166 #if PTRACING
00167 friend ostream & operator<<(ostream & o, PayloadTypes t);
00168 #endif
00169 };
00170
00171 PLIST(RTP_DataFrameList, RTP_DataFrame);
00172
00173
00176 class RTP_ControlFrame : public PBYTEArray
00177 {
00178 PCLASSINFO(RTP_ControlFrame, PBYTEArray);
00179
00180 public:
00181 RTP_ControlFrame(PINDEX compoundSize = 2048);
00182
00183 unsigned GetVersion() const { return (BYTE)theArray[compoundOffset]>>6; }
00184
00185 unsigned GetCount() const { return (BYTE)theArray[compoundOffset]&0x1f; }
00186 void SetCount(unsigned count);
00187
00188 enum PayloadTypes {
00189 e_IntraFrameRequest = 192,
00190 e_SenderReport = 200,
00191 e_ReceiverReport,
00192 e_SourceDescription,
00193 e_Goodbye,
00194 e_ApplDefined
00195 };
00196
00197 unsigned GetPayloadType() const { return (BYTE)theArray[compoundOffset+1]; }
00198 void SetPayloadType(unsigned t);
00199
00200 PINDEX GetPayloadSize() const { return 4*(*(PUInt16b *)&theArray[compoundOffset+2]); }
00201 void SetPayloadSize(PINDEX sz);
00202
00203 BYTE * GetPayloadPtr() const;
00204
00205 PBoolean ReadNextPacket();
00206 PBoolean StartNewPacket();
00207 void EndPacket();
00208
00209 PINDEX GetCompoundSize() const;
00210
00211 void Reset(PINDEX size);
00212
00213 #pragma pack(1)
00214 struct ReceiverReport {
00215 PUInt32b ssrc;
00216 BYTE fraction;
00217 BYTE lost[3];
00218 PUInt32b last_seq;
00219 PUInt32b jitter;
00220 PUInt32b lsr;
00221 PUInt32b dlsr;
00222
00223 unsigned GetLostPackets() const { return (lost[0]<<16U)+(lost[1]<<8U)+lost[2]; }
00224 void SetLostPackets(unsigned lost);
00225 };
00226
00227 struct SenderReport {
00228 PUInt32b ntp_sec;
00229 PUInt32b ntp_frac;
00230 PUInt32b rtp_ts;
00231 PUInt32b psent;
00232 PUInt32b osent;
00233 };
00234
00235 enum DescriptionTypes {
00236 e_END,
00237 e_CNAME,
00238 e_NAME,
00239 e_EMAIL,
00240 e_PHONE,
00241 e_LOC,
00242 e_TOOL,
00243 e_NOTE,
00244 e_PRIV,
00245 NumDescriptionTypes
00246 };
00247
00248 struct SourceDescription {
00249 PUInt32b src;
00250 struct Item {
00251 BYTE type;
00252 BYTE length;
00253 char data[1];
00254
00255
00256
00257
00258
00259 unsigned int GetLengthTotal() const {return (unsigned int)(length + 2);}
00260 const Item * GetNextItem() const { return (const Item *)((char *)this + length + 2); }
00261 Item * GetNextItem() { return (Item *)((char *)this + length + 2); }
00262 } item[1];
00263 };
00264
00265 void StartSourceDescription(
00266 DWORD src
00267 );
00268
00269 void AddSourceDescriptionItem(
00270 unsigned type,
00271 const PString & data
00272 );
00273 #pragma pack()
00274
00275 protected:
00276 PINDEX compoundOffset;
00277 PINDEX payloadSize;
00278 };
00279
00280
00281 class RTP_Session;
00282
00284
00285 #if OPAL_STATISTICS
00286
00289 class OpalMediaStatistics : public PObject
00290 {
00291 PCLASSINFO(OpalMediaStatistics, PObject);
00292 public:
00293 OpalMediaStatistics();
00294
00295
00296 PUInt64 m_totalBytes;
00297 unsigned m_totalPackets;
00298 unsigned m_packetsLost;
00299 unsigned m_packetsOutOfOrder;
00300 unsigned m_packetsTooLate;
00301 unsigned m_packetOverruns;
00302 unsigned m_minimumPacketTime;
00303 unsigned m_averagePacketTime;
00304 unsigned m_maximumPacketTime;
00305
00306
00307 unsigned m_averageJitter;
00308 unsigned m_maximumJitter;
00309
00310
00311 unsigned m_totalFrames;
00312 unsigned m_keyFrames;
00313
00314
00315 #if OPAL_FAX
00316 struct Fax {
00317 Fax();
00318
00319 int m_result;
00320 int m_bitRate;
00321 int m_compression;
00322 bool m_errorCorrection;
00323 int m_txPages;
00324 int m_rxPages;
00325 int m_totalPages;
00326 int m_imageSize;
00327 int m_resolutionX;
00328 int m_resolutionY;
00329 int m_pageWidth;
00330 int m_pageHeight;
00331 int m_badRows;
00332 int m_mostBadRows;
00333 int m_errorCorrectionRetries;
00334 } m_fax;
00335 #endif
00336 };
00337
00338 #endif
00339
00340
00345 class RTP_UserData : public PObject
00346 {
00347 PCLASSINFO(RTP_UserData, PObject);
00348
00349 public:
00356 virtual void OnTxStatistics(
00357 const RTP_Session & session
00358 ) const;
00359
00366 virtual void OnRxStatistics(
00367 const RTP_Session & session
00368 ) const;
00369
00370 #if OPAL_VIDEO
00371
00376 virtual void OnTxIntraFrameRequest(
00377 const RTP_Session & session
00378 ) const;
00379
00385 virtual void OnRxIntraFrameRequest(
00386 const RTP_Session & session
00387 ) const;
00388 #endif
00389
00393 virtual void SessionFailing(
00394 RTP_Session & session
00395 );
00396 };
00397
00398 class RTP_Encoding;
00399
00400
00403 class RTP_Session : public PObject
00404 {
00405 PCLASSINFO(RTP_Session, PObject);
00406
00407 public:
00410 struct Params {
00411 Params()
00412 : id(0)
00413 , userData(NULL)
00414 , autoDelete(true)
00415 , isAudio(false)
00416 , remoteIsNAT(false)
00417 { }
00418
00419 PString encoding;
00420 unsigned id;
00421 RTP_UserData * userData;
00422 bool autoDelete;
00423 bool isAudio;
00424 bool remoteIsNAT;
00425 };
00426
00429 RTP_Session(
00430 const Params & options
00431 );
00432
00436 ~RTP_Session();
00438
00448 void SetJitterBufferSize(
00449 unsigned minJitterDelay,
00450 unsigned maxJitterDelay,
00451 unsigned timeUnits = 8,
00452 PINDEX packetSize = 2048
00453 );
00454
00460 unsigned GetJitterBufferSize() const;
00461
00464 unsigned GetJitterTimeUnits() const;
00465
00467 virtual PBoolean ModifyQOS(RTP_QOS * )
00468 { return PFalse; }
00469
00475 virtual PBoolean ReadBufferedData(
00476 RTP_DataFrame & frame
00477 );
00478
00484 virtual PBoolean ReadData(
00485 RTP_DataFrame & frame,
00486 PBoolean loop
00487 ) = 0;
00488
00491 virtual PBoolean WriteData(
00492 RTP_DataFrame & frame
00493 ) = 0;
00494
00498 virtual PBoolean WriteOOBData(
00499 RTP_DataFrame & frame,
00500 bool rewriteTimeStamp = true
00501 );
00502
00505 virtual PBoolean WriteControl(
00506 RTP_ControlFrame & frame
00507 ) = 0;
00508
00511 virtual PBoolean SendReport();
00512
00515 virtual void Close(
00516 PBoolean reading
00517 ) = 0;
00518
00521 virtual void Reopen(
00522 PBoolean isReading
00523 ) = 0;
00524
00527 virtual PString GetLocalHostName() = 0;
00528
00529 #if OPAL_STATISTICS
00530 virtual void GetStatistics(OpalMediaStatistics & statistics, bool receiver) const;
00531 #endif
00532
00533
00536 enum SendReceiveStatus {
00537 e_ProcessPacket,
00538 e_IgnorePacket,
00539 e_AbortTransport
00540 };
00541 virtual SendReceiveStatus OnSendData(RTP_DataFrame & frame);
00542 virtual SendReceiveStatus Internal_OnSendData(RTP_DataFrame & frame);
00543
00544 virtual SendReceiveStatus OnSendControl(RTP_ControlFrame & frame, PINDEX & len);
00545 virtual SendReceiveStatus Internal_OnSendControl(RTP_ControlFrame & frame, PINDEX & len);
00546
00547 virtual SendReceiveStatus OnReceiveData(RTP_DataFrame & frame);
00548 virtual SendReceiveStatus Internal_OnReceiveData(RTP_DataFrame & frame);
00549
00550 virtual SendReceiveStatus OnReceiveControl(RTP_ControlFrame & frame);
00551
00552 class ReceiverReport : public PObject {
00553 PCLASSINFO(ReceiverReport, PObject);
00554 public:
00555 void PrintOn(ostream &) const;
00556
00557 DWORD sourceIdentifier;
00558 DWORD fractionLost;
00559 DWORD totalLost;
00560 DWORD lastSequenceNumber;
00561 DWORD jitter;
00562 PTimeInterval lastTimestamp;
00563 PTimeInterval delay;
00564 };
00565 PARRAY(ReceiverReportArray, ReceiverReport);
00566
00567 class SenderReport : public PObject {
00568 PCLASSINFO(SenderReport, PObject);
00569 public:
00570 void PrintOn(ostream &) const;
00571
00572 DWORD sourceIdentifier;
00573 PTime realTimestamp;
00574 DWORD rtpTimestamp;
00575 DWORD packetsSent;
00576 DWORD octetsSent;
00577 };
00578 virtual void OnRxSenderReport(const SenderReport & sender,
00579 const ReceiverReportArray & reports);
00580 virtual void OnRxReceiverReport(DWORD src,
00581 const ReceiverReportArray & reports);
00582
00583 class SourceDescription : public PObject {
00584 PCLASSINFO(SourceDescription, PObject);
00585 public:
00586 SourceDescription(DWORD src) { sourceIdentifier = src; }
00587 void PrintOn(ostream &) const;
00588
00589 DWORD sourceIdentifier;
00590 POrdinalToString items;
00591 };
00592 PARRAY(SourceDescriptionArray, SourceDescription);
00593 virtual void OnRxSourceDescription(const SourceDescriptionArray & descriptions);
00594
00595 virtual void OnRxGoodbye(const PDWORDArray & sources,
00596 const PString & reason);
00597
00598 virtual void OnRxApplDefined(const PString & type, unsigned subtype, DWORD src,
00599 const BYTE * data, PINDEX size);
00601
00606 unsigned GetSessionID() const { return sessionID; }
00607
00610 void SetSessionID(unsigned id) { sessionID = id; }
00611
00614 bool IsAudio() const { return isAudio; }
00615
00618 void SetAudio(
00619 bool aud
00620 ) { isAudio = aud; }
00621
00624 PString GetCanonicalName() const;
00625
00628 void SetCanonicalName(const PString & name);
00629
00632 PString GetToolName() const;
00633
00636 void SetToolName(const PString & name);
00637
00640 RTP_UserData * GetUserData() const { return userData; }
00641
00644 void SetUserData(
00645 RTP_UserData * data,
00646 PBoolean autoDeleteUserData = PTrue
00647 );
00648
00651 DWORD GetSyncSourceOut() const { return syncSourceOut; }
00652
00655 bool AllowAnySyncSource() const { return allowAnySyncSource; }
00656
00659 void SetAnySyncSource(
00660 bool allow
00661 ) { allowAnySyncSource = allow; }
00662
00665 PBoolean WillIgnoreOutOfOrderPackets() const { return ignoreOutOfOrderPackets; }
00666
00669 void SetIgnoreOutOfOrderPackets(
00670 PBoolean ignore
00671 ) { ignoreOutOfOrderPackets = ignore; }
00672
00675 void SetIgnorePayloadTypeChanges(
00676 PBoolean ignore
00677 ) { ignorePayloadTypeChanges = ignore; }
00678
00681 const PTimeInterval & GetReportTimeInterval() { return reportTimeInterval; }
00682
00685 void SetReportTimeInterval(
00686 const PTimeInterval & interval
00687 ) { reportTimeInterval = interval; }
00688
00691 PTimeInterval GetReportTimer()
00692 { return reportTimer; }
00693
00696 unsigned GetTxStatisticsInterval() { return txStatisticsInterval; }
00697
00700 void SetTxStatisticsInterval(
00701 unsigned packets
00702 );
00703
00706 unsigned GetRxStatisticsInterval() { return rxStatisticsInterval; }
00707
00710 void SetRxStatisticsInterval(
00711 unsigned packets
00712 );
00713
00716 void ClearStatistics();
00717
00720 DWORD GetPacketsSent() const { return packetsSent; }
00721
00724 DWORD GetOctetsSent() const { return octetsSent; }
00725
00728 DWORD GetPacketsReceived() const { return packetsReceived; }
00729
00732 DWORD GetOctetsReceived() const { return octetsReceived; }
00733
00736 DWORD GetPacketsLost() const { return packetsLost; }
00737
00740 DWORD GetPacketsOutOfOrder() const { return packetsOutOfOrder; }
00741
00744 DWORD GetPacketsTooLate() const;
00745
00748 DWORD GetPacketOverruns() const;
00749
00754 DWORD GetAverageSendTime() const { return averageSendTime; }
00755
00760 DWORD GetMarkerRecvCount() const { return markerRecvCount; }
00761
00766 DWORD GetMarkerSendCount() const { return markerSendCount; }
00767
00772 DWORD GetMaximumSendTime() const { return maximumSendTime; }
00773
00778 DWORD GetMinimumSendTime() const { return minimumSendTime; }
00779
00784 DWORD GetAverageReceiveTime() const { return averageReceiveTime; }
00785
00790 DWORD GetMaximumReceiveTime() const { return maximumReceiveTime; }
00791
00796 DWORD GetMinimumReceiveTime() const { return minimumReceiveTime; }
00797
00802 DWORD GetAvgJitterTime() const { return jitterLevel>>7; }
00803
00807 DWORD GetMaxJitterTime() const { return maximumJitterLevel>>7; }
00809
00810 virtual void SetCloseOnBYE(PBoolean v) { closeOnBye = v; }
00811
00816 virtual void SendIntraFrameRequest();
00817
00818 void SetNextSentSequenceNumber(WORD num) { lastSentSequenceNumber = (WORD)(num-1); }
00819
00820 virtual PString GetEncoding() const { return m_encoding; }
00821 virtual void SetEncoding(const PString & newEncoding);
00822
00823 DWORD GetSyncSourceIn() const { return syncSourceIn; }
00824
00825 class EncodingLock
00826 {
00827 public:
00828 EncodingLock(RTP_Session & _session);
00829 ~EncodingLock();
00830
00831 __inline RTP_Encoding * operator->() const { return m_encodingHandler; }
00832
00833 protected:
00834 RTP_Session & session;
00835 RTP_Encoding * m_encodingHandler;
00836 };
00837
00838 friend class EncodingLock;
00839
00840 void SetFailed(bool v)
00841 { failed = v; }
00842
00843 bool HasFailed() const
00844 { return failed; }
00845
00846 void AddFilter(const PNotifier & filter);
00847
00848 protected:
00849 virtual void SendBYE();
00850 void AddReceiverReport(RTP_ControlFrame::ReceiverReport & receiver);
00851 PBoolean InsertReportPacket(RTP_ControlFrame & report);
00852
00853 PString m_encoding;
00854 PMutex m_encodingMutex;
00855 RTP_Encoding * m_encodingHandler;
00856
00857 unsigned sessionID;
00858 bool isAudio;
00859 PString canonicalName;
00860 PString toolName;
00861 RTP_UserData * userData;
00862 PBoolean autoDeleteUserData;
00863
00864 typedef PSafePtr<RTP_JitterBuffer, PSafePtrMultiThreaded> JitterBufferPtr;
00865 JitterBufferPtr m_jitterBuffer;
00866
00867 PBoolean ignoreOutOfOrderPackets;
00868 DWORD syncSourceOut;
00869 DWORD syncSourceIn;
00870 DWORD lastSentTimestamp;
00871 bool allowAnySyncSource;
00872 bool allowOneSyncSourceChange;
00873 PBoolean allowRemoteTransmitAddressChange;
00874 PBoolean allowSequenceChange;
00875 PTimeInterval reportTimeInterval;
00876 unsigned txStatisticsInterval;
00877 unsigned rxStatisticsInterval;
00878 WORD lastSentSequenceNumber;
00879 WORD expectedSequenceNumber;
00880 PTimeInterval lastSentPacketTime;
00881 PTimeInterval lastReceivedPacketTime;
00882 WORD lastRRSequenceNumber;
00883 PINDEX consecutiveOutOfOrderPackets;
00884
00885 PMutex dataMutex;
00886 DWORD timeStampOffs;
00887 PBoolean oobTimeStampBaseEstablished;
00888 DWORD oobTimeStampOutBase;
00889 PTimeInterval oobTimeStampBase;
00890
00891
00892 DWORD packetsSent;
00893 DWORD rtcpPacketsSent;
00894 DWORD octetsSent;
00895 DWORD packetsReceived;
00896 DWORD octetsReceived;
00897 DWORD packetsLost;
00898 DWORD packetsOutOfOrder;
00899 DWORD averageSendTime;
00900 DWORD maximumSendTime;
00901 DWORD minimumSendTime;
00902 DWORD averageReceiveTime;
00903 DWORD maximumReceiveTime;
00904 DWORD minimumReceiveTime;
00905 DWORD jitterLevel;
00906 DWORD maximumJitterLevel;
00907
00908 DWORD markerSendCount;
00909 DWORD markerRecvCount;
00910
00911 unsigned txStatisticsCount;
00912 unsigned rxStatisticsCount;
00913
00914 DWORD averageSendTimeAccum;
00915 DWORD maximumSendTimeAccum;
00916 DWORD minimumSendTimeAccum;
00917 DWORD averageReceiveTimeAccum;
00918 DWORD maximumReceiveTimeAccum;
00919 DWORD minimumReceiveTimeAccum;
00920 DWORD packetsLostSinceLastRR;
00921 DWORD lastTransitTime;
00922
00923 RTP_DataFrame::PayloadTypes lastReceivedPayloadType;
00924 PBoolean ignorePayloadTypeChanges;
00925
00926 PMutex reportMutex;
00927 PTimer reportTimer;
00928
00929 PBoolean closeOnBye;
00930 PBoolean byeSent;
00931 bool failed;
00932
00933 class Filter : public PObject {
00934 PCLASSINFO(Filter, PObject);
00935 public:
00936 Filter(const PNotifier & n) : notifier(n) { }
00937 PNotifier notifier;
00938 };
00939 PList<Filter> filters;
00940 };
00941
00944 class RTP_UDP : public RTP_Session
00945 {
00946 PCLASSINFO(RTP_UDP, RTP_Session);
00947
00948 public:
00953 RTP_UDP(
00954 const Params & options
00955 );
00956
00958 ~RTP_UDP();
00960
00968 virtual PBoolean ReadData(RTP_DataFrame & frame, PBoolean loop);
00969 virtual PBoolean Internal_ReadData(RTP_DataFrame & frame, PBoolean loop);
00970
00973 virtual PBoolean WriteData(RTP_DataFrame & frame);
00974 virtual PBoolean Internal_WriteData(RTP_DataFrame & frame);
00975
00979 virtual PBoolean WriteOOBData(RTP_DataFrame & frame, bool setTimeStamp = true);
00980
00983 virtual PBoolean WriteControl(RTP_ControlFrame & frame);
00984
00987 virtual void Close(
00988 PBoolean reading
00989 );
00990
00993 virtual PString GetLocalHostName();
00995
00998 virtual PBoolean ModifyQOS(RTP_QOS * rtpqos);
00999
01004 virtual PBoolean Open(
01005 PIPSocket::Address localAddress,
01006 WORD portBase,
01007 WORD portMax,
01008 BYTE ipTypeOfService,
01009 PNatMethod * natMethod = NULL,
01010 RTP_QOS * rtpqos = NULL
01011 );
01013
01016 virtual void Reopen(PBoolean isReading);
01018
01023 virtual PIPSocket::Address GetLocalAddress() const { return localAddress; }
01024
01027 virtual void SetLocalAddress(
01028 const PIPSocket::Address & addr
01029 ) { localAddress = addr; }
01030
01033 PIPSocket::Address GetRemoteAddress() const { return remoteAddress; }
01034
01037 virtual WORD GetLocalDataPort() const { return localDataPort; }
01038
01041 virtual WORD GetLocalControlPort() const { return localControlPort; }
01042
01045 virtual WORD GetRemoteDataPort() const { return remoteDataPort; }
01046
01049 virtual WORD GetRemoteControlPort() const { return remoteControlPort; }
01050
01053 virtual PUDPSocket & GetDataSocket() { return *dataSocket; }
01054
01057 virtual PUDPSocket & GetControlSocket() { return *controlSocket; }
01058
01061 virtual PBoolean SetRemoteSocketInfo(
01062 PIPSocket::Address address,
01063 WORD port,
01064 PBoolean isDataPort
01065 );
01066
01069 virtual void ApplyQOS(
01070 const PIPSocket::Address & addr
01071 );
01073
01074 virtual int GetDataSocketHandle() const
01075 { return dataSocket != NULL ? dataSocket->GetHandle() : -1; }
01076
01077 virtual int GetControlSocketHandle() const
01078 { return controlSocket != NULL ? controlSocket->GetHandle() : -1; }
01079
01080 friend class RTP_Encoding;
01081
01082 virtual int WaitForPDU(PUDPSocket & dataSocket, PUDPSocket & controlSocket, const PTimeInterval & timer);
01083 virtual int Internal_WaitForPDU(PUDPSocket & dataSocket, PUDPSocket & controlSocket, const PTimeInterval & timer);
01084
01085 virtual SendReceiveStatus ReadDataPDU(RTP_DataFrame & frame);
01086 virtual SendReceiveStatus Internal_ReadDataPDU(RTP_DataFrame & frame);
01087
01088 virtual SendReceiveStatus OnReadTimeout(RTP_DataFrame & frame);
01089 virtual SendReceiveStatus Internal_OnReadTimeout(RTP_DataFrame & frame);
01090
01091 virtual SendReceiveStatus ReadControlPDU();
01092 virtual SendReceiveStatus ReadDataOrControlPDU(
01093 BYTE * framePtr,
01094 PINDEX frameSize,
01095 PBoolean fromDataChannel
01096 );
01097
01098 virtual bool WriteDataPDU(RTP_DataFrame & frame);
01099 virtual bool WriteDataOrControlPDU(
01100 const BYTE * framePtr,
01101 PINDEX frameSize,
01102 bool toDataChannel
01103 );
01104
01105
01106 protected:
01107 PIPSocket::Address localAddress;
01108 WORD localDataPort;
01109 WORD localControlPort;
01110
01111 PIPSocket::Address remoteAddress;
01112 WORD remoteDataPort;
01113 WORD remoteControlPort;
01114
01115 PIPSocket::Address remoteTransmitAddress;
01116
01117 PUDPSocket * dataSocket;
01118 PUDPSocket * controlSocket;
01119
01120 bool shutdownRead;
01121 bool shutdownWrite;
01122 bool appliedQOS;
01123 bool remoteIsNAT;
01124 bool localHasNAT;
01125 bool first;
01126 int badTransmitCounter;
01127 PTime badTransmitStart;
01128 };
01129
01131
01132 class RTP_UDP;
01133
01134 class RTP_Encoding
01135 {
01136 public:
01137 RTP_Encoding();
01138 virtual ~RTP_Encoding();
01139 virtual void OnStart(RTP_Session & _rtpSession);
01140 virtual void OnFinish();
01141 virtual RTP_Session::SendReceiveStatus OnSendData(RTP_DataFrame & frame);
01142 virtual PBoolean WriteData(RTP_DataFrame & frame, bool oob);
01143 virtual PBoolean WriteDataPDU(RTP_DataFrame & frame);
01144 virtual RTP_Session::SendReceiveStatus OnSendControl(RTP_ControlFrame & frame, PINDEX & len);
01145 virtual RTP_Session::SendReceiveStatus ReadDataPDU(RTP_DataFrame & frame);
01146 virtual RTP_Session::SendReceiveStatus OnReceiveData(RTP_DataFrame & frame);
01147 virtual RTP_Session::SendReceiveStatus OnReadTimeout(RTP_DataFrame & frame);
01148 virtual PBoolean ReadData(RTP_DataFrame & frame, PBoolean loop);
01149 virtual int WaitForPDU(PUDPSocket & dataSocket, PUDPSocket & controlSocket, const PTimeInterval &);
01150
01151 PMutex mutex;
01152 unsigned refCount;
01153
01154 protected:
01155 RTP_UDP * rtpUDP;
01156 };
01157
01158 PFACTORY_LOAD(RTP_Encoding);
01159
01160
01162
01163 class SecureRTP_UDP : public RTP_UDP
01164 {
01165 PCLASSINFO(SecureRTP_UDP, RTP_UDP);
01166
01167 public:
01172 SecureRTP_UDP(
01173 const Params & options
01174 );
01175
01177 ~SecureRTP_UDP();
01178
01179 virtual void SetSecurityMode(OpalSecurityMode * srtpParms);
01180 virtual OpalSecurityMode * GetSecurityParms() const;
01181
01182 protected:
01183 OpalSecurityMode * securityParms;
01184 };
01185
01186 #endif // OPAL_RTP_RTP_H
01187