mod_localmediaplay.cpp 53 KB

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