mod_localmediaplay.cpp 38 KB

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