mod_localmediaplay.cpp 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380
  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_ERROR){
  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. mediaplayer_init();
  468. m_pMediaPlayer[i] = new Clibmediaplayer(this);
  469. m_pPicturePlayer[i] = new Clibpictureplayer(this);
  470. #endif
  471. }
  472. #ifdef RVC_OS_WIN
  473. m_pAudioPlayer = new Clibwmpplayer(this);
  474. #else
  475. m_pMediaAudioPlayer = new Clibmediaplayer(this);
  476. signal(SIGTERM, sig_handler);
  477. #endif // RVC_OS_WIN
  478. if (!IsRunConfigExist())
  479. {
  480. SetLocalVideoVolume(0, 50);
  481. SetLocalAudioVolume(50);
  482. }
  483. //setMediaPath();
  484. loadDefaultMedia();
  485. GetFunction()->SubscribeLog(m_SubIDIEIdle, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_SELFCHECK_IEBROWSER_IDLE, NULL, false);
  486. #ifdef RVC_OS_WIN
  487. m_scanThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)& qryMedia, this, 0, NULL);
  488. if (NULL != m_scanThread)
  489. Dbg("create qryMeia thread success, %d.", m_scanThread);
  490. #else
  491. int err = pthread_create(&m_scanThreadId, NULL, queryMedia, this);
  492. if (0 == err){
  493. Dbg("create queryMedia thread success, %u.", m_scanThreadId);
  494. }
  495. else{
  496. Dbg("create queryMedia thread failed.");
  497. }
  498. #endif // RVC_OS_WIN
  499. return Error_Succeed;
  500. }
  501. void CLocalMediaPlayEntity::OnPreClose(EntityCloseCauseEnum eCloseCause, CSmartPointer<ITransactionContext> pTransactionContext)
  502. {
  503. LOG_FUNCTION();
  504. ErrorCodeEnum Error = __OnClose(Error_Succeed);
  505. pTransactionContext->SendAnswer(Error);
  506. }
  507. ErrorCodeEnum CLocalMediaPlayEntity::__OnClose(ErrorCodeEnum preOperationError)
  508. {
  509. for (int i = 0; i != MAX_PLAY_CHANNELS; ++i)
  510. {
  511. #ifdef RVC_OS_WIN
  512. delete m_pVideoPlayer[i]; m_pVideoPlayer[i] = NULL;
  513. delete m_pImagePlayer[i]; m_pImagePlayer[i] = NULL;
  514. #else
  515. delete m_pMediaPlayer[i]; m_pMediaPlayer[i] = NULL;
  516. delete m_pPicturePlayer[i]; m_pPicturePlayer[i] = NULL;
  517. #endif // RVC_OS_WIN
  518. }
  519. #ifdef RVC_OS_WIN
  520. delete m_pAudioPlayer; m_pAudioPlayer = NULL;
  521. #else
  522. delete m_pMediaAudioPlayer; m_pMediaAudioPlayer = NULL;
  523. mediaplayer_term();
  524. #endif // RVC_OS_WIN
  525. GetFunction()->UnsubscribeLog(m_SubIDIEIdle);
  526. return Error_Succeed;
  527. }
  528. #ifdef RVC_OS_WIN
  529. DWORD WINAPI CheckAudioThread(LPVOID param)
  530. {
  531. CLocalMediaPlayEntity *entity = (CLocalMediaPlayEntity*)param;
  532. Dbg("Begin CheckAudioThread");
  533. HANDLE playThread = NULL;
  534. if (!entity->m_pAudioPlayer->checkIsPlay(playThread))
  535. {
  536. Dbg("Create play audio Media Thread Failed!");
  537. return 0;
  538. }
  539. WaitForSingleObject(playThread, INFINITE);
  540. entity->m_pAudioPlayer->Close();
  541. AudioPlayRet ret;
  542. ret.AudioNames = entity->m_lastPlayAudio.c_str();
  543. ret.ret = true;
  544. Dbg("stop play audio %s success", ret.AudioNames);
  545. SpSendBroadcast(entity->GetFunction(), eMsg_AudioPlayRet, eMsgSig_AudioPlayRet, ret);
  546. return 0;
  547. }
  548. #else
  549. void* StartAudioPlayingThreadFunc(void* param)
  550. {
  551. CLocalMediaPlayEntity* entity = (CLocalMediaPlayEntity*)param;
  552. Dbg("Enter StartAudioPlayingThreadFunc");
  553. const char* pAudioNames = entity->m_lastPlayAudio.c_str();
  554. Dbg("Begin StartAudio, and Audio Info is %s.", pAudioNames);
  555. if (0 == entity->m_pMediaAudioPlayer->PlayLocalAudio(pAudioNames)) {
  556. Dbg("Succeed to StartAudio, and Audio Info is %s.", pAudioNames);
  557. }
  558. else{
  559. Dbg("StartAudio failed, for %s is not exsit.", pAudioNames);
  560. }
  561. Dbg("Leave StartAudioPlayingThreadFunc");
  562. return 0;
  563. }
  564. #endif // RVC_OS_WIN
  565. #ifdef RVC_OS_WIN
  566. DWORD WINAPI MediaPlayThread(LPVOID param)
  567. {
  568. CLocalMediaPlayEntity *entity = (CLocalMediaPlayEntity*)param;
  569. while (TRUE)
  570. {
  571. vector<ResourceParse> curParse;
  572. entity->m_mediaManage.GetPlayListByLocal(curParse);
  573. if (0 == curParse.size())
  574. {
  575. HANDLE playThread = NULL;
  576. CWmpPlayConfig config;
  577. ZeroMemory(&config, sizeof(CWmpPlayConfig));
  578. memcpy(&config, &(entity->m_defaultVideo[entity->m_mediaParam.nCfgInx]), sizeof(CWmpPlayConfig));
  579. config.nPlayCnt = 1; //can be change
  580. config.eMode = LOCALVIDEO;
  581. config.nWndX = entity->m_mediaParam.nWndX;
  582. config.nWndY = entity->m_mediaParam.nWndY;
  583. config.nWndWidth = entity->m_mediaParam.nWndWidth;
  584. config.nWndHeight = entity->m_mediaParam.nWndHeight;
  585. if (IS_DEBUG)
  586. {
  587. config.bFullScreen = false;
  588. config.bPrimMonitor = true;
  589. }
  590. // add by ly@2018/07/30
  591. if (!entity->GetLocalVideoVolume(0, config.nVolume))
  592. {
  593. config.nVolume = entity->m_defaultVolum;
  594. }
  595. Dbg("config.nVolume=%d while play local video.", config.nVolume);
  596. // �жϵ�ǰʱ���Ƿ���������
  597. SYSTEMTIME st;
  598. GetLocalTime(&st);
  599. TCHAR strNow[TIME_LEN];
  600. sprintf(strNow, "%02d:%02d:%02d", st.wHour, st.wMinute, st.wSecond);
  601. if (strcmp(strNow, config.strVideoRunTime_S) < 0 || strcmp(strNow, config.strVideoRunTime_E) >= 0)
  602. {
  603. Sleep(10000);
  604. continue;
  605. }
  606. entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
  607. if (!entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(playThread))
  608. {
  609. Dbg("Create play Video Media Thread Failed!");
  610. return 0;
  611. }
  612. WaitForSingleObject(playThread, INFINITE);
  613. if (entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->checkIsStop())
  614. {//ֹͣ����
  615. Dbg("stop play video");
  616. return 0;
  617. }
  618. else
  619. entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->Close();
  620. }
  621. for (vector<ResourceParse>::iterator i = curParse.begin(); i != curParse.end(); i++)
  622. {
  623. HANDLE playThread = NULL;
  624. Dbg("begin play extend %c:%s, %s", i->type, i->resourcePath.c_str(), i->videoNames.c_str());
  625. if ('V' == i->type)
  626. {//video
  627. CWmpPlayConfig config;
  628. ZeroMemory(&config, sizeof(CWmpPlayConfig));
  629. config.bFullScreen = IS_DEBUG ? false : i->fullScreen;
  630. config.bPrimMonitor = IS_DEBUG ? true : i->primMonitor;
  631. config.bSimpleMode = i->simpleMode;
  632. config.eMode = LOCALVIDEO;
  633. config.nFileCnt = 1;
  634. config.nPlayCnt = 1;
  635. config.nPlayInterval = i->playInterval;
  636. // add by ly@2018/07/30
  637. //config.nVolume = IS_DEBUG ? 0 : entity->m_defaultVolum;
  638. if (!entity->GetLocalVideoVolume(0, config.nVolume))
  639. {
  640. config.nVolume = entity->m_defaultVolum;
  641. }
  642. Dbg("config.nVolume=%d while play local video.", config.nVolume);
  643. config.nWndX = entity->m_mediaParam.nWndX;
  644. config.nWndY = entity->m_mediaParam.nWndY;
  645. config.nWndWidth = entity->m_mediaParam.nWndWidth;
  646. config.nWndHeight = entity->m_mediaParam.nWndHeight;
  647. strncpy_s(config.strRootPath, i->resourcePath.c_str(), sizeof(config.strRootPath));
  648. strncpy_s(config.strFileNames[0], i->videoNames.c_str(), 256);
  649. strncpy_s(config.strVideoRunTime_S, "09:00:00", sizeof(config.strVideoRunTime_S));
  650. strncpy_s(config.strVideoRunTime_E, "17:30:00", sizeof(config.strVideoRunTime_E));
  651. entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
  652. if (!entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(playThread))
  653. {
  654. Dbg("Create play Video Media Thread Failed!");
  655. return 0;
  656. }
  657. WaitForSingleObject(playThread, INFINITE);
  658. if (entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->checkIsStop())
  659. {//ֹͣ����
  660. Dbg("stop play video");
  661. return 0;
  662. }
  663. else
  664. entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->Close();
  665. }
  666. else if ('P' == i->type)
  667. {//play Image
  668. CImgPlayConfig config;
  669. ZeroMemory(&config, sizeof(CImgPlayConfig));
  670. config.bFullScreen = IS_DEBUG ? false : i->fullScreen;
  671. config.bPrimMonitor = IS_DEBUG ? true : i->primMonitor;
  672. config.nFileCnt = 1;
  673. config.nPlayCnt = 1;
  674. config.nPlayInterval = i->playInterval;
  675. config.nWndX = entity->m_mediaParam.nWndX;
  676. config.nWndY = entity->m_mediaParam.nWndY;
  677. config.nWndWidth = entity->m_mediaParam.nWndWidth;
  678. config.nWndHeight = entity->m_mediaParam.nWndHeight;
  679. strncpy_s(config.strRootPath, i->resourcePath.c_str(), sizeof(config.strRootPath));
  680. strncpy_s(config.strFileNames[0], i->videoNames.c_str(), 256);
  681. entity->m_pImagePlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
  682. if (!entity->m_pImagePlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(playThread))
  683. {
  684. Dbg("Create play Image Media Thread Failed!");
  685. return 0;
  686. }
  687. WaitForSingleObject(playThread, i->playInterval);
  688. if (entity->m_pImagePlayer[entity->m_mediaParam.nCfgInx]->checkIsStop())
  689. {//ֹͣ����
  690. Dbg("stop play Image");
  691. return 0;
  692. }
  693. else
  694. entity->m_pImagePlayer[entity->m_mediaParam.nCfgInx]->Close();
  695. }
  696. }
  697. }
  698. return 0;
  699. }
  700. #else
  701. void* StartMediaPlayFunc(void* param)
  702. {
  703. int iRet = -1;
  704. if (NULL == param){
  705. return (void*)&iRet;
  706. }
  707. CLocalMediaPlayEntity* entity = (CLocalMediaPlayEntity*)param;
  708. while (entity->GetPlayFlag())
  709. {
  710. rvcResourceParse_t ResourceList[MAX_LOCAL_MEDIAS] = { 0 };
  711. size_t uCount = entity->m_mediaManage.GetPlayListByLocal(ResourceList, MAX_LOCAL_MEDIAS);
  712. if (0 == uCount){
  713. int64_t playThreadId = 0;
  714. CMediaPlayConfig config = {0};
  715. memcpy(&config, &(entity->m_Videos[entity->m_mediaParam.nCfgInx]), sizeof(CMediaPlayConfig));
  716. config.nPlayCnt = 1; //can be change
  717. config.eMode = LOCALVIDEO;
  718. config.nWndX = entity->m_mediaParam.nWndX;
  719. config.nWndY = entity->m_mediaParam.nWndY;
  720. config.nWndWidth = entity->m_mediaParam.nWndWidth;
  721. config.nWndHeight = entity->m_mediaParam.nWndHeight;
  722. if (IS_DEBUG){
  723. config.bFullScreen = false;
  724. config.bPrimMonitor = true;
  725. }
  726. if (!entity->GetLocalVideoVolume(0, config.nVolume)){
  727. config.nVolume = entity->m_defaultVolum;
  728. }
  729. struct tm* ptm = NULL;
  730. time_t t = time(NULL);
  731. ptm = localtime(&t);
  732. TCHAR strNow[TIME_LEN] = {0};
  733. sprintf(strNow, "%02d:%02d:%02d", ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
  734. if (strcmp(strNow, config.strVideoRunTime_S) < 0 || strcmp(strNow, config.strVideoRunTime_E) >= 0){
  735. Sleep(10000);
  736. continue;
  737. }
  738. if (-1 == entity->m_pMediaPlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config)){
  739. Sleep(60000);
  740. }
  741. }
  742. for (int i = 0; i < uCount && i < MAX_LOCAL_MEDIAS && entity->GetPlayFlag(); i++)
  743. {
  744. //Dbg("ResourceList[%d] address is 0x%0x", i, ResourceList[i]);
  745. int64_t playThreadId = 0;
  746. rvcResourceParse_t item = ResourceList[i];
  747. //Dbg("begin play extend %c:%s, %s", item.type, item.strResourcePath, item.strvideoNames);
  748. if ('V' == item.type)
  749. {//video
  750. CMediaPlayConfig config = {0};
  751. config.bFullScreen = IS_DEBUG ? false : item.fullScreen;
  752. config.bPrimMonitor = IS_DEBUG ? true : item.primMonitor;
  753. config.bSimpleMode = item.simpleMode;
  754. config.eMode = LOCALVIDEO;
  755. config.nFileCnt = 1;
  756. config.nPlayCnt = 1;
  757. config.nPlayInterval = item.playInterval;
  758. // add by ly@2018/07/30
  759. //config.nVolume = IS_DEBUG ? 0 : entity->m_defaultVolum;
  760. if (!entity->GetLocalVideoVolume(0, config.nVolume))
  761. {
  762. config.nVolume = entity->m_defaultVolum;
  763. }
  764. //Dbg("config.nVolume=%d while play local video.", config.nVolume);
  765. config.nWndX = entity->m_mediaParam.nWndX;
  766. config.nWndY = entity->m_mediaParam.nWndY;
  767. config.nWndWidth = entity->m_mediaParam.nWndWidth;
  768. config.nWndHeight = entity->m_mediaParam.nWndHeight;
  769. strncpy(config.strRootPath, item.strResourcePath, strlen(item.strResourcePath));
  770. strncpy(config.strFileNames[0], item.strvideoNames, strlen(item.strvideoNames));
  771. strncpy(config.strVideoRunTime_S, "09:00:00", sizeof(config.strVideoRunTime_S));
  772. strncpy(config.strVideoRunTime_E, "17:30:00", sizeof(config.strVideoRunTime_E));
  773. entity->m_pMediaPlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
  774. Sleep(800);
  775. }
  776. else if ('P' == item.type)
  777. {//play Image
  778. CPicPlayConfig config = {0};
  779. config.bFullScreen = IS_DEBUG ? false : item.fullScreen;
  780. config.bPrimMonitor = IS_DEBUG ? true : item.primMonitor;
  781. config.nFileCnt = 1;
  782. config.nPlayCnt = 1;
  783. config.nPlayInterval = item.playInterval;
  784. config.nWndX = entity->m_mediaParam.nWndX;
  785. config.nWndY = entity->m_mediaParam.nWndY;
  786. config.nWndWidth = entity->m_mediaParam.nWndWidth;
  787. config.nWndHeight = entity->m_mediaParam.nWndHeight;
  788. strncpy(config.strRootPath, item.strResourcePath, strlen(item.strResourcePath));
  789. strncpy(config.strFileNames[0], item.strvideoNames, strlen(item.strvideoNames));
  790. entity->m_pPicturePlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
  791. if (!entity->m_pPicturePlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(&playThreadId)){
  792. Dbg("Create play Image Media Thread Failed!");
  793. iRet = -1;
  794. return (void*)& iRet;
  795. }
  796. else{
  797. Dbg("Image Media Player Thread id is %u.", playThreadId);
  798. }
  799. if (0 == pthread_join(playThreadId, NULL)){
  800. Dbg("pthread join thread id %u success.", playThreadId);
  801. iRet = 0;
  802. }
  803. else {
  804. Dbg("pthread join thread id %u failed for %s.", playThreadId, strerror(errno));
  805. iRet = -1;
  806. }
  807. }
  808. }
  809. }
  810. return (void*)&iRet;
  811. }
  812. #endif // RVC_OS_WIN
  813. void CLocalMediaPlayEntity::StartVideo(int nCfgInx, int nWndX, int nWndY, int nWndWidth, int nWndHeight)
  814. {
  815. if (nCfgInx >= MAX_PLAY_CHANNELS || nCfgInx < 0)
  816. {
  817. Dbg("Invalid CfgInx while StartVideo!");
  818. return;
  819. }
  820. m_mediaParam.nCfgInx = nCfgInx;
  821. m_mediaParam.nWndX = nWndX;
  822. m_mediaParam.nWndY = nWndY;
  823. m_mediaParam.nWndWidth = nWndWidth;
  824. m_mediaParam.nWndHeight = nWndHeight;
  825. #ifdef RVC_OS_WIN // RVC_OS_WIN
  826. if (NULL != m_playThread)
  827. {
  828. WaitForSingleObject(m_playThread, 5000);
  829. m_playThread = NULL;
  830. }
  831. if (NULL == m_playThread)
  832. m_playThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)& MediaPlayThread, this, 0, NULL);
  833. #else
  834. m_badplayflag = true;
  835. int err = pthread_create(&m_uMediaPlayThreadId, NULL, StartMediaPlayFunc, this);
  836. if (0 == err) {
  837. Dbg("create media play thread[%u] success.", m_uMediaPlayThreadId);
  838. }
  839. else {
  840. Dbg("create media play thread failed.");
  841. }
  842. #endif
  843. }
  844. void CLocalMediaPlayEntity::StartAudio(const char *pAudioNames)
  845. {
  846. #ifdef RVC_OS_WIN
  847. static HANDLE audioPlayThread = NULL;
  848. if (audioPlayThread)//�ر����ڲ��ŵ���Ƶ
  849. {
  850. DWORD exitCode = 0;
  851. if (WAIT_TIMEOUT == WaitForSingleObject(audioPlayThread, 50))
  852. {
  853. TerminateThread(audioPlayThread, exitCode);
  854. m_pAudioPlayer->Close();
  855. }
  856. audioPlayThread = NULL;
  857. }
  858. Dbg("Begin StartAudio, and Audio Info is %s.", pAudioNames);
  859. m_pAudioPlayer->PlayLocalAudio(pAudioNames);
  860. Dbg("Succeed to StartAudio, and Audio Info is %s.", pAudioNames);
  861. auto audioRet = GetLocalAudioVolume();
  862. m_pAudioPlayer->SetVolume(audioRet.second);
  863. Dbg("Succeed to set audio volume %d!", audioRet.second);
  864. m_lastPlayAudio = pAudioNames;
  865. audioPlayThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)& CheckAudioThread, this, 0, NULL);
  866. #else
  867. if (m_pMediaAudioPlayer->checkIsPlay()) {
  868. Dbg("current is playing, close it.");
  869. if (0 != m_uMediaPlayThreadId){
  870. m_pMediaAudioPlayer->Close();
  871. m_uMediaPlayThreadId = 0;
  872. Sleep(800);
  873. }
  874. }
  875. m_lastPlayAudio = pAudioNames;
  876. int err = pthread_create(&m_uMediaPlayThreadId, NULL, StartAudioPlayingThreadFunc, this);
  877. if (0 == err) {
  878. Dbg("create audio play thread[%u] success.", m_uMediaPlayThreadId);
  879. }
  880. else {
  881. Dbg("create audio play thread failed.");
  882. }
  883. auto audioRet = GetLocalAudioVolume();
  884. m_pMediaAudioPlayer->SetVolume(audioRet.second);
  885. Dbg("Succeed to set audio volume %d!", audioRet.second);
  886. #endif // RVC_OS_WIN
  887. }
  888. void CLocalMediaPlayEntity::StartImage(int nCfgInx, int nWndX, int nWndY, int nWndWidth, int nWndHeight)
  889. {
  890. if (nCfgInx >= MAX_PLAY_CHANNELS || nCfgInx < 0)
  891. {
  892. Dbg("Invalid CfgInx while StartImage!");
  893. return;
  894. }
  895. #ifdef RVC_OS_WIN
  896. m_pImagePlayer[nCfgInx]->Play(nCfgInx, nWndX, nWndY, nWndWidth, nWndHeight);
  897. #else
  898. m_pPicturePlayer[nCfgInx]->Play(nCfgInx, nWndX, nWndY, nWndWidth, nWndHeight);
  899. #endif // RVC_OS_WIN
  900. Dbg("Succeed to StartImage!");
  901. }
  902. void CLocalMediaPlayEntity::StopVideo(int nCfgInx)
  903. {
  904. if (nCfgInx >= MAX_PLAY_CHANNELS || nCfgInx < 0)
  905. {
  906. Dbg("Invalid CfgInx while StopVideo!");
  907. return;
  908. }
  909. #ifdef RVC_OS_WIN
  910. m_pVideoPlayer[nCfgInx]->Close();
  911. m_pImagePlayer[nCfgInx]->Close();
  912. if (m_playThread)
  913. {
  914. TerminateThread(m_playThread, -1);
  915. m_playThread = NULL;
  916. }
  917. #else
  918. m_pMediaPlayer[nCfgInx]->Close();
  919. m_pPicturePlayer[nCfgInx]->Close();
  920. m_badplayflag = false;
  921. #endif // RVC_OS_WIN
  922. Dbg("Succeed to StopVideo!");
  923. }
  924. void CLocalMediaPlayEntity::StopAudio()
  925. {
  926. #ifdef RVC_OS_WIN
  927. m_pAudioPlayer->Close();
  928. #else
  929. m_pMediaAudioPlayer->Close();
  930. #endif
  931. Dbg("Succeed to StopAudio!");
  932. }
  933. void CLocalMediaPlayEntity::StopImage(int nCfgInx)
  934. {
  935. if (nCfgInx >= MAX_PLAY_CHANNELS || nCfgInx < 0)
  936. {
  937. Dbg("Invalid CfgInx while StopImage!");
  938. return;
  939. }
  940. #ifdef RVC_OS_WIN
  941. m_pImagePlayer[nCfgInx]->Close();
  942. #else
  943. m_pPicturePlayer[nCfgInx]->Close();
  944. #endif // RVC_OS_WIN
  945. Dbg("Succeed to StopImage!");
  946. }
  947. void CLocalMediaPlayEntity::StopAll()
  948. {
  949. StopAudio(); // �ر���Ƶ
  950. for (int i = 0; i < MAX_PLAY_CHANNELS; ++i)
  951. {
  952. StopVideo(i); // �ر���Ƶ
  953. StopImage(i); // �ر�ͼ��
  954. }
  955. }
  956. bool CLocalMediaPlayEntity::GetLocalVideoVolume(int nCfgInx, int &nVolume)
  957. {
  958. //Dbg("get local video volume req.");
  959. CSmartPointer<IConfigInfo> spConfig;
  960. ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_Run, spConfig);
  961. if (Error == Error_Succeed)
  962. {
  963. Error = spConfig->ReadConfigValueInt("LocalVideo", "Volume", nVolume);
  964. if (Error == Error_Succeed && nVolume >= 0 && nVolume <= 100)
  965. {
  966. //Dbg("succeed to get local video volume with nCfgInx:%d, nVolume:%d", nCfgInx, nVolume);
  967. return true;
  968. }
  969. }
  970. Dbg("fail to get local video volume!");
  971. return false;
  972. }
  973. std::pair<bool, int> CLocalMediaPlayEntity::GetLocalAudioVolume()
  974. {
  975. Dbg("get local audio volume req.");
  976. CSmartPointer<IConfigInfo> spConfig;
  977. int nVolume = 0;
  978. ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_Run, spConfig);
  979. if (Error == Error_Succeed)
  980. {
  981. Error = spConfig->ReadConfigValueInt("LocalAudio", "Volume", nVolume);
  982. if (nVolume == 0)
  983. {
  984. nVolume = 50;
  985. spConfig->WriteConfigValueInt("LocalAudio", "Volume", nVolume);
  986. Dbg("read nVolume 0, set default 50");
  987. }
  988. if (Error == Error_Succeed && nVolume >= 0 && nVolume <= 100)
  989. {
  990. Dbg("succeed to get local audio volume with nVolume:%d", nVolume);
  991. return std::make_pair(true, nVolume);
  992. }
  993. }
  994. Dbg("fail to get local audio volume!");
  995. return std::make_pair(false, nVolume);
  996. }
  997. bool CLocalMediaPlayEntity::SetLocalAudioVolume(int nVolume)
  998. {
  999. Dbg("set local video audio req.");
  1000. if (nVolume < 0 || nVolume > 100)
  1001. {
  1002. return false;
  1003. }
  1004. CSmartPointer<IConfigInfo> spConfig;
  1005. ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_Run, spConfig);
  1006. if (Error == Error_Succeed)
  1007. {
  1008. Error = spConfig->WriteConfigValueInt("LocalAudio", "Volume", nVolume);
  1009. if (Error == Error_Succeed)
  1010. {
  1011. Dbg("succeed to set local audio volume with nVolume:%d!", nVolume);
  1012. #ifdef RVC_OS_WIN
  1013. m_pAudioPlayer->SetVolume(nVolume);
  1014. #else
  1015. m_pMediaAudioPlayer->SetVolume(nVolume);
  1016. #endif // RVC_OS_WIN
  1017. return true;
  1018. }
  1019. }
  1020. Dbg("fail to set local video volume!");
  1021. return false;
  1022. }
  1023. bool CLocalMediaPlayEntity::SetLocalVideoVolume(int nCfgInx, int nVolume)
  1024. {
  1025. Dbg("set local video volume req.");
  1026. if (nVolume < 0 || nVolume > 100)
  1027. {
  1028. return false;
  1029. }
  1030. CSmartPointer<IConfigInfo> spConfig;
  1031. ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_Run, spConfig);
  1032. if (Error == Error_Succeed)
  1033. {
  1034. Error = spConfig->WriteConfigValueInt("LocalVideo", "Volume", nVolume);
  1035. if (Error == Error_Succeed)
  1036. {
  1037. Dbg("succeed to set local video volume with nCfgInx:%d, nVolume:%d!", nCfgInx, nVolume);
  1038. for (int i = 0; i < MAX_PLAY_CHANNELS; ++i)
  1039. {
  1040. #ifdef RVC_OS_WIN
  1041. m_pVideoPlayer[i]->SetVolume(nVolume);
  1042. #else
  1043. m_pMediaPlayer[i]->SetVolume(nVolume);
  1044. #endif
  1045. }
  1046. return true;
  1047. }
  1048. }
  1049. Dbg("fail to set local video volume!");
  1050. return false;
  1051. }
  1052. bool CLocalMediaPlayEntity::IsRunConfigExist()
  1053. {
  1054. CSimpleStringA strPath;
  1055. ErrorCodeEnum eErr;
  1056. if ((eErr = GetFunction()->GetPath("RunInfo", strPath)) != Error_Succeed)
  1057. {
  1058. Dbg("get runinfo path failed(%d)", eErr);
  1059. return false;
  1060. }
  1061. #ifdef RVC_OS_WIN
  1062. CSimpleStringA strRuninfoFile;
  1063. strRuninfoFile = CSimpleStringA::Format("%s\\runcfg\\%s.ini", (LPCTSTR)strPath, GetEntityName());
  1064. WIN32_FIND_DATA findData;
  1065. if (FindFirstFileA((LPCTSTR)strRuninfoFile, &findData) != INVALID_HANDLE_VALUE) return true;
  1066. return false;
  1067. #else
  1068. CSimpleStringA strRuninfoFile;
  1069. strRuninfoFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR "%s.ini", (LPCTSTR)strPath, GetEntityName());
  1070. if (ExistsFileA(strRuninfoFile)) {
  1071. return true;
  1072. }
  1073. else{
  1074. return false;
  1075. }
  1076. #endif // RVC_OS_WIN
  1077. }
  1078. void CLocalMediaPlayEntity::OnSelfTest(EntityTestEnum eTestType, CSmartPointer<ITransactionContext> pTransactionContext)
  1079. {
  1080. if (Test_ShakeHand == eTestType)
  1081. {
  1082. pTransactionContext->SendAnswer(Error_Succeed);
  1083. }
  1084. }
  1085. void CLocalMediaPlayEntity::CStringSplit(char *str, char **result, const char *del)
  1086. {
  1087. char *p = strtok(str, del);
  1088. while (p != NULL)
  1089. {
  1090. *result++ = p;
  1091. p = strtok(NULL, del);
  1092. }
  1093. }
  1094. void CLocalMediaPlaySession::Handle_StartPlayVideo(SpReqAnsContext<PlayService_StartPlayVideo_Req, PlayService_StartPlayVideo_Ans>::Pointer ctx)
  1095. {
  1096. 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);
  1097. CSimpleStringA UpdateState = "";
  1098. ErrorCodeEnum Error = m_pEntity->GetFunction()->GetSysVar("UpdateState", UpdateState);
  1099. if (Error == Error_Succeed && "1" == UpdateState)
  1100. {
  1101. Dbg("detect current is upgrade, do not play the media");
  1102. ctx->Answer(Error_Stoped);
  1103. m_pEntity->StopAll();
  1104. return;
  1105. }
  1106. m_pEntity->StartVideo(ctx->Req.CfgInx, ctx->Req.WndX, ctx->Req.WndY, ctx->Req.WndWidth, ctx->Req.WndHeight);
  1107. ctx->Answer(Error_Succeed);
  1108. }
  1109. void CLocalMediaPlaySession::Handle_StartPlayAudio(SpReqAnsContext<PlayService_StartPlayAudio_Req, PlayService_StartPlayAudio_Ans>::Pointer ctx)
  1110. {
  1111. CSimpleStringA AudioNames = CSimpleStringW2A(ctx->Req.AudioNames);
  1112. CSimpleStringA UpdateState = "";
  1113. ErrorCodeEnum Error = m_pEntity->GetFunction()->GetSysVar("UpdateState", UpdateState);
  1114. if (Error == Error_Succeed && "1" == UpdateState)
  1115. {
  1116. Dbg("detect current is upgrade, do not play the media");
  1117. ctx->Answer(Error_Stoped);
  1118. m_pEntity->StopAll();
  1119. return;
  1120. }
  1121. m_pEntity->StartAudio(AudioNames.GetData());
  1122. ctx->Answer(Error_Succeed);
  1123. }
  1124. void CLocalMediaPlaySession::Handle_StartPlayImage(SpReqAnsContext<PlayService_StartPlayImage_Req, PlayService_StartPlayImage_Ans>::Pointer ctx)
  1125. {
  1126. m_pEntity->StartImage(ctx->Req.CfgInx, ctx->Req.WndX, ctx->Req.WndY, ctx->Req.WndWidth, ctx->Req.WndHeight);
  1127. ctx->Answer(Error_Succeed);
  1128. }
  1129. void CLocalMediaPlaySession::Handle_StopPlayVideo(SpReqAnsContext<PlayService_StopPlayVideo_Req, PlayService_StopPlayVideo_Ans>::Pointer ctx)
  1130. {
  1131. Dbg("stop play Video, Index:%d", ctx->Req.CfgInx);
  1132. m_pEntity->StopVideo(ctx->Req.CfgInx);
  1133. ctx->Answer(Error_Succeed);
  1134. }
  1135. void CLocalMediaPlaySession::Handle_StopPlayAudio(SpReqAnsContext<PlayService_StopPlayAudio_Req, PlayService_StopPlayAudio_Ans>::Pointer ctx)
  1136. {
  1137. m_pEntity->StopAudio();
  1138. ctx->Answer(Error_Succeed);
  1139. }
  1140. void CLocalMediaPlaySession::Handle_StopPlayImage(SpReqAnsContext<PlayService_StopPlayImage_Req, PlayService_StopPlayImage_Ans>::Pointer ctx)
  1141. {
  1142. m_pEntity->StopImage(ctx->Req.CfgInx);
  1143. ctx->Answer(Error_Succeed);
  1144. }
  1145. void CLocalMediaPlaySession::OnClose(ErrorCodeEnum)
  1146. {
  1147. LOG_FUNCTION();
  1148. }
  1149. void CLocalMediaPlaySession::Handle_GetLocalVideoVolume( SpReqAnsContext<PlayService_GetLocalVideoVolume_Req, PlayService_GetLocalVideoVolume_Ans>::Pointer ctx )
  1150. {
  1151. int volume = 0;
  1152. if (m_pEntity->GetLocalVideoVolume(ctx->Req.CfgInx, volume))
  1153. {
  1154. ctx->Ans.Volume = volume;
  1155. ctx->Answer(Error_Succeed);
  1156. }
  1157. else
  1158. {
  1159. ctx->Answer(Error_Unexpect);
  1160. }
  1161. }
  1162. void CLocalMediaPlaySession::Handle_SetLocalVideoVolume( SpReqAnsContext<PlayService_SetLocalVideoVolume_Req, PlayService_SetLocalVideoVolume_Ans>::Pointer ctx )
  1163. {
  1164. if (m_pEntity->SetLocalVideoVolume(ctx->Req.CfgInx, ctx->Req.Volume))
  1165. {
  1166. ctx->Answer(Error_Succeed);
  1167. }
  1168. else
  1169. {
  1170. ctx->Answer(Error_Unexpect);
  1171. }
  1172. }
  1173. void CLocalMediaPlaySession::Handle_GetLocalAudioVolume(SpReqAnsContext<PlayService_GetLocalAudioVolume_Req, PlayService_GetLocalAudioVolume_Ans>::Pointer ctx)
  1174. {
  1175. auto audioRet = m_pEntity->GetLocalAudioVolume();
  1176. if (audioRet.first)
  1177. {
  1178. ctx->Ans.Volume = audioRet.second;
  1179. ctx->Answer(Error_Succeed);
  1180. }
  1181. else
  1182. {
  1183. ctx->Answer(Error_Unexpect);
  1184. }
  1185. }
  1186. void CLocalMediaPlaySession::Handle_SetLocalAudioVolume(SpReqAnsContext<PlayService_SetLocalAudioVolume_Req, PlayService_SetLocalAudioVolume_Ans>::Pointer ctx)
  1187. {
  1188. if (m_pEntity->SetLocalAudioVolume(ctx->Req.Volume))
  1189. {
  1190. ctx->Answer(Error_Succeed);
  1191. }
  1192. else
  1193. {
  1194. ctx->Answer(Error_Unexpect);
  1195. }
  1196. }
  1197. SP_BEGIN_ENTITY_MAP()
  1198. SP_ENTITY(CLocalMediaPlayEntity)
  1199. SP_END_ENTITY_MAP()