Browse Source

Z991239-2055 #comment fix: 优化本地播放功能的稳定性

陈礼鹏80274480 4 years ago
parent
commit
548552aa35

+ 3 - 0
Other/libmediaplayer/audio.cpp

@@ -8,6 +8,9 @@ static void sdl_audio_callback(void *opaque, Uint8 *stream, int len);
 static int audio_decode_frame(AVCodecContext *p_codec_ctx, packet_queue_t *p_pkt_queue, AVFrame *frame, CMediaHostApi* hostapi)
 {
     int ret = -1;
+	if (NULL == p_codec_ctx){
+		return ret;
+	}
 
     while (0 == p_pkt_queue->abort_flag)
     {

+ 0 - 12
Other/libmediaplayer/demux.cpp

@@ -114,16 +114,6 @@ static int demux_thread(void *arg)
     // 4. 解复用处理
     while (0 == is->abort_request)
     {
-		//if (0 != ret)
-		//{
-		//	//SDL_Event event;
-		//	//event.type = FF_QUIT_EVENT;
-		//	//event.user.data1 = is;
-		//	//SDL_PushEvent(&event);
-		//	//is->rvc_hostapi->Debug("SDL_PushEvent FF_QUIT_EVENT.");
-		//	
-		//}
-        
         /* if the queue are full, no need to read more */
         if (is->audio_pkt_queue.size + is->video_pkt_queue.size > MAX_QUEUE_SIZE ||
             (stream_has_enough_packets(is->p_audio_stream[is->index], is->audio_idx[is->index], &is->audio_pkt_queue) &&
@@ -183,8 +173,6 @@ static int demux_thread(void *arg)
     }
 
     SDL_DestroyMutex(wait_mutex);
-	//SDL_Delay(100);
-	//is->abort_request = 1;
 	is->bread_finished = true;
 	is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "%s exit, thread id is %u, and is->abort_request = %d",SDL_GetThreadName(is->read_tid), SDL_ThreadID(), is->abort_request);
 

+ 15 - 29
Other/libmediaplayer/player.cpp

@@ -90,19 +90,10 @@ static int player_deinit(player_stat_t *is)
 		return -1;
 	}
 
-    is->abort_request = 1;
+	is->abort_request = 1;
 
     SDL_WaitThread(is->read_tid, NULL);
-	is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "is->read_tid finished.");
-    /* close each stream */
-    //if (is->audio_idx >= 0)
-	//{
-        //stream_component_close(is, is->p_audio_stream);
-    //}
-    //if (is->video_idx >= 0)
-	//{
-        //stream_component_close(is, is->p_video_stream);
-    //}
+	is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "demux thread finished.");
 
 	for (int index = 0; index < is->uFilesCount; index++){
 		if (NULL != is->p_fmt_ctx[index]){
@@ -110,21 +101,18 @@ static int player_deinit(player_stat_t *is)
 		}
 	}
 
-    packet_queue_abort(&is->video_pkt_queue, is->rvc_hostapi);
-    packet_queue_abort(&is->audio_pkt_queue, is->rvc_hostapi);
+    //packet_queue_abort(&is->video_pkt_queue, is->rvc_hostapi);
+    //packet_queue_abort(&is->audio_pkt_queue, is->rvc_hostapi);
 
-    packet_queue_destroy(&is->video_pkt_queue, is->rvc_hostapi);
-    packet_queue_destroy(&is->audio_pkt_queue, is->rvc_hostapi);
+    //packet_queue_destroy(&is->video_pkt_queue, is->rvc_hostapi);
+    //packet_queue_destroy(&is->audio_pkt_queue, is->rvc_hostapi);
 
 	frame_queue_signal(&is->video_frm_queue);
 	frame_queue_signal(&is->audio_frm_queue);
 
-	is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "before frame_queue_destory.");
     /* free all pictures */
-    frame_queue_destory(&is->video_frm_queue);
-	is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "after video_frm_queue frame_queue_destory.");
-    frame_queue_destory(&is->audio_frm_queue);
-	is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "after frame_queue_destory.");
+    //frame_queue_destory(&is->video_frm_queue);
+    //frame_queue_destory(&is->audio_frm_queue);
 
     SDL_DestroyCond(is->continue_read_thread);
 
@@ -138,14 +126,12 @@ static int player_deinit(player_stat_t *is)
 		}
 	}
 
-	is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "av_free player_stat_t.");
-	av_free(is->piconpath);
+	if (is->sdl_video.texture) {
+		SDL_DestroyTexture(is->sdl_video.texture);
+	}
 
-    if (NULL != is->sdl_video.texture){
-        //SDL_DestroyTexture(is->sdl_video.texture);
-    }
 	is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "av_free player_stat_t.");
-    av_free(is);
+    //av_free(is);
 
     return 0;
 }
@@ -222,7 +208,7 @@ CMediaPlayer::~CMediaPlayer()
 
 	Uint32 uRet = SDL_WasInit(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER);
 	if (0 != uRet) {
-		SDL_Quit();
+		//SDL_Quit();
 	}
 }
 
@@ -390,7 +376,7 @@ int CMediaPlayer::Init(rvc_media_player_param_t* pMedia_Player)
 		}
 
 	}
-	
+
 	iRet = 0;
 
 	return iRet;
@@ -500,7 +486,7 @@ int CMediaPlayer::ExitMediaPlayingThread()
 	m_player_stat = NULL;
 	m_bplaying = false;
 
-	avformat_network_deinit();
+	//avformat_network_deinit();
 
 	//SDL_Quit();
 

+ 1 - 1
Other/libmediaplayer/player.h

@@ -157,7 +157,7 @@ typedef enum eWindType_s {
 }eWindType_t;
 
 typedef struct player_stat_s{
-    char *filename;
+
     AVFormatContext *p_fmt_ctx[MAX_FILECOUNT];
     AVStream *p_audio_stream[MAX_FILECOUNT];
     AVStream *p_video_stream[MAX_FILECOUNT];