mod_localmediaplay.cpp 76 KB

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