浏览代码

Z991239-2055 #comment fix: 优化sipphone实体的稳定性

陈礼鹏80274480 4 年之前
父节点
当前提交
981f1d7949

+ 1 - 2
Module/mod_sipphone/audio_session.cpp

@@ -348,7 +348,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, audio dir = %d",in_dev,out_dev, conf->dir);
+	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) {
@@ -607,7 +607,6 @@ on_error:
 static int phonemedia_stop(audio_session_t *session, int b_record_turn_off)
 {
 	audio_session_t *media = session;
-	Dbg("%s:%d", __FUNCTION__, __LINE__);
 	if (media->context) {
 		audioengine_stop_context(media->engine, media->context);
 		audiocontext_remove_driver(media->context, &media->bridge->base);

+ 1 - 1
Module/mod_sipphone/endpoint.cpp

@@ -1292,7 +1292,7 @@ static void __endpoint_stop(endpoint_t *ep)
 		su_task_execute(su_root_task(ep->root), &__endpoint_break, ep, &rc);
 		Dbg("%s:%d ep address is 0x%0x, event_threadid is %u.", __FUNCTION__, __LINE__, ep, ep->ievent_threadid);
 		if (0 == pthread_join(ep->ievent_threadid, NULL)) {
-			Dbg("pthread join success.");
+			Dbg("event_thread pthread join success.");
 			ep->ievent_threadid = 0;
 		}
 		else {

+ 2 - 6
Module/mod_sipphone/video_session.cpp

@@ -1474,7 +1474,6 @@ static int start_video(video_session_t *session)
 				}
 			}
 
-			Dbg("%s:%d.", __FUNCTION__, __LINE__);
 			if (0 != start_local_video_clock(session)) {
 				goto on_error;
 			}
@@ -2344,16 +2343,13 @@ static void stop_ui(video_session_t *session)
 	Dbg("set pg_last_session  to null.");
 
 #else
-	Dbg("%s:%d.", __FUNCTION__, __LINE__);
 	sem_post(&session->ui_stop_sem);
-	Dbg("%s:%d.", __FUNCTION__, __LINE__);
 	if (session->ui_threadid > 0) {
-		Dbg("%s:%d.", __FUNCTION__, __LINE__);
 		if (0 == pthread_join(session->ui_threadid, NULL)){
-			Dbg("pthread join success.");
+			Dbg("video render thread pthread join success.");
 		}
 		else{
-			Dbg("pthread join error for %s", strerror(errno));
+			Dbg("video render thread pthread join error for %s", strerror(errno));
 		}
 	}
 

+ 40 - 28
Other/libaudioframework/audiomicspkpulse.c

@@ -81,7 +81,7 @@ static int get_device_id(audio_context_t* audio_ctx, int indev, const char* key)
 
 	audio_device_t* audio_device = NULL;
 	
-	if (0 == indev){
+	if (1 == indev){
 		device_count = audio_ctx->num_input_dev;
 	}
 	else{
@@ -95,7 +95,7 @@ static int get_device_id(audio_context_t* audio_ctx, int indev, const char* key)
 		else {
 			audio_device = &audio_ctx->list_output_devices[index];
 		}
-
+		//audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d audio_device(%d) description is %s.", __FUNCTION__, __LINE__, indev, audio_device->description);
 		if (audio_device->description && strstr(audio_device->description, key)) {
 			iret = index;
 		}
@@ -883,13 +883,17 @@ int audio_stop_playaudio(audio_context_t* audio_ctx)
 {
 	/*assertions*/
 	assert(audio_ctx != NULL);
-	audio_ctx->play_stream_flag = AUDIO_STRM_OFF;
-
-	if (0 == pthread_join(audio_ctx->writethreadid, NULL)) {
-		audio_log_v(AUDIO_LOG_LEVEL_INFO, "AUDIO: (pulse audio) write thread joined success.");
-	}
-	else {
-		audio_log_v(AUDIO_LOG_LEVEL_INFO, "AUDIO: (pulse audio) write thread joined failed.");
+	if (AUDIO_STRM_ON == audio_ctx->play_stream_flag){
+		audio_ctx->play_stream_flag = AUDIO_STRM_OFF;
+		if (0 != audio_ctx->writethreadid) {
+			if (0 == pthread_join(audio_ctx->writethreadid, NULL)) {
+				audio_ctx->writethreadid = 0;
+				audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d pulse audio write thread joined success.", __FUNCTION__, __LINE__);
+			}
+			else {
+				audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d pulse audio write thread joined failed for %s.", __FUNCTION__, __LINE__, strerror(errno));
+			}
+		}
 	}
 
 	return 0;
@@ -899,15 +903,18 @@ int audio_stop_pulseaudio(audio_context_t* audio_ctx)
 {
 	/*assertions*/
 	assert(audio_ctx != NULL);
-	audio_ctx->stream_flag = AUDIO_STRM_OFF;
-
-	if (0 == pthread_join(audio_ctx->readthreadid, NULL)){
-		audio_log_v(AUDIO_LOG_LEVEL_INFO, "AUDIO: (pulse audio) read thread joined success.");
-	}
-	else {
-		audio_log_v(AUDIO_LOG_LEVEL_INFO, "AUDIO: (pulse audio) read thread joined failed.");
+	if (AUDIO_STRM_ON == audio_ctx->stream_flag){
+		audio_ctx->stream_flag = AUDIO_STRM_OFF;
+		if (0 != audio_ctx->readthreadid){
+			if (0 == pthread_join(audio_ctx->readthreadid, NULL)) {
+				audio_ctx->readthreadid = 0;
+				audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d pulse audio read thread joined success.", __FUNCTION__, __LINE__);
+			}
+			else {
+				audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d pulse audio read thread joined failed for %s.", __FUNCTION__, __LINE__, strerror(errno));
+			}
+		}
 	}
-	
 
 	return 0;
 }
@@ -915,14 +922,15 @@ int audio_stop_pulseaudio(audio_context_t* audio_ctx)
 
 void audio_close_pulseaudio(audio_context_t* audio_ctx)
 {
-	if (audio_ctx == NULL)
+	if (audio_ctx == NULL) {
 		return;
-
-	if (audio_ctx->play_stream_flag == AUDIO_STRM_ON){
+	}	
+	
+	if (audio_ctx->play_stream_flag == AUDIO_STRM_ON) {
 		audio_stop_playaudio(audio_ctx);
 	}
 
-	if (audio_ctx->stream_flag == AUDIO_STRM_ON){
+	if (audio_ctx->stream_flag == AUDIO_STRM_ON) {
 		audio_stop_pulseaudio(audio_ctx);
 	}
 
@@ -1208,8 +1216,7 @@ on_error:
 	else if (micspk->opt & AMS_OPT_PLAY) {
 		uninitialize_speaker(micspk);
 	}
-	else if (micspk->opt & AMS_OPT_RECORD)
-	{
+	else if (micspk->opt & AMS_OPT_RECORD){
 		uninitialize_micro(micspk);
 	}
 	audio_log_v(AUDIO_LOG_LEVEL_INFO, "audiowork_proc exit.");
@@ -1242,10 +1249,11 @@ apr_status_t audiomicspkpulse_create(apr_pool_t* pool,
 	micspk->ply_dev_id = get_device_id(micspk->audio_ctx, 0, ply_dev_key);
 	 
 	if (-1 == micspk->rec_dev_id || -1 == micspk->ply_dev_id) {
+		audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d, get device id failed!", __FUNCTION__, __LINE__);
 		return APR_EGENERAL;
 	}
 	else {
-		audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d , rec_dev_id is %d, ply_dev_id is %d.", __FUNCTION__, __LINE__, micspk->rec_dev_id, micspk->ply_dev_id);
+		audio_log_v(AUDIO_LOG_LEVEL_INFO, "%s:%d, rec_dev_id is %d, ply_dev_id is %d.", __FUNCTION__, __LINE__, micspk->rec_dev_id, micspk->ply_dev_id);
 	}
 
 	play_frame_samples = FRAME_TIME * clock / 1000;
@@ -1328,16 +1336,20 @@ void audiomicspkpulse_destroy(audiomicspkpulse_t* micspk)
 	assert(NULL != micspk);
 
 	sem_post(micspk->audio_device_started_sem);
-	
+
 	if (micspk->audio_ctx){
 		audio_close_pulseaudio(micspk->audio_ctx);
 	}
 
-	if (micspk->ply_dbuf)
+	if (micspk->ply_dbuf) {
 		delay_buf_destroy((delay_buf*)micspk->ply_dbuf);
-
-	if (micspk->rec_dbuf)
+		micspk->ply_dbuf = NULL;
+	}
+	
+	if (micspk->rec_dbuf) {
 		delay_buf_destroy((delay_buf*)micspk->rec_dbuf);
+		micspk->rec_dbuf = NULL;
+	}
 
 	if (micspk->opt & AMS_OPT_AS_ENGINE) {
 		//DeleteCriticalSection(&micspk->engine_lock);