📄 main.cxx
字号:
if (dir == PSoundChannel::Player) {
if (SetSoundChannelPlayDevice(dev))
return TRUE;
}
else {
if (SetSoundChannelRecordDevice(dev))
return TRUE;
}
cerr << "Device for " << optionName << " (\"" << dev << "\") must be one of:\n";
PStringArray names = PSoundChannel::GetDeviceNames(dir);
for (PINDEX i = 0; i < names.GetSize(); i++)
cerr << " \"" << names[i] << "\"\n";
return FALSE;
}
H323Connection * MyH323EndPoint::CreateConnection(unsigned callReference)
{
return new MyH323Connection(*this, callReference);
}
BOOL MyH323EndPoint::OnIncomingCall(H323Connection & connection,
const H323SignalPDU &,
H323SignalPDU &)
{
if (currentCallToken.IsEmpty())
return TRUE;
if (busyForwardParty.IsEmpty()) {
cout << "Incoming call from \"" << connection.GetRemotePartyName() << "\" rejected, line busy!" << endl;
return FALSE;
}
cout << "Forwarding call to \"" << busyForwardParty << "\"." << endl;
return !connection.ForwardCall(busyForwardParty);
}
H323Connection::AnswerCallResponse
MyH323EndPoint::OnAnswerCall(H323Connection & connection,
const PString & caller,
const H323SignalPDU &,
H323SignalPDU &)
{
currentCallToken = connection.GetCallToken();
if (autoAnswer) {
cout << "Automatically accepting call." << endl;
return H323Connection::AnswerCallNow;
}
cout << "Incoming call from \""
<< caller
<< "\", answer call (Y/n)? "
<< flush;
return H323Connection::AnswerCallPending;
}
BOOL MyH323EndPoint::OnConnectionForwarded(H323Connection & /*connection*/,
const PString & forwardParty,
const H323SignalPDU & /*pdu*/)
{
if (MakeCall(forwardParty, currentCallToken)) {
cout << "Call is being forwarded to host " << forwardParty << endl;
return TRUE;
}
cout << "Error forwarding call to \"" << forwardParty << '"' << endl;
return FALSE;
}
void MyH323EndPoint::OnConnectionEstablished(H323Connection & connection,
const PString & token)
{
currentCallToken = token;
cout << "In call with " << connection.GetRemotePartyName() << endl;
}
void MyH323EndPoint::OnConnectionCleared(H323Connection & connection,
const PString & clearedCallToken)
{
currentCallToken = PString();
if (((MyH323Connection &)connection).IMCall)
return;
PString remoteName = '"' + connection.GetRemotePartyName() + '"';
switch (connection.GetCallEndReason()) {
case H323Connection::EndedByRemoteUser :
cout << remoteName << " has cleared the call";
break;
case H323Connection::EndedByCallerAbort :
cout << remoteName << " has stopped calling";
break;
case H323Connection::EndedByRefusal :
cout << remoteName << " did not accept your call";
break;
case H323Connection::EndedByNoAnswer :
cout << remoteName << " did not answer your call";
break;
case H323Connection::EndedByTransportFail :
cout << "Call with " << remoteName << " ended abnormally";
break;
case H323Connection::EndedByCapabilityExchange :
cout << "Could not find common codec with " << remoteName;
break;
case H323Connection::EndedByNoAccept :
cout << "Did not accept incoming call from " << remoteName;
break;
case H323Connection::EndedByAnswerDenied :
cout << "Refused incoming call from " << remoteName;
break;
case H323Connection::EndedByNoUser :
cout << "Gatekeeper could find user " << remoteName;
break;
case H323Connection::EndedByNoBandwidth :
cout << "Call to " << remoteName << " aborted, insufficient bandwidth.";
break;
case H323Connection::EndedByUnreachable :
cout << remoteName << " could not be reached.";
break;
case H323Connection::EndedByHostOffline :
cout << remoteName << " is not online.";
break;
case H323Connection::EndedByNoEndPoint :
cout << "No phone running for " << remoteName;
break;
case H323Connection::EndedByConnectFail :
cout << "Transport error calling " << remoteName;
break;
default :
cout << "Call with " << remoteName << " completed";
}
PTime connectTime = connection.GetConnectionStartTime();
if (connectTime.GetTimeInSeconds() != 0)
cout << ", duration "
<< setprecision(0) << setw(5)
<< (PTime() - connectTime);
cout << endl;
}
BOOL MyH323EndPoint::OpenAudioChannel(H323Connection & connection,
BOOL isEncoding,
unsigned bufferSize,
H323AudioCodec & codec)
{
if (H323EndPoint::OpenAudioChannel(connection, isEncoding, bufferSize, codec))
return TRUE;
cerr << "Could not open sound device ";
if (isEncoding)
cerr << GetSoundChannelRecordDevice();
else
cerr << GetSoundChannelPlayDevice();
cerr << " - Check permissions or full duplex capability." << endl;
return FALSE;
}
BOOL MyH323EndPoint::OnSendFeatureSet(unsigned id, H225_FeatureSet & Message)
{
return features.SendFeature(id, Message);
}
void MyH323EndPoint::OnReceiveFeatureSet(unsigned id, const H225_FeatureSet & Message)
{
features.ReceiveFeature(id, Message);
}
static const char * IMOID = "1.3.6.1.4.1.17090.0.1";
BOOL MyH323EndPoint::OnSendCallIndependentSupplementaryService(const H323Connection * connection,
H323SignalPDU & pdu)
{
const Q931 & q931 = pdu.GetQ931();
if (q931.GetMessageType() != Q931::SetupMsg)
return FALSE;
/// check to see if
MyH323Connection * con = (MyH323Connection *)connection;
H460_FeatureSet * featset = con->GetFeatureSet();
H460_FeatureID ID = H460_FeatureID(OpalOID(IMOID));
if ((!IMCall) || (!featset->HasFeature(ID)))
return FALSE;
MyH323Connection * conn = (MyH323Connection *)FindConnectionWithLock(con->GetCallToken());
if (conn != NULL) {
conn->SetNonCallConnection(); // Set Flag to specify a Non Connection connection
conn->IMCall = TRUE; // Open Call
conn->IMsession = IMsession; // Flag to specify if a IM session
conn->IMmsg = IMmsg; // IM Message
currentCallToken = connection->GetCallToken();
IMCall = IMsession = FALSE; // Reset flag
conn->Unlock();
}
H225_Setup_UUIE & setup = pdu.m_h323_uu_pdu.m_h323_message_body;
setup.m_conferenceGoal.SetTag(H225_Setup_UUIE_conferenceGoal::e_callIndependentSupplementaryService);
H225_FeatureSet fs;
if (featset->SendFeature(H460_MessageType::e_setup, fs)) {
if (fs.HasOptionalField(H225_FeatureSet::e_supportedFeatures)) {
setup.IncludeOptionalField(H225_Setup_UUIE::e_supportedFeatures);
H225_ArrayOf_FeatureDescriptor & fsn = setup.m_supportedFeatures;
fsn = fs.m_supportedFeatures;
}
return TRUE;
}
return FALSE;
}
BOOL MyH323EndPoint::OnReceiveCallIndependentSupplementaryService(const H323Connection * connection,
const H323SignalPDU & pdu)
{
const Q931 & q931 = pdu.GetQ931();
if (q931.GetMessageType() != Q931::SetupMsg)
return FALSE;
const H225_Setup_UUIE & setup = pdu.m_h323_uu_pdu.m_h323_message_body;
if (!setup.HasOptionalField(H225_Setup_UUIE::e_supportedFeatures))
return FALSE;
PTRACE(6,"MyEP\tReceived Call Independent Supplementary Service");
currentCallToken = connection->GetCallToken();
// Get the FeatureSet
H460_FeatureSet * featset = ((MyH323Connection *)connection)->GetFeatureSet();
H460_FeatureID ID = H460_FeatureID(OpalOID(IMOID));
if (!featset->HasFeature(ID))
return FALSE;
return TRUE;
}
void MyH323EndPoint::SupportsIM(const PString & token)
{
}
void MyH323EndPoint::ReceivedIM(const PString & token, const PString & msg)
{
MyH323Connection * connection = (MyH323Connection *)FindConnectionWithLock(token);
if (connection != NULL) {
cout << "Message Received from "
<< connection->GetRemotePartyName() << endl;
connection->Unlock();
}
cout << " " << msg << endl;
}
void MyH323EndPoint::SendIM(const PString & token, const PString & msg)
{
MyH323Connection * connection = (MyH323Connection *)FindConnectionWithLock(token);
if (connection != NULL) {
if (!connection->IMsession)
connection->IMsession = TRUE;
connection->IMmsg = msg;
H323SignalPDU facilityPDU;
facilityPDU.BuildFacility(*connection, FALSE);
connection->WriteSignalPDU(facilityPDU);
connection->Unlock();
}
}
void MyH323EndPoint::IMOpenSession(const PString & token)
{
MyH323Connection * connection = (MyH323Connection *)FindConnectionWithLock(token);
if (connection != NULL) {
connection->IMsession = TRUE;
H323SignalPDU facilityPDU;
facilityPDU.BuildFacility(*connection, FALSE);
connection->WriteSignalPDU(facilityPDU);
connection->Unlock();
}
}
void MyH323EndPoint::IMCloseSession(const PString & token)
{
MyH323Connection * connection = (MyH323Connection *)FindConnectionWithLock(token);
if (connection != NULL) {
connection->IMsession = FALSE;
H323SignalPDU facilityPDU;
facilityPDU.BuildFacility(*connection, FALSE);
connection->WriteSignalPDU(facilityPDU);
connection->Unlock();
}
}
void MyH323EndPoint::IMSessionOpen(const PString & token)
{
cout << "IM Session Opened" << endl;
}
void MyH323EndPoint::IMSessionClosed(const PString & token)
{
cout << "IM Session Closed" << endl;
}
void MyH323EndPoint::IMMessageSent()
{
cout << "IM Message Sent" << endl;
}
void MyH323EndPoint::IMRegister(const PIPSocket::Address & gateway,
const PString & id,
const PString & pwd)
{
}
void MyH323EndPoint::IMRegistered(const PString & token)
{
}
///////////////////////////////////////////////////////////////
MyH323Connection::MyH323Connection(MyH323EndPoint & ep, unsigned ref)
: H323Connection(ep, ref)
{
IMmsg = PString();
IMsession = FALSE;
IMCall = FALSE;
IMRegID = PString();
IMRegPwd = PString();
IMReg = FALSE;
}
BOOL MyH323Connection::OnStartLogicalChannel(H323Channel & channel)
{
if (!H323Connection::OnStartLogicalChannel(channel))
return FALSE;
cout << "Started logical channel: ";
switch (channel.GetDirection()) {
case H323Channel::IsTransmitter :
cout << "sending ";
break;
case H323Channel::IsReceiver :
cout << "receiving ";
break;
default :
break;
}
cout << channel.GetCapability() << endl;
return TRUE;
}
void MyH323Connection::OnUserInputString(const PString & value)
{
cout << "User input received: \"" << value << '"' << endl;
}
BOOL MyH323Connection::OnSendFeatureSet(unsigned code, H225_FeatureSet & feat) const
{
PTRACE(4,"MyEP\tSend FeatureSet");
return features.SendFeature(code,feat);
}
void MyH323Connection::OnReceiveFeatureSet(unsigned code, const H225_FeatureSet & feat) const
{
features.ReceiveFeature(code, feat);
PTRACE(4,"MyEP\tReceived FeatureSet");
}
// End of File ///////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -