mod_localmediaplay.cpp 37 KB

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