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 T38 = 38,
00114
00115 LastKnownPayloadType,
00116
00117 DynamicBase = 96,
00118 MaxPayloadType = 127,
00119 IllegalPayloadType
00120 };
00121
00122 unsigned GetVersion() const { return (theArray[0]>>6)&3; }
00123
00124 PBoolean GetExtension() const { return (theArray[0]&0x10) != 0; }
00125 void SetExtension(PBoolean ext);
00126
00127 PBoolean GetMarker() const { return (theArray[1]&0x80) != 0; }
00128 void SetMarker(PBoolean m);
00129
00130 bool GetPadding() const { return (theArray[0]&0x20) != 0; }
00131 void SetPadding(bool v) { if (v) theArray[0] |= 0x20; else theArray[0] &= 0xdf; }
00132
00133 unsigned GetPaddingSize() const;
00134
00135 PayloadTypes GetPayloadType() const { return (PayloadTypes)(theArray[1]&0x7f); }
00136 void SetPayloadType(PayloadTypes t);
00137
00138 WORD GetSequenceNumber() const { return *(PUInt16b *)&theArray[2]; }
00139 void SetSequenceNumber(WORD n) { *(PUInt16b *)&theArray[2] = n; }
00140
00141 DWORD GetTimestamp() const { return *(PUInt32b *)&theArray[4]; }
00142 void SetTimestamp(DWORD t) { *(PUInt32b *)&theArray[4] = t; }
00143
00144 DWORD GetSyncSource() const { return *(PUInt32b *)&theArray[8]; }
00145 void SetSyncSource(DWORD s) { *(PUInt32b *)&theArray[8] = s; }
00146
00147 PINDEX GetContribSrcCount() const { return theArray[0]&0xf; }
00148 DWORD GetContribSource(PINDEX idx) const;
00149 void SetContribSource(PINDEX idx, DWORD src);
00150
00151 PINDEX GetHeaderSize() const;
00152
00153 int GetExtensionType() const;
00154 void SetExtensionType(int type);
00155 PINDEX GetExtensionSizeDWORDs() const;
00156 bool SetExtensionSizeDWORDs(PINDEX sz);
00157 BYTE * GetExtensionPtr() const;
00158
00159 PINDEX GetPayloadSize() const { return payloadSize - GetPaddingSize(); }
00160 PBoolean SetPayloadSize(PINDEX sz);
00161 BYTE * GetPayloadPtr() const { return (BYTE *)(theArray+GetHeaderSize()); }
00162
00163 virtual void PrintOn(ostream & strm) const;
00164
00165 protected:
00166 PINDEX payloadSize;
00167
00168 #if PTRACING
00169 friend ostream & operator<<(ostream & o, PayloadTypes t);
00170 #endif
00171 };
00172
00173 PLIST(RTP_DataFrameList, RTP_DataFrame);
00174
00175
00178 class RTP_ControlFrame : public PBYTEArray
00179 {
00180 PCLASSINFO(RTP_ControlFrame, PBYTEArray);
00181
00182 public:
00183 RTP_ControlFrame(PINDEX compoundSize = 2048);
00184
00185 unsigned GetVersion() const { return (BYTE)theArray[compoundOffset]>>6; }
00186
00187 unsigned GetCount() const { return (BYTE)theArray[compoundOffset]&0x1f; }
00188 void SetCount(unsigned count);
00189
00190 enum PayloadTypes {
00191 e_IntraFrameRequest = 192,
00192 e_SenderReport = 200,
00193 e_ReceiverReport,
00194 e_SourceDescription,
00195 e_Goodbye,
00196 e_ApplDefined
00197 };
00198
00199 unsigned GetPayloadType() const { return (BYTE)theArray[compoundOffset+1]; }
00200 void SetPayloadType(unsigned t);
00201
00202 PINDEX GetPayloadSize() const { return 4*(*(PUInt16b *)&theArray[compoundOffset+2]); }
00203 void SetPayloadSize(PINDEX sz);
00204
00205 BYTE * GetPayloadPtr() const;
00206
00207 PBoolean ReadNextPacket();
00208 PBoolean StartNewPacket();
00209 void EndPacket();
00210
00211 PINDEX GetCompoundSize() const;
00212
00213 void Reset(PINDEX size);
00214
00215 #pragma pack(1)
00216 struct ReceiverReport {
00217 PUInt32b ssrc;
00218 BYTE fraction;
00219 BYTE lost[3];
00220 PUInt32b last_seq;
00221 PUInt32b jitter;
00222 PUInt32b lsr;
00223 PUInt32b dlsr;
00224
00225 unsigned GetLostPackets() const { return (lost[0]<<16U)+(lost[1]<<8U)+lost[2]; }
00226 void SetLostPackets(unsigned lost);
00227 };
00228
00229 struct SenderReport {
00230 PUInt32b ntp_sec;
00231 PUInt32b ntp_frac;
00232 PUInt32b rtp_ts;
00233 PUInt32b psent;
00234 PUInt32b osent;
00235 };
00236
00237 enum DescriptionTypes {
00238 e_END,
00239 e_CNAME,
00240 e_NAME,
00241 e_EMAIL,
00242 e_PHONE,
00243 e_LOC,
00244 e_TOOL,
00245 e_NOTE,
00246 e_PRIV,
00247 NumDescriptionTypes
00248 };
00249
00250 struct SourceDescription {
00251 PUInt32b src;
00252 struct Item {
00253 BYTE type;
00254 BYTE length;
00255 char data[1];
00256
00257
00258
00259
00260
00261 unsigned int GetLengthTotal() const {return (unsigned int)(length + 2);}
00262 const Item * GetNextItem() const { return (const Item *)((char *)this + length + 2); }
00263 Item * GetNextItem() { return (Item *)((char *)this + length + 2); }
00264 } item[1];
00265 };
00266
00267 void StartSourceDescription(
00268 DWORD src
00269 );
00270
00271 void AddSourceDescriptionItem(
00272 unsigned type,
00273 const PString & data
00274 );
00275 #pragma pack()
00276
00277 protected:
00278 PINDEX compoundOffset;
00279 PINDEX payloadSize;
00280 };
00281
00282
00283 class RTP_Session;
00284
00286
00287 #if OPAL_STATISTICS
00288
00291 class OpalMediaStatistics : public PObject
00292 {
00293 PCLASSINFO(OpalMediaStatistics, PObject);
00294 public:
00295 OpalMediaStatistics();
00296
00297
00298 PUInt64 m_totalBytes;
00299 unsigned m_totalPackets;
00300 unsigned m_packetsLost;
00301 unsigned m_packetsOutOfOrder;
00302 unsigned m_packetsTooLate;
00303 unsigned m_packetOverruns;
00304 unsigned m_minimumPacketTime;
00305 unsigned m_averagePacketTime;
00306 unsigned m_maximumPacketTime;
00307
00308
00309 unsigned m_averageJitter;
00310 unsigned m_maximumJitter;
00311
00312
00313 unsigned m_totalFrames;
00314 unsigned m_keyFrames;
00315
00316
00317 #if OPAL_FAX
00318 struct Fax {
00319 Fax();
00320
00321 int m_result;
00322 int m_bitRate;
00323 int m_compression;
00324 bool m_errorCorrection;
00325 int m_txPages;
00326 int m_rxPages;
00327 int m_totalPages;
00328 int m_imageSize;
00329 int m_resolutionX;
00330 int m_resolutionY;
00331 int m_pageWidth;
00332 int m_pageHeight;
00333 int m_badRows;
00334 int m_mostBadRows;
00335 int m_errorCorrectionRetries;
00336
00337 PString m_errorText;
00338 } m_fax;
00339 #endif
00340 };
00341
00342 #endif
00343
00344
00349 class RTP_UserData : public PObject
00350 {
00351 PCLASSINFO(RTP_UserData, PObject);
00352
00353 public:
00360 virtual void OnTxStatistics(
00361 const RTP_Session & session
00362 ) const;
00363
00370 virtual void OnRxStatistics(
00371 const RTP_Session & session
00372 ) const;
00373
00374 #if OPAL_VIDEO
00375
00380 virtual void OnTxIntraFrameRequest(
00381 const RTP_Session & session
00382 ) const;
00383
00389 virtual void OnRxIntraFrameRequest(
00390 const RTP_Session & session
00391 ) const;
00392 #endif
00393
00397 virtual void SessionFailing(
00398 RTP_Session & session
00399 );
00400 };
00401
00402 class RTP_Encoding;
00403
00404
00407 class RTP_Session : public PObject
00408 {
00409 PCLASSINFO(RTP_Session, PObject);
00410
00411 public:
00414 struct Params {
00415 Params()
00416 : id(0)
00417 , userData(NULL)
00418 , autoDelete(true)
00419 , isAudio(false)
00420 , remoteIsNAT(false)
00421 { }
00422
00423 PString encoding;
00424 unsigned id;
00425 RTP_UserData * userData;
00426 bool autoDelete;
00427 bool isAudio;
00428 bool remoteIsNAT;
00429 };
00430
00433 RTP_Session(
00434 const Params & options
00435 );
00436
00440 ~RTP_Session();
00442
00452 void SetJitterBufferSize(
00453 unsigned minJitterDelay,
00454 unsigned maxJitterDelay,
00455 unsigned timeUnits = 0,
00456 PINDEX packetSize = 2048
00457 );
00458
00464 unsigned GetJitterBufferSize() const;
00465
00468 unsigned GetJitterTimeUnits() const { return m_timeUnits; }
00469
00471 virtual PBoolean ModifyQOS(RTP_QOS * )
00472 { return PFalse; }
00473
00479 virtual PBoolean ReadBufferedData(
00480 RTP_DataFrame & frame
00481 );
00482
00488 virtual PBoolean ReadData(
00489 RTP_DataFrame & frame,
00490 PBoolean loop
00491 ) = 0;
00492
00495 virtual PBoolean WriteData(
00496 RTP_DataFrame & frame
00497 ) = 0;
00498
00502 virtual PBoolean WriteOOBData(
00503 RTP_DataFrame & frame,
00504 bool rewriteTimeStamp = true
00505 );
00506
00509 virtual PBoolean WriteControl(
00510 RTP_ControlFrame & frame
00511 ) = 0;
00512
00515 virtual PBoolean SendReport();
00516
00519 virtual bool Close(
00520 PBoolean reading
00521 ) = 0;
00522
00525 virtual void Reopen(
00526 PBoolean isReading
00527 ) = 0;
00528
00531 virtual PString GetLocalHostName() = 0;
00532
00533 #if OPAL_STATISTICS
00534 virtual void GetStatistics(OpalMediaStatistics & statistics, bool receiver) const;
00535 #endif
00536
00537
00540 enum SendReceiveStatus {
00541 e_ProcessPacket,
00542 e_IgnorePacket,
00543 e_AbortTransport
00544 };
00545 virtual SendReceiveStatus OnSendData(RTP_DataFrame & frame);
00546 virtual SendReceiveStatus Internal_OnSendData(RTP_DataFrame & frame);
00547
00548 virtual SendReceiveStatus OnSendControl(RTP_ControlFrame & frame, PINDEX & len);
00549 virtual SendReceiveStatus Internal_OnSendControl(RTP_ControlFrame & frame, PINDEX & len);
00550
00551 virtual SendReceiveStatus OnReceiveData(RTP_DataFrame & frame);
00552 virtual SendReceiveStatus Internal_OnReceiveData(RTP_DataFrame & frame);
00553
00554 virtual SendReceiveStatus OnReceiveControl(RTP_ControlFrame & frame);
00555
00556 class ReceiverReport : public PObject {
00557 PCLASSINFO(ReceiverReport, PObject);
00558 public:
00559 void PrintOn(ostream &) const;
00560
00561 DWORD sourceIdentifier;
00562 DWORD fractionLost;
00563 DWORD totalLost;
00564 DWORD lastSequenceNumber;
00565 DWORD jitter;
00566 PTimeInterval lastTimestamp;
00567 PTimeInterval delay;
00568 };
00569 PARRAY(ReceiverReportArray, ReceiverReport);
00570
00571 class SenderReport : public PObject {
00572 PCLASSINFO(SenderReport, PObject);
00573 public:
00574 void PrintOn(ostream &) const;
00575
00576 DWORD sourceIdentifier;
00577 PTime realTimestamp;
00578 DWORD rtpTimestamp;
00579 DWORD packetsSent;
00580 DWORD octetsSent;
00581 };
00582 virtual void OnRxSenderReport(const SenderReport & sender,
00583 const ReceiverReportArray & reports);
00584 virtual void OnRxReceiverReport(DWORD src,
00585 const ReceiverReportArray & reports);
00586 virtual void OnReceiverReports(const ReceiverReportArray & reports);
00587
00588 class SourceDescription : public PObject {
00589 PCLASSINFO(SourceDescription, PObject);
00590 public:
00591 SourceDescription(DWORD src) { sourceIdentifier = src; }
00592 void PrintOn(ostream &) const;
00593
00594 DWORD sourceIdentifier;
00595 POrdinalToString items;
00596 };
00597 PARRAY(SourceDescriptionArray, SourceDescription);
00598 virtual void OnRxSourceDescription(const SourceDescriptionArray & descriptions);
00599
00600 virtual void OnRxGoodbye(const PDWORDArray & sources,
00601 const PString & reason);
00602
00603 virtual void OnRxApplDefined(const PString & type, unsigned subtype, DWORD src,
00604 const BYTE * data, PINDEX size);
00606
00611 unsigned GetSessionID() const { return sessionID; }
00612
00615 void SetSessionID(unsigned id) { sessionID = id; }
00616
00619 bool IsAudio() const { return isAudio; }
00620
00623 void SetAudio(
00624 bool aud
00625 ) { isAudio = aud; }
00626
00629 PString GetCanonicalName() const;
00630
00633 void SetCanonicalName(const PString & name);
00634
00637 PString GetToolName() const;
00638
00641 void SetToolName(const PString & name);
00642
00645 RTP_UserData * GetUserData() const { return userData; }
00646
00649 void SetUserData(
00650 RTP_UserData * data,
00651 PBoolean autoDeleteUserData = PTrue
00652 );
00653
00656 DWORD GetSyncSourceOut() const { return syncSourceOut; }
00657
00660 bool AllowAnySyncSource() const { return allowAnySyncSource; }
00661
00664 void SetAnySyncSource(
00665 bool allow
00666 ) { allowAnySyncSource = allow; }
00667
00670 PBoolean WillIgnoreOutOfOrderPackets() const { return ignoreOutOfOrderPackets; }
00671
00674 void SetIgnoreOutOfOrderPackets(
00675 PBoolean ignore
00676 ) { ignoreOutOfOrderPackets = ignore; }
00677
00680 void SetIgnorePayloadTypeChanges(
00681 PBoolean ignore
00682 ) { ignorePayloadTypeChanges = ignore; }
00683
00686 const PTimeInterval & GetReportTimeInterval() { return reportTimeInterval; }
00687
00690 void SetReportTimeInterval(
00691 const PTimeInterval & interval
00692 ) { reportTimeInterval = interval; }
00693
00696 PTimeInterval GetReportTimer()
00697 { return reportTimer; }
00698
00701 unsigned GetTxStatisticsInterval() { return txStatisticsInterval; }
00702
00705 void SetTxStatisticsInterval(
00706 unsigned packets
00707 );
00708
00711 unsigned GetRxStatisticsInterval() { return rxStatisticsInterval; }
00712
00715 void SetRxStatisticsInterval(
00716 unsigned packets
00717 );
00718
00721 void ClearStatistics();
00722
00725 DWORD GetPacketsSent() const { return packetsSent; }
00726
00729 DWORD GetOctetsSent() const { return octetsSent; }
00730
00733 DWORD GetPacketsReceived() const { return packetsReceived; }
00734
00737 DWORD GetOctetsReceived() const { return octetsReceived; }
00738
00741 DWORD GetPacketsLost() const { return packetsLost; }
00742
00746 DWORD GetPacketsLostByRemote() const { return packetsLostByRemote; }
00747
00750 DWORD GetPacketsOutOfOrder() const { return packetsOutOfOrder; }
00751
00754 DWORD GetPacketsTooLate() const;
00755
00758 DWORD GetPacketOverruns() const;
00759
00764 DWORD GetAverageSendTime() const { return averageSendTime; }
00765
00770 DWORD GetMarkerRecvCount() const { return markerRecvCount; }
00771
00776 DWORD GetMarkerSendCount() const { return markerSendCount; }
00777
00782 DWORD GetMaximumSendTime() const { return maximumSendTime; }
00783
00788 DWORD GetMinimumSendTime() const { return minimumSendTime; }
00789
00794 DWORD GetAverageReceiveTime() const { return averageReceiveTime; }
00795
00800 DWORD GetMaximumReceiveTime() const { return maximumReceiveTime; }
00801
00806 DWORD GetMinimumReceiveTime() const { return minimumReceiveTime; }
00807
00808 enum { JitterRoundingGuardBits = 4 };
00813 DWORD GetAvgJitterTime() const { return (jitterLevel>>JitterRoundingGuardBits)/GetJitterTimeUnits(); }
00814
00818 DWORD GetMaxJitterTime() const { return (maximumJitterLevel>>JitterRoundingGuardBits)/GetJitterTimeUnits(); }
00819
00824 DWORD GetJitterTimeOnRemote() const { return jitterLevelOnRemote/GetJitterTimeUnits(); }
00826
00827 virtual void SetCloseOnBYE(PBoolean v) { closeOnBye = v; }
00828
00833 virtual void SendIntraFrameRequest();
00834
00835 void SetNextSentSequenceNumber(WORD num) { lastSentSequenceNumber = (WORD)(num-1); }
00836
00837 virtual PString GetEncoding() const { return m_encoding; }
00838 virtual void SetEncoding(const PString & newEncoding);
00839
00840 DWORD GetSyncSourceIn() const { return syncSourceIn; }
00841
00842 class EncodingLock
00843 {
00844 public:
00845 EncodingLock(RTP_Session & _session);
00846 ~EncodingLock();
00847
00848 __inline RTP_Encoding * operator->() const { return m_encodingHandler; }
00849
00850 protected:
00851 RTP_Session & session;
00852 RTP_Encoding * m_encodingHandler;
00853 };
00854
00855 friend class EncodingLock;
00856
00857 void SetFailed(bool v)
00858 { failed = v; }
00859
00860 bool HasFailed() const
00861 { return failed; }
00862
00863 void AddFilter(const PNotifier & filter);
00864
00865 protected:
00866 virtual void SendBYE();
00867 void AddReceiverReport(RTP_ControlFrame::ReceiverReport & receiver);
00868 PBoolean InsertReportPacket(RTP_ControlFrame & report);
00869
00870 PString m_encoding;
00871 PMutex m_encodingMutex;
00872 RTP_Encoding * m_encodingHandler;
00873
00874 unsigned sessionID;
00875 bool isAudio;
00876 unsigned m_timeUnits;
00877 PString canonicalName;
00878 PString toolName;
00879 RTP_UserData * userData;
00880 PBoolean autoDeleteUserData;
00881
00882 typedef PSafePtr<RTP_JitterBuffer, PSafePtrMultiThreaded> JitterBufferPtr;
00883 JitterBufferPtr m_jitterBuffer;
00884
00885 PBoolean ignoreOutOfOrderPackets;
00886 DWORD syncSourceOut;
00887 DWORD syncSourceIn;
00888 DWORD lastSentTimestamp;
00889 bool allowAnySyncSource;
00890 bool allowOneSyncSourceChange;
00891 PBoolean allowRemoteTransmitAddressChange;
00892 PBoolean allowSequenceChange;
00893 PTimeInterval reportTimeInterval;
00894 unsigned txStatisticsInterval;
00895 unsigned rxStatisticsInterval;
00896 WORD lastSentSequenceNumber;
00897 WORD expectedSequenceNumber;
00898 PTimeInterval lastSentPacketTime;
00899 PTimeInterval lastReceivedPacketTime;
00900 WORD lastRRSequenceNumber;
00901 PINDEX consecutiveOutOfOrderPackets;
00902
00903 PMutex dataMutex;
00904 DWORD timeStampOffs;
00905 PBoolean oobTimeStampBaseEstablished;
00906 DWORD oobTimeStampOutBase;
00907 PTimeInterval oobTimeStampBase;
00908
00909
00910 DWORD packetsSent;
00911 DWORD rtcpPacketsSent;
00912 DWORD octetsSent;
00913 DWORD packetsReceived;
00914 DWORD octetsReceived;
00915 DWORD packetsLost;
00916 DWORD packetsLostByRemote;
00917 DWORD packetsOutOfOrder;
00918 DWORD averageSendTime;
00919 DWORD maximumSendTime;
00920 DWORD minimumSendTime;
00921 DWORD averageReceiveTime;
00922 DWORD maximumReceiveTime;
00923 DWORD minimumReceiveTime;
00924 DWORD jitterLevel;
00925 DWORD jitterLevelOnRemote;
00926 DWORD maximumJitterLevel;
00927
00928 DWORD markerSendCount;
00929 DWORD markerRecvCount;
00930
00931 unsigned txStatisticsCount;
00932 unsigned rxStatisticsCount;
00933
00934 DWORD averageSendTimeAccum;
00935 DWORD maximumSendTimeAccum;
00936 DWORD minimumSendTimeAccum;
00937 DWORD averageReceiveTimeAccum;
00938 DWORD maximumReceiveTimeAccum;
00939 DWORD minimumReceiveTimeAccum;
00940 DWORD packetsLostSinceLastRR;
00941 DWORD lastTransitTime;
00942
00943 RTP_DataFrame::PayloadTypes lastReceivedPayloadType;
00944 PBoolean ignorePayloadTypeChanges;
00945
00946 PMutex reportMutex;
00947 PTimer reportTimer;
00948
00949 PBoolean closeOnBye;
00950 PBoolean byeSent;
00951 bool failed;
00952
00953 class Filter : public PObject {
00954 PCLASSINFO(Filter, PObject);
00955 public:
00956 Filter(const PNotifier & n) : notifier(n) { }
00957 PNotifier notifier;
00958 };
00959 PList<Filter> filters;
00960 };
00961
00964 class RTP_UDP : public RTP_Session
00965 {
00966 PCLASSINFO(RTP_UDP, RTP_Session);
00967
00968 public:
00973 RTP_UDP(
00974 const Params & options
00975 );
00976
00978 ~RTP_UDP();
00980
00988 virtual PBoolean ReadData(RTP_DataFrame & frame, PBoolean loop);
00989 virtual PBoolean Internal_ReadData(RTP_DataFrame & frame, PBoolean loop);
00990
00993 virtual PBoolean WriteData(RTP_DataFrame & frame);
00994 virtual PBoolean Internal_WriteData(RTP_DataFrame & frame);
00995
00999 virtual PBoolean WriteOOBData(RTP_DataFrame & frame, bool setTimeStamp = true);
01000
01003 virtual PBoolean WriteControl(RTP_ControlFrame & frame);
01004
01007 virtual bool Close(
01008 PBoolean reading
01009 );
01010
01013 virtual PString GetLocalHostName();
01015
01018 virtual PBoolean ModifyQOS(RTP_QOS * rtpqos);
01019
01024 virtual PBoolean Open(
01025 PIPSocket::Address localAddress,
01026 WORD portBase,
01027 WORD portMax,
01028 BYTE ipTypeOfService,
01029 PNatMethod * natMethod = NULL,
01030 RTP_QOS * rtpqos = NULL
01031 );
01033
01036 virtual void Reopen(PBoolean isReading);
01038
01043 virtual PIPSocket::Address GetLocalAddress() const { return localAddress; }
01044
01047 virtual void SetLocalAddress(
01048 const PIPSocket::Address & addr
01049 ) { localAddress = addr; }
01050
01053 PIPSocket::Address GetRemoteAddress() const { return remoteAddress; }
01054
01057 virtual WORD GetLocalDataPort() const { return localDataPort; }
01058
01061 virtual WORD GetLocalControlPort() const { return localControlPort; }
01062
01065 virtual WORD GetRemoteDataPort() const { return remoteDataPort; }
01066
01069 virtual WORD GetRemoteControlPort() const { return remoteControlPort; }
01070
01073 virtual PUDPSocket & GetDataSocket() { return *dataSocket; }
01074
01077 virtual PUDPSocket & GetControlSocket() { return *controlSocket; }
01078
01081 virtual PBoolean SetRemoteSocketInfo(
01082 PIPSocket::Address address,
01083 WORD port,
01084 PBoolean isDataPort
01085 );
01086
01089 virtual void ApplyQOS(
01090 const PIPSocket::Address & addr
01091 );
01093
01094 virtual int GetDataSocketHandle() const
01095 { return dataSocket != NULL ? dataSocket->GetHandle() : -1; }
01096
01097 virtual int GetControlSocketHandle() const
01098 { return controlSocket != NULL ? controlSocket->GetHandle() : -1; }
01099
01100 friend class RTP_Encoding;
01101
01102 virtual int WaitForPDU(PUDPSocket & dataSocket, PUDPSocket & controlSocket, const PTimeInterval & timer);
01103 virtual int Internal_WaitForPDU(PUDPSocket & dataSocket, PUDPSocket & controlSocket, const PTimeInterval & timer);
01104
01105 virtual SendReceiveStatus ReadDataPDU(RTP_DataFrame & frame);
01106 virtual SendReceiveStatus Internal_ReadDataPDU(RTP_DataFrame & frame);
01107
01108 virtual SendReceiveStatus OnReadTimeout(RTP_DataFrame & frame);
01109 virtual SendReceiveStatus Internal_OnReadTimeout(RTP_DataFrame & frame);
01110
01111 virtual SendReceiveStatus ReadControlPDU();
01112 virtual SendReceiveStatus ReadDataOrControlPDU(
01113 BYTE * framePtr,
01114 PINDEX frameSize,
01115 PBoolean fromDataChannel
01116 );
01117
01118 virtual bool WriteDataPDU(RTP_DataFrame & frame);
01119 virtual bool WriteDataOrControlPDU(
01120 const BYTE * framePtr,
01121 PINDEX frameSize,
01122 bool toDataChannel
01123 );
01124
01125
01126 protected:
01127 PIPSocket::Address localAddress;
01128 WORD localDataPort;
01129 WORD localControlPort;
01130
01131 PIPSocket::Address remoteAddress;
01132 WORD remoteDataPort;
01133 WORD remoteControlPort;
01134
01135 PIPSocket::Address remoteTransmitAddress;
01136
01137 PUDPSocket * dataSocket;
01138 PUDPSocket * controlSocket;
01139
01140 bool shutdownRead;
01141 bool shutdownWrite;
01142 bool appliedQOS;
01143 bool remoteIsNAT;
01144 bool localHasNAT;
01145 bool first;
01146 int badTransmitCounter;
01147 PTime badTransmitStart;
01148 };
01149
01151
01152 class RTP_UDP;
01153
01154 class RTP_Encoding
01155 {
01156 public:
01157 RTP_Encoding();
01158 virtual ~RTP_Encoding();
01159 virtual void ApplyStringOptions(const PStringToString & ) {}
01160 virtual void OnStart(RTP_Session & _rtpSession);
01161 virtual void OnFinish();
01162 virtual RTP_Session::SendReceiveStatus OnSendData(RTP_DataFrame & frame);
01163 virtual PBoolean WriteData(RTP_DataFrame & frame, bool oob);
01164 virtual PBoolean WriteDataPDU(RTP_DataFrame & frame);
01165 virtual RTP_Session::SendReceiveStatus OnSendControl(RTP_ControlFrame & frame, PINDEX & len);
01166 virtual RTP_Session::SendReceiveStatus ReadDataPDU(RTP_DataFrame & frame);
01167 virtual RTP_Session::SendReceiveStatus OnReceiveData(RTP_DataFrame & frame);
01168 virtual RTP_Session::SendReceiveStatus OnReadTimeout(RTP_DataFrame & frame);
01169 virtual PBoolean ReadData(RTP_DataFrame & frame, PBoolean loop);
01170 virtual int WaitForPDU(PUDPSocket & dataSocket, PUDPSocket & controlSocket, const PTimeInterval &);
01171
01172 PMutex mutex;
01173 unsigned refCount;
01174
01175 protected:
01176 RTP_UDP * rtpUDP;
01177 };
01178
01179 PFACTORY_LOAD(RTP_Encoding);
01180
01181
01183
01184 class SecureRTP_UDP : public RTP_UDP
01185 {
01186 PCLASSINFO(SecureRTP_UDP, RTP_UDP);
01187
01188 public:
01193 SecureRTP_UDP(
01194 const Params & options
01195 );
01196
01198 ~SecureRTP_UDP();
01199
01200 virtual void SetSecurityMode(OpalSecurityMode * srtpParms);
01201 virtual OpalSecurityMode * GetSecurityParms() const;
01202
01203 protected:
01204 OpalSecurityMode * securityParms;
01205 };
01206
01207 #endif // OPAL_RTP_RTP_H
01208