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
00045 class RTP_JitterBuffer;
00046 class PNatMethod;
00047 class OpalSecurityMode;
00048
00050
00051
00052
00053 class RTP_QOS : public PObject
00054 {
00055 PCLASSINFO(RTP_QOS,PObject);
00056 public:
00057 PQoS dataQoS;
00058 PQoS ctrlQoS;
00059 };
00060
00062
00063
00066 class RTP_DataFrame : public PBYTEArray
00067 {
00068 PCLASSINFO(RTP_DataFrame, PBYTEArray);
00069
00070 public:
00071 RTP_DataFrame(PINDEX payloadSize, PINDEX bufferSize = 0);
00072 RTP_DataFrame(const BYTE * data, PINDEX len, PBoolean dynamic = PTrue);
00073
00074 enum {
00075 ProtocolVersion = 2,
00076 MinHeaderSize = 12,
00077
00078 MaxMtuPayloadSize = (576-20-16-12)
00079 };
00080
00081 enum PayloadTypes {
00082 PCMU,
00083 FS1016,
00084 G721,
00085 G726 = G721,
00086 GSM,
00087 G7231,
00088 DVI4_8k,
00089 DVI4_16k,
00090 LPC,
00091 PCMA,
00092 G722,
00093 L16_Stereo,
00094 L16_Mono,
00095 G723,
00096 CN,
00097 MPA,
00098 G728,
00099 DVI4_11k,
00100 DVI4_22k,
00101 G729,
00102 Cisco_CN,
00103
00104 CelB = 25,
00105 JPEG,
00106 H261 = 31,
00107 MPV,
00108 MP2T,
00109 H263,
00110
00111 LastKnownPayloadType,
00112
00113 DynamicBase = 96,
00114 MaxPayloadType = 127,
00115 IllegalPayloadType
00116 };
00117
00118 unsigned GetVersion() const { return (theArray[0]>>6)&3; }
00119
00120 PBoolean GetExtension() const { return (theArray[0]&0x10) != 0; }
00121 void SetExtension(PBoolean ext);
00122
00123 PBoolean GetMarker() const { return (theArray[1]&0x80) != 0; }
00124 void SetMarker(PBoolean m);
00125
00126 bool GetPadding() const { return (theArray[0]&0x20) != 0; }
00127 void SetPadding(bool v) { if (v) theArray[0] |= 0x20; else theArray[0] &= 0xdf; }
00128
00129 unsigned GetPaddingSize() const;
00130
00131 PayloadTypes GetPayloadType() const { return (PayloadTypes)(theArray[1]&0x7f); }
00132 void SetPayloadType(PayloadTypes t);
00133
00134 WORD GetSequenceNumber() const { return *(PUInt16b *)&theArray[2]; }
00135 void SetSequenceNumber(WORD n) { *(PUInt16b *)&theArray[2] = n; }
00136
00137 DWORD GetTimestamp() const { return *(PUInt32b *)&theArray[4]; }
00138 void SetTimestamp(DWORD t) { *(PUInt32b *)&theArray[4] = t; }
00139
00140 DWORD GetSyncSource() const { return *(PUInt32b *)&theArray[8]; }
00141 void SetSyncSource(DWORD s) { *(PUInt32b *)&theArray[8] = s; }
00142
00143 PINDEX GetContribSrcCount() const { return theArray[0]&0xf; }
00144 DWORD GetContribSource(PINDEX idx) const;
00145 void SetContribSource(PINDEX idx, DWORD src);
00146
00147 PINDEX GetHeaderSize() const;
00148
00149 int GetExtensionType() const;
00150 void SetExtensionType(int type);
00151 PINDEX GetExtensionSize() const;
00152 PBoolean SetExtensionSize(PINDEX sz);
00153 BYTE * GetExtensionPtr() const;
00154
00155 PINDEX GetPayloadSize() const { return payloadSize - GetPaddingSize(); }
00156 PBoolean SetPayloadSize(PINDEX sz);
00157 BYTE * GetPayloadPtr() const { return (BYTE *)(theArray+GetHeaderSize()); }
00158
00159 virtual void PrintOn(ostream & strm) const;
00160
00161 protected:
00162 PINDEX payloadSize;
00163
00164 #if PTRACING
00165 friend ostream & operator<<(ostream & o, PayloadTypes t);
00166 #endif
00167 };
00168
00169 PLIST(RTP_DataFrameList, RTP_DataFrame);
00170
00171
00174 class RTP_ControlFrame : public PBYTEArray
00175 {
00176 PCLASSINFO(RTP_ControlFrame, PBYTEArray);
00177
00178 public:
00179 RTP_ControlFrame(PINDEX compoundSize = 2048);
00180
00181 unsigned GetVersion() const { return (BYTE)theArray[compoundOffset]>>6; }
00182
00183 unsigned GetCount() const { return (BYTE)theArray[compoundOffset]&0x1f; }
00184 void SetCount(unsigned count);
00185
00186 enum PayloadTypes {
00187 e_IntraFrameRequest = 192,
00188 e_SenderReport = 200,
00189 e_ReceiverReport,
00190 e_SourceDescription,
00191 e_Goodbye,
00192 e_ApplDefined
00193 };
00194
00195 unsigned GetPayloadType() const { return (BYTE)theArray[compoundOffset+1]; }
00196 void SetPayloadType(unsigned t);
00197
00198 PINDEX GetPayloadSize() const { return 4*(*(PUInt16b *)&theArray[compoundOffset+2]); }
00199 void SetPayloadSize(PINDEX sz);
00200
00201 BYTE * GetPayloadPtr() const;
00202
00203 PBoolean ReadNextPacket();
00204 PBoolean StartNewPacket();
00205 void EndPacket();
00206
00207 PINDEX GetCompoundSize() const;
00208
00209 void Reset(PINDEX size);
00210
00211 #pragma pack(1)
00212 struct ReceiverReport {
00213 PUInt32b ssrc;
00214 BYTE fraction;
00215 BYTE lost[3];
00216 PUInt32b last_seq;
00217 PUInt32b jitter;
00218 PUInt32b lsr;
00219 PUInt32b dlsr;
00220
00221 unsigned GetLostPackets() const { return (lost[0]<<16U)+(lost[1]<<8U)+lost[2]; }
00222 void SetLostPackets(unsigned lost);
00223 };
00224
00225 struct SenderReport {
00226 PUInt32b ntp_sec;
00227 PUInt32b ntp_frac;
00228 PUInt32b rtp_ts;
00229 PUInt32b psent;
00230 PUInt32b osent;
00231 };
00232
00233 enum DescriptionTypes {
00234 e_END,
00235 e_CNAME,
00236 e_NAME,
00237 e_EMAIL,
00238 e_PHONE,
00239 e_LOC,
00240 e_TOOL,
00241 e_NOTE,
00242 e_PRIV,
00243 NumDescriptionTypes
00244 };
00245
00246 struct SourceDescription {
00247 PUInt32b src;
00248 struct Item {
00249 BYTE type;
00250 BYTE length;
00251 char data[1];
00252
00253
00254
00255
00256
00257 unsigned int GetLengthTotal() const {return (unsigned int)(length + 2);}
00258 const Item * GetNextItem() const { return (const Item *)((char *)this + length + 2); }
00259 Item * GetNextItem() { return (Item *)((char *)this + length + 2); }
00260 } item[1];
00261 };
00262
00263 void StartSourceDescription(
00264 DWORD src
00265 );
00266
00267 void AddSourceDescriptionItem(
00268 unsigned type,
00269 const PString & data
00270 );
00271 #pragma pack()
00272
00273 protected:
00274 PINDEX compoundOffset;
00275 PINDEX payloadSize;
00276 };
00277
00278
00279 class RTP_Session;
00280
00282
00283 #if OPAL_STATISTICS
00284
00287 class OpalMediaStatistics : public PObject
00288 {
00289 PCLASSINFO(OpalMediaStatistics, PObject);
00290 public:
00291 OpalMediaStatistics();
00292
00293
00294 PUInt64 m_totalBytes;
00295 unsigned m_totalPackets;
00296 unsigned m_packetsLost;
00297 unsigned m_packetsOutOfOrder;
00298 unsigned m_packetsTooLate;
00299 unsigned m_packetOverruns;
00300 unsigned m_minimumPacketTime;
00301 unsigned m_averagePacketTime;
00302 unsigned m_maximumPacketTime;
00303
00304
00305 unsigned m_averageJitter;
00306 unsigned m_maximumJitter;
00307
00308
00309 unsigned m_totalFrames;
00310 unsigned m_keyFrames;
00311 };
00312
00313 #endif
00314
00315
00320 class RTP_UserData : public PObject
00321 {
00322 PCLASSINFO(RTP_UserData, PObject);
00323
00324 public:
00331 virtual void OnTxStatistics(
00332 const RTP_Session & session
00333 ) const;
00334
00341 virtual void OnRxStatistics(
00342 const RTP_Session & session
00343 ) const;
00344
00345 #if OPAL_VIDEO
00346
00351 virtual void OnTxIntraFrameRequest(
00352 const RTP_Session & session
00353 ) const;
00354
00360 virtual void OnRxIntraFrameRequest(
00361 const RTP_Session & session
00362 ) const;
00363 #endif
00364
00368 virtual void SessionFailing(
00369 RTP_Session & session
00370 );
00371 };
00372
00373 class RTP_Encoding;
00374
00375
00378 class RTP_Session : public PObject
00379 {
00380 PCLASSINFO(RTP_Session, PObject);
00381
00382 public:
00385 struct Params {
00386 Params()
00387 : id(0)
00388 , userData(NULL)
00389 , autoDelete(true)
00390 , isAudio(false)
00391 , remoteIsNAT(false)
00392 { }
00393
00394 PString encoding;
00395 unsigned id;
00396 RTP_UserData * userData;
00397 bool autoDelete;
00398 bool isAudio;
00399 bool remoteIsNAT;
00400 };
00401
00404 RTP_Session(
00405 const Params & options
00406 );
00407
00411 ~RTP_Session();
00413
00425 void SetJitterBufferSize(
00426 unsigned minJitterDelay,
00427 unsigned maxJitterDelay,
00428 unsigned timeUnits = 8,
00429 PINDEX stackSize = 30000
00430 );
00431
00437 unsigned GetJitterBufferSize() const;
00438
00441 unsigned GetJitterTimeUnits() const;
00442
00444 virtual PBoolean ModifyQOS(RTP_QOS * )
00445 { return PFalse; }
00446
00452 virtual PBoolean ReadBufferedData(
00453 RTP_DataFrame & frame
00454 );
00455
00461 virtual PBoolean ReadData(
00462 RTP_DataFrame & frame,
00463 PBoolean loop
00464 ) = 0;
00465
00468 virtual PBoolean WriteData(
00469 RTP_DataFrame & frame
00470 ) = 0;
00471
00475 virtual PBoolean WriteOOBData(
00476 RTP_DataFrame & frame,
00477 bool rewriteTimeStamp = true
00478 );
00479
00482 virtual PBoolean WriteControl(
00483 RTP_ControlFrame & frame
00484 ) = 0;
00485
00488 virtual PBoolean SendReport();
00489
00492 virtual void Close(
00493 PBoolean reading
00494 ) = 0;
00495
00498 virtual void Reopen(
00499 PBoolean isReading
00500 ) = 0;
00501
00504 virtual PString GetLocalHostName() = 0;
00505
00506 #if OPAL_STATISTICS
00507 virtual void GetStatistics(OpalMediaStatistics & statistics, bool receiver) const;
00508 #endif
00509
00510
00513 enum SendReceiveStatus {
00514 e_ProcessPacket,
00515 e_IgnorePacket,
00516 e_AbortTransport
00517 };
00518 virtual SendReceiveStatus OnSendData(RTP_DataFrame & frame);
00519 virtual SendReceiveStatus Internal_OnSendData(RTP_DataFrame & frame);
00520
00521 virtual SendReceiveStatus OnSendControl(RTP_ControlFrame & frame, PINDEX & len);
00522 virtual SendReceiveStatus Internal_OnSendControl(RTP_ControlFrame & frame, PINDEX & len);
00523
00524 virtual SendReceiveStatus OnReceiveData(RTP_DataFrame & frame);
00525 virtual SendReceiveStatus Internal_OnReceiveData(RTP_DataFrame & frame);
00526
00527 virtual SendReceiveStatus OnReceiveControl(RTP_ControlFrame & frame);
00528
00529 class ReceiverReport : public PObject {
00530 PCLASSINFO(ReceiverReport, PObject);
00531 public:
00532 void PrintOn(ostream &) const;
00533
00534 DWORD sourceIdentifier;
00535 DWORD fractionLost;
00536 DWORD totalLost;
00537 DWORD lastSequenceNumber;
00538 DWORD jitter;
00539 PTimeInterval lastTimestamp;
00540 PTimeInterval delay;
00541 };
00542 PARRAY(ReceiverReportArray, ReceiverReport);
00543
00544 class SenderReport : public PObject {
00545 PCLASSINFO(SenderReport, PObject);
00546 public:
00547 void PrintOn(ostream &) const;
00548
00549 DWORD sourceIdentifier;
00550 PTime realTimestamp;
00551 DWORD rtpTimestamp;
00552 DWORD packetsSent;
00553 DWORD octetsSent;
00554 };
00555 virtual void OnRxSenderReport(const SenderReport & sender,
00556 const ReceiverReportArray & reports);
00557 virtual void OnRxReceiverReport(DWORD src,
00558 const ReceiverReportArray & reports);
00559
00560 class SourceDescription : public PObject {
00561 PCLASSINFO(SourceDescription, PObject);
00562 public:
00563 SourceDescription(DWORD src) { sourceIdentifier = src; }
00564 void PrintOn(ostream &) const;
00565
00566 DWORD sourceIdentifier;
00567 POrdinalToString items;
00568 };
00569 PARRAY(SourceDescriptionArray, SourceDescription);
00570 virtual void OnRxSourceDescription(const SourceDescriptionArray & descriptions);
00571
00572 virtual void OnRxGoodbye(const PDWORDArray & sources,
00573 const PString & reason);
00574
00575 virtual void OnRxApplDefined(const PString & type, unsigned subtype, DWORD src,
00576 const BYTE * data, PINDEX size);
00578
00583 unsigned GetSessionID() const { return sessionID; }
00584
00587 bool IsAudio() const { return isAudio; }
00588
00591 void SetAudio(
00592 bool aud
00593 ) { isAudio = aud; }
00594
00597 PString GetCanonicalName() const;
00598
00601 void SetCanonicalName(const PString & name);
00602
00605 PString GetToolName() const;
00606
00609 void SetToolName(const PString & name);
00610
00613 RTP_UserData * GetUserData() const { return userData; }
00614
00617 void SetUserData(
00618 RTP_UserData * data,
00619 PBoolean autoDeleteUserData = PTrue
00620 );
00621
00624 DWORD GetSyncSourceOut() const { return syncSourceOut; }
00625
00628 bool AllowAnySyncSource() const { return allowAnySyncSource; }
00629
00632 void SetAnySyncSource(
00633 bool allow
00634 ) { allowAnySyncSource = allow; }
00635
00638 PBoolean WillIgnoreOutOfOrderPackets() const { return ignoreOutOfOrderPackets; }
00639
00642 void SetIgnoreOutOfOrderPackets(
00643 PBoolean ignore
00644 ) { ignoreOutOfOrderPackets = ignore; }
00645
00648 void SetIgnorePayloadTypeChanges(
00649 PBoolean ignore
00650 ) { ignorePayloadTypeChanges = ignore; }
00651
00654 const PTimeInterval & GetReportTimeInterval() { return reportTimeInterval; }
00655
00658 void SetReportTimeInterval(
00659 const PTimeInterval & interval
00660 ) { reportTimeInterval = interval; }
00661
00664 PTimeInterval GetReportTimer()
00665 { return reportTimer; }
00666
00669 unsigned GetTxStatisticsInterval() { return txStatisticsInterval; }
00670
00673 void SetTxStatisticsInterval(
00674 unsigned packets
00675 );
00676
00679 unsigned GetRxStatisticsInterval() { return rxStatisticsInterval; }
00680
00683 void SetRxStatisticsInterval(
00684 unsigned packets
00685 );
00686
00689 void ClearStatistics();
00690
00693 DWORD GetPacketsSent() const { return packetsSent; }
00694
00697 DWORD GetOctetsSent() const { return octetsSent; }
00698
00701 DWORD GetPacketsReceived() const { return packetsReceived; }
00702
00705 DWORD GetOctetsReceived() const { return octetsReceived; }
00706
00709 DWORD GetPacketsLost() const { return packetsLost; }
00710
00713 DWORD GetPacketsOutOfOrder() const { return packetsOutOfOrder; }
00714
00717 DWORD GetPacketsTooLate() const;
00718
00721 DWORD GetPacketOverruns() const;
00722
00727 DWORD GetAverageSendTime() const { return averageSendTime; }
00728
00733 DWORD GetMarkerRecvCount() const { return markerRecvCount; }
00734
00739 DWORD GetMarkerSendCount() const { return markerSendCount; }
00740
00745 DWORD GetMaximumSendTime() const { return maximumSendTime; }
00746
00751 DWORD GetMinimumSendTime() const { return minimumSendTime; }
00752
00757 DWORD GetAverageReceiveTime() const { return averageReceiveTime; }
00758
00763 DWORD GetMaximumReceiveTime() const { return maximumReceiveTime; }
00764
00769 DWORD GetMinimumReceiveTime() const { return minimumReceiveTime; }
00770
00775 DWORD GetAvgJitterTime() const { return jitterLevel>>7; }
00776
00780 DWORD GetMaxJitterTime() const { return maximumJitterLevel>>7; }
00782
00785 virtual int GetDataSocketHandle() const
00786 { return -1; }
00787 virtual int GetControlSocketHandle() const
00788 { return -1; }
00790
00791 virtual void SetCloseOnBYE(PBoolean v) { closeOnBye = v; }
00792
00797 virtual void SendIntraFrameRequest();
00798
00799 void SetNextSentSequenceNumber(WORD num) { lastSentSequenceNumber = (WORD)(num-1); }
00800
00801 virtual PString GetEncoding() const { return m_encoding; }
00802 virtual void SetEncoding(const PString & newEncoding);
00803
00804 DWORD GetSyncSourceIn() const { return syncSourceIn; }
00805
00806 class EncodingLock
00807 {
00808 public:
00809 EncodingLock(RTP_Session & _session);
00810 ~EncodingLock();
00811
00812 __inline RTP_Encoding * operator->() const { return m_encodingHandler; }
00813
00814 protected:
00815 RTP_Session & session;
00816 RTP_Encoding * m_encodingHandler;
00817 };
00818
00819 friend class EncodingLock;
00820
00821 void SetFailed(bool v)
00822 { failed = v; }
00823
00824 bool HasFailed() const
00825 { return failed; }
00826
00827 void AddFilter(const PNotifier & filter);
00828
00829 protected:
00830 virtual void SendBYE();
00831 void AddReceiverReport(RTP_ControlFrame::ReceiverReport & receiver);
00832 PBoolean InsertReportPacket(RTP_ControlFrame & report);
00833
00834 PString m_encoding;
00835 PMutex m_encodingMutex;
00836 RTP_Encoding * m_encodingHandler;
00837
00838 unsigned sessionID;
00839 bool isAudio;
00840 PString canonicalName;
00841 PString toolName;
00842 RTP_UserData * userData;
00843 PBoolean autoDeleteUserData;
00844 RTP_JitterBuffer * jitter;
00845
00846 PBoolean ignoreOutOfOrderPackets;
00847 DWORD syncSourceOut;
00848 DWORD syncSourceIn;
00849 DWORD lastSentTimestamp;
00850 bool allowAnySyncSource;
00851 bool allowOneSyncSourceChange;
00852 PBoolean allowRemoteTransmitAddressChange;
00853 PBoolean allowSequenceChange;
00854 PTimeInterval reportTimeInterval;
00855 unsigned txStatisticsInterval;
00856 unsigned rxStatisticsInterval;
00857 WORD lastSentSequenceNumber;
00858 WORD expectedSequenceNumber;
00859 PTimeInterval lastSentPacketTime;
00860 PTimeInterval lastReceivedPacketTime;
00861 WORD lastRRSequenceNumber;
00862 PINDEX consecutiveOutOfOrderPackets;
00863
00864 PMutex dataMutex;
00865 DWORD timeStampOffs;
00866 PBoolean oobTimeStampBaseEstablished;
00867 DWORD oobTimeStampOutBase;
00868 PTimeInterval oobTimeStampBase;
00869
00870
00871 DWORD packetsSent;
00872 DWORD rtcpPacketsSent;
00873 DWORD octetsSent;
00874 DWORD packetsReceived;
00875 DWORD octetsReceived;
00876 DWORD packetsLost;
00877 DWORD packetsOutOfOrder;
00878 DWORD averageSendTime;
00879 DWORD maximumSendTime;
00880 DWORD minimumSendTime;
00881 DWORD averageReceiveTime;
00882 DWORD maximumReceiveTime;
00883 DWORD minimumReceiveTime;
00884 DWORD jitterLevel;
00885 DWORD maximumJitterLevel;
00886
00887 DWORD markerSendCount;
00888 DWORD markerRecvCount;
00889
00890 unsigned txStatisticsCount;
00891 unsigned rxStatisticsCount;
00892
00893 DWORD averageSendTimeAccum;
00894 DWORD maximumSendTimeAccum;
00895 DWORD minimumSendTimeAccum;
00896 DWORD averageReceiveTimeAccum;
00897 DWORD maximumReceiveTimeAccum;
00898 DWORD minimumReceiveTimeAccum;
00899 DWORD packetsLostSinceLastRR;
00900 DWORD lastTransitTime;
00901
00902 RTP_DataFrame::PayloadTypes lastReceivedPayloadType;
00903 PBoolean ignorePayloadTypeChanges;
00904
00905 PMutex reportMutex;
00906 PTimer reportTimer;
00907
00908 PBoolean closeOnBye;
00909 PBoolean byeSent;
00910 bool failed;
00911
00912 class Filter : public PObject {
00913 PCLASSINFO(Filter, PObject);
00914 public:
00915 Filter(const PNotifier & n) : notifier(n) { }
00916 PNotifier notifier;
00917 };
00918 PList<Filter> filters;
00919 };
00920
00923 class RTP_UDP : public RTP_Session
00924 {
00925 PCLASSINFO(RTP_UDP, RTP_Session);
00926
00927 public:
00932 RTP_UDP(
00933 const Params & options
00934 );
00935
00937 ~RTP_UDP();
00939
00947 virtual PBoolean ReadData(RTP_DataFrame & frame, PBoolean loop);
00948 virtual PBoolean Internal_ReadData(RTP_DataFrame & frame, PBoolean loop);
00949
00952 virtual PBoolean WriteData(RTP_DataFrame & frame);
00953 virtual PBoolean Internal_WriteData(RTP_DataFrame & frame);
00954
00958 virtual PBoolean WriteOOBData(RTP_DataFrame & frame, bool setTimeStamp = true);
00959
00962 virtual PBoolean WriteControl(RTP_ControlFrame & frame);
00963
00966 virtual void Close(
00967 PBoolean reading
00968 );
00969
00972 virtual PString GetLocalHostName();
00974
00977 virtual PBoolean ModifyQOS(RTP_QOS * rtpqos);
00978
00983 virtual PBoolean Open(
00984 PIPSocket::Address localAddress,
00985 WORD portBase,
00986 WORD portMax,
00987 BYTE ipTypeOfService,
00988 PNatMethod * natMethod = NULL,
00989 RTP_QOS * rtpqos = NULL
00990 );
00992
00995 virtual void Reopen(PBoolean isReading);
00997
01002 virtual PIPSocket::Address GetLocalAddress() const { return localAddress; }
01003
01006 virtual void SetLocalAddress(
01007 const PIPSocket::Address & addr
01008 ) { localAddress = addr; }
01009
01012 PIPSocket::Address GetRemoteAddress() const { return remoteAddress; }
01013
01016 virtual WORD GetLocalDataPort() const { return localDataPort; }
01017
01020 virtual WORD GetLocalControlPort() const { return localControlPort; }
01021
01024 virtual WORD GetRemoteDataPort() const { return remoteDataPort; }
01025
01028 virtual WORD GetRemoteControlPort() const { return remoteControlPort; }
01029
01032 virtual PUDPSocket & GetDataSocket() { return *dataSocket; }
01033
01036 virtual PUDPSocket & GetControlSocket() { return *controlSocket; }
01037
01040 virtual PBoolean SetRemoteSocketInfo(
01041 PIPSocket::Address address,
01042 WORD port,
01043 PBoolean isDataPort
01044 );
01045
01048 virtual void ApplyQOS(
01049 const PIPSocket::Address & addr
01050 );
01052
01053 virtual int GetDataSocketHandle() const
01054 { return dataSocket != NULL ? dataSocket->GetHandle() : -1; }
01055
01056 virtual int GetControlSocketHandle() const
01057 { return controlSocket != NULL ? controlSocket->GetHandle() : -1; }
01058
01059 friend class RTP_Encoding;
01060
01061 virtual int WaitForPDU(PUDPSocket & dataSocket, PUDPSocket & controlSocket, const PTimeInterval & timer);
01062 virtual int Internal_WaitForPDU(PUDPSocket & dataSocket, PUDPSocket & controlSocket, const PTimeInterval & timer);
01063
01064 virtual SendReceiveStatus ReadDataPDU(RTP_DataFrame & frame);
01065 virtual SendReceiveStatus Internal_ReadDataPDU(RTP_DataFrame & frame);
01066
01067 virtual SendReceiveStatus OnReadTimeout(RTP_DataFrame & frame);
01068 virtual SendReceiveStatus Internal_OnReadTimeout(RTP_DataFrame & frame);
01069
01070 virtual SendReceiveStatus ReadControlPDU();
01071 virtual SendReceiveStatus ReadDataOrControlPDU(
01072 BYTE * framePtr,
01073 PINDEX frameSize,
01074 PBoolean fromDataChannel
01075 );
01076
01077 virtual bool WriteDataPDU(RTP_DataFrame & frame);
01078 virtual bool WriteDataOrControlPDU(
01079 const BYTE * framePtr,
01080 PINDEX frameSize,
01081 bool toDataChannel
01082 );
01083
01084
01085 protected:
01086 PIPSocket::Address localAddress;
01087 WORD localDataPort;
01088 WORD localControlPort;
01089
01090 PIPSocket::Address remoteAddress;
01091 WORD remoteDataPort;
01092 WORD remoteControlPort;
01093
01094 PIPSocket::Address remoteTransmitAddress;
01095
01096 PUDPSocket * dataSocket;
01097 PUDPSocket * controlSocket;
01098
01099 bool shutdownRead;
01100 bool shutdownWrite;
01101 bool appliedQOS;
01102 bool remoteIsNAT;
01103 bool localHasNAT;
01104 bool first;
01105 int badTransmitCounter;
01106 PTime badTransmitStart;
01107 };
01108
01110
01111 class RTP_UDP;
01112
01113 class RTP_Encoding
01114 {
01115 public:
01116 RTP_Encoding();
01117 virtual ~RTP_Encoding();
01118 virtual void OnStart(RTP_Session & _rtpSession);
01119 virtual void OnFinish();
01120 virtual RTP_Session::SendReceiveStatus OnSendData(RTP_DataFrame & frame);
01121 virtual PBoolean WriteData(RTP_DataFrame & frame);
01122 virtual PBoolean WriteDataPDU(RTP_DataFrame & frame);
01123 virtual RTP_Session::SendReceiveStatus OnSendControl(RTP_ControlFrame & frame, PINDEX & len);
01124 virtual RTP_Session::SendReceiveStatus ReadDataPDU(RTP_DataFrame & frame);
01125 virtual RTP_Session::SendReceiveStatus OnReceiveData(RTP_DataFrame & frame);
01126 virtual RTP_Session::SendReceiveStatus OnReadTimeout(RTP_DataFrame & frame);
01127 virtual PBoolean ReadData(RTP_DataFrame & frame, PBoolean loop);
01128 virtual int WaitForPDU(PUDPSocket & dataSocket, PUDPSocket & controlSocket, const PTimeInterval &);
01129
01130 PMutex mutex;
01131 unsigned refCount;
01132
01133 protected:
01134 RTP_UDP * rtpUDP;
01135 };
01136
01138
01139 class SecureRTP_UDP : public RTP_UDP
01140 {
01141 PCLASSINFO(SecureRTP_UDP, RTP_UDP);
01142
01143 public:
01148 SecureRTP_UDP(
01149 const Params & options
01150 );
01151
01153 ~SecureRTP_UDP();
01154
01155 virtual void SetSecurityMode(OpalSecurityMode * srtpParms);
01156 virtual OpalSecurityMode * GetSecurityParms() const;
01157
01158 protected:
01159 OpalSecurityMode * securityParms;
01160 };
01161
01162 #endif // OPAL_RTP_RTP_H
01163