mod_localmediaplay.cpp 48 KB

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