mod_localmediaplay.cpp 86 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756
  1. #include "stdafx.h"
  2. #include "mod_localmediaplay.h"
  3. #include "LocalMediaPlay_msg_g.h"
  4. #include "y2k_time.h"
  5. #include "fileutil.h"
  6. #include "../../Other/rvcmediacommon/rvc_media_common.h"
  7. #include <stdint.h>
  8. #include "../mod_interactivecontrol/Event.h"
  9. #ifndef RVC_MIN_LOCALPLAYER_TIME
  10. #define RVC_MIN_LOCALPLAYER_TIME 1
  11. #endif
  12. #define DEFAULT_SLEEP_TIME 1000
  13. #define DEFAULT_ADVERT_TYPE 'A'
  14. bool IS_DEBUG = false;
  15. int scanTime = 600;
  16. int removeOldTime = 1800;
  17. #ifndef MAX_LOCAL_MEDIAS
  18. #define MAX_LOCAL_MEDIAS 128
  19. #endif // !MAX_LOCAL_MEDIAS
  20. #ifndef RVC_MIN_LOCALPLAYER_TIME
  21. #define RVC_MIN_LOCALPLAYER_TIME 6
  22. #endif
  23. static uint32_t ConvertStereo2Mono(char* pDstBuf, const uint32_t uDstLen, char* pSrcBuf, uint32_t uSrcLen, uint32_t uBitDeepth)
  24. {
  25. uint32_t uRet = 0;
  26. uint32_t uOneChannelLen = uSrcLen / 2;
  27. uint32_t i = 0;
  28. for (; i < uOneChannelLen / 2 && i < uDstLen / uBitDeepth; i++) {
  29. memcpy((uint16_t*)pDstBuf + i, ((uint32_t*)(pSrcBuf)) + i, uBitDeepth);
  30. }
  31. if (i == uOneChannelLen / 2) {
  32. uRet = uOneChannelLen;
  33. }
  34. return uRet;
  35. }
  36. static uint32_t Transform2Pcm8k(char* pdstbuf, const uint32_t udstlen, char* pcm_441kdata, int idata_size, int ichannels)
  37. {
  38. uint32_t nLen = 0;
  39. int nSkipByte = 5 * ichannels;
  40. int nSourcePos = 0;
  41. char* pcm_8k_data = (char*)pdstbuf;
  42. for (nLen = 0; nSourcePos + 1 < idata_size; nLen = nLen + 2)
  43. {
  44. pcm_8k_data[nLen] = pcm_441kdata[nSourcePos];
  45. pcm_8k_data[nLen + 1] = pcm_441kdata[nSourcePos + 1];
  46. if (nSkipByte == 5 * ichannels) {
  47. nSkipByte = 6 * ichannels;
  48. }
  49. else {
  50. nSkipByte = 5 * ichannels;
  51. }
  52. nSourcePos = nSourcePos + nSkipByte * 2;
  53. }
  54. return nLen;
  55. }
  56. static uint32_t PcmConvert(char* pdstbuf, const uint32_t udstlen, char* pcmsrcdata, int isrclen, int isamplespersec, int ichannels)
  57. {
  58. uint32_t uLen = 0;
  59. if (2 == ichannels) {
  60. if (8000 == isamplespersec) {
  61. uLen = ConvertStereo2Mono(pdstbuf, udstlen, pcmsrcdata, isrclen, 2);
  62. }
  63. else if (44100 == isamplespersec) {
  64. uLen = Transform2Pcm8k(pdstbuf, udstlen, pcmsrcdata, isrclen, 2);
  65. }
  66. }
  67. else {
  68. if (44100 == isamplespersec) {
  69. uLen = Transform2Pcm8k(pdstbuf, udstlen, pcmsrcdata, isrclen, 1);
  70. }
  71. }
  72. return uLen;
  73. }
  74. static void CStringSplit(char* str, char** result, const char* del)
  75. {
  76. char* pdata = NULL;
  77. char* p = NULL;
  78. #ifdef RVC_OS_WIN
  79. p = strtok_s(str, del, &pdata);
  80. #else
  81. p = strtok_r(str, del, &pdata);
  82. #endif // RVC_OS_WIN
  83. while (p != NULL) {
  84. *result++ = p;
  85. #ifdef RVC_OS_WIN
  86. p = strtok_s(NULL, del, &pdata);
  87. #else
  88. p = strtok_r(NULL, del, &pdata);
  89. #endif
  90. }
  91. }
  92. #ifdef RVC_OS_WIN
  93. static inline BOOL IsFileExisted(LPCTSTR lpszSpecifiedPath)
  94. {
  95. auto dwRet = GetFileAttributes(lpszSpecifiedPath);
  96. return (dwRet != INVALID_FILE_ATTRIBUTES) && !(dwRet & FILE_ATTRIBUTE_DIRECTORY);
  97. }
  98. DWORD WINAPI clearOutdata(LPVOID lpv)
  99. {
  100. CLocalMediaPlayEntity* curEntity = (CLocalMediaPlayEntity*)lpv;
  101. Sleep(removeOldTime * 1000);
  102. curEntity->m_mediaManage.clearOutdataResource();
  103. return 0;
  104. }
  105. DWORD WINAPI qryMedia(LPVOID lpv)
  106. {
  107. CLocalMediaPlayEntity* curEntity = (CLocalMediaPlayEntity*)lpv;
  108. Sleep(3000);
  109. while (true){
  110. curEntity->m_mediaManage.InitResourceListByLocal();
  111. Sleep(3600 * 1000);
  112. }
  113. return 0;
  114. }
  115. #else
  116. void* queryMedia(void* param)
  117. {
  118. CLocalMediaPlayEntity* curEntity = (CLocalMediaPlayEntity*)param;
  119. sleep(3);
  120. while (false == curEntity->GetScanExitFlag())
  121. {
  122. curEntity->m_mediaManage.InitResourceListByLocal();
  123. sleep(3600);
  124. }
  125. return 0;
  126. }
  127. void sig_handler(int signum)
  128. {
  129. if (SIGTERM == signum){
  130. int ipid = getpid();
  131. kill(ipid, SIGKILL);
  132. }
  133. }
  134. #endif // RVC_OS_WIN
  135. CLocalMediaPlayEntity::CLocalMediaPlayEntity()
  136. : m_id_seq(0), m_connection(NULL)
  137. {
  138. m_defaultVolum = 50;
  139. #ifdef RVC_OS_WIN
  140. m_pAudioPlayer = NULL;
  141. m_scanThread = NULL;
  142. m_playThread = NULL;
  143. memset(m_pVideoPlayer, 0, sizeof(m_pVideoPlayer));
  144. memset(m_pImagePlayer, 0, sizeof(m_pImagePlayer));
  145. #endif // RVC_OS_WIN
  146. ZeroMemory(&m_mediaParam, sizeof(MediaPlayParam));
  147. m_pMediaAudioPlayer = NULL;
  148. memset(m_pMediaPlayer, 0, sizeof(m_pMediaPlayer));
  149. memset(m_pPicturePlayer, 0, sizeof(m_pPicturePlayer));
  150. #ifdef RVC_OS_WIN
  151. m_scanThreadId = NULL;
  152. m_uMediaPlayThreadId = NULL;
  153. m_uNoticePlayThreadId = NULL;
  154. #else
  155. m_scanThreadId = 0;
  156. m_uMediaPlayThreadId = 0;
  157. m_uNoticePlayThreadId = 0;
  158. #endif // !RVC_OS_WIN
  159. m_badplayflag = true;
  160. m_bgetflag = false;
  161. m_bgetico = false;
  162. m_remote_audio_queue = NULL;
  163. m_pFile = NULL;
  164. m_bRecordPCM = false;
  165. m_iPlayType = 0;
  166. m_bStartRecord = false;
  167. m_leftlen = 0;
  168. m_piclevel = PIC_LOG_ERROR;
  169. m_medialevel = MEDIA_LOG_ERROR;
  170. }
  171. CLocalMediaPlayEntity::~CLocalMediaPlayEntity()
  172. {
  173. SecureClientRelease();
  174. #ifdef RVC_OS_WIN
  175. DWORD exitCode = 0;
  176. if (m_scanThread){
  177. TerminateThread(m_scanThread, exitCode);
  178. m_scanThread = NULL;
  179. }
  180. #else
  181. m_scanexitflag = true;
  182. if (0 == pthread_join(m_scanThreadId, NULL)) {
  183. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("pthread join scanThreadId success.");
  184. }
  185. m_bgetflag = false;
  186. m_bgetico = false;
  187. #endif // RVC_OS_WIN
  188. }
  189. void CLocalMediaPlayEntity::SecureClientRelease()
  190. {
  191. if (NULL != m_connection){
  192. if (m_connection->IsConnectionOK()) {
  193. m_connection->Close();
  194. }
  195. m_connection->DecRefCount();
  196. m_connection = NULL;
  197. }
  198. }
  199. bool CLocalMediaPlayEntity::SecureClientConnect()
  200. {
  201. if (NULL != m_connection && m_connection->IsConnectionOK()) {
  202. return true;
  203. }
  204. SecureClientRelease();
  205. m_connection = new CAdvertSyncConnection(this);
  206. return m_connection->ConnectFromCentralSetting();
  207. }
  208. void CLocalMediaPlayEntity::setMediaPath()
  209. {
  210. CSimpleStringA downloadPath, mediaPath;
  211. GetFunction()->GetPath("Download", downloadPath);
  212. GetFunction()->GetPath("Ad", mediaPath);
  213. m_mediaManage.setDefaultDownloadPath(downloadPath.GetData());
  214. m_mediaManage.setDefaultAddvertPath(mediaPath.GetData());
  215. }
  216. CServerSessionBase* CLocalMediaPlayEntity::OnNewSession(const char* pszRemoteEntityName, const char * pszClass)
  217. {
  218. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%s connected class = %s!", pszRemoteEntityName, pszClass);
  219. return new CLocalMediaPlaySession(this, m_id_seq++);
  220. }
  221. #ifdef RVC_OS_WIN
  222. BOOL CLocalMediaPlayEntity::LoadPlayConfig(CWmpPlayConfig &config, int CfgInx)
  223. {
  224. if (CfgInx >= MAX_PLAY_CHANNELS || CfgInx < 0){
  225. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Invalid CfgInx while LoadConfig!");
  226. return FALSE;
  227. }
  228. if (config.eMode == LOCALAUDIO && CfgInx < m_defaultAudio.size()) {
  229. memcpy(&config, &(m_defaultAudio[CfgInx]), sizeof(CWmpPlayConfig));
  230. }
  231. else if (config.eMode == LOCALVIDEO && CfgInx < m_defaultVideo.size()) {
  232. memcpy(&config, &(m_defaultVideo[CfgInx]), sizeof(CWmpPlayConfig));
  233. }
  234. else {
  235. return FALSE;
  236. }
  237. return TRUE;
  238. }
  239. BOOL CLocalMediaPlayEntity::LoadPlayConfig(CImgPlayConfig &config, int CfgInx)
  240. {
  241. if (CfgInx >= MAX_PLAY_CHANNELS || CfgInx < 0){
  242. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Invalid CfgInx while LoadConfig!");
  243. return FALSE;
  244. }
  245. memcpy(&config, &(m_defaultImg[CfgInx]), sizeof(CImgPlayConfig));
  246. return TRUE;
  247. }
  248. void CLocalMediaPlayEntity::WmpDebug(const char *fmt, ...)
  249. {
  250. va_list arg;
  251. va_start(arg, fmt);
  252. int n = _vscprintf(fmt, arg);
  253. if (n >= 512) {
  254. char* buf = (char*)malloc((size_t)(n + 1));
  255. _vsnprintf(buf, n + 1, fmt, arg);
  256. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", buf);
  257. free(buf);
  258. }
  259. else{
  260. char strlog[512] = {0};
  261. _vsnprintf(strlog, 512, fmt, arg);
  262. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", strlog);
  263. }
  264. va_end(arg);
  265. }
  266. void CLocalMediaPlayEntity::WmpLogEvt(int ievent, const char* strmsg)
  267. {
  268. if (0 == ievent){
  269. LogWarn(Severity_Low, Error_Debug, LOG_EVT_VICE_MONITOR_NOT_EXIST, strmsg);
  270. }
  271. else if(1 == ievent){
  272. LogWarn(Severity_Low, Error_Debug, LOG_EVT_VICE_MONITOR_SET_ERROR, strmsg);
  273. }
  274. }
  275. void CLocalMediaPlayEntity::ImgDebug(const char *fmt, ...)
  276. {
  277. va_list arg;
  278. va_start(arg, fmt);
  279. int n = _vscprintf(fmt, arg);
  280. if (n >= 512) {
  281. char* buf = (char*)malloc((size_t)(n + 1));
  282. _vsnprintf(buf, n + 1, fmt, arg);
  283. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", buf);
  284. free(buf);
  285. }
  286. else{
  287. char strlog[512] = {0};
  288. _vsnprintf(strlog, 512, fmt, arg);
  289. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", strlog);
  290. }
  291. va_end(arg);
  292. }
  293. #endif // RVC_OS_WIN
  294. void CLocalMediaPlayEntity::loadDefaultMedia(bool fNewVersion)
  295. {
  296. if (!fNewVersion) {
  297. #ifdef RVC_OS_WIN
  298. m_defaultImg.clear();
  299. m_defaultAudio.clear();
  300. m_defaultVideo.clear();
  301. #endif // RVC_OS_WIN
  302. }
  303. else {
  304. m_defaultPic.clear();
  305. m_Audios.clear();
  306. m_Videos.clear();
  307. }
  308. // 获取本地媒体根目录
  309. CSimpleStringA strRootPath;
  310. ErrorCodeEnum Error = Error_Succeed;
  311. Error = GetFunction()->GetPath("ADData", strRootPath);
  312. if (Error != Error_Succeed) {
  313. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Fail to get local media root path!");
  314. return;
  315. }
  316. CSmartPointer<IConfigInfo> spConfigCen;
  317. if (Error_Succeed == GetFunction()->OpenConfig(Config_CenterSetting, spConfigCen)) {
  318. IS_DEBUG = false;
  319. do {
  320. int value(0);
  321. spConfigCen->ReadConfigValueInt(GetEntityName(), "runDebug", value);
  322. if (value > 0) {
  323. IS_DEBUG = true;
  324. }
  325. } while (false);
  326. scanTime = 600;
  327. removeOldTime = 1800;
  328. do {
  329. int value(0);
  330. spConfigCen->ReadConfigValueInt(GetEntityName(), "scanTime", value);
  331. if (value > 0) {
  332. scanTime = value;
  333. }
  334. } while (false);
  335. do {
  336. int value(0);
  337. spConfigCen->ReadConfigValueInt(GetEntityName(), "removeOldTime", value);
  338. if (value > 0) {
  339. removeOldTime = value;
  340. }
  341. } while (false);
  342. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("runDebug:%s, scanTime:%d", IS_DEBUG ? "true" : "false", scanTime);
  343. }
  344. CSimpleStringA imgPath = strRootPath + SPLIT_SLASH_STR + "Image" + SPLIT_SLASH_STR;
  345. //Image0
  346. do {
  347. if (!fNewVersion) {
  348. #ifdef RVC_OS_WIN
  349. CImgPlayConfig curImg;
  350. ZeroMemory(&curImg, sizeof(CImgPlayConfig));
  351. strncpy(curImg.strRootPath, (LPCSTR)imgPath, sizeof(curImg.strRootPath));
  352. curImg.bFullScreen = true;
  353. curImg.bPrimMonitor = false;
  354. curImg.nPlayCnt = 0;
  355. curImg.nPlayInterval = 5000;
  356. curImg.nFileCnt = 4;
  357. for (int i = 0; i < curImg.nFileCnt; ++i) {
  358. _snprintf(curImg.strFileNames[i], MAX_PATH, "Ad0/%d.jpg", i);
  359. }
  360. m_defaultImg.push_back(curImg);
  361. #endif
  362. }
  363. else {
  364. CPicPlayConfig curImg1;
  365. ZeroMemory(&curImg1, sizeof(CPicPlayConfig));
  366. strncpy(curImg1.strRootPath, (LPCSTR)imgPath, sizeof(curImg1.strRootPath));
  367. curImg1.bFullScreen = true;
  368. curImg1.bPrimMonitor = false;
  369. curImg1.nPlayCnt = 0;
  370. curImg1.nPlayInterval = 5000;
  371. curImg1.nFileCnt = 4;
  372. for (int i = 0; i < curImg1.nFileCnt; ++i) {
  373. #ifdef RVC_OS_WIN
  374. _snprintf(curImg1.strFileNames[i], MAX_PATH, "Ad0/%d.jpg", i);
  375. #else
  376. snprintf(curImg1.strFileNames[i], MAX_PATH, "Ad0/%d.jpg", i);
  377. #endif
  378. }
  379. m_defaultPic.push_back(curImg1);
  380. }
  381. } while (false);
  382. //Image1
  383. do {
  384. if (!fNewVersion) {
  385. #ifdef RVC_OS_WIN
  386. CImgPlayConfig curImg;
  387. ZeroMemory(&curImg, sizeof(CImgPlayConfig));
  388. strncpy(curImg.strRootPath, (LPCSTR)imgPath, sizeof(curImg.strRootPath));
  389. curImg.bFullScreen = false;
  390. curImg.bPrimMonitor = true;
  391. curImg.nPlayCnt = 6;
  392. curImg.nPlayInterval = 1000;
  393. curImg.nFileCnt = 4;
  394. for (int i = 0; i < curImg.nFileCnt; ++i) {
  395. #ifdef RVC_OS_WIN
  396. _snprintf(curImg.strFileNames[i], MAX_PATH, "Ad1/%d.jpg", i);
  397. #else
  398. snprintf(curImg.strFileNames[i], MAX_PATH, "Ad1/%d.jpg", i);
  399. #endif
  400. }
  401. m_defaultImg.push_back(curImg);
  402. #endif
  403. }
  404. else {
  405. CPicPlayConfig curImg1;
  406. ZeroMemory(&curImg1, sizeof(CPicPlayConfig));
  407. strncpy(curImg1.strRootPath, (LPCSTR)imgPath, sizeof(curImg1.strRootPath));
  408. curImg1.bFullScreen = true;
  409. curImg1.bPrimMonitor = false;
  410. curImg1.nPlayCnt = 6;
  411. curImg1.nPlayInterval = 1000;
  412. curImg1.nFileCnt = 4;
  413. for (int i = 0; i < curImg1.nFileCnt; ++i) {
  414. #ifdef RVC_OS_WIN
  415. _snprintf(curImg1.strFileNames[i], MAX_PATH, "Ad1/%d.jpg", i);
  416. #else
  417. snprintf(curImg1.strFileNames[i], MAX_PATH, "Ad1/%d.jpg", i);
  418. #endif // RVC_OS_WIN
  419. }
  420. m_defaultPic.push_back(curImg1);
  421. }
  422. } while (false);
  423. CSimpleStringA videoPath = strRootPath + SPLIT_SLASH_STR + "Video" + SPLIT_SLASH_STR;
  424. CSimpleStringA strRunTime_S("09:00:00"), strRunTime_E("17:30:00");
  425. //Video0
  426. do {
  427. if (!fNewVersion) {
  428. #ifdef RVC_OS_WIN
  429. CWmpPlayConfig curVideo;
  430. ZeroMemory(&curVideo, sizeof(CWmpPlayConfig));
  431. strcpy(curVideo.strRootPath, (LPCSTR)videoPath);
  432. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("config.strRootPath: %s", curVideo.strRootPath);
  433. curVideo.bFullScreen = true;
  434. curVideo.bPrimMonitor = false;
  435. curVideo.bSimpleMode = true;
  436. curVideo.nPlayCnt = 1;
  437. curVideo.nPlayInterval = 2000;
  438. curVideo.nVolume = 50;
  439. CSmartPointer<IConfigInfo> tempConfig;
  440. Error = GetFunction()->OpenConfig(Config_Run, tempConfig);
  441. if (Error == Error_Succeed) {
  442. Error = tempConfig->ReadConfigValueInt("LocalVideo", "Volume", curVideo.nVolume);
  443. if (Error != Error_Succeed || curVideo.nVolume < 0 || curVideo.nVolume > 100)
  444. curVideo.nVolume = 50;
  445. m_defaultVolum = curVideo.nVolume;
  446. }
  447. strcpy(curVideo.strVideoRunTime_S, (LPCSTR)strRunTime_S);
  448. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("config.strVideoRunTime_S: %s", (LPCSTR)strRunTime_S);
  449. strcpy(curVideo.strVideoRunTime_E, (LPCSTR)strRunTime_E);
  450. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("config.strVideoRunTime_E: %s", (LPCSTR)strRunTime_E);
  451. curVideo.nFileCnt = 1;
  452. strcpy(curVideo.strFileNames[0], "可视柜台欢迎界面.wmv");
  453. m_defaultVideo.push_back(curVideo);
  454. #endif // RVC_OS_WIN
  455. }
  456. else {
  457. CMediaPlayConfig curVideo1 = { 0 };
  458. strcpy(curVideo1.strRootPath, (LPCSTR)videoPath);
  459. curVideo1.bFullScreen = true;
  460. curVideo1.bPrimMonitor = false;
  461. curVideo1.bSimpleMode = true;
  462. curVideo1.nPlayCnt = 1;
  463. curVideo1.nPlayInterval = 2000;
  464. curVideo1.nVolume = 50;
  465. curVideo1.nFileCnt = 1;
  466. strcpy(curVideo1.strFileNames[0], "可视柜台欢迎界面.wmv");
  467. strcpy(curVideo1.strVideoRunTime_S, strRunTime_S.GetData());
  468. strcpy(curVideo1.strVideoRunTime_E, strRunTime_E.GetData());
  469. m_Videos.push_back(curVideo1);
  470. }
  471. } while (false);
  472. //Video1
  473. do {
  474. if (!fNewVersion) {
  475. #ifdef RVC_OS_WIN
  476. CWmpPlayConfig curVideo;
  477. ZeroMemory(&curVideo, sizeof(CWmpPlayConfig));
  478. strcpy(curVideo.strRootPath, (LPCSTR)videoPath);
  479. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("config.strRootPath: %s", curVideo.strRootPath);
  480. curVideo.bFullScreen = true;
  481. curVideo.bPrimMonitor = false;
  482. curVideo.bSimpleMode = true;
  483. curVideo.nPlayCnt = 0;
  484. curVideo.nPlayInterval = 10000;
  485. curVideo.nVolume = 50;
  486. CSmartPointer<IConfigInfo> tempConfig;
  487. Error = GetFunction()->OpenConfig(Config_Run, tempConfig);
  488. if (Error == Error_Succeed) {
  489. Error = tempConfig->ReadConfigValueInt("LocalVideo", "Volume", curVideo.nVolume);
  490. if (Error != Error_Succeed || curVideo.nVolume < 0 || curVideo.nVolume > 100)
  491. curVideo.nVolume = 50;
  492. m_defaultVolum = curVideo.nVolume;
  493. }
  494. strcpy(curVideo.strVideoRunTime_S, (LPCSTR)strRunTime_S);
  495. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("config.strVideoRunTime_S: %s", (LPCSTR)strRunTime_S);
  496. strcpy(curVideo.strVideoRunTime_E, (LPCSTR)strRunTime_E);
  497. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("config.strVideoRunTime_E: %s", (LPCSTR)strRunTime_E);
  498. curVideo.nFileCnt = 1;
  499. strcpy(curVideo.strFileNames[0], "存款保险标识0418.wmv");
  500. m_defaultVideo.push_back(curVideo);
  501. #endif // RVC_OS_WIN
  502. }
  503. else {
  504. CMediaPlayConfig curVideo1 = { 0 };
  505. strcpy(curVideo1.strRootPath, (LPCSTR)videoPath);
  506. curVideo1.bFullScreen = true;
  507. curVideo1.bPrimMonitor = false;
  508. curVideo1.bSimpleMode = true;
  509. curVideo1.nPlayCnt = 0;
  510. curVideo1.nPlayInterval = 10000;
  511. curVideo1.nVolume = 50;
  512. curVideo1.nFileCnt = 1;
  513. strcpy(curVideo1.strFileNames[0], "存款保险标识0418.wmv");
  514. strcpy(curVideo1.strVideoRunTime_S, strRunTime_S.GetData());
  515. strcpy(curVideo1.strVideoRunTime_E, strRunTime_E.GetData());
  516. m_Videos.push_back(curVideo1);
  517. }
  518. } while (false);
  519. CSimpleStringA audioPath = strRootPath + "/Audio/";
  520. m_AudioPath = audioPath;
  521. //Audio
  522. do {
  523. if (!fNewVersion) {
  524. #ifdef RVC_OS_WIN
  525. CWmpPlayConfig curAudio;
  526. ZeroMemory(&curAudio, sizeof(CWmpPlayConfig));
  527. strcpy(curAudio.strRootPath, (LPCSTR)audioPath);
  528. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("config.strRootPath: %s", curAudio.strRootPath);
  529. curAudio.nPlayCnt = 1;
  530. curAudio.nPlayInterval = 5000;
  531. auto audioRet = GetLocalAudioVolume();
  532. if (audioRet.first) {
  533. curAudio.nVolume = audioRet.second;
  534. }
  535. else {
  536. curAudio.nVolume = m_defaultVolum;
  537. }
  538. m_defaultAudio.push_back(curAudio);
  539. #endif
  540. }
  541. else {
  542. CMediaPlayConfig curAudio1 = { 0 };
  543. strcpy(curAudio1.strRootPath, (LPCSTR)audioPath);
  544. curAudio1.nPlayCnt = 1;
  545. curAudio1.nPlayInterval = 5000;
  546. auto audioRet = GetLocalAudioVolume();
  547. if (audioRet.first) {
  548. curAudio1.nVolume = audioRet.second;
  549. }
  550. else {
  551. curAudio1.nVolume = m_defaultVolum;
  552. }
  553. m_Audios.push_back(curAudio1);
  554. }
  555. } while (false);
  556. }
  557. int CLocalMediaPlayEntity::LoadPlayConfig(CMediaPlayConfig& config, int CfgInx)
  558. {
  559. if (CfgInx >= MAX_PLAY_CHANNELS || CfgInx < 0){
  560. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Invalid CfgInx while LoadConfig!");
  561. return -1;
  562. }
  563. if (config.eMode == LOCALAUDIO && CfgInx < m_Audios.size()){
  564. memcpy(&config, &(m_Audios[CfgInx]), sizeof(CMediaPlayConfig));
  565. }
  566. else if (config.eMode == LOCALVIDEO && CfgInx < m_Videos.size()){
  567. memcpy(&config, &(m_Videos[CfgInx]), sizeof(CMediaPlayConfig));
  568. }
  569. else {
  570. return -1;
  571. }
  572. return 0;
  573. }
  574. int CLocalMediaPlayEntity::LoadPlayConfig(CPicPlayConfig& config, int CfgInx)
  575. {
  576. if (CfgInx >= MAX_PLAY_CHANNELS || CfgInx < 0){
  577. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Invalid CfgInx while LoadConfig!");
  578. return -1;
  579. }
  580. memcpy(&config, &(m_defaultPic[CfgInx]), sizeof(CPicPlayConfig));
  581. return 0;
  582. }
  583. void CLocalMediaPlayEntity::Debug(media_loglevel log_level, const char* fmt, ...)
  584. {
  585. if (log_level >= m_medialevel){
  586. va_list arg;
  587. va_start(arg, fmt);
  588. int n = vsnprintf(NULL, 0, fmt, arg);
  589. if (n >= MAX_PATH) {
  590. char* buf = (char*)malloc((size_t)(n + 1));
  591. vsnprintf(buf, n + 1, fmt, arg);
  592. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", buf);
  593. free(buf);
  594. }
  595. else {
  596. char strlog[MAX_PATH] = { 0 };
  597. vsnprintf(strlog, MAX_PATH, fmt, arg);
  598. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", strlog);
  599. }
  600. va_end(arg);
  601. }
  602. }
  603. void CLocalMediaPlayEntity::PicDebug(pic_loglevel log_level, const char* fmt, ...)
  604. {
  605. if (log_level >= m_piclevel){
  606. va_list arg;
  607. va_start(arg, fmt);
  608. int n = vsnprintf(NULL, 0, fmt, arg);
  609. if (n >= MAX_PATH) {
  610. char* buf = (char*)malloc((size_t)(n + 1));
  611. vsnprintf(buf, n + 1, fmt, arg);
  612. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", buf);
  613. free(buf);
  614. }
  615. else {
  616. char strlog[MAX_PATH] = { 0 };
  617. vsnprintf(strlog, MAX_PATH, fmt, arg);
  618. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", strlog);
  619. }
  620. va_end(arg);
  621. }
  622. }
  623. void CLocalMediaPlayEntity::MediaPlayFinished(int iMediaType)
  624. {
  625. if (0 == iMediaType) {
  626. AudioPlayRet ret;
  627. ret.AudioNames = m_lastPlayAudio.c_str();
  628. ret.ret = true;
  629. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("stop play audio %s success.", ret.AudioNames.GetData());
  630. if (false == m_buserstopaudio) {
  631. SpSendBroadcast(GetFunction(), eMsg_AudioPlayRet, eMsgSig_AudioPlayRet, ret);
  632. }
  633. else {
  634. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("user stop, not broadcast!");
  635. }
  636. }
  637. else {
  638. VideoPlayRet ret;
  639. ret.VideoNames = m_lastPlayVideo.c_str();
  640. ret.ret = true;
  641. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("stop play video notice %s success.", ret.VideoNames.GetData());
  642. SpSendBroadcast(GetFunction(), eMsg_VideoPlayRet, eMsgSig_VideoPlayRet, ret);
  643. }
  644. }
  645. int CLocalMediaPlayEntity::GetMediaPlayerIcoPath(char* strPath, size_t uLen)
  646. {
  647. return GetPlayerIcoPath(strPath, uLen);
  648. }
  649. int CLocalMediaPlayEntity::GetAudioOutDevName(char* strDev, size_t uLen)
  650. {
  651. int iRet = -1;
  652. int idatalen = m_strAudioOutDev.GetLength();
  653. if (uLen > idatalen && idatalen > 0) {
  654. memcpy(strDev, m_strAudioOutDev.GetData(), idatalen);
  655. iRet = 0;
  656. if (false == m_bgetflag) {
  657. m_bgetflag = true;
  658. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d audio Out Device Name is %s.", __FUNCTION__, __LINE__, strDev);
  659. }
  660. }
  661. return iRet;
  662. }
  663. int CLocalMediaPlayEntity::PlayingAudioDataCallback(audio_param_t* param, const void* input, unsigned long uaudiolen)
  664. {
  665. int iRet = -1;
  666. if (0 != m_iPlayType && m_bStartRecord) {
  667. if (false == m_bloged) {
  668. char strmsg[MAX_PATH * 2] = { 0 };
  669. #ifdef RVC_OS_WIN
  670. _snprintf(strmsg, MAX_PATH * 2, "audio param target (%d channels, %d Hz, channel_layout(%d), frame_size(%d), bytes_per_sec(%d), audio format(%d)).", param->channels, param->freq, param->channel_layout, param->frame_size, param->bytes_per_sec, param->fmt);
  671. #else
  672. snprintf(strmsg, MAX_PATH * 2, "audio param target (%d channels, %d Hz, channel_layout(%d), frame_size(%d), bytes_per_sec(%d), audio format(%d)).", param->channels, param->freq, param->channel_layout, param->frame_size, param->bytes_per_sec, param->fmt);
  673. #endif // RVC_OS_WIN
  674. m_bloged = true;
  675. LogWarn(Severity_Low, Error_Debug, LOG_EVT_PLAYING_AUDIO_INFOS, strmsg);
  676. }
  677. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d uaudiolen:%d", __FUNCTION__, __LINE__, uaudiolen);
  678. //AV_SAMPLE_FMT_S16 == 1
  679. if (1 == param->fmt) {
  680. int isingle_audioframe_len = param->bytes_per_sec/50;
  681. int ioffset = 0;
  682. int icount = (uaudiolen + m_leftlen) / isingle_audioframe_len;
  683. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d icount:%d, isingle_audioframe_len = %d.", __FUNCTION__, __LINE__, icount, isingle_audioframe_len);
  684. if (icount > 0) {
  685. for (int i = 0; i < icount; i++) {
  686. audio_frame frm;
  687. char* straudio = new char[isingle_audioframe_len];
  688. if (m_leftlen > 0){
  689. memcpy(straudio, m_audiobuffer, m_leftlen);
  690. memcpy(straudio + m_leftlen, (char*)input, isingle_audioframe_len - m_leftlen);
  691. ioffset += (isingle_audioframe_len - m_leftlen);
  692. m_leftlen = 0;
  693. }
  694. else{
  695. memcpy(straudio, (char*)input + ioffset, isingle_audioframe_len);
  696. ioffset += isingle_audioframe_len;
  697. }
  698. frm.bitspersample = 16;
  699. frm.format = param->fmt;
  700. frm.data = straudio;
  701. frm.framesize = isingle_audioframe_len;
  702. frm.nchannels = param->channels;
  703. frm.samplespersec = param->freq;
  704. frm.iseriesnumber = m_iseriesnumber++;
  705. if (1 == frm.nchannels && 8000 == frm.samplespersec){
  706. if (!m_remote_audio_queue->InsertAudio(&frm)) {
  707. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("InsertAudio failed! frameCount:%d", frm.framesize);
  708. }
  709. else {
  710. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d InsertAudio(series number = %d) success and framesize = %d.", __FUNCTION__, __LINE__, frm.iseriesnumber, frm.framesize);
  711. if (m_bRecordPCM && m_pFile){
  712. fwrite(frm.data, isingle_audioframe_len, 1, m_pFile);
  713. }
  714. }
  715. }
  716. else{
  717. char strsingle[RVC_AUDIO_LEN*2] = {0};
  718. uint32_t uLen = PcmConvert(strsingle, RVC_AUDIO_LEN*2, straudio, isingle_audioframe_len, frm.samplespersec, frm.nchannels);
  719. frm.data = strsingle;
  720. frm.framesize = RVC_AUDIO_LEN;
  721. frm.nchannels = 1;
  722. if (!m_remote_audio_queue->InsertAudio(&frm)) {
  723. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("InsertAudio failed! frameCount:%d", frm.framesize);
  724. }
  725. }
  726. delete []straudio;
  727. }
  728. memset(m_audiobuffer, 0, RVC_AUDIO_BUFFER_LEN);
  729. int ileftaudio = uaudiolen - ioffset;
  730. memcpy(m_audiobuffer, (char*)input + ioffset, ileftaudio);
  731. m_leftlen = ileftaudio;
  732. }
  733. else {
  734. memcpy(m_audiobuffer + m_leftlen, (char*)input , uaudiolen);
  735. m_leftlen += uaudiolen;
  736. }
  737. iRet = 0;
  738. }
  739. }
  740. return iRet;
  741. }
  742. int CLocalMediaPlayEntity::GetPicPlayerIcoPath(char* strPath, size_t uLen)
  743. {
  744. return GetPlayerIcoPath(strPath, uLen);
  745. }
  746. bool CLocalMediaPlayEntity::GetPlayFlag()
  747. {
  748. return m_badplayflag;
  749. }
  750. bool CLocalMediaPlayEntity::GetScanExitFlag()
  751. {
  752. return m_scanexitflag;
  753. }
  754. DeviceTypeEnum CLocalMediaPlayEntity::GetDeviceType()
  755. {
  756. return m_eDeviceType;
  757. }
  758. int CLocalMediaPlayEntity::GetPlayerIcoPath(char* strPath, size_t uLen)
  759. {
  760. int iRet = -1;
  761. if (NULL == strPath) {
  762. return iRet;
  763. }
  764. CSimpleStringA csBinPath;
  765. ErrorCodeEnum eErrPath = GetFunction()->GetPath("Bin", csBinPath);
  766. if (eErrPath != Error_Succeed) {
  767. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("GetBasePath failed (%d).", eErrPath);
  768. return iRet;
  769. }
  770. CSimpleStringA szIcoName("rvc_media_player_64px.bmp");
  771. szIcoName = csBinPath + SPLIT_SLASH_STR + szIcoName;
  772. if (m_bgetico == false) {
  773. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("media player ico full path is %s.", szIcoName.GetData());
  774. m_bgetico = true;
  775. }
  776. if (uLen > szIcoName.GetLength()) {
  777. memcpy(strPath, szIcoName.GetData(), szIcoName.GetLength());
  778. iRet = 0;
  779. m_bgetico = true;
  780. }
  781. return iRet;
  782. }
  783. int CLocalMediaPlayEntity::GetAudioOutDev()
  784. {
  785. int iRet = -1;
  786. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  787. CSmartPointer<IConfigInfo> spRootConfig;
  788. ErrorCodeEnum Error = spFunction->OpenConfig(Config_Root, spRootConfig);
  789. if (Error == Error_Succeed) {
  790. SpIniMappingTable table;
  791. table.AddEntryString("audio", "handfree_out_dev", m_strAudioOutDev, "$");
  792. Error = table.Load(spRootConfig);
  793. if (Error == Error_Succeed) {
  794. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Audio Out Device name is %s.", m_strAudioOutDev.GetData());
  795. iRet = 0;
  796. }
  797. }
  798. return iRet;
  799. }
  800. ErrorCodeEnum CLocalMediaPlayEntity::LoadEntityConfig()
  801. {
  802. SpIniMappingTable table;
  803. int iPlayType = 0;
  804. int iMediaLogLevel = (int)MEDIA_LOG_ERROR;
  805. int iPicLogLevel = (int)PIC_LOG_ERROR;
  806. table.AddEntryInt("LocalMediaPlay", "PlayType", iPlayType, 0);
  807. table.AddEntryInt("LocalMediaPlay", "MediaLevel", iMediaLogLevel, (int)MEDIA_LOG_ERROR);
  808. table.AddEntryInt("LocalMediaPlay", "PicLevel", iPicLogLevel, (int)PIC_LOG_ERROR);
  809. CSmartPointer<IConfigInfo> spConfig;
  810. ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_CenterSetting, spConfig);
  811. if (Error == Error_Succeed) {
  812. Error = table.Load(spConfig);
  813. if (Error_Succeed == Error){
  814. m_iPlayType = iPlayType;
  815. if (iMediaLogLevel <= MEDIA_LOG_ERROR && iMediaLogLevel > 0){
  816. m_medialevel = (media_loglevel)iMediaLogLevel;
  817. }
  818. if (iPicLogLevel <= PIC_LOG_ERROR && iPicLogLevel > 0) {
  819. m_piclevel = (pic_loglevel)iPicLogLevel;
  820. }
  821. }
  822. }
  823. #ifdef RVC_OS_LINUX
  824. m_iPlayType = 1;
  825. #endif // RVC_OS_LINUX
  826. return Error;
  827. }
  828. void CLocalMediaPlayEntity::OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID, const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  829. const DWORD dwSysError, const DWORD dwUserCode, const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  830. const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage, const linkContext &pLinkInfo)
  831. {
  832. if (LOG_EVT_SELFCHECK_IEBROWSER_IDLE == dwUserCode){
  833. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("IEBrowser to idle, stop all media!");
  834. StopAll();
  835. }
  836. else if(LOG_EVT_UI_STARTREMOTERECORD == dwUserCode){
  837. if (0 != m_iPlayType){
  838. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Start remote record.");
  839. HandleRemoteRecord(pszMessage);
  840. }
  841. }
  842. else if (LOG_EVT_UI_STOPREMOTERECORD == dwUserCode) {
  843. if (0 != m_iPlayType){
  844. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Stop remote record.");
  845. m_bStartRecord = false;
  846. m_iseriesnumber = 0;
  847. m_leftlen = 0;
  848. if (NULL != m_remote_audio_queue) {
  849. delete m_remote_audio_queue;
  850. m_remote_audio_queue = NULL;
  851. }
  852. if (m_pFile) {
  853. fclose(m_pFile);
  854. m_pFile = NULL;
  855. }
  856. }
  857. }
  858. }
  859. void CLocalMediaPlayEntity::OnPreStart(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext)
  860. {
  861. ErrorCodeEnum Error = __OnStart(Error_Succeed);
  862. pTransactionContext->SendAnswer(Error);
  863. }
  864. ErrorCodeEnum CLocalMediaPlayEntity::__OnStart(ErrorCodeEnum preOperationError)
  865. {
  866. SetLogFlag(false);
  867. SetLocalLogFlag(false);
  868. SetLocalPicLogFlag(false);
  869. m_eDeviceType = RvcGetDeviceType();
  870. if (Error_Succeed == LoadEntityConfig()){
  871. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("LoadEntityConfig success, and media play type is %d, media log level is %d, picture log level is %d.", m_iPlayType, (int)m_medialevel, (int)m_piclevel);
  872. }
  873. return Error_Succeed;
  874. }
  875. void CLocalMediaPlayEntity::OnStarted()
  876. {
  877. LogEvent(Severity_Middle, LOG_EVT_MOD_LOCALPLAYER_STARTED_SUCCESS, "local meida play entity started successfully.");
  878. GetAudioOutDev();
  879. for (int i = 0; i != MAX_PLAY_CHANNELS; ++i)
  880. {
  881. #ifdef RVC_OS_WIN
  882. m_pVideoPlayer[i] = new Clibwmpplayer(this);
  883. m_pImagePlayer[i] = new Clibimgplayer(this);
  884. #endif
  885. mediaplayer_init();
  886. m_pMediaPlayer[i] = new Clibmediaplayer(this);
  887. m_pPicturePlayer[i] = new Clibpictureplayer(this);
  888. }
  889. m_pMediaAudioPlayer = new Clibmediaplayer(this);
  890. #ifdef RVC_OS_WIN
  891. m_pAudioPlayer = new Clibwmpplayer(this);
  892. #else
  893. signal(SIGTERM, sig_handler);
  894. #endif // RVC_OS_WIN
  895. if (!IsRunConfigExist()){
  896. SetLocalVideoVolume(0, 50);
  897. SetLocalAudioVolume(50);
  898. }
  899. //setMediaPath();
  900. loadDefaultMedia(0 != m_iPlayType);
  901. GetFunction()->SubscribeLog(m_SubIDIEIdle, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_SELFCHECK_IEBROWSER_IDLE, NULL, false);
  902. GetFunction()->SubscribeLog(m_SubIDStartRecord, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTREMOTERECORD, NULL, false);
  903. GetFunction()->SubscribeLog(m_SubIDStopRecord, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPREMOTERECORD, NULL, false);
  904. #ifdef RVC_OS_WIN
  905. m_scanThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)& qryMedia, this, 0, NULL);
  906. if (NULL != m_scanThread)
  907. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create qryMeia thread success, %d.", m_scanThread);
  908. #else
  909. int err = pthread_create(&m_scanThreadId, NULL, queryMedia, this);
  910. if (0 == err) {
  911. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create queryMedia thread success, %u.", m_scanThreadId);
  912. }
  913. else {
  914. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create queryMedia thread failed.");
  915. }
  916. GetPcmRecordFlag();
  917. #endif // RVC_OS_WIN
  918. }
  919. void CLocalMediaPlayEntity::OnPreClose(EntityCloseCauseEnum eCloseCause, CSmartPointer<ITransactionContext> pTransactionContext)
  920. {
  921. ErrorCodeEnum Error = __OnClose(Error_Succeed);
  922. pTransactionContext->SendAnswer(Error);
  923. }
  924. ErrorCodeEnum CLocalMediaPlayEntity::__OnClose(ErrorCodeEnum preOperationError)
  925. {
  926. for (int i = 0; i != MAX_PLAY_CHANNELS; ++i)
  927. {
  928. #ifdef RVC_OS_WIN
  929. delete m_pVideoPlayer[i];
  930. m_pVideoPlayer[i] = NULL;
  931. delete m_pImagePlayer[i];
  932. m_pImagePlayer[i] = NULL;
  933. #endif // RVC_OS_WIN
  934. delete m_pMediaPlayer[i];
  935. m_pMediaPlayer[i] = NULL;
  936. delete m_pPicturePlayer[i];
  937. m_pPicturePlayer[i] = NULL;
  938. }
  939. #ifdef RVC_OS_WIN
  940. delete m_pAudioPlayer;
  941. m_pAudioPlayer = NULL;
  942. #endif
  943. delete m_pMediaAudioPlayer;
  944. m_pMediaAudioPlayer = NULL;
  945. GetFunction()->UnsubscribeLog(m_SubIDIEIdle);
  946. GetFunction()->UnsubscribeLog(m_SubIDStartRecord);
  947. GetFunction()->UnsubscribeLog(m_SubIDStopRecord);
  948. // 释放播放对象
  949. if (0 != m_iPlayType){
  950. mediaplayer_term();
  951. }
  952. return Error_Succeed;
  953. }
  954. ErrorCodeEnum CLocalMediaPlayEntity::GetPcmRecordFlag()
  955. {
  956. CSmartPointer<IConfigInfo> spConfig;
  957. SpIniMappingTable table;
  958. ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_CenterSetting, spConfig);
  959. if (Error == Error_Succeed){
  960. table.AddEntryBoolean("SalesRecorder", "IsRecordPCM", m_bRecordPCM, false);
  961. Error = table.Load(spConfig);
  962. }
  963. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("record pcm flag is %s.", m_bRecordPCM ? "true" : "false");
  964. return Error;
  965. }
  966. ErrorCodeEnum CLocalMediaPlayEntity::HandleRemoteRecord(const char* pszMessage)
  967. {
  968. ErrorCodeEnum Error = Error_Succeed;
  969. m_bStartRecord = true;
  970. memset(m_audiobuffer, 0, RVC_AUDIO_LEN);
  971. m_leftlen = 0;
  972. m_remote_audio_queue = new Clibaudioqueue(REC_COMMON_REMOTEAUDIO_SHM_QUEUE);
  973. m_iseriesnumber = 0;
  974. m_bloged = false;
  975. if (true == m_bRecordPCM){
  976. char strSwiftName[MAX_PATH] = { 0 };
  977. if (NULL != pszMessage) {
  978. size_t ulen = strlen(pszMessage);
  979. char* tmp = new char[ulen + 1];
  980. memset(tmp, 0, ulen + 1);
  981. memcpy(tmp, pszMessage, ulen);
  982. char* result[16] = { 0 };
  983. auto arr1 = CSimpleStringA2W(tmp).Split('@');
  984. auto arr2 = CAutoArray<CSimpleStringA>(arr1.GetCount());
  985. for (int i = 0; i < arr1.GetCount(); ++i) {
  986. arr2[i] = CSimpleStringW2A(arr1[i]);
  987. result[i] = const_cast<LPSTR>(arr2[i].GetData());
  988. }
  989. if (arr1.GetCount() > 4) {
  990. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("record swift number is %s.", result[4]);
  991. #ifdef RVC_OS_WIN
  992. _snprintf(strSwiftName, MAX_PATH, "%s", result[4]);
  993. #else
  994. snprintf(strSwiftName, MAX_PATH, "%s", result[4]);
  995. #endif // RVC_OS_WIN
  996. }
  997. delete tmp;
  998. tmp = NULL;
  999. }
  1000. char strName[MAX_PATH] = { 0 };
  1001. CSimpleStringA strTempDir;
  1002. if (Error_Succeed == GetFunction()->GetPath("Temp", strTempDir)) {
  1003. #ifdef RVC_OS_WIN
  1004. _snprintf(strName, MAX_PATH, "%s/remote_audio_notice_%s.pcm", strTempDir.GetData(), strSwiftName);
  1005. #else
  1006. snprintf(strName, MAX_PATH, "%s/remote_audio_notice_%s.pcm", strTempDir.GetData(), strSwiftName);
  1007. #endif
  1008. }
  1009. else {
  1010. #ifdef RVC_OS_WIN
  1011. _snprintf(strName, MAX_PATH, "remote_audio_notice_%s.pcm", strSwiftName);
  1012. #else
  1013. snprintf(strName, MAX_PATH, "remote_audio_notice_%s.pcm", strSwiftName);
  1014. #endif
  1015. }
  1016. m_pFile = fopen(strName, "wb+");
  1017. if (NULL != m_pFile) {
  1018. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("fopen %s success.", strName);
  1019. }
  1020. else {
  1021. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("fopen %s failed.", strName);
  1022. }
  1023. }
  1024. return Error;
  1025. }
  1026. #ifdef RVC_OS_WIN
  1027. DWORD WINAPI CheckAudioThread(LPVOID param)
  1028. {
  1029. CLocalMediaPlayEntity *entity = (CLocalMediaPlayEntity*)param;
  1030. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Begin CheckAudioThread");
  1031. HANDLE playEndEvent = NULL;
  1032. if (!entity->m_pAudioPlayer->checkIsPlay(playEndEvent)){
  1033. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Create play audio Media Thread Failed!");
  1034. return 0;
  1035. }
  1036. BOOL bPlayFinished = FALSE;
  1037. for (;;) {
  1038. DWORD dwRet = WaitForSingleObject(playEndEvent, 100);
  1039. if (dwRet == WAIT_OBJECT_0) { // exit
  1040. bPlayFinished = TRUE;
  1041. break;
  1042. }
  1043. else { // timeout
  1044. if (entity->m_pAudioPlayer->checkIsStop()){
  1045. break;
  1046. }
  1047. }
  1048. }
  1049. entity->m_pAudioPlayer->Close();
  1050. if (bPlayFinished){
  1051. AudioPlayRet ret;
  1052. ret.AudioNames = entity->m_lastPlayAudio.c_str();
  1053. ret.ret = true;
  1054. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("stop play audio %s success", ret.AudioNames);
  1055. SpSendBroadcast(entity->GetFunction(), eMsg_AudioPlayRet, eMsgSig_AudioPlayRet, ret);
  1056. }
  1057. entity->m_lastPlayAudio.clear();
  1058. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("End CheckAudioThread");
  1059. return 0;
  1060. }
  1061. DWORD WINAPI StartAudioPlayingThreadFunc(LPVOID param)
  1062. {
  1063. CLocalMediaPlayEntity* entity = (CLocalMediaPlayEntity*)param;
  1064. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Enter StartAudioPlayingThreadFunc");
  1065. const char* pAudioNames = entity->m_lastPlayAudio.c_str();
  1066. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Begin StartAudio, and Audio Info is %s.", pAudioNames);
  1067. if (0 == entity->m_pMediaAudioPlayer->PlayLocalAudio(pAudioNames)) {
  1068. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Succeed to StartAudio, and Audio Info is %s.", pAudioNames);
  1069. }
  1070. else{
  1071. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("StartAudio failed, for %s is not exist.", pAudioNames);
  1072. }
  1073. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Leave StartAudioPlayingThreadFunc");
  1074. entity->m_uMediaPlayThreadId = NULL;
  1075. return 0;
  1076. }
  1077. DWORD WINAPI NoticePlayThread(LPVOID param)
  1078. {
  1079. CLocalMediaPlayEntity *entity = (CLocalMediaPlayEntity*)param;
  1080. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Begin NoticePlayThread");
  1081. HANDLE playEndEvent = NULL;
  1082. if (!entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(playEndEvent)){
  1083. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Get notice play end event failed!");
  1084. return 0;
  1085. }
  1086. BOOL bPlayFinished = FALSE;
  1087. for (;;) {
  1088. DWORD dwRet = WaitForSingleObject(playEndEvent, 100);
  1089. if (dwRet == WAIT_OBJECT_0) { // exit
  1090. bPlayFinished = TRUE;
  1091. break;
  1092. }
  1093. else { // timeout
  1094. if (entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->checkIsStop()){
  1095. break;
  1096. }
  1097. }
  1098. }
  1099. entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->Close();
  1100. if (bPlayFinished){
  1101. VideoPlayRet ret;
  1102. ret.VideoNames = entity->m_lastPlayVideo.c_str();
  1103. ret.ret = true;
  1104. SpSendBroadcast(entity->GetFunction(), eMsg_VideoPlayRet, eMsgSig_VideoPlayRet, ret);
  1105. char strmsg[MAX_PATH] = {0};
  1106. _snprintf(strmsg, MAX_PATH, "notice %s play finished.", ret.VideoNames);
  1107. LogWarn(Severity_Low, Error_Debug, LOG_EVT_NOTICE_PLAY_FINISHED, strmsg);
  1108. }
  1109. else{
  1110. char strinfo[MAX_PATH] = {0};
  1111. _snprintf(strinfo, MAX_PATH, "notice %s play early terminate.", entity->m_lastPlayVideo.c_str());
  1112. LogWarn(Severity_Low, Error_Debug, LOG_EVT_NOTICE_PLAY_EARLY_TERM, strinfo);
  1113. }
  1114. entity->m_lastPlayVideo.clear();
  1115. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("End NoticePlayThread");
  1116. return 0;
  1117. }
  1118. static bool IsValidPlayTime(CWmpPlayConfig config)
  1119. {
  1120. bool bRet = true;
  1121. SYSTEMTIME st;
  1122. GetLocalTime(&st);
  1123. char strNow[MAX_PATH] = {0};
  1124. _snprintf(strNow, MAX_PATH, "%02d:%02d:%02d", st.wHour, st.wMinute, st.wSecond);
  1125. if (strcmp(strNow, config.strVideoRunTime_S) < 0 || strcmp(strNow, config.strVideoRunTime_E) >= 0) {
  1126. bRet = false;
  1127. }
  1128. return bRet;
  1129. }
  1130. DWORD WINAPI MediaPlayThread(LPVOID param)
  1131. {
  1132. CLocalMediaPlayEntity *entity = (CLocalMediaPlayEntity*)param;
  1133. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Enter MediaPlayThread.");
  1134. while (entity->GetPlayFlag())
  1135. {
  1136. vector<ResourceParse> curParse;
  1137. entity->m_mediaManage.GetPlayListByLocal(curParse);
  1138. unsigned int ustart_time = y2k_time_now();
  1139. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("curParse.size = %d.", curParse.size());
  1140. if (0 == curParse.size())
  1141. {
  1142. HANDLE playThread = NULL;
  1143. CWmpPlayConfig config;
  1144. ZeroMemory(&config, sizeof(CWmpPlayConfig));
  1145. memcpy(&config, &(entity->m_defaultVideo[entity->m_mediaParam.nCfgInx]), sizeof(CWmpPlayConfig));
  1146. config.nPlayCnt = 1; //can be change
  1147. config.eMode = LOCALVIDEO;
  1148. config.nWndX = entity->m_mediaParam.nWndX;
  1149. config.nWndY = entity->m_mediaParam.nWndY;
  1150. config.nWndWidth = entity->m_mediaParam.nWndWidth;
  1151. config.nWndHeight = entity->m_mediaParam.nWndHeight;
  1152. if (IS_DEBUG){
  1153. config.bFullScreen = false;
  1154. config.bPrimMonitor = true;
  1155. }
  1156. CSimpleStringA strVideoPath = config.strRootPath;
  1157. CSimpleStringA strVideoFileName = config.strFileNames[0];
  1158. CSimpleStringA strVideoFullPath = strVideoPath + strVideoFileName;
  1159. BOOL bRet = IsFileExisted(strVideoFullPath.GetData());
  1160. if (FALSE == bRet && false == entity->GetLogFlag()){
  1161. char strmsg[MAX_PATH] = {0};
  1162. _snprintf(strmsg, MAX_PATH, "adv video file %s not exist!", strVideoFullPath.GetData());
  1163. LogWarn(Severity_Low, Error_Debug, LOG_EVT_ADV_VIDEO_NOT_EXIST, strmsg);
  1164. entity->SetLogFlag(true);
  1165. }
  1166. if (false == IsValidPlayTime(config) || FALSE == bRet){
  1167. Sleep(1000);
  1168. continue;
  1169. }
  1170. if (!entity->GetLocalVideoVolume(0, config.nVolume)){
  1171. config.nVolume = entity->m_defaultVolum;
  1172. }
  1173. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("config.nVolume=%d while play local video.", config.nVolume);
  1174. entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
  1175. if (!entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(playThread)){
  1176. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Get Play End Event Failed!");
  1177. }
  1178. else{
  1179. WaitForSingleObject(playThread, INFINITE);
  1180. if (entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->checkIsStop()){//停止播放
  1181. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("stop play video");
  1182. }
  1183. else{
  1184. entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->Close();
  1185. }
  1186. }
  1187. }
  1188. else
  1189. {
  1190. for (vector<ResourceParse>::iterator i = curParse.begin(); i != curParse.end() && entity->GetPlayFlag(); i++)
  1191. {
  1192. HANDLE playThread = NULL;
  1193. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("begin play extend [Media] %c:%s, %s", i->type, i->resourcePath.c_str(), i->videoNames.c_str());
  1194. if ('V' == i->type)
  1195. {//video
  1196. CWmpPlayConfig config;
  1197. ZeroMemory(&config, sizeof(CWmpPlayConfig));
  1198. config.bFullScreen = IS_DEBUG ? false : i->fullScreen;
  1199. config.bPrimMonitor = IS_DEBUG ? true : i->primMonitor;
  1200. config.bSimpleMode = i->simpleMode;
  1201. config.eMode = LOCALVIDEO;
  1202. config.nFileCnt = 1;
  1203. config.nPlayCnt = 1;
  1204. config.nPlayInterval = i->playInterval;
  1205. if (!entity->GetLocalVideoVolume(0, config.nVolume)){
  1206. config.nVolume = entity->m_defaultVolum;
  1207. }
  1208. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("config.nVolume=%d while play local video.", config.nVolume);
  1209. config.nWndX = entity->m_mediaParam.nWndX;
  1210. config.nWndY = entity->m_mediaParam.nWndY;
  1211. config.nWndWidth = entity->m_mediaParam.nWndWidth;
  1212. config.nWndHeight = entity->m_mediaParam.nWndHeight;
  1213. strncpy_s(config.strRootPath, i->resourcePath.c_str(), sizeof(config.strRootPath));
  1214. strncpy_s(config.strFileNames[0], i->videoNames.c_str(), 256);
  1215. strncpy_s(config.strVideoRunTime_S, "09:00:00", sizeof(config.strVideoRunTime_S));
  1216. strncpy_s(config.strVideoRunTime_E, "17:30:00", sizeof(config.strVideoRunTime_E));
  1217. if (false == IsValidPlayTime(config)) {
  1218. Sleep(3000);
  1219. continue;
  1220. }
  1221. CSimpleStringA strVideoPath = config.strRootPath;
  1222. CSimpleStringA strVideoFileName = config.strFileNames[0];
  1223. CSimpleStringA strVideoFullPath = strVideoPath + strVideoFileName;
  1224. BOOL bRet = IsFileExisted(strVideoFullPath.GetData());
  1225. bool bFileValid = entity->m_pMediaPlayer[entity->m_mediaParam.nCfgInx]->IsFileValid(strVideoFullPath.GetData());
  1226. if (FALSE == bRet && false == entity->GetLocalLogFlag()){
  1227. char strmsg[MAX_PATH] = {0};
  1228. _snprintf(strmsg, MAX_PATH, "adv video file %s not exist!", strVideoFullPath.GetData());
  1229. LogWarn(Severity_Low, Error_Debug, LOG_EVT_ADV_VIDEO_NOT_EXIST, strmsg);
  1230. entity->SetLocalLogFlag(true);
  1231. }
  1232. if(FALSE == bRet || false == bFileValid){
  1233. continue;
  1234. }
  1235. entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
  1236. if (!entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(playThread)){
  1237. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Get Play End Event Failed!");
  1238. }
  1239. else{
  1240. WaitForSingleObject(playThread, INFINITE);
  1241. if (entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->checkIsStop()){//停止播放
  1242. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("stop play video");
  1243. }
  1244. else{
  1245. entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->Close();
  1246. }
  1247. }
  1248. }
  1249. else if ('P' == i->type)
  1250. {//play Image
  1251. CImgPlayConfig config;
  1252. ZeroMemory(&config, sizeof(CImgPlayConfig));
  1253. config.bFullScreen = IS_DEBUG ? false : i->fullScreen;
  1254. config.bPrimMonitor = IS_DEBUG ? true : i->primMonitor;
  1255. config.nFileCnt = 1;
  1256. config.nPlayCnt = 1;
  1257. config.nPlayInterval = i->playInterval;
  1258. config.nWndX = entity->m_mediaParam.nWndX;
  1259. config.nWndY = entity->m_mediaParam.nWndY;
  1260. config.nWndWidth = entity->m_mediaParam.nWndWidth;
  1261. config.nWndHeight = entity->m_mediaParam.nWndHeight;
  1262. strncpy_s(config.strRootPath, i->resourcePath.c_str(), sizeof(config.strRootPath));
  1263. strncpy_s(config.strFileNames[0], i->videoNames.c_str(), 256);
  1264. CSimpleStringA strPicPath = config.strRootPath;
  1265. CSimpleStringA strPicFileName = config.strFileNames[0];
  1266. CSimpleStringA strPicFullPath = strPicPath + strPicFileName;
  1267. BOOL bRet = IsFileExisted(strPicFullPath.GetData());
  1268. if (FALSE == bRet && false == entity->GetLocalPicLogFlag()){
  1269. char strmsg[MAX_PATH] = {0};
  1270. _snprintf(strmsg, MAX_PATH, "adv picture file %s not exist!", strPicFullPath.GetData());
  1271. LogWarn(Severity_Low, Error_Debug, LOG_EVT_ADV_PIC_NOT_EXIST, strmsg);
  1272. entity->SetLocalPicLogFlag(true);
  1273. }
  1274. if(FALSE == bRet){
  1275. continue;
  1276. }
  1277. entity->m_pImagePlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
  1278. if (!entity->m_pImagePlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(playThread)){
  1279. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Create play Image Media Thread Failed!");
  1280. }
  1281. else
  1282. {
  1283. WaitForSingleObject(playThread, i->playInterval);
  1284. if (entity->m_pImagePlayer[entity->m_mediaParam.nCfgInx]->checkIsStop()){//停止播放
  1285. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("stop play Image");
  1286. }
  1287. else{
  1288. entity->m_pImagePlayer[entity->m_mediaParam.nCfgInx]->Close();
  1289. }
  1290. }
  1291. }
  1292. }
  1293. }
  1294. unsigned int uend_time = y2k_time_now();
  1295. if (uend_time - ustart_time < RVC_MIN_LOCALPLAYER_TIME) {
  1296. LogWarn(Severity_Low, Error_Debug, LOG_EVT_MEDIAPLAY_COST_TIME_ERROR, "广告播放错误,播放时长不足1秒");
  1297. break;
  1298. }
  1299. }
  1300. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Exit MediaPlayThread.");
  1301. return 0;
  1302. }
  1303. DWORD WINAPI StartMediaPlayFunc(LPVOID param)
  1304. {
  1305. int iRet = -1;
  1306. if (NULL == param){
  1307. return iRet;
  1308. }
  1309. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Enter Media Play Function.");
  1310. CLocalMediaPlayEntity* entity = (CLocalMediaPlayEntity*)param;
  1311. while (entity->GetPlayFlag())
  1312. {
  1313. vector<ResourceParse> curParse;
  1314. entity->m_mediaManage.GetPlayListByLocal(curParse);
  1315. unsigned int ustart_time = y2k_time_now();
  1316. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("curParse.size = %d.", curParse.size());
  1317. if (0 == curParse.size()){
  1318. CMediaPlayConfig config = {0};
  1319. memcpy(&config, &(entity->m_Videos[entity->m_mediaParam.nCfgInx]), sizeof(CMediaPlayConfig));
  1320. config.nPlayCnt = 1; //can be change
  1321. config.eMode = MEDIA_LOCALVIDEO;
  1322. config.nWndX = entity->m_mediaParam.nWndX;
  1323. config.nWndY = entity->m_mediaParam.nWndY;
  1324. config.nWndWidth = entity->m_mediaParam.nWndWidth;
  1325. config.nWndHeight = entity->m_mediaParam.nWndHeight;
  1326. if (IS_DEBUG){
  1327. config.bFullScreen = false;
  1328. config.bPrimMonitor = true;
  1329. }
  1330. if (!entity->GetLocalVideoVolume(0, config.nVolume)){
  1331. config.nVolume = entity->m_defaultVolum;
  1332. }
  1333. struct tm* ptm = NULL;
  1334. time_t t = time(NULL);
  1335. ptm = localtime(&t);
  1336. TCHAR strNow[TIME_LEN] = {0};
  1337. sprintf(strNow, "%02d:%02d:%02d", ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
  1338. if (strcmp(strNow, config.strVideoRunTime_S) < 0 || strcmp(strNow, config.strVideoRunTime_E) >= 0){
  1339. Sleep(1000);
  1340. continue;
  1341. }
  1342. if (-1 == entity->m_pMediaPlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config)){
  1343. Sleep(3000);
  1344. }
  1345. Sleep(800);
  1346. }
  1347. for (int i = 0; i < curParse.size() && entity->GetPlayFlag(); i++)
  1348. {
  1349. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("ResourceList[%d] address is 0x%0x", i, ResourceList[i]);
  1350. HANDLE playThreadId = 0;
  1351. ResourceParse item = curParse[i];
  1352. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("begin play extend [Media%d] %c:%s, %s",i, item.type, item.resourcePath.c_str(), item.videoNames.c_str());
  1353. if ('V' == item.type)
  1354. {//video
  1355. CMediaPlayConfig config = {0};
  1356. config.bFullScreen = IS_DEBUG ? false : item.fullScreen;
  1357. config.bPrimMonitor = IS_DEBUG ? true : item.primMonitor;
  1358. config.bSimpleMode = item.simpleMode;
  1359. config.eMode = MEDIA_LOCALVIDEO;
  1360. config.nFileCnt = 1;
  1361. config.nPlayCnt = 1;
  1362. config.nPlayInterval = item.playInterval;
  1363. if (!entity->GetLocalVideoVolume(0, config.nVolume)){
  1364. config.nVolume = entity->m_defaultVolum;
  1365. }
  1366. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("config.nVolume=%d while play local video.", config.nVolume);
  1367. config.nWndX = entity->m_mediaParam.nWndX;
  1368. config.nWndY = entity->m_mediaParam.nWndY;
  1369. config.nWndWidth = entity->m_mediaParam.nWndWidth;
  1370. config.nWndHeight = entity->m_mediaParam.nWndHeight;
  1371. strncpy(config.strRootPath, item.resourcePath.c_str(), item.resourcePath.length() < MAX_PATH ? item.resourcePath.length() : MAX_PATH);
  1372. strncpy(config.strFileNames[0], item.videoNames.c_str(), item.videoNames.length() < MAX_PATH ? item.videoNames.length() : MAX_PATH);
  1373. strncpy(config.strVideoRunTime_S, "09:00:00", sizeof(config.strVideoRunTime_S));
  1374. strncpy(config.strVideoRunTime_E, "17:30:00", sizeof(config.strVideoRunTime_E));
  1375. int iPlayRet = entity->m_pMediaPlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
  1376. if (-2 == iPlayRet){
  1377. Sleep(3000);
  1378. continue;
  1379. }
  1380. if (-3 == iPlayRet) {
  1381. Sleep(DEFAULT_SLEEP_TIME);
  1382. }
  1383. Sleep(800);
  1384. }
  1385. else if ('P' == item.type)
  1386. {//play Image
  1387. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Begin new Image play, entity->m_mediaParam.nCfgInx = %d.", entity->m_mediaParam.nCfgInx);
  1388. CPicPlayConfig config = {0};
  1389. config.bFullScreen = IS_DEBUG ? false : item.fullScreen;
  1390. config.bPrimMonitor = IS_DEBUG ? true : item.primMonitor;
  1391. config.nFileCnt = 1;
  1392. config.nPlayCnt = 1;
  1393. config.nPlayInterval = item.playInterval;
  1394. config.nWndX = entity->m_mediaParam.nWndX;
  1395. config.nWndY = entity->m_mediaParam.nWndY;
  1396. config.nWndWidth = entity->m_mediaParam.nWndWidth;
  1397. config.nWndHeight = entity->m_mediaParam.nWndHeight;
  1398. strncpy(config.strRootPath, item.resourcePath.c_str(), item.resourcePath.length() < MAX_PATH ? item.resourcePath.length() : MAX_PATH);
  1399. strncpy(config.strFileNames[0], item.videoNames.c_str(), item.videoNames.length() < MAX_PATH ? item.videoNames.length() : MAX_PATH);
  1400. if (entity->m_pPicturePlayer[entity->m_mediaParam.nCfgInx]->checkIsStop()){
  1401. entity->m_pPicturePlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
  1402. if (!entity->m_pPicturePlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(&playThreadId)) {
  1403. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Create play Image Media Thread Failed!");
  1404. iRet = -1;
  1405. return iRet;
  1406. }
  1407. else {
  1408. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Image Media Player Thread id is 0x%p.", playThreadId);
  1409. }
  1410. WaitForSingleObject(playThreadId, INFINITE);
  1411. if (entity->m_pPicturePlayer[entity->m_mediaParam.nCfgInx]->checkIsStop()){//停止播放
  1412. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("stop play video");
  1413. }
  1414. else{
  1415. entity->m_pPicturePlayer[entity->m_mediaParam.nCfgInx]->Close();
  1416. }
  1417. }
  1418. Sleep(100);
  1419. }
  1420. }
  1421. unsigned int uend_time = y2k_time_now();
  1422. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("uend_time - ustart_time = %u.", uend_time - ustart_time);
  1423. if (uend_time - ustart_time < RVC_MIN_LOCALPLAYER_TIME) {
  1424. LogWarn(Severity_Low, Error_Debug, LOG_EVT_MEDIAPLAY_COST_TIME_ERROR, "广告播放错误,播放时长不足1秒");
  1425. break;
  1426. }
  1427. }
  1428. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Leave Media Play Function.");
  1429. entity->m_uMediaPlayThreadId = 0;
  1430. return iRet;
  1431. }
  1432. #else
  1433. void* StartAudioPlayingThreadFunc(void* param)
  1434. {
  1435. CLocalMediaPlayEntity* entity = (CLocalMediaPlayEntity*)param;
  1436. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Enter StartAudioPlayingThreadFunc");
  1437. const char* pAudioNames = entity->m_lastPlayAudio.c_str();
  1438. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Begin StartAudio, and Audio Info is %s.", pAudioNames);
  1439. if (0 == entity->m_pMediaAudioPlayer->PlayLocalAudio(pAudioNames)) {
  1440. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Succeed to StartAudio, and Audio Info is %s.", pAudioNames);
  1441. }
  1442. else {
  1443. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("StartAudio failed, for %s is not exsit.", pAudioNames);
  1444. }
  1445. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Leave StartAudioPlayingThreadFunc");
  1446. entity->m_uMediaPlayThreadId = 0;
  1447. return 0;
  1448. }
  1449. void* StartMediaPlayFunc(void* param)
  1450. {
  1451. int iRet = -1;
  1452. if (NULL == param) {
  1453. return (void*)&iRet;
  1454. }
  1455. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Enter Media Play Function.");
  1456. CLocalMediaPlayEntity* entity = (CLocalMediaPlayEntity*)param;
  1457. while (entity->GetPlayFlag())
  1458. {
  1459. rvcResourceParse_t ResourceList[MAX_LOCAL_MEDIAS] = { 0 };
  1460. size_t uCount = entity->m_mediaManage.GetPlayListByLocal(ResourceList, MAX_LOCAL_MEDIAS);
  1461. unsigned int ustart_time = y2k_time_now();
  1462. if (0 == uCount) {
  1463. int64_t playThreadId = 0;
  1464. CMediaPlayConfig config = { 0 };
  1465. memcpy(&config, &(entity->m_Videos[entity->m_mediaParam.nCfgInx]), sizeof(CMediaPlayConfig));
  1466. config.nPlayCnt = 1; //can be change
  1467. config.eMode = LOCALVIDEO;
  1468. config.nWndX = entity->m_mediaParam.nWndX;
  1469. config.nWndY = entity->m_mediaParam.nWndY;
  1470. config.nWndWidth = entity->m_mediaParam.nWndWidth;
  1471. config.nWndHeight = entity->m_mediaParam.nWndHeight;
  1472. if (IS_DEBUG) {
  1473. config.bFullScreen = false;
  1474. config.bPrimMonitor = true;
  1475. }
  1476. if (!entity->GetLocalVideoVolume(0, config.nVolume)) {
  1477. config.nVolume = entity->m_defaultVolum;
  1478. }
  1479. struct tm* ptm = NULL;
  1480. time_t t = time(NULL);
  1481. ptm = localtime(&t);
  1482. TCHAR strNow[TIME_LEN] = { 0 };
  1483. sprintf(strNow, "%02d:%02d:%02d", ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
  1484. if (strcmp(strNow, config.strVideoRunTime_S) < 0 || strcmp(strNow, config.strVideoRunTime_E) >= 0) {
  1485. Sleep(10000);
  1486. continue;
  1487. }
  1488. if (-1 == entity->m_pMediaPlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config)) {
  1489. Sleep(30 * DEFAULT_SLEEP_TIME);
  1490. }
  1491. Sleep(800);
  1492. }
  1493. for (int i = 0; i < uCount && i < MAX_LOCAL_MEDIAS && entity->GetPlayFlag(); i++)
  1494. {
  1495. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("ResourceList[%d] address is 0x%0x", i, ResourceList[i]);
  1496. int64_t playThreadId = 0;
  1497. rvcResourceParse_t item = ResourceList[i];
  1498. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("begin play extend %c:%s, %s", item.type, item.strResourcePath, item.strvideoNames);
  1499. if ('V' == item.type)
  1500. {//video
  1501. CMediaPlayConfig config = { 0 };
  1502. config.bFullScreen = IS_DEBUG ? false : item.fullScreen;
  1503. config.bPrimMonitor = IS_DEBUG ? true : item.primMonitor;
  1504. config.bSimpleMode = item.simpleMode;
  1505. config.eMode = LOCALVIDEO;
  1506. config.nFileCnt = 1;
  1507. config.nPlayCnt = 1;
  1508. config.nPlayInterval = item.playInterval;
  1509. // add by ly@2018/07/30
  1510. //config.nVolume = IS_DEBUG ? 0 : entity->m_defaultVolum;
  1511. if (!entity->GetLocalVideoVolume(0, config.nVolume)) {
  1512. config.nVolume = entity->m_defaultVolum;
  1513. }
  1514. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("config.nVolume=%d while play local video.", config.nVolume);
  1515. config.nWndX = entity->m_mediaParam.nWndX;
  1516. config.nWndY = entity->m_mediaParam.nWndY;
  1517. config.nWndWidth = entity->m_mediaParam.nWndWidth;
  1518. config.nWndHeight = entity->m_mediaParam.nWndHeight;
  1519. strncpy(config.strRootPath, item.strResourcePath, strlen(item.strResourcePath));
  1520. strncpy(config.strFileNames[0], item.strvideoNames, strlen(item.strvideoNames));
  1521. strncpy(config.strVideoRunTime_S, "09:00:00", sizeof(config.strVideoRunTime_S));
  1522. strncpy(config.strVideoRunTime_E, "17:30:00", sizeof(config.strVideoRunTime_E));
  1523. int iPlayRet = entity->m_pMediaPlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
  1524. if (-2 == iPlayRet) {
  1525. Sleep(DEFAULT_SLEEP_TIME);
  1526. continue;
  1527. }
  1528. if (-3 == iPlayRet) {
  1529. Sleep(DEFAULT_SLEEP_TIME / 6);
  1530. }
  1531. Sleep(800);
  1532. }
  1533. else if ('P' == item.type)
  1534. {//play Image
  1535. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Begin new Image play, entity->m_mediaParam.nCfgInx = %d.", entity->m_mediaParam.nCfgInx);
  1536. CPicPlayConfig config = { 0 };
  1537. config.bFullScreen = IS_DEBUG ? false : item.fullScreen;
  1538. config.bPrimMonitor = IS_DEBUG ? true : item.primMonitor;
  1539. config.nFileCnt = 1;
  1540. config.nPlayCnt = 1;
  1541. config.nPlayInterval = item.playInterval;
  1542. config.nWndX = entity->m_mediaParam.nWndX;
  1543. config.nWndY = entity->m_mediaParam.nWndY;
  1544. config.nWndWidth = entity->m_mediaParam.nWndWidth;
  1545. config.nWndHeight = entity->m_mediaParam.nWndHeight;
  1546. strncpy(config.strRootPath, item.strResourcePath, strlen(item.strResourcePath));
  1547. strncpy(config.strFileNames[0], item.strvideoNames, strlen(item.strvideoNames));
  1548. if (entity->m_pPicturePlayer[entity->m_mediaParam.nCfgInx]->checkIsStop()) {
  1549. entity->m_pPicturePlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
  1550. if (!entity->m_pPicturePlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(&playThreadId)) {
  1551. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Create play Image Media Thread Failed!");
  1552. iRet = -1;
  1553. return (void*)&iRet;
  1554. }
  1555. else {
  1556. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Image Media Player Thread id is %u.", playThreadId);
  1557. }
  1558. if (0 == pthread_join(playThreadId, NULL)) {
  1559. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("pthread join thread id %u success.", playThreadId);
  1560. iRet = 0;
  1561. }
  1562. else {
  1563. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("pthread join thread id %u failed for %s.", playThreadId, strerror(errno));
  1564. iRet = -1;
  1565. }
  1566. }
  1567. Sleep(100);
  1568. }
  1569. }
  1570. unsigned int uend_time = y2k_time_now();
  1571. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("uend_time - ustart_time = %u.", uend_time - ustart_time);
  1572. if (uend_time - ustart_time < RVC_MIN_LOCALPLAYER_TIME) {
  1573. Sleep(30 * DEFAULT_SLEEP_TIME);
  1574. }
  1575. }
  1576. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Leave Media Play Function.");
  1577. entity->m_uMediaPlayThreadId = 0;
  1578. return (void*)&iRet;
  1579. }
  1580. void* StartNoticePlayThreadFunc(void* param)
  1581. {
  1582. int iRet = -1;
  1583. CLocalMediaPlayEntity* entity = (CLocalMediaPlayEntity*)param;
  1584. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Enter NoticePlayThreadFunc");
  1585. const char* pVideoName = entity->m_lastPlayVideo.c_str();
  1586. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Begin Start Notice Play, and Video Notice Info is %s.", pVideoName);
  1587. Clibmediaplayer* player = entity->m_pMediaPlayer[entity->m_mediaParam.nCfgInx];
  1588. player->PlayVideoNotice(entity->m_mediaParam.nWndX, entity->m_mediaParam.nWndY, entity->m_mediaParam.nWndWidth, entity->m_mediaParam.nWndHeight, pVideoName);
  1589. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Succeed to Start Notice Play, and Video Notice Info is %s.", pVideoName);
  1590. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Leave NoticePlayThreadFunc");
  1591. entity->m_uNoticePlayThreadId = 0;
  1592. iRet = 0;
  1593. return (void*)&iRet;
  1594. }
  1595. #endif
  1596. DeviceTypeEnum CLocalMediaPlayEntity::RvcGetDeviceType()
  1597. {
  1598. DeviceTypeEnum eType = eStand2sType;
  1599. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  1600. CSystemStaticInfo stStaticinfo;
  1601. spFunction->GetSystemStaticInfo(stStaticinfo);
  1602. if (stricmp(stStaticinfo.strMachineType, "RVC.PAD") == 0) {
  1603. if (stricmp(stStaticinfo.strSite, "CMB.FLB") == 0) {
  1604. eType = eMobilePadType;
  1605. }
  1606. else {
  1607. eType = ePadtype;
  1608. }
  1609. }
  1610. else if (stricmp(stStaticinfo.strMachineType, "RVC.Desk2S") == 0) {
  1611. eType = eDesk2SType;
  1612. }
  1613. else if (stricmp(stStaticinfo.strMachineType, "RPM.Stand1S") == 0) {
  1614. eType = eRpm1sType;
  1615. }
  1616. else if (stricmp(stStaticinfo.strMachineType, "RVC.Desk1S") == 0) {
  1617. eType = eDesk1SType;
  1618. }
  1619. else if (stricmp(stStaticinfo.strMachineType, "RVC.CardStore") == 0 || stricmp(stStaticinfo.strMachineType, "RVC.CardPrinter") == 0) {
  1620. eType = eCardStore;
  1621. }
  1622. else {
  1623. eType = eStand2sType;
  1624. }
  1625. if (eType >= 0 && eType < sizeof(Device_Type_Table) / sizeof(char*)) {
  1626. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("device type is %s.", Device_Type_Table[eType]);
  1627. }
  1628. return eType;
  1629. }
  1630. void CLocalMediaPlayEntity::StartVideo(int nCfgInx, int nWndX, int nWndY, int nWndWidth, int nWndHeight)
  1631. {
  1632. if(eStand2sType == m_eDeviceType){
  1633. if (nCfgInx >= MAX_PLAY_CHANNELS || nCfgInx < 0){
  1634. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Invalid CfgInx while StartVideo!");
  1635. return;
  1636. }
  1637. m_mediaParam.nCfgInx = nCfgInx;
  1638. m_mediaParam.nWndX = nWndX;
  1639. m_mediaParam.nWndY = nWndY;
  1640. m_mediaParam.nWndWidth = nWndWidth;
  1641. m_mediaParam.nWndHeight = nWndHeight;
  1642. #ifdef RVC_OS_WIN
  1643. if (0 == m_iPlayType) {
  1644. if (NULL != m_playThread) {
  1645. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Current is playing video, close it.");
  1646. StopVideo(nCfgInx);
  1647. }
  1648. if (NULL == m_playThread) {
  1649. m_badplayflag = true;
  1650. m_playThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&MediaPlayThread, this, 0, NULL);
  1651. }
  1652. }
  1653. else {
  1654. if (NULL != m_uMediaPlayThreadId) {
  1655. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Current is playing video, close it.");
  1656. StopVideo(nCfgInx);
  1657. }
  1658. m_badplayflag = true;
  1659. m_uMediaPlayThreadId = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&StartMediaPlayFunc, this, 0, NULL);
  1660. }
  1661. #else
  1662. m_badplayflag = true;
  1663. int err = pthread_create(&m_uMediaPlayThreadId, NULL, StartMediaPlayFunc, this);
  1664. if (0 == err) {
  1665. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create media play thread[%u] success.", m_uMediaPlayThreadId);
  1666. }
  1667. else {
  1668. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create media play thread failed.");
  1669. }
  1670. #endif // RVC_OS_WIN
  1671. }
  1672. }
  1673. void CLocalMediaPlayEntity::StartAudio(const char *pAudioNames)
  1674. {
  1675. #ifdef RVC_OS_WIN
  1676. if (0 == m_iPlayType) {
  1677. static HANDLE audioPlayThread = NULL;
  1678. if (audioPlayThread)//关闭正在播放的音频
  1679. {
  1680. DWORD exitCode = 0;
  1681. if (WAIT_TIMEOUT == WaitForSingleObject(audioPlayThread, 500)) {
  1682. //TerminateThread(audioPlayThread, exitCode);
  1683. m_pAudioPlayer->Close();
  1684. }
  1685. audioPlayThread = NULL;
  1686. }
  1687. if (NULL != pAudioNames) {
  1688. char strAudios[MAX_PATH] = { 0 };
  1689. _snprintf(strAudios, MAX_PATH, "%s", pAudioNames);
  1690. const char* d = "|";
  1691. char* pName = NULL;
  1692. char* pdata = NULL;
  1693. pName = strtok_s(strAudios, d, &pdata);
  1694. while (pName) {
  1695. CSimpleStringA strAudioFileName = pName;
  1696. CSimpleStringA strAudioFullPath = m_AudioPath + strAudioFileName;
  1697. BOOL bRet = IsFileExisted(strAudioFullPath.GetData());
  1698. if (FALSE == bRet) {
  1699. char strmsg[MAX_PATH] = { 0 };
  1700. _snprintf(strmsg, MAX_PATH, "audio file %s not exist!", strAudioFullPath.GetData());
  1701. LogWarn(Severity_Low, Error_Debug, LOG_EVT_ADV_AUDIO_NOT_EXIST, strmsg);
  1702. }
  1703. pName = strtok_s(NULL, d, &pdata);
  1704. }
  1705. }
  1706. m_pAudioPlayer->PlayLocalAudio(pAudioNames);
  1707. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Succeed to StartAudio!, Audio Info:%s", pAudioNames);
  1708. auto audioRet = GetLocalAudioVolume();
  1709. m_pAudioPlayer->SetVolume(audioRet.second);
  1710. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Succeed to set audio volume %d!", audioRet.second);
  1711. m_lastPlayAudio = pAudioNames;
  1712. audioPlayThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&CheckAudioThread, this, 0, NULL);
  1713. }
  1714. else
  1715. {
  1716. if (m_pMediaAudioPlayer->checkIsPlay()) {
  1717. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("current is playing, close it.");
  1718. if (0 != m_uMediaPlayThreadId) {
  1719. m_pMediaAudioPlayer->Close();
  1720. m_uMediaPlayThreadId = 0;
  1721. Sleep(500);
  1722. }
  1723. }
  1724. m_lastPlayAudio = pAudioNames;
  1725. m_uMediaPlayThreadId = CreateThread(NULL, 0, StartAudioPlayingThreadFunc, this, 0, NULL);
  1726. m_buserstopaudio = false;
  1727. auto audioRet = GetLocalAudioVolume();
  1728. m_pMediaAudioPlayer->SetVolume(audioRet.second);
  1729. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Succeed to set audio volume %d!", audioRet.second);
  1730. }
  1731. #else
  1732. if (m_pMediaAudioPlayer->checkIsPlay()) {
  1733. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("current is playing, close it.");
  1734. if (0 != m_uMediaPlayThreadId) {
  1735. m_pMediaAudioPlayer->Close();
  1736. m_uMediaPlayThreadId = 0;
  1737. Sleep(500);
  1738. }
  1739. }
  1740. m_lastPlayAudio = pAudioNames;
  1741. int err = pthread_create(&m_uMediaPlayThreadId, NULL, StartAudioPlayingThreadFunc, this);
  1742. if (0 == err) {
  1743. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create audio play thread[%u] success.", m_uMediaPlayThreadId);
  1744. }
  1745. else {
  1746. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create audio play thread failed.");
  1747. }
  1748. m_buserstopaudio = false;
  1749. auto audioRet = GetLocalAudioVolume();
  1750. m_pMediaAudioPlayer->SetVolume(audioRet.second);
  1751. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Succeed to set audio volume %d!", audioRet.second);
  1752. #endif
  1753. }
  1754. void CLocalMediaPlayEntity::StartImage(int nCfgInx, int nWndX, int nWndY, int nWndWidth, int nWndHeight)
  1755. {
  1756. if(eStand2sType == m_eDeviceType){
  1757. if (nCfgInx >= MAX_PLAY_CHANNELS || nCfgInx < 0){
  1758. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Invalid CfgInx while StartImage!");
  1759. return;
  1760. }
  1761. #ifdef RVC_OS_WIN
  1762. if (0 == m_iPlayType){
  1763. m_pImagePlayer[nCfgInx]->Play(nCfgInx, nWndX, nWndY, nWndWidth, nWndHeight);
  1764. }
  1765. else{
  1766. m_pPicturePlayer[nCfgInx]->Play(nCfgInx, nWndX, nWndY, nWndWidth, nWndHeight);
  1767. }
  1768. #else
  1769. m_pPicturePlayer[nCfgInx]->Play(nCfgInx, nWndX, nWndY, nWndWidth, nWndHeight);
  1770. #endif
  1771. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Succeed to StartImage!");
  1772. }
  1773. }
  1774. void CLocalMediaPlayEntity::StopVideo(int nCfgInx)
  1775. {
  1776. if(eStand2sType == m_eDeviceType){
  1777. if (nCfgInx >= MAX_PLAY_CHANNELS || nCfgInx < 0){
  1778. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Invalid CfgInx while StopVideo!");
  1779. return;
  1780. }
  1781. m_badplayflag = false;
  1782. #ifdef RVC_OS_WIN
  1783. if (0 == m_iPlayType){
  1784. if (NULL != m_playThread) {
  1785. m_pVideoPlayer[nCfgInx]->Close();
  1786. m_pImagePlayer[nCfgInx]->Close();
  1787. WaitForSingleObject(m_playThread, INFINITE);
  1788. m_playThread = NULL;
  1789. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Succeed to StopVideo!");
  1790. }
  1791. }
  1792. else{
  1793. if (NULL != m_uMediaPlayThreadId) {
  1794. m_pMediaPlayer[nCfgInx]->Close();
  1795. m_pPicturePlayer[nCfgInx]->Close();
  1796. WaitForSingleObject(m_uMediaPlayThreadId, INFINITE);
  1797. m_uMediaPlayThreadId = NULL;
  1798. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Succeed to StopVideo!");
  1799. }
  1800. }
  1801. #else
  1802. m_pMediaPlayer[nCfgInx]->Close();
  1803. m_pPicturePlayer[nCfgInx]->Close();
  1804. m_badplayflag = false;
  1805. #endif
  1806. }
  1807. }
  1808. void CLocalMediaPlayEntity::StopAudio()
  1809. {
  1810. #ifdef RVC_OS_WIN
  1811. if (0 == m_iPlayType){
  1812. if (FALSE == m_pAudioPlayer->checkIsStop()) {
  1813. m_pAudioPlayer->Close();
  1814. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Succeed to StopAudio!");
  1815. }
  1816. }
  1817. else{
  1818. if(FALSE == m_pMediaAudioPlayer->checkIsStop())
  1819. m_pMediaAudioPlayer->Close();
  1820. m_buserstopaudio = true;
  1821. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Succeed to StopAudio!");
  1822. }
  1823. #else
  1824. m_pMediaAudioPlayer->Close();
  1825. m_buserstopaudio = true;
  1826. #endif
  1827. }
  1828. void CLocalMediaPlayEntity::StopImage(int nCfgInx)
  1829. {
  1830. if(eStand2sType == m_eDeviceType){
  1831. if (nCfgInx >= MAX_PLAY_CHANNELS || nCfgInx < 0){
  1832. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Invalid CfgInx while StopImage!");
  1833. return;
  1834. }
  1835. #ifdef RVC_OS_WIN
  1836. if (0 == m_iPlayType){
  1837. if (FALSE == m_pImagePlayer[nCfgInx]->checkIsStop()) {
  1838. m_pImagePlayer[nCfgInx]->Close();
  1839. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Succeed to StopImage!");
  1840. }
  1841. }
  1842. else{
  1843. if (FALSE == m_pPicturePlayer[nCfgInx]->checkIsStop()) {
  1844. m_pPicturePlayer[nCfgInx]->Close();
  1845. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Succeed to StopImage!");
  1846. }
  1847. }
  1848. #else
  1849. m_pPicturePlayer[nCfgInx]->Close();
  1850. #endif
  1851. }
  1852. }
  1853. void CLocalMediaPlayEntity::StopAll()
  1854. {
  1855. StopAudio(); // 关闭音频
  1856. for (int i = 0; i < MAX_PLAY_CHANNELS; ++i){
  1857. StopVideo(i); // 关闭视频
  1858. StopImage(i); // 关闭图像
  1859. StopNotice(i); // 关闭视频提示
  1860. }
  1861. }
  1862. bool CLocalMediaPlayEntity::GetLocalVideoVolume(int nCfgInx, int &nVolume)
  1863. {
  1864. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get local video volume req.");
  1865. CSmartPointer<IConfigInfo> spConfig;
  1866. ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_Run, spConfig);
  1867. if (Error == Error_Succeed)
  1868. {
  1869. Error = spConfig->ReadConfigValueInt("LocalVideo", "Volume", nVolume);
  1870. if (Error == Error_Succeed && nVolume >= 0 && nVolume <= 100)
  1871. {
  1872. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("succeed to get local video volume with nCfgInx:%d, nVolume:%d", nCfgInx, nVolume);
  1873. return true;
  1874. }
  1875. }
  1876. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("fail to get local video volume!");
  1877. return false;
  1878. }
  1879. std::pair<bool, int> CLocalMediaPlayEntity::GetLocalAudioVolume()
  1880. {
  1881. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("get local audio volume req.");
  1882. CSmartPointer<IConfigInfo> spConfig;
  1883. int nVolume = 0;
  1884. ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_Run, spConfig);
  1885. if (Error == Error_Succeed)
  1886. {
  1887. Error = spConfig->ReadConfigValueInt("LocalAudio", "Volume", nVolume);
  1888. if (nVolume == 0)
  1889. {
  1890. nVolume = 50;
  1891. spConfig->WriteConfigValueInt("LocalAudio", "Volume", nVolume);
  1892. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("read nVolume 0, set default 50");
  1893. }
  1894. if (Error == Error_Succeed && nVolume >= 0 && nVolume <= 100)
  1895. {
  1896. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("succeed to get local audio volume with nVolume:%d", nVolume);
  1897. return std::make_pair(true, nVolume);
  1898. }
  1899. }
  1900. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("fail to get local audio volume!");
  1901. return std::make_pair(false, nVolume);
  1902. }
  1903. bool CLocalMediaPlayEntity::SetLocalAudioVolume(int nVolume)
  1904. {
  1905. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("set local video audio req.");
  1906. if (nVolume < 0 || nVolume > 100){
  1907. return false;
  1908. }
  1909. CSmartPointer<IConfigInfo> spConfig;
  1910. ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_Run, spConfig);
  1911. if (Error == Error_Succeed)
  1912. {
  1913. Error = spConfig->WriteConfigValueInt("LocalAudio", "Volume", nVolume);
  1914. if (Error == Error_Succeed)
  1915. {
  1916. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("succeed to set local audio volume with nVolume:%d!", nVolume);
  1917. #ifdef RVC_OS_WIN
  1918. if (0 == m_iPlayType) {
  1919. m_pAudioPlayer->SetVolume(nVolume);
  1920. }
  1921. else {
  1922. m_pMediaAudioPlayer->SetVolume(nVolume);
  1923. }
  1924. #else
  1925. m_pMediaAudioPlayer->SetVolume(nVolume);
  1926. #endif
  1927. return true;
  1928. }
  1929. }
  1930. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("fail to set local video volume!");
  1931. return false;
  1932. }
  1933. bool CLocalMediaPlayEntity::SetLocalVideoVolume(int nCfgInx, int nVolume)
  1934. {
  1935. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("set local video volume req.");
  1936. if (nVolume < 0 || nVolume > 100){
  1937. return false;
  1938. }
  1939. CSmartPointer<IConfigInfo> spConfig;
  1940. ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_Run, spConfig);
  1941. if (Error == Error_Succeed)
  1942. {
  1943. Error = spConfig->WriteConfigValueInt("LocalVideo", "Volume", nVolume);
  1944. if (Error == Error_Succeed)
  1945. {
  1946. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("succeed to set local video volume with nCfgInx:%d, nVolume:%d!", nCfgInx, nVolume);
  1947. for (int i = 0; i < MAX_PLAY_CHANNELS; ++i)
  1948. {
  1949. #ifdef RVC_OS_WIN
  1950. if (0 == m_iPlayType){
  1951. m_pVideoPlayer[i]->SetVolume(nVolume);
  1952. }
  1953. else{
  1954. m_pMediaPlayer[i]->SetVolume(nVolume);
  1955. }
  1956. #else
  1957. m_pMediaPlayer[i]->SetVolume(nVolume);
  1958. #endif
  1959. }
  1960. return true;
  1961. }
  1962. }
  1963. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("fail to set local video volume!");
  1964. return false;
  1965. }
  1966. bool CLocalMediaPlayEntity::IsRunConfigExist()
  1967. {
  1968. CSimpleStringA strPath;
  1969. ErrorCodeEnum eErr;
  1970. if ((eErr = GetFunction()->GetPath("RunInfo", strPath)) != Error_Succeed){
  1971. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get runinfo path failed(%d)", eErr);
  1972. return false;
  1973. }
  1974. #ifdef RVC_OS_WIN
  1975. CSimpleStringA strRuninfoFile;
  1976. strRuninfoFile = CSimpleStringA::Format("%s\\runcfg\\%s.ini", (LPCTSTR)strPath, GetEntityName());
  1977. WIN32_FIND_DATA findData;
  1978. if (FindFirstFileA((LPCTSTR)strRuninfoFile, &findData) != INVALID_HANDLE_VALUE) return true;
  1979. return false;
  1980. #else
  1981. CSimpleStringA strRuninfoFile;
  1982. strRuninfoFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR "%s.ini", (LPCTSTR)strPath, GetEntityName());
  1983. if (ExistsFileA(strRuninfoFile)) {
  1984. return true;
  1985. }
  1986. else {
  1987. return false;
  1988. }
  1989. #endif
  1990. }
  1991. ErrorCodeEnum CLocalMediaPlayEntity::StartMediaPlayerNotice(int nCfgInx, int nWndX, int nWndY, int nWndWidth, int nWndHeight, const char *pVideoName)
  1992. {
  1993. m_mediaParam.nCfgInx = nCfgInx;
  1994. CSimpleStringA strPath;
  1995. ErrorCodeEnum Error = GetFunction()->GetPath("ADData", strPath);
  1996. if (Error == Error_Succeed) {
  1997. #ifdef RVC_OS_WIN
  1998. CSimpleStringA VideoPath = strPath + "\\Video\\";
  1999. CSimpleStringA strNoticeFileName = VideoPath + pVideoName;
  2000. BOOL bRet = IsFileExisted(strNoticeFileName.GetData());
  2001. if(bRet){
  2002. static HANDLE noticePlayThread = NULL;
  2003. if (noticePlayThread)
  2004. {
  2005. DWORD exitCode = 0;
  2006. if (WAIT_TIMEOUT == WaitForSingleObject(noticePlayThread, 800))
  2007. {
  2008. m_pVideoPlayer[nCfgInx]->Close();
  2009. }
  2010. noticePlayThread = NULL;
  2011. }
  2012. if (m_pMediaPlayer[nCfgInx]->IsFileValid(strNoticeFileName.GetData())){
  2013. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("m_pVideoPlayer[%d] = 0x%08x while play!",nCfgInx, m_pVideoPlayer[nCfgInx]);
  2014. m_pVideoPlayer[nCfgInx]->PlayVideoNotice(nWndX, nWndY, nWndWidth, nWndHeight, VideoPath.GetData(), pVideoName);;
  2015. int iVolume = 60;
  2016. GetLocalVideoVolume(nCfgInx,iVolume);
  2017. m_pVideoPlayer[nCfgInx]->SetVolume(iVolume);
  2018. m_lastPlayVideo = pVideoName;
  2019. noticePlayThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&NoticePlayThread, this, 0, NULL);
  2020. char strinfo[MAX_PATH] = {0};
  2021. _snprintf(strinfo, MAX_PATH, "start play notice %s", strNoticeFileName.GetData());
  2022. LogWarn(Severity_Low, Error_Debug, LOG_EVT_START_NOTICE_PLAY, strinfo);
  2023. }
  2024. else{
  2025. Error = Error_InvalidState;
  2026. char strerrmsg[MAX_PATH] = { 0 };
  2027. _snprintf(strerrmsg, MAX_PATH, "play notice failed for %s is not valid!", strNoticeFileName.GetData());
  2028. LogWarn(Severity_Low, Error_Debug, LOG_EVT_NOTICE_FILE_NOT_VALID, strerrmsg);
  2029. }
  2030. }
  2031. else{
  2032. Error = Error_InvalidState;
  2033. char strmsg[MAX_PATH] = {0};
  2034. _snprintf(strmsg, MAX_PATH, "play notice failed for %s not exist!", strNoticeFileName.GetData());
  2035. LogWarn(Severity_Low, Error_Debug, LOG_EVT_NOTICE_FILE_NOT_EXIST, strmsg);
  2036. }
  2037. #endif
  2038. }
  2039. return Error;
  2040. }
  2041. #ifdef RVC_OS_WIN
  2042. DWORD WINAPI StartNoticePlayThreadFunc(LPVOID param)
  2043. {
  2044. int iRet = -1;
  2045. CLocalMediaPlayEntity* entity = (CLocalMediaPlayEntity*)param;
  2046. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Enter NoticePlayThreadFunc and process id is %u, thread id is %u.", GetCurrentProcessId(), GetCurrentThreadId());
  2047. const char* pVideoName = entity->m_lastPlayVideo.c_str();
  2048. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Begin Start Notice Play, and Video Notice Info is %s.", pVideoName);
  2049. Clibmediaplayer* player = entity->m_pMediaPlayer[entity->m_mediaParam.nCfgInx];
  2050. player->PlayVideoNotice(entity->m_mediaParam.nWndX, entity->m_mediaParam.nWndY, entity->m_mediaParam.nWndWidth, entity->m_mediaParam.nWndHeight, pVideoName);
  2051. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Succeed to Start Notice Play, and Video Notice Info is %s.", pVideoName);
  2052. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Leave NoticePlayThreadFunc");
  2053. entity->m_uNoticePlayThreadId = NULL;
  2054. iRet = 0;
  2055. return iRet;
  2056. }
  2057. #endif
  2058. ErrorCodeEnum CLocalMediaPlayEntity::StartFFPlayerNotice(int nCfgInx, int nWndX, int nWndY, int nWndWidth, int nWndHeight, const char *pVideoName)
  2059. {
  2060. ErrorCodeEnum Error = Error_Succeed;
  2061. if (m_pMediaAudioPlayer->checkIsPlay()) {
  2062. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("audio current is playing, close it.");
  2063. if (0 != m_uMediaPlayThreadId) {
  2064. m_pMediaAudioPlayer->Close();
  2065. m_uMediaPlayThreadId = 0;
  2066. #ifdef RVC_OS_WIN
  2067. Sleep(500);
  2068. #else
  2069. usleep(500*1000);
  2070. #endif // RVC_OS_WI
  2071. }
  2072. }
  2073. if (m_pMediaPlayer[nCfgInx]->checkIsPlay()) {
  2074. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("video current is playing, close it.");
  2075. if (NULL != m_uNoticePlayThreadId) {
  2076. m_pMediaPlayer[nCfgInx]->Close();
  2077. m_uNoticePlayThreadId = 0;
  2078. #ifdef RVC_OS_WIN
  2079. Sleep(500);
  2080. #else
  2081. usleep(500 * 1000);
  2082. #endif // RVC_OS_WI
  2083. }
  2084. }
  2085. m_mediaParam.nCfgInx = nCfgInx;
  2086. m_mediaParam.nWndX = 1280;
  2087. m_mediaParam.nWndY = 0;
  2088. m_mediaParam.nWndWidth = nWndWidth;
  2089. m_mediaParam.nWndHeight = nWndHeight;
  2090. CSimpleStringA strPath;
  2091. Error = GetFunction()->GetPath("ADData", strPath);
  2092. if (Error == Error_Succeed) {
  2093. CSimpleStringA VideoPath = strPath + "/Video/";
  2094. CSimpleStringA strNoticeFileName = VideoPath + CSimpleStringA(pVideoName);
  2095. BOOL bRet = ExistsFile(strNoticeFileName.GetData());
  2096. if (bRet) {
  2097. if (m_pMediaPlayer[nCfgInx]->IsFileValid(strNoticeFileName.GetData())){
  2098. int iVolume = 60;
  2099. GetLocalVideoVolume(nCfgInx, iVolume);
  2100. m_pMediaPlayer[nCfgInx]->SetVolume(iVolume);
  2101. m_lastPlayVideo = strNoticeFileName.GetData();
  2102. #ifdef RVC_OS_WIN
  2103. m_uNoticePlayThreadId = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&StartNoticePlayThreadFunc, this, 0, NULL);
  2104. if (NULL != m_uNoticePlayThreadId) {
  2105. char strinfo[MAX_PATH] = { 0 };
  2106. _snprintf(strinfo, MAX_PATH, "start play video notice %s", strNoticeFileName.GetData());
  2107. LogWarn(Severity_Low, Error_Debug, LOG_EVT_START_NOTICE_PLAY, strinfo);
  2108. }
  2109. else {
  2110. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create notice play thread failed.");
  2111. }
  2112. #else
  2113. int err = pthread_create(&m_uNoticePlayThreadId, NULL, StartNoticePlayThreadFunc, this);
  2114. if (0 == err) {
  2115. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create notice play thread[%u] success.", m_uNoticePlayThreadId);
  2116. char strinfo[MAX_PATH] = { 0 };
  2117. snprintf(strinfo, MAX_PATH, "start play video notice %s", strNoticeFileName.GetData());
  2118. LogWarn(Severity_Low, Error_Debug, LOG_EVT_START_NOTICE_PLAY, strinfo);
  2119. }
  2120. else {
  2121. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create notice play thread failed.");
  2122. }
  2123. #endif
  2124. }
  2125. else{
  2126. Error = Error_InvalidState;
  2127. char strerrmsg[MAX_PATH] = { 0 };
  2128. #ifdef RVC_OS_WIN
  2129. _snprintf(strerrmsg, MAX_PATH, "play notice failed for %s is not valid!", strNoticeFileName.GetData());
  2130. #else
  2131. snprintf(strerrmsg, MAX_PATH, "play notice failed for %s is not valid!", strNoticeFileName.GetData());
  2132. #endif // RVC_OS_WIN
  2133. LogWarn(Severity_Low, Error_Debug, LOG_EVT_NOTICE_FILE_NOT_VALID, strerrmsg);
  2134. }
  2135. }
  2136. else {
  2137. Error = Error_InvalidState;
  2138. char strmsg[MAX_PATH] = { 0 };
  2139. #ifdef RVC_OS_WIN
  2140. _snprintf(strmsg, MAX_PATH, "play notice failed for %s not exist!", strNoticeFileName.GetData());
  2141. #else
  2142. snprintf(strmsg, MAX_PATH, "play notice failed for %s not exist!", strNoticeFileName.GetData());
  2143. #endif
  2144. LogWarn(Severity_Low, Error_Debug, LOG_EVT_NOTICE_FILE_NOT_EXIST, strmsg);
  2145. }
  2146. }
  2147. return Error;
  2148. }
  2149. ErrorCodeEnum CLocalMediaPlayEntity::StartNotice(int nCfgInx, int nWndX, int nWndY, int nWndWidth, int nWndHeight, const char *pVideoName)
  2150. {
  2151. ErrorCodeEnum Error = Error_Succeed;
  2152. if (eStand2sType == m_eDeviceType || eDesk2SType == m_eDeviceType || eMobilePadType == m_eDeviceType || ePadtype == m_eDeviceType){
  2153. if (nCfgInx >= MAX_PLAY_CHANNELS || nCfgInx < 0 || NULL == pVideoName)
  2154. {
  2155. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Invalid param CfgInx or video name while StartNotice!");
  2156. return Error_Param;
  2157. }
  2158. if (0 == m_iPlayType){
  2159. Error = StartMediaPlayerNotice(nCfgInx, nWndX, nWndY, nWndWidth, nWndHeight, pVideoName);
  2160. }
  2161. else{
  2162. Error = StartFFPlayerNotice(nCfgInx, nWndX, nWndY, nWndWidth, nWndHeight, pVideoName);
  2163. }
  2164. }
  2165. return Error;
  2166. }
  2167. ErrorCodeEnum CLocalMediaPlayEntity::StopNotice(int nCfgInx)
  2168. {
  2169. ErrorCodeEnum ErrorCode = Error_Succeed;
  2170. if (eStand2sType == m_eDeviceType || eDesk2SType == m_eDeviceType || eMobilePadType == m_eDeviceType || ePadtype == m_eDeviceType){
  2171. if (nCfgInx >= MAX_PLAY_CHANNELS || nCfgInx < 0){
  2172. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Invalid CfgInx while StopNotice!");
  2173. return Error_Param;
  2174. }
  2175. #ifdef RVC_OS_WIN
  2176. if (0 == m_iPlayType){
  2177. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("m_pPlayer = 0x%08x while play!", m_pVideoPlayer[nCfgInx]);
  2178. if (FALSE == m_pVideoPlayer[nCfgInx]->checkIsStop()) {
  2179. m_pVideoPlayer[nCfgInx]->Close();
  2180. if (m_lastPlayVideo.length() > 0) {
  2181. char strmsg[MAX_PATH] = { 0 };
  2182. _snprintf(strmsg, MAX_PATH, "%s%s", "success to stop play notice ", m_lastPlayVideo.c_str());
  2183. LogWarn(Severity_Low, Error_Debug, LOG_EVT_STOP_NOTICE_PLAY, strmsg);
  2184. }
  2185. }
  2186. }
  2187. else{
  2188. if (FALSE == m_pMediaPlayer[nCfgInx]->checkIsStop()) {
  2189. m_pMediaPlayer[nCfgInx]->Close();
  2190. if (NULL != m_uNoticePlayThreadId) {
  2191. WaitForSingleObject(m_uNoticePlayThreadId, INFINITE);
  2192. if (m_lastPlayVideo.length() > 0) {
  2193. char strmsg[MAX_PATH] = { 0 };
  2194. _snprintf(strmsg, MAX_PATH, "%s%s", "success to stop play notice ", m_lastPlayVideo.c_str());
  2195. LogWarn(Severity_Low, Error_Debug, LOG_EVT_STOP_NOTICE_PLAY, strmsg);
  2196. }
  2197. m_uNoticePlayThreadId = NULL;
  2198. }
  2199. }
  2200. }
  2201. #else
  2202. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("m_pPlayer = 0x%08x while play!", m_pMediaPlayer[nCfgInx]);
  2203. m_pMediaPlayer[nCfgInx]->Close();
  2204. if (m_uNoticePlayThreadId > 0) {
  2205. if (0 == pthread_join(m_uNoticePlayThreadId, NULL)) {
  2206. if (m_lastPlayVideo.length() > 0) {
  2207. char strmsg[MAX_PATH] = { 0 };
  2208. snprintf(strmsg, MAX_PATH, "%s%s", "success to stop play notice ", m_lastPlayVideo.c_str());
  2209. LogWarn(Severity_Low, Error_Debug, LOG_EVT_STOP_NOTICE_PLAY, strmsg);
  2210. }
  2211. }
  2212. m_uNoticePlayThreadId = 0;
  2213. }
  2214. #endif
  2215. }
  2216. return ErrorCode;
  2217. }
  2218. ErrorCodeEnum CLocalMediaPlayEntity::StopPlayAllMedias()
  2219. {
  2220. ErrorCodeEnum ErrorCode = Error_Succeed;
  2221. StopAll();
  2222. return ErrorCode;
  2223. }
  2224. void CLocalMediaPlayEntity::SetLogFlag(bool bflag)
  2225. {
  2226. m_bLogFlag = bflag;
  2227. }
  2228. bool CLocalMediaPlayEntity::GetLogFlag()
  2229. {
  2230. return m_bLogFlag;
  2231. }
  2232. void CLocalMediaPlayEntity::SetLocalLogFlag(bool bflag)
  2233. {
  2234. m_bLocalLogFlag = bflag;
  2235. }
  2236. bool CLocalMediaPlayEntity::GetLocalLogFlag()
  2237. {
  2238. return m_bLocalLogFlag;
  2239. }
  2240. void CLocalMediaPlayEntity::SetLocalPicLogFlag(bool bflag)
  2241. {
  2242. m_bLocalPicLogFlag = bflag;
  2243. }
  2244. bool CLocalMediaPlayEntity::GetLocalPicLogFlag()
  2245. {
  2246. return m_bLocalPicLogFlag;
  2247. }
  2248. void CLocalMediaPlayEntity::OnSelfTest(EntityTestEnum eTestType, CSmartPointer<ITransactionContext> pTransactionContext)
  2249. {
  2250. if (Test_ShakeHand == eTestType){
  2251. pTransactionContext->SendAnswer(Error_Succeed);
  2252. }
  2253. }
  2254. void CLocalMediaPlaySession::Handle_StartPlayVideo(SpReqAnsContext<PlayService_StartPlayVideo_Req, PlayService_StartPlayVideo_Ans>::Pointer ctx)
  2255. {
  2256. DbgToBeidou(ctx->link, __FUNCTION__)();
  2257. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("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);
  2258. CSimpleStringA UpdateState = "";
  2259. ErrorCodeEnum Error = m_pEntity->GetFunction()->GetSysVar("UpdateState", UpdateState);
  2260. if (Error == Error_Succeed && "1" == UpdateState)
  2261. {
  2262. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("detect current is upgrade, do not play the media");
  2263. ctx->Answer(Error_Stoped);
  2264. m_pEntity->StopAll();
  2265. return;
  2266. }
  2267. if (eStand2sType == m_pEntity->GetDeviceType()){
  2268. m_pEntity->StartVideo(ctx->Req.CfgInx, ctx->Req.WndX, ctx->Req.WndY, ctx->Req.WndWidth, ctx->Req.WndHeight);
  2269. }
  2270. ctx->Answer(Error_Succeed);
  2271. }
  2272. void CLocalMediaPlaySession::Handle_StartPlayAudio(SpReqAnsContext<PlayService_StartPlayAudio_Req, PlayService_StartPlayAudio_Ans>::Pointer ctx)
  2273. {
  2274. DbgToBeidou(ctx->link, __FUNCTION__)();
  2275. CSimpleStringA AudioNames = CSimpleStringW2A(ctx->Req.AudioNames);
  2276. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start play audio, name:%s", AudioNames);
  2277. CSimpleStringA UpdateState = "";
  2278. ErrorCodeEnum Error = m_pEntity->GetFunction()->GetSysVar("UpdateState", UpdateState);
  2279. if (Error == Error_Succeed && "1" == UpdateState)
  2280. {
  2281. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("detect current is upgrade, do not play the media");
  2282. ctx->Answer(Error_Stoped);
  2283. m_pEntity->StopAll();
  2284. return;
  2285. }
  2286. m_pEntity->StartAudio(AudioNames.GetData());
  2287. ctx->Answer(Error_Succeed);
  2288. }
  2289. void CLocalMediaPlaySession::Handle_StartPlayImage(SpReqAnsContext<PlayService_StartPlayImage_Req, PlayService_StartPlayImage_Ans>::Pointer ctx)
  2290. {
  2291. DbgToBeidou(ctx->link, __FUNCTION__)();
  2292. m_pEntity->StartImage(ctx->Req.CfgInx, ctx->Req.WndX, ctx->Req.WndY, ctx->Req.WndWidth, ctx->Req.WndHeight);
  2293. ctx->Answer(Error_Succeed);
  2294. }
  2295. void CLocalMediaPlaySession::Handle_StopPlayVideo(SpReqAnsContext<PlayService_StopPlayVideo_Req, PlayService_StopPlayVideo_Ans>::Pointer ctx)
  2296. {
  2297. DbgToBeidou(ctx->link, __FUNCTION__)();
  2298. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("stop play Video, Index:%d", ctx->Req.CfgInx);
  2299. m_pEntity->StopVideo(ctx->Req.CfgInx);
  2300. ctx->Answer(Error_Succeed);
  2301. }
  2302. void CLocalMediaPlaySession::Handle_StopPlayAudio(SpReqAnsContext<PlayService_StopPlayAudio_Req, PlayService_StopPlayAudio_Ans>::Pointer ctx)
  2303. {
  2304. DbgToBeidou(ctx->link, __FUNCTION__)();
  2305. m_pEntity->StopAudio();
  2306. ctx->Answer(Error_Succeed);
  2307. }
  2308. void CLocalMediaPlaySession::Handle_StopPlayImage(SpReqAnsContext<PlayService_StopPlayImage_Req, PlayService_StopPlayImage_Ans>::Pointer ctx)
  2309. {
  2310. DbgToBeidou(ctx->link, __FUNCTION__)();
  2311. m_pEntity->StopImage(ctx->Req.CfgInx);
  2312. ctx->Answer(Error_Succeed);
  2313. }
  2314. void CLocalMediaPlaySession::OnClose(ErrorCodeEnum)
  2315. {
  2316. }
  2317. void CLocalMediaPlaySession::Handle_GetLocalVideoVolume( SpReqAnsContext<PlayService_GetLocalVideoVolume_Req, PlayService_GetLocalVideoVolume_Ans>::Pointer ctx )
  2318. {
  2319. DbgToBeidou(ctx->link, __FUNCTION__)();
  2320. int volume = 0;
  2321. if (m_pEntity->GetLocalVideoVolume(ctx->Req.CfgInx, volume)){
  2322. ctx->Ans.Volume = volume;
  2323. ctx->Answer(Error_Succeed);
  2324. }
  2325. else{
  2326. ctx->Answer(Error_Unexpect);
  2327. }
  2328. }
  2329. void CLocalMediaPlaySession::Handle_SetLocalVideoVolume( SpReqAnsContext<PlayService_SetLocalVideoVolume_Req, PlayService_SetLocalVideoVolume_Ans>::Pointer ctx )
  2330. {
  2331. DbgToBeidou(ctx->link, __FUNCTION__)();
  2332. if (m_pEntity->SetLocalVideoVolume(ctx->Req.CfgInx, ctx->Req.Volume)){
  2333. ctx->Answer(Error_Succeed);
  2334. }
  2335. else{
  2336. ctx->Answer(Error_Unexpect);
  2337. }
  2338. }
  2339. void CLocalMediaPlaySession::Handle_GetLocalAudioVolume(SpReqAnsContext<PlayService_GetLocalAudioVolume_Req, PlayService_GetLocalAudioVolume_Ans>::Pointer ctx)
  2340. {
  2341. DbgToBeidou(ctx->link, __FUNCTION__)();
  2342. auto audioRet = m_pEntity->GetLocalAudioVolume();
  2343. if (audioRet.first){
  2344. ctx->Ans.Volume = audioRet.second;
  2345. ctx->Answer(Error_Succeed);
  2346. }
  2347. else{
  2348. ctx->Answer(Error_Unexpect);
  2349. }
  2350. }
  2351. void CLocalMediaPlaySession::Handle_SetLocalAudioVolume(SpReqAnsContext<PlayService_SetLocalAudioVolume_Req, PlayService_SetLocalAudioVolume_Ans>::Pointer ctx)
  2352. {
  2353. DbgToBeidou(ctx->link, __FUNCTION__)();
  2354. if (m_pEntity->SetLocalAudioVolume(ctx->Req.Volume)){
  2355. ctx->Answer(Error_Succeed);
  2356. }
  2357. else{
  2358. ctx->Answer(Error_Unexpect);
  2359. }
  2360. }
  2361. void CLocalMediaPlaySession::Handle_StartPlayNotice(SpReqAnsContext<PlayService_StartPlayNotice_Req, PlayService_StartPlayNotice_Ans>::Pointer ctx)
  2362. {
  2363. DbgToBeidou(ctx->link, __FUNCTION__)();
  2364. CSimpleStringA UpdateState = "";
  2365. ErrorCodeEnum Error = m_pEntity->GetFunction()->GetSysVar("UpdateState", UpdateState);
  2366. if (Error == Error_Succeed && "1" == UpdateState){
  2367. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("detect current is upgrade, do not play the media");
  2368. ctx->Answer(Error_Stoped);
  2369. m_pEntity->StopAll();
  2370. return;
  2371. }
  2372. CSimpleStringA VideoName = CSimpleStringW2A(ctx->Req.VideoName);
  2373. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("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());
  2374. Error = m_pEntity->StartNotice(ctx->Req.CfgInx, ctx->Req.WndX, ctx->Req.WndY, ctx->Req.WndWidth, ctx->Req.WndHeight, VideoName.GetData());
  2375. ctx->Answer(Error);
  2376. }
  2377. void CLocalMediaPlaySession::Handle_StopPlayNotice(SpReqAnsContext<PlayService_StopPlayNotice_Req, PlayService_StopPlayNotice_Ans>::Pointer ctx)
  2378. {
  2379. DbgToBeidou(ctx->link, __FUNCTION__)();
  2380. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("stop play notice, Index:%d", ctx->Req.CfgInx);
  2381. ErrorCodeEnum Error = m_pEntity->StopNotice(ctx->Req.CfgInx);
  2382. ctx->Answer(Error);
  2383. }
  2384. void CLocalMediaPlaySession::Handle_StopPlayAllMedias(SpReqAnsContext<PlayService_StopPlayAllMedias_Req, PlayService_StopPlayAllMedias_Ans>::Pointer ctx)
  2385. {
  2386. DbgToBeidou(ctx->link, __FUNCTION__)();
  2387. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("stop play all medias");
  2388. ErrorCodeEnum Error = m_pEntity->StopPlayAllMedias();
  2389. ctx->Answer(Error);
  2390. }
  2391. SP_BEGIN_ENTITY_MAP()
  2392. SP_ENTITY(CLocalMediaPlayEntity)
  2393. SP_END_ENTITY_MAP()