mod_localmediaplay.cpp 40 KB

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