1 |
/***************************************************************************
|
2 |
ep.cxx
|
3 |
|
4 |
Copyright (c) 2002-2003 Vladimir Toncar
|
5 |
|
6 |
The contents of this file are subject to the Mozilla Public License
|
7 |
Version 1.1 (the "License"); you may not use this file except in
|
8 |
compliance with the License. You may obtain a copy of the License at
|
9 |
http://www.mozilla.org/MPL/
|
10 |
|
11 |
Software distributed under the License is distributed on an "AS IS"
|
12 |
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
|
13 |
See the License for the specific language governing rights and
|
14 |
limitations under the License.
|
15 |
|
16 |
The Original Code is oh323tut.
|
17 |
|
18 |
The Initial Developer of the Original Code is Vladimir Toncar.
|
19 |
All Rights Reserved.
|
20 |
|
21 |
Contributor(s): ______________________________________.
|
22 |
|
23 |
***************************************************************************/
|
24 |
|
25 |
#include <ptlib.h>
|
26 |
#include "ep.h"
|
27 |
#include "nullchan.h"
|
28 |
#include "wavchan.h"
|
29 |
|
30 |
|
31 |
// ***********************************************************************
|
32 |
|
33 |
MyEndPoint::MyEndPoint(const ProgConf & conf) : progConf(conf)
|
34 |
{}
|
35 |
|
36 |
|
37 |
// ***********************************************************************
|
38 |
|
39 |
MyEndPoint::~MyEndPoint()
|
40 |
{}
|
41 |
|
42 |
|
43 |
// ***********************************************************************
|
44 |
|
45 |
void MyEndPoint::OnConnectionEstablished(H323Connection & connection,
|
46 |
const PString & token)
|
47 |
{
|
48 |
PTRACE(1, "Connection established, token is " << token);
|
49 |
}
|
50 |
|
51 |
|
52 |
// ***********************************************************************
|
53 |
|
54 |
void MyEndPoint::OnConnectionCleared(H323Connection &connection,
|
55 |
const PString &token)
|
56 |
{
|
57 |
PTRACE(1, "Connection cleared, token is " << token);
|
58 |
}
|
59 |
|
60 |
|
61 |
// ***********************************************************************
|
62 |
|
63 |
H323Connection::AnswerCallResponse MyEndPoint::OnAnswerCall(
|
64 |
H323Connection & connection,
|
65 |
const PString & caller,
|
66 |
const H323SignalPDU &,
|
67 |
H323SignalPDU &)
|
68 |
{
|
69 |
PTRACE(1, "Accepting connection from " << caller);
|
70 |
return H323Connection::AnswerCallNow;
|
71 |
}
|
72 |
|
73 |
|
74 |
// ***********************************************************************
|
75 |
|
76 |
bool MyEndPoint::Init()
|
77 |
{
|
78 |
// Set user name
|
79 |
if (!progConf.userAliases.IsEmpty())
|
80 |
{
|
81 |
SetLocalUserName(progConf.userAliases[0]);
|
82 |
for (PINDEX i=1; i<progConf.userAliases.GetSize(); i++)
|
83 |
AddAliasName(progConf.userAliases[i]);
|
84 |
}
|
85 |
|
86 |
//DisableFastStart(true);
|
87 |
//DisableH245Tunneling(true);
|
88 |
//DisableH245inSetup(true);
|
89 |
|
90 |
// Codecs
|
91 |
SpeexNarrow3AudioCapability *speex3Cap;
|
92 |
SetCapability(0, 0, speex3Cap = new SpeexNarrow3AudioCapability());
|
93 |
speex3Cap->SetTxFramesInPacket(5); // For Speex, 1 frame ~ 20 milliseconds
|
94 |
H323_GSM0610Capability * gsmCap;
|
95 |
SetCapability(0, 0, gsmCap = new H323_GSM0610Capability);
|
96 |
gsmCap->SetTxFramesInPacket(4); // For GSM 06.10, 1 frame ~ 20 milliseconds
|
97 |
SetCapability(0, 0, new H323_G711Capability(H323_G711Capability::muLaw) );
|
98 |
SetCapability(0, 0, new H323_G711Capability(H323_G711Capability::ALaw) );
|
99 |
SetCapability(0, 0, new H323_LPC10Capability(*this) );
|
100 |
|
101 |
AddAllUserInputCapabilities(0, 1);
|
102 |
|
103 |
PTRACE(1, "Capabilities:\n" << setprecision(2) << capabilities);
|
104 |
|
105 |
// Start H323 Listener
|
106 |
PIPSocket::Address addr = INADDR_ANY;
|
107 |
H323ListenerTCP *listener = new H323ListenerTCP(*this, addr,
|
108 |
progConf.port);
|
109 |
if (listener == NULL || !StartListener(listener))
|
110 |
{ PError << "Unable to start H323 Listener at port "
|
111 |
<< progConf.port << endl;
|
112 |
if (listener != NULL)
|
113 |
delete listener;
|
114 |
return false;
|
115 |
}
|
116 |
|
117 |
// Gatekeeper registration
|
118 |
bool gkResult = false;
|
119 |
switch (progConf.gkMode)
|
120 |
{
|
121 |
case ProgConf::NoGatekeeper:
|
122 |
gkResult = true;
|
123 |
break;
|
124 |
case ProgConf::RegisterWithGatekeeper:
|
125 |
gkResult = UseGatekeeper(progConf.gkAddr, progConf.gkId);
|
126 |
break;
|
127 |
default:
|
128 |
break;
|
129 |
}
|
130 |
|
131 |
if (!gkResult)
|
132 |
{
|
133 |
PError << "Failed to register with gatekeeper" << endl;
|
134 |
return false;
|
135 |
}
|
136 |
|
137 |
return true;
|
138 |
}
|
139 |
|
140 |
|
141 |
// ***********************************************************************
|
142 |
|
143 |
BOOL MyEndPoint::OpenAudioChannel(H323Connection &connection,
|
144 |
BOOL isEncoding,
|
145 |
unsigned bufferSize,
|
146 |
H323AudioCodec &codec)
|
147 |
{
|
148 |
//codec.SetSilenceDetectionMode(H323AudioCodec::NoSilenceDetection);
|
149 |
if (isEncoding)
|
150 |
{ // send audio direction
|
151 |
WavChannel *ch = new WavChannel(progConf.fileName, connection);
|
152 |
return codec.AttachChannel(ch, true);
|
153 |
}
|
154 |
else
|
155 |
{ // receive audio direction
|
156 |
NullChannel *ch = new NullChannel();
|
157 |
return codec.AttachChannel(ch, true);
|
158 |
}
|
159 |
|
160 |
return false;
|
161 |
}
|
162 |
|
163 |
|
164 |
// ***********************************************************************
|
165 |
|
166 |
BOOL MyEndPoint::OnStartLogicalChannel(H323Connection & connection,
|
167 |
H323Channel & channel)
|
168 |
{
|
169 |
PString dir;
|
170 |
switch (channel.GetDirection())
|
171 |
{
|
172 |
case H323Channel::IsTransmitter :
|
173 |
dir = "sending";
|
174 |
break;
|
175 |
case H323Channel::IsReceiver :
|
176 |
dir = "receiving";
|
177 |
break;
|
178 |
default :
|
179 |
break;
|
180 |
}
|
181 |
|
182 |
PTRACE(1, "Started logical channel " << dir << " "
|
183 |
<< channel.GetCapability() );
|
184 |
return true;
|
185 |
}
|
186 |
|
187 |
|
188 |
// ***********************************************************************
|
189 |
|