| 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 | capabilities.AddAllCapabilities(0, 0, "SpeexIETFNarrow-8k"); |
| 92 | |
| 93 | H323Capability *gsmCap = H323Capability::Create("GSM-06.10{sw}"); |
| 94 | if (gsmCap != NULL) |
| 95 | { |
| 96 | SetCapability(0, 0, gsmCap); |
| 97 | gsmCap->SetTxFramesInPacket(4); // For GSM 06.10, 1 frame ~ 20 milliseconds |
| 98 | } |
| 99 | |
| 100 | SetCapability(0, 0, new H323_G711Capability(H323_G711Capability::muLaw) ); |
| 101 | SetCapability(0, 0, new H323_G711Capability(H323_G711Capability::ALaw) ); |
| 102 | |
| 103 | AddAllUserInputCapabilities(0, 1); |
| 104 | |
| 105 | PTRACE(1, "Capabilities:\n" << setprecision(2) << capabilities); |
| 106 | |
| 107 | // Start H323 Listener |
| 108 | PIPSocket::Address addr = INADDR_ANY; |
| 109 | H323ListenerTCP *listener = new H323ListenerTCP(*this, addr, |
| 110 | progConf.port); |
| 111 | if (listener == NULL || !StartListener(listener)) |
| 112 | { PError << "Unable to start H323 Listener at port " |
| 113 | << progConf.port << endl; |
| 114 | if (listener != NULL) |
| 115 | delete listener; |
| 116 | return false; |
| 117 | } |
| 118 | |
| 119 | // Gatekeeper registration |
| 120 | bool gkResult = false; |
| 121 | switch (progConf.gkMode) |
| 122 | { |
| 123 | case ProgConf::NoGatekeeper: |
| 124 | gkResult = true; |
| 125 | break; |
| 126 | case ProgConf::RegisterWithGatekeeper: |
| 127 | gkResult = UseGatekeeper(progConf.gkAddr, progConf.gkId); |
| 128 | break; |
| 129 | default: |
| 130 | break; |
| 131 | } |
| 132 | |
| 133 | if (!gkResult) |
| 134 | { |
| 135 | PError << "Failed to register with gatekeeper" << endl; |
| 136 | return false; |
| 137 | } |
| 138 | |
| 139 | return true; |
| 140 | } |
| 141 | |
| 142 | |
| 143 | // *********************************************************************** |
| 144 | |
| 145 | BOOL MyEndPoint::OpenAudioChannel(H323Connection &connection, |
| 146 | BOOL isEncoding, |
| 147 | unsigned bufferSize, |
| 148 | H323AudioCodec &codec) |
| 149 | { |
| 150 | //codec.SetSilenceDetectionMode(H323AudioCodec::NoSilenceDetection); |
| 151 | if (isEncoding) |
| 152 | { // send audio direction |
| 153 | WavChannel *ch = new WavChannel(progConf.fileName, connection); |
| 154 | return codec.AttachChannel(ch, true); |
| 155 | } |
| 156 | else |
| 157 | { // receive audio direction |
| 158 | NullChannel *ch = new NullChannel(); |
| 159 | return codec.AttachChannel(ch, true); |
| 160 | } |
| 161 | |
| 162 | return false; |
| 163 | } |
| 164 | |
| 165 | |
| 166 | // *********************************************************************** |
| 167 | |
| 168 | BOOL MyEndPoint::OnStartLogicalChannel(H323Connection & connection, |
| 169 | H323Channel & channel) |
| 170 | { |
| 171 | PString dir; |
| 172 | switch (channel.GetDirection()) |
| 173 | { |
| 174 | case H323Channel::IsTransmitter : |
| 175 | dir = "sending"; |
| 176 | break; |
| 177 | case H323Channel::IsReceiver : |
| 178 | dir = "receiving"; |
| 179 | break; |
| 180 | default : |
| 181 | break; |
| 182 | } |
| 183 | |
| 184 | PTRACE(1, "Started logical channel " << dir << " " |
| 185 | << channel.GetCapability() ); |
| 186 | return true; |
| 187 | } |
| 188 | |
| 189 | |
| 190 | // *********************************************************************** |
| 191 |