mod_localmediaplay.cpp 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638
  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. ErrorCodeEnum CLocalMediaPlayEntity::LoadEntityConfig()
  842. {
  843. SpIniMappingTable table;
  844. int iPlayType = 0;
  845. int iMediaLogLevel = (int)MEDIA_LOG_INFO;
  846. int iPicLogLevel = (int)PIC_LOG_INFO;
  847. bool bRecordPCM = false;
  848. table.AddEntryInt("LocalMediaPlay", "PlayType", iPlayType, 0);
  849. table.AddEntryInt("LocalMediaPlay", "MediaLevel", iMediaLogLevel, (int)MEDIA_LOG_INFO);
  850. table.AddEntryInt("LocalMediaPlay", "PicLevel", iPicLogLevel, (int)PIC_LOG_INFO);
  851. table.AddEntryBoolean("SalesRecorder", "IsRecordPCM", bRecordPCM, false);
  852. CSmartPointer<IConfigInfo> spConfig;
  853. ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_CenterSetting, spConfig);
  854. if (Error == Error_Succeed) {
  855. Error = table.Load(spConfig);
  856. if (Error_Succeed == Error){
  857. m_iPlayType = iPlayType;
  858. if (iMediaLogLevel <= MEDIA_LOG_ERROR && iMediaLogLevel > 0){
  859. m_medialevel = (media_loglevel)iMediaLogLevel;
  860. }
  861. if (iPicLogLevel <= PIC_LOG_ERROR && iPicLogLevel > 0) {
  862. m_piclevel = (pic_loglevel)iPicLogLevel;
  863. }
  864. if (bRecordPCM) {
  865. m_bRecordPCM = true;
  866. }
  867. }
  868. }
  869. #ifdef RVC_OS_LINUX
  870. m_iPlayType = 1;
  871. #endif // RVC_OS_LINUX
  872. return Error;
  873. }
  874. void CLocalMediaPlayEntity::OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID, const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  875. const DWORD dwSysError, const DWORD dwUserCode, const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  876. const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage, const linkContext &pLinkInfo)
  877. {
  878. if (LOG_EVT_HEALTHMANAGER_BROWSER_IDLE == dwUserCode){
  879. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("IEBrowser to idle, stop all media!");
  880. StopAll();
  881. }
  882. else if(LOG_EVT_UI_STARTREMOTERECORD == dwUserCode){
  883. if (0 != m_iPlayType){
  884. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Start remote record.");
  885. HandleRemoteRecord(pszMessage);
  886. }
  887. }
  888. else if (LOG_EVT_UI_STOPREMOTERECORD == dwUserCode) {
  889. if (0 != m_iPlayType){
  890. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Stop remote record.");
  891. m_bStartRecord = false;
  892. m_iseriesnumber = 0;
  893. m_leftlen = 0;
  894. if (NULL != m_remote_audio_queue) {
  895. delete m_remote_audio_queue;
  896. m_remote_audio_queue = NULL;
  897. }
  898. if (m_pFile) {
  899. fclose(m_pFile);
  900. m_pFile = NULL;
  901. }
  902. }
  903. }
  904. }
  905. void CLocalMediaPlayEntity::OnPreStart(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext)
  906. {
  907. ErrorCodeEnum Error = __OnStart(Error_Succeed);
  908. pTransactionContext->SendAnswer(Error);
  909. }
  910. ErrorCodeEnum CLocalMediaPlayEntity::__OnStart(ErrorCodeEnum preOperationError)
  911. {
  912. m_eDeviceType = RvcGetDeviceType();
  913. if (Error_Succeed != LoadEntityConfig()){
  914. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("LoadEntityConfig failed.");
  915. }
  916. return Error_Succeed;
  917. }
  918. void CLocalMediaPlayEntity::OnStarted()
  919. {
  920. LogEvent(Severity_Middle, LOG_EVT_MOD_LOCALPLAYER_STARTED_SUCCESS, "local media play entity started successfully.");
  921. GetAudioOutDev();
  922. for (int i = 0; i != MAX_PLAY_CHANNELS; ++i)
  923. {
  924. #ifdef RVC_OS_WIN
  925. m_pVideoPlayer[i] = new Clibwmpplayer(this);
  926. m_pImagePlayer[i] = new Clibimgplayer(this);
  927. #endif
  928. mediaplayer_init();
  929. m_pMediaPlayer[i] = new Clibmediaplayer(this);
  930. m_pPicturePlayer[i] = new Clibpictureplayer(this);
  931. }
  932. m_pMediaAudioPlayer = new Clibmediaplayer(this);
  933. #ifdef RVC_OS_WIN
  934. m_pAudioPlayer = new Clibwmpplayer(this);
  935. #else
  936. signal(SIGTERM, sig_handler);
  937. #endif // RVC_OS_WIN
  938. if (!IsRunConfigExist()){
  939. SetLocalVideoVolume(0, 50);
  940. SetLocalAudioVolume(50);
  941. }
  942. setMediaPath();
  943. loadDefaultMedia(0 != m_iPlayType);
  944. GetFunction()->SubscribeLog(m_SubIDIEIdle, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_HEALTHMANAGER_BROWSER_IDLE, NULL, false);
  945. GetFunction()->SubscribeLog(m_SubIDStartRecord, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTREMOTERECORD, NULL, false);
  946. GetFunction()->SubscribeLog(m_SubIDStopRecord, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPREMOTERECORD, NULL, false);
  947. if (eStand2sType == m_eDeviceType) {
  948. #ifdef RVC_OS_WIN
  949. m_scanThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&qryMedia, this, 0, NULL);
  950. if (NULL == m_scanThread) {
  951. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create queryMedia thread failed.");
  952. }
  953. #else
  954. int err = pthread_create(&m_scanThreadId, NULL, queryMedia, this);
  955. if (0 != err) {
  956. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create queryMedia thread failed.");
  957. }
  958. #endif // RVC_OS_WIN
  959. }
  960. }
  961. void CLocalMediaPlayEntity::OnPreClose(EntityCloseCauseEnum eCloseCause, CSmartPointer<ITransactionContext> pTransactionContext)
  962. {
  963. ErrorCodeEnum Error = __OnClose(Error_Succeed);
  964. pTransactionContext->SendAnswer(Error);
  965. }
  966. ErrorCodeEnum CLocalMediaPlayEntity::__OnClose(ErrorCodeEnum preOperationError)
  967. {
  968. for (int i = 0; i != MAX_PLAY_CHANNELS; ++i)
  969. {
  970. #ifdef RVC_OS_WIN
  971. delete m_pVideoPlayer[i];
  972. m_pVideoPlayer[i] = NULL;
  973. delete m_pImagePlayer[i];
  974. m_pImagePlayer[i] = NULL;
  975. #endif // RVC_OS_WIN
  976. delete m_pMediaPlayer[i];
  977. m_pMediaPlayer[i] = NULL;
  978. delete m_pPicturePlayer[i];
  979. m_pPicturePlayer[i] = NULL;
  980. }
  981. #ifdef RVC_OS_WIN
  982. delete m_pAudioPlayer;
  983. m_pAudioPlayer = NULL;
  984. #endif
  985. delete m_pMediaAudioPlayer;
  986. m_pMediaAudioPlayer = NULL;
  987. GetFunction()->UnsubscribeLog(m_SubIDIEIdle);
  988. GetFunction()->UnsubscribeLog(m_SubIDStartRecord);
  989. GetFunction()->UnsubscribeLog(m_SubIDStopRecord);
  990. // 释放播放对象
  991. if (0 != m_iPlayType){
  992. mediaplayer_term();
  993. }
  994. return Error_Succeed;
  995. }
  996. ErrorCodeEnum CLocalMediaPlayEntity::HandleRemoteRecord(const char* pszMessage)
  997. {
  998. ErrorCodeEnum Error = Error_Succeed;
  999. m_bStartRecord = true;
  1000. memset(m_audiobuffer, 0, RVC_AUDIO_LEN);
  1001. m_leftlen = 0;
  1002. m_remote_audio_queue = new Clibaudioqueue(REC_COMMON_REMOTEAUDIO_SHM_QUEUE);
  1003. m_iseriesnumber = 0;
  1004. m_bloged = false;
  1005. if (true == m_bRecordPCM){
  1006. char strSwiftName[MAX_PATH] = { 0 };
  1007. if (NULL != pszMessage) {
  1008. size_t ulen = strlen(pszMessage);
  1009. char* tmp = new char[ulen + 1];
  1010. memset(tmp, 0, ulen + 1);
  1011. memcpy(tmp, pszMessage, ulen);
  1012. char* result[16] = { 0 };
  1013. auto arr1 = CSimpleStringA2W(tmp).Split('@');
  1014. auto arr2 = CAutoArray<CSimpleStringA>(arr1.GetCount());
  1015. for (int i = 0; i < arr1.GetCount(); ++i) {
  1016. arr2[i] = CSimpleStringW2A(arr1[i]);
  1017. result[i] = const_cast<LPSTR>(arr2[i].GetData());
  1018. }
  1019. if (arr1.GetCount() > 4) {
  1020. #ifdef RVC_OS_WIN
  1021. _snprintf(strSwiftName, MAX_PATH, "%s", result[4]);
  1022. #else
  1023. snprintf(strSwiftName, MAX_PATH, "%s", result[4]);
  1024. #endif // RVC_OS_WIN
  1025. }
  1026. delete tmp;
  1027. tmp = NULL;
  1028. }
  1029. CSimpleStringA strTempDir("");
  1030. CSimpleStringA strName("");
  1031. if (Error_Succeed == GetFunction()->GetPath("Temp", strTempDir)) {
  1032. strName = CSimpleStringA::Format("%s/remote_audio_notice_%s.pcm", strTempDir.GetData(), strSwiftName);
  1033. }
  1034. else {
  1035. strName = CSimpleStringA::Format("remote_audio_notice_%s.pcm", strSwiftName);
  1036. }
  1037. m_pFile = fopen(strName.GetData(), "wb+");
  1038. if (NULL == m_pFile) {
  1039. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("fopen %s failed.", strName.GetData());
  1040. }
  1041. }
  1042. return Error;
  1043. }
  1044. #ifdef RVC_OS_WIN
  1045. DWORD WINAPI StartAudioPlayingThreadFunc(LPVOID param)
  1046. {
  1047. CLocalMediaPlayEntity* entity = (CLocalMediaPlayEntity*)param;
  1048. const char* pAudioNames = entity->m_lastPlayAudio.c_str();
  1049. if (0 == entity->m_iPlayType) {
  1050. HANDLE playEndEvent = NULL;
  1051. entity->m_pAudioPlayer->PlayLocalAudio(pAudioNames);
  1052. if (!entity->m_pAudioPlayer->checkIsPlay(playEndEvent)) {
  1053. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Get audio Play End Event Failed!");
  1054. }
  1055. else {
  1056. WaitForSingleObject(playEndEvent, INFINITE);
  1057. if (entity->m_pAudioPlayer->checkIsStop()) {
  1058. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("stop audio play success.");
  1059. }
  1060. else {
  1061. entity->m_pAudioPlayer->Close();
  1062. }
  1063. }
  1064. }
  1065. else {
  1066. if (0 != entity->m_pMediaAudioPlayer->PlayLocalAudio(pAudioNames)) {
  1067. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("StartAudio failed, for %s is not exist.", pAudioNames);
  1068. }
  1069. }
  1070. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Leave StartAudioPlayingThreadFunc");
  1071. entity->m_uMediaPlayThreadId = NULL;
  1072. return 0;
  1073. }
  1074. DWORD WINAPI NoticePlayThread(LPVOID param)
  1075. {
  1076. CLocalMediaPlayEntity *entity = (CLocalMediaPlayEntity*)param;
  1077. HANDLE playEndEvent = NULL;
  1078. if (!entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(playEndEvent)){
  1079. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Get notice play end event failed!");
  1080. return 0;
  1081. }
  1082. bool bPlayFinished = FALSE;
  1083. for (;;) {
  1084. DWORD dwRet = WaitForSingleObject(playEndEvent, 100);
  1085. if (dwRet == WAIT_OBJECT_0) { // exit
  1086. bPlayFinished = true;
  1087. break;
  1088. }
  1089. else { // timeout
  1090. if (entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->checkIsStop()){
  1091. break;
  1092. }
  1093. }
  1094. }
  1095. entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->Close();
  1096. if (bPlayFinished){
  1097. VideoPlayRet ret;
  1098. ret.VideoNames = entity->m_lastPlayVideo.c_str();
  1099. ret.ret = true;
  1100. SpSendBroadcast(entity->GetFunction(), eMsg_VideoPlayRet, eMsgSig_VideoPlayRet, ret);
  1101. //LogWarn(Severity_Low, Error_Debug, LOG_EVT_NOTICE_PLAY_FINISHED, CSimpleStringA::Format("notice %s play finished.", ret.VideoNames.GetData()).GetData());
  1102. }
  1103. else{
  1104. //LogWarn(Severity_Low, Error_Debug, LOG_EVT_NOTICE_PLAY_EARLY_TERM, CSimpleStringA::Format("notice %s play early terminate.", entity->m_lastPlayVideo.c_str()).GetData());
  1105. }
  1106. entity->m_lastPlayVideo.clear();
  1107. return 0;
  1108. }
  1109. DWORD WINAPI MediaPlayThread(LPVOID param)
  1110. {
  1111. CLocalMediaPlayEntity *entity = (CLocalMediaPlayEntity*)param;
  1112. static bool blog = true;
  1113. while (entity->GetPlayFlag())
  1114. {
  1115. vector<ResourceParse> curParse;
  1116. entity->m_mediaManage.GetPlayListByLocal(curParse);
  1117. unsigned int ustart_time = y2k_time_now();
  1118. if (0 == curParse.size())
  1119. {
  1120. HANDLE playThread = NULL;
  1121. CWmpPlayConfig config;
  1122. ZeroMemory(&config, sizeof(CWmpPlayConfig));
  1123. memcpy(&config, &(entity->m_defaultVideo[entity->m_mediaParam.nCfgInx]), sizeof(CWmpPlayConfig));
  1124. config.nPlayCnt = 1; //can be change
  1125. config.eMode = LOCALVIDEO;
  1126. config.nWndX = entity->m_mediaParam.nWndX;
  1127. config.nWndY = entity->m_mediaParam.nWndY;
  1128. config.nWndWidth = entity->m_mediaParam.nWndWidth;
  1129. config.nWndHeight = entity->m_mediaParam.nWndHeight;
  1130. config.bPrimMonitor = false;
  1131. if (IS_DEBUG){
  1132. config.bFullScreen = false;
  1133. config.bPrimMonitor = true;
  1134. }
  1135. if (!CheckFileExist(config.strRootPath, config.strFileNames[0], blog)){
  1136. break;
  1137. }
  1138. if (false == IsValidPlayTime(config.strVideoRunTime_S, config.strVideoRunTime_E)){
  1139. if (WAIT_TIMEOUT == WaitForSingleObject(entity->m_hStopMediaPlayEvent, 30*DEFAULT_SLEEP_TIME)) {
  1140. continue;
  1141. }
  1142. else {
  1143. break;
  1144. }
  1145. }
  1146. if (!entity->GetLocalVideoVolume(0, config.nVolume)){
  1147. config.nVolume = entity->m_defaultVolum;
  1148. }
  1149. entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
  1150. if (!entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(playThread)){
  1151. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Get Play End Event Failed!");
  1152. }
  1153. else{
  1154. WaitForSingleObject(playThread, INFINITE);
  1155. if (entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->checkIsStop()){//停止播放
  1156. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("stop play video");
  1157. }
  1158. else{
  1159. entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->Close();
  1160. }
  1161. }
  1162. }
  1163. else
  1164. {
  1165. for (vector<ResourceParse>::iterator i = curParse.begin(); i != curParse.end() && entity->GetPlayFlag(); i++)
  1166. {
  1167. HANDLE playThread = NULL;
  1168. if ('V' == i->type)
  1169. {//video
  1170. CWmpPlayConfig config;
  1171. ZeroMemory(&config, sizeof(CWmpPlayConfig));
  1172. config.bFullScreen = IS_DEBUG ? false : i->fullScreen;
  1173. config.bPrimMonitor = IS_DEBUG ? true : false;
  1174. config.bSimpleMode = i->simpleMode;
  1175. config.eMode = LOCALVIDEO;
  1176. config.nFileCnt = 1;
  1177. config.nPlayCnt = 1;
  1178. config.nPlayInterval = i->playInterval;
  1179. if (!entity->GetLocalVideoVolume(0, config.nVolume)){
  1180. config.nVolume = entity->m_defaultVolum;
  1181. }
  1182. config.nWndX = entity->m_mediaParam.nWndX;
  1183. config.nWndY = entity->m_mediaParam.nWndY;
  1184. config.nWndWidth = entity->m_mediaParam.nWndWidth;
  1185. config.nWndHeight = entity->m_mediaParam.nWndHeight;
  1186. strncpy_s(config.strRootPath, i->resourcePath.c_str(), sizeof(config.strRootPath));
  1187. strncpy_s(config.strFileNames[0], i->videoNames.c_str(), 256);
  1188. strncpy_s(config.strVideoRunTime_S, RVC_VIDEOPLAY_START_TIME, sizeof(config.strVideoRunTime_S));
  1189. strncpy_s(config.strVideoRunTime_E, RVC_VIDEOPLAY_END_TIME, sizeof(config.strVideoRunTime_E));
  1190. if (false == IsValidPlayTime(config.strVideoRunTime_S, config.strVideoRunTime_E)) {
  1191. if (WAIT_TIMEOUT == WaitForSingleObject(entity->m_hStopMediaPlayEvent, 30 * DEFAULT_SLEEP_TIME)) {
  1192. continue;
  1193. }
  1194. else {
  1195. break;
  1196. }
  1197. }
  1198. if(!CheckFileExist(config.strRootPath, config.strFileNames[0], blog)){
  1199. continue;
  1200. }
  1201. entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
  1202. if (!entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(playThread)){
  1203. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Get Play End Event Failed!");
  1204. }
  1205. else{
  1206. WaitForSingleObject(playThread, INFINITE);
  1207. if (entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->checkIsStop()){//停止播放
  1208. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("stop play video");
  1209. }
  1210. else{
  1211. entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->Close();
  1212. }
  1213. }
  1214. }
  1215. else if ('P' == i->type)
  1216. {//play Image
  1217. CImgPlayConfig config;
  1218. ZeroMemory(&config, sizeof(CImgPlayConfig));
  1219. config.bFullScreen = IS_DEBUG ? false : i->fullScreen;
  1220. config.bPrimMonitor = IS_DEBUG ? true : false;
  1221. config.nFileCnt = 1;
  1222. config.nPlayCnt = 1;
  1223. config.nPlayInterval = i->playInterval;
  1224. config.nWndX = entity->m_mediaParam.nWndX;
  1225. config.nWndY = entity->m_mediaParam.nWndY;
  1226. config.nWndWidth = entity->m_mediaParam.nWndWidth;
  1227. config.nWndHeight = entity->m_mediaParam.nWndHeight;
  1228. strncpy_s(config.strRootPath, i->resourcePath.c_str(), sizeof(config.strRootPath));
  1229. strncpy_s(config.strFileNames[0], i->videoNames.c_str(), 256);
  1230. if (!CheckFileExist(config.strRootPath, config.strFileNames[0], blog)) {
  1231. continue;
  1232. }
  1233. entity->m_pImagePlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
  1234. if (!entity->m_pImagePlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(playThread)){
  1235. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Create play Image Media Thread Failed!");
  1236. }
  1237. else
  1238. {
  1239. WaitForSingleObject(playThread, i->playInterval);
  1240. if (entity->m_pImagePlayer[entity->m_mediaParam.nCfgInx]->checkIsStop()){//停止播放
  1241. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("stop play Image");
  1242. }
  1243. else{
  1244. entity->m_pImagePlayer[entity->m_mediaParam.nCfgInx]->Close();
  1245. }
  1246. }
  1247. }
  1248. }
  1249. }
  1250. unsigned int uend_time = y2k_time_now();
  1251. if (uend_time - ustart_time < RVC_MIN_LOCALPLAYER_TIME) {
  1252. LogWarn(Severity_Low, Error_Debug, LOG_EVT_MEDIAPLAY_COST_TIME_ERROR, "广告播放时长不足1秒");
  1253. break;
  1254. }
  1255. blog = false;
  1256. }
  1257. if (entity->m_badplayflag) {
  1258. entity->m_badplayflag = false;
  1259. }
  1260. if (entity->m_playThread) {
  1261. entity->m_playThread = NULL;
  1262. }
  1263. return 0;
  1264. }
  1265. DWORD WINAPI StartMediaPlayFunc(LPVOID param)
  1266. {
  1267. int iRet = -1;
  1268. if (NULL == param){
  1269. return iRet;
  1270. }
  1271. CLocalMediaPlayEntity* entity = (CLocalMediaPlayEntity*)param;
  1272. static bool blog = true;
  1273. while (entity->GetPlayFlag())
  1274. {
  1275. vector<ResourceParse> curParse;
  1276. entity->m_mediaManage.GetPlayListByLocal(curParse);
  1277. unsigned int ustart_time = y2k_time_now();
  1278. if (0 == curParse.size()){
  1279. CMediaPlayConfig config = {0};
  1280. memcpy(&config, &(entity->m_Videos[entity->m_mediaParam.nCfgInx]), sizeof(CMediaPlayConfig));
  1281. config.nPlayCnt = 1; //can be change
  1282. config.eMode = MEDIA_LOCALVIDEO;
  1283. config.nWndX = entity->m_mediaParam.nWndX;
  1284. config.nWndY = entity->m_mediaParam.nWndY;
  1285. config.nWndWidth = entity->m_mediaParam.nWndWidth;
  1286. config.nWndHeight = entity->m_mediaParam.nWndHeight;
  1287. config.bPrimMonitor = false;
  1288. if (IS_DEBUG){
  1289. config.bFullScreen = false;
  1290. config.bPrimMonitor = true;
  1291. }
  1292. if (!entity->GetLocalVideoVolume(0, config.nVolume)){
  1293. config.nVolume = entity->m_defaultVolum;
  1294. }
  1295. if(false == IsValidPlayTime(config.strVideoRunTime_S, config.strVideoRunTime_E)){
  1296. if (WAIT_TIMEOUT == WaitForSingleObject(entity->m_hStopMediaPlayEvent, 30 * DEFAULT_SLEEP_TIME)) {
  1297. continue;
  1298. }
  1299. else {
  1300. break;
  1301. }
  1302. }
  1303. if (!CheckFileExist(config.strRootPath, config.strFileNames[0], blog)) {
  1304. break;
  1305. }
  1306. if (-1 == entity->m_pMediaPlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config)){
  1307. break;
  1308. }
  1309. }
  1310. for (int i = 0; i < curParse.size() && entity->GetPlayFlag(); i++)
  1311. {
  1312. HANDLE playThreadId = 0;
  1313. ResourceParse item = curParse[i];
  1314. if ('V' == item.type)
  1315. {//video
  1316. CMediaPlayConfig config = {0};
  1317. config.bFullScreen = IS_DEBUG ? false : item.fullScreen;
  1318. config.bPrimMonitor = IS_DEBUG ? true : false;
  1319. config.bSimpleMode = item.simpleMode;
  1320. config.eMode = MEDIA_LOCALVIDEO;
  1321. config.nFileCnt = 1;
  1322. config.nPlayCnt = 1;
  1323. config.nPlayInterval = item.playInterval;
  1324. if (!entity->GetLocalVideoVolume(0, config.nVolume)){
  1325. config.nVolume = entity->m_defaultVolum;
  1326. }
  1327. config.nWndX = entity->m_mediaParam.nWndX;
  1328. config.nWndY = entity->m_mediaParam.nWndY;
  1329. config.nWndWidth = entity->m_mediaParam.nWndWidth;
  1330. config.nWndHeight = entity->m_mediaParam.nWndHeight;
  1331. strncpy(config.strRootPath, item.resourcePath.c_str(), item.resourcePath.length() < MAX_PATH ? item.resourcePath.length() : MAX_PATH);
  1332. strncpy(config.strFileNames[0], item.videoNames.c_str(), item.videoNames.length() < MAX_PATH ? item.videoNames.length() : MAX_PATH);
  1333. strncpy(config.strVideoRunTime_S, RVC_VIDEOPLAY_START_TIME, sizeof(config.strVideoRunTime_S));
  1334. strncpy(config.strVideoRunTime_E, RVC_VIDEOPLAY_END_TIME, sizeof(config.strVideoRunTime_E));
  1335. if (false == IsValidPlayTime(config.strVideoRunTime_S, config.strVideoRunTime_E)){
  1336. if (WAIT_TIMEOUT == WaitForSingleObject(entity->m_hStopMediaPlayEvent, 30 * DEFAULT_SLEEP_TIME)) {
  1337. continue;
  1338. }
  1339. else {
  1340. break;
  1341. }
  1342. }
  1343. if (!CheckFileExist(config.strRootPath, config.strFileNames[0], blog)) {
  1344. continue;
  1345. }
  1346. int iPlayRet = entity->m_pMediaPlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
  1347. if (-3 == iPlayRet) {
  1348. if (WAIT_TIMEOUT == WaitForSingleObject(entity->m_hStopMediaPlayEvent, DEFAULT_SLEEP_TIME)) {
  1349. continue;
  1350. }
  1351. else {
  1352. break;
  1353. }
  1354. }
  1355. }
  1356. else if ('P' == item.type)
  1357. {//play Image
  1358. CPicPlayConfig config = {0};
  1359. config.bFullScreen = IS_DEBUG ? false : item.fullScreen;
  1360. config.bPrimMonitor = IS_DEBUG ? true : false;
  1361. config.nFileCnt = 1;
  1362. config.nPlayCnt = 1;
  1363. config.nPlayInterval = item.playInterval;
  1364. config.nWndX = entity->m_mediaParam.nWndX;
  1365. config.nWndY = entity->m_mediaParam.nWndY;
  1366. config.nWndWidth = entity->m_mediaParam.nWndWidth;
  1367. config.nWndHeight = entity->m_mediaParam.nWndHeight;
  1368. strncpy(config.strRootPath, item.resourcePath.c_str(), item.resourcePath.length() < MAX_PATH ? item.resourcePath.length() : MAX_PATH);
  1369. strncpy(config.strFileNames[0], item.videoNames.c_str(), item.videoNames.length() < MAX_PATH ? item.videoNames.length() : MAX_PATH);
  1370. if (!CheckFileExist(config.strRootPath, config.strFileNames[0], blog)) {
  1371. continue;
  1372. }
  1373. if (entity->m_pPicturePlayer[entity->m_mediaParam.nCfgInx]->checkIsStop()){
  1374. entity->m_pPicturePlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
  1375. if (!entity->m_pPicturePlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(&playThreadId)) {
  1376. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Create play Image Media Thread Failed!");
  1377. iRet = -1;
  1378. return iRet;
  1379. }
  1380. WaitForSingleObject(playThreadId, INFINITE);
  1381. if (entity->m_pPicturePlayer[entity->m_mediaParam.nCfgInx]->checkIsStop()){//停止播放
  1382. }
  1383. else{
  1384. entity->m_pPicturePlayer[entity->m_mediaParam.nCfgInx]->Close();
  1385. }
  1386. }
  1387. }
  1388. }
  1389. unsigned int uend_time = y2k_time_now();
  1390. if (uend_time - ustart_time < RVC_MIN_LOCALPLAYER_TIME) {
  1391. LogWarn(Severity_Low, Error_Debug, LOG_EVT_MEDIAPLAY_COST_TIME_ERROR, "广告播放时长不足1秒");
  1392. break;
  1393. }
  1394. blog = false;
  1395. }
  1396. if (entity->m_badplayflag) {
  1397. entity->m_badplayflag = false;
  1398. }
  1399. if (0 != entity->m_uMediaPlayThreadId) {
  1400. entity->m_uMediaPlayThreadId = 0;
  1401. }
  1402. return iRet;
  1403. }
  1404. #else
  1405. void* StartAudioPlayingThreadFunc(void* param)
  1406. {
  1407. CLocalMediaPlayEntity* entity = (CLocalMediaPlayEntity*)param;
  1408. const char* pAudioNames = entity->m_lastPlayAudio.c_str();
  1409. if (0 != entity->m_pMediaAudioPlayer->PlayLocalAudio(pAudioNames)) {
  1410. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("StartAudio failed, for %s is not exsit.", pAudioNames);
  1411. }
  1412. entity->m_uAudioPlayThreadId = 0;
  1413. return 0;
  1414. }
  1415. void* StartMediaPlayFunc(void* param)
  1416. {
  1417. int iRet = -1;
  1418. if (NULL == param) {
  1419. return (void*)&iRet;
  1420. }
  1421. CLocalMediaPlayEntity* entity = (CLocalMediaPlayEntity*)param;
  1422. static bool blog = true;
  1423. while (entity->GetPlayFlag())
  1424. {
  1425. rvcResourceParse_t ResourceList[MAX_LOCAL_MEDIAS] = { 0 };
  1426. int iCount = entity->m_mediaManage.GetPlayListByLocal(ResourceList, MAX_LOCAL_MEDIAS);
  1427. unsigned int ustart_time = y2k_time_now();
  1428. if (0 == iCount) {
  1429. int64_t playThreadId = 0;
  1430. CMediaPlayConfig config = { 0 };
  1431. memcpy(&config, &(entity->m_Videos[entity->m_mediaParam.nCfgInx]), sizeof(CMediaPlayConfig));
  1432. config.nPlayCnt = 1; //can be change
  1433. config.eMode = MEDIA_LOCALVIDEO;
  1434. config.nWndX = entity->m_mediaParam.nWndX;
  1435. config.nWndY = entity->m_mediaParam.nWndY;
  1436. config.nWndWidth = entity->m_mediaParam.nWndWidth;
  1437. config.nWndHeight = entity->m_mediaParam.nWndHeight;
  1438. config.bPrimMonitor = false;
  1439. if (IS_DEBUG) {
  1440. config.bFullScreen = false;
  1441. config.bPrimMonitor = true;
  1442. }
  1443. if (!entity->GetLocalVideoVolume(0, config.nVolume)) {
  1444. config.nVolume = entity->m_defaultVolum;
  1445. }
  1446. if (false == IsValidPlayTime(config.strVideoRunTime_S, config.strVideoRunTime_E)){
  1447. struct timespec ts;
  1448. clock_gettime(CLOCK_REALTIME, &ts);
  1449. ts.tv_sec += 30;
  1450. int iresult = sem_timedwait(&entity->m_stop_mediaplay_semt, &ts);
  1451. if (0 != iresult && (ETIMEDOUT == errno)) {
  1452. continue;
  1453. }
  1454. else {
  1455. break;
  1456. }
  1457. }
  1458. if (!CheckFileExist(config.strRootPath, config.strFileNames[0], blog)) {
  1459. break;
  1460. }
  1461. if (-1 == entity->m_pMediaPlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config)) {
  1462. break;
  1463. }
  1464. }
  1465. for (int i = 0; i < iCount && i < MAX_LOCAL_MEDIAS && entity->GetPlayFlag(); i++)
  1466. {
  1467. int64_t playThreadId = 0;
  1468. rvcResourceParse_t item = ResourceList[i];
  1469. if ('V' == item.type)
  1470. {//video
  1471. CMediaPlayConfig config = { 0 };
  1472. config.bFullScreen = IS_DEBUG ? false : item.fullScreen;
  1473. config.bPrimMonitor = IS_DEBUG ? true : false;
  1474. config.bSimpleMode = item.simpleMode;
  1475. config.eMode = MEDIA_LOCALVIDEO;
  1476. config.nFileCnt = 1;
  1477. config.nPlayCnt = 1;
  1478. config.nPlayInterval = item.playInterval;
  1479. if (!entity->GetLocalVideoVolume(0, config.nVolume)) {
  1480. config.nVolume = entity->m_defaultVolum;
  1481. }
  1482. config.nWndX = entity->m_mediaParam.nWndX;
  1483. config.nWndY = entity->m_mediaParam.nWndY;
  1484. config.nWndWidth = entity->m_mediaParam.nWndWidth;
  1485. config.nWndHeight = entity->m_mediaParam.nWndHeight;
  1486. strncpy(config.strRootPath, item.strResourcePath, strlen(item.strResourcePath));
  1487. strncpy(config.strFileNames[0], item.strvideoNames, strlen(item.strvideoNames));
  1488. strncpy(config.strVideoRunTime_S, RVC_VIDEOPLAY_START_TIME, sizeof(config.strVideoRunTime_S));
  1489. strncpy(config.strVideoRunTime_E, RVC_VIDEOPLAY_END_TIME, sizeof(config.strVideoRunTime_E));
  1490. if (false == IsValidPlayTime(config.strVideoRunTime_S, config.strVideoRunTime_E)) {
  1491. struct timespec ts;
  1492. clock_gettime(CLOCK_REALTIME, &ts);
  1493. ts.tv_sec += 30;
  1494. if (0 != sem_timedwait(&entity->m_stop_mediaplay_semt, &ts) && (ETIMEDOUT == errno)) {
  1495. continue;
  1496. }
  1497. else {
  1498. break;
  1499. }
  1500. }
  1501. if (!CheckFileExist(config.strRootPath, config.strFileNames[0], blog)) {
  1502. continue;
  1503. }
  1504. int iPlayRet = entity->m_pMediaPlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
  1505. if (-3 == iPlayRet) {
  1506. struct timespec ts;
  1507. clock_gettime(CLOCK_REALTIME, &ts);
  1508. ts.tv_sec += 2;
  1509. if (0 != sem_timedwait(&entity->m_stop_mediaplay_semt, &ts) && (ETIMEDOUT == errno)) {
  1510. continue;
  1511. }
  1512. else {
  1513. break;
  1514. }
  1515. }
  1516. }
  1517. else if ('P' == item.type)
  1518. {//play Image
  1519. CPicPlayConfig config = { 0 };
  1520. config.bFullScreen = IS_DEBUG ? false : item.fullScreen;
  1521. config.bPrimMonitor = IS_DEBUG ? true : false;
  1522. config.nFileCnt = 1;
  1523. config.nPlayCnt = 1;
  1524. config.nPlayInterval = item.playInterval;
  1525. config.nWndX = entity->m_mediaParam.nWndX;
  1526. config.nWndY = entity->m_mediaParam.nWndY;
  1527. config.nWndWidth = entity->m_mediaParam.nWndWidth;
  1528. config.nWndHeight = entity->m_mediaParam.nWndHeight;
  1529. strncpy(config.strRootPath, item.strResourcePath, strlen(item.strResourcePath));
  1530. strncpy(config.strFileNames[0], item.strvideoNames, strlen(item.strvideoNames));
  1531. if (!CheckFileExist(config.strRootPath, config.strFileNames[0], blog)) {
  1532. continue;
  1533. }
  1534. if (entity->m_pPicturePlayer[entity->m_mediaParam.nCfgInx]->checkIsStop()) {
  1535. entity->m_pPicturePlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
  1536. if (!entity->m_pPicturePlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(&playThreadId)) {
  1537. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Create play Image Media Thread Failed!");
  1538. iRet = -1;
  1539. return (void*)&iRet;
  1540. }
  1541. if (0 == pthread_join(playThreadId, NULL)) {
  1542. iRet = 0;
  1543. }
  1544. else {
  1545. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("pthread join thread id %u failed for %s.", playThreadId, strerror(errno));
  1546. iRet = -1;
  1547. }
  1548. }
  1549. }
  1550. }
  1551. unsigned int uend_time = y2k_time_now();
  1552. if (uend_time - ustart_time < RVC_MIN_LOCALPLAYER_TIME) {
  1553. LogWarn(Severity_Low, Error_Debug, LOG_EVT_MEDIAPLAY_COST_TIME_ERROR, "广告播放时长不足1秒");
  1554. break;
  1555. }
  1556. blog = false;
  1557. }
  1558. entity->m_uMediaPlayThreadId = 0;
  1559. return (void*)&iRet;
  1560. }
  1561. void* StartNoticePlayThreadFunc(void* param)
  1562. {
  1563. int iRet = -1;
  1564. CLocalMediaPlayEntity* entity = (CLocalMediaPlayEntity*)param;
  1565. const char* pVideoName = entity->m_lastPlayVideo.c_str();
  1566. Clibmediaplayer* player = entity->m_pMediaPlayer[entity->m_mediaParam.nCfgInx];
  1567. player->PlayVideoNotice(entity->m_mediaParam.nWndX, entity->m_mediaParam.nWndY, entity->m_mediaParam.nWndWidth, entity->m_mediaParam.nWndHeight, pVideoName);
  1568. entity->m_uNoticePlayThreadId = 0;
  1569. iRet = 0;
  1570. return (void*)&iRet;
  1571. }
  1572. #endif
  1573. DeviceTypeEnum CLocalMediaPlayEntity::RvcGetDeviceType()
  1574. {
  1575. DeviceTypeEnum eType = eStand2sType;
  1576. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  1577. CSystemStaticInfo stStaticinfo;
  1578. spFunction->GetSystemStaticInfo(stStaticinfo);
  1579. if (_stricmp(stStaticinfo.strMachineType, "RVC.Stand1SPlus") == 0) {
  1580. eType = eStand1SPlusType;
  1581. }
  1582. else if (_stricmp(stStaticinfo.strMachineType, "RVC.CardStore") == 0 || _stricmp(stStaticinfo.strMachineType, "RVC.CardPrinter") == 0) {
  1583. eType = eCardStore;
  1584. }
  1585. else {
  1586. eType = eStand2sType;
  1587. }
  1588. if (eType >= 0 && eType < sizeof(Device_Type_Table) / sizeof(char*)) {
  1589. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("device type is %s.", Device_Type_Table[eType]);
  1590. }
  1591. return eType;
  1592. }
  1593. void CLocalMediaPlayEntity::StartVideo(int nCfgInx, int nWndX, int nWndY, int nWndWidth, int nWndHeight)
  1594. {
  1595. if(eStand2sType == m_eDeviceType){
  1596. if (nCfgInx >= MAX_PLAY_CHANNELS || nCfgInx < 0){
  1597. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Invalid CfgInx while StartVideo!");
  1598. return;
  1599. }
  1600. m_mediaParam.nCfgInx = nCfgInx;
  1601. m_mediaParam.nWndX = nWndX;
  1602. m_mediaParam.nWndY = nWndY;
  1603. m_mediaParam.nWndWidth = nWndWidth;
  1604. m_mediaParam.nWndHeight = nWndHeight;
  1605. #ifdef RVC_OS_WIN
  1606. if (0 == m_iPlayType) {
  1607. if (NULL != m_playThread) {
  1608. StopVideo(nCfgInx);
  1609. }
  1610. if (NULL == m_playThread) {
  1611. m_hStopMediaPlayEvent = CreateEventA(NULL, false, false, NULL);
  1612. m_badplayflag = true;
  1613. m_playThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&MediaPlayThread, this, 0, NULL);
  1614. }
  1615. }
  1616. else {
  1617. if (NULL != m_uMediaPlayThreadId) {
  1618. StopVideo(nCfgInx);
  1619. }
  1620. m_hStopMediaPlayEvent = CreateEventA(NULL, false, false, NULL);
  1621. m_badplayflag = true;
  1622. m_uMediaPlayThreadId = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&StartMediaPlayFunc, this, 0, NULL);
  1623. }
  1624. #else
  1625. sem_init(&m_stop_mediaplay_semt, 0, 0);
  1626. m_badplayflag = true;
  1627. int err = pthread_create(&m_uMediaPlayThreadId, NULL, StartMediaPlayFunc, this);
  1628. if (0 != err) {
  1629. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create media play thread failed.");
  1630. }
  1631. #endif // RVC_OS_WIN
  1632. }
  1633. }
  1634. void CLocalMediaPlayEntity::StartAudio(const char *pAudioNames)
  1635. {
  1636. if (NULL != pAudioNames) {
  1637. char strAudios[MAX_PATH] = { 0 };
  1638. rvc_snprintf(strAudios, MAX_PATH, "%s", pAudioNames);
  1639. const char* d = "|";
  1640. char* pName = NULL;
  1641. char* pdata = NULL;
  1642. #ifdef RVC_OS_WIN
  1643. pName = strtok_s(strAudios, d, &pdata);
  1644. #else
  1645. pName = strtok_r(strAudios, d, &pdata);
  1646. #endif
  1647. while (pName) {
  1648. CSimpleStringA strAudioFileName = pName;
  1649. CSimpleStringA strAudioFullPath = m_AudioPath + strAudioFileName;
  1650. if (!ExistsFileA(strAudioFullPath.GetData())) {
  1651. LogWarn(Severity_Low, Error_Debug, LOG_EVT_ADV_AUDIO_NOT_EXIST, CSimpleStringA::Format("audio file %s not exist!", strAudioFullPath.GetData()).GetData());
  1652. return;
  1653. }
  1654. #ifdef RVC_OS_WIN
  1655. pName = strtok_s(NULL, d, &pdata);
  1656. #else
  1657. pName = strtok_r(NULL, d, &pdata);
  1658. #endif
  1659. }
  1660. }
  1661. #ifdef RVC_OS_WIN
  1662. if (0 == m_iPlayType) {
  1663. if (!m_pAudioPlayer->checkIsStop()) {
  1664. StopAudio();
  1665. }
  1666. m_lastPlayAudio = pAudioNames;
  1667. m_uAudioPlayThreadId = CreateThread(NULL, 0, StartAudioPlayingThreadFunc, this, 0, NULL);
  1668. m_buserstopaudio = false;
  1669. auto audioRet = GetLocalAudioVolume();
  1670. m_pMediaAudioPlayer->SetVolume(audioRet.second);
  1671. }
  1672. else
  1673. {
  1674. if (m_pMediaAudioPlayer->checkIsPlay()) {
  1675. StopAudio();
  1676. }
  1677. m_lastPlayAudio = pAudioNames;
  1678. m_uAudioPlayThreadId = CreateThread(NULL, 0, StartAudioPlayingThreadFunc, this, 0, NULL);
  1679. m_buserstopaudio = false;
  1680. auto audioRet = GetLocalAudioVolume();
  1681. m_pMediaAudioPlayer->SetVolume(audioRet.second);
  1682. }
  1683. #else
  1684. if (m_pMediaAudioPlayer->checkIsPlay()) {
  1685. StopAudio();
  1686. }
  1687. m_lastPlayAudio = pAudioNames;
  1688. int err = pthread_create(&m_uAudioPlayThreadId, NULL, StartAudioPlayingThreadFunc, this);
  1689. if (0 != err) {
  1690. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create audio play thread failed.");
  1691. }
  1692. m_buserstopaudio = false;
  1693. auto audioRet = GetLocalAudioVolume();
  1694. m_pMediaAudioPlayer->SetVolume(audioRet.second);
  1695. #endif
  1696. }
  1697. void CLocalMediaPlayEntity::StartImage(int nCfgInx, int nWndX, int nWndY, int nWndWidth, int nWndHeight)
  1698. {
  1699. if(eStand2sType == m_eDeviceType){
  1700. if (nCfgInx >= MAX_PLAY_CHANNELS || nCfgInx < 0){
  1701. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Invalid CfgInx while StartImage!");
  1702. return;
  1703. }
  1704. #ifdef RVC_OS_WIN
  1705. if (0 == m_iPlayType){
  1706. m_pImagePlayer[nCfgInx]->Play(nCfgInx, nWndX, nWndY, nWndWidth, nWndHeight);
  1707. }
  1708. else{
  1709. m_pPicturePlayer[nCfgInx]->Play(nCfgInx, nWndX, nWndY, nWndWidth, nWndHeight);
  1710. }
  1711. #else
  1712. m_pPicturePlayer[nCfgInx]->Play(nCfgInx, nWndX, nWndY, nWndWidth, nWndHeight);
  1713. #endif
  1714. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Succeed to StartImage!");
  1715. }
  1716. }
  1717. void CLocalMediaPlayEntity::StopVideo(int nCfgInx)
  1718. {
  1719. if(eStand2sType == m_eDeviceType){
  1720. if (nCfgInx >= MAX_PLAY_CHANNELS || nCfgInx < 0){
  1721. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Invalid CfgInx while StopVideo!");
  1722. return;
  1723. }
  1724. m_badplayflag = false;
  1725. #ifdef RVC_OS_WIN
  1726. if (0 == m_iPlayType){
  1727. if (NULL != m_playThread) {
  1728. m_pVideoPlayer[nCfgInx]->Close();
  1729. m_pImagePlayer[nCfgInx]->Close();
  1730. SetEvent(m_hStopMediaPlayEvent);
  1731. WaitForSingleObject(m_playThread, INFINITE);
  1732. m_playThread = NULL;
  1733. CloseHandle(m_hStopMediaPlayEvent);
  1734. }
  1735. }
  1736. else{
  1737. if (NULL != m_uMediaPlayThreadId) {
  1738. m_pMediaPlayer[nCfgInx]->Close();
  1739. m_pPicturePlayer[nCfgInx]->Close();
  1740. SetEvent(m_hStopMediaPlayEvent);
  1741. WaitForSingleObject(m_uMediaPlayThreadId, INFINITE);
  1742. m_uMediaPlayThreadId = NULL;
  1743. CloseHandle(m_hStopMediaPlayEvent);
  1744. }
  1745. }
  1746. #else
  1747. if (0 != m_uMediaPlayThreadId) {
  1748. m_pMediaPlayer[nCfgInx]->Close();
  1749. m_pPicturePlayer[nCfgInx]->Close();
  1750. sem_post(&m_stop_mediaplay_semt);
  1751. pthread_join(m_uMediaPlayThreadId, NULL);
  1752. m_uMediaPlayThreadId = 0;
  1753. sem_destroy(&m_stop_mediaplay_semt);
  1754. }
  1755. #endif
  1756. }
  1757. }
  1758. void CLocalMediaPlayEntity::StopAudio()
  1759. {
  1760. #ifdef RVC_OS_WIN
  1761. if (NULL != m_uAudioPlayThreadId) {
  1762. if (0 == m_iPlayType) {
  1763. m_pAudioPlayer->Close();
  1764. }
  1765. else {
  1766. m_pMediaAudioPlayer->Close();
  1767. }
  1768. m_buserstopaudio = true;
  1769. WaitForSingleObject(m_uAudioPlayThreadId, INFINITE);
  1770. m_uAudioPlayThreadId = NULL;
  1771. }
  1772. #else
  1773. if (0 != m_uAudioPlayThreadId) {
  1774. m_pMediaAudioPlayer->Close();
  1775. m_buserstopaudio = true;
  1776. pthread_join(m_uAudioPlayThreadId, NULL);
  1777. m_uAudioPlayThreadId = 0;
  1778. }
  1779. #endif
  1780. }
  1781. void CLocalMediaPlayEntity::StopImage(int nCfgInx)
  1782. {
  1783. if(eStand2sType == m_eDeviceType){
  1784. if (nCfgInx >= MAX_PLAY_CHANNELS || nCfgInx < 0){
  1785. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Invalid CfgInx while StopImage!");
  1786. return;
  1787. }
  1788. #ifdef RVC_OS_WIN
  1789. if (0 == m_iPlayType){
  1790. if (false == m_pImagePlayer[nCfgInx]->checkIsStop()) {
  1791. m_pImagePlayer[nCfgInx]->Close();
  1792. }
  1793. }
  1794. else{
  1795. if (false == m_pPicturePlayer[nCfgInx]->checkIsStop()) {
  1796. m_pPicturePlayer[nCfgInx]->Close();
  1797. }
  1798. }
  1799. #else
  1800. if (false == m_pPicturePlayer[nCfgInx]->checkIsStop()) {
  1801. m_pPicturePlayer[nCfgInx]->Close();
  1802. }
  1803. #endif
  1804. }
  1805. }
  1806. void CLocalMediaPlayEntity::StopAll()
  1807. {
  1808. StopAudio(); // 关闭音频
  1809. for (int i = 0; i < MAX_PLAY_CHANNELS; ++i){
  1810. StopVideo(i); // 关闭视频
  1811. StopImage(i); // 关闭图像
  1812. StopNotice(i); // 关闭视频提示
  1813. }
  1814. }
  1815. bool CLocalMediaPlayEntity::GetLocalVideoVolume(int nCfgInx, int &nVolume)
  1816. {
  1817. CSmartPointer<IConfigInfo> spConfig;
  1818. ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_Run, spConfig);
  1819. if (Error == Error_Succeed)
  1820. {
  1821. Error = spConfig->ReadConfigValueInt("LocalVideo", "Volume", nVolume);
  1822. if (Error == Error_Succeed && nVolume >= 0 && nVolume <= 100)
  1823. {
  1824. return true;
  1825. }
  1826. }
  1827. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("fail to get local video volume!");
  1828. return false;
  1829. }
  1830. std::pair<bool, int> CLocalMediaPlayEntity::GetLocalAudioVolume()
  1831. {
  1832. CSmartPointer<IConfigInfo> spConfig;
  1833. int nVolume = 0;
  1834. ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_Run, spConfig);
  1835. if (Error == Error_Succeed)
  1836. {
  1837. Error = spConfig->ReadConfigValueInt("LocalAudio", "Volume", nVolume);
  1838. if (nVolume == 0)
  1839. {
  1840. nVolume = 50;
  1841. spConfig->WriteConfigValueInt("LocalAudio", "Volume", nVolume);
  1842. }
  1843. if (Error == Error_Succeed && nVolume >= 0 && nVolume <= 100)
  1844. {
  1845. return std::make_pair(true, nVolume);
  1846. }
  1847. }
  1848. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("fail to get local audio volume!");
  1849. return std::make_pair(false, nVolume);
  1850. }
  1851. bool CLocalMediaPlayEntity::SetLocalAudioVolume(int nVolume)
  1852. {
  1853. if (nVolume < 0 || nVolume > 100){
  1854. return false;
  1855. }
  1856. CSmartPointer<IConfigInfo> spConfig;
  1857. ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_Run, spConfig);
  1858. if (Error == Error_Succeed)
  1859. {
  1860. Error = spConfig->WriteConfigValueInt("LocalAudio", "Volume", nVolume);
  1861. if (Error == Error_Succeed)
  1862. {
  1863. #ifdef RVC_OS_WIN
  1864. if (0 == m_iPlayType) {
  1865. m_pAudioPlayer->SetVolume(nVolume);
  1866. }
  1867. else {
  1868. m_pMediaAudioPlayer->SetVolume(nVolume);
  1869. }
  1870. #else
  1871. m_pMediaAudioPlayer->SetVolume(nVolume);
  1872. #endif
  1873. return true;
  1874. }
  1875. }
  1876. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("fail to set local video volume!");
  1877. return false;
  1878. }
  1879. bool CLocalMediaPlayEntity::SetLocalVideoVolume(int nCfgInx, int nVolume)
  1880. {
  1881. if (nVolume < 0 || nVolume > 100){
  1882. return false;
  1883. }
  1884. CSmartPointer<IConfigInfo> spConfig;
  1885. ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_Run, spConfig);
  1886. if (Error == Error_Succeed)
  1887. {
  1888. Error = spConfig->WriteConfigValueInt("LocalVideo", "Volume", nVolume);
  1889. if (Error == Error_Succeed)
  1890. {
  1891. for (int i = 0; i < MAX_PLAY_CHANNELS; ++i)
  1892. {
  1893. #ifdef RVC_OS_WIN
  1894. if (0 == m_iPlayType){
  1895. m_pVideoPlayer[i]->SetVolume(nVolume);
  1896. }
  1897. else{
  1898. m_pMediaPlayer[i]->SetVolume(nVolume);
  1899. }
  1900. #else
  1901. m_pMediaPlayer[i]->SetVolume(nVolume);
  1902. #endif
  1903. }
  1904. return true;
  1905. }
  1906. }
  1907. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("fail to set local video volume!");
  1908. return false;
  1909. }
  1910. bool CLocalMediaPlayEntity::IsRunConfigExist()
  1911. {
  1912. CSimpleStringA strPath;
  1913. ErrorCodeEnum eErr;
  1914. if ((eErr = GetFunction()->GetPath("RunInfo", strPath)) != Error_Succeed){
  1915. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get runinfo path failed(%d)", eErr);
  1916. return false;
  1917. }
  1918. CSimpleStringA strRuninfoFile;
  1919. strRuninfoFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR "%s.ini", (LPCTSTR)strPath, GetEntityName());
  1920. if (ExistsFileA(strRuninfoFile)) {
  1921. return true;
  1922. }
  1923. else {
  1924. return false;
  1925. }
  1926. }
  1927. ErrorCodeEnum CLocalMediaPlayEntity::StartMediaPlayerNotice(int nCfgInx, int nWndX, int nWndY, int nWndWidth, int nWndHeight, const char *pVideoName)
  1928. {
  1929. #ifdef RVC_OS_WIN
  1930. if (false == m_pAudioPlayer->checkIsStop()) {
  1931. StopAudio();
  1932. }
  1933. if (false == m_pVideoPlayer[nCfgInx]->checkIsStop()) {
  1934. StopNotice(nCfgInx);
  1935. }
  1936. #endif // RVC_OS_WI
  1937. m_mediaParam.nCfgInx = nCfgInx;
  1938. m_mediaParam.nWndX = nWndX;
  1939. m_mediaParam.nWndY = nWndY;
  1940. m_mediaParam.nWndWidth = nWndWidth%2 ? nWndWidth+1 : nWndWidth;
  1941. m_mediaParam.nWndHeight = nWndHeight%2 ? nWndHeight+1 : nWndHeight;
  1942. CSimpleStringA strPath;
  1943. ErrorCodeEnum Error = GetFunction()->GetPath("ADData", strPath);
  1944. if (Error == Error_Succeed) {
  1945. #ifdef RVC_OS_WIN
  1946. CSimpleStringA VideoPath = strPath + SPLIT_SLASH_STR + "Video" + SPLIT_SLASH_STR;
  1947. CSimpleStringA strNoticeFileName = VideoPath + pVideoName;
  1948. if(ExistsFileA(strNoticeFileName.GetData())){
  1949. if (m_pMediaPlayer[nCfgInx]->IsFileValid(strNoticeFileName.GetData())){
  1950. int iVolume = 60;
  1951. GetLocalVideoVolume(nCfgInx,iVolume);
  1952. m_pVideoPlayer[nCfgInx]->SetVolume(iVolume);
  1953. m_lastPlayVideo = pVideoName;
  1954. m_uNoticePlayThreadId = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&StartNoticePlayThreadFunc, this, 0, NULL);
  1955. //LogWarn(Severity_Low, Error_Debug, LOG_EVT_START_NOTICE_PLAY, CSimpleStringA::Format("start play notice %s", strNoticeFileName.GetData()).GetData());
  1956. }
  1957. else{
  1958. Error = Error_InvalidState;
  1959. LogWarn(Severity_Low, Error_Debug, LOG_EVT_NOTICE_FILE_NOT_VALID, CSimpleStringA::Format("play notice failed for %s is not valid!", strNoticeFileName.GetData()).GetData());
  1960. }
  1961. }
  1962. else{
  1963. Error = Error_InvalidState;
  1964. LogWarn(Severity_Low, Error_Debug, LOG_EVT_NOTICE_FILE_NOT_EXIST, CSimpleStringA::Format("play notice failed for %s not exist!", strNoticeFileName.GetData()).GetData());
  1965. }
  1966. #endif
  1967. }
  1968. return Error;
  1969. }
  1970. #ifdef RVC_OS_WIN
  1971. DWORD WINAPI StartNoticePlayThreadFunc(LPVOID param)
  1972. {
  1973. int iRet = -1;
  1974. CLocalMediaPlayEntity* entity = (CLocalMediaPlayEntity*)param;
  1975. const char* pVideoName = entity->m_lastPlayVideo.c_str();
  1976. int nCfgInx = entity->m_mediaParam.nCfgInx;
  1977. int nWndX = entity->m_mediaParam.nWndX;
  1978. int nWndY = entity->m_mediaParam.nWndY;
  1979. int nWndWidth = entity->m_mediaParam.nWndWidth;
  1980. int nWndHeight = entity->m_mediaParam.nWndHeight;
  1981. if (0 == entity->m_iPlayType) {
  1982. HANDLE playEndEvent = NULL;
  1983. entity->m_pVideoPlayer[nCfgInx]->PlayVideoNotice(nWndX, nWndY, nWndWidth, nWndHeight, entity->m_VideoPath.GetData(), pVideoName);
  1984. if (!entity->m_pVideoPlayer[nCfgInx]->checkIsPlay(playEndEvent)) {
  1985. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Get notice Play End Event Failed!");
  1986. }
  1987. else {
  1988. WaitForSingleObject(playEndEvent, INFINITE);
  1989. if (entity->m_pVideoPlayer[nCfgInx]->checkIsStop()) {
  1990. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("stop notice play success.");
  1991. }
  1992. else {
  1993. entity->m_pVideoPlayer[nCfgInx]->Close();
  1994. }
  1995. }
  1996. }
  1997. else {
  1998. Clibmediaplayer* player = entity->m_pMediaPlayer[nCfgInx];
  1999. player->PlayVideoNotice(nWndX, nWndY, nWndWidth, nWndHeight, pVideoName);
  2000. }
  2001. entity->m_uNoticePlayThreadId = NULL;
  2002. iRet = 0;
  2003. return iRet;
  2004. }
  2005. #endif
  2006. ErrorCodeEnum CLocalMediaPlayEntity::StartFFPlayerNotice(int nCfgInx, int nWndX, int nWndY, int nWndWidth, int nWndHeight, const char *pVideoName)
  2007. {
  2008. ErrorCodeEnum Error = Error_Succeed;
  2009. if (m_pMediaAudioPlayer->checkIsPlay()) {
  2010. StopAudio();
  2011. }
  2012. if (m_pMediaPlayer[nCfgInx]->checkIsPlay()) {
  2013. StopNotice(nCfgInx);
  2014. }
  2015. m_mediaParam.nCfgInx = nCfgInx;
  2016. m_mediaParam.nWndX = nWndX;
  2017. m_mediaParam.nWndY = nWndY;
  2018. m_mediaParam.nWndWidth = nWndWidth % 2 ? nWndWidth + 1 : nWndWidth;
  2019. m_mediaParam.nWndHeight = nWndHeight % 2 ? nWndHeight + 1 : nWndHeight;
  2020. CSimpleStringA strPath;
  2021. Error = GetFunction()->GetPath("ADData", strPath);
  2022. if (Error == Error_Succeed) {
  2023. CSimpleStringA VideoPath = strPath + SPLIT_SLASH_STR + "Video" + SPLIT_SLASH_STR;
  2024. CSimpleStringA strNoticeFileName = VideoPath + CSimpleStringA(pVideoName);
  2025. BOOL bRet = ExistsFile(strNoticeFileName.GetData());
  2026. if (bRet) {
  2027. if (m_pMediaPlayer[nCfgInx]->IsFileValid(strNoticeFileName.GetData())){
  2028. int iVolume = 60;
  2029. GetLocalVideoVolume(nCfgInx, iVolume);
  2030. m_pMediaPlayer[nCfgInx]->SetVolume(iVolume);
  2031. m_lastPlayVideo = strNoticeFileName.GetData();
  2032. #ifdef RVC_OS_WIN
  2033. m_uNoticePlayThreadId = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&StartNoticePlayThreadFunc, this, 0, NULL);
  2034. if (NULL != m_uNoticePlayThreadId) {
  2035. //LogWarn(Severity_Low, Error_Debug, LOG_EVT_START_NOTICE_PLAY, CSimpleStringA::Format("start play video notice %s", strNoticeFileName.GetData()).GetData());
  2036. }
  2037. else {
  2038. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create notice play thread failed.");
  2039. }
  2040. #else
  2041. int err = pthread_create(&m_uNoticePlayThreadId, NULL, StartNoticePlayThreadFunc, this);
  2042. if (0 == err) {
  2043. //LogWarn(Severity_Low, Error_Debug, LOG_EVT_START_NOTICE_PLAY, CSimpleStringA::Format("start play video notice %s", strNoticeFileName.GetData()).GetData());
  2044. }
  2045. else {
  2046. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create notice play thread failed.");
  2047. }
  2048. #endif
  2049. }
  2050. else{
  2051. Error = Error_InvalidState;
  2052. LogWarn(Severity_Low, Error_Debug, LOG_EVT_NOTICE_FILE_NOT_VALID, CSimpleStringA::Format("play notice failed for %s is not valid!", strNoticeFileName.GetData()).GetData());
  2053. }
  2054. }
  2055. else {
  2056. Error = Error_InvalidState;
  2057. LogWarn(Severity_Low, Error_Debug, LOG_EVT_NOTICE_FILE_NOT_EXIST, CSimpleStringA::Format("play notice failed for %s not exist!", strNoticeFileName.GetData()).GetData());
  2058. }
  2059. }
  2060. return Error;
  2061. }
  2062. ErrorCodeEnum CLocalMediaPlayEntity::StartNotice(int nCfgInx, int nWndX, int nWndY, int nWndWidth, int nWndHeight, const char *pVideoName)
  2063. {
  2064. ErrorCodeEnum Error = Error_Succeed;
  2065. if (eStand2sType == m_eDeviceType || eStand1SPlusType == m_eDeviceType){
  2066. if (nCfgInx >= MAX_PLAY_CHANNELS || nCfgInx < 0 || NULL == pVideoName)
  2067. {
  2068. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Invalid param CfgInx or video name while StartNotice!");
  2069. return Error_Param;
  2070. }
  2071. if (0 == m_iPlayType){
  2072. Error = StartMediaPlayerNotice(nCfgInx, nWndX, nWndY, nWndWidth, nWndHeight, pVideoName);
  2073. }
  2074. else{
  2075. Error = StartFFPlayerNotice(nCfgInx, nWndX, nWndY, nWndWidth, nWndHeight, pVideoName);
  2076. }
  2077. }
  2078. return Error;
  2079. }
  2080. ErrorCodeEnum CLocalMediaPlayEntity::StopNotice(int nCfgInx)
  2081. {
  2082. ErrorCodeEnum ErrorCode = Error_Succeed;
  2083. if (eStand2sType == m_eDeviceType || eStand1SPlusType == m_eDeviceType){
  2084. if (nCfgInx >= MAX_PLAY_CHANNELS || nCfgInx < 0){
  2085. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Invalid CfgInx while StopNotice!");
  2086. return Error_Param;
  2087. }
  2088. #ifdef RVC_OS_WIN
  2089. if (NULL != m_uNoticePlayThreadId) {
  2090. if (0 == m_iPlayType) {
  2091. if (false == m_pVideoPlayer[nCfgInx]->checkIsStop()) {
  2092. m_pVideoPlayer[nCfgInx]->Close();
  2093. }
  2094. }
  2095. else {
  2096. if (false == m_pMediaPlayer[nCfgInx]->checkIsStop()) {
  2097. m_pMediaPlayer[nCfgInx]->Close();
  2098. }
  2099. }
  2100. WaitForSingleObject(m_uNoticePlayThreadId, INFINITE);
  2101. if (m_lastPlayVideo.length() > 0) {
  2102. //LogWarn(Severity_Low, Error_Debug, LOG_EVT_STOP_NOTICE_PLAY, CSimpleStringA::Format("success to stop play notice ", m_lastPlayVideo.c_str()).GetData());
  2103. }
  2104. m_uNoticePlayThreadId = NULL;
  2105. }
  2106. #else
  2107. m_pMediaPlayer[nCfgInx]->Close();
  2108. if (m_uNoticePlayThreadId > 0) {
  2109. if (0 == pthread_join(m_uNoticePlayThreadId, NULL)) {
  2110. if (m_lastPlayVideo.length() > 0) {
  2111. //LogWarn(Severity_Low, Error_Debug, LOG_EVT_STOP_NOTICE_PLAY, CSimpleStringA::Format("%s%s", "success to stop play notice ", m_lastPlayVideo.c_str()).GetData());
  2112. }
  2113. }
  2114. m_uNoticePlayThreadId = 0;
  2115. }
  2116. #endif
  2117. }
  2118. return ErrorCode;
  2119. }
  2120. ErrorCodeEnum CLocalMediaPlayEntity::StopPlayAllMedias()
  2121. {
  2122. ErrorCodeEnum ErrorCode = Error_Succeed;
  2123. StopAll();
  2124. return ErrorCode;
  2125. }
  2126. void CLocalMediaPlayEntity::OnSelfTest(EntityTestEnum eTestType, CSmartPointer<ITransactionContext> pTransactionContext)
  2127. {
  2128. if (Test_ShakeHand == eTestType){
  2129. pTransactionContext->SendAnswer(Error_Succeed);
  2130. }
  2131. }
  2132. void CLocalMediaPlaySession::Handle_StartPlayVideo(SpReqAnsContext<PlayService_StartPlayVideo_Req, PlayService_StartPlayVideo_Ans>::Pointer ctx)
  2133. {
  2134. DbgToBeidou(ctx->link, __FUNCTION__)();
  2135. CSimpleStringA UpdateState = "";
  2136. ErrorCodeEnum Error = m_pEntity->GetFunction()->GetSysVar("UpdateState", UpdateState);
  2137. if (Error == Error_Succeed && "1" == UpdateState)
  2138. {
  2139. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("detect current is upgrade, do not play the media");
  2140. ctx->Answer(Error_Stoped);
  2141. m_pEntity->StopAll();
  2142. return;
  2143. }
  2144. if (eStand2sType == m_pEntity->GetDeviceType()){
  2145. m_pEntity->StartVideo(ctx->Req.CfgInx, ctx->Req.WndX, ctx->Req.WndY, ctx->Req.WndWidth, ctx->Req.WndHeight);
  2146. }
  2147. ctx->Answer(Error_Succeed);
  2148. }
  2149. void CLocalMediaPlaySession::Handle_StartPlayAudio(SpReqAnsContext<PlayService_StartPlayAudio_Req, PlayService_StartPlayAudio_Ans>::Pointer ctx)
  2150. {
  2151. DbgToBeidou(ctx->link, __FUNCTION__)();
  2152. CSimpleStringA AudioNames = CSimpleStringW2A(ctx->Req.AudioNames);
  2153. CSimpleStringA UpdateState = "";
  2154. ErrorCodeEnum Error = m_pEntity->GetFunction()->GetSysVar("UpdateState", UpdateState);
  2155. if (Error == Error_Succeed && "1" == UpdateState)
  2156. {
  2157. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("detect current is upgrade, do not play the media");
  2158. ctx->Answer(Error_Stoped);
  2159. m_pEntity->StopAll();
  2160. return;
  2161. }
  2162. m_pEntity->StartAudio(AudioNames.GetData());
  2163. ctx->Answer(Error_Succeed);
  2164. }
  2165. void CLocalMediaPlaySession::Handle_StartPlayImage(SpReqAnsContext<PlayService_StartPlayImage_Req, PlayService_StartPlayImage_Ans>::Pointer ctx)
  2166. {
  2167. DbgToBeidou(ctx->link, __FUNCTION__)();
  2168. m_pEntity->StartImage(ctx->Req.CfgInx, ctx->Req.WndX, ctx->Req.WndY, ctx->Req.WndWidth, ctx->Req.WndHeight);
  2169. ctx->Answer(Error_Succeed);
  2170. }
  2171. void CLocalMediaPlaySession::Handle_StopPlayVideo(SpReqAnsContext<PlayService_StopPlayVideo_Req, PlayService_StopPlayVideo_Ans>::Pointer ctx)
  2172. {
  2173. DbgToBeidou(ctx->link, __FUNCTION__)();
  2174. m_pEntity->StopVideo(ctx->Req.CfgInx);
  2175. ctx->Answer(Error_Succeed);
  2176. }
  2177. void CLocalMediaPlaySession::Handle_StopPlayAudio(SpReqAnsContext<PlayService_StopPlayAudio_Req, PlayService_StopPlayAudio_Ans>::Pointer ctx)
  2178. {
  2179. DbgToBeidou(ctx->link, __FUNCTION__)();
  2180. m_pEntity->StopAudio();
  2181. ctx->Answer(Error_Succeed);
  2182. }
  2183. void CLocalMediaPlaySession::Handle_StopPlayImage(SpReqAnsContext<PlayService_StopPlayImage_Req, PlayService_StopPlayImage_Ans>::Pointer ctx)
  2184. {
  2185. DbgToBeidou(ctx->link, __FUNCTION__)();
  2186. m_pEntity->StopImage(ctx->Req.CfgInx);
  2187. ctx->Answer(Error_Succeed);
  2188. }
  2189. void CLocalMediaPlaySession::OnClose(ErrorCodeEnum)
  2190. {
  2191. }
  2192. void CLocalMediaPlaySession::Handle_GetLocalVideoVolume( SpReqAnsContext<PlayService_GetLocalVideoVolume_Req, PlayService_GetLocalVideoVolume_Ans>::Pointer ctx )
  2193. {
  2194. DbgToBeidou(ctx->link, __FUNCTION__)();
  2195. int volume = 0;
  2196. if (m_pEntity->GetLocalVideoVolume(ctx->Req.CfgInx, volume)){
  2197. ctx->Ans.Volume = volume;
  2198. ctx->Answer(Error_Succeed);
  2199. }
  2200. else{
  2201. ctx->Answer(Error_Unexpect);
  2202. }
  2203. }
  2204. void CLocalMediaPlaySession::Handle_SetLocalVideoVolume( SpReqAnsContext<PlayService_SetLocalVideoVolume_Req, PlayService_SetLocalVideoVolume_Ans>::Pointer ctx )
  2205. {
  2206. DbgToBeidou(ctx->link, __FUNCTION__)();
  2207. if (m_pEntity->SetLocalVideoVolume(ctx->Req.CfgInx, ctx->Req.Volume)){
  2208. ctx->Answer(Error_Succeed);
  2209. }
  2210. else{
  2211. ctx->Answer(Error_Unexpect);
  2212. }
  2213. }
  2214. void CLocalMediaPlaySession::Handle_GetLocalAudioVolume(SpReqAnsContext<PlayService_GetLocalAudioVolume_Req, PlayService_GetLocalAudioVolume_Ans>::Pointer ctx)
  2215. {
  2216. DbgToBeidou(ctx->link, __FUNCTION__)();
  2217. auto audioRet = m_pEntity->GetLocalAudioVolume();
  2218. if (audioRet.first){
  2219. ctx->Ans.Volume = audioRet.second;
  2220. ctx->Answer(Error_Succeed);
  2221. }
  2222. else{
  2223. ctx->Answer(Error_Unexpect);
  2224. }
  2225. }
  2226. void CLocalMediaPlaySession::Handle_SetLocalAudioVolume(SpReqAnsContext<PlayService_SetLocalAudioVolume_Req, PlayService_SetLocalAudioVolume_Ans>::Pointer ctx)
  2227. {
  2228. DbgToBeidou(ctx->link, __FUNCTION__)();
  2229. if (m_pEntity->SetLocalAudioVolume(ctx->Req.Volume)){
  2230. ctx->Answer(Error_Succeed);
  2231. }
  2232. else{
  2233. ctx->Answer(Error_Unexpect);
  2234. }
  2235. }
  2236. void CLocalMediaPlaySession::Handle_StartPlayNotice(SpReqAnsContext<PlayService_StartPlayNotice_Req, PlayService_StartPlayNotice_Ans>::Pointer ctx)
  2237. {
  2238. DbgToBeidou(ctx->link, __FUNCTION__)();
  2239. CSimpleStringA UpdateState = "";
  2240. ErrorCodeEnum Error = m_pEntity->GetFunction()->GetSysVar("UpdateState", UpdateState);
  2241. if (Error == Error_Succeed && "1" == UpdateState){
  2242. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("detect current is upgrade, do not play the media");
  2243. ctx->Answer(Error_Stoped);
  2244. m_pEntity->StopAll();
  2245. return;
  2246. }
  2247. CSimpleStringA VideoName = CSimpleStringW2A(ctx->Req.VideoName);
  2248. Error = m_pEntity->StartNotice(ctx->Req.CfgInx, ctx->Req.WndX, ctx->Req.WndY, ctx->Req.WndWidth, ctx->Req.WndHeight, VideoName.GetData());
  2249. ctx->Answer(Error);
  2250. }
  2251. void CLocalMediaPlaySession::Handle_StopPlayNotice(SpReqAnsContext<PlayService_StopPlayNotice_Req, PlayService_StopPlayNotice_Ans>::Pointer ctx)
  2252. {
  2253. DbgToBeidou(ctx->link, __FUNCTION__)();
  2254. ErrorCodeEnum Error = m_pEntity->StopNotice(ctx->Req.CfgInx);
  2255. ctx->Answer(Error);
  2256. }
  2257. void CLocalMediaPlaySession::Handle_StopPlayAllMedias(SpReqAnsContext<PlayService_StopPlayAllMedias_Req, PlayService_StopPlayAllMedias_Ans>::Pointer ctx)
  2258. {
  2259. DbgToBeidou(ctx->link, __FUNCTION__)();
  2260. ErrorCodeEnum Error = m_pEntity->StopPlayAllMedias();
  2261. ctx->Answer(Error);
  2262. }
  2263. SP_BEGIN_ENTITY_MAP()
  2264. SP_ENTITY(CLocalMediaPlayEntity)
  2265. SP_END_ENTITY_MAP()