mod_localmediaplay.cpp 39 KB

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