OPAL Version 3.10.2
|
00001 /* 00002 * rfc2833.h 00003 * 00004 * Open Phone Abstraction Library (OPAL) 00005 * Formally known as the Open H323 project. 00006 * 00007 * Copyright (c) 2001 Equivalence Pty. Ltd. 00008 * 00009 * The contents of this file are subject to the Mozilla Public License 00010 * Version 1.0 (the "License"); you may not use this file except in 00011 * compliance with the License. You may obtain a copy of the License at 00012 * http://www.mozilla.org/MPL/ 00013 * 00014 * Software distributed under the License is distributed on an "AS IS" 00015 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 00016 * the License for the specific language governing rights and limitations 00017 * under the License. 00018 * 00019 * The Original Code is Open Phone Abstraction Library. 00020 * 00021 * The Initial Developer of the Original Code is Equivalence Pty. Ltd. 00022 * 00023 * Contributor(s): ______________________________________. 00024 * 00025 * $Revision: 26128 $ 00026 * $Author: rjongbloed $ 00027 * $Date: 2011-07-07 21:36:57 -0500 (Thu, 07 Jul 2011) $ 00028 */ 00029 00030 #ifndef OPAL_CODEC_RFC2833_H 00031 #define OPAL_CODEC_RFC2833_H 00032 00033 #ifdef P_USE_PRAGMA 00034 #pragma interface 00035 #endif 00036 00037 #include <opal/buildopts.h> 00038 00039 #include <opal/mediafmt.h> 00040 #include <rtp/rtp.h> 00041 00042 00043 class OpalRTPConnection; 00044 00045 00047 00048 class OpalRFC2833EventsMask : public std::vector<bool> 00049 { 00050 public: 00051 enum { NumEvents = 256 }; 00052 OpalRFC2833EventsMask(bool defaultValue = false); 00053 OpalRFC2833EventsMask(const char * defaultValues); 00054 OpalRFC2833EventsMask & operator&=(const OpalRFC2833EventsMask & other); 00055 friend ostream & operator<<(ostream & strm, const OpalRFC2833EventsMask & mask); 00056 friend istream & operator>>(istream & strm, OpalRFC2833EventsMask & mask); 00057 }; 00058 00059 typedef OpalMediaOptionValue<OpalRFC2833EventsMask> OpalRFC288EventsOption; 00060 const PCaselessString & OpalRFC288EventsName(); 00061 00062 00064 00065 class OpalRFC2833Info : public PObject 00066 { 00067 PCLASSINFO(OpalRFC2833Info, PObject); 00068 public: 00069 // the following values are mandated by RFC 2833 00070 enum NTEEvent { 00071 Digit0 = 0, 00072 Digit1 = 1, 00073 Digit2 = 2, 00074 Digit3 = 3, 00075 Digit4 = 4, 00076 Digit5 = 5, 00077 Digit6 = 6, 00078 Digit7 = 7, 00079 Digit8 = 8, 00080 Digit9 = 9, 00081 Star = 10, 00082 Hash = 11, 00083 A = 12, 00084 B = 13, 00085 C = 14, 00086 D = 15, 00087 Flash = 16, 00088 CED = 32, 00089 CNG = 36 00090 }; 00091 00092 OpalRFC2833Info( 00093 char tone, 00094 unsigned duration = 0, 00095 unsigned timestamp = 0 00096 ); 00097 00098 char GetTone() const { return tone; } 00099 unsigned GetDuration() const { return duration; } 00100 unsigned GetTimestamp() const { return timestamp; } 00101 bool IsToneStart() const { return duration == 0; } 00102 00103 protected: 00104 char tone; 00105 unsigned duration; 00106 unsigned timestamp; 00107 }; 00108 00109 00111 00112 class OpalRFC2833Proto : public PObject { 00113 PCLASSINFO(OpalRFC2833Proto, PObject); 00114 public: 00115 OpalRFC2833Proto( 00116 OpalRTPConnection & conn, 00117 const PNotifier & receiveNotifier, 00118 const OpalMediaFormat & mediaFormat 00119 ); 00120 ~OpalRFC2833Proto(); 00121 00122 virtual bool SendToneAsync( 00123 char tone, 00124 unsigned duration 00125 ); 00126 00127 virtual void OnStartReceive( 00128 char tone, 00129 unsigned timestamp 00130 ); 00131 virtual void OnStartReceive( 00132 char tone 00133 ); 00134 virtual void OnEndReceive( 00135 char tone, 00136 unsigned duration, 00137 unsigned timestamp 00138 ); 00139 00140 const RTP_Session::FilterNotifier & GetReceiveHandler() const { return m_receiveHandler; } 00141 00142 OpalMediaFormat GetTxMediaFormat() const; 00143 OpalMediaFormat GetRxMediaFormat() const; 00144 void SetTxMediaFormat(const OpalMediaFormat & mediaFormat); 00145 void SetRxMediaFormat(const OpalMediaFormat & mediaFormat); 00146 00147 static PINDEX ASCIIToRFC2833(char tone, bool hasNSE); 00148 static char RFC2833ToASCII(PINDEX rfc2833, bool hasNSE); 00149 00150 protected: 00151 void SendAsyncFrame(); 00152 00153 PDECLARE_RTPFilterNotifier(OpalRFC2833Proto, ReceivedPacket); 00154 PDECLARE_NOTIFIER(PTimer, OpalRFC2833Proto, ReceiveTimeout); 00155 PDECLARE_NOTIFIER(PTimer, OpalRFC2833Proto, AsyncTimeout); 00156 00157 OpalRTPConnection & m_connection; 00158 OpalMediaFormat m_baseMediaFormat; 00159 RTP_DataFrame::PayloadTypes m_txPayloadType; 00160 RTP_DataFrame::PayloadTypes m_rxPayloadType; 00161 OpalRFC2833EventsMask m_txEvents; 00162 OpalRFC2833EventsMask m_rxEvents; 00163 PNotifier m_receiveNotifier; 00164 RTP_Session::FilterNotifier m_receiveHandler; 00165 00166 enum { 00167 ReceiveIdle, 00168 ReceiveActive, 00169 ReceiveEnding 00170 } m_receiveState; 00171 00172 BYTE m_receivedTone; 00173 unsigned m_tonesReceived; 00174 PTimer m_receiveTimer; 00175 DWORD m_previousReceivedTimestamp; 00176 00177 enum { 00178 TransmitIdle, 00179 TransmitActive, 00180 TransmitEnding1, 00181 TransmitEnding2, 00182 TransmitEnding3, 00183 } m_transmitState; 00184 00185 RTP_Session * m_rtpSession; 00186 PTimer m_asyncTransmitTimer; 00187 PTimer m_asyncDurationTimer; 00188 DWORD m_transmitTimestamp; 00189 bool m_rewriteTransmitTimestamp; 00190 PTimeInterval m_asyncStart; 00191 BYTE m_transmitCode; 00192 unsigned m_transmitDuration; 00193 00194 PMutex m_mutex; 00195 }; 00196 00197 00198 #endif // OPAL_CODEC_RFC2833_H 00199 00200