123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- #include "libpictureplayer.h"
- #include "CPicturePlayer.h"
- #include <unistd.h>
- #include <string.h>
- #include <pthread.h>
- void* PicturePlayingFunc(void* param);
- class libpictureplayer_impl
- {
- public:
- CPicPlayConfig m_stPlayConfig;
- CPicHostApi* m_pHostApi;
- CPicturePlayer* m_Player;
- bool m_bIsPlay;
- pthread_t m_PlayThreadId;
- public:
- libpictureplayer_impl(CPicHostApi* pHostApi) {
- m_bIsPlay = false;
- m_pHostApi = pHostApi;
- memset(&m_stPlayConfig, 0, sizeof(m_stPlayConfig));
- m_Player = new CPicturePlayer(pHostApi);
- if (NULL == m_Player) {
- pHostApi->PicDebug("new PicturePlayer failed!");
- }
- m_PlayThreadId = 0;
- }
- ~libpictureplayer_impl()
- {
- m_pHostApi = NULL;
- delete m_Player;
- m_Player = NULL;
- m_bIsPlay = false;
- m_PlayThreadId = 0;
- }
- bool isStop()
- {
- return !m_bIsPlay;
- }
- bool CheckIsPlay(void* pthreadid)
- {
- bool bret = false;
- int64_t iThreadId = m_PlayThreadId;
- if (0 != iThreadId)
- {
- bret = true;
- pthreadid = &iThreadId;
- }
- }
- bool StartPlayMedia(CPicPlayConfig& config)
- {
- bool bRet = false;
- if (m_bIsPlay){
- return true;
- }
- memcpy(&m_stPlayConfig, &config, sizeof(CPicPlayConfig));
- rvc_picture_player_param_t tplayer_param = { 0 };
- tplayer_param.icx = m_stPlayConfig.nWndX;
- tplayer_param.icy = m_stPlayConfig.nWndY;
- tplayer_param.uwindow_width = m_stPlayConfig.nWndWidth;
- tplayer_param.uwindow_height = m_stPlayConfig.nWndHeight;
- if (0 == GetPicturePlayingParams(&tplayer_param)) {
- if (0 == m_Player->Init(&tplayer_param))
- {
- m_pHostApi->PicDebug("Init Picture Player Success.");
- m_pHostApi->PicDebug("Start Picture Play Success.");
- int err = pthread_create(&m_PlayThreadId, NULL, PicturePlayingFunc, m_Player);
- if (0 == err) {
- m_pHostApi->PicDebug("create picture play thread[%lu] success.", m_PlayThreadId);
- m_bIsPlay = true;
- bRet = true;
- m_pHostApi->PicDebug("Start Picture Play Success.");
- }
- else {
- m_pHostApi->PicDebug("create picture play thread failed.");
- }
- }
- }
- else {
- m_pHostApi->PicDebug("Get Picture Playing Params failed!");
- }
- return bRet;
- }
- int GetPicturePlayingParams(rvc_picture_player_param_t* pParam)
- {
- int iRet = -1;
- if (NULL == pParam) {
- return iRet;
- }
- pParam->bfull_screen = m_stPlayConfig.bFullScreen;
- pParam->nplay_cnt = m_stPlayConfig.nPlayCnt;
- pParam->nplay_interval = m_stPlayConfig.nPlayInterval;
- size_t uValidCount = 0;
- for (int i = 0; i < m_stPlayConfig.nFileCnt && i < MAX_FILECOUNT; i++) {
- char strFileName[MAX_PATH] = { 0 };
- snprintf(strFileName, MAX_PATH, "%s%s", m_stPlayConfig.strRootPath, m_stPlayConfig.strFileNames[i]);
- if (IsFileExist(strFileName)) {
- memcpy(pParam->strfile_names[i], strFileName, strlen(strFileName));
- uValidCount++;
- }
- else {
- m_pHostApi->PicDebug("File %s is not exsit.", strFileName);
- continue;
- }
- }
- pParam->nfile_cnt = uValidCount;
- if (NULL != m_pHostApi) {
- m_pHostApi->PicDebug("pParam uFilesCount = %d", uValidCount);
- }
- if (uValidCount > 0) {
- iRet = 0;
- }
- return iRet;
- }
- bool StartPlay(int nCfgInx, int nWndX, int nWndY, int nWndWidth, int nWndHeight)
- {
- bool bRet = false;
- int iRet = m_pHostApi->LoadPlayConfig(m_stPlayConfig, nCfgInx);
- if (0 != iRet){
- m_pHostApi->PicDebug("Load ImgConfiguration failed!");
- return bRet;
- }
- else{
- m_pHostApi->PicDebug("Load ImgConfiguration succeeded while play local image!");
- m_pHostApi->PicDebug("m_stPlayConfig.strRootPath: %s", m_stPlayConfig.strRootPath);
- }
- m_stPlayConfig.nWndX = nWndX;
- m_stPlayConfig.nWndY = nWndY;
- m_stPlayConfig.nWndWidth = nWndWidth;
- m_stPlayConfig.nWndHeight = nWndHeight;
- rvc_picture_player_param_t tplayer_param = { 0 };
- tplayer_param.icx = m_stPlayConfig.nWndX;
- tplayer_param.icy = m_stPlayConfig.nWndY;
- tplayer_param.uwindow_width = m_stPlayConfig.nWndWidth;
- tplayer_param.uwindow_height = m_stPlayConfig.nWndHeight;
- if (0 == GetPicturePlayingParams(&tplayer_param)) {
- if (0 == m_Player->Init(&tplayer_param))
- {
- m_pHostApi->PicDebug("Init Picture Player Success.");
- m_pHostApi->PicDebug("Start Picture Play Success.");
- int err = pthread_create(&m_PlayThreadId, NULL, PicturePlayingFunc, m_Player);
- if (0 == err) {
- m_pHostApi->PicDebug("create picture play thread[%lu] success.", m_PlayThreadId);
- m_bIsPlay = true;
- bRet = true;
- m_pHostApi->PicDebug("Start Picture Play Success.");
- }
- else {
- m_pHostApi->PicDebug("create picture play thread failed.");
- }
- }
- }
- else {
- m_pHostApi->PicDebug("Get Picture Playing Params failed!");
- }
- return bRet;
- }
- bool StopPlay()
- {
- if (NULL != m_Player)
- {
- if (m_Player->GetPicPlayingFlag())
- {
- m_Player->StopPicPlay();
- m_bIsPlay = false;
- }
- else
- {
- m_pHostApi->PicDebug("picture playing already stopped!");
- }
- }
- return true;
- }
- bool IsFileExist(const char* pFilePath)
- {
- bool bRet = false;
- if (NULL != pFilePath) {
- if (0 == access(pFilePath, F_OK)) {
- bRet = true;
- }
- }
- return bRet;
- }
- };
- Clibpictureplayer::Clibpictureplayer(CPicHostApi* pHostApi)
- {
- m_pImpl = new libpictureplayer_impl(pHostApi);
- }
- Clibpictureplayer::~Clibpictureplayer()
- {
- delete m_pImpl;
- m_pImpl = NULL;
- }
- void Clibpictureplayer::Play(int nCfgInx, int nWndX, int nWndY, int nWndWidth, int nWndHeight)
- {
- m_pImpl->StartPlay(nCfgInx, nWndX, nWndY, nWndWidth, nWndHeight);
- }
- void Clibpictureplayer::PlayMedia(CPicPlayConfig& config)
- {
- m_pImpl->StartPlayMedia(config);
- }
- bool Clibpictureplayer::checkIsStop() {
- return m_pImpl->isStop();
- }
- bool Clibpictureplayer::checkIsPlay(void* pthreadid)
- {
- return m_pImpl->CheckIsPlay(pthreadid);
- }
- void Clibpictureplayer::Close()
- {
- m_pImpl->StopPlay();
- }
- void* PicturePlayingFunc(void* param)
- {
- CPicturePlayer* is = (CPicturePlayer*)param;
- is->m_pHostApi->PicDebug("enter PicturePlayingFunc");
- is->StartPicPlay();
- is->m_pHostApi->PicDebug("leave PicturePlayingFunc");
- return 0;
- }
|