Prechádzať zdrojové kódy

Z991239-1387 #comment other: 优化播放器ico设置实现方式

陈礼鹏80274480 4 rokov pred
rodič
commit
2bf50f247e

+ 82 - 49
Module/mod_localmediaplay/mod_localmediaplay.cpp

@@ -238,10 +238,10 @@ void CLocalMediaPlayEntity::loadDefaultMedia()
 				Dbg("config.strRootPath: %s", curVideo.strRootPath);
 
 				CSimpleStringA strRunTime_S, strRunTime_E;
-				// ����ͨ������
+				
 				table.AddEntryString("General", "VideoRunTime_Start", strRunTime_S, "");
 				table.AddEntryString("General", "VideoRunTime_End", strRunTime_E, "");
-				// ������Ƶ����
+				
 				table.AddEntryBoolean(sectionList[i].GetData(), "FullScreen", curVideo.bFullScreen, false);
 				table.AddEntryBoolean(sectionList[i].GetData(), "PrimMonitor", curVideo.bPrimMonitor, false);
 				table.AddEntryBoolean(sectionList[i].GetData(), "SimpleMode", curVideo.bSimpleMode, true);
@@ -253,7 +253,6 @@ void CLocalMediaPlayEntity::loadDefaultMedia()
 				else
 					Dbg("Fail to LoadWmpConfig!");
 
-				// �������� add by ly at 2017/06/06
 				curVideo.nVolume = 50;
 				Error = GetFunction()->OpenConfig(Config_Run, tempConfig);
 				if (Error == Error_Succeed)
@@ -309,7 +308,6 @@ void CLocalMediaPlayEntity::loadDefaultMedia()
 				table.AddEntryInt(sectionList[i], "PlayCount", curAudio.nPlayCnt, 0);
 				table.AddEntryInt(sectionList[i], "PlayInterval", curAudio.nPlayInterval, 0);
 
-				// �������� 
 				auto audioRet = GetLocalAudioVolume();
 				if (audioRet.first)
 					curAudio.nVolume = audioRet.second;
@@ -450,6 +448,41 @@ void CLocalMediaPlayEntity::AudioPlayFinished()
 	SpSendBroadcast(GetFunction(), eMsg_AudioPlayRet, eMsgSig_AudioPlayRet, ret);
 }
 
+int CLocalMediaPlayEntity::GetMediaPlayerIcoPath(char* strPath, size_t uLen)
+{
+	return GetPlayerIcoPath(strPath, uLen);
+}
+
+int CLocalMediaPlayEntity::GetPicPlayerIcoPath(char* strPath, size_t uLen)
+{
+	return GetPlayerIcoPath(strPath, uLen);
+}
+
+
+int CLocalMediaPlayEntity::GetPlayerIcoPath(char* strPath, size_t uLen)
+{
+	int iRet = -1;
+	if (NULL == strPath) {
+		return iRet;
+	}
+	CSimpleStringA csBinPath, csBackslash("/");
+	ErrorCodeEnum eErrPath = GetFunction()->GetPath("Bin", csBinPath);
+	if (eErrPath != Error_Succeed) {
+		Dbg("GetBasePath failed (%d).", eErrPath);
+		return iRet;
+	}
+
+	CSimpleStringA szIcoName("rvc_media_player_64px.bmp");
+	szIcoName = csBinPath + csBackslash + szIcoName;
+	Dbg("media player ico full path is %s.", szIcoName.GetData());
+
+	if (uLen > szIcoName.GetLength()) {
+		memcpy(strPath, szIcoName.GetData(), szIcoName.GetLength());
+		iRet = 0;
+	}
+
+	return iRet;
+}
 #endif // RVC_OS_WIN
 
 
@@ -510,10 +543,8 @@ ErrorCodeEnum CLocalMediaPlayEntity::__OnStart(ErrorCodeEnum preOperationError)
 
 	//setMediaPath();
 	loadDefaultMedia();
-
-	// ����IEBrowser�����¼�
+	
 	GetFunction()->SubscribeLog(m_SubIDIEIdle, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_SELFCHECK_IEBROWSER_IDLE, NULL, false);
-	// ʵ�������Ŷ���
 
 #ifdef RVC_OS_WIN
 	m_scanThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)& qryMedia, this, 0, NULL);
@@ -558,9 +589,7 @@ ErrorCodeEnum CLocalMediaPlayEntity::__OnClose(ErrorCodeEnum preOperationError)
 	delete m_pMediaAudioPlayer; m_pMediaAudioPlayer = NULL;
 #endif // RVC_OS_WIN
 	
-	// �˶�������ҳ�¼�
 	GetFunction()->UnsubscribeLog(m_SubIDIEIdle);
-	// �ͷŲ��Ŷ���
 	return Error_Succeed;
 }
 
@@ -591,26 +620,20 @@ DWORD WINAPI CheckAudioThread(LPVOID param)
 
 #else
 
-void* CheckAudioPlayingThreadFunc(void* param)
+void* StartAudioPlayingThreadFunc(void* param)
 {
 	CLocalMediaPlayEntity* entity = (CLocalMediaPlayEntity*)param;
-	Dbg("Begin CheckAudioPlayingThreadFunc");
-
-	pthread_t playThreadId = 0;
-	if (!entity->m_pMediaAudioPlayer->checkIsPlay(&playThreadId))
-	{
-		Dbg("Create play audio Media Thread Failed!");
-		return 0;
+	Dbg("Enter StartAudioPlayingThreadFunc");
+	const char* pAudioNames = entity->m_lastPlayAudio.c_str();
+	Dbg("Begin StartAudio, and Audio Info is %s.", pAudioNames);
+	if (0 == entity->m_pMediaAudioPlayer->PlayLocalAudio(pAudioNames)) {
+		Dbg("Succeed to StartAudio, and Audio Info is %s.", pAudioNames);
 	}
-	pthread_join(playThreadId, NULL);
-
-	AudioPlayRet ret;
-	ret.AudioNames = entity->m_lastPlayAudio.c_str();
-	ret.ret = true;
-	Dbg("stop play audio %s success", ret.AudioNames);
-	SpSendBroadcast(entity->GetFunction(), eMsg_AudioPlayRet, eMsgSig_AudioPlayRet, ret);
+	else{
+		Dbg("StartAudio failed, for %s is not exsit.", pAudioNames);
+	}
+	Dbg("Leave StartAudioPlayingThreadFunc");
 
-	return 0;
 }
 
 #endif // RVC_OS_WIN
@@ -756,11 +779,11 @@ DWORD WINAPI MediaPlayThread(LPVOID param)
 	return 0;
 }
 #else
-int StartMediaPlay(void* param)
+void* StartMediaPlayFunc(void* param)
 {
 	int iRet = -1;
 	if (NULL == param){
-		return iRet;
+		return (void*)&iRet;
 	}
 
 	CLocalMediaPlayEntity* entity = (CLocalMediaPlayEntity*)param;
@@ -806,14 +829,14 @@ int StartMediaPlay(void* param)
 			if (!entity->m_pMediaPlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(&playThreadId))
 			{
 				Dbg("Create play Video Media Thread Failed!");
-				return iRet;
+				return (void*)&iRet;
 			}
 			iRet = 0;
 			pthread_join(playThreadId, NULL);
 			if (entity->m_pMediaPlayer[entity->m_mediaParam.nCfgInx]->checkIsStop())
 			{//ֹͣ����
 				Dbg("stop play video");
-				return iRet;
+				return (void*)&iRet;
 			}
 		}
 
@@ -852,13 +875,15 @@ int StartMediaPlay(void* param)
 				if (!entity->m_pMediaPlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(&playThreadId))
 				{
 					Dbg("Create play Video Media Thread Failed!");
-					return 0;
+					iRet = 0;
+					return (void*)& iRet;
 				}
 				pthread_join(playThreadId, NULL);
 				if (entity->m_pMediaPlayer[entity->m_mediaParam.nCfgInx]->checkIsStop())
 				{//ֹͣ����
 					Dbg("stop play video");
-					return 0;
+					iRet = 0;
+					return (void*)& iRet;
 				}
 			}
 			else if ('P' == i->type)
@@ -880,15 +905,18 @@ int StartMediaPlay(void* param)
 				if (!entity->m_pPicturePlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(&playThreadId))
 				{
 					Dbg("Create play Image Media Thread Failed!");
-					return -1;
+					iRet = -1;
+					return (void*)& iRet;
 				}
 
 				//WaitForSingleObject(playThread, i->playInterval);
 				struct timespec ts;
 				{
 					int rc = clock_gettime(CLOCK_REALTIME, &ts);
-					if (rc)
-						return -1;
+					if (rc) {
+						iRet = -1;
+						return (void*)& iRet;
+					}
 				}
 				ts.tv_nsec += (i->playInterval * 1000000);
 				pthread_timedjoin_np(playThreadId, NULL, &ts);
@@ -896,7 +924,8 @@ int StartMediaPlay(void* param)
 				if (entity->m_pPicturePlayer[entity->m_mediaParam.nCfgInx]->checkIsStop())
 				{//ֹͣ����
 					Dbg("stop play Image");
-					return 0;
+					iRet = 0;
+					return (void*)& iRet;
 				}
 				else
 				{
@@ -906,7 +935,7 @@ int StartMediaPlay(void* param)
 		}
 	}
 
-	return iRet;
+	return (void*)&iRet;
 }
 
 #endif // RVC_OS_WIN
@@ -937,8 +966,14 @@ void CLocalMediaPlayEntity::StartVideo(int nCfgInx, int nWndX, int nWndY, int nW
 		m_playThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)& MediaPlayThread, this, 0, NULL);
 #else
 
-	StartMediaPlay(this);
-
+	pthread_t uMediaPlayThreadId = 0;
+	int err = pthread_create(&uMediaPlayThreadId, NULL, StartMediaPlayFunc, this);
+	if (0 == err) {
+		Dbg("create media play thread[%lu] success.", uMediaPlayThreadId);
+	}
+	else {
+		Dbg("create media play thread failed.");
+	}
 
 #endif 
 }
@@ -973,23 +1008,21 @@ void CLocalMediaPlayEntity::StartAudio(const char *pAudioNames)
 	//if (0 == pthread_kill(audioPlayThreadId, 0)) {
 
 	//}
+	m_lastPlayAudio = pAudioNames;
 
-	Dbg("Begin StartAudio, and Audio Info is %s.", pAudioNames);
-	if (0 == m_pMediaAudioPlayer->PlayLocalAudio(pAudioNames)) {
-		Dbg("Succeed to StartAudio, and Audio Info is %s.", pAudioNames);
+	pthread_t uAudioPlayThreadId = 0;
+	int err = pthread_create(&uAudioPlayThreadId, NULL, StartAudioPlayingThreadFunc, this);
+	if (0 == err) {
+		Dbg("create audio play thread[%lu] success.", uAudioPlayThreadId);
 	}
-	else{
-		Dbg("StartAudio failed, for %s is not exsit.", pAudioNames);
+	else {
+		Dbg("create audio play thread failed.");
 	}
-	
 
 	auto audioRet = GetLocalAudioVolume();
 	m_pMediaAudioPlayer->SetVolume(audioRet.second);
 	Dbg("Succeed to set audio volume %d!", audioRet.second);
-	m_lastPlayAudio = pAudioNames;
-
-
-
+	
 #endif // RVC_OS_WIN
 }
 
@@ -1272,7 +1305,7 @@ void CLocalMediaPlaySession::Handle_StartPlayAudio(SpReqAnsContext<PlayService_S
 	}
 	else
 	{
-		return;
+		return m_pEntity->StartAudio("CardOut.mp3|CardIn.mp3");
 	}
 #endif
 

+ 6 - 3
Module/mod_localmediaplay/mod_localmediaplay.h

@@ -74,6 +74,9 @@ public:
 	virtual void Debug(const char* fmt, ...);
 	virtual void PicDebug(const char* fmt, ...);
 	virtual void AudioPlayFinished();
+	virtual int GetMediaPlayerIcoPath(char* strPath, size_t uLen);
+	virtual int GetPicPlayerIcoPath(char* strPath, size_t uLen);
+	
 #endif // _WIN32
 
 	virtual void OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID, const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
@@ -108,7 +111,6 @@ public:
 	bool SetLocalAudioVolume(int nVolume);
 	bool IsRunConfigExist();
 
-
 protected:
 	// ÒôƵ²¥·Å¶ÔÏóÖ¸Õë
 #ifdef RVC_OS_WIN
@@ -133,8 +135,8 @@ private:
 	friend DWORD WINAPI CheckAudioThread(LPVOID param);
 #else
 	friend void* queryMedia(void* param);
-	friend void* CheckAudioPlayingThreadFunc(void* param);
-	friend int StartMediaPlay(void* param);
+	friend void* StartAudioPlayingThreadFunc(void* param);
+	friend void* StartMediaPlayFunc(void* param);
 #endif // RVC_OS_WIN
 
 	void setMediaPath();
@@ -143,6 +145,7 @@ private:
 
 	void loadDefaultMedia();
 
+	int GetPlayerIcoPath(char* strPath, size_t uLen);
 private:
 	int m_id_seq;
 	CUUID m_SubIDIEIdle;

+ 1 - 0
Other/libmediaplayer/idatastruct.h

@@ -64,4 +64,5 @@ struct RVC_NO_VTABLE CMediaHostApi
 	virtual int LoadPlayConfig(CMediaPlayConfig& config, int CfgInx = 0) = 0;
 	virtual void Debug(const char* fmt, ...) = 0;
 	virtual void AudioPlayFinished() = 0;
+	virtual int GetMediaPlayerIcoPath(char* strPath, size_t uLen) = 0;
 };

+ 38 - 2
Other/libmediaplayer/libmediaplayer.cpp

@@ -15,7 +15,8 @@ public:
 	libmediaplayer_impl(CMediaHostApi* pHostApi) {
 		m_pHostApi = pHostApi;
 		pHostApi->Debug("begin new MediaPlayer.");
-		m_Player = new CMediaPlayer(pHostApi, "./rvc_media_player_64px.bmp");
+
+		m_Player = new CMediaPlayer(pHostApi);
 		if (NULL != m_Player) {
 			pHostApi->Debug("new MediaPlayer success!");
 		}
@@ -284,9 +285,44 @@ public:
 		return true;
 	}
 
-	void StartPlayMedia(CMediaPlayConfig& config)
+	int StartPlayMedia(CMediaPlayConfig& config)
 	{
+		int iRet = -1;
+
+		memcpy(&m_stPlayConfig, &config, sizeof(CMediaPlayConfig));
 
+		// 判断当前时间是否允许播放
+		struct tm* ptm = NULL;
+		time_t t = time(NULL);
+		ptm = localtime(&t);
+		char strNow[TIME_LEN] = { 0 };
+		sprintf(strNow, "%02d:%02d:%02d", ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
+		if (strcmp(strNow, m_stPlayConfig.strVideoRunTime_S) < 0 || strcmp(strNow, m_stPlayConfig.strVideoRunTime_E) >= 0)
+		{
+			m_pHostApi->Debug("Now is %s, play video rejected!", strNow);
+			iRet = 0;
+			return iRet;
+		}
+
+		rvc_media_player_param_t t_param = { 0 };
+		if (0 != GetLocalVideoPlayingParams(&t_param)) {
+			return iRet;
+		}
+
+		play_media_callback_t cb;
+		cb.cb_play_media_finished = &__cb_play_finished;
+		cb.user_data = this;
+		t_param.cb = &cb;
+
+		if (0 == m_Player->Init(&t_param)) {
+			m_Player->StartMediaPlay();
+			iRet = 0;
+		}
+		else {
+			m_pHostApi->Debug("Player Init failed!");
+		}
+
+		return iRet;
 	}
 
 	bool StopPlay()

+ 11 - 3
Other/libmediaplayer/player.cpp

@@ -167,15 +167,21 @@ static void toggle_full_screen(player_stat_t* is)
 }
 
 
-CMediaPlayer::CMediaPlayer(CMediaHostApi* pHostApi, const char* picon_path)
+CMediaPlayer::CMediaPlayer(CMediaHostApi* pHostApi)
 {
 	m_hostapi = pHostApi;
 	m_player_stat = NULL;
 	m_uvolume = SDL_MIX_MAXVOLUME;
 	m_bplaying = false;
-	m_piconpath = av_strdup(picon_path);
+	m_piconpath = NULL;
+	
 	if (NULL != m_hostapi){
 		m_hostapi->Debug("new CMediaPlayer success!");
+		char str_iconpath[MAX_PATH] = {0};
+		if (0 == pHostApi->GetMediaPlayerIcoPath(str_iconpath, MAX_PATH)){
+			m_piconpath = av_strdup(str_iconpath);
+		}
+		
 	}
 }
 
@@ -216,7 +222,9 @@ int CMediaPlayer::Initialize_Player_Stat(rvc_media_player_param_t* pMedia_Player
 	m_player_stat->prvc_cb = pMedia_Player->cb;
 	m_player_stat->eMType = pMedia_Player->eType;
 	m_player_stat->eWindType = pMedia_Player->eWindType;
-	m_player_stat->piconpath = av_strdup(m_piconpath);
+	if (NULL != m_piconpath){
+		m_player_stat->piconpath = av_strdup(m_piconpath);
+	}
 	m_player_stat->uVolume = m_uvolume;
 
 	m_player_stat->uFilesCount = pMedia_Player->uFilesCount;

+ 1 - 1
Other/libmediaplayer/player.h

@@ -232,7 +232,7 @@ void set_clock(play_clock_t *c, double pts, int serial);
 class CMediaPlayer
 {
 public:
-	CMediaPlayer(CMediaHostApi* pHostApi, const char* picon_path);
+	CMediaPlayer(CMediaHostApi* pHostApi);
 	~CMediaPlayer();
 
 	int Init(rvc_media_player_param_t* pMedia_Player);

+ 11 - 8
Other/libmediaplayer/video.cpp

@@ -418,7 +418,7 @@ static int open_video_playing(void *arg)
 			return -1;
 		}
 		else {
-			is->rvc_hostapi->Debug("%s:%d is->img_convert_ctx[%d] = 0x%0x\n", __FUNCTION__, __LINE__, index, is->img_convert_ctx[index]);
+			is->rvc_hostapi->Debug("%s:%d is->img_convert_ctx[%d] = 0x%0x", __FUNCTION__, __LINE__, index, is->img_convert_ctx[index]);
 		}
 	}
 
@@ -445,13 +445,16 @@ static int open_video_playing(void *arg)
         return -1;
     }
 
-	IconSurface = SDL_LoadBMP(is->piconpath);
-	if (NULL == IconSurface){
-		is->rvc_hostapi->Debug("SDL_LoadBMP(%s) failed: %s", is->piconpath, SDL_GetError());
-	}
-	else{
-		SDL_SetWindowIcon(is->sdl_video.window, IconSurface);
-		SDL_FreeSurface(IconSurface);
+
+	if (NULL != is->piconpath){
+		IconSurface = SDL_LoadBMP(is->piconpath);
+		if (NULL == IconSurface) {
+			is->rvc_hostapi->Debug("SDL_LoadBMP(%s) failed: %s", is->piconpath, SDL_GetError());
+		}
+		else {
+			SDL_SetWindowIcon(is->sdl_video.window, IconSurface);
+			SDL_FreeSurface(IconSurface);
+		}
 	}
 
     // 2. 创建SDL_Renderer

+ 16 - 9
Other/libpictureplayer/CPicturePlayer.cpp

@@ -34,15 +34,16 @@ static void rvc_strfree(char* strdata)
 }
 
 
-CPicturePlayer::CPicturePlayer(CPicHostApi* pHostApi, const char* picopath)
+CPicturePlayer::CPicturePlayer(CPicHostApi* pHostApi)
 {
 	m_thid = NULL;
 	m_bplaying = false;
-	m_stricopath = rvc_strdup(picopath);
+	
 	m_window = NULL;
 	m_nfile_cnt = 0;
 	m_nplay_cnt = 0;
 	m_nplay_interval = 5000;
+	m_stricopath = NULL;
 	memset(m_strroot_path, 0, MAX_PATH);
 	for (size_t i = 0; i < MAX_FILECOUNT; i++){
 		memset(m_strfile_names[i], 0, MAX_PATH);
@@ -50,6 +51,10 @@ CPicturePlayer::CPicturePlayer(CPicHostApi* pHostApi, const char* picopath)
 	m_pHostApi = pHostApi;
 	if (NULL != m_pHostApi){
 		m_pHostApi->PicDebug("new CPicturePlayer success!");
+		char strIcoPath[MAX_PATH] = { 0 };
+		if (0 == pHostApi->GetPicPlayerIcoPath(strIcoPath, MAX_PATH)) {
+			m_stricopath = rvc_strdup(strIcoPath);
+		}
 	}
 
 	for (int inum = 0; inum < MAX_DISPLAYNUM; inum++){
@@ -137,13 +142,15 @@ int CPicturePlayer::Init(rvc_picture_player_param_t* tparam)
 	}
 
 	//2.设置播放器ico
-	SDL_Surface* IconSurface = SDL_LoadBMP(m_stricopath);
-	if (NULL == IconSurface){
-		m_pHostApi->PicDebug("SDL_LoadBMP(%s) failed: %s", m_stricopath, SDL_GetError());
-	}
-	else{
-		SDL_SetWindowIcon(m_window, IconSurface);
-		SDL_FreeSurface(IconSurface);
+	if (NULL != m_stricopath) {
+		SDL_Surface* IconSurface = SDL_LoadBMP(m_stricopath);
+		if (NULL == IconSurface) {
+			m_pHostApi->PicDebug("SDL_LoadBMP(%s) failed: %s", m_stricopath, SDL_GetError());
+		}
+		else {
+			SDL_SetWindowIcon(m_window, IconSurface);
+			SDL_FreeSurface(IconSurface);
+		}
 	}
 
 	iRet = 0;

+ 1 - 1
Other/libpictureplayer/CPicturePlayer.h

@@ -63,7 +63,7 @@ typedef struct rvc_picture_player_param_s {
 class CPicturePlayer
 {
 public:
-	CPicturePlayer(CPicHostApi* pHostApi, const char* picopath);
+	CPicturePlayer(CPicHostApi* pHostApi);
 	~CPicturePlayer();
 
 	int Init(rvc_picture_player_param_t* tparam);

+ 1 - 0
Other/libpictureplayer/ipicdatastruct.h

@@ -41,6 +41,7 @@ struct RVC_NO_VTABLE CPicHostApi
 {
 	virtual void PicDebug(const char* fmt, ...) = 0;
 	virtual int LoadPlayConfig(CPicPlayConfig& config, int CfgInx = 0) = 0;
+	virtual int GetPicPlayerIcoPath(char* strPath, size_t uLen) = 0;
 };
 
 #endif

+ 1 - 1
Other/libpictureplayer/libpictureplayer.cpp

@@ -21,7 +21,7 @@ public:
 		m_bIsPlay = false;
 		m_pHostApi = pHostApi;
 		memset(&m_stPlayConfig, 0, sizeof(m_stPlayConfig));
-		m_Player = new CPicturePlayer(pHostApi, "./rvc_media_player_64px.bmp");
+		m_Player = new CPicturePlayer(pHostApi);
 		if (NULL != m_Player) {
 			pHostApi->PicDebug("new PicturePlayer success!");
 		}