Sfoglia il codice sorgente

Z991239-4157 #comment 优化连线音频引擎处理流程

80274480 2 anni fa
parent
commit
399087fcbd

+ 6 - 30
Module/mod_sipphone/audio_session.cpp

@@ -821,15 +821,16 @@ static int phonemedia_stop(audio_session_t *session, int b_record_turn_off)
 		}
 		media->rtpsess = NULL;
 	}
-	//if (media->aecstream) {
-	//	audioaec_destroy(media->aecstream);
-	//	media->aecstream = NULL;
-	//}
+
 	if (media->dspstream) {
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start audiodsp_destroy");
 		audiodsp_destroy(media->dspstream);
 		media->dspstream = NULL;
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("audiodsp_destroy success!");
 	}
+
 	if (media->micspkstream) {
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start audiomicspk_destroy");
 #ifdef _WIN32
 		audiomicspk2_destroy(media->micspkstream);
 #else
@@ -840,32 +841,7 @@ static int phonemedia_stop(audio_session_t *session, int b_record_turn_off)
 		apr_pool_destroy(media->micspk_pool);
 		media->micspk_pool = NULL;
 	}
-	//if (media->record.state) {
-	//	if (media->record.codecstream) {
-	//		audiocodec_destroy(media->record.codecstream);
-	//		media->record.codecstream = NULL;
-	//	}
-	//	if (media->record.resizestream) {
-	//		audioresize_destroy(media->record.resizestream);
-	//		media->record.resizestream = NULL;
-	//	}
-	//	if (media->record.rtpstream) {
-	//		audiortp_destroy(media->record.rtpstream);
-	//		media->record.rtpstream = NULL;
-	//		unsigned short ilocal_port = 0;
-	//		rtp_session_get_local_rtp_port(media->record.rtpsess, &ilocal_port);
-	//		rtp_session_destroy(media->record.rtpsess);
-	//		{
-	//			char strInfo[MAX_PATH] = { 0 };
-	//			snprintf(strInfo, MAX_PATH, "audio rtp(record.rtpsess) destroy and local port is %u.", ilocal_port);
-	//			LogWarn(Severity_Low, Error_Debug, EVENT_MOD_SIP_AUDIO_RTP_DESTROY, strInfo);
-	//		}
-	//		media->record.rtpsess = NULL;
-	//	}
-	//	if (b_record_turn_off) {
-	//		media->record.state = 0;
-	//	}
-	//}
+
 	if (media->pool) {
 		apr_pool_destroy(media->pool);
 		media->pool = NULL;

+ 18 - 22
Other/libaudioframework/audiomicspkpulse.c

@@ -448,7 +448,7 @@ static void  stream_write_request_cb(pa_stream* s, size_t length, void* data)
 	void* audiodata;
 	while ((nbytes = pa_stream_writable_size(s)) != (size_t)-1)
 	{
-		audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d pa_stream_writable_size nbytes = %d.", __FUNCTION__, __LINE__, nbytes);
+		//audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d pa_stream_writable_size nbytes = %d.", __FUNCTION__, __LINE__, nbytes);
 		get_play_latency(s);
 		if (0 == nbytes){
 			return;
@@ -457,7 +457,7 @@ static void  stream_write_request_cb(pa_stream* s, size_t length, void* data)
 		/*write to stream*/
 		if (PA_OK == pa_stream_begin_write(s, &audiodata, &nbytes))
 		{
-			audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d pa_stream_begin_write nbytes = %d, audio_ctx->uaudio_len = %d.", __FUNCTION__, __LINE__, nbytes, audio_ctx->uaudio_len);
+			//audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d pa_stream_begin_write nbytes = %d, audio_ctx->uaudio_len = %d.", __FUNCTION__, __LINE__, nbytes, audio_ctx->uaudio_len);
 			while (audio_ctx->uaudio_len < nbytes)
 			{
 				char delaybuffer[RVC_DELAY_AUDIO_LEN] = { 0 };
@@ -477,12 +477,12 @@ static void  stream_write_request_cb(pa_stream* s, size_t length, void* data)
 								if (audio_ctx->uaudio_len + RVC_DELAY_AUDIO_LEN <= RVC_MAX_AUDIO_BUFFER_LEN) {
 									memcpy(audio_ctx->paudio_buffer + audio_ctx->uaudio_len, delaybuffer, RVC_DELAY_AUDIO_LEN);
 									audio_ctx->uaudio_len += RVC_DELAY_AUDIO_LEN;
-									audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d audio_ctx->uaudio_len = %d.", __FUNCTION__, __LINE__, audio_ctx->uaudio_len);
+									//audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d audio_ctx->uaudio_len = %d.", __FUNCTION__, __LINE__, audio_ctx->uaudio_len);
 								}
 								else {
 									memcpy(audio_ctx->paudio_buffer + audio_ctx->uaudio_len, delaybuffer, RVC_MAX_AUDIO_BUFFER_LEN - audio_ctx->uaudio_len);
 									audio_ctx->uaudio_len = RVC_MAX_AUDIO_BUFFER_LEN;		
-									audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d audio_ctx->uaudio_len = %d and break.", __FUNCTION__, __LINE__, audio_ctx->uaudio_len);
+									//audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d audio_ctx->uaudio_len = %d and break.", __FUNCTION__, __LINE__, audio_ctx->uaudio_len);
 									break;
 								}
 							//}
@@ -492,7 +492,7 @@ static void  stream_write_request_cb(pa_stream* s, size_t length, void* data)
 			}
 
 			int ileft = audio_ctx->uaudio_len - nbytes;
-			audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d ileft = %d.", __FUNCTION__, __LINE__, ileft);
+			//audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d ileft = %d.", __FUNCTION__, __LINE__, ileft);
 			if (ileft >= 0) {
 				memcpy(audiodata, audio_ctx->paudio_buffer, nbytes);
 				if (ileft > 0) {
@@ -511,9 +511,9 @@ static void  stream_write_request_cb(pa_stream* s, size_t length, void* data)
 				audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d pa_stream_write failed.", __FUNCTION__, __LINE__);
 				break;
 			}
-			else {
-				audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d pa_stream_write(%d) success.", __FUNCTION__, __LINE__, nbytes);
-			}
+			//else {
+			//	audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d pa_stream_write(%d) success.", __FUNCTION__, __LINE__, nbytes);
+			//}
 		}
 		else {
 			audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d pa_stream_begin_write failed for %s.", __FUNCTION__, __LINE__, pa_strerror(pa_context_errno(audio_ctx)));
@@ -914,15 +914,10 @@ int audio_stop_playaudio(audio_context_t* audio_ctx)
 	/*assertions*/
 	assert(audio_ctx != NULL);
 	if (AUDIO_STRM_ON == audio_ctx->play_stream_flag){
+		audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d set play_stream_flag to off.", __FUNCTION__, __LINE__);
 		audio_ctx->play_stream_flag = AUDIO_STRM_OFF;
 		if (0 != audio_ctx->writethreadid) {
 			if (0 == pthread_join(audio_ctx->writethreadid, NULL)) {
-			//struct timespec ts;
-			//clock_gettime(CLOCK_REALTIME, &ts);
-			//long unsec = ts.tv_nsec + (1000 * 1000 * 1000);
-			//ts.tv_sec += (unsec / 1000000000);
-			//ts.tv_nsec = (unsec % 1000000000);
-			//if (0 == pthread_timedjoin_np(audio_ctx->writethreadid, NULL, &ts)) {
 				audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d pulse audio write thread %u joined success.", __FUNCTION__, __LINE__, audio_ctx->writethreadid);
 				audio_ctx->writethreadid = 0;
 			}
@@ -931,6 +926,9 @@ int audio_stop_playaudio(audio_context_t* audio_ctx)
 			}
 		}
 	}
+	else {
+		audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d audio play stream flag is alreay off.", __FUNCTION__, __LINE__);
+	}
 
 	return 0;
 }
@@ -943,12 +941,6 @@ int audio_stop_pulseaudio(audio_context_t* audio_ctx)
 		audio_ctx->stream_flag = AUDIO_STRM_OFF;
 		if (0 != audio_ctx->readthreadid){
 			if (0 == pthread_join(audio_ctx->readthreadid, NULL)) {
-			//struct timespec ts;
-			//clock_gettime(CLOCK_REALTIME, &ts);
-			//long unsec = ts.tv_nsec + (1000 * 1000 * 1000);
-			//ts.tv_sec += (unsec / 1000000000);
-			//ts.tv_nsec = (unsec % 1000000000);
-			//if (0 == pthread_timedjoin_np(audio_ctx->readthreadid, NULL, &ts)) {
 				audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d pulse audio read thread %u joined success.", __FUNCTION__, __LINE__, audio_ctx->readthreadid);
 				audio_ctx->readthreadid = 0;
 			}
@@ -957,6 +949,9 @@ int audio_stop_pulseaudio(audio_context_t* audio_ctx)
 			}
 		}
 	}
+	else {
+		audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d audio read stream flag is alreay off.", __FUNCTION__, __LINE__);
+	}
 
 	return 0;
 }
@@ -1315,12 +1310,12 @@ apr_status_t audiomicspkpulse_create(apr_pool_t* pool,
 
 		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);
+			//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) {
@@ -1365,6 +1360,7 @@ void audiomicspkpulse_destroy(audiomicspkpulse_t* micspk)
 		audio_close_pulseaudio(micspk->audio_ctx);
 	}
 
+	audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d sem post audio_device_started_sem.", __FUNCTION__, __LINE__);
 	sem_post(micspk->audio_device_started_sem);
 
 	if (NULL != micspk->audio_work_thread){

+ 2 - 2
Other/libaudioframework/audiomicspkpulse.h

@@ -86,8 +86,8 @@ typedef struct audio_context_s
 	int64_t snd_begintime;        /*sound capture start ref time*/
 	int64_t ts_drift;             /*drift between real and generated ts*/
 
-	int stream_flag;              /*stream flag*/
-	int play_stream_flag;         /*stream flag*/
+	volatile int stream_flag;              /*stream flag*/
+	volatile int play_stream_flag;         /*stream flag*/
 	pthread_t readthreadid;
 	pthread_t writethreadid;
 

+ 1 - 1
Other/libaudiomgr/linux/libaudiomgr_linux.h

@@ -96,7 +96,7 @@ typedef struct rvc_audio_context_s
 	int capture_buff_size;        /*capture buffer size (bytes)*/
 	float capture_buff_level[2];  /*capture buffer channels level*/
 
-	int stream_flag;              /*stream flag*/
+	volatile int stream_flag;              /*stream flag*/
 
 	audiocap_param_t audio_param;
 }rvc_audio_context_t;