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 #include <list>
00047
00048 #include <rtp/metrics.h>
00049
00050 class RTP_JitterBuffer;
00051 class PNatMethod;
00052 class OpalSecurityMode;
00053
00055
00056
00057
00058 class RTP_QOS : public PObject
00059 {
00060 PCLASSINFO(RTP_QOS,PObject);
00061 public:
00062 PQoS dataQoS;
00063 PQoS ctrlQoS;
00064 };
00065
00067
00068
00071 class RTP_DataFrame : public PBYTEArray
00072 {
00073 PCLASSINFO(RTP_DataFrame, PBYTEArray);
00074
00075 public:
00076 RTP_DataFrame(PINDEX payloadSize = 0, PINDEX bufferSize = 0);
00077 RTP_DataFrame(const BYTE * data, PINDEX len, PBoolean dynamic = true);
00078
00079 enum {
00080 ProtocolVersion = 2,
00081 MinHeaderSize = 12,
00082
00083 MaxMtuPayloadSize = (576-20-16-12)
00084 };
00085
00086 enum PayloadTypes {
00087 PCMU,
00088 FS1016,
00089 G721,
00090 G726 = G721,
00091 GSM,
00092 G7231,
00093 DVI4_8k,
00094 DVI4_16k,
00095 LPC,
00096 PCMA,
00097 G722,
00098 L16_Stereo,
00099 L16_Mono,
00100 G723,
00101 CN,
00102 MPA,
00103 G728,
00104 DVI4_11k,
00105 DVI4_22k,
00106 G729,
00107 Cisco_CN,
00108
00109 CelB = 25,
00110 JPEG,
00111 H261 = 31,
00112 MPV,
00113 MP2T,
00114 H263,
00115
00116 T38 = 38,
00117
00118 LastKnownPayloadType,
00119
00120 DynamicBase = 96,
00121 MaxPayloadType = 127,
00122 IllegalPayloadType
00123 };
00124
00125 unsigned GetVersion() const { return (theArray[0]>>6)&3; }
00126
00127 PBoolean GetExtension() const { return (theArray[0]&0x10) != 0; }
00128 void SetExtension(PBoolean ext);
00129
00130 PBoolean GetMarker() const { return (theArray[1]&0x80) != 0; }
00131 void SetMarker(PBoolean m);
00132
00133 bool GetPadding() const { return (theArray[0]&0x20) != 0; }
00134 void SetPadding(bool v) { if (v) theArray[0] |= 0x20; else theArray[0] &= 0xdf; }
00135 BYTE * GetPaddingPtr() const { return (BYTE *)(theArray+m_headerSize+m_payloadSize); }
00136
00137 unsigned GetPaddingSize() const { return m_paddingSize; }
00138 bool SetPaddingSize(PINDEX sz);
00139
00140 PayloadTypes GetPayloadType() const { return (PayloadTypes)(theArray[1]&0x7f); }
00141 void SetPayloadType(PayloadTypes t);
00142
00143 WORD GetSequenceNumber() const { return *(PUInt16b *)&theArray[2]; }
00144 void SetSequenceNumber(WORD n) { *(PUInt16b *)&theArray[2] = n; }
00145
00146 DWORD GetTimestamp() const { return *(PUInt32b *)&theArray[4]; }
00147 void SetTimestamp(DWORD t) { *(PUInt32b *)&theArray[4] = t; }
00148
00149 DWORD GetSyncSource() const { return *(PUInt32b *)&theArray[8]; }
00150 void SetSyncSource(DWORD s) { *(PUInt32b *)&theArray[8] = s; }
00151
00152 PINDEX GetContribSrcCount() const { return theArray[0]&0xf; }
00153 DWORD GetContribSource(PINDEX idx) const;
00154 void SetContribSource(PINDEX idx, DWORD src);
00155
00156 PINDEX GetHeaderSize() const { return m_headerSize; }
00157
00158 int GetExtensionType() const;
00159 void SetExtensionType(int type);
00160 PINDEX GetExtensionSizeDWORDs() const;
00161 bool SetExtensionSizeDWORDs(PINDEX sz);
00162 BYTE * GetExtensionPtr() const;
00163
00164 PINDEX GetPayloadSize() const { return m_payloadSize; }
00165 bool SetPayloadSize(PINDEX sz);
00166 BYTE * GetPayloadPtr() const { return (BYTE *)(theArray+m_headerSize); }
00167
00168 virtual PObject * Clone() const { return new RTP_DataFrame(*this); }
00169 virtual void PrintOn(ostream & strm) const;
00170
00171
00172
00173 bool SetPacketSize(PINDEX sz);
00174
00175 protected:
00176 PINDEX m_headerSize;
00177 PINDEX m_payloadSize;
00178 PINDEX m_paddingSize;
00179
00180 #if PTRACING
00181 friend ostream & operator<<(ostream & o, PayloadTypes t);
00182 #endif
00183 };
00184
00185 PLIST(RTP_DataFrameList, RTP_DataFrame);
00186
00187
00190 class RTP_ControlFrame : public PBYTEArray
00191 {
00192 PCLASSINFO(RTP_ControlFrame, PBYTEArray);
00193
00194 public:
00195 RTP_ControlFrame(PINDEX compoundSize = 2048);
00196
00197 unsigned GetVersion() const { return (BYTE)theArray[compoundOffset]>>6; }
00198
00199 unsigned GetCount() const { return (BYTE)theArray[compoundOffset]&0x1f; }
00200 void SetCount(unsigned count);
00201
00202 enum PayloadTypes {
00203 e_IntraFrameRequest = 192,
00204 e_SenderReport = 200,
00205 e_ReceiverReport = 201,
00206 e_SourceDescription = 202,
00207 e_Goodbye = 203,
00208 e_ApplDefined = 204,
00209 e_TransportLayerFeedBack = 205,
00210 e_PayloadSpecificFeedBack = 206,
00211 e_ExtendedReport = 207
00212 };
00213
00214 unsigned GetPayloadType() const { return (BYTE)theArray[compoundOffset+1]; }
00215 void SetPayloadType(unsigned t);
00216
00217 PINDEX GetPayloadSize() const { return 4*(*(PUInt16b *)&theArray[compoundOffset+2]); }
00218 void SetPayloadSize(PINDEX sz);
00219
00220 BYTE * GetPayloadPtr() const;
00221
00222 PBoolean ReadNextPacket();
00223 PBoolean StartNewPacket();
00224 void EndPacket();
00225
00226 PINDEX GetCompoundSize() const;
00227
00228 void Reset(PINDEX size);
00229
00230 #pragma pack(1)
00231 struct ReceiverReport {
00232 PUInt32b ssrc;
00233 BYTE fraction;
00234 BYTE lost[3];
00235 PUInt32b last_seq;
00236 PUInt32b jitter;
00237 PUInt32b lsr;
00238 PUInt32b dlsr;
00239
00240 unsigned GetLostPackets() const { return (lost[0]<<16U)+(lost[1]<<8U)+lost[2]; }
00241 void SetLostPackets(unsigned lost);
00242 };
00243
00244 struct SenderReport {
00245 PUInt32b ntp_sec;
00246 PUInt32b ntp_frac;
00247 PUInt32b rtp_ts;
00248 PUInt32b psent;
00249 PUInt32b osent;
00250 };
00251
00252 struct ExtendedReport {
00253
00254 BYTE bt;
00255 BYTE type_specific;
00256 PUInt16b length;
00257 PUInt32b ssrc;
00258 BYTE loss_rate;
00259 BYTE discard_rate;
00260 BYTE burst_density;
00261 BYTE gap_density;
00262 PUInt16b burst_duration;
00263 PUInt16b gap_duration;
00264 PUInt16b round_trip_delay;
00265 PUInt16b end_system_delay;
00266 BYTE signal_level;
00267 BYTE noise_level;
00268 BYTE rerl;
00269 BYTE gmin;
00270 BYTE r_factor;
00271 BYTE ext_r_factor;
00272 BYTE mos_lq;
00273 BYTE mos_cq;
00274 BYTE rx_config;
00275 BYTE reserved;
00276 PUInt16b jb_nominal;
00277 PUInt16b jb_maximum;
00278 PUInt16b jb_absolute;
00279 };
00280
00281 enum DescriptionTypes {
00282 e_END,
00283 e_CNAME,
00284 e_NAME,
00285 e_EMAIL,
00286 e_PHONE,
00287 e_LOC,
00288 e_TOOL,
00289 e_NOTE,
00290 e_PRIV,
00291 NumDescriptionTypes
00292 };
00293
00294 struct SourceDescription {
00295 PUInt32b src;
00296 struct Item {
00297 BYTE type;
00298 BYTE length;
00299 char data[1];
00300
00301
00302
00303
00304
00305 unsigned int GetLengthTotal() const {return (unsigned int)(length + 2);}
00306 const Item * GetNextItem() const { return (const Item *)((char *)this + length + 2); }
00307 Item * GetNextItem() { return (Item *)((char *)this + length + 2); }
00308 } item[1];
00309 };
00310
00311 void StartSourceDescription(
00312 DWORD src
00313 );
00314
00315 void AddSourceDescriptionItem(
00316 unsigned type,
00317 const PString & data
00318 );
00319
00320
00321 unsigned GetFbType() const { return (BYTE)theArray[compoundOffset]&0x1f; }
00322 void SetFbType(unsigned type, PINDEX fciSize);
00323
00324 enum PayloadSpecificFbTypes {
00325 e_PictureLossIndication = 1,
00326 e_SliceLostIndication,
00327 e_ReferencePictureSelectionIndication,
00328 e_FullIntraRequest,
00329 e_TemporalSpatialTradeOffRequest,
00330 e_TemporalSpatialTradeOffNotification,
00331 e_VideoBackChannelMessage,
00332 e_ApplicationLayerFbMessage = 15
00333 };
00334
00335 struct FbFCI {
00336 PUInt32b senderSSRC;
00337 PUInt32b mediaSSRC;
00338 };
00339
00340 struct FbFIR {
00341 FbFCI fci;
00342 PUInt32b requestSSRC;
00343 BYTE sequenceNUmber;
00344 };
00345
00346 struct FbTSTO {
00347 FbFCI fci;
00348 PUInt32b requestSSRC;
00349 BYTE sequenceNUmber;
00350 BYTE reserver[2];
00351 BYTE tradeOff;
00352 };
00353
00354 #pragma pack()
00355
00356 protected:
00357 PINDEX compoundOffset;
00358 PINDEX payloadSize;
00359 };
00360
00361
00362 class RTP_Session;
00363
00365
00366 #if OPAL_STATISTICS
00367
00370 class OpalMediaStatistics : public PObject
00371 {
00372 PCLASSINFO(OpalMediaStatistics, PObject);
00373 public:
00374 OpalMediaStatistics();
00375
00376
00377 PUInt64 m_totalBytes;
00378 unsigned m_totalPackets;
00379 unsigned m_packetsLost;
00380 unsigned m_packetsOutOfOrder;
00381 unsigned m_packetsTooLate;
00382 unsigned m_packetOverruns;
00383 unsigned m_minimumPacketTime;
00384 unsigned m_averagePacketTime;
00385 unsigned m_maximumPacketTime;
00386
00387
00388 unsigned m_averageJitter;
00389 unsigned m_maximumJitter;
00390 unsigned m_jitterBufferDelay;
00391
00392
00393 unsigned m_totalFrames;
00394 unsigned m_keyFrames;
00395
00396
00397 #if OPAL_FAX
00398 enum {
00399 FaxNotStarted = -2,
00400 FaxInProgress = -1,
00401 FaxSuccessful = 0,
00402 FaxErrorBase = 1
00403 };
00404 enum FaxCompression {
00405 FaxCompressionUnknown,
00406 FaxCompressionT4_1d,
00407 FaxCompressionT4_2d,
00408 FaxCompressionT6,
00409 };
00410 friend ostream & operator<<(ostream & strm, FaxCompression compression);
00411 struct Fax {
00412 Fax();
00413
00414 int m_result;
00415 char m_phase;
00416 int m_bitRate;
00417 FaxCompression m_compression;
00418 bool m_errorCorrection;
00419 int m_txPages;
00420 int m_rxPages;
00421 int m_totalPages;
00422 int m_imageSize;
00423 int m_resolutionX;
00424 int m_resolutionY;
00425 int m_pageWidth;
00426 int m_pageHeight;
00427 int m_badRows;
00428 int m_mostBadRows;
00429 int m_errorCorrectionRetries;
00430
00431 PString m_stationId;
00432 PString m_errorText;
00433 } m_fax;
00434 #endif
00435 };
00436
00437 #endif
00438
00439
00444 class RTP_UserData : public PObject
00445 {
00446 PCLASSINFO(RTP_UserData, PObject);
00447
00448 public:
00455 virtual void OnTxStatistics(
00456 const RTP_Session & session
00457 ) const;
00458
00465 virtual void OnRxStatistics(
00466 const RTP_Session & session
00467 ) const;
00468
00469 #if OPAL_VIDEO
00470
00475 virtual void OnTxIntraFrameRequest(
00476 const RTP_Session & session
00477 ) const;
00478
00484 virtual void OnRxIntraFrameRequest(
00485 const RTP_Session & session
00486 ) const;
00487 #endif
00488
00492 virtual void SessionFailing(
00493 RTP_Session & session
00494 );
00495 };
00496
00497 class RTP_Encoding;
00498
00499
00502 class RTP_Session : public PObject
00503 {
00504 PCLASSINFO(RTP_Session, PObject);
00505
00506 public:
00509 struct Params {
00510 Params()
00511 : id(0)
00512 , userData(NULL)
00513 , autoDelete(true)
00514 , isAudio(false)
00515 , remoteIsNAT(false)
00516 { }
00517
00518 PString encoding;
00519 unsigned id;
00520 RTP_UserData * userData;
00521 bool autoDelete;
00522 bool isAudio;
00523 bool remoteIsNAT;
00524 };
00525
00528 RTP_Session(
00529 const Params & options
00530 );
00531
00535 ~RTP_Session();
00537
00547 void SetJitterBufferSize(
00548 unsigned minJitterDelay,
00549 unsigned maxJitterDelay,
00550 unsigned timeUnits = 0,
00551 PINDEX packetSize = 2048
00552 );
00553
00559 unsigned GetJitterBufferSize() const;
00560 unsigned GetJitterBufferDelay() const { return GetJitterBufferSize()/GetJitterTimeUnits(); }
00561
00564 unsigned GetJitterTimeUnits() const { return m_timeUnits; }
00565
00567 virtual PBoolean ModifyQOS(RTP_QOS * )
00568 { return false; }
00569
00575 virtual PBoolean ReadBufferedData(
00576 RTP_DataFrame & frame
00577 );
00578
00584 virtual PBoolean ReadData(
00585 RTP_DataFrame & frame
00586 ) = 0;
00587
00590 virtual void FlushData();
00591
00594 virtual PBoolean WriteData(
00595 RTP_DataFrame & frame
00596 ) = 0;
00597
00601 virtual PBoolean WriteOOBData(
00602 RTP_DataFrame & frame,
00603 bool rewriteTimeStamp = true
00604 );
00605
00608 virtual PBoolean WriteControl(
00609 RTP_ControlFrame & frame
00610 ) = 0;
00611
00614 virtual bool Close(
00615 PBoolean reading
00616 ) = 0;
00617
00620 virtual void Reopen(
00621 PBoolean isReading
00622 ) = 0;
00623
00626 virtual PString GetLocalHostName() = 0;
00627
00628 #if OPAL_STATISTICS
00629 virtual void GetStatistics(OpalMediaStatistics & statistics, bool receiver) const;
00630 #endif
00631
00632
00635 enum SendReceiveStatus {
00636 e_ProcessPacket,
00637 e_IgnorePacket,
00638 e_AbortTransport
00639 };
00640 virtual SendReceiveStatus OnSendData(RTP_DataFrame & frame);
00641 virtual SendReceiveStatus Internal_OnSendData(RTP_DataFrame & frame);
00642
00643 virtual SendReceiveStatus OnSendControl(RTP_ControlFrame & frame, PINDEX & len);
00644 virtual SendReceiveStatus Internal_OnSendControl(RTP_ControlFrame & frame, PINDEX & len);
00645
00646 virtual SendReceiveStatus OnReceiveData(RTP_DataFrame & frame);
00647 virtual SendReceiveStatus Internal_OnReceiveData(RTP_DataFrame & frame);
00648
00649 virtual SendReceiveStatus OnReceiveControl(RTP_ControlFrame & frame);
00650
00651 class ReceiverReport : public PObject {
00652 PCLASSINFO(ReceiverReport, PObject);
00653 public:
00654 void PrintOn(ostream &) const;
00655
00656 DWORD sourceIdentifier;
00657 DWORD fractionLost;
00658 DWORD totalLost;
00659 DWORD lastSequenceNumber;
00660 DWORD jitter;
00661 PTimeInterval lastTimestamp;
00662 PTimeInterval delay;
00663 };
00664 PARRAY(ReceiverReportArray, ReceiverReport);
00665
00666 class SenderReport : public PObject {
00667 PCLASSINFO(SenderReport, PObject);
00668 public:
00669 void PrintOn(ostream &) const;
00670
00671 DWORD sourceIdentifier;
00672 PTime realTimestamp;
00673 DWORD rtpTimestamp;
00674 DWORD packetsSent;
00675 DWORD octetsSent;
00676 };
00677
00678 virtual void OnRxSenderReport(const SenderReport & sender,
00679 const ReceiverReportArray & reports);
00680 virtual void OnRxReceiverReport(DWORD src,
00681 const ReceiverReportArray & reports);
00682 virtual void OnReceiverReports(const ReceiverReportArray & reports);
00683
00684 class SourceDescription : public PObject {
00685 PCLASSINFO(SourceDescription, PObject);
00686 public:
00687 SourceDescription(DWORD src) { sourceIdentifier = src; }
00688 void PrintOn(ostream &) const;
00689
00690 DWORD sourceIdentifier;
00691 POrdinalToString items;
00692 };
00693 PARRAY(SourceDescriptionArray, SourceDescription);
00694 virtual void OnRxSourceDescription(const SourceDescriptionArray & descriptions);
00695
00696 virtual void OnRxGoodbye(const PDWORDArray & sources,
00697 const PString & reason);
00698
00699 virtual void OnRxApplDefined(const PString & type, unsigned subtype, DWORD src,
00700 const BYTE * data, PINDEX size);
00701
00702 #if OPAL_RTCP_XR
00703 class ExtendedReport : public PObject {
00704 PCLASSINFO(ExtendedReport, PObject);
00705 public:
00706 void PrintOn(ostream &) const;
00707
00708 DWORD sourceIdentifier;
00709 DWORD lossRate;
00710 DWORD discardRate;
00711 DWORD burstDensity;
00712 DWORD gapDensity;
00713 DWORD roundTripDelay;
00714 DWORD RFactor;
00715 DWORD mosLQ;
00716 DWORD mosCQ;
00717 DWORD jbNominal;
00718 DWORD jbMaximum;
00719 DWORD jbAbsolute;
00720 };
00721 PARRAY(ExtendedReportArray, ExtendedReport);
00722
00723 virtual void OnRxExtendedReport(DWORD src,
00724 const ExtendedReportArray & reports);
00725 #endif
00726
00727
00732 unsigned GetSessionID() const { return sessionID; }
00733
00736 void SetSessionID(unsigned id) { sessionID = id; }
00737
00740 bool IsAudio() const { return isAudio; }
00741
00744 void SetAudio(
00745 bool aud
00746 ) { isAudio = aud; }
00747
00750 PString GetCanonicalName() const;
00751
00754 void SetCanonicalName(const PString & name);
00755
00758 PString GetToolName() const;
00759
00762 void SetToolName(const PString & name);
00763
00766 RTP_UserData * GetUserData() const { return userData; }
00767
00770 void SetUserData(
00771 RTP_UserData * data,
00772 PBoolean autoDeleteUserData = true
00773 );
00774
00777 DWORD GetSyncSourceOut() const { return syncSourceOut; }
00778
00781 bool AllowAnySyncSource() const { return allowAnySyncSource; }
00782
00785 void SetAnySyncSource(
00786 bool allow
00787 ) { allowAnySyncSource = allow; }
00788
00791 void SetIgnorePayloadTypeChanges(
00792 PBoolean ignore
00793 ) { ignorePayloadTypeChanges = ignore; }
00794
00797 const PTimeInterval & GetReportTimeInterval() { return m_reportTimer.GetResetTime(); }
00798
00801 void SetReportTimeInterval(
00802 const PTimeInterval & interval
00803 ) { m_reportTimer.RunContinuous(interval); }
00804
00807 unsigned GetTxStatisticsInterval() { return txStatisticsInterval; }
00808
00811 void SetTxStatisticsInterval(
00812 unsigned packets
00813 );
00814
00817 unsigned GetRxStatisticsInterval() { return rxStatisticsInterval; }
00818
00821 void SetRxStatisticsInterval(
00822 unsigned packets
00823 );
00824
00827 void ClearStatistics();
00828
00831 DWORD GetPacketsSent() const { return packetsSent; }
00832
00835 DWORD GetOctetsSent() const { return octetsSent; }
00836
00839 DWORD GetPacketsReceived() const { return packetsReceived; }
00840
00843 DWORD GetOctetsReceived() const { return octetsReceived; }
00844
00847 DWORD GetPacketsLost() const { return packetsLost; }
00848
00852 DWORD GetPacketsLostByRemote() const { return packetsLostByRemote; }
00853
00856 DWORD GetPacketsOutOfOrder() const { return packetsOutOfOrder; }
00857
00860 DWORD GetPacketsTooLate() const;
00861
00864 DWORD GetPacketOverruns() const;
00865
00870 DWORD GetAverageSendTime() const { return averageSendTime; }
00871
00876 DWORD GetMarkerRecvCount() const { return markerRecvCount; }
00877
00882 DWORD GetMarkerSendCount() const { return markerSendCount; }
00883
00888 DWORD GetMaximumSendTime() const { return maximumSendTime; }
00889
00894 DWORD GetMinimumSendTime() const { return minimumSendTime; }
00895
00900 DWORD GetAverageReceiveTime() const { return averageReceiveTime; }
00901
00906 DWORD GetMaximumReceiveTime() const { return maximumReceiveTime; }
00907
00912 DWORD GetMinimumReceiveTime() const { return minimumReceiveTime; }
00913
00914 enum { JitterRoundingGuardBits = 4 };
00919 DWORD GetAvgJitterTime() const { return (jitterLevel>>JitterRoundingGuardBits)/GetJitterTimeUnits(); }
00920
00924 DWORD GetMaxJitterTime() const { return (maximumJitterLevel>>JitterRoundingGuardBits)/GetJitterTimeUnits(); }
00925
00930 DWORD GetJitterTimeOnRemote() const { return jitterLevelOnRemote/GetJitterTimeUnits(); }
00932
00933 virtual void SetCloseOnBYE(PBoolean v) { closeOnBye = v; }
00934
00939 virtual void SendIntraFrameRequest(bool rfc2032, bool pictureLoss);
00940
00945 virtual void SendTemporalSpatialTradeOff(unsigned tradeOff);
00946
00947 void SetNextSentSequenceNumber(WORD num) { lastSentSequenceNumber = (WORD)(num-1); }
00948
00949 virtual PString GetEncoding() const { return m_encoding; }
00950 virtual void SetEncoding(const PString & newEncoding);
00951
00952 DWORD GetSyncSourceIn() const { return syncSourceIn; }
00953
00954 class EncodingLock
00955 {
00956 public:
00957 EncodingLock(RTP_Session & _session);
00958 ~EncodingLock();
00959
00960 __inline RTP_Encoding * operator->() const { return m_encodingHandler; }
00961
00962 protected:
00963 RTP_Session & session;
00964 RTP_Encoding * m_encodingHandler;
00965 };
00966
00967 friend class EncodingLock;
00968
00969 void SetFailed(bool v)
00970 { failed = v; }
00971
00972 bool HasFailed() const
00973 { return failed; }
00974
00975 typedef PNotifierTemplate<SendReceiveStatus &> FilterNotifier;
00976 #define PDECLARE_RTPFilterNotifier(cls, fn) PDECLARE_NOTIFIER2(RTP_DataFrame, cls, fn, RTP_Session::SendReceiveStatus &)
00977 #define PCREATE_RTPFilterNotifier(fn) PCREATE_NOTIFIER2(fn, RTP_Session::SendReceiveStatus &)
00978
00979 void AddFilter(const FilterNotifier & filter);
00980
00981 #if OPAL_RTCP_XR
00982 const RTCP_XR_Metrics & GetMetrics() const { return m_metrics; }
00983 RTCP_XR_Metrics & GetMetrics() { return m_metrics; }
00984 #endif
00985
00986 virtual void SendBYE();
00987
00988 protected:
00989 void AddReceiverReport(RTP_ControlFrame::ReceiverReport & receiver);
00990
00991 PBoolean InsertReportPacket(RTP_ControlFrame & report);
00992
00993 #if OPAL_RTCP_XR
00994 void InsertExtendedReportPacket(RTP_ControlFrame & report);
00995 void OnRxSenderReportToMetrics(const RTP_ControlFrame & frame, PINDEX offset);
00996 #endif
00997
00998 PString m_encoding;
00999 PMutex m_encodingMutex;
01000 RTP_Encoding * m_encodingHandler;
01001
01002 unsigned sessionID;
01003 bool isAudio;
01004 unsigned m_timeUnits;
01005 PString canonicalName;
01006 PString toolName;
01007 RTP_UserData * userData;
01008 PBoolean autoDeleteUserData;
01009
01010 typedef PSafePtr<RTP_JitterBuffer, PSafePtrMultiThreaded> JitterBufferPtr;
01011 JitterBufferPtr m_jitterBuffer;
01012
01013 DWORD syncSourceOut;
01014 DWORD syncSourceIn;
01015 DWORD lastSentTimestamp;
01016 bool allowAnySyncSource;
01017 bool allowOneSyncSourceChange;
01018 PBoolean allowRemoteTransmitAddressChange;
01019 PBoolean allowSequenceChange;
01020 unsigned txStatisticsInterval;
01021 unsigned rxStatisticsInterval;
01022 WORD lastSentSequenceNumber;
01023 WORD expectedSequenceNumber;
01024 PTimeInterval lastSentPacketTime;
01025 PTimeInterval lastReceivedPacketTime;
01026 PTime lastSRTimestamp;
01027 PTime lastSRReceiveTime;
01028 PTimeInterval delaySinceLastSR;
01029 WORD lastRRSequenceNumber;
01030 bool resequenceOutOfOrderPackets;
01031 unsigned consecutiveOutOfOrderPackets;
01032 PTimeInterval outOfOrderWaitTime;
01033 PTimeInterval outOfOrderPacketTime;
01034
01035 std::list<RTP_DataFrame> m_outOfOrderPackets;
01036 void SaveOutOfOrderPacket(RTP_DataFrame & frame);
01037
01038 PMutex dataMutex;
01039 DWORD timeStampOffs;
01040 PBoolean oobTimeStampBaseEstablished;
01041 DWORD oobTimeStampOutBase;
01042 PTimeInterval oobTimeStampBase;
01043
01044
01045 PTime firstPacketSent;
01046 DWORD packetsSent;
01047 DWORD rtcpPacketsSent;
01048 DWORD octetsSent;
01049 PTime firstPacketReceived;
01050 DWORD packetsReceived;
01051 DWORD senderReportsReceived;
01052 DWORD octetsReceived;
01053 DWORD packetsLost;
01054 DWORD packetsLostByRemote;
01055 DWORD packetsOutOfOrder;
01056 DWORD averageSendTime;
01057 DWORD maximumSendTime;
01058 DWORD minimumSendTime;
01059 DWORD averageReceiveTime;
01060 DWORD maximumReceiveTime;
01061 DWORD minimumReceiveTime;
01062 DWORD jitterLevel;
01063 DWORD jitterLevelOnRemote;
01064 DWORD maximumJitterLevel;
01065
01066 DWORD markerSendCount;
01067 DWORD markerRecvCount;
01068
01069 unsigned txStatisticsCount;
01070 unsigned rxStatisticsCount;
01071
01072 #if OPAL_RTCP_XR
01073
01074 RTCP_XR_Metrics m_metrics;
01075 #endif
01076
01077 DWORD averageSendTimeAccum;
01078 DWORD maximumSendTimeAccum;
01079 DWORD minimumSendTimeAccum;
01080 DWORD averageReceiveTimeAccum;
01081 DWORD maximumReceiveTimeAccum;
01082 DWORD minimumReceiveTimeAccum;
01083 DWORD packetsLostSinceLastRR;
01084 DWORD lastTransitTime;
01085
01086 RTP_DataFrame::PayloadTypes lastReceivedPayloadType;
01087 PBoolean ignorePayloadTypeChanges;
01088
01089 PMutex m_reportMutex;
01090 PTimer m_reportTimer;
01091 PDECLARE_NOTIFIER(PTimer, RTP_Session, SendReport);
01092
01093 PBoolean closeOnBye;
01094 PBoolean byeSent;
01095 bool failed;
01096
01097 list<FilterNotifier> m_filters;
01098 };
01099
01102 class RTP_UDP : public RTP_Session
01103 {
01104 PCLASSINFO(RTP_UDP, RTP_Session);
01105
01106 public:
01111 RTP_UDP(
01112 const Params & options
01113 );
01114
01116 ~RTP_UDP();
01118
01126 virtual PBoolean ReadData(RTP_DataFrame & frame);
01127 virtual PBoolean Internal_ReadData(RTP_DataFrame & frame);
01128
01131 virtual void FlushData();
01132
01135 virtual PBoolean WriteData(RTP_DataFrame & frame);
01136 virtual PBoolean Internal_WriteData(RTP_DataFrame & frame);
01137
01141 virtual PBoolean WriteOOBData(RTP_DataFrame & frame, bool setTimeStamp = true);
01142
01145 virtual PBoolean WriteControl(RTP_ControlFrame & frame);
01146
01149 virtual bool Close(
01150 PBoolean reading
01151 );
01152
01155 virtual PString GetLocalHostName();
01157
01160 virtual PBoolean ModifyQOS(RTP_QOS * rtpqos);
01161
01166 virtual PBoolean Open(
01167 PIPSocket::Address localAddress,
01168 WORD portBase,
01169 WORD portMax,
01170 BYTE ipTypeOfService,
01171 PNatMethod * natMethod = NULL,
01172 RTP_QOS * rtpqos = NULL
01173 );
01175
01178 virtual void Reopen(PBoolean isReading);
01180
01185 virtual PIPSocket::Address GetLocalAddress() const { return localAddress; }
01186
01189 virtual void SetLocalAddress(
01190 const PIPSocket::Address & addr
01191 ) { localAddress = addr; }
01192
01195 PIPSocket::Address GetRemoteAddress() const { return remoteAddress; }
01196
01199 virtual WORD GetLocalDataPort() const { return localDataPort; }
01200
01203 virtual WORD GetLocalControlPort() const { return localControlPort; }
01204
01207 virtual WORD GetRemoteDataPort() const { return remoteDataPort; }
01208
01211 virtual WORD GetRemoteControlPort() const { return remoteControlPort; }
01212
01215 virtual PUDPSocket & GetDataSocket() { return *dataSocket; }
01216
01219 virtual PUDPSocket & GetControlSocket() { return *controlSocket; }
01220
01223 virtual PBoolean SetRemoteSocketInfo(
01224 PIPSocket::Address address,
01225 WORD port,
01226 PBoolean isDataPort
01227 );
01228
01231 virtual void ApplyQOS(
01232 const PIPSocket::Address & addr
01233 );
01235
01236 virtual int GetDataSocketHandle() const
01237 { return dataSocket != NULL ? dataSocket->GetHandle() : -1; }
01238
01239 virtual int GetControlSocketHandle() const
01240 { return controlSocket != NULL ? controlSocket->GetHandle() : -1; }
01241
01242 friend class RTP_Encoding;
01243
01244 virtual int WaitForPDU(PUDPSocket & dataSocket, PUDPSocket & controlSocket, const PTimeInterval & timer);
01245 virtual int Internal_WaitForPDU(PUDPSocket & dataSocket, PUDPSocket & controlSocket, const PTimeInterval & timer);
01246
01247 virtual SendReceiveStatus ReadDataPDU(RTP_DataFrame & frame);
01248 virtual SendReceiveStatus Internal_ReadDataPDU(RTP_DataFrame & frame);
01249
01250 virtual SendReceiveStatus OnReadTimeout(RTP_DataFrame & frame);
01251 virtual SendReceiveStatus Internal_OnReadTimeout(RTP_DataFrame & frame);
01252
01253 virtual SendReceiveStatus ReadControlPDU();
01254 virtual SendReceiveStatus ReadDataOrControlPDU(
01255 BYTE * framePtr,
01256 PINDEX frameSize,
01257 PBoolean fromDataChannel
01258 );
01259
01260 virtual bool WriteDataPDU(RTP_DataFrame & frame);
01261 virtual bool WriteDataOrControlPDU(
01262 const BYTE * framePtr,
01263 PINDEX frameSize,
01264 bool toDataChannel
01265 );
01266
01267 virtual void SetEncoding(const PString & newEncoding);
01268
01269
01270 protected:
01271 PIPSocket::Address localAddress;
01272 WORD localDataPort;
01273 WORD localControlPort;
01274
01275 PIPSocket::Address remoteAddress;
01276 WORD remoteDataPort;
01277 WORD remoteControlPort;
01278
01279 PIPSocket::Address remoteTransmitAddress;
01280
01281 PUDPSocket * dataSocket;
01282 PUDPSocket * controlSocket;
01283
01284 bool shutdownRead;
01285 bool shutdownWrite;
01286 bool appliedQOS;
01287 bool remoteIsNAT;
01288 bool localHasNAT;
01289 bool m_firstControl;
01290 int badTransmitCounter;
01291 PTime badTransmitStart;
01292
01293 PTimer timerWriteDataIdle;
01294 PDECLARE_NOTIFIER(PTimer, RTP_UDP, OnWriteDataIdle);
01295 };
01296
01298
01299 class RTP_UDP;
01300
01301 class RTP_Encoding
01302 {
01303 public:
01304 RTP_Encoding();
01305 virtual ~RTP_Encoding();
01306 virtual void ApplyStringOptions(const PStringToString & ) {}
01307 virtual void OnStart(RTP_Session & _rtpSession);
01308 virtual void OnFinish();
01309 virtual RTP_Session::SendReceiveStatus OnSendData(RTP_DataFrame & frame);
01310 virtual PBoolean WriteData(RTP_DataFrame & frame, bool oob);
01311 virtual PBoolean WriteDataPDU(RTP_DataFrame & frame);
01312 virtual void OnWriteDataIdle() {}
01313 virtual void SetWriteDataIdleTimer(PTimer &) {}
01314 virtual RTP_Session::SendReceiveStatus OnSendControl(RTP_ControlFrame & frame, PINDEX & len);
01315 virtual RTP_Session::SendReceiveStatus ReadDataPDU(RTP_DataFrame & frame);
01316 virtual RTP_Session::SendReceiveStatus OnReceiveData(RTP_DataFrame & frame);
01317 virtual RTP_Session::SendReceiveStatus OnReadTimeout(RTP_DataFrame & frame);
01318 virtual PBoolean ReadData(RTP_DataFrame & frame);
01319 virtual int WaitForPDU(PUDPSocket & dataSocket, PUDPSocket & controlSocket, const PTimeInterval &);
01320
01321 PMutex mutex;
01322 unsigned refCount;
01323
01324 protected:
01325 RTP_UDP * rtpUDP;
01326 };
01327
01328 PFACTORY_LOAD(RTP_Encoding);
01329
01330
01332
01333 class SecureRTP_UDP : public RTP_UDP
01334 {
01335 PCLASSINFO(SecureRTP_UDP, RTP_UDP);
01336
01337 public:
01342 SecureRTP_UDP(
01343 const Params & options
01344 );
01345
01347 ~SecureRTP_UDP();
01348
01349 virtual void SetSecurityMode(OpalSecurityMode * srtpParms);
01350 virtual OpalSecurityMode * GetSecurityParms() const;
01351
01352 protected:
01353 OpalSecurityMode * securityParms;
01354 };
01355
01356 #endif // OPAL_RTP_RTP_H
01357