Browse Source

Z991239-1621 #comment other sipiphone迁移改造

陈礼鹏80274480 4 years ago
parent
commit
1fa20b65a9

+ 0 - 4
Module/mod_counterconnector/CMakeLists.txt

@@ -19,10 +19,6 @@ target_link_directories(${MODULE_NAME} PRIVATE
 	${ThirdPartyLib}
 )
 
-if(NOT MSVC)
-target_compile_definitions(${MODULE_NAME} PRIVATE "DEPEND_MODS_NOT_FINISHED")
-endif(NOT MSVC)
-
 
 # 添加实体需要依赖的其他共享库(包括系统库)
 set(${MODULE_PREFIX}_LIBS  ${MODULE_BASE_LIBS})

+ 8 - 0
Module/mod_counterconnector/ConnectorFSM.h

@@ -626,6 +626,7 @@ private:
 		{
 			return Error_Param;
 		}
+		Dbg("nChanServer = %d, ChanProxyIP[%s], ChanCallNum[%s], ChanProxyPort[%d]", nChanServer, m_strChanProxyIP[nChanServer].GetData(), m_strChanCallNum[nChanServer].GetData(), m_iChanProxyPort[nChanServer]);
 		ChannelService_Connect_Req Req;
 		ChannelService_Connect_Ans Ans;
 		Req.callno = m_strChanCallNum[nChanServer];
@@ -742,6 +743,13 @@ private:
 		ErrorCodeEnum Error = m_pEntity->GetFunction()->OpenConfig(Config_CenterSetting, spConfig);
 		if (Error == Error_Succeed) {
 			Error = table.Load(spConfig);
+
+			m_strSIPProxyIP[0] = "99.12.136.208";
+			m_iSIPProxyPort[0] = 5080;
+			m_strSIPCallNum[0] = "1008";
+			m_strChanProxyIP[0] = "99.12.136.208";
+			m_iChanProxyPort[0] = 2326;
+			m_strChanCallNum[0] = "9990";
 		}
 		return Error;
 	}

+ 0 - 4
Module/mod_counterconnector/mod_counterconnector.cpp

@@ -130,13 +130,9 @@ using namespace CounterConnector;
 				return Error;
 			}
 		}
-#ifdef DEPEND_MODS_NOT_FINISHED
 
-#else
 		m_fsm.Init(this);
-#endif	
 		int i = 0;
-
 		m_arrListener.Init(24);
 		spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_PICKUP_CALL,NULL,false);
 		spFunction->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_MOD_CONNECT_HANDFREE_CALL,NULL,false);

+ 3 - 0
Module/mod_gpio/mod_gpio.h

@@ -176,6 +176,9 @@ public:
 
 	virtual void OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext)
 	{
+		LogEvent(Severity_Middle, LOG_EVT_PICKUP, "pick up");
+		Dbg("logevent pick up");
+
 		CSimpleStringA initDriver = "";
 		int driverPort;
 		ErrorCodeEnum Error;

+ 0 - 48
Module/mod_initiativetransfer/mod_initiativetransfer.vcxproj.filters

@@ -1,48 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <ItemGroup>
-    <Filter Include="Source Files">
-      <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
-      <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
-    </Filter>
-    <Filter Include="Header Files">
-      <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
-      <Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
-    </Filter>
-    <Filter Include="Resource Files">
-      <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
-      <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
-    </Filter>
-  </ItemGroup>
-  <ItemGroup>
-    <ClInclude Include="..\..\Framework\Common\stdafx.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="FlowControlFSM.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="InitiativeTransfer_client_g.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="InitiativeTransfer_def_g.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="InitiativeTransfer_msg_g.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-    <ClInclude Include="InitiativeTransfer_server_g.h">
-      <Filter>Header Files</Filter>
-    </ClInclude>
-  </ItemGroup>
-  <ItemGroup>
-    <ClCompile Include="..\..\Framework\Common\stdafx.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="FlowControlFSM.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-    <ClCompile Include="mod_initiativetransfer.cpp">
-      <Filter>Source Files</Filter>
-    </ClCompile>
-  </ItemGroup>
-</Project>

+ 24 - 9
Module/mod_sipphone/CMakeLists.txt

@@ -4,10 +4,12 @@ if(RVC_DEBUG_MODE)
     set(STRMBASE_LIB strmbasd)
 	set(SPBASE_LIB spbased)
 	set(TOOLKIT_LIB libtoolkitd)
+	set(RVCCOMM_LIB RVCCommD)
 else()
     set(STRMBASE_LIB strmbase)
 	set(SPBASE_LIB spbase)
 	set(TOOLKIT_LIB libtoolkit)
+	set(RVCCOMM_LIB RVCComm)
 endif(RVC_DEBUG_MODE)
 
 
@@ -72,7 +74,7 @@ conan_cmake_run(REQUIRES ffmpeg/4.1@LR04.02_ThirdParty/testing
 BASIC_SETUP CMAKE_TARGETS
 BUILD missing)
 else(WIN32)
-conan_cmake_run(REQUIRES ffmpeg/4.1@LR04.02_ThirdParty/testing
+conan_cmake_run(REQUIRES ffmpeg/4.1.6@LR04.02_ThirdParty/shared
 BASIC_SETUP CMAKE_TARGETS
 BUILD missing)
 endif(WIN32)
@@ -81,7 +83,7 @@ endif(WIN32)
 if(WIN32)
 conan_cmake_run(REQUIRES IPP/1.0@LR04.02_ThirdParty/testing
 	lib8k/1.0@LR04.02_ThirdParty/testing
-	spandsp/0.0.6@LR04.02_ThirdParty/testing
+#	spandsp/0.0.6@LR04.02_ThirdParty/testing
 BASIC_SETUP CMAKE_TARGETS
 BUILD missing)
 endif(WIN32)
@@ -92,7 +94,7 @@ conan_cmake_run(REQUIRES apache-apr/1.4.2@LR04.02_ThirdParty/testing
 BASIC_SETUP CMAKE_TARGETS
 BUILD missing)
 else(WIN32)
-conan_cmake_run(REQUIRES apache-apr/1.6.3@LR04.02_ThirdParty/testing
+conan_cmake_run(REQUIRES apr/1.7.0@LR04.02_ThirdParty/shared
 BASIC_SETUP CMAKE_TARGETS
 BUILD missing)
 endif(WIN32)
@@ -109,17 +111,23 @@ BUILD missing)
 endif(WIN32)
 
 conan_cmake_run(REQUIRES SpeexDSP/1.2rc3@LR04.02_ThirdParty/testing
+spandsp/0.0.6@LR04.02_ThirdParty/testing
 BASIC_SETUP CMAKE_TARGETS
 BUILD missing)
 
 
 target_include_directories(${MODULE_NAME} PRIVATE
+	${CONAN_INCLUDE_DIRS_APR}/apr-1
+	${CONAN_RVCFRAMEWORK_ROOT}/include
+	${CONAN_RVCFRAMEWORK_ROOT}/include/libtoolkit
+	#${CONAN_RVCFRAMEWORK_ROOT}/include/winpr
 	${CONAN_INCLUDE_DIRS_PORTAUDIO}
 	${CONAN_INCLUDE_DIRS_FFMPEG}
 	${CONAN_INCLUDE_DIRS_OPENCV}
     ${CONAN_INCLUDE_DIRS_OPENCV}/opencv
-	
 	${RVC_TOOLKIT_INCLUDE_DIR}
+	${RVC_FRAMEWORK_INCLUDES_DIR}
+	#${RVC_FRAMEWORK_INCLUDES_DIR}/winpr
 	if(WIN32)
 	${CONAN_INCLUDE_DIRS_IPP}
 	${CONAN_INCLUDE_DIRS_APACHE-APR}/include
@@ -134,7 +142,7 @@ target_include_directories(${MODULE_NAME} PRIVATE
 	${CONAN_INCLUDE_DIRS_SOFIA}/libsofia-sip-ua/nea
 	${CONAN_INCLUDE_DIRS_SOFIA}/libsofia-sip-ua/soa
 	else
-	${CONAN_INCLUDE_DIRS_APACHE-APR}
+	${CONAN_INCLUDE_DIRS_APR}/apr-1
 	${CONAN_INCLUDE_DIRS_SOFIA}/sofia-sip-1.13
 	endif(WIN32)
 )
@@ -145,15 +153,18 @@ target_link_directories(${MODULE_NAME} PRIVATE
 	${CONAN_LIB_DIRS_PORTAUDIO}
 	${CONAN_LIB_DIRS_FFMPEG}
 	${CONAN_LIB_DIRS_OPENCV}
-	${CONAN_LIB_DIRS_APACHE-APR}
 	${CONAN_LIB_DIRS_RVCFRAMEWORK}
 	${CONAN_LIB_DIRS_SPANDSP}
 	${CONAN_LIB_DIRS_SOFIA}
 	${CONAN_LIB_DIRS_SPEEXDSP}
+	${CONAN_LIB_DIRS_LIBKYSM}
 
 	if(WIN32)
 	${CONAN_LIB_DIRS_IPP}
 	${CONAN_LIB_DIRS_LIB8K}
+	${CONAN_LIB_DIRS_APACHE-APR}
+	else
+	${CONAN_LIB_DIRS_APR}
 	endif(WIN32)
 )
 
@@ -196,15 +207,19 @@ set(${MODULE_PREFIX}_LIBS  ${MODULE_BASE_LIBS}
 	${CONAN_LIBS_OPENCV}
 	${SPBASE_LIB}
 	${TOOLKIT_LIB}
-	#${CONAN_PKG_LIBS_APACHE-APR}
+	${CONAN_PKG_LIBS_APR}
 	${CONAN_PKG_LIBS_SPANDSP}
 	${CONAN_PKG_LIBS_SOFIA}
 	${CONAN_PKG_LIBS_SPEEXDSP}
-	#libaudioframework
-	#libvideoframework
+	libaudioframework
+	libvideoframework
 	audioqueue
 	videoqueue
 	asound
+	pthread
+	${RVCCOMM_LIB}
+	${CONAN_PKG_LIBS_LIBKYSM}
+	${WINPR_LIB}
 )
 endif(WIN32)
 

+ 79 - 64
Module/mod_sipphone/audio_session.cpp

@@ -12,8 +12,14 @@
 #include "../../Other/libaudioqueue/libaudioqueue.h"
 
 #include "../../Other/rvcmediacommon/rvc_media_common.h"
+#include <string.h>
 
+#ifdef _WIN32
 #define AUDIO_CLOCK	8000
+#else
+#define AUDIO_CLOCK	44100
+#endif
+
 #define AUDIO_SHM_FRAME_TIME	20 // 20ms
 
 #ifndef RVC_MAX_BUFFER_LEN
@@ -55,7 +61,13 @@ struct audio_session_t
 
 	audiobridge_t *bridge;
 	apr_pool_t *micspk_pool;
-	audiomicspk2_t *micspkstream;
+
+#ifdef _WIN32
+	audiomicspk2_t* micspkstream;
+#else
+	audiomicspklinux_t* micspkstream;
+#endif // _WIN32
+
 	audiodsp_t *dspstream;
 	audioresize_t *resizestream;
 	audiortp_t *rtpstream;
@@ -106,8 +118,9 @@ static int on_rx_audio(char *frame,void*userdata)
 
 static void m_on_send_hook(const char *buf, int size, void *arg)
 {
+	LOG_FUNCTION();
 	//Dbg("send audio pkt");
-	if ((g_nAudioSendNum%60) ==0)
+	//if ((g_nAudioSendNum%60) ==0)
 	{
 		Dbg("send audio pkt num %d,single size %d",g_nAudioSendNum,size);
 	}
@@ -136,10 +149,12 @@ static bool phonemedia_rtp_record(audio_session_t* pseesion)
 
 static void m_on_recv_hook(const char *buf, int size, void *arg)
 {
+	LOG_FUNCTION();
 	rtp_hdr *hdr = (rtp_hdr*)buf;
 	audio_session_t* pseesion = (audio_session_t*)arg;
 
-	if ((g_nAudioRecvNum%100) == 0){
+	//if ((g_nAudioRecvNum%100) == 0)
+	{
 		Dbg("recv audio pkt num %d,single size %d",g_nAudioRecvNum,size);
 		if (pseesion->phonemedia_conf.eDeviceType == eStand2sType){
 			Dbg("current hand free flag is %d, call type = %d, pt = %d,arg addr is %0x.",(int)pseesion->phonemedia_conf.dev_type, pseesion->phonemedia_conf.eCalltype, hdr->pt, arg);
@@ -335,6 +350,7 @@ on_error:
 
 static int phonemedia_start(audio_session_t *session)
 {
+	LOG_FUNCTION();
 	audio_session_t *media = session;
 	audio_session_phonemedia_conf_t *conf = &media->phonemedia_conf;
 	apr_status_t status;
@@ -351,7 +367,7 @@ static int phonemedia_start(audio_session_t *session)
 
 	in_dev = &session->conf.in_dev[conf->dev_type][0];
 	out_dev = &session->conf.out_dev[conf->dev_type][0];
-	Dbg("in_dev = %s,out_dev =%s",in_dev,out_dev);
+	Dbg("in_dev = %s,out_dev =%s, audio dir = %d",in_dev,out_dev, conf->dir);
 
 	opt_micspk = AMS_OPT_AS_STREAM;
 	if (conf->dir & DIR_TX) {
@@ -375,15 +391,6 @@ static int phonemedia_start(audio_session_t *session)
 		if (conf->remote_ptime == 0)
 			conf->remote_ptime = 20;
 		break;
-#if 0
-	case 4:
-		codec = "G723";
-		if (conf->local_ptime == 0)
-			conf->local_ptime = 30;
-		if (conf->remote_ptime == 0)
-			conf->remote_ptime = 30;
-		break;
-#endif
 	case 8: 
 		codec = "PCMA";
 		if (conf->local_ptime == 0)
@@ -408,41 +415,45 @@ static int phonemedia_start(audio_session_t *session)
 	if (conf->local_ptime != conf->remote_ptime) {
 		conf->local_ptime = conf->remote_ptime;
 	}
-
 	status = apr_pool_create(&media->pool, NULL);
 	if (status != APR_SUCCESS) {
 		Dbg("create pool failed!");
 		return Error_Resource;
 	}
+	else {
+		Dbg("create pool success!");
+	}
 
 	status = audioengine_create(media->pool, &media->engine);
 	if (status != APR_SUCCESS) {
 		Dbg("create audio engine failed!");
 		goto on_error;
 	}
+	else {
+		Dbg("create audio engine success!");
+	}
 
 	status = audioengine_start(media->engine);
 	if (status != APR_SUCCESS) {
 		goto on_error;
 	}
-	Dbg("audioengine_start success!");
 
-	rc = rtp_session_create2(conf->local_rtp_ip, conf->local_rtp_port, 
-		2, &media->rtpsess);
+	rc = rtp_session_create2(conf->local_rtp_ip, conf->local_rtp_port, 2, &media->rtpsess);
 	if (rc != 0) {
 		goto on_error;
 	}
-	Dbg("rtp_session_create2 success!");
-	//rc = rtp_session_reset2(media->rtpsess, conf->dir|RTP_SESSION_FLAG_NO_RTCP, conf->remote_rtp_ip, conf->remote_rtp_port, conf->remote_rtp_port+1);
-	rc = rtp_session_reset2(media->rtpsess, conf->dir, conf->remote_rtp_ip, conf->remote_rtp_port, conf->remote_rtp_port+1);
+
+	rc = rtp_session_reset2(media->rtpsess, conf->dir, conf->remote_rtp_ip, conf->remote_rtp_port, conf->remote_rtp_port + 1);
 	if (rc != 0) {
 		goto on_error;
 	}
-	Dbg("rtp_session_create2 success!");
+	Dbg("rtp_session_reset2 success! rc = %d", rc);
 	
 	status = audiobridge_create(media->pool, media->engine, &media->bridge);
 	if (status != APR_SUCCESS)
 		goto on_error;
+	Dbg("audiobridge_create success!");
+
 	status = apr_pool_create(&media->micspk_pool, media->pool);
 	if (status != APR_SUCCESS)
 		goto on_error;
@@ -452,15 +463,21 @@ static int phonemedia_start(audio_session_t *session)
 		opt_micspk |= AMS2_OPT_NS;
 	if (aec)
 		opt_micspk |= AMS2_OPT_AEC;
+#ifdef _WIN32
 	//create Spk 
 	status = audiomicspk2_create(media->micspk_pool, media->engine, opt_micspk, AUDIO_CLOCK, in_dev, out_dev, &media->micspkstream);
+#else
+	status = audiomicspklinux_create(media->micspk_pool, media->engine, opt_micspk, AUDIO_CLOCK, in_dev, out_dev, &media->micspkstream);
+#endif
+	if (status != APR_SUCCESS)
+		goto on_error;
+
 	//ÒôƵ»Øµ÷
+	Dbg("audiomicspk_create success!");
 	media->micspkstream->user_data = media;
 	media->micspkstream->on_rx_audio = &on_rx_audio;
 	Dbg("init on_rx_audio success!");
-	//status = audiomicspk3_create(media->micspk_pool, media->engine, opt_micspk, AUDIO_CLOCK, in_dev, out_dev, &media->micspkstream);
-	if (status != APR_SUCCESS)
-		goto on_error;
+
 	if (out_agc || out_ns) {
 		int read_opt = AUDIO_DSP_NONE;
 		int write_opt = AUDIO_DSP_NONE;
@@ -468,31 +485,40 @@ static int phonemedia_start(audio_session_t *session)
 			write_opt |= AUDIO_DSP_AGC;
 		if (out_ns)
 			write_opt |= AUDIO_DSP_DENOISE;
-		//Dbg("audiomicspk2_create success!");
+		
 		status = audiodsp_create(media->micspk_pool, media->engine, read_opt, write_opt, AUDIO_CLOCK, &media->dspstream);
 		if (status != APR_SUCCESS)
 			goto on_error;
-		//Dbg("audiodsp_create success!");
+
+		Dbg("audiodsp_create success!");
 	}
+
 #if 0
 	status = audioaec_create(media->pool, media->engine, AUDIO_CLOCK, FRAME_TIME, 
 		AUDIO_AEC_OPT_READ_AS_CAPTURE, &media->aecstream);
 	if (status != APR_SUCCESS)
 		goto on_error;
 #endif
+
 	status = audioresize_create(media->pool, media->engine, FRAME_TIME*2*AUDIO_CLOCK/1000, 
 		conf->remote_ptime*2*AUDIO_CLOCK/1000, FRAME_TIME*2*AUDIO_CLOCK/1000, 
 		conf->local_ptime*2*AUDIO_CLOCK/1000, &media->resizestream);
 	if (status != APR_SUCCESS)
 		goto on_error;
+
+	Dbg("audioresize_create success!");
+	
 	status = audiocodec_create(media->pool, media->engine, codec, AUDIO_CLOCK, FRAME_TIME, 
 		AUDIO_CODEC_OPT_ENCODE_WRITE, &media->codecstream);
 	if (status != APR_SUCCESS)
 		goto on_error;
+
+	Dbg("audiocodec_create success!");
+
 	status = audiortp_create(media->pool, media->engine, media->rtpsess, &media->rtpstream);
 	if (status != APR_SUCCESS)
 		goto on_error;
-	Dbg("audio_session_t session addr is %0x, audiortp_create success,and media->rtpstream addrs is %0x!",session, media->rtpstream);
+	Dbg("audio_session_t session addr is 0x%0x, audiortp_create success,and media->rtpstream addrs is 0x%0x!",session, media->rtpstream);
 
 	g_nAudioRecvNum = 0;
 	g_nAudioSendNum = 0;
@@ -517,10 +543,8 @@ static int phonemedia_start(audio_session_t *session)
 		//Dbg("recv hook addr %d,send hook addr %d", &m_on_recv_hook,&m_on_send_hook);
 		audiortp_set_param(media->rtpstream, AUDIO_RTP_FLAG_HOOK_ARG, media);
 		Dbg("AUDIO_RTP_FLAG_HOOK_ARG addr is %0x.", media);
-		
-		//audiortp_set_param(media->rtpstream, AUDIO_RTP_FLAG_RECV_HOOK, &m_on_recv_hook);
-		//audiortp_set_param(media->rtpstream, AUDIO_RTP_FLAG_SEND_HOOK, &m_on_send_hook);
-		
+		audiortp_set_param(media->rtpstream, AUDIO_RTP_FLAG_RECV_HOOK, (const void*)&m_on_recv_hook);
+		audiortp_set_param(media->rtpstream, AUDIO_RTP_FLAG_SEND_HOOK, (const void *)&m_on_send_hook);
 		//audiortp_set_param(media->rtpstream, AUDIO_RTP_FLAG_HOOK_ARG, media->rtpstream);
 		audiortp_init(media->rtpstream);
 	}
@@ -571,6 +595,7 @@ static int phonemedia_start(audio_session_t *session)
 	status = audiocontext_create(media->pool, media->engine, &media->context);
 	if (status != APR_SUCCESS)
 		goto on_error;
+
 	Dbg("audiocontext_create success!");
 
 	audiocontext_add_driver(media->context, &media->bridge->base);
@@ -588,7 +613,7 @@ static int phonemedia_start(audio_session_t *session)
 
 on_error:
 	phonemedia_stop(media, TRUE);
-	Dbg("phonemedia_stop error!!!");
+	Dbg("phonemedia_start error!!!");
 	return Error_Resource;
 }
 
@@ -598,8 +623,8 @@ static int phonemedia_stop(audio_session_t *session, int b_record_turn_off)
 	if (media->context) {
 		audioengine_stop_context(media->engine, media->context);
 		audiocontext_remove_driver(media->context, &media->bridge->base);
-		audiocontext_destroy(media->context);
-		media->context = NULL;
+		//audiocontext_destroy(media->context);
+		//media->context = NULL;
 	}
 	if (media->engine) {
 		audioengine_stop(media->engine);
@@ -635,7 +660,11 @@ static int phonemedia_stop(audio_session_t *session, int b_record_turn_off)
 		media->dspstream = NULL;
 	}
 	if (media->micspkstream) {
+#ifdef _WIN32
 		audiomicspk2_destroy(media->micspkstream);
+#else
+		audiomicspklinux_destroy(media->micspkstream);
+#endif
 		media->micspkstream = NULL;
 		apr_pool_destroy(media->micspk_pool);
 		media->micspk_pool = NULL;
@@ -701,9 +730,13 @@ static int phonemedia_chang_dev(audio_session_t *session, e_dev_type t)
 		//apr_status_t status;
 		audiocontext_remove_driver(media->context, &media->bridge->base);
 		if (media->micspkstream) {
-			Dbg("start audiomicspk2_destroy");
+			Dbg("start audiomicspk_destroy");
+#ifdef _WIN32
 			audiomicspk2_destroy(media->micspkstream);
-			Dbg("start audiomicspk2_destroy success");
+#else
+			audiomicspklinux_destroy(media->micspkstream);
+#endif
+			Dbg("start audiomicspk_destroy success");
 			media->micspkstream = NULL;
 		}
 		if (media->dspstream) {
@@ -719,8 +752,12 @@ static int phonemedia_chang_dev(audio_session_t *session, e_dev_type t)
 		if (aec)
 			opt_micspk |= AMS2_OPT_AEC;
 		Dbg("start audiomicspk2_create");
+#ifdef _WIN32
 		audiomicspk2_create(media->micspk_pool, media->engine, opt_micspk, AUDIO_CLOCK, in_dev, out_dev, &media->micspkstream);
-		Dbg("start audiomicspk2_create success");
+#else
+		audiomicspklinux_create(media->micspk_pool, media->engine, opt_micspk, AUDIO_CLOCK, in_dev, out_dev, &media->micspkstream);
+#endif
+		Dbg("start audiomicspk_create success");
 		media->micspkstream->on_rx_audio = &on_rx_audio;
 		media->phonemedia_conf.dev_type = t;
 		Dbg("init change dev on_rx_audio success!");
@@ -813,6 +850,7 @@ int audio_session_create(const audio_session_conf_t *conf, audio_session_t **p_s
 int audio_session_start_phonemedia(audio_session_t *session, const audio_session_phonemedia_conf_t *conf)
 {
 	int rc;
+	LOG_FUNCTION();
 	if (!session)
 		return Error_NotInit;
 	if (session->pool) { // already started
@@ -855,9 +893,10 @@ static void __stdcall __audio_log_func(int level, const char *s)
 
 int audio_lib_init()
 {
-#ifdef RVC_OS_WIN
+	LOG_FUNCTION();
 	audio_log_set_func(&__audio_log_func);
 	int rc = audioframework_init();
+
 	if (rc != 0) {
 		return Error_Resource;
 	}
@@ -881,38 +920,13 @@ int audio_lib_init()
 		audio_log_set_func(&__audio_log_func);
 	}
 
-#else
-	Pa_Initialize();
-	//PaUtil_SetDebugPrintFunction(&__PaUtilLogCallback);
-
-	int icnt, ocnt;
-	int rc = audio_get_dev_count(&icnt, &ocnt);
-	if (rc == 0) {
-		int i;
-		Dbg("audio input devices(%d):", icnt);
-		for (i = 0; i < icnt; ++i) {
-			CSimpleStringA str = audio_get_dev_name(true, i);
-			Dbg("%d = %s", i, (LPCSTR)str);
-		}
-		Dbg("audio output devices(%d):", ocnt);
-		for (i = 0; i < ocnt; ++i) {
-			CSimpleStringA str = audio_get_dev_name(false, i);
-			Dbg("%d = %s", i, (LPCSTR)str);
-		}
-	}
-
-#endif // RVC_OS_WIN
-
 	return 0;
 }
 
 void audio_lib_deinit()
 {
-#ifdef RVC_OS_WIN
+	LOG_FUNCTION();
 	audioframework_term();
-#else
-
-#endif // RVC_OS_WIN
 }
 
 int audio_get_dev_count(int *in_cnt, int *out_cnt)
@@ -987,6 +1001,7 @@ int capture_get_audio_device_id(bool in_direction, const char *dev_name)
 	return -1;
 }
 
+
 int get_audio_dev_name(char*devname,char*in_dev,char*out_dev)
 {
 	int icnt, ocnt;

+ 88 - 9
Module/mod_sipphone/endpoint.cpp

@@ -128,7 +128,12 @@ struct endpoint_t {
 	su_root_t *root;
 	nua_t *nua;
 	endpoint_call_t *active_call;
-	HANDLE event_thread;
+#ifdef RVC_OS_WIN
+	HANDLE event_thread;;
+#else
+	pthread_t ievent_threadid;
+#endif
+	
 	int call_seq;
 	int media_port_seq;
 	CEntityBase *entity;
@@ -181,6 +186,7 @@ static const char* call_type_table[] = {
 
 static void endpoint_media_change_audio_dev(endpoint_call_t *call, e_dev_type current_dev_type)
 {
+	LOG_FUNCTION();
 	if (call->audio) {
 		Dbg("begin audio_session_change_dev %d", current_dev_type);
 		audio_session_change_dev(call->audio, current_dev_type);
@@ -441,14 +447,16 @@ static void endpoint_media_update_audio(endpoint_call_t *call, media_desc_t *aud
 		}
 		
 		rc = audio_session_start_phonemedia(call->audio, &phone_conf);
-		if (rc != 0) 
-		{
+		if (rc != 0) {
 			Dbg("start audio session failed! rc = %d", rc);
 			LogError(Severity_High,Error_DevMedia,ERROR_MOD_SIP_AUDIO_INITFAIL,"audio initialize fail");
 			audio_session_destroy(call->audio);
 			call->audio = NULL;
 			return;
 		}
+		else {
+			Dbg("start audio session success!");
+		}
 	}
 }
 
@@ -797,6 +805,7 @@ static int negotiate_video(endpoint_call_t *call, media_desc_t *video_desc, cons
 
 static void negotiate_sdp(endpoint_call_t *call, const sdp_session_t *local_sdp, const sdp_session_t* remote_sdp)
 {
+	LOG_FUNCTION();
 	const sdp_media_t *lm = local_sdp->sdp_media;
 	const sdp_media_t *rm = remote_sdp->sdp_media;
 	media_desc_t audio_desc = {0}, video_desc = {0};
@@ -873,6 +882,7 @@ static void negotiate_sdp(endpoint_call_t *call, const sdp_session_t *local_sdp,
 
 static void on_state(CONDITION_PARAMS)
 {
+	LOG_FUNCTION();
 	int offer_recv = 0, answer_recv = 0, offer_sent = 0, answer_sent = 0;
 	int state = nua_callstate_init;
 	const char *replaces_str = NULL;
@@ -1006,10 +1016,15 @@ static void on_state(CONDITION_PARAMS)
 			audio_desc.media_dir = DIR_NONE;
 			endpoint_media_update_audio(call, &audio_desc, call->ep->curr_audio_dev_type);
 		}
+		Dbg("%s:%d", __FUNCTION__, __LINE__);
 		call->cb.on_call_state(st, state_desc[st], phrase, call->cb.user_data);
+		Dbg("%s:%d", __FUNCTION__, __LINE__);
 		nua_handle_bind(nh, NULL);
+		Dbg("%s:%d", __FUNCTION__, __LINE__);
 		nua_handle_destroy(nh);
+		Dbg("%s:%d call = 0x%0x", __FUNCTION__, __LINE__, call);
 		call->nh = NULL;
+		Dbg("%s:%d", __FUNCTION__, __LINE__);
 		break;
 	}
 
@@ -1039,6 +1054,7 @@ static void endpoint_callback(nua_event_t   event,
 						 sip_t const  *sip,
 						 tagi_t        tags[])
 {
+	LOG_FUNCTION();
 	switch (event) 
 	{
 		if (!g_IsExternalTerminalted)
@@ -1120,8 +1136,13 @@ static void endpoint_callback(nua_event_t   event,
 
 }
 
-static unsigned int __stdcall __event_thread(void *arg)
+#ifdef RVC_OS_WIN
+static unsigned int __stdcall __event_thread(void* arg)
+#else
+void* __event_thread(void* arg)
+#endif
 {
+	LOG_FUNCTION();
 	endpoint_t *ep = (endpoint_t *)arg;
 	ep->entity->GetFunction()->InitLogCurrentThread();
 
@@ -1138,6 +1159,7 @@ static unsigned int __stdcall __event_thread(void *arg)
 		ep, 
 		NUTAG_URL(ep->conf.uri),
 		TAG_END());
+	Dbg("%s:%d", __FUNCTION__, __LINE__);
 
 	nua_set_params(ep->nua,
 		SIPTAG_ALLOW_STR("INVITE,CANCEL,BYE,ACK,INFO,OPTIONS"),
@@ -1150,12 +1172,17 @@ static unsigned int __stdcall __event_thread(void *arg)
 		NTATAG_SIP_T1X64(8000),
 		TAG_NULL());
 
+	Dbg("%s:%d", __FUNCTION__, __LINE__);
 	su_root_run(ep->root);
+	Dbg("%s:%d", __FUNCTION__, __LINE__);
 	nua_shutdown(ep->nua);
+	Dbg("%s:%d", __FUNCTION__, __LINE__);
 	ep->nua = NULL;
+	Dbg("%s:%d", __FUNCTION__, __LINE__);
 	su_root_destroy(ep->root);
+	Dbg("%s:%d", __FUNCTION__, __LINE__);
 	ep->root = NULL;
-
+	Dbg("%s:%d", __FUNCTION__, __LINE__);
 
 #ifdef RVC_OS_WIN
 	CoUninitialize();
@@ -1188,6 +1215,7 @@ unsigned long GetTickCount()
 
 static endpoint_t *__endpoint_create(CEntityBase *pEntity, const endpoint_conf_t *conf,int nDev)
 {
+	LOG_FUNCTION();
 	endpoint_t *ep;
 
 	ep = ZALLOC_T(endpoint_t);
@@ -1214,13 +1242,16 @@ static void __endpoint_destroy(endpoint_t *ep)\
 
 static int __endpoint_start(endpoint_t *ep)
 {
+	LOG_FUNCTION();
+
+#ifdef RVC_OS_WIN
 	ep->event_thread = (HANDLE)_beginthreadex(NULL, 0, &__event_thread, ep, 0, NULL);
-	if (ep->event_thread) 
+	if (ep->event_thread)
 	{
-		while (!ep->root) 
+		while (!ep->root)
 		{
 			DWORD dwRet = WaitForSingleObject(ep->event_thread, 1);
-			if (dwRet == WAIT_OBJECT_0) 
+			if (dwRet == WAIT_OBJECT_0)
 			{
 				CloseHandle(ep->event_thread);
 				ep->event_thread = NULL;
@@ -1229,11 +1260,35 @@ static int __endpoint_start(endpoint_t *ep)
 		}
 	}
 	return ep->event_thread ? 0 : -1;
+#else
+	int err = pthread_create(&ep->ievent_threadid, NULL, __event_thread, ep);
+	if (0 == err) {
+		Dbg("create event thread success, %lu.", ep->ievent_threadid);
+		struct timespec ts;
+		Dbg("before circle ep->root = 0x%0x", ep->root);
+		while (!ep->root) {
+			clock_gettime(CLOCK_REALTIME, &ts);
+			ts.tv_nsec += 1000 * 1000;
+			if (0 == pthread_timedjoin_np(ep->ievent_threadid, NULL, &ts)) {
+				ep->ievent_threadid = 0;
+				Dbg("__event_thread exit break");
+				break;
+			}
+		}
+		Dbg("break circle ep->root = 0x%0x", ep->root);
+	}
+	else {
+		Dbg("create event thread failed.");
+	}
+
+	return ep->ievent_threadid > 0 ? 0 : -1;
+#endif
 }
 
 static void __endpoint_stop(endpoint_t *ep)
 {
-	if (ep->event_thread) 
+#ifdef RVC_OS_WIN
+	if (ep->event_thread)
 	{
 		int rc;
 		su_task_execute(su_root_task(ep->root), &__endpoint_break, ep, &rc);
@@ -1241,6 +1296,16 @@ static void __endpoint_stop(endpoint_t *ep)
 		CloseHandle(ep->event_thread);
 		ep->event_thread = NULL;
 	}
+#else
+	if (ep->ievent_threadid > 0)
+	{
+		int rc;
+		su_task_execute(su_root_task(ep->root), &__endpoint_break, ep, &rc);
+		pthread_join(ep->ievent_threadid, NULL);
+		ep->ievent_threadid = 0;
+	}
+#endif
+
 }
 
 int endpoint_init_lib()
@@ -1255,6 +1320,7 @@ void endpoint_deinit_lib()
 
 endpoint_t *endpoint_create(CEntityBase *pEntity, const endpoint_conf_t *conf,int nDev)
 {
+	LOG_FUNCTION();
 	endpoint_t *endpt;
 	
 	endpt = __endpoint_create(pEntity, conf,nDev);
@@ -1273,6 +1339,7 @@ endpoint_t *endpoint_create(CEntityBase *pEntity, const endpoint_conf_t *conf,in
 
 void endpoint_destroy(endpoint_t *ep)
 {
+	LOG_FUNCTION();
 	if (ep) 
 	{
 		__endpoint_stop(ep);
@@ -1287,6 +1354,7 @@ int endpoint_invoke(endpoint_t *ep, int (*func)(void*), void *user_data, int *re
 
 void endpoint_change_audio_dev(endpoint_t *ep, int dev_type)
 {
+	LOG_FUNCTION();
 	if (ep->curr_audio_dev_type != dev_type) {
 		ep->curr_audio_dev_type = dev_type;
 		if (ep->active_call) {
@@ -1303,6 +1371,7 @@ void endpoint_change_audio_dev(endpoint_t *ep, int dev_type)
 
 endpoint_call_t *endpoint_call_create(endpoint_t *ep, const char *remote_uri, const char*local_ip,DeviceTypeEnum nDeviceType,CallingTypeEnum nCallType,const endpoint_call_callback_t *cb)
 {
+	LOG_FUNCTION();
 	endpoint_call_t *call = NULL;
 	su_home_t *home = NULL; 
 
@@ -1344,11 +1413,14 @@ on_error:
 
 void endpoint_call_destroy(endpoint_call_t *call)
 {
+	LOG_FUNCTION();
 	endpoint_call_dec_ref(call);
 }
 
 int endpoint_call_start(endpoint_call_t *call)
 {
+	LOG_FUNCTION();
+
 	char sdp[512] = {0};
 
 	if (call->nh)
@@ -1360,8 +1432,13 @@ int endpoint_call_start(endpoint_call_t *call)
 		SIPTAG_TO_STR(call->remote_uri),
 		TAG_END());
 
+	Dbg("uri is %s.", call->ep->conf.uri);
+	Dbg("call remote_uri is %s.", call->remote_uri);
+	
 	call_make_offer(call, sdp, -1);
 
+	Dbg("sdp is %s", sdp);
+
 	nua_invite(call->nh, 
 		//NUTAG_URL(call->remote_uri), 
 		SOATAG_USER_SDP_STR(sdp), 
@@ -1374,6 +1451,7 @@ int endpoint_call_start(endpoint_call_t *call)
 
 int endpoint_call_hangup(endpoint_call_t *call)
 {
+	LOG_FUNCTION();
 	if (call->nh) {
 		if (call->connected) {
 			nua_bye(call->nh, NUTAG_SESSION_TIMER(8000),TAG_END());
@@ -1530,6 +1608,7 @@ int endpoint_call_start_video(endpoint_call_t *call, unsigned long remote_ip, in
 {
 	char local_ip_str[128]={0};
 	char remtote_ip_str[128]={0};
+	LOG_FUNCTION();
 
 	translate_ipaddr_from_int(local_ip_str, 128, local_ip);
 	translate_ipaddr_from_int(remtote_ip_str, 128, remote_ip);

+ 1 - 1
Module/mod_sipphone/endpoint.h

@@ -5,7 +5,7 @@
 #include "../include/EventCode.h"
 #include "../mod_counterconnector/CallType.h"
 
-#ifdef RVC_OS_WIN
+#ifdef _WIN32
 #include <process.h>
 #include <objbase.h>
 #else

+ 11 - 3
Module/mod_sipphone/mod_sipphone.cpp

@@ -220,6 +220,7 @@ private:
 
 	static void __on_call_state(int state, const char *state_desc, const char *phrase, void *user_data)
 	{
+		LOG_FUNCTION();
 		CSIPPhoneSession *pThis = static_cast<CSIPPhoneSession*>(user_data);
 		if (pThis->m_iLastState != state) {
 			pThis->m_iLastState = state;
@@ -837,7 +838,7 @@ public:
 				return Error_Unexpect;
 			}
 			else{
-				Dbg("__OnStart endpoint_create m_pEndpoint addr is %0x.", m_pEndpoint);
+				Dbg("__OnStart call uri is %s, endpoint_create m_pEndpoint addr is %0x.",conf.uri, m_pEndpoint);
 			}
 		} 
 		else 
@@ -1956,6 +1957,7 @@ void CSIPPhoneSession::OnClose( ErrorCodeEnum eErrorCode )
 void CSIPPhoneSession::Handle_MakeCall( SpReqAnsContext<PhoneService_MakeCall_Req, PhoneService_MakeCall_Ans>::Pointer ctx )
 {
 	LOG_FUNCTION();
+
 	LOG_TRACE("make call [%s]", (LPCSTR)ctx->Req.call_uri);
 	int rc;
 	MakeCallCommand *cmd = new MakeCallCommand();
@@ -2138,13 +2140,14 @@ void CSIPPhoneSession::Handle_EndState( SpOnewayCallContext<PhoneService_EndStat
 
 void CSIPPhoneSession::hangup_call(HangupCallCommand* cmd)
 {
+	LOG_FUNCTION();
 	if (m_pCall) {
 		Dbg("normal hangup.");
 		endpoint_call_hangup(m_pCall);
 	}
 	else
 	{  
-		if (m_pEntity && m_pEntity->m_nCallType != DOUBLERECORD_CALLTYPE){
+		if (m_pEntity && m_pEntity->m_nCallType == MOBILETOPAD_CALLTYPE){
 			//分布式呼叫主动挂断场景
 			Dbg("distribute hangup, without pickup");
 			if (cmd){
@@ -2184,6 +2187,7 @@ void CSIPPhoneSession::release_call()
 
 void CSIPPhoneSession::on_call_state(int state, const char *state_desc, const char *phrase)
 {
+	LOG_FUNCTION();
 	if (m_spCallbackContext != NULL) 
 	{
 		LOG_TRACE("on_call_state message state = %d, status=%s, phrase=%s!", state, state_desc, phrase);
@@ -2191,18 +2195,22 @@ void CSIPPhoneSession::on_call_state(int state, const char *state_desc, const ch
 		Info.state = state;
 		Info.status = CSimpleStringA::Format("%s,%s", state_desc, phrase);
 		m_spCallbackContext->SendMessage(Info);
+		Dbg("%s:%d", __FUNCTION__, __LINE__);
 	}
 
 	if (state == TERMINATED) 
 	{
+		Dbg("%s:%d", __FUNCTION__, __LINE__);
 		if (m_pCall)
 		{
+			Dbg("%s:%d", __FUNCTION__, __LINE__);
 			endpoint_call_destroy(m_pCall);
 			m_pCall = NULL;
 		}
 	}
-
+	Dbg("%s:%d", __FUNCTION__, __LINE__);
 	m_pEntity->SetState(state);
+	Dbg("%s:%d", __FUNCTION__, __LINE__);
 }
 
 int CSIPPhoneSession::make_call( const char *remote_uri )

+ 5 - 4
Module/mod_sipphone/video_session.cpp

@@ -2203,11 +2203,11 @@ void video_session_destroy(video_session_t *session)
 				session->pic_record->evt = NULL;
 			}
 		}
+	}
 #else
 
 #endif // RVC_OS_WIN
 
-
 	if (session->video_shm_q_env) {
 		delete session->video_shm_q_env;
 		session->video_shm_q_env = NULL;
@@ -2248,7 +2248,8 @@ void video_session_destroy(video_session_t *session)
 	free(session);
 }
 
-static void av_log_cb(void*ptr, int level, const char*fmt, va_list list)
+
+void av_log_cb(void*ptr, int level, const char*fmt, va_list list)
 {
 	//vDbg(fmt, list);
 }
@@ -2275,10 +2276,10 @@ int video_lib_init()
 	av_log_set_callback(&av_log_cb);
 	//av_log_set_level(AV_LOG_DEBUG);
 	av_log_set_level(AV_LOG_QUIET);
+	
 #else
-
+	videoframework_init();
 #endif // RVC_OS_WIN
-
 	return 0;
 }
 

+ 14 - 12
Other/libaudioframework/audiomicspklinux.c

@@ -77,18 +77,18 @@ static int inStreamCallback(const void* input,
 		}
 		else {
 			unsigned long nsamples = frameCount + micspk->rec_buf_cnt;
-			//while (nsamples >= micspk->frame_samples) {
-			//	unsigned chunk_count = micspk->frame_samples - micspk->rec_buf_cnt;
-			//	memcpy(micspk->rec_buf + micspk->rec_buf_cnt, input, chunk_count << 1);
-			//	input = (const short*)input + chunk_count;
-			//	delay_buf_put(micspk->rec_dbuf, micspk->rec_buf);
-			//	micspk->rec_buf_cnt = 0;
-			//	nsamples -= micspk->frame_samples;
-			//}
-			//if (nsamples > 0) {
-			//	memcpy(micspk->rec_buf + micspk->rec_buf_cnt, input, nsamples << 1);
-			//	micspk->rec_buf_cnt += nsamples;
-			//}
+			while (nsamples >= micspk->frame_samples) {
+				unsigned chunk_count = micspk->frame_samples - micspk->rec_buf_cnt;
+				memcpy(micspk->rec_buf + micspk->rec_buf_cnt, input, chunk_count << 1);
+				input = (const short*)input + chunk_count;
+				delay_buf_put(micspk->rec_dbuf, micspk->rec_buf);
+				micspk->rec_buf_cnt = 0;
+				nsamples -= micspk->frame_samples;
+			}
+			if (nsamples > 0) {
+				memcpy(micspk->rec_buf + micspk->rec_buf_cnt, input, nsamples << 1);
+				micspk->rec_buf_cnt += nsamples;
+			}
 		}
 		audio_log_v(AUDIO_LOG_LEVEL_INFO, "audio micro inStreamCallback.");
 	}
@@ -414,6 +414,8 @@ apr_status_t audiomicspklinux_create(apr_pool_t* pool,
 	if (opt & AMS_OPT_RECORD) {
 		micspk->base.direction |= STREAM_DIR_READ;
 		delay_buf_create(clock, frame_samples, 1, MAX_DELAY, 0, (delay_buf**)& micspk->rec_dbuf);
+		micspk->rec_buf = (short*)apr_palloc(pool, frame_samples << 1);
+		micspk->rec_buf_cnt = 0;
 		//micspk->input_resample_state = speex_resampler_init(1, CAPTURE_AUDIO_CLOCK, AUDIO_CLOCK, RESAMPLE_QUALITY, NULL);
 	}
 	micspk->baudio_device_started_flag = false;

+ 25 - 8
Other/libaudioframework/audiortp.c

@@ -49,11 +49,15 @@ static __inline int digit2event(int digit) {
 
 static int send_dtmf_digit(rtp_session_t *sess, rtp_dtmf_event *digit, unsigned dtmf_pt)
 {
+	Dbg("%s : %d", __FUNCTION__, __LINE__);
 	rtp_state *st = rtp_session_get_rtp_state(sess);
 	rtp_session_send(sess, 0, dtmf_pt, digit->e, 0, (const char*)digit, sizeof(rtp_dtmf_event));
 	if (digit->e) {
+		Dbg("%s : %d", __FUNCTION__, __LINE__);
 		rtp_session_send(sess, 0, dtmf_pt, digit->e, 0, (const char*)digit, sizeof(rtp_dtmf_event));
+		Dbg("%s : %d", __FUNCTION__, __LINE__);
 		rtp_session_send(sess, 0, dtmf_pt, digit->e, 0, (const char*)digit, sizeof(rtp_dtmf_event));
+		Dbg("%s : %d", __FUNCTION__, __LINE__);
 	}
 	return 0;
 }
@@ -90,9 +94,12 @@ static apr_status_t read_frame(void *self, audioframe_t *frame)
 
 	audiortp->m_rtp_tick++;
 
+	Dbg("%s : %d", __FUNCTION__, __LINE__);
 	/* read packet from net */
 	for (i = 0 ; i < max_recv_cnt; ++i) {
+		Dbg("%s : %d", __FUNCTION__, __LINE__);
 		int ret = rtp_session_recv_hook(audiortp->m_rtpsession, &pt, &mark, &ts, &seq, buf, sizeof(buf), audiortp->m_on_recv_hook, audiortp->m_hook_data);
+		Dbg("%s : %d rtp_session_recv_hook ret = %d", __FUNCTION__, __LINE__, ret);
 		if (ret <= 0)
 			break;
 		audiortp->m_last_rtp_tick = audiortp->m_rtp_tick;
@@ -184,13 +191,13 @@ static apr_status_t write_frame(void *self, const audioframe_t *frame)
 {
 	audiortp_t *audiortp = CONTAINING_RECORD(self, audiortp_t, base);
 	int dtmf = 0;
-
+	Dbg("%s : %d", __FUNCTION__, __LINE__);
 #ifdef WIN32
 	EnterCriticalSection(&audiortp->m_dtmf_lock);
 #else
 	apr_thread_mutex_lock(audiortp->m_dtmf_mtx);
 #endif
-
+	Dbg("%s : %d", __FUNCTION__, __LINE__);
 	if (frame->dtmf && CIRC_LEN(audiortp->m_send_dtmf_rd, audiortp->m_send_dtmf_wr, MAX_DTMF) < MAX_DTMF - 1) {
 		rtp_dtmf_event* dtmf = &audiortp->m_send_dtmf[audiortp->m_send_dtmf_wr];
 		dtmf->event = (unsigned char)digit2event(frame->dtmf);
@@ -200,6 +207,7 @@ static apr_status_t write_frame(void *self, const audioframe_t *frame)
 		dtmf->duration = 0;
 		audiortp->m_send_dtmf_wr = CIRC_INC(audiortp->m_send_dtmf_wr, MAX_DTMF);
 	}
+	Dbg("%s : %d", __FUNCTION__, __LINE__);
 	if (!CIRC_IS_EMPTY(audiortp->m_send_dtmf_rd, audiortp->m_send_dtmf_wr)) {
 		rtp_dtmf_event* digit = &audiortp->m_send_dtmf[audiortp->m_send_dtmf_rd];
 		send_dtmf_digit(audiortp->m_rtpsession, digit, audiortp->m_send_dtmf_pt);
@@ -215,12 +223,13 @@ static apr_status_t write_frame(void *self, const audioframe_t *frame)
 			rtp_session_advance_timestamp(audiortp->m_rtpsession, DTMF_DURATION);
 		}
 	}
+	Dbg("%s : %d", __FUNCTION__, __LINE__);
 #ifdef _WIN32
 	LeaveCriticalSection(&audiortp->m_dtmf_lock);
 #else
 	apr_thread_mutex_unlock(audiortp->m_dtmf_mtx);
 #endif // WIN32
-
+	Dbg("%s : %d", __FUNCTION__, __LINE__);
 	if (dtmf) {
 		/* because we send dtmf, so ignore this frame */
 		return 0;
@@ -228,6 +237,7 @@ static apr_status_t write_frame(void *self, const audioframe_t *frame)
 
 	if (frame->size < (unsigned long)audiortp->m_send_psize) {
 		if (frame->size) {
+			Dbg("%s : %d", __FUNCTION__, __LINE__);
 			memcpy(audiortp->m_SendSample.buffer + audiortp->m_SendSample.size, frame->buffer, frame->size);
 			audiortp->m_SendSample.size += frame->size;
 		} else {
@@ -236,12 +246,16 @@ static apr_status_t write_frame(void *self, const audioframe_t *frame)
 			memset(tmp, 0, tmp_cnt);
 			memcpy(audiortp->m_SendSample.buffer + audiortp->m_SendSample.size, tmp, tmp_cnt);
 			audiortp->m_SendSample.size += tmp_cnt;
+			Dbg("%s : %d", __FUNCTION__, __LINE__);
 		}
 		if (audiortp->m_SendSample.size >= (unsigned long)audiortp->m_send_psize) {
-			//printf("send out %d\n", audiortp->m_send_psize);
+			Dbg("send out %d\n", audiortp->m_send_psize);
+			Dbg("%s : %d", __FUNCTION__, __LINE__);
 			rtp_session_send_hook(audiortp->m_rtpsession, 0, 
 				audiortp->m_send_pt, 0, audiortp->m_send_ptime*audiortp->m_send_clock/1000, 
 				audiortp->m_SendSample.buffer, audiortp->m_send_psize, audiortp->m_on_send_hook, audiortp->m_hook_data);
+
+			Dbg("%s : %d", __FUNCTION__, __LINE__);
 			if (audiortp->m_SendSample.size > (unsigned long)audiortp->m_send_psize) {
 				audiortp->m_SendSample.size -= audiortp->m_send_psize;
 				memmove(audiortp->m_SendSample.buffer, 
@@ -253,16 +267,21 @@ static apr_status_t write_frame(void *self, const audioframe_t *frame)
 		}
 	} else {
 		int delta_ts = audiortp->m_send_ptime*audiortp->m_send_clock/1000;
+		Dbg("%s : %d audiortp->m_rtpsession = 0x%0x audiortp->m_send_pt = %d delta_ts = %d frame->buffer = 0x%0x, audiortp->m_send_psize = %d", 
+			__FUNCTION__, __LINE__, audiortp->m_rtpsession, audiortp->m_send_pt, delta_ts, frame->buffer, audiortp->m_send_psize);
 		rtp_session_send_hook(audiortp->m_rtpsession, 0, 
 			audiortp->m_send_pt, 0, delta_ts, frame->buffer, audiortp->m_send_psize, audiortp->m_on_send_hook, audiortp->m_hook_data);
+		Dbg("%s : %d", __FUNCTION__, __LINE__);
+
 		if (frame->size > (unsigned long)audiortp->m_send_psize) {
 			audiortp->m_SendSample.size = frame->size-audiortp->m_send_psize;
 			memcpy(audiortp->m_SendSample.buffer, 
 				frame->buffer+audiortp->m_send_psize, 
 				audiortp->m_SendSample.size);			
 		}
+		Dbg("%s : %d", __FUNCTION__, __LINE__);
 	}
-
+	Dbg("%s : %d", __FUNCTION__, __LINE__);
 	return APR_SUCCESS;
 }
 
@@ -435,7 +454,7 @@ apr_status_t audiortp_init(audiortp_t *ar)
 	audiortp->m_jbuf_psize = audiortp->m_jbuf_ptime * audiortp->m_recv_clock / 1000 * audiortp->m_recv_samplebit / 8;
 	jbuf_create(audiortp->m_jbuf_psize, audiortp->m_jbuf_ptime, JB_MAX, &audiortp->m_jitterbuf);
 	jbuf_set_adaptive(audiortp->m_jitterbuf, 0, 7, JB_MAX);
-	DEBUG_TRACE("audiortp init, send_psize:%d, recv_psize:%d", audiortp->m_send_psize, audiortp->m_recv_psize);
+	Dbg("audiortp init, send_psize:%d, recv_psize:%d", audiortp->m_send_psize, audiortp->m_recv_psize);
 	Dbg("%s : %d", __FUNCTION__, __LINE__);
 	return APR_SUCCESS;
 }
@@ -524,8 +543,6 @@ apr_status_t audiortp_recv_dtmf(audiortp_t *self, char *digits, unsigned *cnt)
 	apr_thread_mutex_unlock(audiortp->m_dtmf_mtx);
 #endif // _WIN32
 	
-
-
 	return APR_SUCCESS;
 }