Browse Source

Z991239-1721 #comment other 解决Linux下放音卡顿问题

陈礼鹏80274480 4 years ago
parent
commit
9825f064ef

+ 13 - 8
Module/mod_sipphone/audio_session.cpp

@@ -92,7 +92,6 @@ static int on_rx_audio(char *frame,void*userdata)
 	{
 		if (frame) 
 		{
-			//Dbg("recv data size %d",strlen(frame));
 			audio_frame frm;
 			frm.bitspersample = 16;
 			frm.format = 1;
@@ -102,6 +101,7 @@ static int on_rx_audio(char *frame,void*userdata)
 			//frm.framesize = strlen(frame);  //不能使用此方法,网络传输的包大小可能是不定长的
 			frm.nchannels = 1;
 			frm.samplespersec = 8000;
+			frm.iseriesnumber = g_nAudioRecvNum;
 			if (!session->remoteaudioqueue->InsertAudio(&frm)) 
 			{
 				Dbg("InsertAudio failed! frameCount:%d", frm.framesize);
@@ -114,11 +114,11 @@ static int on_rx_audio(char *frame,void*userdata)
 
 static void m_on_send_hook(const char *buf, int size, void *arg)
 {
-	LOG_FUNCTION();
+	//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);
+		//Dbg("send audio pkt num %d,single size %d",g_nAudioSendNum,size);
 	}
 	g_nAudioSendNum++;
 }
@@ -145,14 +145,16 @@ static bool phonemedia_rtp_record(audio_session_t* pseesion)
 
 static void m_on_recv_hook(const char *buf, int size, void *arg)
 {
-	LOG_FUNCTION();
+	//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("recv audio pkt num %d,single size %d",g_nAudioRecvNum,size);
+		static int icount = 0;
+		if (pseesion->phonemedia_conf.eDeviceType == eStand2sType && icount == 0){
+			icount++;
 			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);
 		}
 		
@@ -433,6 +435,9 @@ static int phonemedia_start(audio_session_t *session)
 	if (status != APR_SUCCESS) {
 		goto on_error;
 	}
+	else {
+		Dbg("audio engine start success!");
+	}
 
 	rc = rtp_session_create2(conf->local_rtp_ip, conf->local_rtp_port, 2, &media->rtpsess);
 	if (rc != 0) {

+ 16 - 3
Other/libaudioframework/audiocontext.c

@@ -56,29 +56,42 @@ static void *APR_THREAD_FUNC audiocontext_run(apr_thread_t *thread_handle, void
 #ifdef _WIN32
 		WaitForSingleObject(ctx->sem, INFINITE);
 #else
-		audio_log_v(AUDIO_LOG_LEVEL_INFO, "before sem_wait......");
+		//audio_log_v(AUDIO_LOG_LEVEL_INFO, "before sem_wait......");
 		sem_wait(ctx->sem);
-		audio_log_v(AUDIO_LOG_LEVEL_INFO, "after sem_wait......");
+		//audio_log_v(AUDIO_LOG_LEVEL_INFO, "after sem_wait......");
 #endif // _WIN32
 		if (!ctx->bstop) {
 			int i;
+			//audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d", __FUNCTION__, __LINE__);
 			apr_thread_mutex_lock(ctx->mtx);
+			//audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d", __FUNCTION__, __LINE__);
 			//OutputDebugStringA("enter lock");
 			for (i = 0; i < ctx->arr_drv->nelts; ++i) {
 				audiodriver_t *drv = APR_ARRAY_IDX(ctx->arr_drv, i, audiodriver_t*);
+				//audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d ctx->arr_drv->nelts = %d, drv = 0x%0x, drv->vtbl->process_frame = 0x%0x.", __FUNCTION__, __LINE__, ctx->arr_drv->nelts, drv, drv->vtbl->process_frame);
 				//暂时屏蔽rtp流发送功能
 				drv->vtbl->process_frame(drv);
+				//audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d drv = 0x%0x", __FUNCTION__, __LINE__, drv);
 			}
+			
+			//audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d ctx->event_list_cnt = %d", __FUNCTION__, __LINE__, ctx->event_list_cnt);
+
 			while (ctx->event_list_cnt > 0) {
 				event_entry *e = APR_RING_FIRST(&ctx->event_list);
 				event_handler_entry *ep1, *ep2;
+				//audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d", __FUNCTION__, __LINE__);
 				APR_RING_REMOVE(e, link);
 				ctx->event_list_cnt--;
 				APR_RING_FOREACH_SAFE(ep1, ep2, &ctx->event_handler_list, event_handler_entry, link) {
-					if ((*ep1->event_handler)(ctx, ep1->user_data, e->bstream, e->stream_or_driver, e->evt, e->param1, e->param2) == TRUE)
+					//audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d", __FUNCTION__, __LINE__);
+					if ((*ep1->event_handler)(ctx, ep1->user_data, e->bstream, e->stream_or_driver, e->evt, e->param1, e->param2) == TRUE) {
+						//audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d", __FUNCTION__, __LINE__);
 						break;
+					}
 				}
+				//audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d", __FUNCTION__, __LINE__);
 				APR_RING_INSERT_TAIL(&ctx->event_list_free, e, event_entry, link);
+				//audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d", __FUNCTION__, __LINE__);
 				ctx->event_list_free_cnt++;
 			}
 			//OutputDebugStringA("leave lock");

+ 5 - 2
Other/libaudioframework/audioengine.c

@@ -74,7 +74,7 @@ static void engine_on_clock(audioengine_t *e)
 		for (i = 0; i < e->arr_ctx->nelts; ++i) {
 			audiocontext_t *ctx = APR_ARRAY_IDX(e->arr_ctx, i, audiocontext_t*);
 			audiocontext_signal(ctx);
-			audio_log_v(AUDIO_LOG_LEVEL_INFO, "audiocontext_signal ********");
+			//audio_log_v(AUDIO_LOG_LEVEL_INFO, "audiocontext_signal (%d) ********", i);
 		}
 	}
 	apr_thread_mutex_unlock(e->mtx);
@@ -117,16 +117,19 @@ static void handler(union sigval si)
 	LONGLONG duration;
 	GetTick(&e->tick, &e->tick);
 
+	//audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d", __FUNCTION__, __LINE__);
+
 	diff = e->tick.QuadPart - e->start_tick.QuadPart;
 	duration = e->seq.QuadPart * FRAME_TIME;
 
 	if (diff > duration + 100) {
 		engine_on_clock(e);
 		engine_on_clock(e);
-		audio_log_v(AUDIO_LOG_LEVEL_ERROR, "time_cb swift, add one on clock!");
+		audio_log_v(AUDIO_LOG_LEVEL_ERROR, "diff > duration + 100 time_cb swift, add one on clock!");
 	}
 	else if (diff > duration - 100) {
 		engine_on_clock(e);
+		//audio_log_v(AUDIO_LOG_LEVEL_ERROR, "diff > duration - 100 time_cb swift, add one on clock!");
 	}
 	else {
 		audio_log_v(AUDIO_LOG_LEVEL_ERROR, "time_cb swift, remove one on clock!");

+ 47 - 64
Other/libaudioframework/audiomicspklinux.c

@@ -7,7 +7,8 @@
 #include <assert.h>
 #include <speex/speex_resampler.h>
 #include <time.h>
-
+#include <semaphore.h>
+#include <pthread.h>
 
 #define MAX_DELAY			60
 #define CLOCK_PERIOD		20
@@ -15,42 +16,6 @@
 #define CAPTURE_AUDIO_CLOCK	44100
 #define RESAMPLE_QUALITY	6
 
-
-static void From32To16Bit(void* input_data, int input_samples, void* output_data, int out_samples) {
-	int i = 0;
-	float f;
-	for (i = 0; i < input_samples; i++) {
-		float* pinput = (float*)input_data + i;
-		uint16_t* poutput = (uint16_t*)output_data + i;
-		//Dbg("[From32To16Bit]pinput :%f", *pinput);
-		f = *pinput;
-		f = f * 32768;
-		if (f > 32767) f = 32767;
-		if (f < -32768) f = -32768;
-		//转为正数
-		*poutput = f + 32768;
-		//Dbg("[From32To16Bit]poutput :%u, i: %d", *poutput, i);
-	}
-}
-
-static void From16ToFloat(void* input_data, int input_samples, void* output_data, int out_samples) {
-	int i = 0;
-	int input_value;
-	for (i = 0; i < input_samples; i++) {
-		uint16_t* pinput = (uint16_t*)input_data + i;
-		float* poutput = (float*)output_data + i;
-		//Dbg("[From16ToFloat]pinput :%u", *pinput);
-		input_value = *pinput;
-		//转为有符合数
-		input_value = input_value - 32768;
-		*poutput = ((float)input_value) / (float)32768;
-		if (*poutput > 1) *poutput = 1;
-		if (*poutput < -1) *poutput = -1;
-		//Dbg("[From16ToFloat]poutput :%f, i: %d", *poutput, i);
-	}
-}
-
-
 static int get_device_index(int indev, const char* key)
 {
 	int i;
@@ -81,6 +46,7 @@ static int outStreamCallback(const void* input,
 
 	if (output) {
 		unsigned nsamples_req = frameCount;
+		//audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d", __FUNCTION__, __LINE__);
 		if (micspk->ply_buf_cnt == 0 && nsamples_req == micspk->capture_frame_samples) {
 			char* float_output;
 			int float_samples;
@@ -88,15 +54,16 @@ static int outStreamCallback(const void* input,
 			spx_uint16_t high_outdata[512] = { 0 };
 			spx_uint32_t in_len = micspk->frame_samples;
 			spx_uint32_t out_len = micspk->capture_frame_samples;
+			//audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d delay_buf_get", __FUNCTION__,__LINE__);
 			delay_buf_get((delay_buf*)micspk->ply_dbuf, data);
 			//if (micspk->pcmfile && strlen(data) > 0)
 			//{
 			//	fwrite(data, in_len * sizeof(spx_int16_t), 1, micspk->pcmfile);
 			//}
-			//if (micspk->user_data)
-			//{
-			//	micspk->on_rx_audio((char*)data, micspk->user_data);
-			//}
+			if (micspk->user_data)
+			{
+				micspk->on_rx_audio((char*)data, micspk->user_data);
+			}
 			speex_resampler_process_int((SpeexResamplerState*)micspk->output_resample_state, 0,
 				data, &in_len, (spx_int16_t*)output, &out_len);
 			//if (micspk->highhzpcmFile)
@@ -120,18 +87,14 @@ static int inStreamCallback(const void* input,
 	void* userData)
 {
 	audiomicspklinux_t* micspk = userData;
-	apr_status_t status;
 
 	if (input) {
 		int in_samples = frameCount; //采集为32位float
 		if (micspk->rec_buf_cnt == 0 && frameCount == micspk->frame_samples) {
-			int before_resample_samples = frameCount;//重采样前转为16位
 			int after_resample_samples = frameCount;
-			char before_resample_buffer[frameCount * 16 / 8];
-			char after_resample_buffer[frameCount * 16 / 8];
-			From32To16Bit(input, in_samples, before_resample_buffer, before_resample_samples);
+			spx_uint16_t after_resample_buffer[128] = {0};
 			speex_resampler_process_int((SpeexResamplerState*)micspk->input_resample_state, 0,
-				before_resample_buffer, &before_resample_samples, (spx_int16_t*)after_resample_buffer, &after_resample_samples);
+				input, &in_samples, (spx_int16_t*)after_resample_buffer, &after_resample_samples);
 			delay_buf_put(micspk->rec_dbuf, (short*)after_resample_buffer);
 		}
 		else {
@@ -139,11 +102,9 @@ static int inStreamCallback(const void* input,
 			//先转换为需要的格式
 			int before_resample_samples = frameCount;//重采样前转为16位
 			int after_resample_samples = frameCount;
-			char before_resample_buffer[frameCount * 16 / 8];
-			char after_resample_buffer[frameCount * 16 / 8];
-			From32To16Bit(input, in_samples, before_resample_buffer, before_resample_samples);
+			spx_int16_t after_resample_buffer[128] = {0};
 			speex_resampler_process_int((SpeexResamplerState*)micspk->input_resample_state, 0,
-				before_resample_buffer, &before_resample_samples, (spx_int16_t*)after_resample_buffer, &after_resample_samples);
+				input, &before_resample_samples, (spx_int16_t*)after_resample_buffer, &after_resample_samples);
 
 			nsamples = after_resample_samples + micspk->rec_buf_cnt;
 			while (nsamples >= micspk->frame_samples) {
@@ -159,7 +120,7 @@ static int inStreamCallback(const void* input,
 				micspk->rec_buf_cnt += nsamples;
 			}
 		}
-		audio_log_v(AUDIO_LOG_LEVEL_INFO, "audio micro inStreamCallback.");
+		//audio_log_v(AUDIO_LOG_LEVEL_INFO, "audio micro inStreamCallback.");
 	}
 	
 	return paContinue;
@@ -185,7 +146,7 @@ static apr_status_t write_frame(void* self, const audioframe_t* frame)
 	//audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%s:%d micspk->frame_samples = %d, frame->size = %d.", __FILE__, __FUNCTION__, __LINE__, micspk->frame_samples, frame->size);
 	assert(micspk->frame_samples * 2 == frame->size);
 
-	//audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%s:%d", __FILE__, __FUNCTION__, __LINE__);
+	//audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d delay_buf_put", __FUNCTION__, __LINE__);
 	delay_buf_put(micspk->ply_dbuf, (short*)frame->buffer);
 	//if (micspk->putpcmfile && strlen(frame->buffer) > 0)
 	//{
@@ -363,13 +324,18 @@ static void uninitialize_micro(audiomicspklinux_t* micspk)
 	audio_log_v(AUDIO_LOG_LEVEL_INFO, "uninitialize_micro success!");
 }
 
-void* APR_THREAD_FUNC* audiowork_proc(apr_thread_t* threadhandle, void* param)
+//void* APR_THREAD_FUNC* audiowork_proc(apr_thread_t* threadhandle, void* param)
+void* audiowork_proc(void* param)
 {
 	audiomicspklinux_t* micspk = (audiomicspklinux_t*)param;
 	int rc;
+	struct sched_param schparam;
+	int policy;
+
 	audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d micspk addr is 0x%0x, current sem addr is 0x%0x.  started flag is %s.", __FUNCTION__, __LINE__, param, micspk->audio_device_started_sem, micspk->baudio_device_started_flag ? "true" : "false");
 	
-	
+	pthread_getschedparam(pthread_self(), &policy, &schparam);
+	audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d current thread policy is %d, priority is %d.", __FUNCTION__, __LINE__, policy, schparam.sched_priority);
 	//
 	// record need play because of AEC, so 
 	// record <---> record and play
@@ -465,6 +431,9 @@ apr_status_t audiomicspklinux_create(apr_pool_t* pool,
 	unsigned long frame_samples;
 	unsigned long capture_frame_samples;
 
+	pthread_attr_t attr;
+	struct sched_param param;
+
 	ply_dev_id = get_device_index(0, ply_dev_key);
 	rec_dev_id = get_device_index(1, rec_dev_key);
 
@@ -528,20 +497,34 @@ apr_status_t audiomicspklinux_create(apr_pool_t* pool,
 	micspk->baudio_device_started_flag = false;
 	sem_init(micspk->audio_device_started_sem, 0, 0);
 	audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d micspk addr is 0x%0x, current sem addr is 0x%0x. started flag is %s.", __FUNCTION__, __LINE__, micspk, micspk->audio_device_started_sem, micspk->baudio_device_started_flag ? "true" : "false");
-	apr_status_t err = apr_thread_create(&micspk->audio_work_threadid, NULL, audiowork_proc, micspk, pool);
-	if (APR_SUCCESS == err) {
-		audio_log_v(AUDIO_LOG_LEVEL_INFO, "create audiomicspk work thread success, %lu.", micspk->audio_work_threadid);
+	
+	pthread_attr_init(&attr);
+	param.sched_priority = sched_get_priority_max(SCHED_RR);
+	pthread_attr_setschedpolicy(&attr, SCHED_RR);
+	pthread_attr_setschedparam(&attr, &param);
+	pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);
+	int err = pthread_create(&micspk->audio_work_threadid, &attr, audiowork_proc, micspk);
+	if (0 == err) {
+		audio_log_v(AUDIO_LOG_LEVEL_INFO, "create audio micspk work thread success, %lu.", micspk->audio_work_threadid);
+	//}
+	//else {
+	//	audio_log_v(AUDIO_LOG_LEVEL_INFO, "create audio micspk work thread failed.");
+	//}
+	//
+	//apr_status_t err = apr_thread_create(&micspk->audio_work_threadid, NULL, audiowork_proc, micspk, pool);
+	//if (APR_SUCCESS == err) {
+	//	audio_log_v(AUDIO_LOG_LEVEL_INFO, "create audiomicspk work thread success, %lu.", micspk->audio_work_threadid);
 		bool baudio_work_thread_exit = false;
 		
 		do {
 			struct timespec ts;
-			int ivalue = -1;
+			//int ivalue = -1;
 			clock_gettime(CLOCK_REALTIME, &ts);
 			long unsec = ts.tv_nsec + (1000 * 1000 * 10);
 			ts.tv_sec += (unsec / 1000000000);
 			ts.tv_nsec = (unsec % 1000000000);
-			sem_getvalue(micspk->audio_device_started_sem, &ivalue);
-			audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d current sem value is %d.", __FUNCTION__, __LINE__, ivalue);
+			//sem_getvalue(micspk->audio_device_started_sem, &ivalue);
+			//audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d current sem value is %d.", __FUNCTION__, __LINE__, ivalue);
 			if(-1 == sem_timedwait(micspk->audio_device_started_sem, &ts)) {
 				if (ETIMEDOUT == errno){
 					if (micspk->baudio_device_started_flag) {
@@ -557,14 +540,14 @@ apr_status_t audiomicspklinux_create(apr_pool_t* pool,
 		} while (!baudio_work_thread_exit);
 
 		if (baudio_work_thread_exit) {
-			audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d", __FUNCTION__, __LINE__);
+			//audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d", __FUNCTION__, __LINE__);
 			audiomicspklinux_destroy(micspk);
-			audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d", __FUNCTION__, __LINE__);
+			//audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d", __FUNCTION__, __LINE__);
 			return APR_EGENERAL;
 		}
 	}
 	else {
-		audio_log_v(AUDIO_LOG_LEVEL_INFO, "create audiomicspk work thread failed.");
+		audio_log_v(AUDIO_LOG_LEVEL_INFO, "create audio micspk work thread failed.");
 		audiomicspklinux_destroy(micspk);
 		return APR_EGENERAL;
 	}

+ 1 - 1
Other/libaudioframework/audiomicspklinux.h

@@ -33,7 +33,7 @@ typedef struct audiomicspklinux_s
 	void* rec_dbuf;
 	unsigned long  rec_buf_cnt;
 
-	apr_thread_t* audio_work_threadid;
+	pthread_t audio_work_threadid;
 	sem_t* audio_device_started_sem;
 	bool baudio_device_started_flag;
 

+ 0 - 24
Other/libaudioframework/audiortp.c

@@ -49,15 +49,11 @@ 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;
 }
@@ -94,12 +90,9 @@ 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;
@@ -191,13 +184,11 @@ 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);
@@ -207,7 +198,6 @@ 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);
@@ -223,13 +213,11 @@ 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;
@@ -237,7 +225,6 @@ 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 {
@@ -246,16 +233,13 @@ 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) {
 			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, 
@@ -267,11 +251,8 @@ 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;
@@ -279,9 +260,7 @@ static apr_status_t write_frame(void *self, const audioframe_t *frame)
 				frame->buffer+audiortp->m_send_psize, 
 				audiortp->m_SendSample.size);			
 		}
-		Dbg("%s : %d", __FUNCTION__, __LINE__);
 	}
-	Dbg("%s : %d", __FUNCTION__, __LINE__);
 	return APR_SUCCESS;
 }
 
@@ -445,7 +424,6 @@ apr_status_t audiortp_get_param(audiortp_t *audiortp, int flag, void *ptr)
 apr_status_t audiortp_init(audiortp_t *ar)
 {
 	audiortp_t *audiortp = (audiortp_t *)ar;
-	Dbg("%s : %d", __FUNCTION__, __LINE__);
 	audiortp->m_send_samplebit = pt2bitsample(audiortp->m_send_pt);
 	audiortp->m_recv_samplebit = pt2bitsample(audiortp->m_recv_pt);
 	audiortp->m_send_psize = audiortp->m_send_ptime * audiortp->m_send_clock / 1000 * audiortp->m_send_samplebit / 8;
@@ -454,8 +432,6 @@ 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);
-	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;
 }
 

+ 16 - 18
Other/libaudioframework/other/delaybuf.c

@@ -252,29 +252,27 @@ int delay_buf_put(delay_buf *b,
     if (circ_buf_get_len(b->circ_buf) + b->samples_per_frame > 
 	b->max_cnt)
     {
-	unsigned erase_cnt;
-	
-	/* shrink one frame or just the diff? */
-	//erase_cnt = b->samples_per_frame;
-	erase_cnt = circ_buf_get_len(b->circ_buf) + 
+		unsigned erase_cnt;
+		/* shrink one frame or just the diff? */
+		//erase_cnt = b->samples_per_frame;
+		erase_cnt = circ_buf_get_len(b->circ_buf) + 
 		    b->samples_per_frame - b->max_cnt;
 
-	shrink_buffer(b, erase_cnt);
+		shrink_buffer(b, erase_cnt);
 
-	/* Check if shrinking failed or erased count is less than requested,
-	 * delaybuf needs to drop eldest samples, this is bad since the voice
-	 * samples get rough transition which may produce tick noise.
-	 */
-	if (circ_buf_get_len(b->circ_buf) + b->samples_per_frame > 
-	    b->max_cnt) 
-	{
-	    erase_cnt = circ_buf_get_len(b->circ_buf) + 
-			b->samples_per_frame - b->max_cnt;
+		/* Check if shrinking failed or erased count is less than requested,
+		* delaybuf needs to drop eldest samples, this is bad since the voice
+		* samples get rough transition which may produce tick noise.
+		*/
+		if (circ_buf_get_len(b->circ_buf) + b->samples_per_frame > 
+			b->max_cnt) 
+		{
+			erase_cnt = circ_buf_get_len(b->circ_buf) + 
+				b->samples_per_frame - b->max_cnt;
 
-	    circ_buf_adv_read_ptr(b->circ_buf, erase_cnt);
-	}
+			circ_buf_adv_read_ptr(b->circ_buf, erase_cnt);
+		}
     }
-
     circ_buf_write(b->circ_buf, frame, b->samples_per_frame);
 
 #ifdef _WIN32