mod_localmediaplay.cpp 82 KB

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