/* MyH323_ExternalRTPChannel */
MyH323_ExternalRTPChannel::MyH323_ExternalRTPChannel(MyH323Connection & connection,
						     const H323Capability & capability,
                                                     Directions direction,
                                                     unsigned id)
 : H323_ExternalRTPChannel::H323_ExternalRTPChannel(connection, capability, direction, id)
{   
	struct rtp_info *info;

	/* Determine the Local (A side) IP Address and port */
	info = on_external_rtp_create(connection.GetCallReference(), (const char *)connection.GetCallToken()); 
	if (!info) {
		cout << "\tERROR: on_external_rtp_create failure" << endl;
		return;
	} else {
		/* Request our peer to send RTP packets to the same address we
		 * use for signalling. We rely on OpenH323 to determine this
		 * address. */
	    	connection.GetSignallingChannel()->GetLocalAddress().GetIpAddress(localIpAddr);
		localPort = info->port;
		/* tell the H.323 stack  */ 
		SetExternalAddress(H323TransportAddress(localIpAddr, localPort), H323TransportAddress(localIpAddr, localPort + 1));
		/* clean up allocated memory */
		free(info);
	}

	/* Get the payload code	*/
	OpalMediaFormat format(capability.GetFormatName(), FALSE);
	payloadCode = format.GetPayloadType();
} 
Example #2
0
BOOL MyH323_ExternalRTPChannel::OnReceivedAckPDU(const H245_H2250LogicalChannelAckParameters & param)
{
       PIPSocket::Address remoteIpAddress;
       WORD remotePort;
       MyH323Connection* conn = (MyH323Connection*) &connection;
	       
       if (h323debug)
       		cout << "\t=-= In OnReceivedAckPDU for call " << connection.GetCallReference() << endl;

       if (H323_ExternalRTPChannel::OnReceivedAckPDU(param)) {
               if (!connection.Lock()) {
		       ast_log(LOG_ERROR,"chan_h323: OnReceivedAckPDU: Could not obtain connection lock");
		       return FALSE;
               }
               /* if RTP hasn't been connected yet */
               if (!conn->AST_RTP_Connected) {
                       H323_ExternalRTPChannel::GetRemoteAddress(remoteIpAddress, remotePort);
                       if (h323debug) {
                                 cout << "\t\tRTP channel id " << sessionID << " parameters:" << endl;
                                 cout << "\t\t-- remoteIpAddress: " << remoteIpAddress << endl;
                                 cout << "\t\t-- remotePort: " << remotePort << endl;
                                 cout << "\t\t-- ExternalIpAddress: " <<  conn->externalIpAddress << endl;
                                 cout << "\t\t-- ExternalPort: " << conn->externalPort << endl;
		       }

		       /* Notify Asterisk of remote RTP information */
		       on_start_logical_channel(connection.GetCallReference(), (const char *)remoteIpAddress.AsString(), remotePort,
                                                  (const char *)conn->GetCallToken());
		       conn->AST_RTP_Connected = TRUE;
               }
               connection.Unlock();
               return TRUE;
       }
       return FALSE;
}
/** The fullAddress parameter is used directly in the MakeCall method so
  * the General form for the fullAddress argument is :
  * [alias@][transport$]host[:port]
  * default values:	alias = the same value as host.
  *					transport = ip.
  *					port = 1720.
  */
int MyH323EndPoint::MakeCall(const PString & dest, PString & token, unsigned int *callReference, call_options_t *opts)
{
	PString fullAddress;
	MyH323Connection * connection;

	/* Determine whether we are using a gatekeeper or not. */
	if (GetGatekeeper()) {
		fullAddress = dest;
		if (h323debug) {
			cout << " -- Making call to " << fullAddress << " using gatekeeper." << endl;
		}
	} else {
		fullAddress = dest; 
		if (h323debug) {
			cout << " -- Making call to " << fullAddress << " without gatekeeper." << endl;
		}
	}
	if (!(connection = (MyH323Connection *)H323EndPoint::MakeCallLocked(fullAddress, token, opts))) {
		if (h323debug) {
			cout << "Error making call to \"" << fullAddress << '"' << endl;
		}
		return 1;
	}
	*callReference = connection->GetCallReference();	

	if (opts->cid_num) {
		connection->ast_cid_num = PString(opts->cid_num);
	}
	if (opts->cid_name) {
		connection->ast_cid_name = PString(opts->cid_name);
		connection->SetLocalPartyName(connection->ast_cid_name);
	}

	connection->dtmfCodec = (RTP_DataFrame::PayloadTypes)opts->dtmfcodec;

	if (h323debug) {
		cout << "\t-- " << GetLocalUserName() << " is calling host " << fullAddress << endl;
		cout << "\t-- Call token is " << (const char *)token << endl;
		cout << "\t-- Call reference is " << *callReference << endl;
		cout << "\t-- DTMF Payload is " << connection->dtmfCodec << endl;
	}
	connection->Unlock(); 	
	return 0;
}
/* alas, this doesn't work :(   */
void h323_native_bridge(const char *token, const char *them, char *capability)
{
	H323Channel *channel;
	MyH323Connection *connection = (MyH323Connection *)endPoint->FindConnectionWithLock(token);
	
	if (!connection) {
		cout << "ERROR: No connection found, this is bad\n";
		return;
	}

	cout << "Native Bridge:  them [" << them << "]" << endl; 

	channel = connection->FindChannel(connection->sessionId, TRUE);
	connection->bridging = TRUE;
	connection->CloseLogicalChannelNumber(channel->GetNumber());
	
	connection->Unlock();
	return;

}
int h323_clear_call(const char *call_token, int cause)
{
	H225_ReleaseCompleteReason dummy;
	H323Connection::CallEndReason r = H323Connection::EndedByLocalUser;
	MyH323Connection *connection;
	const PString currentToken(call_token);

	if (!h323_end_point_exist()) {
		return 1;
	}

	if (cause) {
		r = H323TranslateToCallEndReason((Q931::CauseValues)(cause), dummy);
	}

	connection = (MyH323Connection *)endPoint->FindConnectionWithLock(currentToken);
	if (connection) {
		connection->SetCause(cause);
		connection->SetCallEndReason(r);
		connection->Unlock();
	}
	endPoint->ClearCall(currentToken, r);
	return 0;
};
/**
 * Add capability to the capability table of the end point. 
 */
int h323_set_capabilities(const char *token, int cap, int dtmfMode, struct ast_codec_pref *prefs)
{
	MyH323Connection *conn;

	if (!h323_end_point_exist()) {
		cout << " ERROR: [h323_set_capablities] No Endpoint, this is bad" << endl;
		return 1;
	}
	if (!token || !*token) {
		cout << " ERROR: [h323_set_capabilities] Invalid call token specified." << endl;
		return 1;
	}

	PString myToken(token);
	conn = (MyH323Connection *)endPoint->FindConnectionWithLock(myToken);
	if (!conn) {
		cout << " ERROR: [h323_set_capabilities] Unable to find connection " << token << endl;
		return 1;
	}
	conn->SetCapabilities(cap, dtmfMode, prefs);
	conn->Unlock();

	return 0;
}
Example #7
0
/** MyH323EndPoint 
  * The fullAddress parameter is used directly in the MakeCall method so
  * the General form for the fullAddress argument is :
  * [alias@][transport$]host[:port]
  * default values:	alias = the same value as host.
  *					transport = ip.
  *					port = 1720.
  */
int MyH323EndPoint::MakeCall(const PString & dest, PString & token, unsigned int *callReference, unsigned int port, char *callerid, char *callername)
{
	PString fullAddress;
	MyH323Connection * connection;

	/* Determine whether we are using a gatekeeper or not. */
	if (GetGatekeeper() != NULL) {
		fullAddress = dest;
		if (h323debug)
			cout << " -- Making call to " << fullAddress << " using gatekeeper." << endl;
	} else {
			fullAddress = dest; /* host */
			if (h323debug)
				cout << " -- Making call to " << fullAddress << "." << endl;
	}

	if (!(connection = (MyH323Connection *)H323EndPoint::MakeCallLocked(fullAddress, token))) {
		if (h323debug)
			cout << "Error making call to \"" << fullAddress << '"' << endl;
		return 1;
	}
	
	*callReference = connection->GetCallReference();
	
	if (callerid)
		connection->SetLocalPartyName(PString(callerid));
	if (callername) {
                localAliasNames.RemoveAll();
		connection->SetLocalPartyName(PString(callername));
	        if (callerid)
                  localAliasNames.AppendString(PString(callerid));
        } else if (callerid) {
                localAliasNames.RemoveAll();
                connection->SetLocalPartyName(PString(callerid));
        }
        
        connection->AST_Outgoing = TRUE;

	connection->Unlock(); 	

	if (h323debug) {
		cout << "	-- " << GetLocalUserName() << " is calling host " << fullAddress << endl;
		cout << "	-- " << "Call token is " << (const char *)token << endl;
		cout << "	-- Call reference is " << *callReference << endl;
	}
	return 0;
}