mod_localmediaplay.cpp 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387
  1. #include "stdafx.h"
  2. #include "mod_localmediaplay.h"
  3. #include "LocalMediaPlay_msg_g.h"
  4. #include "fileutil.h"
  5. #define DEFAULT_SLEEP_TIME (60 * 1000)
  6. #define DEFAULT_ADVERT_TYPE 'A'
  7. bool IS_DEBUG = false;
  8. int scanTime = 600;
  9. int removeOldTime = 1800;
  10. #ifndef MAX_LOCAL_MEDIAS
  11. #define MAX_LOCAL_MEDIAS 128
  12. #endif // !MAX_LOCAL_MEDIAS
  13. //DWORD WINAPI clearOutdata(LPVOID lpv)
  14. //{
  15. // CLocalMediaPlayEntity* curEntity = (CLocalMediaPlayEntity*)lpv;
  16. // Sleep(removeOldTime * 1000);
  17. // curEntity->m_mediaManage.clearOutdataResource();
  18. // return 0;
  19. //}
  20. #ifdef RVC_OS_WIN
  21. DWORD WINAPI qryMedia(LPVOID lpv)
  22. {
  23. CLocalMediaPlayEntity* curEntity = (CLocalMediaPlayEntity*)lpv;
  24. Sleep(3000);
  25. while (true)
  26. {
  27. curEntity->m_mediaManage.InitResourceListByLocal();
  28. //curEntity->StartVideo(0, 0, 0, 0, 0);
  29. Sleep(3600 * 1000);
  30. }
  31. return 0;
  32. }
  33. #else
  34. void* queryMedia(void* param)
  35. {
  36. CLocalMediaPlayEntity* curEntity = (CLocalMediaPlayEntity*)param;
  37. sleep(3);
  38. while (false == curEntity->GetScanExitFlag())
  39. {
  40. curEntity->m_mediaManage.InitResourceListByLocal();
  41. sleep(3600);
  42. }
  43. return 0;
  44. }
  45. void sig_handler(int signum)
  46. {
  47. if (SIGTERM == signum){
  48. int ipid = getpid();
  49. kill(ipid, SIGKILL);
  50. }
  51. }
  52. #endif // RVC_OS_WIN
  53. CLocalMediaPlayEntity::CLocalMediaPlayEntity()
  54. : m_id_seq(0), m_connection(NULL)
  55. {
  56. //stopForDebug();
  57. m_defaultVolum = 50;
  58. #ifdef RVC_OS_WIN
  59. m_scanThread=NULL;
  60. m_pAudioPlayer = NULL;
  61. memset(m_pVideoPlayer, 0, sizeof(m_pVideoPlayer));
  62. memset(m_pImagePlayer, 0, sizeof(m_pImagePlayer));
  63. #else
  64. //add by clp 20201103
  65. m_scanThreadId = 0;
  66. m_pMediaAudioPlayer = NULL;
  67. memset(m_pMediaPlayer, 0, sizeof(m_pMediaPlayer));
  68. memset(m_pPicturePlayer, 0, sizeof(m_pPicturePlayer));
  69. m_uMediaPlayThreadId = 0;
  70. m_badplayflag = true;
  71. #endif // RVC_OS_WIN
  72. ZeroMemory(&m_mediaParam, sizeof(MediaPlayParam));
  73. }
  74. CLocalMediaPlayEntity::~CLocalMediaPlayEntity()
  75. {
  76. SecureClientRelease();
  77. DWORD exitCode = 0;
  78. #ifdef RVC_OS_WIN
  79. if (m_scanThread)
  80. {
  81. TerminateThread(m_scanThread, exitCode);
  82. m_scanThread = NULL;
  83. }
  84. #else
  85. m_scanexitflag = true;
  86. if (0 == pthread_join(m_scanThreadId, NULL)) {
  87. Dbg("pthread join scanThreadId success.");
  88. }
  89. #endif // RVC_OS_WIN
  90. }
  91. void CLocalMediaPlayEntity::SecureClientRelease()
  92. {
  93. if (NULL != m_connection)
  94. {
  95. if (m_connection->IsConnectionOK())
  96. m_connection->Close();
  97. m_connection->DecRefCount();
  98. m_connection = NULL;
  99. }
  100. }
  101. bool CLocalMediaPlayEntity::SecureClientConnect()
  102. {
  103. if (NULL != m_connection && m_connection->IsConnectionOK())
  104. return true;
  105. SecureClientRelease();
  106. m_connection = new CAdvertSyncConnection(this);
  107. return m_connection->ConnectFromCentralSetting();
  108. }
  109. void CLocalMediaPlayEntity::setMediaPath()
  110. {
  111. CSimpleStringA downloadPath, mediaPath;
  112. GetFunction()->GetPath("Download", downloadPath);
  113. GetFunction()->GetPath("Ad", mediaPath);
  114. m_mediaManage.setDefaultDownloadPath(downloadPath.GetData());
  115. m_mediaManage.setDefaultAddvertPath(mediaPath.GetData());
  116. }
  117. CServerSessionBase* CLocalMediaPlayEntity::OnNewSession(const char* pszRemoteEntityName, const char * pszClass)
  118. {
  119. LOG_FUNCTION();
  120. LOG_TRACE("%s connected class = %s!", pszRemoteEntityName, pszClass);
  121. return new CLocalMediaPlaySession(this, m_id_seq++);
  122. }
  123. void CLocalMediaPlayEntity::loadDefaultMedia()
  124. {
  125. #ifdef RVC_OS_WIN
  126. m_defaultImg.clear();
  127. m_defaultAudio.clear();
  128. m_defaultVideo.clear();
  129. #else
  130. m_defaultPic.clear();
  131. m_Audios.clear();
  132. m_Videos.clear();
  133. #endif // RVC_OS_WIN
  134. // 读取LocalMediaPlay.ini中的配置
  135. CSimpleStringA strRootPath;
  136. ErrorCodeEnum Error = Error_Succeed;
  137. Error = GetFunction()->GetPath("ADData", strRootPath);
  138. if (Error != Error_Succeed) {
  139. Dbg("Fail to get local media root path!");
  140. return;
  141. }
  142. CSmartPointer<IConfigInfo> spConfig;
  143. CAutoArray<CSimpleStringA> sectionList;
  144. if (Error_Succeed == GetFunction()->OpenConfig(Config_Software, spConfig) && Error_Succeed == spConfig->ReadAllSections(sectionList))
  145. {
  146. for (int i = 0; i < sectionList.GetCount(); i++)
  147. {
  148. CSmartPointer<IConfigInfo> tempConfig = spConfig;
  149. SpIniMappingTable table;
  150. CSimpleStringA strFileNames;
  151. if (sectionList[i].IsStartWith("General"))
  152. {
  153. table.AddEntryBoolean(sectionList[i].GetData(), "runDebug", IS_DEBUG, false);
  154. table.AddEntryInt(sectionList[i].GetData(), "scanTime", scanTime, 600);
  155. table.AddEntryInt(sectionList[i].GetData(), "removeOldTime", removeOldTime, 1800);
  156. if (Error_Succeed == table.Load(tempConfig))
  157. Dbg("runDebug:%s, scanTime:%d", IS_DEBUG ? "true" : "false", scanTime);
  158. else
  159. Dbg("General load fail!");
  160. if (removeOldTime < 1800)
  161. {
  162. removeOldTime = 1800;
  163. }
  164. }
  165. else if (sectionList[i].IsStartWith("Image"))
  166. {
  167. // ����ͼƬ����
  168. #ifdef RVC_OS_WIN
  169. CImgPlayConfig curImg;
  170. ZeroMemory(&curImg, sizeof(CImgPlayConfig));
  171. #else
  172. CPicPlayConfig curImg;
  173. ZeroMemory(&curImg, sizeof(CPicPlayConfig));
  174. #endif // RVC_OS_WIN
  175. CSimpleStringA imgPath = strRootPath + SPLIT_SLASH_STR +"Image" + SPLIT_SLASH_STR;
  176. strncpy(curImg.strRootPath, (LPCSTR)imgPath, sizeof(curImg.strRootPath));
  177. Dbg("curSection: %s, config.strRootPath: %s", sectionList[i].GetData(), curImg.strRootPath);
  178. table.AddEntryBoolean(sectionList[i].GetData(), "FullScreen", curImg.bFullScreen, false);
  179. table.AddEntryBoolean(sectionList[i].GetData(), "PrimMonitor", curImg.bPrimMonitor, false);
  180. table.AddEntryInt(sectionList[i].GetData(), "PlayCount", curImg.nPlayCnt, 0);
  181. table.AddEntryInt(sectionList[i].GetData(), "PlayInterval", curImg.nPlayInterval, 0);
  182. table.AddEntryString(sectionList[i].GetData(), "ImageNames", strFileNames, "");
  183. if (Error_Succeed == table.Load(tempConfig))
  184. Dbg("Image Succeed to LoadConfig!");
  185. else
  186. Dbg("Image Fail to LoadConfig!");
  187. char *Tmp = new char[strFileNames.GetLength() + 1];
  188. strcpy(Tmp, (LPCSTR)strFileNames);
  189. char *Result[MAX_FILECOUNT] = { NULL };
  190. CStringSplit(Tmp, Result, "|");
  191. int FileCount = 0;
  192. char** pStr = Result;
  193. while (*pStr != NULL)
  194. {
  195. ++pStr; ++FileCount;
  196. }
  197. curImg.nFileCnt = FileCount;
  198. Dbg("Image config.nFileCnt = %d!", FileCount);
  199. for (int i = 0; i != FileCount; ++i)
  200. {
  201. strcpy(curImg.strFileNames[i], Result[i]);
  202. }
  203. delete[] Tmp; Tmp = NULL;
  204. #ifdef RVC_OS_WIN
  205. m_defaultImg.push_back(curImg);
  206. #else
  207. m_defaultPic.push_back(curImg);
  208. #endif // RVC_OS_WIN
  209. }
  210. else if (sectionList[i].IsStartWith("Video"))
  211. {
  212. #ifdef RVC_OS_WIN
  213. CWmpPlayConfig curVideo;
  214. ZeroMemory(&curVideo, sizeof(CWmpPlayConfig));
  215. #else
  216. CMediaPlayConfig curVideo = {0};
  217. #endif // RVC_OS_WIN
  218. CSimpleStringA videoPath = strRootPath + SPLIT_SLASH_STR +"Video" + SPLIT_SLASH_STR;
  219. strcpy(curVideo.strRootPath, (LPCSTR)videoPath);
  220. Dbg("config.strRootPath: %s", curVideo.strRootPath);
  221. CSimpleStringA strRunTime_S, strRunTime_E;
  222. table.AddEntryString("General", "VideoRunTime_Start", strRunTime_S, "");
  223. table.AddEntryString("General", "VideoRunTime_End", strRunTime_E, "");
  224. table.AddEntryBoolean(sectionList[i].GetData(), "FullScreen", curVideo.bFullScreen, false);
  225. table.AddEntryBoolean(sectionList[i].GetData(), "PrimMonitor", curVideo.bPrimMonitor, false);
  226. table.AddEntryBoolean(sectionList[i].GetData(), "SimpleMode", curVideo.bSimpleMode, true);
  227. table.AddEntryInt(sectionList[i].GetData(), "PlayCount", curVideo.nPlayCnt, 0);
  228. table.AddEntryInt(sectionList[i].GetData(), "PlayInterval", curVideo.nPlayInterval, 0);
  229. table.AddEntryString(sectionList[i].GetData(), "VideoNames", strFileNames, "");
  230. if (Error_Succeed == table.Load(tempConfig))
  231. Dbg("Succeed to LoadWmpConfig!");
  232. else
  233. Dbg("Fail to LoadWmpConfig!");
  234. curVideo.nVolume = 50;
  235. Error = GetFunction()->OpenConfig(Config_Run, tempConfig);
  236. if (Error == Error_Succeed)
  237. {
  238. Error = tempConfig->ReadConfigValueInt("LocalVideo", "Volume", curVideo.nVolume);
  239. if (Error != Error_Succeed || curVideo.nVolume < 0 || curVideo.nVolume > 100)
  240. curVideo.nVolume = 50;
  241. m_defaultVolum = curVideo.nVolume;
  242. }
  243. strcpy(curVideo.strVideoRunTime_S, (LPCSTR)strRunTime_S);
  244. Dbg("config.strVideoRunTime_S: %s", (LPCSTR)strRunTime_S);
  245. strcpy(curVideo.strVideoRunTime_E, (LPCSTR)strRunTime_E);
  246. Dbg("config.strVideoRunTime_E: %s", (LPCSTR)strRunTime_E);
  247. char *Tmp = new char[strFileNames.GetLength() + 1];
  248. strcpy(Tmp, (LPCSTR)strFileNames);
  249. char *Result[MAX_FILECOUNT] = { NULL };
  250. CStringSplit(Tmp, Result, "|");
  251. int FileCount = 0;
  252. char** pStr = Result;
  253. while (*pStr != NULL)
  254. {
  255. ++pStr; ++FileCount;
  256. }
  257. curVideo.nFileCnt = FileCount;
  258. Dbg("Wmp config.strFileNames = %s!", (LPCSTR)strFileNames);
  259. Dbg("Wmp config.nFileCnt = %d!", FileCount);
  260. for (int i = 0; i != FileCount; ++i)
  261. strcpy(curVideo.strFileNames[i], Result[i]);
  262. delete[] Tmp; Tmp = NULL;
  263. #ifdef RVC_OS_WIN
  264. m_defaultVideo.push_back(curVideo);
  265. #else
  266. m_Videos.push_back(curVideo);
  267. #endif // RVC_OS_WIN
  268. }
  269. else if (sectionList[i].IsStartWith("Audio"))
  270. {
  271. #ifdef RVC_OS_WIN
  272. CWmpPlayConfig curAudio;
  273. ZeroMemory(&curAudio, sizeof(CWmpPlayConfig));
  274. #else
  275. CMediaPlayConfig curAudio = { 0 };
  276. #endif // RVC_OS_WIN
  277. CSimpleStringA audioPath = strRootPath + SPLIT_SLASH_STR +"Audio" + SPLIT_SLASH_STR;
  278. strcpy(curAudio.strRootPath, (LPCSTR)audioPath);
  279. Dbg("config.strRootPath: %s", curAudio.strRootPath);
  280. table.AddEntryInt(sectionList[i], "PlayCount", curAudio.nPlayCnt, 0);
  281. table.AddEntryInt(sectionList[i], "PlayInterval", curAudio.nPlayInterval, 0);
  282. auto audioRet = GetLocalAudioVolume();
  283. if (audioRet.first)
  284. curAudio.nVolume = audioRet.second;
  285. else
  286. curAudio.nVolume = m_defaultVolum;
  287. if (Error_Succeed == table.Load(tempConfig))
  288. Dbg("Succeed to LoadWmpConfig!");
  289. else
  290. Dbg("Fail to LoadWmpConfig!");
  291. #ifdef RVC_OS_WIN
  292. m_defaultAudio.push_back(curAudio);
  293. #else
  294. m_Audios.push_back(curAudio);
  295. #endif // RVC_OS_WIN
  296. }
  297. }
  298. }
  299. }
  300. #ifdef RVC_OS_WIN
  301. BOOL CLocalMediaPlayEntity::LoadPlayConfig(CWmpPlayConfig& config, int CfgInx)
  302. {
  303. if (CfgInx >= MAX_PLAY_CHANNELS || CfgInx < 0)
  304. {
  305. Dbg("Invalid CfgInx while LoadConfig!");
  306. return FALSE;
  307. }
  308. if (config.eMode == LOCALAUDIO && CfgInx < m_defaultAudio.size())
  309. {
  310. memcpy(&config, &(m_defaultAudio[CfgInx]), sizeof(CWmpPlayConfig));
  311. }
  312. else if (config.eMode == LOCALVIDEO && CfgInx < m_defaultVideo.size())
  313. {
  314. memcpy(&config, &(m_defaultVideo[CfgInx]), sizeof(CWmpPlayConfig));
  315. }
  316. else {
  317. return FALSE;
  318. }
  319. return TRUE;
  320. }
  321. BOOL CLocalMediaPlayEntity::LoadPlayConfig(CImgPlayConfig& config, int CfgInx)
  322. {
  323. if (CfgInx >= m_defaultImg.size() || CfgInx < 0)
  324. {
  325. Dbg("Invalid CfgInx while LoadConfig!");
  326. return FALSE;
  327. }
  328. memcpy(&config, &(m_defaultImg[CfgInx]), sizeof(CImgPlayConfig));
  329. return TRUE;
  330. }
  331. void CLocalMediaPlayEntity::WmpDebug(const char* fmt, ...)
  332. {
  333. va_list arg;
  334. va_start(arg, fmt);
  335. vDbg(fmt, arg);
  336. va_end(arg);
  337. }
  338. void CLocalMediaPlayEntity::ImgDebug(const char* fmt, ...)
  339. {
  340. va_list arg;
  341. va_start(arg, fmt);
  342. vDbg(fmt, arg);
  343. va_end(arg);
  344. }
  345. #else
  346. int CLocalMediaPlayEntity::LoadPlayConfig(CMediaPlayConfig& config, int CfgInx)
  347. {
  348. if (CfgInx >= MAX_PLAY_CHANNELS || CfgInx < 0)
  349. {
  350. Dbg("Invalid CfgInx while LoadConfig!");
  351. return -1;
  352. }
  353. if (config.eMode == LOCALAUDIO && CfgInx < m_Audios.size())
  354. {
  355. memcpy(&config, &(m_Audios[CfgInx]), sizeof(CMediaPlayConfig));
  356. }
  357. else if (config.eMode == LOCALVIDEO && CfgInx < m_Videos.size())
  358. {
  359. memcpy(&config, &(m_Videos[CfgInx]), sizeof(CMediaPlayConfig));
  360. }
  361. else {
  362. return -1;
  363. }
  364. return 0;
  365. }
  366. int CLocalMediaPlayEntity::LoadPlayConfig(CPicPlayConfig& config, int CfgInx)
  367. {
  368. if (CfgInx >= m_defaultPic.size() || CfgInx < 0)
  369. {
  370. Dbg("Invalid CfgInx while LoadConfig!");
  371. return -1;
  372. }
  373. memcpy(&config, &(m_defaultPic[CfgInx]), sizeof(CPicPlayConfig));
  374. return 0;
  375. }
  376. void CLocalMediaPlayEntity::Debug(media_loglevel log_level, const char* fmt, ...)
  377. {
  378. if (log_level >= MEDIA_LOG_DEBUG){
  379. va_list arg;
  380. va_start(arg, fmt);
  381. vDbg(fmt, arg);
  382. va_end(arg);
  383. }
  384. }
  385. void CLocalMediaPlayEntity::PicDebug(pic_loglevel log_level, const char* fmt, ...)
  386. {
  387. if (log_level >= PIC_LOG_ERROR){
  388. va_list arg;
  389. va_start(arg, fmt);
  390. vDbg(fmt, arg);
  391. va_end(arg);
  392. }
  393. }
  394. void CLocalMediaPlayEntity::AudioPlayFinished()
  395. {
  396. AudioPlayRet ret;
  397. ret.AudioNames = m_lastPlayAudio.c_str();
  398. ret.ret = true;
  399. Dbg("stop play audio %s success", ret.AudioNames.GetData());
  400. SpSendBroadcast(GetFunction(), eMsg_AudioPlayRet, eMsgSig_AudioPlayRet, ret);
  401. }
  402. int CLocalMediaPlayEntity::GetMediaPlayerIcoPath(char* strPath, size_t uLen)
  403. {
  404. return GetPlayerIcoPath(strPath, uLen);
  405. }
  406. int CLocalMediaPlayEntity::GetPicPlayerIcoPath(char* strPath, size_t uLen)
  407. {
  408. return GetPlayerIcoPath(strPath, uLen);
  409. }
  410. bool CLocalMediaPlayEntity::GetPlayFlag()
  411. {
  412. return m_badplayflag;
  413. }
  414. bool CLocalMediaPlayEntity::GetScanExitFlag()
  415. {
  416. return m_scanexitflag;
  417. }
  418. int CLocalMediaPlayEntity::GetPlayerIcoPath(char* strPath, size_t uLen)
  419. {
  420. int iRet = -1;
  421. if (NULL == strPath) {
  422. return iRet;
  423. }
  424. CSimpleStringA csBinPath;
  425. ErrorCodeEnum eErrPath = GetFunction()->GetPath("Bin", csBinPath);
  426. if (eErrPath != Error_Succeed) {
  427. Dbg("GetBasePath failed (%d).", eErrPath);
  428. return iRet;
  429. }
  430. CSimpleStringA szIcoName("rvc_media_player_64px.bmp");
  431. szIcoName = csBinPath + SPLIT_SLASH_STR + szIcoName;
  432. //Dbg("media player ico full path is %s.", szIcoName.GetData());
  433. if (uLen > szIcoName.GetLength()) {
  434. memcpy(strPath, szIcoName.GetData(), szIcoName.GetLength());
  435. iRet = 0;
  436. }
  437. return iRet;
  438. }
  439. #endif // RVC_OS_WIN
  440. void CLocalMediaPlayEntity::OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID, const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  441. const DWORD dwSysError, const DWORD dwUserCode, const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  442. const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName, const char *pszMessage)
  443. {
  444. if (dwUserCode == LOG_EVT_SELFCHECK_IEBROWSER_IDLE)
  445. {
  446. Dbg("IEBrowser to idle, stop all media!");
  447. StopAll();
  448. }
  449. }
  450. void CLocalMediaPlayEntity::OnPreStart(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext)
  451. {
  452. LOG_FUNCTION();
  453. ErrorCodeEnum Error = __OnStart(Error_Succeed);
  454. pTransactionContext->SendAnswer(Error);
  455. }
  456. ErrorCodeEnum CLocalMediaPlayEntity::__OnStart(ErrorCodeEnum preOperationError)
  457. {
  458. #ifdef RVC_OS_WIN
  459. //toolkit_setenv("SDL_AUDIODRIVER", "winmm");
  460. #endif // RVC_OS_WIN
  461. for (int i = 0; i != MAX_PLAY_CHANNELS; ++i)
  462. {
  463. #ifdef RVC_OS_WIN
  464. m_pVideoPlayer[i] = new Clibwmpplayer(this);
  465. m_pImagePlayer[i] = new Clibimgplayer(this);
  466. #else
  467. m_pMediaPlayer[i] = new Clibmediaplayer(this);
  468. m_pPicturePlayer[i] = new Clibpictureplayer(this);
  469. #endif
  470. }
  471. #ifdef RVC_OS_WIN
  472. m_pAudioPlayer = new Clibwmpplayer(this);
  473. #else
  474. m_pMediaAudioPlayer = new Clibmediaplayer(this);
  475. signal(SIGTERM, sig_handler);
  476. #endif // RVC_OS_WIN
  477. if (!IsRunConfigExist())
  478. {
  479. SetLocalVideoVolume(0, 50);
  480. SetLocalAudioVolume(50);
  481. }
  482. //setMediaPath();
  483. loadDefaultMedia();
  484. GetFunction()->SubscribeLog(m_SubIDIEIdle, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_SELFCHECK_IEBROWSER_IDLE, NULL, false);
  485. #ifdef RVC_OS_WIN
  486. m_scanThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)& qryMedia, this, 0, NULL);
  487. if (NULL != m_scanThread)
  488. Dbg("create qryMeia thread success, %d.", m_scanThread);
  489. #else
  490. int err = pthread_create(&m_scanThreadId, NULL, queryMedia, this);
  491. if (0 == err){
  492. Dbg("create queryMedia thread success, %u.", m_scanThreadId);
  493. }
  494. else{
  495. Dbg("create queryMedia thread failed.");
  496. }
  497. #endif // RVC_OS_WIN
  498. return Error_Succeed;
  499. }
  500. void CLocalMediaPlayEntity::OnPreClose(EntityCloseCauseEnum eCloseCause, CSmartPointer<ITransactionContext> pTransactionContext)
  501. {
  502. LOG_FUNCTION();
  503. ErrorCodeEnum Error = __OnClose(Error_Succeed);
  504. pTransactionContext->SendAnswer(Error);
  505. }
  506. ErrorCodeEnum CLocalMediaPlayEntity::__OnClose(ErrorCodeEnum preOperationError)
  507. {
  508. for (int i = 0; i != MAX_PLAY_CHANNELS; ++i)
  509. {
  510. #ifdef RVC_OS_WIN
  511. delete m_pVideoPlayer[i]; m_pVideoPlayer[i] = NULL;
  512. delete m_pImagePlayer[i]; m_pImagePlayer[i] = NULL;
  513. #else
  514. delete m_pMediaPlayer[i]; m_pMediaPlayer[i] = NULL;
  515. delete m_pPicturePlayer[i]; m_pPicturePlayer[i] = NULL;
  516. #endif // RVC_OS_WIN
  517. }
  518. #ifdef RVC_OS_WIN
  519. delete m_pAudioPlayer; m_pAudioPlayer = NULL;
  520. #else
  521. delete m_pMediaAudioPlayer; m_pMediaAudioPlayer = NULL;
  522. #endif // RVC_OS_WIN
  523. GetFunction()->UnsubscribeLog(m_SubIDIEIdle);
  524. return Error_Succeed;
  525. }
  526. #ifdef RVC_OS_WIN
  527. DWORD WINAPI CheckAudioThread(LPVOID param)
  528. {
  529. CLocalMediaPlayEntity *entity = (CLocalMediaPlayEntity*)param;
  530. Dbg("Begin CheckAudioThread");
  531. HANDLE playThread = NULL;
  532. if (!entity->m_pAudioPlayer->checkIsPlay(playThread))
  533. {
  534. Dbg("Create play audio Media Thread Failed!");
  535. return 0;
  536. }
  537. WaitForSingleObject(playThread, INFINITE);
  538. entity->m_pAudioPlayer->Close();
  539. AudioPlayRet ret;
  540. ret.AudioNames = entity->m_lastPlayAudio.c_str();
  541. ret.ret = true;
  542. Dbg("stop play audio %s success", ret.AudioNames);
  543. SpSendBroadcast(entity->GetFunction(), eMsg_AudioPlayRet, eMsgSig_AudioPlayRet, ret);
  544. return 0;
  545. }
  546. #else
  547. void* StartAudioPlayingThreadFunc(void* param)
  548. {
  549. CLocalMediaPlayEntity* entity = (CLocalMediaPlayEntity*)param;
  550. Dbg("Enter StartAudioPlayingThreadFunc");
  551. const char* pAudioNames = entity->m_lastPlayAudio.c_str();
  552. Dbg("Begin StartAudio, and Audio Info is %s.", pAudioNames);
  553. if (0 == entity->m_pMediaAudioPlayer->PlayLocalAudio(pAudioNames)) {
  554. Dbg("Succeed to StartAudio, and Audio Info is %s.", pAudioNames);
  555. }
  556. else{
  557. Dbg("StartAudio failed, for %s is not exsit.", pAudioNames);
  558. }
  559. Dbg("Leave StartAudioPlayingThreadFunc");
  560. return 0;
  561. }
  562. #endif // RVC_OS_WIN
  563. #ifdef RVC_OS_WIN
  564. DWORD WINAPI MediaPlayThread(LPVOID param)
  565. {
  566. CLocalMediaPlayEntity *entity = (CLocalMediaPlayEntity*)param;
  567. while (TRUE)
  568. {
  569. vector<ResourceParse> curParse;
  570. entity->m_mediaManage.GetPlayListByLocal(curParse);
  571. if (0 == curParse.size())
  572. {
  573. HANDLE playThread = NULL;
  574. CWmpPlayConfig config;
  575. ZeroMemory(&config, sizeof(CWmpPlayConfig));
  576. memcpy(&config, &(entity->m_defaultVideo[entity->m_mediaParam.nCfgInx]), sizeof(CWmpPlayConfig));
  577. config.nPlayCnt = 1; //can be change
  578. config.eMode = LOCALVIDEO;
  579. config.nWndX = entity->m_mediaParam.nWndX;
  580. config.nWndY = entity->m_mediaParam.nWndY;
  581. config.nWndWidth = entity->m_mediaParam.nWndWidth;
  582. config.nWndHeight = entity->m_mediaParam.nWndHeight;
  583. if (IS_DEBUG)
  584. {
  585. config.bFullScreen = false;
  586. config.bPrimMonitor = true;
  587. }
  588. // add by ly@2018/07/30
  589. if (!entity->GetLocalVideoVolume(0, config.nVolume))
  590. {
  591. config.nVolume = entity->m_defaultVolum;
  592. }
  593. Dbg("config.nVolume=%d while play local video.", config.nVolume);
  594. // �жϵ�ǰʱ���Ƿ���������
  595. SYSTEMTIME st;
  596. GetLocalTime(&st);
  597. TCHAR strNow[TIME_LEN];
  598. sprintf(strNow, "%02d:%02d:%02d", st.wHour, st.wMinute, st.wSecond);
  599. if (strcmp(strNow, config.strVideoRunTime_S) < 0 || strcmp(strNow, config.strVideoRunTime_E) >= 0)
  600. {
  601. Sleep(10000);
  602. continue;
  603. }
  604. entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
  605. if (!entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(playThread))
  606. {
  607. Dbg("Create play Video Media Thread Failed!");
  608. return 0;
  609. }
  610. WaitForSingleObject(playThread, INFINITE);
  611. if (entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->checkIsStop())
  612. {//ֹͣ����
  613. Dbg("stop play video");
  614. return 0;
  615. }
  616. else
  617. entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->Close();
  618. }
  619. for (vector<ResourceParse>::iterator i = curParse.begin(); i != curParse.end(); i++)
  620. {
  621. HANDLE playThread = NULL;
  622. Dbg("begin play extend %c:%s, %s", i->type, i->resourcePath.c_str(), i->videoNames.c_str());
  623. if ('V' == i->type)
  624. {//video
  625. CWmpPlayConfig config;
  626. ZeroMemory(&config, sizeof(CWmpPlayConfig));
  627. config.bFullScreen = IS_DEBUG ? false : i->fullScreen;
  628. config.bPrimMonitor = IS_DEBUG ? true : i->primMonitor;
  629. config.bSimpleMode = i->simpleMode;
  630. config.eMode = LOCALVIDEO;
  631. config.nFileCnt = 1;
  632. config.nPlayCnt = 1;
  633. config.nPlayInterval = i->playInterval;
  634. // add by ly@2018/07/30
  635. //config.nVolume = IS_DEBUG ? 0 : entity->m_defaultVolum;
  636. if (!entity->GetLocalVideoVolume(0, config.nVolume))
  637. {
  638. config.nVolume = entity->m_defaultVolum;
  639. }
  640. Dbg("config.nVolume=%d while play local video.", config.nVolume);
  641. config.nWndX = entity->m_mediaParam.nWndX;
  642. config.nWndY = entity->m_mediaParam.nWndY;
  643. config.nWndWidth = entity->m_mediaParam.nWndWidth;
  644. config.nWndHeight = entity->m_mediaParam.nWndHeight;
  645. strncpy_s(config.strRootPath, i->resourcePath.c_str(), sizeof(config.strRootPath));
  646. strncpy_s(config.strFileNames[0], i->videoNames.c_str(), 256);
  647. strncpy_s(config.strVideoRunTime_S, "09:00:00", sizeof(config.strVideoRunTime_S));
  648. strncpy_s(config.strVideoRunTime_E, "17:30:00", sizeof(config.strVideoRunTime_E));
  649. entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
  650. if (!entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(playThread))
  651. {
  652. Dbg("Create play Video Media Thread Failed!");
  653. return 0;
  654. }
  655. WaitForSingleObject(playThread, INFINITE);
  656. if (entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->checkIsStop())
  657. {//ֹͣ����
  658. Dbg("stop play video");
  659. return 0;
  660. }
  661. else
  662. entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->Close();
  663. }
  664. else if ('P' == i->type)
  665. {//play Image
  666. CImgPlayConfig config;
  667. ZeroMemory(&config, sizeof(CImgPlayConfig));
  668. config.bFullScreen = IS_DEBUG ? false : i->fullScreen;
  669. config.bPrimMonitor = IS_DEBUG ? true : i->primMonitor;
  670. config.nFileCnt = 1;
  671. config.nPlayCnt = 1;
  672. config.nPlayInterval = i->playInterval;
  673. config.nWndX = entity->m_mediaParam.nWndX;
  674. config.nWndY = entity->m_mediaParam.nWndY;
  675. config.nWndWidth = entity->m_mediaParam.nWndWidth;
  676. config.nWndHeight = entity->m_mediaParam.nWndHeight;
  677. strncpy_s(config.strRootPath, i->resourcePath.c_str(), sizeof(config.strRootPath));
  678. strncpy_s(config.strFileNames[0], i->videoNames.c_str(), 256);
  679. entity->m_pImagePlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
  680. if (!entity->m_pImagePlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(playThread))
  681. {
  682. Dbg("Create play Image Media Thread Failed!");
  683. return 0;
  684. }
  685. WaitForSingleObject(playThread, i->playInterval);
  686. if (entity->m_pImagePlayer[entity->m_mediaParam.nCfgInx]->checkIsStop())
  687. {//ֹͣ����
  688. Dbg("stop play Image");
  689. return 0;
  690. }
  691. else
  692. entity->m_pImagePlayer[entity->m_mediaParam.nCfgInx]->Close();
  693. }
  694. }
  695. }
  696. return 0;
  697. }
  698. #else
  699. void* StartMediaPlayFunc(void* param)
  700. {
  701. int iRet = -1;
  702. if (NULL == param){
  703. return (void*)&iRet;
  704. }
  705. CLocalMediaPlayEntity* entity = (CLocalMediaPlayEntity*)param;
  706. while (entity->GetPlayFlag())
  707. {
  708. rvcResourceParse_t ResourceList[MAX_LOCAL_MEDIAS] = { 0 };
  709. size_t uCount = entity->m_mediaManage.GetPlayListByLocal(ResourceList, MAX_LOCAL_MEDIAS);
  710. //Dbg("uCount == %d", uCount);
  711. //for (int i = 0; i < uCount; i++)
  712. //{
  713. // rvcResourceParse_t item = ResourceList[i];
  714. // Dbg("%s:%d ResourceList[%d] address is 0x%0x.", __FUNCTION__, __LINE__, i, ResourceList[i]);
  715. // Dbg("item->type address is 0x%0x.", item.type);
  716. // Dbg("item->presourcePath address is 0x%0x.", item.strResourcePath);
  717. // Dbg("item->pvideoNames address is 0x%0x.", item.strvideoNames);
  718. // Dbg("play extend %c:%s, %s", item.type, item.strResourcePath, item.strvideoNames);
  719. //}
  720. if (0 == uCount)
  721. {
  722. int64_t playThreadId = 0;
  723. CMediaPlayConfig config = {0};
  724. memcpy(&config, &(entity->m_Videos[entity->m_mediaParam.nCfgInx]), sizeof(CMediaPlayConfig));
  725. config.nPlayCnt = 1; //can be change
  726. config.eMode = LOCALVIDEO;
  727. config.nWndX = entity->m_mediaParam.nWndX;
  728. config.nWndY = entity->m_mediaParam.nWndY;
  729. config.nWndWidth = entity->m_mediaParam.nWndWidth;
  730. config.nWndHeight = entity->m_mediaParam.nWndHeight;
  731. if (IS_DEBUG)
  732. {
  733. config.bFullScreen = false;
  734. config.bPrimMonitor = true;
  735. }
  736. if (!entity->GetLocalVideoVolume(0, config.nVolume))
  737. {
  738. config.nVolume = entity->m_defaultVolum;
  739. }
  740. //Dbg("config.nVolume=%d while play local video.", config.nVolume);
  741. struct tm* ptm = NULL;
  742. time_t t = time(NULL);
  743. ptm = localtime(&t);
  744. TCHAR strNow[TIME_LEN] = {0};
  745. sprintf(strNow, "%02d:%02d:%02d", ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
  746. if (strcmp(strNow, config.strVideoRunTime_S) < 0 || strcmp(strNow, config.strVideoRunTime_E) >= 0)
  747. {
  748. Sleep(10000);
  749. continue;
  750. }
  751. entity->m_pMediaPlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
  752. }
  753. for (int i = 0; i < uCount && i < MAX_LOCAL_MEDIAS && entity->GetPlayFlag(); i++)
  754. {
  755. //Dbg("ResourceList[%d] address is 0x%0x", i, ResourceList[i]);
  756. int64_t playThreadId = 0;
  757. rvcResourceParse_t item = ResourceList[i];
  758. //Dbg("begin play extend %c:%s, %s", item.type, item.strResourcePath, item.strvideoNames);
  759. if ('V' == item.type)
  760. {//video
  761. CMediaPlayConfig config = {0};
  762. config.bFullScreen = IS_DEBUG ? false : item.fullScreen;
  763. config.bPrimMonitor = IS_DEBUG ? true : item.primMonitor;
  764. config.bSimpleMode = item.simpleMode;
  765. config.eMode = LOCALVIDEO;
  766. config.nFileCnt = 1;
  767. config.nPlayCnt = 1;
  768. config.nPlayInterval = item.playInterval;
  769. // add by ly@2018/07/30
  770. //config.nVolume = IS_DEBUG ? 0 : entity->m_defaultVolum;
  771. if (!entity->GetLocalVideoVolume(0, config.nVolume))
  772. {
  773. config.nVolume = entity->m_defaultVolum;
  774. }
  775. //Dbg("config.nVolume=%d while play local video.", config.nVolume);
  776. config.nWndX = entity->m_mediaParam.nWndX;
  777. config.nWndY = entity->m_mediaParam.nWndY;
  778. config.nWndWidth = entity->m_mediaParam.nWndWidth;
  779. config.nWndHeight = entity->m_mediaParam.nWndHeight;
  780. strncpy(config.strRootPath, item.strResourcePath, strlen(item.strResourcePath));
  781. strncpy(config.strFileNames[0], item.strvideoNames, strlen(item.strvideoNames));
  782. strncpy(config.strVideoRunTime_S, "09:00:00", sizeof(config.strVideoRunTime_S));
  783. strncpy(config.strVideoRunTime_E, "17:30:00", sizeof(config.strVideoRunTime_E));
  784. entity->m_pMediaPlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
  785. Sleep(2000);
  786. }
  787. else if ('P' == item.type)
  788. {//play Image
  789. CPicPlayConfig config = {0};
  790. config.bFullScreen = IS_DEBUG ? false : item.fullScreen;
  791. config.bPrimMonitor = IS_DEBUG ? true : item.primMonitor;
  792. config.nFileCnt = 1;
  793. config.nPlayCnt = 1;
  794. config.nPlayInterval = item.playInterval;
  795. config.nWndX = entity->m_mediaParam.nWndX;
  796. config.nWndY = entity->m_mediaParam.nWndY;
  797. config.nWndWidth = entity->m_mediaParam.nWndWidth;
  798. config.nWndHeight = entity->m_mediaParam.nWndHeight;
  799. strncpy(config.strRootPath, item.strResourcePath, strlen(item.strResourcePath));
  800. strncpy(config.strFileNames[0], item.strvideoNames, strlen(item.strvideoNames));
  801. entity->m_pPicturePlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
  802. if (!entity->m_pPicturePlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(&playThreadId)){
  803. Dbg("Create play Image Media Thread Failed!");
  804. iRet = -1;
  805. return (void*)& iRet;
  806. }
  807. else{
  808. Dbg("Image Media Player Thread id is %u.", playThreadId);
  809. }
  810. if (0 == pthread_join(playThreadId, NULL)){
  811. //Dbg("pthread join thread id %u success.", playThreadId);
  812. iRet = 0;
  813. }
  814. else {
  815. Dbg("pthread join thread id %u failed for %s.", playThreadId, strerror(errno));
  816. iRet = -1;
  817. }
  818. }
  819. }
  820. }
  821. return (void*)&iRet;
  822. }
  823. #endif // RVC_OS_WIN
  824. void CLocalMediaPlayEntity::StartVideo(int nCfgInx, int nWndX, int nWndY, int nWndWidth, int nWndHeight)
  825. {
  826. if (nCfgInx >= MAX_PLAY_CHANNELS || nCfgInx < 0)
  827. {
  828. Dbg("Invalid CfgInx while StartVideo!");
  829. return;
  830. }
  831. m_mediaParam.nCfgInx = nCfgInx;
  832. m_mediaParam.nWndX = nWndX;
  833. m_mediaParam.nWndY = nWndY;
  834. m_mediaParam.nWndWidth = nWndWidth;
  835. m_mediaParam.nWndHeight = nWndHeight;
  836. #ifdef RVC_OS_WIN // RVC_OS_WIN
  837. if (NULL != m_playThread)
  838. {
  839. WaitForSingleObject(m_playThread, 5000);
  840. m_playThread = NULL;
  841. }
  842. if (NULL == m_playThread)
  843. m_playThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)& MediaPlayThread, this, 0, NULL);
  844. #else
  845. m_badplayflag = true;
  846. int err = pthread_create(&m_uMediaPlayThreadId, NULL, StartMediaPlayFunc, this);
  847. if (0 == err) {
  848. Dbg("create media play thread[%u] success.", m_uMediaPlayThreadId);
  849. }
  850. else {
  851. Dbg("create media play thread failed.");
  852. }
  853. #endif
  854. }
  855. void CLocalMediaPlayEntity::StartAudio(const char *pAudioNames)
  856. {
  857. #ifdef RVC_OS_WIN
  858. static HANDLE audioPlayThread = NULL;
  859. if (audioPlayThread)//�ر����ڲ��ŵ���Ƶ
  860. {
  861. DWORD exitCode = 0;
  862. if (WAIT_TIMEOUT == WaitForSingleObject(audioPlayThread, 50))
  863. {
  864. TerminateThread(audioPlayThread, exitCode);
  865. m_pAudioPlayer->Close();
  866. }
  867. audioPlayThread = NULL;
  868. }
  869. Dbg("Begin StartAudio, and Audio Info is %s.", pAudioNames);
  870. m_pAudioPlayer->PlayLocalAudio(pAudioNames);
  871. Dbg("Succeed to StartAudio, and Audio Info is %s.", pAudioNames);
  872. auto audioRet = GetLocalAudioVolume();
  873. m_pAudioPlayer->SetVolume(audioRet.second);
  874. Dbg("Succeed to set audio volume %d!", audioRet.second);
  875. m_lastPlayAudio = pAudioNames;
  876. audioPlayThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)& CheckAudioThread, this, 0, NULL);
  877. #else
  878. if (m_pMediaAudioPlayer->checkIsPlay()) {
  879. Dbg("aurrent is playing, wait for it.");
  880. //m_pMediaAudioPlayer->Close();
  881. pthread_join(m_uMediaPlayThreadId, NULL);
  882. }
  883. m_lastPlayAudio = pAudioNames;
  884. int err = pthread_create(&m_uMediaPlayThreadId, NULL, StartAudioPlayingThreadFunc, this);
  885. if (0 == err) {
  886. Dbg("create audio play thread[%u] success.", m_uMediaPlayThreadId);
  887. }
  888. else {
  889. Dbg("create audio play thread failed.");
  890. }
  891. auto audioRet = GetLocalAudioVolume();
  892. m_pMediaAudioPlayer->SetVolume(audioRet.second);
  893. Dbg("Succeed to set audio volume %d!", audioRet.second);
  894. #endif // RVC_OS_WIN
  895. }
  896. void CLocalMediaPlayEntity::StartImage(int nCfgInx, int nWndX, int nWndY, int nWndWidth, int nWndHeight)
  897. {
  898. if (nCfgInx >= MAX_PLAY_CHANNELS || nCfgInx < 0)
  899. {
  900. Dbg("Invalid CfgInx while StartImage!");
  901. return;
  902. }
  903. #ifdef RVC_OS_WIN
  904. m_pImagePlayer[nCfgInx]->Play(nCfgInx, nWndX, nWndY, nWndWidth, nWndHeight);
  905. #else
  906. m_pPicturePlayer[nCfgInx]->Play(nCfgInx, nWndX, nWndY, nWndWidth, nWndHeight);
  907. #endif // RVC_OS_WIN
  908. Dbg("Succeed to StartImage!");
  909. }
  910. void CLocalMediaPlayEntity::StopVideo(int nCfgInx)
  911. {
  912. if (nCfgInx >= MAX_PLAY_CHANNELS || nCfgInx < 0)
  913. {
  914. Dbg("Invalid CfgInx while StopVideo!");
  915. return;
  916. }
  917. #ifdef RVC_OS_WIN
  918. m_pVideoPlayer[nCfgInx]->Close();
  919. m_pImagePlayer[nCfgInx]->Close();
  920. if (m_playThread)
  921. {
  922. TerminateThread(m_playThread, -1);
  923. m_playThread = NULL;
  924. }
  925. #else
  926. m_pMediaPlayer[nCfgInx]->Close();
  927. m_pPicturePlayer[nCfgInx]->Close();
  928. m_badplayflag = false;
  929. #endif // RVC_OS_WIN
  930. Dbg("Succeed to StopVideo!");
  931. }
  932. void CLocalMediaPlayEntity::StopAudio()
  933. {
  934. #ifdef RVC_OS_WIN
  935. m_pAudioPlayer->Close();
  936. #else
  937. m_pMediaAudioPlayer->Close();
  938. #endif
  939. Dbg("Succeed to StopAudio!");
  940. }
  941. void CLocalMediaPlayEntity::StopImage(int nCfgInx)
  942. {
  943. if (nCfgInx >= MAX_PLAY_CHANNELS || nCfgInx < 0)
  944. {
  945. Dbg("Invalid CfgInx while StopImage!");
  946. return;
  947. }
  948. #ifdef RVC_OS_WIN
  949. m_pImagePlayer[nCfgInx]->Close();
  950. #else
  951. m_pPicturePlayer[nCfgInx]->Close();
  952. #endif // RVC_OS_WIN
  953. Dbg("Succeed to StopImage!");
  954. }
  955. void CLocalMediaPlayEntity::StopAll()
  956. {
  957. StopAudio(); // �ر���Ƶ
  958. for (int i = 0; i < MAX_PLAY_CHANNELS; ++i)
  959. {
  960. StopVideo(i); // �ر���Ƶ
  961. StopImage(i); // �ر�ͼ��
  962. }
  963. }
  964. bool CLocalMediaPlayEntity::GetLocalVideoVolume(int nCfgInx, int &nVolume)
  965. {
  966. //Dbg("get local video volume req.");
  967. CSmartPointer<IConfigInfo> spConfig;
  968. ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_Run, spConfig);
  969. if (Error == Error_Succeed)
  970. {
  971. Error = spConfig->ReadConfigValueInt("LocalVideo", "Volume", nVolume);
  972. if (Error == Error_Succeed && nVolume >= 0 && nVolume <= 100)
  973. {
  974. //Dbg("succeed to get local video volume with nCfgInx:%d, nVolume:%d", nCfgInx, nVolume);
  975. return true;
  976. }
  977. }
  978. Dbg("fail to get local video volume!");
  979. return false;
  980. }
  981. std::pair<bool, int> CLocalMediaPlayEntity::GetLocalAudioVolume()
  982. {
  983. Dbg("get local audio volume req.");
  984. CSmartPointer<IConfigInfo> spConfig;
  985. int nVolume = 0;
  986. ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_Run, spConfig);
  987. if (Error == Error_Succeed)
  988. {
  989. Error = spConfig->ReadConfigValueInt("LocalAudio", "Volume", nVolume);
  990. if (nVolume == 0)
  991. {
  992. nVolume = 50;
  993. spConfig->WriteConfigValueInt("LocalAudio", "Volume", nVolume);
  994. Dbg("read nVolume 0, set default 50");
  995. }
  996. if (Error == Error_Succeed && nVolume >= 0 && nVolume <= 100)
  997. {
  998. Dbg("succeed to get local audio volume with nVolume:%d", nVolume);
  999. return std::make_pair(true, nVolume);
  1000. }
  1001. }
  1002. Dbg("fail to get local audio volume!");
  1003. return std::make_pair(false, nVolume);
  1004. }
  1005. bool CLocalMediaPlayEntity::SetLocalAudioVolume(int nVolume)
  1006. {
  1007. Dbg("set local video audio req.");
  1008. if (nVolume < 0 || nVolume > 100)
  1009. {
  1010. return false;
  1011. }
  1012. CSmartPointer<IConfigInfo> spConfig;
  1013. ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_Run, spConfig);
  1014. if (Error == Error_Succeed)
  1015. {
  1016. Error = spConfig->WriteConfigValueInt("LocalAudio", "Volume", nVolume);
  1017. if (Error == Error_Succeed)
  1018. {
  1019. Dbg("succeed to set local audio volume with nVolume:%d!", nVolume);
  1020. #ifdef RVC_OS_WIN
  1021. m_pAudioPlayer->SetVolume(nVolume);
  1022. #else
  1023. m_pMediaAudioPlayer->SetVolume(nVolume);
  1024. #endif // RVC_OS_WIN
  1025. return true;
  1026. }
  1027. }
  1028. Dbg("fail to set local video volume!");
  1029. return false;
  1030. }
  1031. bool CLocalMediaPlayEntity::SetLocalVideoVolume(int nCfgInx, int nVolume)
  1032. {
  1033. Dbg("set local video volume req.");
  1034. if (nVolume < 0 || nVolume > 100)
  1035. {
  1036. return false;
  1037. }
  1038. CSmartPointer<IConfigInfo> spConfig;
  1039. ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_Run, spConfig);
  1040. if (Error == Error_Succeed)
  1041. {
  1042. Error = spConfig->WriteConfigValueInt("LocalVideo", "Volume", nVolume);
  1043. if (Error == Error_Succeed)
  1044. {
  1045. Dbg("succeed to set local video volume with nCfgInx:%d, nVolume:%d!", nCfgInx, nVolume);
  1046. for (int i = 0; i < MAX_PLAY_CHANNELS; ++i)
  1047. {
  1048. #ifdef RVC_OS_WIN
  1049. m_pVideoPlayer[i]->SetVolume(nVolume);
  1050. #else
  1051. m_pMediaPlayer[i]->SetVolume(nVolume);
  1052. #endif
  1053. }
  1054. return true;
  1055. }
  1056. }
  1057. Dbg("fail to set local video volume!");
  1058. return false;
  1059. }
  1060. bool CLocalMediaPlayEntity::IsRunConfigExist()
  1061. {
  1062. CSimpleStringA strPath;
  1063. ErrorCodeEnum eErr;
  1064. if ((eErr = GetFunction()->GetPath("RunInfo", strPath)) != Error_Succeed)
  1065. {
  1066. Dbg("get runinfo path failed(%d)", eErr);
  1067. return false;
  1068. }
  1069. #ifdef RVC_OS_WIN
  1070. CSimpleStringA strRuninfoFile;
  1071. strRuninfoFile = CSimpleStringA::Format("%s\\runcfg\\%s.ini", (LPCTSTR)strPath, GetEntityName());
  1072. WIN32_FIND_DATA findData;
  1073. if (FindFirstFileA((LPCTSTR)strRuninfoFile, &findData) != INVALID_HANDLE_VALUE) return true;
  1074. return false;
  1075. #else
  1076. CSimpleStringA strRuninfoFile;
  1077. strRuninfoFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR "%s.ini", (LPCTSTR)strPath, GetEntityName());
  1078. if (ExistsFileA(strRuninfoFile)) {
  1079. return true;
  1080. }
  1081. else{
  1082. return false;
  1083. }
  1084. #endif // RVC_OS_WIN
  1085. }
  1086. void CLocalMediaPlayEntity::OnSelfTest(EntityTestEnum eTestType, CSmartPointer<ITransactionContext> pTransactionContext)
  1087. {
  1088. if (Test_ShakeHand == eTestType)
  1089. {
  1090. pTransactionContext->SendAnswer(Error_Succeed);
  1091. }
  1092. }
  1093. void CLocalMediaPlayEntity::CStringSplit(char *str, char **result, const char *del)
  1094. {
  1095. char *p = strtok(str, del);
  1096. while (p != NULL)
  1097. {
  1098. *result++ = p;
  1099. p = strtok(NULL, del);
  1100. }
  1101. }
  1102. void CLocalMediaPlaySession::Handle_StartPlayVideo(SpReqAnsContext<PlayService_StartPlayVideo_Req, PlayService_StartPlayVideo_Ans>::Pointer ctx)
  1103. {
  1104. Dbg("start play Video, Index:%d, WndX:%d, WndY:%d, WndWidth:%d, WndWidth:%d", ctx->Req.CfgInx, ctx->Req.WndX, ctx->Req.WndY, ctx->Req.WndWidth, ctx->Req.WndHeight);
  1105. CSimpleStringA UpdateState = "";
  1106. ErrorCodeEnum Error = m_pEntity->GetFunction()->GetSysVar("UpdateState", UpdateState);
  1107. if (Error == Error_Succeed && "1" == UpdateState)
  1108. {
  1109. Dbg("detect current is upgrade, do not play the media");
  1110. ctx->Answer(Error_Stoped);
  1111. m_pEntity->StopAll();
  1112. return;
  1113. }
  1114. m_pEntity->StartVideo(ctx->Req.CfgInx, ctx->Req.WndX, ctx->Req.WndY, ctx->Req.WndWidth, ctx->Req.WndHeight);
  1115. ctx->Answer(Error_Succeed);
  1116. }
  1117. void CLocalMediaPlaySession::Handle_StartPlayAudio(SpReqAnsContext<PlayService_StartPlayAudio_Req, PlayService_StartPlayAudio_Ans>::Pointer ctx)
  1118. {
  1119. CSimpleStringA AudioNames = CSimpleStringW2A(ctx->Req.AudioNames);
  1120. CSimpleStringA UpdateState = "";
  1121. ErrorCodeEnum Error = m_pEntity->GetFunction()->GetSysVar("UpdateState", UpdateState);
  1122. if (Error == Error_Succeed && "1" == UpdateState)
  1123. {
  1124. Dbg("detect current is upgrade, do not play the media");
  1125. ctx->Answer(Error_Stoped);
  1126. m_pEntity->StopAll();
  1127. return;
  1128. }
  1129. m_pEntity->StartAudio(AudioNames.GetData());
  1130. ctx->Answer(Error_Succeed);
  1131. }
  1132. void CLocalMediaPlaySession::Handle_StartPlayImage(SpReqAnsContext<PlayService_StartPlayImage_Req, PlayService_StartPlayImage_Ans>::Pointer ctx)
  1133. {
  1134. m_pEntity->StartImage(ctx->Req.CfgInx, ctx->Req.WndX, ctx->Req.WndY, ctx->Req.WndWidth, ctx->Req.WndHeight);
  1135. ctx->Answer(Error_Succeed);
  1136. }
  1137. void CLocalMediaPlaySession::Handle_StopPlayVideo(SpReqAnsContext<PlayService_StopPlayVideo_Req, PlayService_StopPlayVideo_Ans>::Pointer ctx)
  1138. {
  1139. Dbg("stop play Video, Index:%d", ctx->Req.CfgInx);
  1140. m_pEntity->StopVideo(ctx->Req.CfgInx);
  1141. ctx->Answer(Error_Succeed);
  1142. }
  1143. void CLocalMediaPlaySession::Handle_StopPlayAudio(SpReqAnsContext<PlayService_StopPlayAudio_Req, PlayService_StopPlayAudio_Ans>::Pointer ctx)
  1144. {
  1145. m_pEntity->StopAudio();
  1146. ctx->Answer(Error_Succeed);
  1147. }
  1148. void CLocalMediaPlaySession::Handle_StopPlayImage(SpReqAnsContext<PlayService_StopPlayImage_Req, PlayService_StopPlayImage_Ans>::Pointer ctx)
  1149. {
  1150. m_pEntity->StopImage(ctx->Req.CfgInx);
  1151. ctx->Answer(Error_Succeed);
  1152. }
  1153. void CLocalMediaPlaySession::OnClose(ErrorCodeEnum)
  1154. {
  1155. LOG_FUNCTION();
  1156. }
  1157. void CLocalMediaPlaySession::Handle_GetLocalVideoVolume( SpReqAnsContext<PlayService_GetLocalVideoVolume_Req, PlayService_GetLocalVideoVolume_Ans>::Pointer ctx )
  1158. {
  1159. int volume = 0;
  1160. if (m_pEntity->GetLocalVideoVolume(ctx->Req.CfgInx, volume))
  1161. {
  1162. ctx->Ans.Volume = volume;
  1163. ctx->Answer(Error_Succeed);
  1164. }
  1165. else
  1166. {
  1167. ctx->Answer(Error_Unexpect);
  1168. }
  1169. }
  1170. void CLocalMediaPlaySession::Handle_SetLocalVideoVolume( SpReqAnsContext<PlayService_SetLocalVideoVolume_Req, PlayService_SetLocalVideoVolume_Ans>::Pointer ctx )
  1171. {
  1172. if (m_pEntity->SetLocalVideoVolume(ctx->Req.CfgInx, ctx->Req.Volume))
  1173. {
  1174. ctx->Answer(Error_Succeed);
  1175. }
  1176. else
  1177. {
  1178. ctx->Answer(Error_Unexpect);
  1179. }
  1180. }
  1181. void CLocalMediaPlaySession::Handle_GetLocalAudioVolume(SpReqAnsContext<PlayService_GetLocalAudioVolume_Req, PlayService_GetLocalAudioVolume_Ans>::Pointer ctx)
  1182. {
  1183. auto audioRet = m_pEntity->GetLocalAudioVolume();
  1184. if (audioRet.first)
  1185. {
  1186. ctx->Ans.Volume = audioRet.second;
  1187. ctx->Answer(Error_Succeed);
  1188. }
  1189. else
  1190. {
  1191. ctx->Answer(Error_Unexpect);
  1192. }
  1193. }
  1194. void CLocalMediaPlaySession::Handle_SetLocalAudioVolume(SpReqAnsContext<PlayService_SetLocalAudioVolume_Req, PlayService_SetLocalAudioVolume_Ans>::Pointer ctx)
  1195. {
  1196. if (m_pEntity->SetLocalAudioVolume(ctx->Req.Volume))
  1197. {
  1198. ctx->Answer(Error_Succeed);
  1199. }
  1200. else
  1201. {
  1202. ctx->Answer(Error_Unexpect);
  1203. }
  1204. }
  1205. SP_BEGIN_ENTITY_MAP()
  1206. SP_ENTITY(CLocalMediaPlayEntity)
  1207. SP_END_ENTITY_MAP()