OPAL  Version 3.18.8
rfc2833.h
Go to the documentation of this file.
1 /*
2  * rfc2833.h
3  *
4  * Open Phone Abstraction Library (OPAL)
5  * Formally known as the Open H323 project.
6  *
7  * Copyright (c) 2001 Equivalence Pty. Ltd.
8  *
9  * The contents of this file are subject to the Mozilla Public License
10  * Version 1.0 (the "License"); you may not use this file except in
11  * compliance with the License. You may obtain a copy of the License at
12  * http://www.mozilla.org/MPL/
13  *
14  * Software distributed under the License is distributed on an "AS IS"
15  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
16  * the License for the specific language governing rights and limitations
17  * under the License.
18  *
19  * The Original Code is Open Phone Abstraction Library.
20  *
21  * The Initial Developer of the Original Code is Equivalence Pty. Ltd.
22  *
23  * Contributor(s): ______________________________________.
24  */
25 
26 #ifndef OPAL_CODEC_RFC2833_H
27 #define OPAL_CODEC_RFC2833_H
28 
29 #ifdef P_USE_PRAGMA
30 #pragma interface
31 #endif
32 
33 #include <opal_config.h>
34 
35 #include <opal/mediafmt.h>
36 #include <rtp/rtp_session.h>
37 
38 
39 class OpalRTPConnection;
40 
41 
43 
44 class OpalRFC2833EventsMask : public std::vector<bool>
45 {
46  public:
47  enum { NumEvents = 256 };
48  OpalRFC2833EventsMask(bool defaultValue = false);
49  OpalRFC2833EventsMask(const char * defaultValues);
51  friend ostream & operator<<(ostream & strm, const OpalRFC2833EventsMask & mask);
52  friend istream & operator>>(istream & strm, OpalRFC2833EventsMask & mask);
53 };
54 
56 const PCaselessString & OpalRFC288EventsName();
57 
58 
60 
61 class OpalRFC2833Info : public PObject
62 {
63  PCLASSINFO(OpalRFC2833Info, PObject);
64  public:
65  // the following values are mandated by RFC 2833
66  enum NTEEvent {
67  Digit0 = 0,
68  Digit1 = 1,
69  Digit2 = 2,
70  Digit3 = 3,
71  Digit4 = 4,
72  Digit5 = 5,
73  Digit6 = 6,
74  Digit7 = 7,
75  Digit8 = 8,
76  Digit9 = 9,
77  Star = 10,
78  Hash = 11,
79  A = 12,
80  B = 13,
81  C = 14,
82  D = 15,
83  Flash = 16,
84  CED = 32,
85  CNG = 36
86  };
87 
89  char tone,
90  unsigned duration = 0,
91  unsigned timestamp = 0
92  );
93 
94  char GetTone() const { return tone; }
95  unsigned GetDuration() const { return duration; }
96  unsigned GetTimestamp() const { return timestamp; }
97  bool IsToneStart() const { return duration == 0; }
98 
99  protected:
100  char tone;
101  unsigned duration;
102  unsigned timestamp;
103 };
104 
105 
107 
108 class OpalRFC2833Proto : public PObject
109 {
110  PCLASSINFO(OpalRFC2833Proto, PObject);
111  public:
113  typedef PNotifierTemplate<NotifyState> Notifier;
115  const Notifier & receiveNotifier,
116  const OpalMediaFormat & mediaFormat
117  );
119 
120  virtual bool SendToneAsync(
121  char tone,
122  unsigned milliseconds
123  );
124 
125  virtual void OnStartReceive(
126  char tone,
127  unsigned timestamp
128  );
129  virtual void OnEndReceive();
130 
131  void UseRTPSession(bool rx, OpalRTPSession * session);
132 
135  void SetTxMediaFormat(const OpalMediaFormat & mediaFormat);
136  void SetRxMediaFormat(const OpalMediaFormat & mediaFormat);
137 
138  static PINDEX ASCIIToRFC2833(char tone, bool hasNSE);
139  static char RFC2833ToASCII(PINDEX rfc2833, bool hasNSE);
140 
141  protected:
142  bool InternalTransmitFrame();
143  bool AbortTransmit();
144  WORD GetTimestampSince(const PTime & when) const;
145 
147  PDECLARE_NOTIFIER(PTimer, OpalRFC2833Proto, ReceiveTimeout);
148  PDECLARE_NOTIFIER(PTimer, OpalRFC2833Proto, TransmitTimeout);
149 
151  // PTs are atomic as mutex usage is inconsistent
152  atomic<RTP_DataFrame::PayloadTypes> m_txPayloadType;
153  atomic<RTP_DataFrame::PayloadTypes> m_rxPayloadType;
158 
160 
161  enum {
167  } m_transmitState;
174 
175  PDECLARE_MUTEX(m_transmitMutex);
176 
182  PDECLARE_MUTEX(m_receiveMutex);
183 
185  P_REMOVE_VIRTUAL_VOID(OnEndReceive(char, unsigned, unsigned));
186 };
187 
188 
189 #endif // OPAL_CODEC_RFC2833_H
190 
191 
static PINDEX ASCIIToRFC2833(char tone, bool hasNSE)
Definition: rfc2833.h:76
Definition: rfc2833.h:67
WORD m_receivedDuration
Definition: rfc2833.h:180
OpalRFC2833Proto(const Notifier &receiveNotifier, const OpalMediaFormat &mediaFormat)
Definition: rtpconn.h:57
virtual void OnEndReceive()
char tone
Definition: rfc2833.h:100
PTimer m_transmitUpdateTimer
Definition: rfc2833.h:168
Definition: rfc2833.h:74
PTimer m_transmitDurationTimer
Definition: rfc2833.h:169
Definition: rfc2833.h:162
Definition: rfc2833.h:82
OpalRFC2833EventsMask & operator&=(const OpalRFC2833EventsMask &other)
unsigned duration
Definition: rfc2833.h:101
bool InternalTransmitFrame()
Definition: mediafmt.h:441
Definition: rfc2833.h:79
Definition: rfc2833.h:71
const PCaselessString & OpalRFC288EventsName()
NotifyState
Definition: rfc2833.h:112
PDECLARE_RTPDataNotifier(OpalRFC2833Proto, ReceivedPacket)
Definition: rfc2833.h:78
Definition: rfc2833.h:72
friend ostream & operator<<(ostream &strm, const OpalRFC2833EventsMask &mask)
PTimer m_receiveTimer
Definition: rfc2833.h:181
virtual void OnStartReceive(char tone, unsigned timestamp)
NTEEvent
Definition: rfc2833.h:66
Definition: rfc2833.h:164
char GetTone() const
Definition: rfc2833.h:94
friend istream & operator>>(istream &strm, OpalRFC2833EventsMask &mask)
void SetRxMediaFormat(const OpalMediaFormat &mediaFormat)
PNotifierTemplate< NotifyState > Notifier
Definition: rfc2833.h:113
PNotifierTemplate< Data & > DataNotifier
Definition: rtp_session.h:249
Definition: rfc2833.h:84
Notifier m_receiveNotifier
Definition: rfc2833.h:156
unsigned timestamp
Definition: rfc2833.h:102
Definition: rfc2833.h:61
OpalRTPSession * m_rtpSession
Definition: rfc2833.h:159
OpalMediaFormat GetTxMediaFormat() const
Definition: rfc2833.h:70
Definition: rfc2833.h:83
void SetTxMediaFormat(const OpalMediaFormat &mediaFormat)
Definition: rfc2833.h:68
Definition: rfc2833.h:75
P_REMOVE_VIRTUAL_VOID(OnStartReceive(char))
const OpalMediaFormat m_baseMediaFormat
Definition: rfc2833.h:150
virtual bool SendToneAsync(char tone, unsigned milliseconds)
Definition: mediafmt.h:806
DWORD m_transmitTimestamp
Definition: rfc2833.h:170
atomic< RTP_DataFrame::PayloadTypes > m_rxPayloadType
Definition: rfc2833.h:153
PDECLARE_NOTIFIER(PTimer, OpalRFC2833Proto, ReceiveTimeout)
void UseRTPSession(bool rx, OpalRTPSession *session)
Definition: rfc2833.h:73
WORD m_transmitDuration
Definition: rfc2833.h:173
OpalRFC2833EventsMask(bool defaultValue=false)
Definition: rtp_session.h:90
PDECLARE_MUTEX(m_transmitMutex)
BYTE m_transmitCode
Definition: rfc2833.h:172
Definition: rfc2833.h:108
OpalMediaFormat GetRxMediaFormat() const
Definition: rfc2833.h:166
static char RFC2833ToASCII(PINDEX rfc2833, bool hasNSE)
DWORD m_receivedTimestamp
Definition: rfc2833.h:179
Definition: rfc2833.h:44
atomic< RTP_DataFrame::PayloadTypes > m_txPayloadType
Definition: rfc2833.h:152
Definition: rfc2833.h:80
Definition: rfc2833.h:85
Definition: rfc2833.h:112
OpalRFC2833EventsMask m_txEvents
Definition: rfc2833.h:154
WORD GetTimestampSince(const PTime &when) const
OpalRFC2833Info(char tone, unsigned duration=0, unsigned timestamp=0)
Definition: rfc2833.h:77
unsigned GetTimestamp() const
Definition: rfc2833.h:96
bool IsToneStart() const
Definition: rfc2833.h:97
Definition: rfc2833.h:81
unsigned GetDuration() const
Definition: rfc2833.h:95
Definition: rfc2833.h:163
Definition: rfc2833.h:112
BYTE m_receivedTone
Definition: rfc2833.h:178
Definition: rfc2833.h:69
bool m_receiveIdle
Definition: rfc2833.h:177
Definition: rfc2833.h:165
Definition: rfc2833.h:47
enum OpalRFC2833Proto::@8 m_transmitState
PTime m_transmitStartTime
Definition: rfc2833.h:171
OpalRFC2833EventsMask m_rxEvents
Definition: rfc2833.h:155
OpalMediaOptionValue< OpalRFC2833EventsMask > OpalRFC288EventsOption
Definition: rfc2833.h:55
OpalRTPSession::DataNotifier m_receiveHandler
Definition: rfc2833.h:157