Răsfoiți Sursa

Z991239-2234 #comment fix: 优化本地播放资源释放流程

陈礼鹏80274480 4 ani în urmă
părinte
comite
45ecb8c8e7

+ 3 - 3
Other/libmediaplayer/audio.cpp

@@ -205,14 +205,14 @@ int open_audio_stream(player_stat_t *is)
 	}
 
     // 2. 创建音频解码线程
-	SDL_Thread* audio_decode = SDL_CreateThread(audio_decode_thread, "audio decode thread", is);
-	if (NULL == audio_decode) {
+	is->audio_decode_tid = SDL_CreateThread(audio_decode_thread, "audio decode thread", is);
+	if (NULL == is->audio_decode_tid) {
 		is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "SDL_Create audio decode thread failed: %s.", SDL_GetError());
 		return -1;
 	}
 	else {
 		ret = 0;
-		is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "create %s success, and thread id is %u.", SDL_GetThreadName(audio_decode), SDL_GetThreadID(audio_decode));
+		is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "create %s success, and thread id is %u.", SDL_GetThreadName(is->audio_decode_tid), SDL_GetThreadID(is->audio_decode_tid));
 	}
 
     return ret;

+ 2 - 1
Other/libmediaplayer/demux.cpp

@@ -81,6 +81,7 @@ static int demux_init(player_stat_t *is)
 		is->video_idx[index] = v_idx;
 		is->p_audio_stream[index] = p_fmt_ctx->streams[a_idx];
 		is->p_video_stream[index] = p_fmt_ctx->streams[v_idx];
+		
 		ret = 0;
 	}
 
@@ -116,7 +117,7 @@ static int demux_thread(void *arg)
     while (0 == is->abort_request)
     {
         /* if the queue are full, no need to read more */
-        if (is->audio_pkt_queue.size + is->video_pkt_queue.size > MAX_QUEUE_SIZE ||
+        if (is->audio_pkt_queue.packet_queue_size + is->video_pkt_queue.packet_queue_size > MAX_QUEUE_SIZE ||
             (stream_has_enough_packets(is->p_audio_stream[is->index], is->audio_idx[is->index], &is->audio_pkt_queue) &&
              stream_has_enough_packets(is->p_video_stream[is->index], is->video_idx[is->index], &is->video_pkt_queue)))
         {

+ 6 - 1
Other/libmediaplayer/frame.cpp

@@ -9,12 +9,15 @@ void frame_queue_unref_item(frame_t *vp)
 int frame_queue_init(frame_queue_t *f, packet_queue_t *pktq, int max_size, int keep_last)
 {
     memset(f, 0, sizeof(frame_queue_t));
-    if (!(f->frame_mutex = SDL_CreateMutex())) {
+    
+	if (!(f->frame_mutex = SDL_CreateMutex())) {
         return AVERROR(ENOMEM);
     }
+
     if (!(f->frame_cond = SDL_CreateCond())) {
         return AVERROR(ENOMEM);
     }
+
     f->pktq = pktq;
     f->max_size = FFMIN(max_size, FRAME_QUEUE_SIZE);
     f->keep_last = !!keep_last;
@@ -24,6 +27,7 @@ int frame_queue_init(frame_queue_t *f, packet_queue_t *pktq, int max_size, int k
 			return AVERROR(ENOMEM);
 		}
 	}
+
     return 0;
 }
 
@@ -34,6 +38,7 @@ void frame_queue_destory(frame_queue_t *f)
         frame_queue_unref_item(vp);
         av_frame_free(&vp->frame);
     }
+
     SDL_DestroyMutex(f->frame_mutex);
     SDL_DestroyCond(f->frame_cond);
 }

+ 20 - 18
Other/libmediaplayer/packet.cpp

@@ -3,19 +3,20 @@
 int packet_queue_init(packet_queue_t *q, CMediaHostApi* hostapi)
 {
     memset(q, 0, sizeof(packet_queue_t));
+
     q->mutex = SDL_CreateMutex();
-    if (!q->mutex)
-    {
+    if (!q->mutex){
 		hostapi->Debug(MEDIA_LOG_DEBUG, "SDL_CreateMutex(): %s.", SDL_GetError());
         return AVERROR(ENOMEM);
     }
+
     q->cond = SDL_CreateCond();
-    if (!q->cond)
-    {
+    if (!q->cond){
 		hostapi->Debug(MEDIA_LOG_DEBUG, "SDL_CreateCond(): %s.", SDL_GetError());
         return AVERROR(ENOMEM);
     }
     q->abort_flag = 0;
+
     return 0;
 }
 
@@ -25,14 +26,13 @@ int packet_queue_put(packet_queue_t *q, AVPacket *pkt, CMediaHostApi* hostapi)
 {
 	AVPacketList* pkt_list = NULL;
 
-    if (av_packet_make_refcounted(pkt) < 0)
-    {
+    if (av_packet_make_refcounted(pkt) < 0){
 		hostapi->Debug(MEDIA_LOG_DEBUG, "[pkt] is not refrence counted.");
         return -1;
     }
+
     pkt_list = (AVPacketList*)av_malloc(sizeof(AVPacketList));
-    if (!pkt_list)
-    {
+    if (!pkt_list){
         return -1;
     }
     
@@ -51,13 +51,12 @@ int packet_queue_put(packet_queue_t *q, AVPacket *pkt, CMediaHostApi* hostapi)
     }
     q->last_pkt = pkt_list;
     q->nb_packets++;
-    q->size += pkt_list->pkt.size;
+    q->packet_queue_size += pkt_list->pkt.size;
     // 发个条件变量的信号:重启等待q->cond条件变量的一个线程
-	//printf("packet queue put new pkt, CondSignal cond.pkt == 0x%0x, pkt_list->pkt.data == 0x%0x,(pkt->data == 0x%0x) pkt_list->pkt.size = %d, (pkt->size == %d)\n\n\n",pkt, pkt_list->pkt.data, pkt->data, pkt_list->pkt.size, pkt->size);
-	//printf("packet queue put new pkt, CondSignal cond.\n");
 	SDL_CondSignal(q->cond);
 
     SDL_UnlockMutex(q->mutex);
+
     return 0;
 }
 
@@ -81,7 +80,7 @@ int packet_queue_get(packet_queue_t *q, AVPacket *pkt, int block)
                 q->last_pkt = NULL;
             }
             q->nb_packets--;
-            q->size -= p_pkt_node->pkt.size;
+            q->packet_queue_size -= p_pkt_node->pkt.size;
             *pkt = p_pkt_node->pkt;
             av_free(p_pkt_node);
             ret = 1;
@@ -89,13 +88,11 @@ int packet_queue_get(packet_queue_t *q, AVPacket *pkt, int block)
         }
 		else if (!block)            // 队列空且阻塞标志无效,则立即退出
 		{
-			//printf("packet queue is empty, and block flag is invalid, break.\n");
 			ret = 0;
 			break;
 		}
 		else                        // 队列空且阻塞标志有效,则等待
 		{
-			//printf("packet queue is empty, and block flag is valid, continue wait.\n");
 			SDL_CondWait(q->cond, q->mutex);
 		}
     }
@@ -121,13 +118,18 @@ void packet_queue_flush(packet_queue_t *q)
     SDL_LockMutex(q->mutex);
     for (pkt = q->first_pkt; pkt; pkt = pkt1) {
         pkt1 = pkt->next;
-        av_packet_unref(&pkt->pkt);
-        av_freep(&pkt);
+		if (pkt->pkt.size > 0)
+		{
+			q->packet_queue_size -= pkt->pkt.size;
+			av_packet_unref(&pkt->pkt);
+			av_freep(&pkt);
+			q->nb_packets--;
+		}
     }
     q->last_pkt = NULL;
     q->first_pkt = NULL;
     q->nb_packets = 0;
-    q->size = 0;
+    q->packet_queue_size = 0;
     q->duration = 0;
     SDL_UnlockMutex(q->mutex);
 }
@@ -144,7 +146,7 @@ void packet_queue_abort(packet_queue_t *q, CMediaHostApi* m_hostapi)
 {
     SDL_LockMutex(q->mutex);
     q->abort_flag = 1;
-	//m_hostapi->Debug("packet_queue_abort, CondSignal cond.");
+	m_hostapi->Debug(MEDIA_LOG_DEBUG, "packet_queue_abort, CondSignal cond.");
     SDL_CondSignal(q->cond);
     SDL_UnlockMutex(q->mutex);
 }

+ 116 - 113
Other/libmediaplayer/player.cpp

@@ -1,14 +1,4 @@
-/*******************************************************************************
- * player.c
- *
- * details:
- *   A simple ffmpeg player.
- *
- * refrence:
- *   ffplay.c in FFmpeg 4.1 project.
- *******************************************************************************/
-
-#include <stdio.h>
+#include <stdio.h>
 #include <stdbool.h>
 #include <assert.h>
 
@@ -20,8 +10,6 @@
 #include "audio.h"
 
 
-static int player_deinit(player_stat_t *is);
-
 // 返回值:返回上一帧的pts更新值(上一帧pts+流逝的时间)
 double get_clock(play_clock_t *c)
 {
@@ -82,81 +70,6 @@ static void sync_play_clock_to_slave(play_clock_t *c, play_clock_t *slave)
         set_clock(c, slave_clock, slave->serial);
 }
 
-
-static int player_deinit(player_stat_t *is)
-{
-    /* XXX: use a special url_shutdown call to abort parse cleanly */
-	if (NULL == is){
-		return -1;
-	}
-
-	is->abort_request = 1;
-
-    SDL_WaitThread(is->read_tid, NULL);
-	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]){
-			avformat_close_input(&is->p_fmt_ctx[index]);
-		}
-
-		if (NULL != is->p_acodec_ctx[index]){
-			avcodec_free_context(&is->p_acodec_ctx[index]);
-		}
-		
-		if (NULL != is->p_vcodec_ctx[index]) {
-			avcodec_free_context(&is->p_vcodec_ctx[index]);
-		}
-	}
-
-    packet_queue_abort(&is->video_pkt_queue, is->rvc_hostapi);
-    packet_queue_abort(&is->audio_pkt_queue, is->rvc_hostapi);
-
-	frame_queue_signal(&is->video_frm_queue);
-	frame_queue_signal(&is->audio_frm_queue);
-
-    SDL_DestroyCond(is->continue_read_thread);
-
-	if (is->eMType == eVideo_Type) {
-		for (int index = 0; index < is->uFilesCount; index++) {
-			is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "%s:%d is->img_convert_ctx[%d] = 0x%0x", __FUNCTION__, __LINE__, index, is->img_convert_ctx[index]);
-			if (NULL != is->img_convert_ctx[index]) {
-				sws_freeContext(is->img_convert_ctx[index]);
-				is->img_convert_ctx[index] = NULL;
-			}
-			if (NULL != is->p_frm_yuv[index]){
-				av_frame_free(&is->p_frm_yuv[index]);
-			}
-		}
-	}
-
-	if (is->sdl_video.texture) {
-		SDL_DestroyTexture(is->sdl_video.texture);
-	}
-
-	//packet_queue_destroy(&is->video_pkt_queue, is->rvc_hostapi);
-	//packet_queue_destroy(&is->audio_pkt_queue, is->rvc_hostapi);
-
-	///* free all pictures */
-	//frame_queue_destory(&is->video_frm_queue);
-	//frame_queue_destory(&is->audio_frm_queue);
-
-	is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "av_free player_stat_t.");
-
-	swr_free(&is->audio_swr_ctx);
-
-	is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "%s:%d", __FUNCTION__, __LINE__);
-	if (NULL != is->audio_frm_rwr) {
-		av_free(is->audio_frm_rwr);
-		is->audio_frm_rwr = NULL;
-	}
-
-	av_freep(is);
-
-	return 0;
-}
-
-
 /* pause or resume the video */
 static void stream_toggle_pause(player_stat_t *is)
 {
@@ -227,8 +140,7 @@ CMediaPlayer::CMediaPlayer(CMediaHostApi* pHostApi)
 CMediaPlayer::~CMediaPlayer()
 {
 	if (NULL != m_player_stat) {
-		player_deinit(m_player_stat);
-		m_player_stat = NULL;
+		UnInitialize_Player_Stat();
 	}
 
 	if (NULL != m_piconpath) {
@@ -284,7 +196,7 @@ int CMediaPlayer::Initialize_Player_Stat(rvc_media_player_param_t* pMedia_Player
 	}
 
 	if (NULL != m_player_stat) {
-		player_deinit(m_player_stat);
+		UnInitialize_Player_Stat();
 	}
 
 	m_player_stat = (player_stat_t*)av_mallocz(sizeof(player_stat_t));
@@ -319,8 +231,7 @@ int CMediaPlayer::Initialize_Player_Stat(rvc_media_player_param_t* pMedia_Player
 		memcpy(m_player_stat->strPlayLists[i], pMedia_Player->strPlayLists[i], strlen(pMedia_Player->strPlayLists[i]));
 	}
 	if (0 == pMedia_Player->uFilesCount || NULL == m_player_stat->rvc_hostapi || NULL == m_player_stat->prvc_cb || NULL == m_player_stat->piconpath) {
-		av_free(m_player_stat);
-		m_player_stat = NULL;
+		UnInitialize_Player_Stat();
 		return iRet;
 	}
 	else{
@@ -331,6 +242,106 @@ int CMediaPlayer::Initialize_Player_Stat(rvc_media_player_param_t* pMedia_Player
 }
 
 
+int CMediaPlayer::UnInitialize_Player_Stat()
+{
+	/* XXX: use a special url_shutdown call to abort parse cleanly */
+	if (NULL == m_player_stat) {
+		return -1;
+	}
+
+	m_player_stat->abort_request = 1;
+
+	SDL_WaitThread(m_player_stat->read_tid, NULL);
+	m_hostapi->Debug(MEDIA_LOG_DEBUG, "demux thread finished.");
+	
+	for (int index = 0; index < m_player_stat->uFilesCount; index++) {
+		if (NULL != m_player_stat->p_fmt_ctx[index]) {
+			avformat_close_input(&m_player_stat->p_fmt_ctx[index]);
+			m_player_stat->p_fmt_ctx[index] = NULL;
+		}
+
+		if (NULL != m_player_stat->p_acodec_ctx[index]) {
+			avcodec_free_context(&m_player_stat->p_acodec_ctx[index]);
+		}
+
+		if (NULL != m_player_stat->p_vcodec_ctx[index]) {
+			avcodec_free_context(&m_player_stat->p_vcodec_ctx[index]);
+		}
+	}
+
+	packet_queue_abort(&m_player_stat->video_pkt_queue, m_hostapi);
+	packet_queue_abort(&m_player_stat->audio_pkt_queue, m_hostapi);
+
+	frame_queue_signal(&m_player_stat->video_frm_queue);
+	frame_queue_signal(&m_player_stat->audio_frm_queue);
+
+	SDL_DestroyCond(m_player_stat->continue_read_thread);
+
+	if (NULL != m_player_stat->audio_decode_tid){
+		SDL_WaitThread(m_player_stat->audio_decode_tid, NULL);
+	}
+	if (m_player_stat->eMType == eVideo_Type) {
+		if (NULL != m_player_stat->video_decode_tid){
+			SDL_WaitThread(m_player_stat->video_decode_tid, NULL);
+			m_hostapi->Debug(MEDIA_LOG_DEBUG, "video decode thread finished.");
+		}
+
+		if (NULL != m_player_stat->video_playing_tid) {
+			SDL_WaitThread(m_player_stat->video_playing_tid, NULL);
+			m_hostapi->Debug(MEDIA_LOG_DEBUG, "video playing thread finished.");
+		}
+
+		for (int index = 0; index < m_player_stat->uFilesCount; index++) {
+			//m_player_stat->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "%s:%d m_player_stat->img_convert_ctx[%d] = 0x%0x", __FUNCTION__, __LINE__, index, m_player_stat->img_convert_ctx[index]);
+			if (NULL != m_player_stat->img_convert_ctx[index]) {
+				sws_freeContext(m_player_stat->img_convert_ctx[index]);
+				m_player_stat->img_convert_ctx[index] = NULL;
+			}
+			//m_player_stat->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "%s:%d m_player_stat->p_frm_yuv[%d] = 0x%0x", __FUNCTION__, __LINE__, index, m_player_stat->p_frm_yuv[index]);
+			if (NULL != m_player_stat->p_frm_yuv[index]) {
+				av_frame_free(&m_player_stat->p_frm_yuv[index]);
+				av_frame_unref(m_player_stat->p_frm_yuv[index]);
+			}
+			//m_player_stat->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "%s:%d m_player_stat->p_video_buffer[%d] = 0x%0x", __FUNCTION__, __LINE__, index, m_player_stat->p_video_buffer[index]);
+			if (NULL != m_player_stat->p_video_buffer[index]) {
+				av_free(m_player_stat->p_video_buffer[index]);
+				m_player_stat->p_video_buffer[index] = NULL;
+			}
+		}
+	}
+
+	packet_queue_destroy(&m_player_stat->video_pkt_queue, m_hostapi);
+	packet_queue_destroy(&m_player_stat->audio_pkt_queue, m_hostapi);
+
+	///* free all pictures */
+	frame_queue_destory(&m_player_stat->video_frm_queue);
+	frame_queue_destory(&m_player_stat->audio_frm_queue);
+
+	m_hostapi->Debug(MEDIA_LOG_DEBUG, "av_free player_stat_t.");
+
+	swr_free(&m_player_stat->audio_swr_ctx);
+
+	if (NULL != m_player_stat->audio_frm_rwr) {
+		av_free(m_player_stat->audio_frm_rwr);
+		m_player_stat->audio_frm_rwr = NULL;
+	}
+
+	if (m_player_stat->piconpath){
+		av_free(m_player_stat->piconpath);
+		m_player_stat->piconpath = NULL;
+	}
+
+	if (m_player_stat->paudiodev) {
+		av_free(m_player_stat->paudiodev);
+		m_player_stat->paudiodev = NULL;
+	}
+
+	av_free(m_player_stat);
+	m_player_stat = NULL;
+
+	return 0;
+}
+
 int CMediaPlayer::GetViceVideoDisplayInfo(int* icx, int* icy, int* iwidth, int* iheight)
 {
 	int iRet = -1;
@@ -368,12 +379,10 @@ int CMediaPlayer::InitParam(rvc_media_player_param_t* pMedia_Player)
 		frame_queue_init(&m_player_stat->audio_frm_queue, &m_player_stat->audio_pkt_queue, SAMPLE_QUEUE_SIZE, 1) < 0)
 	{
 		m_hostapi->Debug(MEDIA_LOG_DEBUG, "media frame queue init failed!");
-		player_deinit(m_player_stat);
-		m_player_stat = NULL;
+		UnInitialize_Player_Stat();
 		return iRet;
 	}
-	else
-	{
+	else{
 		m_hostapi->Debug(MEDIA_LOG_DEBUG, "frame queue init success!");
 	}
 
@@ -382,12 +391,10 @@ int CMediaPlayer::InitParam(rvc_media_player_param_t* pMedia_Player)
 		packet_queue_init(&m_player_stat->audio_pkt_queue, m_hostapi) < 0)
 	{
 		m_hostapi->Debug(MEDIA_LOG_DEBUG, "media packet queue init failed!");
-		player_deinit(m_player_stat);
-		m_player_stat = NULL;
+		UnInitialize_Player_Stat();
 		return iRet;
 	}
-	else
-	{
+	else{
 		m_hostapi->Debug(MEDIA_LOG_DEBUG, "packet queue init success!");
 	}
 
@@ -397,11 +404,9 @@ int CMediaPlayer::InitParam(rvc_media_player_param_t* pMedia_Player)
 	packet_queue_put(&m_player_stat->video_pkt_queue, &flush_pkt, m_hostapi);
 	packet_queue_put(&m_player_stat->audio_pkt_queue, &flush_pkt, m_hostapi);
 
-	if (!(m_player_stat->continue_read_thread = SDL_CreateCond()))
-	{
+	if (!(m_player_stat->continue_read_thread = SDL_CreateCond())){
 		m_hostapi->Debug(MEDIA_LOG_DEBUG, "SDL_CreateCond(): %s.", SDL_GetError());
-		player_deinit(m_player_stat);
-		m_player_stat = NULL;
+		UnInitialize_Player_Stat();
 		return iRet;
 	}
 
@@ -414,7 +419,6 @@ int CMediaPlayer::InitParam(rvc_media_player_param_t* pMedia_Player)
 		if (0 == GetViceVideoDisplayInfo(&m_player_stat->iDisplayCx, &m_player_stat->iDisplayCy, &m_player_stat->iDisplayWidth, &m_player_stat->iDisplayHeight)){
 			m_hostapi->Debug(MEDIA_LOG_DEBUG,"display cx is %d, cy is %d, width is %d, height is %d.", m_player_stat->iDisplayCx, m_player_stat->iDisplayCy, m_player_stat->iDisplayWidth, m_player_stat->iDisplayHeight);
 		}
-
 	}
 
 	iRet = 0;
@@ -488,7 +492,6 @@ int CMediaPlayer::StopMediaPlay()
 	m_player_stat->abort_request = 1;
 	if (m_bplaying) {
 		m_hostapi->Debug(MEDIA_LOG_DEBUG, "user stop audio play set SDL_PauseAudioDevice param to 1.");
-		//SDL_PauseAudio(1);
 		SDL_PauseAudioDevice(audio_dev, 1);
 	}
 
@@ -512,6 +515,10 @@ int CMediaPlayer::ExitMediaPlayingThread()
 	m_hostapi->Debug(MEDIA_LOG_DEBUG, "ExitMediaPlayingThread called.");
 
 	if(eVideo_Type == m_player_stat->eMType){
+		if (m_player_stat->sdl_video.texture) {
+			SDL_DestroyTexture(m_player_stat->sdl_video.texture);
+		}
+
 		if (m_player_stat->sdl_video.renderer){
 			SDL_DestroyRenderer(m_player_stat->sdl_video.renderer);
 		}
@@ -526,13 +533,9 @@ int CMediaPlayer::ExitMediaPlayingThread()
 		m_player_stat->prvc_cb->cb_play_media_finished(m_player_stat->prvc_cb->user_data);
 	}
 
-	player_deinit(m_player_stat);
-	m_player_stat = NULL;
-	m_bplaying = false;
-
-	//avformat_network_deinit();
+	UnInitialize_Player_Stat();
 
-	//SDL_Quit();
+	m_bplaying = false;
 
 	iRet = 0;
 

+ 6 - 1
Other/libmediaplayer/player.h

@@ -106,7 +106,7 @@ typedef struct sdl_video_s{
 typedef struct packet_queue_s{
     AVPacketList *first_pkt, *last_pkt;
     int nb_packets;                 // 队列中packet的数量
-    int size;                       // 队列所占内存空间大小
+    int packet_queue_size;          // 队列所占内存空间大小
     int64_t duration;               // 队列中所有packet总的播放时长
     int abort_flag;
     int serial;                     // 播放序列,所谓播放序列就是一段连续的播放动作,一个seek操作会启动一段新的播放序列
@@ -186,6 +186,7 @@ typedef struct player_stat_s{
     struct SwsContext *img_convert_ctx[MAX_FILECOUNT];
     struct SwrContext *audio_swr_ctx;
     AVFrame *p_frm_yuv[MAX_FILECOUNT];
+	uint8_t *p_video_buffer[MAX_FILECOUNT];
 
     audio_param_t audio_param_src;
     audio_param_t audio_param_tgt;
@@ -207,6 +208,9 @@ typedef struct player_stat_s{
 
     SDL_cond *continue_read_thread;
     SDL_Thread *read_tid;           // demux解复用线程
+	SDL_Thread* audio_decode_tid;	// 音频解码线程
+	SDL_Thread* video_decode_tid;   // 视频解码线程
+	SDL_Thread* video_playing_tid;  // 视频播放线程
 	
 	play_media_callback_t* prvc_cb;	// 播放状态回调函数
 	char* piconpath;				// icon图标路径
@@ -260,6 +264,7 @@ public:
 
 	int InitParam(rvc_media_player_param_t* pMedia_Player);
 	int Initialize_Player_Stat(rvc_media_player_param_t* pMedia_Player);
+	int UnInitialize_Player_Stat();
 	int SetVolume(uint8_t uVolume);
 	bool GetPlayingFlag();
 	void StartMediaPlay();

+ 10 - 8
Other/libmediaplayer/video.cpp

@@ -340,7 +340,7 @@ static int video_playing_thread(void *arg)
         remaining_time = REFRESH_RATE;
         // 立即显示当前帧,或延时remaining_time后再显示
         video_refresh(is, &remaining_time);
-		remaining_time += 0.040;
+		//remaining_time += 0.020;
     }
 
 	is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "video playing thread exit, thread id is %u, and is->abort_request = %d", SDL_ThreadID(), is->abort_request);
@@ -390,15 +390,17 @@ static int open_video_playing(void* arg)
 			is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "av_malloc() for buffer failed");
 			return -1;
 		}
+		is->p_video_buffer[index] = buffer;
 		// 使用给定参数设定p_frm_yuv->data和p_frm_yuv->linesize
 		ret = av_image_fill_arrays(is->p_frm_yuv[index]->data,     // dst data[]
 			is->p_frm_yuv[index]->linesize, // dst linesize[]
-			buffer,                  // src buffer
+			is->p_video_buffer[index],                  // src buffer
 			AV_PIX_FMT_YUV420P,      // pixel format
 			iplay_video_width,		// width
 			iplay_video_height,		// height
 			1                        // align
 		);
+
 		if (ret < 0) {
 			is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "av_image_fill_arrays() failed %d", ret);
 			return -1;;
@@ -502,13 +504,13 @@ static int open_video_playing(void* arg)
 			return -1;
 		}
 
-		SDL_Thread* video_playing = SDL_CreateThread(video_playing_thread, "video playing thread", is);
-		if (NULL == video_playing) {
+		is->video_playing_tid = SDL_CreateThread(video_playing_thread, "video playing thread", is);
+		if (NULL == is->video_playing_tid) {
 			is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "SDL_Create video playing thread failed: %s.", SDL_GetError());
 			return -1;
 		}
 		else {
-			is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "create %s success, and thread id is %u.", SDL_GetThreadName(video_playing), SDL_GetThreadID(video_playing));
+			is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "create %s success, and thread id is %u.", SDL_GetThreadName(is->video_playing_tid), SDL_GetThreadID(is->video_playing_tid));
 		}
 	}
 
@@ -560,13 +562,13 @@ static int open_video_stream(player_stat_t *is)
 	}
 
     // 2. 创建视频解码线程
-	SDL_Thread* video_decode = SDL_CreateThread(video_decode_thread, "video decode thread", is);
-	if (NULL == video_decode) {
+	is->video_decode_tid = SDL_CreateThread(video_decode_thread, "video decode thread", is);
+	if (NULL == is->video_decode_tid) {
 		is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "SDL_Create video decode thread failed: %s.", SDL_GetError());
 		return -1;
 	}
 	else {
-		is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "create %s success, and thread id is %u.", SDL_GetThreadName(video_decode), SDL_GetThreadID(video_decode));
+		is->rvc_hostapi->Debug(MEDIA_LOG_DEBUG, "create %s success, and thread id is %u.", SDL_GetThreadName(is->video_decode_tid), SDL_GetThreadID(is->video_decode_tid));
 	}
 
     return 0;