📄 rtp.cxx
字号:
/*
* rtp.cxx
*
* RTP protocol handler
*
* Open H323 Library
*
* Copyright (c) 1998-2000 Equivalence Pty. Ltd.
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Open H323 Library.
*
* The Initial Developer of the Original Code is Equivalence Pty. Ltd.
*
* Portions of this code were written with the assisance of funding from
* Vovida Networks, Inc. http://www.vovida.com.
*
* Contributor(s): ______________________________________.
*
* $Log: rtp.cxx,v $
* Revision 1.11 2007/07/15 07:50:06 joegenbaclor
* tidying up resource counters
*
* Revision 1.10 2007/05/07 06:00:19 joegenbaclor
* Removed DiffShift in RTP. It is not compatible with bytes GT 127
*
* Revision 1.9 2007/04/10 06:13:55 joegenbaclor
* Added new Encryption Mode
*
* Revision 1.8 2007/02/07 09:32:01 joegenbaclor
* Added capability to set a temporary remote socket info for sessions with still to
* be known bindings.
*
* Revision 1.7 2006/11/10 08:10:51 rcolobong
* Use ParserTools GetDefaultHashKey1 and GetDefaultHashKey2 in XORHash rather than using the MACRO GS_HASH_KEY_1/GS_HASH_KEY_2
*
* Revision 1.6 2006/10/15 16:07:44 joegenbaclor
* Reverted revision 1.5. Its causing some unexplained crashes in windows
*
* Revision 1.5 2006/09/26 06:18:55 joegenbaclor
* Changed socket read size from frmae.GetSize() to static value of 1024
*
* Revision 1.4 2006/07/06 05:38:12 joegenbaclor
* Final last minute changes to CBCOM hash support
*
* Revision 1.3 2006/07/04 00:38:42 joegenbaclor
* Added Grandstream CBCom support for RTP Sessions
*
* Revision 1.2 2006/06/28 14:15:02 joegenbaclor
* Bulk commit for Media Proxy functionalities for OpenB2BUA
* Marks a minor version upgrade from 1.0.2 to 1.0.3
*
* Revision 1.1 2006/06/26 03:03:54 joegenbaclor
* I have decided to include the latest development realease of OPAL tagged Deimos Devel 1 (June 8 2006) as inegrated classes to opensipstack to avoid future version conflicts due to the fast pace in OPAL development. This move is also aimed to reduce the size of projects using OPAL componets such as the soon to be relased OpenSIPPhone.
*
* Revision 2.31 2006/06/05 20:12:48 dsandras
* Prevent infinite loop when being unable to write to the control port of the
* RTP session. Fixes Ekiga #339306.
*
* Revision 2.30 2006/04/30 16:41:14 dsandras
* Allow exactly one sequence change after a call to SetRemoteSocketInfo. Fixes
* Ekiga bug #339866.
*
* Revision 2.29 2006/03/28 11:20:22 dsandras
* If STUN can not create a socket pair for RTP/RTCP, create separate sockets
* and continue. At worse, RTCP won't be received. The SIP part could reuse
* the RTCP port (different from RTP port + 1) in its SDP if required.
*
* Revision 2.28 2006/02/02 07:03:44 csoutheren
* Added extra logging of first outgoing RTP packet
*
* Revision 2.27 2006/01/24 23:31:07 dsandras
* Fixed bug.
*
* Revision 2.26 2006/01/22 21:53:23 dsandras
* Fail when STUN needs to be used and can not be used.
*
* Revision 2.25 2005/12/30 14:29:15 dsandras
* Removed the assumption that the jitter will contain a 8 kHz signal.
*
* Revision 2.24 2005/11/29 11:50:20 dsandras
* Use PWaitAndSignal so that it works even if no AddSession follows the UseSession. Added missing ignoreOtherSources check.
*
* Revision 2.23 2005/11/22 22:37:57 dsandras
* Reverted the previous change as the bug was triggered by a change in PWLIB.
*
* Revision 2.22 2005/11/20 20:56:35 dsandras
* Allow UseSession to be used and fail without requiring a consecutive AddSession.
*
* Revision 2.21 2005/10/20 20:27:38 dsandras
* Better handling of dynamic RTP session IP address changes.
*
* Revision 2.20 2005/08/04 17:17:08 dsandras
* Fixed remote address change of an established RTP Session.
*
* Revision 2.19 2005/04/11 17:34:57 dsandras
* Added support for dynamic sequence changes in case of Re-INVITE.
*
* Revision 2.18 2005/04/10 21:17:05 dsandras
* Added support for remote address and SyncSource changes during an active RTP Session.
*
* Revision 2.17 2005/01/16 23:07:35 csoutheren
* Fixed problem with IPv6 INADDR_ANY
*
* Revision 2.16 2004/04/26 05:37:13 rjongbloed
* Allowed for selectable auto deletion of RTP user data attached to an RTP session.
*
* Revision 2.15 2004/03/02 10:02:46 rjongbloed
* Added check for unusual error in reading UDP socket, thanks Michael Smith
*
* Revision 2.14 2004/03/02 09:57:54 rjongbloed
* Fixed problems with recent changes to RTP UseSession() function which broke it for H.323
*
* Revision 2.13 2004/02/19 10:47:06 rjongbloed
* Merged OpenH323 version 1.13.1 changes.
*
* Revision 2.12 2003/01/07 04:39:53 robertj
* Updated to OpenH323 v1.11.2
*
* Revision 2.11 2002/11/10 11:33:20 robertj
* Updated to OpenH323 v1.10.3
*
* Revision 2.10 2002/10/09 04:28:10 robertj
* Added session ID to soem trace logs, thanks Ted Szoczei
*
* Revision 2.9 2002/09/04 06:01:49 robertj
* Updated to OpenH323 v1.9.6
*
* Revision 2.8 2002/07/01 04:56:33 robertj
* Updated to OpenH323 v1.9.1
*
* Revision 2.7 2002/04/10 03:10:39 robertj
* Added referential (container) copy functions to session manager class.
*
* Revision 2.6 2002/02/11 09:32:13 robertj
* Updated to openH323 v1.8.0
*
* Revision 2.5 2002/01/14 06:35:58 robertj
* Updated to OpenH323 v1.7.9
*
* Revision 2.4 2002/01/14 02:24:06 robertj
* Fixed possible divide by zero error in statistics.
*
* Revision 2.3 2001/12/07 08:52:28 robertj
* Used new const PWaitAndSignal
*
* Revision 2.2 2001/11/14 06:20:40 robertj
* Changed sending of control channel reports to be timer based.
*
* Revision 2.1 2001/10/05 00:22:14 robertj
* Updated to PWLib 1.2.0 and OpenH323 1.7.0
*
* Revision 2.0 2001/07/27 15:48:25 robertj
* Conversion of OpenH323 to Open Phone Abstraction Library (OPAL)
*
* Revision 1.92 2004/02/09 11:17:50 rjongbloed
* Improved check for compound RTCP packets so does not possibly acess
* memory beyond that allocated in packet. Pointed out by Paul Slootman
*
* Revision 1.91 2003/10/28 22:35:21 dereksmithies
* Fix warning about possible use of unitialized variable.
*
* Revision 1.90 2003/10/27 06:03:39 csoutheren
* Added support for QoS
* Thanks to Henry Harrison of AliceStreet
*
* Revision 1.89 2003/10/09 09:47:45 csoutheren
* Fixed problem with re-opening RTP half-channels under unusual
* circumstances. Thanks to Damien Sandras
*
* Revision 1.88 2003/05/02 04:57:47 robertj
* Added header extension support to RTP data frame class.
*
* Revision 1.87 2003/02/07 00:30:21 robertj
* Changes for bizarre usage of RTP code outside of scope of H.323 specs.
*
* Revision 1.86 2003/02/04 23:50:06 robertj
* Changed trace log for RTP session creation to show local address.
*
* Revision 1.85 2003/02/04 07:06:42 robertj
* Added STUN support.
*
* Revision 1.84 2003/01/07 06:32:22 robertj
* Fixed faint possibility of getting an error on UDP write caused by ICMP
* unreachable being received when no UDP read is active on the socket. Then
* the UDP write gets the error stopping transmission.
*
* Revision 1.83 2002/11/19 01:48:00 robertj
* Allowed get/set of canonical anme and tool name.
*
* Revision 1.82 2002/11/05 03:32:04 robertj
* Added session ID to trace logs.
* Fixed possible extra wait exiting RTP read loop on close.
*
* Revision 1.81 2002/11/05 01:55:50 robertj
* Added comments about strange mutex usage.
*
* Revision 1.80 2002/10/31 00:47:07 robertj
* Enhanced jitter buffer system so operates dynamically between minimum and
* maximum values. Altered API to assure app writers note the change!
*
* Revision 1.79 2002/09/26 04:01:49 robertj
* Fixed calculation of fraction of packets lost in RR, thanks Awais Ali
*
* Revision 1.78 2002/09/03 06:15:32 robertj
* Added copy constructor/operator for session manager.
*
* Revision 1.77 2002/08/05 10:03:48 robertj
* Cosmetic changes to normalise the usage of pragma interface/implementation.
*
* Revision 1.76 2002/07/23 06:28:16 robertj
* Added statistics call back on first sent or received RTP packet, helps with,
* for example, detecting if remote endpoint has started to send audio.
*
* Revision 1.75 2002/05/28 02:37:55 robertj
* Fixed reading data out of RTCP compound statements.
*
* Revision 1.74 2002/05/21 07:12:39 robertj
* Fixed 100% CPU usage loop for checkin on sending RTCP data if
* have no RTP data transferred at all.
*
* Revision 1.73 2002/05/02 05:58:28 robertj
* Changed the mechanism for sending RTCP reports so that they will continue
* to be sent regardless of if there is any actual data traffic.
* Added support for compound RTCP statements for sender and receiver reports.
*
* Revision 1.72 2002/04/18 05:48:58 robertj
* Fixed problem with new SSRC value being ignored after RTP session has
* been restarted, thanks "Jacky".
*
* Revision 1.71 2002/02/09 02:33:49 robertj
* Improved payload type docuemntation and added Cisco CN.
*
* Revision 1.70 2001/12/20 04:34:56 robertj
* Fixed display of some of the unknown RTP types.
*
* Revision 1.69 2001/09/12 07:48:05 robertj
* Fixed various problems with tracing.
*
* Revision 1.68 2001/09/11 00:21:24 robertj
* Fixed missing stack sizes in endpoint for cleaner thread and jitter thread.
*
* Revision 1.67 2001/09/10 08:24:04 robertj
* Fixed setting of destination RTP address so works with endpoints that
* do not get the OLC packets quite right.
*
* Revision 1.66 2001/07/11 03:23:54 robertj
* Bug fixed where every 65536 PDUs the session thinks it is the first PDU again.
*
* Revision 1.65 2001/07/06 06:32:24 robertj
* Added flag and checks for RTP data having specific SSRC.
* Changed transmitter IP address check so is based on first received
* PDU instead of expecting it to come from the host we are sending to.
*
* Revision 1.64 2001/06/04 13:43:44 robertj
* Fixed I/O block breaker code if RTP session is bound to INADDR_ANY interface.
*
* Revision 1.63 2001/06/04 11:37:50 robertj
* Added thread safe enumeration functions of RTP sessions.
* Added member access functions to UDP based RTP sessions.
*
* Revision 1.62 2001/05/24 01:12:23 robertj
* Fixed sender report timestamp field, thanks Johan Gnosspelius
*
* Revision 1.61 2001/05/08 05:28:02 yurik
* No ifdef _WIN32_WCE anymore - 3+ version of SDK allows it
*
* Revision 1.60 2001/04/24 06:15:50 robertj
* Added work around for strange Cisco bug which suddenly starts sending
* RTP packets beginning at a difference sequence number base.
*
* Revision 1.59 2001/04/02 23:58:24 robertj
* Added jitter calculation to RTP session.
* Added trace of statistics.
*
* Revision 1.58 2001/03/20 07:24:05 robertj
* Changed RTP SDES to have simple host name instead of attempting a
* reverse DNS lookup on IP address as badly configured DNS can cause
* a 30 second delay before audio is sent.
*
* Revision 1.57 2001/03/15 05:45:45 robertj
* Changed, yet again, the setting of RTP info to allow for Cisco idosyncracies.
*
* Revision 1.56 2001/02/21 08:08:26 robertj
* Added more debugging.
*
* Revision 1.55 2001/02/09 05:13:56 craigs
* Added pragma implementation to (hopefully) reduce the executable image size
* under Linux
*
* Revision 1.54 2001/01/28 07:06:59 yurik
* WinCE-port - avoid using of IP_TOS
*
* Revision 1.53 2000/12/18 08:59:20 craigs
* Added ability to set ports
*
* Revision 1.52 2000/09/25 22:27:40 robertj
* Fixed uninitialised variable for lastRRSequenceNumber
*
* Revision 1.51 2000/09/25 01:53:20 robertj
* Fixed MSVC warnings.
*
* Revision 1.50 2000/09/25 01:44:13 robertj
* Fixed possible race condition on shutdown of RTP session with jitter buffer.
*
* Revision 1.49 2000/09/22 00:32:34 craigs
* Added extra logging
* Fixed problems with no fastConnect with tunelling
*
* Revision 1.48 2000/09/21 02:06:07 craigs
* Added handling for endpoints that return conformant, but useless, RTP address
* and port numbers
*
* Revision 1.47 2000/08/17 00:42:39 robertj
* Fixed RTP Goodbye message reason string parsing, thanks Thien Nguyen.
*
* Revision 1.46 2000/05/30 10:35:41 robertj
* Fixed GNU compiler warning.
*
* Revision 1.45 2000/05/30 06:52:26 robertj
* Fixed problem with Cisco restarting sequence numbers when changing H.323 logical channels.
*
* Revision 1.44 2000/05/23 12:57:37 robertj
* Added ability to change IP Type Of Service code from applications.
*
* Revision 1.43 2000/05/12 00:27:35 robertj
* Fixed bug in UseSession() that caused asserts on BSD and possible race condition everywhere.
*
* Revision 1.42 2000/05/04 11:52:35 robertj
* Added Packets Too Late statistics, requiring major rearrangement of jitter
* buffer code, not also changes semantics of codec Write() function slightly.
*
* Revision 1.41 2000/05/02 04:32:27 robertj
* Fixed copyright notice comment.
*
* Revision 1.40 2000/05/01 01:01:49 robertj
* Added flag for what to do with out of orer packets (use if jitter, don't if not).
*
* Revision 1.39 2000/04/30 03:55:09 robertj
* Improved the RTCP messages, epecially reports
*
* Revision 1.38 2000/04/28 12:56:39 robertj
* Fixed transmission of SDES record in RTCP channel.
*
* Revision 1.37 2000/04/19 01:50:05 robertj
* Improved debugging messages.
*
* Revision 1.36 2000/04/13 18:07:39 robertj
* Fixed missing mutex release causing possible deadlocks.
*
* Revision 1.35 2000/04/10 17:40:05 robertj
* Fixed debug output of RTP payload types to allow for unknown numbers.
*
* Revision 1.34 2000/04/05 04:09:24 robertj
* Fixed portability problem with max() macro.
*
* Revision 1.33 2000/04/05 03:17:32 robertj
* Added more RTP statistics gathering and H.245 round trip delay calculation.
*
* Revision 1.32 2000/04/03 18:15:44 robertj
* Added "fractional" part of RTCP status NTP timestamp field.
*
* Revision 1.31 2000/03/23 02:54:57 robertj
* Added sending of SDES control packets.
*
* Revision 1.30 2000/03/20 20:53:42 robertj
* Fixed problem with being able to reopen for reading an RTP_Session (Cisco compatibilty)
*
* Revision 1.29 2000/03/04 12:32:23 robertj
* Added setting of TOS field in IP header to get poor mans QoS on some routers.
*
* Revision 1.28 2000/02/29 13:00:13 robertj
* Added extra statistic display for RTP packets out of order.
*
* Revision 1.27 2000/02/29 02:13:56 robertj
* Fixed RTP receive of both control and data, ignores ECONNRESET/ECONNREFUSED errors.
*
* Revision 1.26 2000/02/27 10:56:24 robertj
* Fixed error in code allowing non-consecutive RTP port numbers coming from broken stacks, thanks Vassili Leonov.
*
* Revision 1.25 2000/02/17 12:07:44 robertj
* Used ne wPWLib random number generator after finding major problem in MSVC rand().
*
* Revision 1.24 2000/01/29 07:10:20 robertj
* Fixed problem with RTP transmit to host that is not yet ready causing the
* receive side to die with ECONNRESET, thanks Ian MacDonald
*
* Revision 1.23 2000/01/20 05:57:46 robertj
* Added extra flexibility in receiving incorrectly formed OpenLogicalChannel PDU's
*
* Revision 1.22 2000/01/14 00:31:40 robertj
* Bug fix for RTP port allocation (MSVC optimised version), Thanks to Ian MacDonald.
*
* Revision 1.21 1999/12/30 09:14:49 robertj
* Changed payload type functions to use enum.
*
* Revision 1.20 1999/12/23 23:02:36 robertj
* File reorganision for separating RTP from H.323 and creation of LID for VPB support.
*
* Revision 1.19 1999/11/29 04:50:11 robertj
* Added adaptive threshold calculation to silence detection.
*
* Revision 1.18 1999/11/22 00:09:59 robertj
* Fixed error in RTP transmit rewrite for ternary state, didn't transmit at all!
*
* Revision 1.17 1999/11/20 05:35:48 robertj
* Fixed possibly I/O block in RTP read loops.
*
* Revision 1.16 1999/11/19 13:13:31 robertj
* Fixed Windows 95 compatibility issue in shutdown of RTP reading.
*
* Revision 1.15 1999/11/19 10:23:16 robertj
* Fixed local binding of socket to correct address on multi-homes systems.
*
* Revision 1.14 1999/11/19 09:17:15 robertj
* Fixed problems with aycnhronous shut down of logical channels.
*
* Revision 1.13 1999/11/17 03:49:51 robertj
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -