# rfc2833.h

Go to the documentation of this file.

    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: 27199 $
    00026  * $Author: rjongbloed $
    00027  * $Date: 2012-03-15 02:19:15 -0500 (Thu, 15 Mar 2012) $
    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_session.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 {
    00114     PCLASSINFO(OpalRFC2833Proto, PObject);
    00115   public:
    00116     OpalRFC2833Proto(
    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     void UseRTPSession(bool rx, OpalRTPSession * session);
    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     OpalMediaFormat             m_baseMediaFormat;
    00158     RTP_DataFrame::PayloadTypes m_txPayloadType;
    00159     RTP_DataFrame::PayloadTypes m_rxPayloadType;
    00160     OpalRFC2833EventsMask       m_txEvents;
    00161     OpalRFC2833EventsMask       m_rxEvents;
    00162     PNotifier                   m_receiveNotifier;
    00163     OpalRTPSession::FilterNotifier m_receiveHandler;
    00164
    00165     enum {
    00166       ReceiveIdle,
    00167       ReceiveActive,
    00168       ReceiveEnding
    00169     } m_receiveState;
    00170
    00171     PMutex   m_receiveMutex;
    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     PMutex           m_sendMutex;
    00186     OpalRTPSession * m_rtpSession;
    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