mod_localmediaplay.cpp 40 KB

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