rfc2833.h
Go to the documentation of this file.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 #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
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 PMutex m_receiveMutex;
00173 BYTE m_receivedTone;
00174 unsigned m_tonesReceived;
00175 PTimer m_receiveTimer;
00176 DWORD m_previousReceivedTimestamp;
00177
00178 enum {
00179 TransmitIdle,
00180 TransmitActive,
00181 TransmitEnding1,
00182 TransmitEnding2,
00183 TransmitEnding3,
00184 } m_transmitState;
00185
00186 PMutex m_sendMutex;
00187 PTimer m_asyncTransmitTimer;
00188 PTimer m_asyncDurationTimer;
00189 DWORD m_transmitTimestamp;
00190 bool m_rewriteTransmitTimestamp;
00191 PTimeInterval m_asyncStart;
00192 BYTE m_transmitCode;
00193 unsigned m_transmitDuration;
00194 };
00195
00196
00197 #endif // OPAL_CODEC_RFC2833_H
00198
00199