提交 8675abfa authored 作者: Brian West's avatar Brian West

moving this for now

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6337 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 3fcf09ba
AM_CFLAGS = $(SWITCH_AM_CFLAGS)
AM_CPPFLAGS = $(SWITCH_AM_CXXFLAGS)
AM_LDFLAGS = $(SWITCH_AM_LDFLAGS)
#we should set all these vars from configure, no reason to have these in each Makefile.am
LIBTOOL = echo "`link=\`echo $@|grep .la;echo $@|grep .so;echo $@|grep .dll\`;if test -n "$$link"; then echo Creating $@;fi`";`if test -z "$(VERBOSE)" ; \
then echo $(SHELL) $(switch_builddir)/quiet_libtool ;else echo $(SHELL) $(switch_builddir)/libtool; fi`
AM_MAKEFLAGS=`test -n "$(VERBOSE)" || echo -s`
# Dirty trick to override the link output
LIBS+=> $(MODNAME).log || error="yes";if test -n "$(VERBOSE)" -o "$$error" = "yes";then cat $(MODNAME).log;fi;if test "$$error" = "yes";then exit 1;fi
moddir=$(prefix)/mod
MODNAME=mod_opal
OPALDIR=/home/tuyan/CODE/OPAL/opal
PWLIBDIR=/home/tuyan/CODE/OPAL/pwlib
CC=g++
# enabled the debug compile for opal and pwlib
mod_LTLIBRARIES = mod_opal.la
mod_opal_la_SOURCES = mod_opal.cpp fsmanager.cxx fsep.cxx fsmediastream.cxx fscon.cxx opal_h323.cxx opal_sip.cxx opal_h323con.cxx fsrtp.cxx
mod_opal_la_CPPFLAGS = $(AM_CPPFLAGS) -D_REENTRANT -fno-exceptions -Wall -g3 -ggdb -O0 -D_DEBUG -I/home/tuyan/CODE/OPAL/pwlib/include -DPTRACING -I/home/tuyan/CODE/OPAL/opal/include -felide-constructors -Wreorder -I$(OPALDIR)/include -I$(PWLIBDIR)/include
mod_opal_la_LIBADD = $(switch_builddir)/libfreeswitch.la
mod_opal_la_LDFLAGS = -avoid-version -module -no-undefined -export-symbols-regex ^switch_module_.*$ -rpath $(PREFIX)/$(libdir) -L$(PWLIBDIR)/lib -L$(OPALDIR)/lib -lopal_linux_x86_d -lpt_linux_x86_d -lpthread -lexpat -lSDL -lresolv -ldl -fPIC -DPIC
#Override the linstall target so we just install the .so/.dylib
install-data-am: $(DESTDIR)$(PREFIX)/$(moddir)/$(MODNAME).$(DYNAMIC_LIB_EXTEN)
$(DESTDIR)$(PREFIX)/$(moddir)/$(MODNAME).$(DYNAMIC_LIB_EXTEN): $(MODNAME).la
@echo installing $(MODNAME).$(DYNAMIC_LIB_EXTEN)
@if [ -f .libs/$(MODNAME).$(DYNAMIC_LIB_EXTEN) ] ; then \
$(LIBTOOL) --mode=install $(INSTALL) .libs/$(MODNAME).$(DYNAMIC_LIB_EXTEN) $(DESTDIR)$(PREFIX)/$(moddir) >/dev/null ; \
else \
$(LIBTOOL) --mode=install $(INSTALL) $(MODNAME).$(DYNAMIC_LIB_EXTEN) $(DESTDIR)$(PREFIX)/$(moddir) >/dev/null ; \
fi
差异被折叠。
#ifndef __FREESWITCH_OPAL_CONNECTION__
#define __FREESWITCH_OPAL_CONNECTION__
#include <switch.h>
#include <ptlib.h>
#include <ptlib/psync.h>
#include <opal/buildopts.h>
#include <opal/endpoint.h>
#include <opal/connection.h>
#include <opal/transports.h>
#include "fsep.h"
#include "fsmediastream.h"
typedef enum {
TFLAG_IO = (1 << 0),
TFLAG_INBOUND = (1 << 1),
TFLAG_OUTBOUND = (1 << 2),
TFLAG_READING = (1 << 3),
TFLAG_WRITING = (1 << 4)
} TFLAGS;
class FSConnection;
class FSMediaStream;
typedef struct fs_obj
{
unsigned int flags;
switch_mutex_t *flag_mutex;
OpalCall *ownercall;
FSConnection *Connection;
} fs_obj_t;
class FSConnection : public OpalConnection
{
PCLASSINFO(FSConnection, OpalConnection);
public:
FSConnection(OpalCall & call, FSEndPoint & endpoint, const PString & token, unsigned int options);
~FSConnection();
virtual OpalMediaFormatList GetMediaFormats() const;
virtual OpalMediaStream * CreateMediaStream(OpalConnection & conn,
const OpalMediaFormat & mediaFormat,
BOOL isSource,
RTP_Session &rtpSession,
unsigned minAudioJitterDelay,
unsigned maxAudioJitterDelay);
virtual OpalMediaStream* CreateMediaStream (const OpalMediaFormat & mediaFormat,
unsigned sessionID,
BOOL isSource);
void InitiateCall(const PString & party);
virtual BOOL SetUpConnection();
virtual BOOL OnSetUpConnection();
virtual BOOL SetAlerting(const PString& caleeName, BOOL withMedia);
virtual BOOL SetConnected();
virtual void OnAlerting(OpalConnection & connection);
virtual void OnConnected();
virtual void OnReleased();
virtual BOOL IsMediaBypassPossible(unsigned sessionID);
switch_status_t callback_on_init(switch_core_session_t *io_session);
switch_status_t callback_on_ring(switch_core_session_t *io_session);
switch_status_t callback_on_execute(switch_core_session_t *io_session);
switch_status_t callback_on_hangup(switch_core_session_t *io_session);
switch_status_t callback_on_loopback(switch_core_session_t *session);
switch_status_t callback_on_transmit(switch_core_session_t *io_session);
switch_call_cause_t SwitchInitiateCall(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session, switch_memory_pool_t **pool);
switch_status_t io_read_frame(switch_core_session_t *, switch_frame_t **, int, switch_io_flag_t, int);
switch_status_t io_write_frame(switch_core_session_t *, switch_frame_t *, int, switch_io_flag_t, int);
switch_status_t io_kill_channel(switch_core_session_t *, int);
switch_status_t io_waitfor_read(switch_core_session_t *, int, int);
switch_status_t io_waitfor_write(switch_core_session_t *, int, int);
switch_status_t io_send_dtmf(switch_core_session_t *, char *);
switch_status_t io_receive_message(switch_core_session_t *, switch_core_session_message_t *);
switch_status_t io_receive_event(switch_core_session_t *, switch_event_t *);
switch_status_t io_state_change(switch_core_session_t *);
switch_status_t io_read_video_frame(switch_core_session_t *, switch_frame_t **, int, switch_io_flag_t, int);
switch_status_t io_write_video_frame(switch_core_session_t *, switch_frame_t *, int, switch_io_flag_t, int);
private:
OpalMediaFormatList mediaformats;
switch_frame_t frame;
char databuf[SWITCH_RECOMMENDED_BUFFER_SIZE];
switch_codec_t read_codec; /* Read codec*/
switch_codec_t write_codec; /* Write codec*/
switch_timer_t timer;
protected:
BOOL CreateIncomingFSConnection();
switch_endpoint_interface_t *FSEndpointInterface;
WORD RTPLocalPort;
WORD RTPRemotePort;
PIPSocket::Address RTPLocalAddress;
PIPSocket::Address RTPRemoteAddress;
PMutex ChannelMutex;
RTP_SessionManager *rtpmanager;
RTP_Session *OpalRTPSession;
switch_core_session_t *fssession;
switch_rtp_t *FSRTPSession;
};
#endif //__FREESWITCH_OPAL_CONNECTION__
#include "fsep.h"
#include "fscon.h"
static PString MakeToken()
{
return PGloballyUniqueID().AsString();
}
FSEndPoint::FSEndPoint(OpalManager & manager)
:OpalEndPoint(manager, "fs", CanTerminateCall), initialized(TRUE),
currentmediaport(MIN_MEDIA_PORT), RTPLocalAddress(PIPSocket::Address::Address())
{
mediaformats+=OpalPCM16;
mediaformats+=OpalG711uLaw;
mediaformats+=OpalG711ALaw;
mediaformats+=OpalG711_ULAW_64K;
mediaformats+=OpalG711_ALAW_64K;
mediaformats+=OpalGSM0610;
mediaformats+=OpalPCM16_16KHZ;
mediaformats+=OPAL_G729;
mediaformats+=OPAL_G729A;
mediaformats+=OPAL_G729B;
mediaformats+=OPAL_G729AB;
PTRACE(3, "FSEndPoint: \t FSEndPoint Created!");
}
FSEndPoint::~FSEndPoint()
{
}
BOOL FSEndPoint::SetRTPAddress(PIPSocket::Address addr)
{
RTPLocalAddress = addr;
return TRUE;
}
PIPSocket::Address FSEndPoint::GetRTPAddress()
{
return RTPLocalAddress;
}
BOOL FSEndPoint::OnOpenMediaStream(OpalConnection & connection, OpalMediaStream & stream)
{
manager.OnOpenMediaStream(connection, stream);
return TRUE;
}
BOOL FSEndPoint::OnIncomingConnection(OpalConnection&, unsigned int, OpalConnection::StringOptions*)
{
return TRUE;
}
BOOL FSEndPoint::OnSetUpConnection(OpalConnection & connection)
{
return TRUE;
}
void FSEndPoint::OnEstablished(OpalConnection &connection)
{
}
BOOL FSEndPoint::MakeConnection (OpalCall & call, const PString & party,
void *userData, unsigned int options,
OpalConnection::StringOptions* stringOptions)
{
FSConnection *connection;
PString token = MakeToken();
connection = new FSConnection(call, *this, token, 0);
PString dest = PString((const char*) userData);
if (connection != NULL){
if (!AddConnection(connection))
return FALSE;
if (call.GetConnection(0) == (OpalConnection*)connection){
connection->SetUpConnection();
}
}
return TRUE;
}
OpalMediaFormatList FSEndPoint::GetMediaFormats() const
{
return mediaformats;
}
WORD FSEndPoint::GetMediaPort()
{
if (currentmediaport++ >= MAX_MEDIA_PORT) {
currentmediaport = MIN_MEDIA_PORT;
}
return currentmediaport;
}
#ifndef __FREESWITCH_OPAL_ENDPOINT__
#define __FREESWITCH_OPAL_ENDPOINT__
#include <switch.h>
#include <ptlib.h>
#include <opal/buildopts.h>
#include <opal/endpoint.h>
#define MAX_MEDIA_PORT 44526
#define MIN_MEDIA_PORT 44000
class FSEndPoint : public OpalEndPoint
{
PCLASSINFO(FSEndPoint, OpalEndPoint);
public:
FSEndPoint(OpalManager& manager);
~FSEndPoint();
virtual BOOL OnIncomingConnection(OpalConnection&, unsigned int, OpalConnection::StringOptions*);
virtual BOOL MakeConnection(OpalCall & call, const PString & party,
void * userData, unsigned int options = 0,
OpalConnection::StringOptions* stringOptions = NULL);
virtual BOOL OnOpenMediaStream(OpalConnection & connection, OpalMediaStream & stream);
virtual BOOL OnSetUpConnection(OpalConnection & connection);
virtual void OnEstablished(OpalConnection &connection);
virtual OpalMediaFormatList GetMediaFormats() const;
WORD GetMediaPort();
BOOL SetRTPAddress(PIPSocket::Address ipaddr);
PIPSocket::Address GetRTPAddress();
private:
BOOL initialized;
PINDEX maxcalls;
OpalMediaFormatList mediaformats;
WORD currentmediaport;
PIPSocket::Address RTPLocalAddress;
};
#endif //__FREESWITCH_OPAL_ENDPOINT__
#include "fsmanager.h"
FSManager::FSManager()
:SessionsHashTable(NULL), SessionsHashTableMutex(NULL),
h323ep(NULL), fsep(NULL)
{
}
FSManager::~FSManager()
{
switch_mutex_destroy(SessionsHashTableMutex);
switch_core_hash_destroy(&SessionsHashTable);
}
BOOL FSManager::Initialize(switch_memory_pool_t* MemoryPool)
{
silenceDetectParams.m_mode = OpalSilenceDetector::NoSilenceDetection;
SetAudioJitterDelay(800, 3000);
if(switch_core_hash_init(&SessionsHashTable,MemoryPool)!=SWITCH_STATUS_SUCCESS)
{
assert(0);
return FALSE;
}
if(switch_mutex_init(&SessionsHashTableMutex,SWITCH_MUTEX_UNNESTED,MemoryPool)!=SWITCH_STATUS_SUCCESS)
{
assert(0);
switch_core_hash_destroy(&SessionsHashTable);
return FALSE;
}
sipep = new FSSIPEndPoint( *(static_cast<OpalManager*>(this)));
h323ep = new FSH323EndPoint( *(static_cast<OpalManager*>(this)));
fsep = new FSEndPoint( *(static_cast<OpalManager*>(this)));
PIPSocket::Address addr("10.0.0.1");
OpalTransportAddress sipTransportAddress(addr,5060, "udp");
OpalTransportAddress h323TransportAddress(addr,1726);
fsep->SetRTPAddress(addr);
if(!sipep->StartListeners(sipTransportAddress)){
delete sipep;
return FALSE;
}
if(!h323ep->StartListeners(h323TransportAddress)){
delete h323ep;
delete sipep;
return FALSE;
}
//SetSTUNServer("stun.voxgratia.org");
PStringArray routes;
routes += "h323:.* = fs:<da>";
SetRouteTable(routes);
return TRUE;
}
#ifndef __FREESWITCH_OPAL_MANAGER__
#define __FREESWITCH_OPAL_MANAGER__
#include <ptlib.h>
#include <opal/manager.h>
#include <h323/h323ep.h>
#include "fsep.h"
#include "opal_h323.h"
#include "opal_sip.h"
class FSH323EndPoint;
class FSManager : public OpalManager
{
PCLASSINFO(FSManager, PObject);
public:
FSManager();
~FSManager();
BOOL Initialize(switch_memory_pool_t* MemoryPool);
private:
switch_hash_t *SessionsHashTable;
switch_mutex_t *SessionsHashTableMutex;
switch_memory_pool_t *MemoryPool;
protected:
FSH323EndPoint *h323ep;
FSSIPEndPoint *sipep;
FSEndPoint *fsep;
};
#endif //__FREESWITCH_OPAL_MANAGER__
#include "fsmediastream.h"
FSMediaStream::FSMediaStream(FSConnection & connection, const OpalMediaFormat &mediaFormat,
BOOL isSource,
RTP_Session & rtpSession,
unsigned minAudioJitterDelay,
unsigned maxAudioJitterDelay)
:OpalRTPMediaStream(connection, mediaFormat, isSource, rtpSession, minAudioJitterDelay, maxAudioJitterDelay),
fsconnection((FSConnection&) connection)
{
if (isSource){
PTRACE(3, "FSMediaStream: Created SOURCE Media Stream");
//channel = fsconnection.writechannel;
}else{
//channel = fsconnection.readchannel;
PTRACE(3, "FSMediaStream: Created SINK Media Stream");
}
}
BOOL FSMediaStream::IsSynchronous() const
{
return FALSE; //rtp mediastream
}
FSMediaStream::~FSMediaStream()
{
}
FSUDPMediaStream::FSUDPMediaStream(OpalConnection & connection, const OpalMediaFormat &mediaFormat,
unsigned sessionID,
BOOL isSource,
OpalTransportUDP &transport)
:OpalUDPMediaStream(connection, mediaFormat, sessionID, isSource, transport)
{
if (isSource){
PTRACE(3, "FSMediaStream: Created SOURCE Media Stream");
}else{
PTRACE(3, "FSMediaStream: Created SINK Media Stream");
}
}
FSUDPMediaStream::~FSUDPMediaStream()
{
}
#ifndef __FREESWITCH_OPAL_MEDIASTREAM__
#define __FREESWITCH_OPAL_MEDIASTREAM__
#include <ptlib.h>
#include <opal/buildopts.h>
#include <opal/connection.h>
#include <opal/mediastrm.h>
#include <switch.h>
#include "fscon.h"
class FSConnection;
class FSMediaStream : public OpalRTPMediaStream
{
PCLASSINFO(FSMediaStream, OpalRTPMediaStream);
public:
FSMediaStream(FSConnection & connection, const OpalMediaFormat &mediaFormat,
BOOL isSource,
RTP_Session & rtpSession,
unsigned minAudioJitterDelay,
unsigned maxAudioJitterDelay);
~FSMediaStream();
//virtual BOOL ReadData(BYTE* data,PINDEX size,PINDEX& length);
//virtual BOOL WriteData(const BYTE* data,PINDEX length, PINDEX& written);
virtual BOOL IsSynchronous() const;
FSConnection &fsconnection;
protected:
PAdaptiveDelay channelDelay;
BOOL isSource;
PQueueChannel *channel;
};
class FSUDPMediaStream : public OpalUDPMediaStream
{
PCLASSINFO(FSUDPMediaStream, OpalUDPMediaStream);
public:
FSUDPMediaStream(OpalConnection & connection, const OpalMediaFormat &mediaFormat,
unsigned sessionID,
BOOL isSource,
OpalTransportUDP &transport);
~FSUDPMediaStream();
};
#endif// __FREESWITCH_OPAL_CONNECTION__
#ifndef __FREESWITCH_RTP_H_
#define __FREESWITCH_RTP_H_
#define HAVE_APR
#include <switch.h>
#include <switch_version.h>
#include <ptlib.h>
#include <opal/buildopts.h>
#include <opal/connection.h>
#include <opal/rtp.h>
// keeps the freeswitch - opal rtp mapping
class FSRTPPairs : public PObject
{
PCLASSINFO(FSRTPPairs, PObject);
public:
FSRTPPairs();
~FSRTPPairs();
private:
switch_rtp_t *fsrtp;
RTP_UDP *opalrtp;
};
// fsrtp session is different from opalrtp session
// we just keep the rtp sessions in fsrtpsession
//
class FSRTPSession : public PObject
{
PCLASSINFO(FSRTPSession, PObject);
public:
FSRTPSession(WORD port, BOOL isOpalRTP = FALSE);
private:
class RTPPairsDictionary : public PSafeDictionary<PString, FSRTPPairs>
{
virtual void DeleteObject(PObject * object) const;
}rtpPairs;
};
#endif //__FREESWITCH_RTP_H_
#include <switch.h>
#include <ptlib.h>
#include <ptlib/svcproc.h>
#include "mod_opal.h"
#include "fsmanager.h"
#include "fscon.h"
static switch_call_cause_t opalfs_outgoing_channel(switch_core_session_t *, switch_caller_profile_t *, switch_core_session_t **, switch_memory_pool_t **);
static switch_status_t opalfs_read_frame(switch_core_session_t *, switch_frame_t **, int, switch_io_flag_t, int);
static switch_status_t opalfs_write_frame(switch_core_session_t *, switch_frame_t *, int, switch_io_flag_t, int);
static switch_status_t opalfs_kill_channel(switch_core_session_t *, int);
static switch_status_t opalfs_waitfor_read(switch_core_session_t *, int, int);
static switch_status_t opalfs_waitfor_write(switch_core_session_t *, int, int);
static switch_status_t opalfs_send_dtmf(switch_core_session_t *, char *);
static switch_status_t opalfs_receive_message(switch_core_session_t *, switch_core_session_message_t *);
static switch_status_t opalfs_receive_event(switch_core_session_t *, switch_event_t *);
static switch_status_t opalfs_state_change(switch_core_session_t *);
static switch_status_t opalfs_read_video_frame(switch_core_session_t *, switch_frame_t **, int, switch_io_flag_t, int);
static switch_status_t opalfs_write_video_frame(switch_core_session_t *, switch_frame_t *, int, switch_io_flag_t, int);
static switch_status_t opalfs_on_init(switch_core_session_t *session);
static switch_status_t opalfs_on_ring(switch_core_session_t *session);
static switch_status_t opalfs_on_execute(switch_core_session_t *session);
static switch_status_t opalfs_on_hangup(switch_core_session_t *session);
static switch_status_t opalfs_on_loopback(switch_core_session_t *session);
static switch_status_t opalfs_on_transmit(switch_core_session_t *session);
static switch_memory_pool_t *opal_pool = NULL;
switch_endpoint_interface_t *opalfs_endpoint_interface = NULL;
static FSManager *opal_manager = NULL;
class _FSOpalProcess : public PProcess
{
PCLASSINFO(_FSOpalProcess, PProcess)
public:
_FSOpalProcess(){PTrace::SetLevel(PSystemLog::Info);}; //just for fun and eyecandy ;)
void Main() {};
} FSOpalProcess;
static switch_io_routines_t opalfs_io_routines = {
/*.outgoing_channel */ opalfs_outgoing_channel,
/*.read_frame */ opalfs_read_frame,
/*.write_frame */ opalfs_write_frame,
/*.kill_channel */ opalfs_kill_channel,
/*.waitfor_read */ opalfs_waitfor_read,
/*.waitfor_read */ opalfs_waitfor_write,
/*.send_dtmf */ opalfs_send_dtmf,
/*.receive_message */ opalfs_receive_message,
/*.receive_event */ opalfs_receive_event,
/*.state_change*/ opalfs_state_change,
/*.read_video_frame*/ opalfs_read_video_frame,
/*.write_video_frame*/ opalfs_write_video_frame
};
static switch_state_handler_table_t opalfs_event_handlers = {
/*.on_init */ opalfs_on_init,
/*.on_ring */ opalfs_on_ring,
/*.on_execute */ opalfs_on_execute,
/*.on_hangup */ opalfs_on_hangup,
/*.on_loopback */ opalfs_on_loopback,
/*.on_transmit */ opalfs_on_transmit
};
SWITCH_MODULE_LOAD_FUNCTION(mod_opal_load);
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_opal_shutdown);
SWITCH_MODULE_DEFINITION(mod_opal, mod_opal_load, mod_opal_shutdown, NULL);
SWITCH_MODULE_LOAD_FUNCTION(mod_opal_load)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE,"Starting loading mod_opal\n");
opal_pool = pool;
*module_interface =NULL;
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
if(!module_interface){
return SWITCH_STATUS_MEMERR;
}
opalfs_endpoint_interface = (switch_endpoint_interface_t*)switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE);
opalfs_endpoint_interface->interface_name = "opalFS";
opalfs_endpoint_interface->io_routines = &opalfs_io_routines;
opalfs_endpoint_interface->state_handler = &opalfs_event_handlers;
opal_manager = new FSManager();
if(!opal_manager) {
return SWITCH_STATUS_MEMERR;
}
if(!opal_manager->Initialize(pool)){
delete opal_manager;
return SWITCH_STATUS_FALSE;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Opal manager initilaized and running\n");
return SWITCH_STATUS_SUCCESS;
}
SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_opal_shutdown)
{
delete opal_manager;
opal_manager = NULL;
opal_pool = NULL;
opalfs_endpoint_interface = NULL;
return SWITCH_STATUS_SUCCESS;
}
static switch_call_cause_t opalfs_outgoing_channel(switch_core_session_t *session,
switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session,
switch_memory_pool_t **pool)
{
fs_obj_t* tech_prv = (fs_obj_t*)switch_core_session_get_private(session);
return SWITCH_CAUSE_SUCCESS;
}
static switch_status_t opalfs_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flags, int stream_id)
{
fs_obj_t* tech_prv = (fs_obj_t*)switch_core_session_get_private(session);
return tech_prv->Connection->io_read_frame(session, frame, timeout, flags, stream_id);
}
static switch_status_t opalfs_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flags, int stream_id)
{
fs_obj_t* tech_prv = (fs_obj_t*)switch_core_session_get_private(session);
return tech_prv->Connection->io_write_frame(session, frame, timeout, flags, stream_id);
}
static switch_status_t opalfs_kill_channel(switch_core_session_t *session, int sig)
{
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t opalfs_waitfor_read(switch_core_session_t *session, int ms, int stream_id)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Waitfor read!!!\n");
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t opalfs_waitfor_write(switch_core_session_t *session, int ms, int stream_id)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Waitfor write!!!\n");
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t opalfs_send_dtmf(switch_core_session_t *session, char *dtmf)
{
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t opalfs_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg)
{
fs_obj_t* tech_prv = (fs_obj_t*) switch_core_session_get_private(session);
return tech_prv->Connection->io_receive_message(session, msg);
}
static switch_status_t opalfs_receive_event(switch_core_session_t *session, switch_event_t *event)
{
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t opalfs_state_change(switch_core_session_t *session)
{
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t opalfs_read_video_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout, switch_io_flag_t flag, int stream_id)
{
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t opalfs_write_video_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout, switch_io_flag_t flag, int stream_id)
{
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t opalfs_on_init(switch_core_session_t *session)
{
fs_obj_t* fs_pvt = (fs_obj_t*)switch_core_session_get_private(session);
return SWITCH_STATUS_SUCCESS;
return fs_pvt->Connection->callback_on_init(session);
}
static switch_status_t opalfs_on_ring(switch_core_session_t *session)
{
fs_obj_t* tech_prv = (fs_obj_t*)switch_core_session_get_private(session);
return tech_prv->Connection->callback_on_ring(session);
}
static switch_status_t opalfs_on_execute(switch_core_session_t *session)
{
fs_obj_t* tech_prv = (fs_obj_t*)switch_core_session_get_private(session);
return tech_prv->Connection->callback_on_execute(session);
}
static switch_status_t opalfs_on_hangup(switch_core_session_t *session)
{
fs_obj_t* tech_prv = (fs_obj_t*)switch_core_session_get_private(session);
return tech_prv->Connection->callback_on_hangup(session);
}
static switch_status_t opalfs_on_loopback(switch_core_session_t *session)
{
fs_obj_t* tech_prv = (fs_obj_t*)switch_core_session_get_private(session);
return tech_prv->Connection->callback_on_loopback(session);;
}
static switch_status_t opalfs_on_transmit(switch_core_session_t *session)
{
return SWITCH_STATUS_SUCCESS;
}
#ifndef __FREESWITCH_MOD_OPAL__
#define __FREESWITCH_MOD_OPAL__
#define HAVE_APR
#include <switch.h>
#include <switch_version.h>
#define MODNAME "mod_opal"
#endif /* __FREESWITCH_MOD_OPAL__ */
#include "opal_h323.h"
#include "opal_h323con.h"
FSH323EndPoint::FSH323EndPoint(OpalManager & manager)
:H323EndPoint(manager), UseH323ExternalRTP(TRUE)
{
//if we have config option for using external rtp for h323,
//please set UseH323ExternalRTP to TRUE
mediaformats+=OpalPCM16;
mediaformats+=OpalG711uLaw;
mediaformats+=OpalG711ALaw;
mediaformats+=OpalG711_ULAW_64K;
mediaformats+=OpalG711_ALAW_64K;
mediaformats+=OpalGSM0610;
mediaformats+=OpalPCM16_16KHZ;
mediaformats+=OPAL_G729;
mediaformats+=OPAL_G729A;
mediaformats+=OPAL_G729B;
mediaformats+=OPAL_G729AB;
}
FSH323EndPoint::~FSH323EndPoint()
{
}
OpalMediaFormatList FSH323EndPoint::GetMediaFormats() const
{
PTRACE(3, "GIMME MEDIA FORMAT");
return mediaformats;
}
OpalConnection::AnswerCallResponse FSH323EndPoint::OnAnswerCall(OpalConnection & connection,
const PString & caller)
{
return OpalConnection::AnswerCallPending;
}
H323Connection * FSH323EndPoint::CreateConnection(OpalCall & call,
const PString & token,
void * userData,
OpalTransport & transport,
const PString & alias,
const H323TransportAddress & address,
H323SignalPDU * setupPDU,
unsigned options,
OpalConnection::StringOptions * stringOptions)
{
if (UseH323ExternalRTP)
return new FSH323Connection(call, *this, token, alias, address, options);
return new H323Connection(call, *this, token, alias, address, options);
}
#ifndef __OPAL_H323_ENDPOINT__
#define __OPAL_H323_ENDPOINT__
#include <ptlib.h>
#include <opal/buildopts.h>
#include <opal/endpoint.h>
#include <h323/h323ep.h>
#include <h323/h323con.h>
#include "opal_h323con.h"
class FSH323EndPoint : public H323EndPoint
{
PCLASSINFO(FSH323EndPoint, H323EndPoint);
public:
FSH323EndPoint(OpalManager & manager);
~FSH323EndPoint();
virtual OpalConnection::AnswerCallResponse OnAnswerCall(OpalConnection & connection,
const PString & caller);
virtual OpalMediaFormatList GetMediaFormats() const;
H323Connection * CreateConnection(OpalCall & call,
const PString & token,
void * userData,
OpalTransport & transport,
const PString & alias,
const H323TransportAddress & address,
H323SignalPDU * setupPDU,
unsigned options,
OpalConnection::StringOptions * stringOptions);
BOOL isExternalRTPEnabled(){return UseH323ExternalRTP;};
protected:
BOOL UseH323ExternalRTP;
OpalMediaFormatList mediaformats;
};
#endif //__OPAL_H323_ENDPOINT__
#include "opal_h323.h"
#include "opal_h323con.h"
FSExternalRTPChannel::FSExternalRTPChannel(H323Connection & connection, ///< Connection to endpoint for channel
const H323Capability & capability, ///< Capability channel is using
Directions direction, ///< Direction of channel
unsigned sessionID) ///< Session ID for channel)
: H323_ExternalRTPChannel(connection, capability, direction, sessionID)
{
PTRACE(3,"Creating External RTP Channel");
PIPSocket::Address addr("10.0.0.1");
WORD port = 41004;
SetExternalAddress(H323TransportAddress(addr, port), H323TransportAddress(addr, port+1));
// get the payload code
PTRACE(3, "Channel Capability " << capability.GetFormatName());
OpalMediaFormat format(capability.GetFormatName());
payloadCode = format.GetPayloadType();
Start();
}
BOOL FSExternalRTPChannel::Start()
{
if (!H323_ExternalRTPChannel::Start())
return FALSE;
PIPSocket::Address addr;
WORD port;
GetRemoteAddress(addr, port);
PTRACE(3, "External RTP Channel Started ::Start");
return TRUE;
}
FSH323Connection::FSH323Connection(OpalCall &call,FSH323EndPoint &endpoint,
const PString & token,const PString &alias,
const H323TransportAddress & address,unsigned options)
:H323Connection(call,endpoint,token,alias,address,options)
{
}
FSH323Connection::~FSH323Connection()
{
}
OpalMediaFormatList FSH323Connection::GetMediaFormats()
{
OpalMediaFormatList mediaformats;
mediaformats+=OpalPCM16;
mediaformats+=OpalG711uLaw;
mediaformats+=OpalG711ALaw;
mediaformats+=OpalG711_ULAW_64K;
mediaformats+=OpalG711_ALAW_64K;
mediaformats+=OpalGSM0610;
mediaformats+=OpalPCM16_16KHZ;
mediaformats+=OPAL_G729;
mediaformats+=OPAL_G729A;
mediaformats+=OPAL_G729B;
mediaformats+=OPAL_G729AB;
PTRACE(3, "RTP Channel Callback !");
return mediaformats;
}
/*
H323Channel* FSH323Connection::CreateRealTimeLogicalChannel(const H323Capability & capability,
H323Channel::Directions dir,
unsigned sessionID,
const H245_H2250LogicalChannelParameters * param,
RTP_QOS * rtpqos)
{
PTRACE(3, "RTP Channel Callback !");
//h323 external rtp can be set from here
return new FSExternalRTPChannel(*this, capability, dir, sessionID);
}
*/
#ifndef __OPAL_H323_CONNECTION__
#define __OPAL_H323_CONNECTION__
#include "opal_h323.h"
#include "fsep.h"
#include "fsmanager.h"
class FSH323EndPoint;
class FSExternalRTPChannel : public H323_ExternalRTPChannel
{
PCLASSINFO(FSExternalRTPChannel, H323_ExternalRTPChannel);
public:
FSExternalRTPChannel(H323Connection & connection, ///< Connection to endpoint for channel
const H323Capability & capability, ///< Capability channel is using
Directions direction, ///< Direction of channel
unsigned sessionID ); ///< Session ID for channel
virtual BOOL Start();
protected:
BYTE payloadCode;
};
class FSH323Connection : public H323Connection
{
PCLASSINFO(FSH323Connection, H323Connection);
public:
FSH323Connection(OpalCall &call, FSH323EndPoint &endpoint,
const PString & token,const PString &alias,
const H323TransportAddress & address,unsigned options = 0);
//External H323 RTP
/*
H323Channel* CreateRealTimeLogicalChannel(const H323Capability & capability,
H323Channel::Directions dir,
unsigned sessionID,
const H245_H2250LogicalChannelParameters * param,
RTP_QOS * rtpqos);
*/
virtual OpalMediaFormatList GetMediaFormats();
~FSH323Connection();
};
#endif // __FREESWITCH_H323_CONNECTION__
#include "opal_sip.h"
FSSIPEndPoint::FSSIPEndPoint(OpalManager & manager)
:SIPEndPoint(manager)
{
}
FSSIPEndPoint::~FSSIPEndPoint()
{
}
BOOL FSSIPEndPoint::OnIncomingConnection (OpalConnection &connection)
{
const char *destination = connection.GetCalledDestinationNumber();
PTRACE(3, "FSSIPEndPoint: Answering Incomming Call "<< "' To '" << destination << "'");
GetManager().MakeConnection(connection.GetCall(), "fs:", (void *) destination);
return TRUE;
}
OpalConnection::AnswerCallResponse FSSIPEndPoint::OnAnswerCall(OpalConnection & connection,
const PString & caller)
{
const char *destination = connection.GetCalledDestinationNumber();
PTRACE(3, "FSSIPEndPoint: Answering Incomming Call from '" << caller << "' To '" << destination << "'");
//OpalManager &manager = connection.GetEndPoint().GetManager();
//OpalCall & call = connection.GetCall();
//manager.MakeConnection(call, "fs", (void *) destination);
return OpalConnection::AnswerCallPending;
}
#ifndef __OPAL_SIP_ENDPOINT__
#define __OPAL_SIP_ENDPOINT__
#include <ptlib.h>
#include <opal/buildopts.h>
#include <opal/endpoint.h>
#include <sip/sipep.h>
class FSSIPEndPoint : public SIPEndPoint
{
PCLASSINFO(FSSIPEndPoint, SIPEndPoint);
public:
FSSIPEndPoint(OpalManager & manager);
~FSSIPEndPoint();
virtual BOOL OnIncomingConnection (OpalConnection &connection);
virtual OpalConnection::AnswerCallResponse OnAnswerCall(OpalConnection & connection,
const PString & caller);
};
#endif //__OPAL_SIP_ENDPOINT__
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论