Explorar o código

Z991239-2055 #comment fix: 解决连续多次调用播放图片接口存在播放失败问题

陈礼鹏80274480 %!s(int64=4) %!d(string=hai) anos
pai
achega
58dffdc733

+ 3 - 1
Module/mod_localmediaplay/mod_localmediaplay.cpp

@@ -551,6 +551,7 @@ ErrorCodeEnum CLocalMediaPlayEntity::__OnStart(ErrorCodeEnum preOperationError)
 		m_pVideoPlayer[i] = new Clibwmpplayer(this);
 		m_pImagePlayer[i] = new Clibimgplayer(this);
 #else
+		mediaplayer_init();
 		m_pMediaPlayer[i] = new Clibmediaplayer(this);
 		m_pPicturePlayer[i] = new Clibpictureplayer(this);
 #endif 
@@ -619,6 +620,7 @@ ErrorCodeEnum CLocalMediaPlayEntity::__OnClose(ErrorCodeEnum preOperationError)
 	delete m_pAudioPlayer; m_pAudioPlayer = NULL;
 #else
 	delete m_pMediaAudioPlayer; m_pMediaAudioPlayer = NULL;
+	mediaplayer_term();
 #endif // RVC_OS_WIN
 	
 	GetFunction()->UnsubscribeLog(m_SubIDIEIdle);
@@ -929,7 +931,7 @@ void* StartMediaPlayFunc(void* param)
 					Dbg("Image Media Player Thread id is %u.", playThreadId);
 				}
 				if (0 == pthread_join(playThreadId, NULL)){
-					//Dbg("pthread join thread id %u success.", playThreadId);
+					Dbg("pthread join thread id %u success.", playThreadId);
 					iRet = 0;
 				}
 				else {

+ 15 - 4
Other/libmediaplayer/libmediaplayer.cpp

@@ -73,7 +73,7 @@ public:
 		memcpy(t_param.strPlayLists[0], strVideoName, strlen(strVideoName));
 		t_param.uFilesCount = 1;
 
-		if (0 == m_Player->Init(&t_param))
+		if (0 == m_Player->InitParam(&t_param))
 		{
 			m_bisplaying = true;
 			m_Player->StartMediaPlay();
@@ -163,7 +163,7 @@ public:
 		cb.user_data = this;
 		t_param.cb = &cb;
 
-		if (0 == m_Player->Init(&t_param)){
+		if (0 == m_Player->InitParam(&t_param)){
 			m_pHostApi->Debug(MEDIA_LOG_DEBUG, "Player Init success!");
 			m_bisplaying = true;
 			m_Player->StartMediaPlay();
@@ -255,7 +255,7 @@ public:
 		cb.user_data = this;
 		t_param.cb = &cb;
 
-		if (0 == m_Player->Init(&t_param)){
+		if (0 == m_Player->InitParam(&t_param)){
 			m_bisplaying = true;
 			m_Player->StartMediaPlay();
 			iRet = 0;
@@ -324,7 +324,7 @@ public:
 		t_param.cb = &cb;
 
 		m_Player->SetVolume(config.nVolume);
-		if (0 == m_Player->Init(&t_param)) {
+		if (0 == m_Player->InitParam(&t_param)) {
 			m_bisplaying = true;
 			m_Player->StartMediaPlay();
 			iRet = 0;
@@ -451,3 +451,14 @@ void Clibmediaplayer::PlaySalesRecordVideo(int nWndX, int nWndY, int nWndWidth,
 {
 	m_pImpl->StartPlaySalesRecordVideo(nWndX, nWndY, nWndWidth, nWndHeight, pVideoDir, pNamePrefix, nVideoCount);
 }
+
+int mediaplayer_init()
+{
+	avcodec_register_all();
+	return 0;
+}
+
+int mediaplayer_term()
+{
+	return 0;
+}

+ 3 - 0
Other/libmediaplayer/libmediaplayer.h

@@ -44,3 +44,6 @@ public:
 private:
 	libmediaplayer_impl* m_pImpl;
 };
+
+extern "C" LIBMEDIAPLAYER_API int mediaplayer_init();
+extern "C" LIBMEDIAPLAYER_API int mediaplayer_term();

+ 2 - 1
Other/libmediaplayer/player.cpp

@@ -316,9 +316,10 @@ int CMediaPlayer::GetViceVideoDisplayInfo(int* icx, int* icy, int* iwidth, int*
 	return iRet;
 }
 
-int CMediaPlayer::Init(rvc_media_player_param_t* pMedia_Player)
+int CMediaPlayer::InitParam(rvc_media_player_param_t* pMedia_Player)
 {
 	int iRet = -1;
+
 	if (0 != Initialize_Player_Stat(pMedia_Player)){
 		return iRet;
 	}

+ 1 - 1
Other/libmediaplayer/player.h

@@ -252,7 +252,7 @@ public:
 	CMediaPlayer(CMediaHostApi* pHostApi);
 	~CMediaPlayer();
 
-	int Init(rvc_media_player_param_t* pMedia_Player);
+	int InitParam(rvc_media_player_param_t* pMedia_Player);
 	int Initialize_Player_Stat(rvc_media_player_param_t* pMedia_Player);
 	int SetVolume(uint8_t uVolume);
 	bool GetPlayingFlag();

+ 52 - 11
Other/libpictureplayer/CPicturePlayer.cpp

@@ -2,6 +2,8 @@
 #include <stdbool.h>
 #include <assert.h>
 #include <string.h>
+#include <time.h>
+#include <errno.h>
 
 #include "CPicturePlayer.h"
 
@@ -66,6 +68,20 @@ CPicturePlayer::CPicturePlayer(CPicHostApi* pHostApi)
 	m_show_width = 0;
 	m_show_height = 0;
 	m_busrstop = false;
+
+	Uint32 uRet = SDL_WasInit(SDL_INIT_VIDEO);
+
+	if (0 == uRet) {
+		if (SDL_Init(SDL_INIT_VIDEO))
+		{
+			m_pHostApi->PicDebug(PIC_LOG_ERROR, "Could not initialize SDL - %s", SDL_GetError());
+			m_pHostApi->PicDebug(PIC_LOG_ERROR, "(Did you set the DISPLAY variable?)");
+		}
+		else {
+			uRet = SDL_WasInit(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER);
+			m_pHostApi->PicDebug(PIC_LOG_DEBUG, "initialize SDL success, and init ret = %d.", uRet);
+		}
+	}
 }
 
 CPicturePlayer::~CPicturePlayer()
@@ -87,19 +103,21 @@ size_t CPicturePlayer::GetVideoDisplayInfo()
 	return uCount;
 }
 
-int CPicturePlayer::Init(rvc_picture_player_param_t* tparam)
+int CPicturePlayer::InitParam(rvc_picture_player_param_t* tparam)
 {
 	int iRet = -1;
 	if (NULL == tparam) {
 		return iRet;
 	}
 
-	if (0 != SDL_Init(SDL_INIT_VIDEO)) {
-		m_pHostApi->PicDebug(PIC_LOG_ERROR,"Could not initialize SDL - %s", SDL_GetError());
-		m_pHostApi->PicDebug(PIC_LOG_ERROR, "(Did you set the DISPLAY variable?)");
-		return iRet;
-	}
+	//if (0 != SDL_Init(SDL_INIT_VIDEO)) {
+	//	m_pHostApi->PicDebug(PIC_LOG_ERROR,"Could not initialize SDL - %s", SDL_GetError());
+	//	m_pHostApi->PicDebug(PIC_LOG_ERROR, "(Did you set the DISPLAY variable?)");
+	//	return iRet;
+	//}
 
+	sem_init(&m_play_exit_sem, 0, 0);
+	m_busrstop = false;
 
 	m_nfile_cnt = tparam->nfile_cnt;
 	m_nplay_cnt = tparam->nplay_cnt;
@@ -116,8 +134,8 @@ int CPicturePlayer::Init(rvc_picture_player_param_t* tparam)
 
 	size_t uVideoPlayNum = GetVideoDisplayInfo();
 
-	int idispalycx = SDL_WINDOWPOS_UNDEFINED;
-	int idispalycy = SDL_WINDOWPOS_UNDEFINED;
+	int idispalycx = 0;
+	int idispalycy = 0;
 	int idispaly_width = m_dispalymode[0].w;
 	int idispaly_height = m_dispalymode[0].h;
 
@@ -174,6 +192,7 @@ int CPicturePlayer::DeInit()
 	m_show_width = 0;
 	m_show_height = 0;
 	m_busrstop = false;
+	sem_destroy(&m_play_exit_sem);
 
 
 	if (NULL != m_window) {
@@ -235,7 +254,28 @@ bool CPicturePlayer::StartPicPlay()
 
 			SDL_FreeSurface(surface);
 			SDL_FreeSurface(image);
-			SDL_Delay(m_nplay_interval);
+			//SDL_Delay(m_nplay_interval);
+
+			struct timespec ts;
+			int itimems = m_nplay_interval;
+			clock_gettime(CLOCK_REALTIME, &ts);
+			if (itimems > 1000){
+				ts.tv_sec += (itimems / 1000);
+				itimems = m_nplay_interval % 1000;
+			}
+			
+			long unsec = ts.tv_nsec + (1000 * 1000 * itimems);
+			ts.tv_sec += (unsec / 1000000000);
+			ts.tv_nsec = (unsec % 1000000000);
+			
+			if (-1 == sem_timedwait(&m_play_exit_sem, &ts)) {
+				if (ETIMEDOUT == errno) {
+
+				}
+			}
+			else {
+				break;
+			}
 		}
 	}
 
@@ -247,7 +287,8 @@ bool CPicturePlayer::StartPicPlay()
 		m_pHostApi->PicDebug(PIC_LOG_INFO, "user stop picture playing task, exit");
 	}
 
-	SDL_Quit();
+	SDL_DestroyWindow(m_window);
+	m_window = NULL;
 
 	bRet = true;
 
@@ -258,7 +299,7 @@ bool CPicturePlayer::StartPicPlay()
 int CPicturePlayer::StopPicPlay()
 {
 	int iRet = -1;
-
+	sem_post(&m_play_exit_sem);
 	m_busrstop = true;
 	m_pHostApi->PicDebug(PIC_LOG_DEBUG, "stop picture play, set user stop flag true.");
 

+ 4 - 2
Other/libpictureplayer/CPicturePlayer.h

@@ -4,6 +4,7 @@
 #include <stdio.h>
 #include <stdint.h>
 #include <stdbool.h>
+#include <semaphore.h>
 
 #include "ipicdatastruct.h"
 
@@ -66,7 +67,7 @@ public:
 	CPicturePlayer(CPicHostApi* pHostApi);
 	~CPicturePlayer();
 
-	int Init(rvc_picture_player_param_t* tparam);
+	int InitParam(rvc_picture_player_param_t* tparam);
 	int DeInit();
 	bool StartPicPlay();
 	int StopPicPlay();
@@ -85,12 +86,13 @@ public:
 	int m_show_width;
 	int m_show_height;
 	bool m_busrstop;
-
+	
 private:
 	bool m_bplaying;
 	char* m_stricopath;
 	SDL_Thread* m_thid;
 	SDL_DisplayMode m_dispalymode[MAX_DISPLAYNUM];
+	sem_t m_play_exit_sem;
 };
 
 

+ 7 - 2
Other/libpictureplayer/libpictureplayer.cpp

@@ -88,7 +88,7 @@ public:
 
 		//if (0 == GetPicturePlayingParams(&tplayer_param)) 
 		{
-			if (0 == m_Player->Init(&tplayer_param))
+			if (0 == m_Player->InitParam(&tplayer_param))
 			{
 				m_pHostApi->PicDebug(PIC_LOG_DEBUG, "init picture player success and begin start picture play.");
 				int err = pthread_create(&m_PlayThreadId, NULL, PicturePlayingFunc, m_Player);
@@ -151,6 +151,11 @@ public:
 	bool StartPlay(int nCfgInx, int nWndX, int nWndY, int nWndWidth, int nWndHeight)
 	{
 		bool bRet = false;
+		if (true == m_Player->GetPicPlayingFlag()){
+			m_pHostApi->PicDebug(PIC_LOG_DEBUG, "now is playing!");
+			return true;
+		}
+
 		int iRet = m_pHostApi->LoadPlayConfig(m_stPlayConfig, nCfgInx);
 		if (0 != iRet){
 			m_pHostApi->PicDebug(PIC_LOG_DEBUG, "Load ImgConfiguration failed!");
@@ -173,7 +178,7 @@ public:
 		tplayer_param.uwindow_height = m_stPlayConfig.nWndHeight;
 
 		if (0 == GetPicturePlayingParams(&tplayer_param)) {
-			if (0 == m_Player->Init(&tplayer_param))
+			if (0 == m_Player->InitParam(&tplayer_param))
 			{
 				m_pHostApi->PicDebug(PIC_LOG_DEBUG, "init picture player Success.");
 				m_pHostApi->PicDebug(PIC_LOG_DEBUG, "start picture play success.");