?? channels.cxx
字號:
/* * channels.cxx * * H.323 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: channels.cxx,v $ * Revision 1.64 2000/07/14 14:04:49 robertj * Clarified a debug message. * * Revision 1.63 2000/07/14 12:47:36 robertj * Added clarification to some logging messags. * * Revision 1.62 2000/07/13 16:05:47 robertj * Removed time critical priority as it can totally slag a Win98 system. * Fixed trace message displaying mismatched codecs in RTP packet around the wrong way. * * Revision 1.61 2000/07/11 11:15:52 robertj * Fixed bug when terminating RTP receiver and not also terminating transmitter. * * Revision 1.60 2000/06/23 02:04:01 robertj * Increased the priority of the media channels, only relevent for Win32 at this time. * * Revision 1.59 2000/06/15 01:46:15 robertj * Added channel pause (aka mute) functions. * * Revision 1.58 2000/05/18 12:10:50 robertj * Removed all Sleep() calls in codec as timing innacuracies make it unusable. All * codec implementations must thus have timing built into them, usually using I/O. * * Revision 1.57 2000/05/11 23:54:25 craigs * Fixed the Windows fix with another Linux fix. But it worked OK on the Alpha! * * Revision 1.56 2000/05/11 09:56:46 robertj * Win32 compatibility and addition of some extra debugging on codec timing. * * Revision 1.55 2000/05/11 02:27:18 robertj * Added "fail safe" timer sleep on codec writes when on output of jitter buffer. * * Revision 1.54 2000/05/04 11:52:34 robertj * Added Packets Too Late statistics, requiring major rearrangement of jitter * buffer code, not also changes semantics of codec Write() function slightly. * * Revision 1.53 2000/05/02 04:32:26 robertj * Fixed copyright notice comment. * * Revision 1.52 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.51 2000/04/28 13:01:44 robertj * Fixed problem with adjusting tx/rx frame counts in capabilities during fast start. * * Revision 1.50 2000/04/10 19:45:49 robertj * Changed RTP data receive tp be more forgiving, will process packet even if payload type is wrong. * * Revision 1.49 2000/03/31 20:04:28 robertj * Fixed log message for start/end of transmitted talk burst. * * Revision 1.48 2000/03/29 04:36:38 robertj * Improved some trace logging messages. * * Revision 1.47 2000/03/22 01:31:36 robertj * Fixed transmitter loop so codec can return multiple frames (crash in G.711 mode) * * Revision 1.46 2000/03/21 03:58:00 robertj * Fixed stuffed up RTP transmit loop after previous change. * * Revision 1.45 2000/03/21 03:06:49 robertj * Changes to make RTP TX of exact numbers of frames in some codecs. * * Revision 1.44 2000/03/20 20:59:28 robertj * Fixed possible buffer overrun problem in RTP_DataFrames * * Revision 1.43 2000/02/24 00:34:25 robertj * Fixed possible endless loop on channel abort, thanks Yura Ershov * * Revision 1.42 2000/02/04 05:11:19 craigs * Updated for new Makefiles and for new video transmission code * * Revision 1.41 2000/01/13 04:03:45 robertj * Added video transmission * * Revision 1.40 2000/01/08 06:52:10 robertj * Removed invalid assert * * Revision 1.39 1999/12/23 23:02:35 robertj * File reorganision for separating RTP from H.323 and creation of LID for VPB support. * * Revision 1.38 1999/11/22 01:37:31 robertj * Fixed channel closure so OnClosedLogicalChannel() only called if channel was actually started. * * Revision 1.37 1999/11/20 05:35:26 robertj * Extra debugging * * Revision 1.36 1999/11/20 00:53:47 robertj * Fixed ability to have variable sized frames in single RTP packet under G.723.1 * * Revision 1.35 1999/11/19 09:06:25 robertj * Changed to close down logical channel if get a transmit codec error. * * Revision 1.34 1999/11/11 23:28:46 robertj * Added first cut silence detection algorithm. * * Revision 1.33 1999/11/06 11:01:37 robertj * Extra debugging. * * Revision 1.32 1999/11/06 05:37:44 robertj * Complete rewrite of termination of connection to avoid numerous race conditions. * * Revision 1.31 1999/11/01 00:47:46 robertj * Added close of logical channel on write error * * Revision 1.30 1999/10/30 12:38:24 robertj * Added more tracing of channel threads. * * Revision 1.29 1999/10/08 09:59:03 robertj * Rewrite of capability for sending multiple audio frames * * Revision 1.28 1999/10/08 04:58:37 robertj * Added capability for sending multiple audio frames in single RTP packet * * Revision 1.27 1999/09/23 07:25:12 robertj * Added open audio and video function to connection and started multi-frame codec send functionality. * * Revision 1.26 1999/09/21 14:09:02 robertj * Removed warnings when no tracing enabled. * * Revision 1.25 1999/09/18 13:24:38 craigs * Added ability to disable jitter buffer * Added ability to access entire RTP packet in codec Write * * Revision 1.24 1999/09/08 04:05:48 robertj * Added support for video capabilities & codec, still needs the actual codec itself! * * Revision 1.23 1999/09/03 02:17:50 robertj * Added more debugging * * Revision 1.22 1999/08/31 12:34:18 robertj * Added gatekeeper support. * * Revision 1.21 1999/07/16 15:02:51 robertj * Changed jitter buffer to throw away old packets if jitter exceeded. * * Revision 1.20 1999/07/16 00:51:03 robertj * Some more debugging of fast start. * * Revision 1.19 1999/07/15 14:45:35 robertj * Added propagation of codec open error to shut down logical channel. * Fixed control channel start up bug introduced with tunnelling. * * Revision 1.18 1999/07/15 09:04:31 robertj * Fixed some fast start bugs * * Revision 1.17 1999/07/14 06:04:04 robertj * Fixed setting of channel number in fast start. * * Revision 1.16 1999/07/13 09:53:24 robertj * Fixed some problems with jitter buffer and added more debugging. * * Revision 1.15 1999/07/13 02:50:58 craigs * Changed semantics of SetPlayDevice/SetRecordDevice, only descendent * endpoint assumes PSoundChannel devices for audio codec. * * Revision 1.14 1999/07/10 03:01:48 robertj * Removed debugging. * * Revision 1.13 1999/07/09 06:09:49 robertj * Major implementation. An ENORMOUS amount of stuff added everywhere. * * Revision 1.12 1999/06/25 14:19:40 robertj * Fixed termination race condition in logical channel tear down. * * Revision 1.11 1999/06/24 13:32:45 robertj * Fixed ability to change sound device on codec and fixed NM3 G.711 compatibility * * Revision 1.10 1999/06/22 13:49:40 robertj * Added GSM support and further RTP protocol enhancements. * * Revision 1.9 1999/06/14 05:15:55 robertj * Changes for using RTP sessions correctly in H323 Logical Channel context * * Revision 1.8 1999/06/13 12:41:14 robertj * Implement logical channel transmitter. * Fixed H245 connect on receiving call. * * Revision 1.7 1999/06/09 06:18:00 robertj * GCC compatibiltiy. * * Revision 1.6 1999/06/09 05:26:19 robertj * Major restructuring of classes. * * Revision 1.5 1999/06/07 00:54:30 robertj * Displayed error on SetOption for buffer size * * Revision 1.4 1999/06/06 06:06:36 robertj * Changes for new ASN compiler and v2 protocol ASN files. * * Revision 1.3 1999/04/26 06:14:46 craigs * Initial implementation for RTP decoding and lots of stuff * As a whole, these changes are called "First Noise" * * Revision 1.2 1999/02/25 03:26:02 robertj * BeOS compatibility * * Revision 1.1 1999/01/16 01:31:09 robertj * Initial revision * */#include <ptlib.h>#include "channels.h"#include "h323pdu.h"#include "h323.h"#include "h323rtp.h"class H323LogicalChannelThread : public PThread{ PCLASSINFO(H323LogicalChannelThread, PThread) public: H323LogicalChannelThread(H323EndPoint & endpoint, H323Channel & channel, BOOL rx); void Main(); private: H323Channel & channel; BOOL receiver;};#define new PNEW#if !PTRACING // Stuff to remove unused parameters warning#define PTRACE_jitter#define PTRACE_skippedFrameCount#define PTRACE_additionalBuffer#endif/////////////////////////////////////////////////////////////////////////////H323LogicalChannelThread::H323LogicalChannelThread(H323EndPoint & endpoint, H323Channel & c, BOOL rx) : PThread(endpoint.GetChannelThreadStackSize(), NoAutoDeleteThread, HighPriority), channel(c){ receiver = rx; Resume();}void H323LogicalChannelThread::Main(){ if (receiver) channel.Receive(); else channel.Transmit();}/////////////////////////////////////////////////////////////////////////////H323ChannelNumber::H323ChannelNumber(unsigned num, BOOL fromRem){ PAssert(num < 0x10000, PInvalidParameter); number = num; fromRemote = fromRem;}PObject * H323ChannelNumber::Clone() const{ return new H323ChannelNumber(number, fromRemote);}PINDEX H323ChannelNumber::HashFunction() const{ if (fromRemote) return number; return number|0x10000;}void H323ChannelNumber::PrintOn(ostream & strm) const{ strm << (fromRemote ? 'R' : 'T') << '-' << number;}H323ChannelNumber & H323ChannelNumber::operator++(int){ number++; return *this;}/////////////////////////////////////////////////////////////////////////////H323Channel::H323Channel(H323Connection & conn, const H323Capability & cap) : endpoint(conn.GetEndPoint()), connection(conn), capability(cap){ codec = NULL; bandwidthUsed = 0; receiveThread = NULL; transmitThread = NULL; terminating = FALSE; paused = FALSE;}H323Channel::~H323Channel(){ connection.UseBandwidth(bandwidthUsed, FALSE); delete codec;}unsigned H323Channel::GetSessionID() const{ return 0;}void H323Channel::CleanUpOnTermination(){ if (terminating) return; PTRACE(3, "LogChan\tCleaning up " << number); terminating = TRUE; // Signal to the connection that this channel is on the way out if (receiveThread != NULL || transmitThread != NULL) connection.OnClosedLogicalChannel(*this); // If we have a codec, then close it, this allows the transmitThread to be // broken out of any I/O block on reading the codec. if (codec != NULL) codec->Close(); // If we have a receiver thread, wait for it to die. if (receiveThread != NULL) { receiveThread->WaitForTermination(); delete receiveThread; receiveThread = NULL; } // If we have a transmitter thread, wait for it to die. if (transmitThread != NULL) { transmitThread->WaitForTermination(); delete transmitThread; transmitThread = NULL; } PTRACE(3, "LogChan\tCleaned up " << number);}BOOL H323Channel::IsRunning() const{ if (receiveThread != NULL && !receiveThread ->IsTerminated()) return TRUE; if (transmitThread != NULL && !transmitThread->IsTerminated()) return TRUE; return FALSE;}BOOL H323Channel::OnReceivedPDU(const H245_OpenLogicalChannel & /*pdu*/, unsigned & /*errorCode*/){ return TRUE;}BOOL H323Channel::OnReceivedAckPDU(const H245_OpenLogicalChannelAck & /*pdu*/){ return TRUE;}void H323Channel::OnSendOpenAck(const H245_OpenLogicalChannel & /*pdu*/, H245_OpenLogicalChannelAck & /* pdu*/) const{}void H323Channel::OnFlowControl(long bitRateRestriction){ if (codec != NULL) codec->OnFlowControl(bitRateRestriction); else PTRACE(3, "LogChan\tOnFlowControl: " << bitRateRestriction);}void H323Channel::OnMiscellaneousCommand(const H245_MiscellaneousCommand_type & type){ if (codec != NULL) codec->OnMiscellaneousCommand(type);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -