mod_localmediaplay.cpp 39 KB

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