mod_localmediaplay.cpp 50 KB

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