mod_localmediaplay.cpp 82 KB

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