mod_localmediaplay.cpp 83 KB

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