mod_localmediaplay.cpp 37 KB

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