mod_localmediaplay.cpp 75 KB

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