mod_localmediaplay.cpp 82 KB

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