123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748 |
- #include "stdafx.h"
- #include "mod_localmediaplay.h"
- #include "LocalMediaPlay_msg_g.h"
- #include "y2k_time.h"
- #include "fileutil.h"
- #include "rvc_media_common.h"
- #include <stdint.h>
- #include "../mod_interactivecontrol/Event.h"
- #include "Event.h"
- #ifndef RVC_MIN_LOCALPLAYER_TIME
- #define RVC_MIN_LOCALPLAYER_TIME 1
- #endif
- #define DEFAULT_SLEEP_TIME 1000
- #define DEFAULT_ADVERT_TYPE 'A'
- bool IS_DEBUG = false;
- int scanTime = 600;
- int removeOldTime = 1800;
- #ifndef MAX_LOCAL_MEDIAS
- #define MAX_LOCAL_MEDIAS 128
- #endif // !MAX_LOCAL_MEDIAS
- #ifndef RVC_MIN_LOCALPLAYER_TIME
- #define RVC_MIN_LOCALPLAYER_TIME 6
- #endif
- #ifndef RVC_VIDEOPLAY_START_TIME
- #define RVC_VIDEOPLAY_START_TIME "09:00:00"
- #endif // !RVC_VIDEOPLAY_START_TIME
- #ifndef RVC_VIDEOPLAY_END_TIME
- #define RVC_VIDEOPLAY_END_TIME "17:30:00"
- #endif // !RVC_VIDEOPLAY_END_TIME
- #ifndef rvc_snprintf
- #ifdef RVC_OS_WIN
- #define rvc_snprintf _snprintf
- #else
- #define rvc_snprintf snprintf
- #endif // RVC_OS_WIN
- #endif // rvc_snprintf
- static uint32_t ConvertStereo2Mono(char* pDstBuf, const uint32_t uDstLen, char* pSrcBuf, uint32_t uSrcLen, uint32_t uBitDeepth)
- {
- uint32_t uRet = 0;
- uint32_t uOneChannelLen = uSrcLen / 2;
- uint32_t i = 0;
- for (; i < uOneChannelLen / 2 && i < uDstLen / uBitDeepth; i++) {
- memcpy((uint16_t*)pDstBuf + i, ((uint32_t*)(pSrcBuf)) + i, uBitDeepth);
- }
- if (i == uOneChannelLen / 2) {
- uRet = uOneChannelLen;
- }
- return uRet;
- }
- static uint32_t Transform2Pcm8k(char* pdstbuf, const uint32_t udstlen, char* pcm_441kdata, int idata_size, int ichannels)
- {
- uint32_t nLen = 0;
- int nSkipByte = 5 * ichannels;
- int nSourcePos = 0;
- char* pcm_8k_data = (char*)pdstbuf;
- for (nLen = 0; nSourcePos + 1 < idata_size; nLen = nLen + 2)
- {
- pcm_8k_data[nLen] = pcm_441kdata[nSourcePos];
- pcm_8k_data[nLen + 1] = pcm_441kdata[nSourcePos + 1];
- if (nSkipByte == 5 * ichannels) {
- nSkipByte = 6 * ichannels;
- }
- else {
- nSkipByte = 5 * ichannels;
- }
- nSourcePos = nSourcePos + nSkipByte * 2;
- }
- return nLen;
- }
- static uint32_t Transform48k2Pcm8k(char* pdstbuf, const uint32_t udstlen, char* pcm_48kdata, int idata_size, int ichannels)
- {
- uint32_t nLen = 0;
- int nSkipByte = 6 * ichannels;
- int nSourcePos = 0;
- char* pcm_8k_data = (char*)pdstbuf;
- for (nLen = 0; nSourcePos + 1 < idata_size; nLen = nLen + 2)
- {
- pcm_8k_data[nLen] = pcm_48kdata[nSourcePos];
- pcm_8k_data[nLen + 1] = pcm_48kdata[nSourcePos + 1];
- nSourcePos = nSourcePos + nSkipByte * 2;
- }
- return nLen;
- }
- static uint32_t PcmConvert(char* pdstbuf, const uint32_t udstlen, char* pcmsrcdata, int isrclen, int isamplespersec, int ichannels)
- {
- uint32_t uLen = 0;
- if (2 == ichannels) {
- if (8000 == isamplespersec) {
- uLen = ConvertStereo2Mono(pdstbuf, udstlen, pcmsrcdata, isrclen, 2);
- }
- else if (44100 == isamplespersec) {
- uLen = Transform2Pcm8k(pdstbuf, udstlen, pcmsrcdata, isrclen, 2);
- }
- else if (48000 == isamplespersec) {
- uLen = Transform48k2Pcm8k(pdstbuf, udstlen, pcmsrcdata, isrclen, 2);
- }
- }
- else {
- if (44100 == isamplespersec) {
- uLen = Transform2Pcm8k(pdstbuf, udstlen, pcmsrcdata, isrclen, 1);
- }
- else if (48000 == isamplespersec) {
- uLen = Transform48k2Pcm8k(pdstbuf, udstlen, pcmsrcdata, isrclen, 1);
- }
- }
- return uLen;
- }
- static bool IsSupportAudioSamprate(int isamprate)
- {
- bool bret = false;
- if (8000 == isamprate || 44100 == isamprate || 48000 == isamprate) {
- bret = true;
- }
- return bret;
- }
- static void CStringSplit(char* str, char** result, const char* del)
- {
- char* pdata = NULL;
- char* p = NULL;
- #ifdef RVC_OS_WIN
- p = strtok_s(str, del, &pdata);
- #else
- p = strtok_r(str, del, &pdata);
- #endif // RVC_OS_WIN
- while (p != NULL) {
- *result++ = p;
- #ifdef RVC_OS_WIN
- p = strtok_s(NULL, del, &pdata);
- #else
- p = strtok_r(NULL, del, &pdata);
- #endif
- }
- }
- static bool IsValidPlayTime(const char* pstrStartTime, const char* pstrEndTime)
- {
- bool bRet = true;
- if (NULL == pstrStartTime || NULL == pstrEndTime) {
- return false;
- }
- #ifdef DEVOPS_ON_ST
- #else
- #ifdef RVC_OS_WIN
- SYSTEMTIME st;
- GetLocalTime(&st);
- char strNow[MAX_PATH] = { 0 };
- _snprintf(strNow, MAX_PATH, "%02d:%02d:%02d", st.wHour, st.wMinute, st.wSecond);
- if (strcmp(strNow, pstrStartTime) < 0 || strcmp(strNow, pstrEndTime) >= 0) {
- bRet = false;
- }
- #else
- struct tm* ptm = NULL;
- time_t t = time(NULL);
- ptm = localtime(&t);
- char strNow[TIME_LEN] = { 0 };
- snprintf(strNow, TIME_LEN, "%02d:%02d:%02d", ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
- if (strcmp(strNow, pstrStartTime) < 0 || strcmp(strNow, pstrEndTime) >= 0) {
- bRet = false;
- }
- #endif // RVC_OS_WIN
- #endif
- return bRet;
- }
- static bool CheckFileExist(const char* pstrFolder, const char* pstrFileName, bool blog)
- {
- bool bret = false;
- if (NULL == pstrFolder || NULL == pstrFileName) {
- return bret;
- }
- CSimpleStringA strFolder(pstrFolder);
- CSimpleStringA strFileName(pstrFileName);
- CSimpleStringA strFullPath = strFolder + strFileName;
- bret = ExistsFileA(strFullPath.GetData());
- if (false == bret) {
- if (blog) {
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_ADV_VIDEO_NOT_EXIST, CSimpleStringA::Format("adv file %s not exist!", strFullPath.GetData()).GetData());
- }
- }
- return bret;
- }
- #ifdef RVC_OS_WIN
- DWORD WINAPI qryMedia(LPVOID lpv)
- {
- CLocalMediaPlayEntity* curEntity = (CLocalMediaPlayEntity*)lpv;
- Sleep(3000);
- while (true){
- curEntity->m_mediaManage.InitResourceListByLocal();
- Sleep(3600 * 1000);
- }
- return 0;
- }
- #else
- void* queryMedia(void* param)
- {
- CLocalMediaPlayEntity* curEntity = (CLocalMediaPlayEntity*)param;
- sleep(3);
- while (false == curEntity->GetScanExitFlag())
- {
- curEntity->m_mediaManage.InitResourceListByLocal();
- sleep(3600);
- }
- return 0;
- }
- void sig_handler(int signum)
- {
- if (SIGTERM == signum){
- int ipid = getpid();
- kill(ipid, SIGKILL);
- }
- }
- #endif // RVC_OS_WIN
- CLocalMediaPlayEntity::CLocalMediaPlayEntity() : m_id_seq(0)
- {
- m_defaultVolum = 50;
- #ifdef RVC_OS_WIN
- m_pAudioPlayer = NULL;
- m_scanThread = NULL;
- m_playThread = NULL;
- memset(m_pVideoPlayer, 0, sizeof(m_pVideoPlayer));
- memset(m_pImagePlayer, 0, sizeof(m_pImagePlayer));
- #endif // RVC_OS_WIN
- ZeroMemory(&m_mediaParam, sizeof(MediaPlayParam));
- m_pMediaAudioPlayer = NULL;
- memset(m_pMediaPlayer, 0, sizeof(m_pMediaPlayer));
- memset(m_pPicturePlayer, 0, sizeof(m_pPicturePlayer));
- #ifdef RVC_OS_WIN
- m_scanThreadId = NULL;
- m_uMediaPlayThreadId = NULL;
- m_uNoticePlayThreadId = NULL;
- m_uAudioPlayThreadId = NULL;
- #else
- m_scanThreadId = 0;
- m_uMediaPlayThreadId = 0;
- m_uNoticePlayThreadId = 0;
- m_uAudioPlayThreadId = 0;
- #endif // !RVC_OS_WIN
- m_scanexitflag = false;
- m_badplayflag = true;
- m_bgetflag = false;
- m_bgetico = false;
- m_remote_audio_queue = NULL;
- m_pFile = NULL;
- m_bRecordPCM = false;
- m_iPlayType = 0;
- m_bStartRecord = false;
- m_leftlen = 0;
- m_piclevel = PIC_LOG_INFO;
- m_medialevel = MEDIA_LOG_INFO;
- m_buserstopaudio = false;
- }
- CLocalMediaPlayEntity::~CLocalMediaPlayEntity()
- {
- #ifdef RVC_OS_WIN
- DWORD exitCode = 0;
- if (m_scanThread){
- TerminateThread(m_scanThread, exitCode);
- m_scanThread = NULL;
- }
- #else
- m_scanexitflag = true;
- if (0 == pthread_join(m_scanThreadId, NULL)) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("pthread join scanThreadId success.");
- }
- m_bgetflag = false;
- m_bgetico = false;
-
- #endif // RVC_OS_WIN
- }
- void CLocalMediaPlayEntity::setMediaPath()
- {
- CSimpleStringA downloadPath, mediaPath;
- GetFunction()->GetPath("Download", downloadPath);
- GetFunction()->GetPath("Ad", mediaPath);
- mediaPath += SPLIT_SLASH_STR;
- mediaPath += "Video";
- m_mediaManage.setDefaultDownloadPath(downloadPath.GetData());
- m_mediaManage.setDefaultAddvertPath(mediaPath.GetData());
- }
- CServerSessionBase* CLocalMediaPlayEntity::OnNewSession(const char* pszRemoteEntityName, const char * pszClass)
- {
- return new CLocalMediaPlaySession(this, m_id_seq++);
- }
- #ifdef RVC_OS_WIN
- bool CLocalMediaPlayEntity::LoadPlayConfig(CWmpPlayConfig &config, int CfgInx)
- {
- if (CfgInx >= MAX_PLAY_CHANNELS || CfgInx < 0){
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Invalid CfgInx while LoadConfig!");
- return false;
- }
- if (config.eMode == LOCALAUDIO && CfgInx < m_defaultAudio.size()) {
- memcpy(&config, &(m_defaultAudio[CfgInx]), sizeof(CWmpPlayConfig));
- }
- else if (config.eMode == LOCALVIDEO && CfgInx < m_defaultVideo.size()) {
- memcpy(&config, &(m_defaultVideo[CfgInx]), sizeof(CWmpPlayConfig));
- }
- else {
- return false;
- }
-
- return true;
- }
- bool CLocalMediaPlayEntity::LoadPlayConfig(CImgPlayConfig &config, int CfgInx)
- {
- if (CfgInx >= MAX_PLAY_CHANNELS || CfgInx < 0){
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Invalid CfgInx while LoadConfig!");
- return false;
- }
- memcpy(&config, &(m_defaultImg[CfgInx]), sizeof(CImgPlayConfig));
- return true;
- }
- void CLocalMediaPlayEntity::WmpDebug(const char *fmt, ...)
- {
- va_list arg;
- va_start(arg, fmt);
- int n = _vsnprintf(NULL, 0, fmt, arg);
- if (n >= 512) {
- char* buf = (char*)malloc((size_t)(n + 1));
- _vsnprintf(buf, n + 1, fmt, arg);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", buf);
- free(buf);
- }
- else{
- char strlog[512] = {0};
- _vsnprintf(strlog, 512, fmt, arg);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", strlog);
- }
- va_end(arg);
- }
- void CLocalMediaPlayEntity::WmpLogEvt(int ievent, const char* strmsg)
- {
- if (0 == ievent){
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_VICE_MONITOR_NOT_EXIST, strmsg);
- }
- else if(1 == ievent){
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_VICE_MONITOR_SET_ERROR, strmsg);
- }
- }
- void CLocalMediaPlayEntity::ImgDebug(const char *fmt, ...)
- {
- va_list arg;
- va_start(arg, fmt);
- int n = _vsnprintf(NULL, 0, fmt, arg);
- if (n >= 512) {
- char* buf = (char*)malloc((size_t)(n + 1));
- _vsnprintf(buf, n + 1, fmt, arg);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", buf);
- free(buf);
- }
- else{
- char strlog[512] = {0};
- _vsnprintf(strlog, 512, fmt, arg);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", strlog);
- }
- va_end(arg);
- }
- #endif // RVC_OS_WIN
- void CLocalMediaPlayEntity::loadDefaultMedia(bool fNewVersion)
- {
- if (!fNewVersion) {
- #ifdef RVC_OS_WIN
- m_defaultImg.clear();
- m_defaultAudio.clear();
- m_defaultVideo.clear();
- #endif // RVC_OS_WIN
- }
- else {
- m_defaultPic.clear();
- m_Audios.clear();
- m_Videos.clear();
- }
- // 获取本地媒体根目录
- CSimpleStringA strRootPath("");
- ErrorCodeEnum Error = Error_Succeed;
- Error = GetFunction()->GetPath("ADData", strRootPath);
- if (Error != Error_Succeed) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Fail to get local media root path!");
- return;
- }
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("local media root path is %s.", strRootPath.GetData());
- CSmartPointer<IConfigInfo> spConfigCen;
- if (Error_Succeed == GetFunction()->OpenConfig(Config_CenterSetting, spConfigCen)) {
- IS_DEBUG = false;
- do {
- int value(0);
- spConfigCen->ReadConfigValueInt(GetEntityName(), "runDebug", value);
- if (value > 0) {
- IS_DEBUG = true;
- }
- } while (false);
- scanTime = 600;
- removeOldTime = 1800;
- do {
- int value(0);
- spConfigCen->ReadConfigValueInt(GetEntityName(), "scanTime", value);
- if (value > 0) {
- scanTime = value;
- }
- } while (false);
- do {
- int value(0);
- spConfigCen->ReadConfigValueInt(GetEntityName(), "removeOldTime", value);
- if (value > 0) {
- removeOldTime = value;
- }
- } while (false);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("runDebug:%s, scanTime:%d", IS_DEBUG ? "true" : "false", scanTime);
- }
- CSimpleStringA imgPath = strRootPath + SPLIT_SLASH_STR + "Image" + SPLIT_SLASH_STR;
- //Image0
- do {
- if (!fNewVersion) {
- #ifdef RVC_OS_WIN
- CImgPlayConfig curImg;
- ZeroMemory(&curImg, sizeof(CImgPlayConfig));
- strncpy(curImg.strRootPath, imgPath.GetData(), sizeof(curImg.strRootPath));
- curImg.bFullScreen = true;
- curImg.bPrimMonitor = false;
- curImg.nPlayCnt = 0;
- curImg.nPlayInterval = 5000;
- curImg.nFileCnt = 4;
- for (int i = 0; i < curImg.nFileCnt; ++i) {
- rvc_snprintf(curImg.strFileNames[i], MAX_PATH, "Ad0%s%d.jpg", SPLIT_SLASH_STR, i);
- }
- m_defaultImg.push_back(curImg);
- #endif
- }
- else {
- CPicPlayConfig curImg1;
- ZeroMemory(&curImg1, sizeof(CPicPlayConfig));
- strncpy(curImg1.strRootPath, imgPath.GetData(), sizeof(curImg1.strRootPath));
- curImg1.bFullScreen = true;
- curImg1.bPrimMonitor = false;
- curImg1.nPlayCnt = 0;
- curImg1.nPlayInterval = 5000;
- curImg1.nFileCnt = 4;
- for (int i = 0; i < curImg1.nFileCnt; ++i) {
- rvc_snprintf(curImg1.strFileNames[i], MAX_PATH, "Ad0%s%d.jpg", SPLIT_SLASH_STR, i);
- }
- m_defaultPic.push_back(curImg1);
- }
- } while (false);
- //Image1
- do {
- if (!fNewVersion) {
- #ifdef RVC_OS_WIN
- CImgPlayConfig curImg;
- ZeroMemory(&curImg, sizeof(CImgPlayConfig));
- strncpy(curImg.strRootPath, imgPath.GetData(), sizeof(curImg.strRootPath));
- curImg.bFullScreen = false;
- curImg.bPrimMonitor = true;
- curImg.nPlayCnt = 6;
- curImg.nPlayInterval = 1000;
- curImg.nFileCnt = 4;
- for (int i = 0; i < curImg.nFileCnt; ++i) {
- rvc_snprintf(curImg.strFileNames[i], MAX_PATH, "Ad1%s%d.jpg", SPLIT_SLASH_STR, i);
- }
- m_defaultImg.push_back(curImg);
- #endif
- }
- else {
- CPicPlayConfig curImg1;
- ZeroMemory(&curImg1, sizeof(CPicPlayConfig));
- strncpy(curImg1.strRootPath, imgPath.GetData(), sizeof(curImg1.strRootPath));
- curImg1.bFullScreen = true;
- curImg1.bPrimMonitor = false;
- curImg1.nPlayCnt = 6;
- curImg1.nPlayInterval = 1000;
- curImg1.nFileCnt = 4;
- for (int i = 0; i < curImg1.nFileCnt; ++i) {
- rvc_snprintf(curImg1.strFileNames[i], MAX_PATH, "Ad1%s%d.jpg", SPLIT_SLASH_STR, i);
- }
- m_defaultPic.push_back(curImg1);
- }
- } while (false);
- CSimpleStringA videoPath = strRootPath + SPLIT_SLASH_STR + "Video" + SPLIT_SLASH_STR;
- m_VideoPath = videoPath;
- //Video0
- do {
- if (!fNewVersion) {
- #ifdef RVC_OS_WIN
- CWmpPlayConfig curVideo;
- ZeroMemory(&curVideo, sizeof(CWmpPlayConfig));
- strcpy(curVideo.strRootPath, videoPath.GetData());
- //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("config.strRootPath: %s", curVideo.strRootPath);
- curVideo.bFullScreen = true;
- curVideo.bPrimMonitor = false;
- curVideo.bSimpleMode = true;
- curVideo.nPlayCnt = 1;
- curVideo.nPlayInterval = 2000;
- curVideo.nVolume = 50;
- CSmartPointer<IConfigInfo> tempConfig;
- Error = GetFunction()->OpenConfig(Config_Run, tempConfig);
- if (Error == Error_Succeed) {
- Error = tempConfig->ReadConfigValueInt("LocalVideo", "Volume", curVideo.nVolume);
- if (Error != Error_Succeed || curVideo.nVolume < 0 || curVideo.nVolume > 100)
- curVideo.nVolume = 50;
- m_defaultVolum = curVideo.nVolume;
- }
- strcpy(curVideo.strVideoRunTime_S, RVC_VIDEOPLAY_START_TIME);
- strcpy(curVideo.strVideoRunTime_E, RVC_VIDEOPLAY_END_TIME);
- curVideo.nFileCnt = 1;
- strcpy(curVideo.strFileNames[0], "可视柜台欢迎界面.wmv");
- m_defaultVideo.push_back(curVideo);
- #endif // RVC_OS_WIN
- }
- else {
- CMediaPlayConfig curVideo1 = { 0 };
- strcpy(curVideo1.strRootPath, videoPath.GetData());
- curVideo1.bFullScreen = true;
- curVideo1.bPrimMonitor = false;
- curVideo1.bSimpleMode = true;
- curVideo1.nPlayCnt = 1;
- curVideo1.nPlayInterval = 2000;
- curVideo1.nVolume = 50;
- curVideo1.nFileCnt = 1;
- strcpy(curVideo1.strFileNames[0], "可视柜台欢迎界面.wmv");
-
- strcpy(curVideo1.strVideoRunTime_S, RVC_VIDEOPLAY_START_TIME);
- strcpy(curVideo1.strVideoRunTime_E, RVC_VIDEOPLAY_END_TIME);
- m_Videos.push_back(curVideo1);
- }
- } while (false);
- //Video1
- do {
- if (!fNewVersion) {
- #ifdef RVC_OS_WIN
- CWmpPlayConfig curVideo;
- ZeroMemory(&curVideo, sizeof(CWmpPlayConfig));
- strcpy(curVideo.strRootPath, videoPath.GetData());
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("config.strRootPath: %s", curVideo.strRootPath);
- curVideo.bFullScreen = true;
- curVideo.bPrimMonitor = false;
- curVideo.bSimpleMode = true;
- curVideo.nPlayCnt = 0;
- curVideo.nPlayInterval = 10000;
- curVideo.nVolume = 50;
- CSmartPointer<IConfigInfo> tempConfig;
- Error = GetFunction()->OpenConfig(Config_Run, tempConfig);
- if (Error == Error_Succeed) {
- Error = tempConfig->ReadConfigValueInt("LocalVideo", "Volume", curVideo.nVolume);
- if (Error != Error_Succeed || curVideo.nVolume < 0 || curVideo.nVolume > 100)
- curVideo.nVolume = 50;
- m_defaultVolum = curVideo.nVolume;
- }
- strcpy(curVideo.strVideoRunTime_S, RVC_VIDEOPLAY_START_TIME);
- strcpy(curVideo.strVideoRunTime_E, RVC_VIDEOPLAY_END_TIME);
- curVideo.nFileCnt = 1;
- strcpy(curVideo.strFileNames[0], "存款保险标识0418.wmv");
- m_defaultVideo.push_back(curVideo);
- #endif // RVC_OS_WIN
- }
- else {
- CMediaPlayConfig curVideo1 = { 0 };
- strcpy(curVideo1.strRootPath, videoPath.GetData());
- curVideo1.bFullScreen = true;
- curVideo1.bPrimMonitor = false;
- curVideo1.bSimpleMode = true;
- curVideo1.nPlayCnt = 0;
- curVideo1.nPlayInterval = 10000;
- curVideo1.nVolume = 50;
- curVideo1.nFileCnt = 1;
- strcpy(curVideo1.strFileNames[0], "存款保险标识0418.wmv");
-
- strcpy(curVideo1.strVideoRunTime_S, RVC_VIDEOPLAY_START_TIME);
- strcpy(curVideo1.strVideoRunTime_E, RVC_VIDEOPLAY_END_TIME);
- m_Videos.push_back(curVideo1);
- }
- } while (false);
- CSimpleStringA audioPath = strRootPath + SPLIT_SLASH_STR + "Audio" + SPLIT_SLASH_STR;
- m_AudioPath = audioPath;
- //Audio
- do {
- if (!fNewVersion) {
- #ifdef RVC_OS_WIN
- CWmpPlayConfig curAudio;
- ZeroMemory(&curAudio, sizeof(CWmpPlayConfig));
- strcpy(curAudio.strRootPath, audioPath.GetData());
- //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("config.strRootPath: %s", curAudio.strRootPath);
- curAudio.nPlayCnt = 1;
- curAudio.nPlayInterval = 5000;
- auto audioRet = GetLocalAudioVolume();
- if (audioRet.first) {
- curAudio.nVolume = audioRet.second;
- }
- else {
- curAudio.nVolume = m_defaultVolum;
- }
- m_defaultAudio.push_back(curAudio);
- #endif
- }
- else {
- CMediaPlayConfig curAudio1 = { 0 };
- strcpy(curAudio1.strRootPath, audioPath.GetData());
- curAudio1.nPlayCnt = 1;
- curAudio1.nPlayInterval = 5000;
- auto audioRet = GetLocalAudioVolume();
- if (audioRet.first) {
- curAudio1.nVolume = audioRet.second;
- }
- else {
- curAudio1.nVolume = m_defaultVolum;
- }
- m_Audios.push_back(curAudio1);
- }
- } while (false);
- #ifdef RVC_OS_WIN
- for (vector<CWmpPlayConfig>::iterator i = m_defaultVideo.begin(); i != m_defaultVideo.end(); i++) {
- for (int index = 0; index < MAX_FILECOUNT; index++) {
- if (strlen(i->strFileNames[index])) {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("m_defaultVideo %s.", i->strFileNames[index]);
- }
- }
- }
- for (vector<CWmpPlayConfig>::iterator i = m_defaultAudio.begin(); i != m_defaultAudio.end(); i++) {
- for (int index = 0; index < MAX_FILECOUNT; index++) {
- if (strlen(i->strFileNames[index])) {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("m_defaultAudio %s.", i->strFileNames[index]);
- }
- }
- }
-
- for (vector<CImgPlayConfig>::iterator i = m_defaultImg.begin(); i != m_defaultImg.end(); i++) {
- for (int index = 0; index < MAX_FILECOUNT; index++) {
- if (strlen(i->strFileNames[index])) {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("m_defaultImg %s.", i->strFileNames[index]);
- }
- }
- }
- #endif
- for (vector<CMediaPlayConfig>::iterator i = m_Videos.begin(); i != m_Videos.end(); i++) {
- for (int index = 0; index < MAX_FILECOUNT; index++) {
- if (strlen(i->strFileNames[index])) {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("m_Videos %s.", i->strFileNames[index]);
- }
- }
- }
- for (vector<CMediaPlayConfig>::iterator i = m_Audios.begin(); i != m_Audios.end(); i++) {
- for (int index = 0; index < MAX_FILECOUNT; index++) {
- if (strlen(i->strFileNames[index])) {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("m_Audios %s.", i->strFileNames[index]);
- }
- }
- }
- for (vector<CPicPlayConfig>::iterator i = m_defaultPic.begin(); i != m_defaultPic.end(); i++) {
- for (int index = 0; index < MAX_FILECOUNT; index++) {
- if (strlen(i->strFileNames[index])) {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("m_defaultPic %s.", i->strFileNames[index]);
- }
- }
- }
- }
- int CLocalMediaPlayEntity::LoadPlayConfig(CMediaPlayConfig& config, int CfgInx)
- {
- if (CfgInx >= MAX_PLAY_CHANNELS || CfgInx < 0){
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Invalid CfgInx while LoadConfig!");
- return -1;
- }
- if (config.eMode == MEDIA_LOCALAUDIO && CfgInx < m_Audios.size()){
- memcpy(&config, &(m_Audios[CfgInx]), sizeof(CMediaPlayConfig));
- }
- else if (config.eMode == MEDIA_LOCALVIDEO && CfgInx < m_Videos.size()){
- memcpy(&config, &(m_Videos[CfgInx]), sizeof(CMediaPlayConfig));
- }
- else {
- return -1;
- }
- return 0;
- }
- int CLocalMediaPlayEntity::LoadPlayConfig(CPicPlayConfig& config, int CfgInx)
- {
- if (CfgInx >= MAX_PLAY_CHANNELS || CfgInx < 0){
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Invalid CfgInx while LoadConfig!");
- return -1;
- }
- memcpy(&config, &(m_defaultPic[CfgInx]), sizeof(CPicPlayConfig));
- return 0;
- }
- void CLocalMediaPlayEntity::Debug(media_loglevel log_level, const char* fmt, ...)
- {
- if (log_level >= m_medialevel){
- va_list arg;
- va_start(arg, fmt);
- int n = vsnprintf(NULL, 0, fmt, arg);
- if (n >= MAX_PATH) {
- char* buf = (char*)malloc((size_t)(n + 1));
- vsnprintf(buf, n + 1, fmt, arg);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", buf);
- free(buf);
- }
- else {
- char strlog[MAX_PATH] = { 0 };
- vsnprintf(strlog, MAX_PATH, fmt, arg);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", strlog);
- }
- va_end(arg);
- }
- }
- void CLocalMediaPlayEntity::PicDebug(pic_loglevel log_level, const char* fmt, ...)
- {
- if (log_level >= m_piclevel){
- va_list arg;
- va_start(arg, fmt);
- int n = vsnprintf(NULL, 0, fmt, arg);
- if (n >= MAX_PATH) {
- char* buf = (char*)malloc((size_t)(n + 1));
- vsnprintf(buf, n + 1, fmt, arg);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", buf);
- free(buf);
- }
- else {
- char strlog[MAX_PATH] = { 0 };
- vsnprintf(strlog, MAX_PATH, fmt, arg);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s", strlog);
- }
- va_end(arg);
- }
- }
- void CLocalMediaPlayEntity::MediaPlayFinished(int iMediaType)
- {
- if (0 == iMediaType) {
- AudioPlayRet ret;
- ret.AudioNames = m_lastPlayAudio.c_str();
- ret.ret = true;
- //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("stop play audio %s success.", ret.AudioNames.GetData());
- if (false == m_buserstopaudio) {
- SpSendBroadcast(GetFunction(), eMsg_AudioPlayRet, eMsgSig_AudioPlayRet, ret);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("SpSendBroadcast AudioPlayRet and audio name is %s.", ret.AudioNames.GetData());
- }
- else {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("user stop, not broadcast!");
- }
- }
- else {
- VideoPlayRet ret;
- ret.VideoNames = m_lastPlayVideo.c_str();
- ret.ret = true;
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("stop play video notice %s success.", ret.VideoNames.GetData());
- SpSendBroadcast(GetFunction(), eMsg_VideoPlayRet, eMsgSig_VideoPlayRet, ret);
- }
- }
- int CLocalMediaPlayEntity::GetMediaPlayerIcoPath(char* strPath, int iLen)
- {
- return GetPlayerIcoPath(strPath, iLen);
- }
- int CLocalMediaPlayEntity::GetAudioOutDevName(char* strDev, int iLen)
- {
- int iRet = -1;
-
- int idatalen = m_strAudioOutDev.GetLength();
- if (iLen > idatalen && idatalen > 0) {
- memcpy(strDev, m_strAudioOutDev.GetData(), idatalen);
- iRet = 0;
- if (false == m_bgetflag) {
- m_bgetflag = true;
- //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d audio Out Device Name is %s.", __FUNCTION__, __LINE__, strDev);
- }
- }
- return iRet;
- }
- int CLocalMediaPlayEntity::PlayingAudioDataCallback(audio_param_t* param, const void* input, unsigned long uaudiolen)
- {
- int iRet = -1;
- if (0 != m_iPlayType && m_bStartRecord) {
- if (false == m_bloged) {
- m_bloged = true;
- 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());
- if (!IsSupportAudioSamprate(param->freq)) {
- LogWarn(Severity_Middle, Error_Debug, LOG_EVT_NOTSUPPORT_AUDIOFORMAT, CSimpleStringA::Format("not support audio param (%d channels, %d Hz, channel_layout(%d), frame_size(%d), bytes_per_sec(%d), audio format(%d)).", param->channels, param->freq, param->channel_layout, param->frame_size, param->bytes_per_sec, param->fmt).GetData());
- }
- }
- //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%s:%d uaudiolen:%d", __FUNCTION__, __LINE__, uaudiolen);
- //AV_SAMPLE_FMT_S16 == 1
- if (1 == param->fmt) {
- int isingle_audioframe_len = param->bytes_per_sec/50;
- int ioffset = 0;
- int icount = (uaudiolen + m_leftlen) / isingle_audioframe_len;
- //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d icount:%d, isingle_audioframe_len = %d.", __FUNCTION__, __LINE__, icount, isingle_audioframe_len);
- if (icount > 0) {
- for (int i = 0; i < icount; i++) {
- audio_frame frm;
- char* straudio = new char[isingle_audioframe_len];
- if (m_leftlen > 0){
- memcpy(straudio, m_audiobuffer, m_leftlen);
- memcpy(straudio + m_leftlen, (char*)input, isingle_audioframe_len - m_leftlen);
- ioffset += (isingle_audioframe_len - m_leftlen);
- m_leftlen = 0;
- }
- else{
- memcpy(straudio, (char*)input + ioffset, isingle_audioframe_len);
- ioffset += isingle_audioframe_len;
- }
-
- frm.bitspersample = 16;
- frm.format = param->fmt;
- frm.data = straudio;
- frm.framesize = isingle_audioframe_len;
- frm.nchannels = param->channels;
- frm.samplespersec = param->freq;
- frm.iseriesnumber = m_iseriesnumber++;
-
- if (1 == frm.nchannels && 8000 == frm.samplespersec){
- if (!m_remote_audio_queue->InsertAudio(&frm)) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("InsertAudio failed! frameCount:%d", frm.framesize);
- }
- else {
- //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%s:%d InsertAudio(series number = %d) success and framesize = %d.", __FUNCTION__, __LINE__, frm.iseriesnumber, frm.framesize);
- if (m_bRecordPCM && m_pFile){
- fwrite(frm.data, frm.framesize, 1, m_pFile);
- }
- }
- }
- else{
- char strsingle[RVC_AUDIO_LEN*2] = {0};
- uint32_t uLen = PcmConvert(strsingle, RVC_AUDIO_LEN*2, straudio, isingle_audioframe_len, frm.samplespersec, frm.nchannels);
- frm.data = strsingle;
- frm.framesize = RVC_AUDIO_LEN;
- frm.nchannels = 1;
- if (!m_remote_audio_queue->InsertAudio(&frm)) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("InsertAudio failed! frameCount:%d", frm.framesize);
- }
- else {
- //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%s:%d InsertAudio(series number = %d) success and framesize = %d.", __FUNCTION__, __LINE__, frm.iseriesnumber, frm.framesize);
- if (m_bRecordPCM && m_pFile) {
- fwrite(frm.data, frm.framesize, 1, m_pFile);
- }
- }
- }
-
- delete []straudio;
- }
- memset(m_audiobuffer, 0, RVC_AUDIO_BUFFER_LEN);
- int ileftaudio = uaudiolen - ioffset;
- memcpy(m_audiobuffer, (char*)input + ioffset, ileftaudio);
- m_leftlen = ileftaudio;
- }
- else {
- memcpy(m_audiobuffer + m_leftlen, (char*)input , uaudiolen);
- m_leftlen += uaudiolen;
- }
- iRet = 0;
- }
- }
- return iRet;
- }
- int CLocalMediaPlayEntity::GetPicPlayerIcoPath(char* strPath, int uLen)
- {
- return GetPlayerIcoPath(strPath, uLen);
- }
- bool CLocalMediaPlayEntity::GetPlayFlag()
- {
- return m_badplayflag;
- }
- bool CLocalMediaPlayEntity::GetScanExitFlag()
- {
- return m_scanexitflag;
- }
- DeviceTypeEnum CLocalMediaPlayEntity::GetDeviceType()
- {
- return m_eDeviceType;
- }
- int CLocalMediaPlayEntity::GetPlayerIcoPath(char* strPath, int iLen)
- {
- int iRet = -1;
- if (NULL == strPath) {
- return iRet;
- }
-
- CSimpleStringA csBinPath;
- ErrorCodeEnum eErrPath = GetFunction()->GetPath("Bin", csBinPath);
- if (eErrPath != Error_Succeed) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("GetBasePath failed (%d).", eErrPath);
- return iRet;
- }
- CSimpleStringA szIcoName("rvc_media_player_64px.bmp");
- szIcoName = csBinPath + SPLIT_SLASH_STR + szIcoName;
- if (m_bgetico == false) {
- //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("media player ico full path is %s.", szIcoName.GetData());
- m_bgetico = true;
- }
- if (iLen > szIcoName.GetLength()) {
- memcpy(strPath, szIcoName.GetData(), szIcoName.GetLength());
- iRet = 0;
- m_bgetico = true;
- }
-
- return iRet;
- }
- int CLocalMediaPlayEntity::GetAudioOutDev()
- {
- int iRet = -1;
- CSmartPointer<IEntityFunction> spFunction = GetFunction();
- CSmartPointer<IConfigInfo> spRootConfig;
- ErrorCodeEnum Error = spFunction->OpenConfig(Config_Root, spRootConfig);
- if (Error == Error_Succeed) {
- SpIniMappingTable table;
- table.AddEntryString("audio", "handfree_out_dev", m_strAudioOutDev, "$");
- Error = table.Load(spRootConfig);
- if (Error == Error_Succeed) {
- //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Audio Out Device name is %s.", m_strAudioOutDev.GetData());
- iRet = 0;
- }
- }
- return iRet;
- }
- ErrorCodeEnum CLocalMediaPlayEntity::LoadEntityConfig()
- {
- SpIniMappingTable table;
- int iPlayType = 0;
- int iMediaLogLevel = (int)MEDIA_LOG_INFO;
- int iPicLogLevel = (int)PIC_LOG_INFO;
- bool bRecordPCM = false;
- table.AddEntryInt("LocalMediaPlay", "PlayType", iPlayType, 0);
- table.AddEntryInt("LocalMediaPlay", "MediaLevel", iMediaLogLevel, (int)MEDIA_LOG_INFO);
- table.AddEntryInt("LocalMediaPlay", "PicLevel", iPicLogLevel, (int)PIC_LOG_INFO);
- table.AddEntryBoolean("SalesRecorder", "IsRecordPCM", bRecordPCM, false);
- CSmartPointer<IConfigInfo> spConfig;
- ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_CenterSetting, spConfig);
- if (Error == Error_Succeed) {
- Error = table.Load(spConfig);
- if (Error_Succeed == Error){
- m_iPlayType = iPlayType;
- if (iMediaLogLevel <= MEDIA_LOG_ERROR && iMediaLogLevel > 0){
- m_medialevel = (media_loglevel)iMediaLogLevel;
- }
- if (iPicLogLevel <= PIC_LOG_ERROR && iPicLogLevel > 0) {
- m_piclevel = (pic_loglevel)iPicLogLevel;
- }
- if (bRecordPCM) {
- m_bRecordPCM = true;
- }
- }
- }
- #ifdef RVC_OS_LINUX
- m_iPlayType = 1;
- #endif // RVC_OS_LINUX
-
- return Error;
- }
- void CLocalMediaPlayEntity::OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID, const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
- const DWORD dwSysError, const DWORD dwUserCode, const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
- const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage, const linkContext &pLinkInfo)
- {
- if (LOG_EVT_HEALTHMANAGER_BROWSER_IDLE == dwUserCode){
- //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("IEBrowser to idle, stop all media!");
- StopAll();
- }
- else if(LOG_EVT_UI_STARTREMOTERECORD == dwUserCode){
- if (0 != m_iPlayType){
- //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Start remote record.");
- HandleRemoteRecord(pszMessage);
- }
- }
- else if (LOG_EVT_UI_STOPREMOTERECORD == dwUserCode) {
- if (0 != m_iPlayType){
- //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Stop remote record.");
- m_bStartRecord = false;
- m_iseriesnumber = 0;
- m_leftlen = 0;
- if (NULL != m_remote_audio_queue) {
- delete m_remote_audio_queue;
- m_remote_audio_queue = NULL;
- }
- if (m_pFile) {
- fclose(m_pFile);
- m_pFile = NULL;
- }
- }
- }
- }
- void CLocalMediaPlayEntity::OnPreStart(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext)
- {
- ErrorCodeEnum Error = __OnStart(Error_Succeed);
- pTransactionContext->SendAnswer(Error);
- }
- ErrorCodeEnum CLocalMediaPlayEntity::__OnStart(ErrorCodeEnum preOperationError)
- {
- m_eDeviceType = RvcGetDeviceType();
- if (Error_Succeed != LoadEntityConfig()){
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("LoadEntityConfig failed.");
- }
- return Error_Succeed;
- }
- void CLocalMediaPlayEntity::OnStarted()
- {
- LogEvent(Severity_Middle, LOG_EVT_MOD_LOCALPLAYER_STARTED_SUCCESS, "local media play entity started successfully.");
- GetAudioOutDev();
- for (int i = 0; i != MAX_PLAY_CHANNELS; ++i)
- {
- #ifdef RVC_OS_WIN
- m_pVideoPlayer[i] = new Clibwmpplayer(this);
- m_pImagePlayer[i] = new Clibimgplayer(this);
- #endif
- mediaplayer_init();
- m_pMediaPlayer[i] = new Clibmediaplayer(this);
- m_pPicturePlayer[i] = new Clibpictureplayer(this);
- }
-
- m_pMediaAudioPlayer = new Clibmediaplayer(this);
- #ifdef RVC_OS_WIN
- m_pAudioPlayer = new Clibwmpplayer(this);
- #else
- signal(SIGTERM, sig_handler);
- #endif // RVC_OS_WIN
- if (!IsRunConfigExist()){
- SetLocalVideoVolume(0, 50);
- SetLocalAudioVolume(50);
- }
- setMediaPath();
-
- loadDefaultMedia(0 != m_iPlayType);
- GetFunction()->SubscribeLog(m_SubIDIEIdle, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_HEALTHMANAGER_BROWSER_IDLE, NULL, false);
- GetFunction()->SubscribeLog(m_SubIDStartRecord, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTREMOTERECORD, NULL, false);
- GetFunction()->SubscribeLog(m_SubIDStopRecord, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPREMOTERECORD, NULL, false);
- if (eStand2sType == m_eDeviceType) {
- #ifdef RVC_OS_WIN
- m_scanThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&qryMedia, this, 0, NULL);
- if (NULL != m_scanThread)
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create qryMeia thread success, %d.", m_scanThread);
- #else
- int err = pthread_create(&m_scanThreadId, NULL, queryMedia, this);
- if (0 != err) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create queryMedia thread failed.");
- }
- #endif // RVC_OS_WIN
- }
- }
- void CLocalMediaPlayEntity::OnPreClose(EntityCloseCauseEnum eCloseCause, CSmartPointer<ITransactionContext> pTransactionContext)
- {
- ErrorCodeEnum Error = __OnClose(Error_Succeed);
- pTransactionContext->SendAnswer(Error);
- }
- ErrorCodeEnum CLocalMediaPlayEntity::__OnClose(ErrorCodeEnum preOperationError)
- {
- for (int i = 0; i != MAX_PLAY_CHANNELS; ++i)
- {
- #ifdef RVC_OS_WIN
- delete m_pVideoPlayer[i];
- m_pVideoPlayer[i] = NULL;
- delete m_pImagePlayer[i];
- m_pImagePlayer[i] = NULL;
- #endif // RVC_OS_WIN
- delete m_pMediaPlayer[i];
- m_pMediaPlayer[i] = NULL;
- delete m_pPicturePlayer[i];
- m_pPicturePlayer[i] = NULL;
- }
- #ifdef RVC_OS_WIN
- delete m_pAudioPlayer;
- m_pAudioPlayer = NULL;
- #endif
- delete m_pMediaAudioPlayer;
- m_pMediaAudioPlayer = NULL;
-
- GetFunction()->UnsubscribeLog(m_SubIDIEIdle);
- GetFunction()->UnsubscribeLog(m_SubIDStartRecord);
- GetFunction()->UnsubscribeLog(m_SubIDStopRecord);
- // 释放播放对象
- if (0 != m_iPlayType){
- mediaplayer_term();
- }
- return Error_Succeed;
- }
- ErrorCodeEnum CLocalMediaPlayEntity::HandleRemoteRecord(const char* pszMessage)
- {
- ErrorCodeEnum Error = Error_Succeed;
- m_bStartRecord = true;
- memset(m_audiobuffer, 0, RVC_AUDIO_LEN);
- m_leftlen = 0;
- m_remote_audio_queue = new Clibaudioqueue(REC_COMMON_REMOTEAUDIO_SHM_QUEUE);
- m_iseriesnumber = 0;
- m_bloged = false;
- if (true == m_bRecordPCM){
- char strSwiftName[MAX_PATH] = { 0 };
- if (NULL != pszMessage) {
- size_t ulen = strlen(pszMessage);
- char* tmp = new char[ulen + 1];
- memset(tmp, 0, ulen + 1);
- memcpy(tmp, pszMessage, ulen);
- char* result[16] = { 0 };
- auto arr1 = CSimpleStringA2W(tmp).Split('@');
- auto arr2 = CAutoArray<CSimpleStringA>(arr1.GetCount());
- for (int i = 0; i < arr1.GetCount(); ++i) {
- arr2[i] = CSimpleStringW2A(arr1[i]);
- result[i] = const_cast<LPSTR>(arr2[i].GetData());
- }
- if (arr1.GetCount() > 4) {
- #ifdef RVC_OS_WIN
- _snprintf(strSwiftName, MAX_PATH, "%s", result[4]);
- #else
- snprintf(strSwiftName, MAX_PATH, "%s", result[4]);
- #endif // RVC_OS_WIN
- }
- delete tmp;
- tmp = NULL;
- }
- CSimpleStringA strTempDir("");
- CSimpleStringA strName("");
- if (Error_Succeed == GetFunction()->GetPath("Temp", strTempDir)) {
- strName = CSimpleStringA::Format("%s/remote_audio_notice_%s.pcm", strTempDir.GetData(), strSwiftName);
- }
- else {
- strName = CSimpleStringA::Format("remote_audio_notice_%s.pcm", strSwiftName);
- }
- m_pFile = fopen(strName.GetData(), "wb+");
- if (NULL == m_pFile) {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("fopen %s failed.", strName.GetData());
- }
- }
- return Error;
- }
- #ifdef RVC_OS_WIN
- DWORD WINAPI StartAudioPlayingThreadFunc(LPVOID param)
- {
- CLocalMediaPlayEntity* entity = (CLocalMediaPlayEntity*)param;
- //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Enter StartAudioPlayingThreadFunc");
- const char* pAudioNames = entity->m_lastPlayAudio.c_str();
- //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Begin StartAudio, and Audio Info is %s.", pAudioNames);
- if (0 == entity->m_iPlayType) {
- HANDLE playEndEvent = NULL;
- entity->m_pAudioPlayer->PlayLocalAudio(pAudioNames);
- if (!entity->m_pAudioPlayer->checkIsPlay(playEndEvent)) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Get audio Play End Event Failed!");
- }
- else {
- WaitForSingleObject(playEndEvent, INFINITE);
- if (entity->m_pAudioPlayer->checkIsStop()) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("stop audio play success.");
- }
- else {
- entity->m_pAudioPlayer->Close();
- }
- }
- }
- else {
- if (0 != entity->m_pMediaAudioPlayer->PlayLocalAudio(pAudioNames)) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("StartAudio failed, for %s is not exist.", pAudioNames);
- }
- }
- //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Leave StartAudioPlayingThreadFunc");
- entity->m_uMediaPlayThreadId = NULL;
- return 0;
- }
- DWORD WINAPI NoticePlayThread(LPVOID param)
- {
- CLocalMediaPlayEntity *entity = (CLocalMediaPlayEntity*)param;
- //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Begin NoticePlayThread");
- HANDLE playEndEvent = NULL;
- if (!entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(playEndEvent)){
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Get notice play end event failed!");
- return 0;
- }
- bool bPlayFinished = FALSE;
- for (;;) {
- DWORD dwRet = WaitForSingleObject(playEndEvent, 100);
- if (dwRet == WAIT_OBJECT_0) { // exit
- bPlayFinished = true;
- break;
- }
- else { // timeout
- if (entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->checkIsStop()){
- break;
- }
- }
- }
- entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->Close();
- if (bPlayFinished){
- VideoPlayRet ret;
- ret.VideoNames = entity->m_lastPlayVideo.c_str();
- ret.ret = true;
- SpSendBroadcast(entity->GetFunction(), eMsg_VideoPlayRet, eMsgSig_VideoPlayRet, ret);
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_NOTICE_PLAY_FINISHED, CSimpleStringA::Format("notice %s play finished.", ret.VideoNames.GetData()).GetData());
- }
- else{
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_NOTICE_PLAY_EARLY_TERM, CSimpleStringA::Format("notice %s play early terminate.", entity->m_lastPlayVideo.c_str()).GetData());
- }
- entity->m_lastPlayVideo.clear();
- //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("End NoticePlayThread");
- return 0;
- }
- DWORD WINAPI MediaPlayThread(LPVOID param)
- {
- CLocalMediaPlayEntity *entity = (CLocalMediaPlayEntity*)param;
- static bool blog = true;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Enter Windows Media Play Thread.");
- while (entity->GetPlayFlag())
- {
- vector<ResourceParse> curParse;
- entity->m_mediaManage.GetPlayListByLocal(curParse);
- unsigned int ustart_time = y2k_time_now();
- if (0 == curParse.size())
- {
- HANDLE playThread = NULL;
- CWmpPlayConfig config;
- ZeroMemory(&config, sizeof(CWmpPlayConfig));
- memcpy(&config, &(entity->m_defaultVideo[entity->m_mediaParam.nCfgInx]), sizeof(CWmpPlayConfig));
- config.nPlayCnt = 1; //can be change
- config.eMode = LOCALVIDEO;
- config.nWndX = entity->m_mediaParam.nWndX;
- config.nWndY = entity->m_mediaParam.nWndY;
- config.nWndWidth = entity->m_mediaParam.nWndWidth;
- config.nWndHeight = entity->m_mediaParam.nWndHeight;
- config.bPrimMonitor = false;
- if (IS_DEBUG){
- config.bFullScreen = false;
- config.bPrimMonitor = true;
- }
- if (!CheckFileExist(config.strRootPath, config.strFileNames[0], blog)){
- break;
- }
- if (false == IsValidPlayTime(config.strVideoRunTime_S, config.strVideoRunTime_E)){
- if (WAIT_TIMEOUT == WaitForSingleObject(entity->m_hStopMediaPlayEvent, 30*DEFAULT_SLEEP_TIME)) {
- continue;
- }
- else {
- break;
- }
- }
- if (!entity->GetLocalVideoVolume(0, config.nVolume)){
- config.nVolume = entity->m_defaultVolum;
- }
- entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
- if (!entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(playThread)){
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Get Play End Event Failed!");
- }
- else{
- WaitForSingleObject(playThread, INFINITE);
- if (entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->checkIsStop()){//停止播放
- //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("stop play video");
- }
- else{
- entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->Close();
- }
- }
- }
- else
- {
- for (vector<ResourceParse>::iterator i = curParse.begin(); i != curParse.end() && entity->GetPlayFlag(); i++)
- {
- HANDLE playThread = NULL;
- if ('V' == i->type)
- {//video
- CWmpPlayConfig config;
- ZeroMemory(&config, sizeof(CWmpPlayConfig));
- config.bFullScreen = IS_DEBUG ? false : i->fullScreen;
- config.bPrimMonitor = IS_DEBUG ? true : false;
- config.bSimpleMode = i->simpleMode;
- config.eMode = LOCALVIDEO;
- config.nFileCnt = 1;
- config.nPlayCnt = 1;
- config.nPlayInterval = i->playInterval;
- if (!entity->GetLocalVideoVolume(0, config.nVolume)){
- config.nVolume = entity->m_defaultVolum;
- }
- //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("config.nVolume=%d while play local video.", config.nVolume);
- config.nWndX = entity->m_mediaParam.nWndX;
- config.nWndY = entity->m_mediaParam.nWndY;
- config.nWndWidth = entity->m_mediaParam.nWndWidth;
- config.nWndHeight = entity->m_mediaParam.nWndHeight;
- strncpy_s(config.strRootPath, i->resourcePath.c_str(), sizeof(config.strRootPath));
- strncpy_s(config.strFileNames[0], i->videoNames.c_str(), 256);
- strncpy_s(config.strVideoRunTime_S, RVC_VIDEOPLAY_START_TIME, sizeof(config.strVideoRunTime_S));
- strncpy_s(config.strVideoRunTime_E, RVC_VIDEOPLAY_END_TIME, sizeof(config.strVideoRunTime_E));
- if (false == IsValidPlayTime(config.strVideoRunTime_S, config.strVideoRunTime_E)) {
- if (WAIT_TIMEOUT == WaitForSingleObject(entity->m_hStopMediaPlayEvent, 30 * DEFAULT_SLEEP_TIME)) {
- continue;
- }
- else {
- break;
- }
- }
- if(!CheckFileExist(config.strRootPath, config.strFileNames[0], blog)){
- continue;
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("begin play extend [Media] %c:%s, %s", i->type, i->resourcePath.c_str(), i->videoNames.c_str());
- entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
- if (!entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(playThread)){
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Get Play End Event Failed!");
- }
- else{
- WaitForSingleObject(playThread, INFINITE);
- if (entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->checkIsStop()){//停止播放
- //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("stop play video");
- }
- else{
- entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->Close();
- }
- }
- }
- else if ('P' == i->type)
- {//play Image
- CImgPlayConfig config;
- ZeroMemory(&config, sizeof(CImgPlayConfig));
- config.bFullScreen = IS_DEBUG ? false : i->fullScreen;
- config.bPrimMonitor = IS_DEBUG ? true : false;
- config.nFileCnt = 1;
- config.nPlayCnt = 1;
- config.nPlayInterval = i->playInterval;
- config.nWndX = entity->m_mediaParam.nWndX;
- config.nWndY = entity->m_mediaParam.nWndY;
- config.nWndWidth = entity->m_mediaParam.nWndWidth;
- config.nWndHeight = entity->m_mediaParam.nWndHeight;
- strncpy_s(config.strRootPath, i->resourcePath.c_str(), sizeof(config.strRootPath));
- strncpy_s(config.strFileNames[0], i->videoNames.c_str(), 256);
- if (!CheckFileExist(config.strRootPath, config.strFileNames[0], blog)) {
- continue;
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("begin play extend [Media] %c:%s, %s", i->type, i->resourcePath.c_str(), i->videoNames.c_str());
- entity->m_pImagePlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
- if (!entity->m_pImagePlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(playThread)){
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Create play Image Media Thread Failed!");
- }
- else
- {
- WaitForSingleObject(playThread, i->playInterval);
- if (entity->m_pImagePlayer[entity->m_mediaParam.nCfgInx]->checkIsStop()){//停止播放
- //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("stop play Image");
- }
- else{
- entity->m_pImagePlayer[entity->m_mediaParam.nCfgInx]->Close();
- }
- }
- }
- }
- }
- unsigned int uend_time = y2k_time_now();
- if (uend_time - ustart_time < RVC_MIN_LOCALPLAYER_TIME) {
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_MEDIAPLAY_COST_TIME_ERROR, "广告播放时长不足1秒");
- break;
- }
- blog = false;
- }
- if (entity->m_badplayflag) {
- entity->m_badplayflag = false;
- }
-
- if (entity->m_playThread) {
- entity->m_playThread = NULL;
- }
-
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Exit Windows Media Play Thread.");
- return 0;
- }
- DWORD WINAPI StartMediaPlayFunc(LPVOID param)
- {
- int iRet = -1;
- if (NULL == param){
- return iRet;
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Enter FFmpeg Media Play Function.");
- CLocalMediaPlayEntity* entity = (CLocalMediaPlayEntity*)param;
- static bool blog = true;
- while (entity->GetPlayFlag())
- {
- vector<ResourceParse> curParse;
- entity->m_mediaManage.GetPlayListByLocal(curParse);
- unsigned int ustart_time = y2k_time_now();
- if (0 == curParse.size()){
- CMediaPlayConfig config = {0};
- memcpy(&config, &(entity->m_Videos[entity->m_mediaParam.nCfgInx]), sizeof(CMediaPlayConfig));
- config.nPlayCnt = 1; //can be change
- config.eMode = MEDIA_LOCALVIDEO;
- config.nWndX = entity->m_mediaParam.nWndX;
- config.nWndY = entity->m_mediaParam.nWndY;
- config.nWndWidth = entity->m_mediaParam.nWndWidth;
- config.nWndHeight = entity->m_mediaParam.nWndHeight;
- config.bPrimMonitor = false;
- if (IS_DEBUG){
- config.bFullScreen = false;
- config.bPrimMonitor = true;
- }
- if (!entity->GetLocalVideoVolume(0, config.nVolume)){
- config.nVolume = entity->m_defaultVolum;
- }
- if(false == IsValidPlayTime(config.strVideoRunTime_S, config.strVideoRunTime_E)){
- if (WAIT_TIMEOUT == WaitForSingleObject(entity->m_hStopMediaPlayEvent, 30 * DEFAULT_SLEEP_TIME)) {
- continue;
- }
- else {
- break;
- }
- }
- if (!CheckFileExist(config.strRootPath, config.strFileNames[0], blog)) {
- break;
- }
- if (-1 == entity->m_pMediaPlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config)){
- break;
- }
- }
- for (int i = 0; i < curParse.size() && entity->GetPlayFlag(); i++)
- {
- HANDLE playThreadId = 0;
- ResourceParse item = curParse[i];
- if ('V' == item.type)
- {//video
- CMediaPlayConfig config = {0};
- config.bFullScreen = IS_DEBUG ? false : item.fullScreen;
- config.bPrimMonitor = IS_DEBUG ? true : false;
- config.bSimpleMode = item.simpleMode;
- config.eMode = MEDIA_LOCALVIDEO;
- config.nFileCnt = 1;
- config.nPlayCnt = 1;
- config.nPlayInterval = item.playInterval;
- if (!entity->GetLocalVideoVolume(0, config.nVolume)){
- config.nVolume = entity->m_defaultVolum;
- }
- config.nWndX = entity->m_mediaParam.nWndX;
- config.nWndY = entity->m_mediaParam.nWndY;
- config.nWndWidth = entity->m_mediaParam.nWndWidth;
- config.nWndHeight = entity->m_mediaParam.nWndHeight;
- strncpy(config.strRootPath, item.resourcePath.c_str(), item.resourcePath.length() < MAX_PATH ? item.resourcePath.length() : MAX_PATH);
- strncpy(config.strFileNames[0], item.videoNames.c_str(), item.videoNames.length() < MAX_PATH ? item.videoNames.length() : MAX_PATH);
- strncpy(config.strVideoRunTime_S, RVC_VIDEOPLAY_START_TIME, sizeof(config.strVideoRunTime_S));
- strncpy(config.strVideoRunTime_E, RVC_VIDEOPLAY_END_TIME, sizeof(config.strVideoRunTime_E));
-
- if (false == IsValidPlayTime(config.strVideoRunTime_S, config.strVideoRunTime_E)){
- if (WAIT_TIMEOUT == WaitForSingleObject(entity->m_hStopMediaPlayEvent, 30 * DEFAULT_SLEEP_TIME)) {
- continue;
- }
- else {
- break;
- }
- }
- if (!CheckFileExist(config.strRootPath, config.strFileNames[0], blog)) {
- continue;
- }
- 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());
- int iPlayRet = entity->m_pMediaPlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
- if (-3 == iPlayRet) {
- if (WAIT_TIMEOUT == WaitForSingleObject(entity->m_hStopMediaPlayEvent, DEFAULT_SLEEP_TIME)) {
- continue;
- }
- else {
- break;
- }
- }
- }
- else if ('P' == item.type)
- {//play Image
- CPicPlayConfig config = {0};
- config.bFullScreen = IS_DEBUG ? false : item.fullScreen;
- config.bPrimMonitor = IS_DEBUG ? true : false;
- config.nFileCnt = 1;
- config.nPlayCnt = 1;
- config.nPlayInterval = item.playInterval;
- config.nWndX = entity->m_mediaParam.nWndX;
- config.nWndY = entity->m_mediaParam.nWndY;
- config.nWndWidth = entity->m_mediaParam.nWndWidth;
- config.nWndHeight = entity->m_mediaParam.nWndHeight;
- strncpy(config.strRootPath, item.resourcePath.c_str(), item.resourcePath.length() < MAX_PATH ? item.resourcePath.length() : MAX_PATH);
- strncpy(config.strFileNames[0], item.videoNames.c_str(), item.videoNames.length() < MAX_PATH ? item.videoNames.length() : MAX_PATH);
-
- if (!CheckFileExist(config.strRootPath, config.strFileNames[0], blog)) {
- continue;
- }
- if (entity->m_pPicturePlayer[entity->m_mediaParam.nCfgInx]->checkIsStop()){
- 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());
- entity->m_pPicturePlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
- if (!entity->m_pPicturePlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(&playThreadId)) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Create play Image Media Thread Failed!");
- iRet = -1;
- return iRet;
- }
- WaitForSingleObject(playThreadId, INFINITE);
- if (entity->m_pPicturePlayer[entity->m_mediaParam.nCfgInx]->checkIsStop()){//停止播放
- //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("stop play video");
- }
- else{
- entity->m_pPicturePlayer[entity->m_mediaParam.nCfgInx]->Close();
- }
- }
- }
- }
- unsigned int uend_time = y2k_time_now();
- //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("uend_time - ustart_time = %u.", uend_time - ustart_time);
- if (uend_time - ustart_time < RVC_MIN_LOCALPLAYER_TIME) {
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_MEDIAPLAY_COST_TIME_ERROR, "广告播放时长不足1秒");
- break;
- }
- blog = false;
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Leave Media Play Function.");
- if (entity->m_badplayflag) {
- entity->m_badplayflag = false;
- }
- if (0 != entity->m_uMediaPlayThreadId) {
- entity->m_uMediaPlayThreadId = 0;
- }
- return iRet;
- }
- #else
- void* StartAudioPlayingThreadFunc(void* param)
- {
- CLocalMediaPlayEntity* entity = (CLocalMediaPlayEntity*)param;
- const char* pAudioNames = entity->m_lastPlayAudio.c_str();
- if (0 != entity->m_pMediaAudioPlayer->PlayLocalAudio(pAudioNames)) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("StartAudio failed, for %s is not exsit.", pAudioNames);
- }
- entity->m_uAudioPlayThreadId = 0;
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Exit Start Audio Playing Thread Function.");
- return 0;
- }
- void* StartMediaPlayFunc(void* param)
- {
- int iRet = -1;
- if (NULL == param) {
- return (void*)&iRet;
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Enter FFmpeg Media Play Function.");
- CLocalMediaPlayEntity* entity = (CLocalMediaPlayEntity*)param;
- static bool blog = true;
- while (entity->GetPlayFlag())
- {
- rvcResourceParse_t ResourceList[MAX_LOCAL_MEDIAS] = { 0 };
- int iCount = entity->m_mediaManage.GetPlayListByLocal(ResourceList, MAX_LOCAL_MEDIAS);
- unsigned int ustart_time = y2k_time_now();
- if (0 == iCount) {
- int64_t playThreadId = 0;
- CMediaPlayConfig config = { 0 };
- memcpy(&config, &(entity->m_Videos[entity->m_mediaParam.nCfgInx]), sizeof(CMediaPlayConfig));
- config.nPlayCnt = 1; //can be change
- config.eMode = MEDIA_LOCALVIDEO;
- config.nWndX = entity->m_mediaParam.nWndX;
- config.nWndY = entity->m_mediaParam.nWndY;
- config.nWndWidth = entity->m_mediaParam.nWndWidth;
- config.nWndHeight = entity->m_mediaParam.nWndHeight;
- config.bPrimMonitor = false;
- if (IS_DEBUG) {
- config.bFullScreen = false;
- config.bPrimMonitor = true;
- }
- if (!entity->GetLocalVideoVolume(0, config.nVolume)) {
- config.nVolume = entity->m_defaultVolum;
- }
- if (false == IsValidPlayTime(config.strVideoRunTime_S, config.strVideoRunTime_E)){
- struct timespec ts;
- clock_gettime(CLOCK_REALTIME, &ts);
- ts.tv_sec += 30;
- int iresult = sem_timedwait(&entity->m_stop_mediaplay_semt, &ts);
- if (0 != iresult && (ETIMEDOUT == errno)) {
- continue;
- }
- else {
- break;
- }
- }
- if (!CheckFileExist(config.strRootPath, config.strFileNames[0], blog)) {
- break;
- }
-
- if (-1 == entity->m_pMediaPlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config)) {
- break;
- }
- }
- for (int i = 0; i < iCount && i < MAX_LOCAL_MEDIAS && entity->GetPlayFlag(); i++)
- {
- int64_t playThreadId = 0;
- rvcResourceParse_t item = ResourceList[i];
- if ('V' == item.type)
- {//video
- CMediaPlayConfig config = { 0 };
- config.bFullScreen = IS_DEBUG ? false : item.fullScreen;
- config.bPrimMonitor = IS_DEBUG ? true : false;
- config.bSimpleMode = item.simpleMode;
- config.eMode = MEDIA_LOCALVIDEO;
- config.nFileCnt = 1;
- config.nPlayCnt = 1;
- config.nPlayInterval = item.playInterval;
- if (!entity->GetLocalVideoVolume(0, config.nVolume)) {
- config.nVolume = entity->m_defaultVolum;
- }
- config.nWndX = entity->m_mediaParam.nWndX;
- config.nWndY = entity->m_mediaParam.nWndY;
- config.nWndWidth = entity->m_mediaParam.nWndWidth;
- config.nWndHeight = entity->m_mediaParam.nWndHeight;
- strncpy(config.strRootPath, item.strResourcePath, strlen(item.strResourcePath));
- strncpy(config.strFileNames[0], item.strvideoNames, strlen(item.strvideoNames));
- strncpy(config.strVideoRunTime_S, RVC_VIDEOPLAY_START_TIME, sizeof(config.strVideoRunTime_S));
- strncpy(config.strVideoRunTime_E, RVC_VIDEOPLAY_END_TIME, sizeof(config.strVideoRunTime_E));
-
- if (false == IsValidPlayTime(config.strVideoRunTime_S, config.strVideoRunTime_E)) {
- struct timespec ts;
- clock_gettime(CLOCK_REALTIME, &ts);
- ts.tv_sec += 30;
- if (0 != sem_timedwait(&entity->m_stop_mediaplay_semt, &ts) && (ETIMEDOUT == errno)) {
- continue;
- }
- else {
- break;
- }
- }
- if (!CheckFileExist(config.strRootPath, config.strFileNames[0], blog)) {
- continue;
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("begin play extend %c:%s, %s", item.type, item.strResourcePath, item.strvideoNames);
- int iPlayRet = entity->m_pMediaPlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
- if (-3 == iPlayRet) {
- struct timespec ts;
- clock_gettime(CLOCK_REALTIME, &ts);
- ts.tv_sec += 2;
- if (0 != sem_timedwait(&entity->m_stop_mediaplay_semt, &ts) && (ETIMEDOUT == errno)) {
- continue;
- }
- else {
- break;
- }
- }
- }
- else if ('P' == item.type)
- {//play Image
- CPicPlayConfig config = { 0 };
- config.bFullScreen = IS_DEBUG ? false : item.fullScreen;
- config.bPrimMonitor = IS_DEBUG ? true : false;
- config.nFileCnt = 1;
- config.nPlayCnt = 1;
- config.nPlayInterval = item.playInterval;
- config.nWndX = entity->m_mediaParam.nWndX;
- config.nWndY = entity->m_mediaParam.nWndY;
- config.nWndWidth = entity->m_mediaParam.nWndWidth;
- config.nWndHeight = entity->m_mediaParam.nWndHeight;
- strncpy(config.strRootPath, item.strResourcePath, strlen(item.strResourcePath));
- strncpy(config.strFileNames[0], item.strvideoNames, strlen(item.strvideoNames));
- if (!CheckFileExist(config.strRootPath, config.strFileNames[0], blog)) {
- continue;
- }
- if (entity->m_pPicturePlayer[entity->m_mediaParam.nCfgInx]->checkIsStop()) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("begin play extend %c:%s, %s", item.type, item.strResourcePath, item.strvideoNames);
- entity->m_pPicturePlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
- if (!entity->m_pPicturePlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(&playThreadId)) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Create play Image Media Thread Failed!");
- iRet = -1;
- return (void*)&iRet;
- }
- if (0 == pthread_join(playThreadId, NULL)) {
- iRet = 0;
- }
- else {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("pthread join thread id %u failed for %s.", playThreadId, strerror(errno));
- iRet = -1;
- }
- }
- }
- }
- unsigned int uend_time = y2k_time_now();
- if (uend_time - ustart_time < RVC_MIN_LOCALPLAYER_TIME) {
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_MEDIAPLAY_COST_TIME_ERROR, "广告播放时长不足1秒");
- break;
- }
- blog = false;
- }
- entity->m_uMediaPlayThreadId = 0;
-
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Leave FFmpeg Media Play Function.");
- return (void*)&iRet;
- }
- void* StartNoticePlayThreadFunc(void* param)
- {
- int iRet = -1;
- CLocalMediaPlayEntity* entity = (CLocalMediaPlayEntity*)param;
- const char* pVideoName = entity->m_lastPlayVideo.c_str();
- Clibmediaplayer* player = entity->m_pMediaPlayer[entity->m_mediaParam.nCfgInx];
- player->PlayVideoNotice(entity->m_mediaParam.nWndX, entity->m_mediaParam.nWndY, entity->m_mediaParam.nWndWidth, entity->m_mediaParam.nWndHeight, pVideoName);
- entity->m_uNoticePlayThreadId = 0;
- iRet = 0;
- return (void*)&iRet;
- }
- #endif
- DeviceTypeEnum CLocalMediaPlayEntity::RvcGetDeviceType()
- {
- DeviceTypeEnum eType = eStand2sType;
- CSmartPointer<IEntityFunction> spFunction = GetFunction();
- CSystemStaticInfo stStaticinfo;
- spFunction->GetSystemStaticInfo(stStaticinfo);
- if (_stricmp(stStaticinfo.strMachineType, "RVC.Stand1SPlus") == 0) {
- eType = eStand1SPlusType;
- }
- else if (_stricmp(stStaticinfo.strMachineType, "RVC.CardStore") == 0 || _stricmp(stStaticinfo.strMachineType, "RVC.CardPrinter") == 0) {
- eType = eCardStore;
- }
- else {
- eType = eStand2sType;
- }
- if (eType >= 0 && eType < sizeof(Device_Type_Table) / sizeof(char*)) {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("device type is %s.", Device_Type_Table[eType]);
- }
- return eType;
- }
- void CLocalMediaPlayEntity::StartVideo(int nCfgInx, int nWndX, int nWndY, int nWndWidth, int nWndHeight)
- {
- if(eStand2sType == m_eDeviceType){
- if (nCfgInx >= MAX_PLAY_CHANNELS || nCfgInx < 0){
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Invalid CfgInx while StartVideo!");
- return;
- }
- m_mediaParam.nCfgInx = nCfgInx;
- m_mediaParam.nWndX = nWndX;
- m_mediaParam.nWndY = nWndY;
- m_mediaParam.nWndWidth = nWndWidth;
- m_mediaParam.nWndHeight = nWndHeight;
- #ifdef RVC_OS_WIN
- if (0 == m_iPlayType) {
- if (NULL != m_playThread) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Current is playing video, close it.");
- StopVideo(nCfgInx);
- }
- if (NULL == m_playThread) {
- m_hStopMediaPlayEvent = CreateEventA(NULL, false, false, NULL);
- m_badplayflag = true;
- m_playThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&MediaPlayThread, this, 0, NULL);
- }
- }
- else {
- if (NULL != m_uMediaPlayThreadId) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Current is playing video, close it.");
- StopVideo(nCfgInx);
- }
- m_hStopMediaPlayEvent = CreateEventA(NULL, false, false, NULL);
- m_badplayflag = true;
- m_uMediaPlayThreadId = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&StartMediaPlayFunc, this, 0, NULL);
- }
- #else
- sem_init(&m_stop_mediaplay_semt, 0, 0);
- m_badplayflag = true;
- int err = pthread_create(&m_uMediaPlayThreadId, NULL, StartMediaPlayFunc, this);
- if (0 != err) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create media play thread failed.");
- }
- #endif // RVC_OS_WIN
- }
- }
- void CLocalMediaPlayEntity::StartAudio(const char *pAudioNames)
- {
- if (NULL != pAudioNames) {
- char strAudios[MAX_PATH] = { 0 };
- rvc_snprintf(strAudios, MAX_PATH, "%s", pAudioNames);
- const char* d = "|";
- char* pName = NULL;
- char* pdata = NULL;
- #ifdef RVC_OS_WIN
- pName = strtok_s(strAudios, d, &pdata);
- #else
- pName = strtok_r(strAudios, d, &pdata);
- #endif
- while (pName) {
- CSimpleStringA strAudioFileName = pName;
- CSimpleStringA strAudioFullPath = m_AudioPath + strAudioFileName;
- if (!ExistsFileA(strAudioFullPath.GetData())) {
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_ADV_AUDIO_NOT_EXIST, CSimpleStringA::Format("audio file %s not exist!", strAudioFullPath.GetData()).GetData());
- return;
- }
- #ifdef RVC_OS_WIN
- pName = strtok_s(NULL, d, &pdata);
- #else
- pName = strtok_r(NULL, d, &pdata);
- #endif
- }
- }
- #ifdef RVC_OS_WIN
- if (0 == m_iPlayType) {
- if (!m_pAudioPlayer->checkIsStop()) {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("current is playing, close it.");
- StopAudio();
- }
- m_lastPlayAudio = pAudioNames;
- m_uAudioPlayThreadId = CreateThread(NULL, 0, StartAudioPlayingThreadFunc, this, 0, NULL);
- m_buserstopaudio = false;
- auto audioRet = GetLocalAudioVolume();
- m_pMediaAudioPlayer->SetVolume(audioRet.second);
- }
- else
- {
- if (m_pMediaAudioPlayer->checkIsPlay()) {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("current is playing, close it.");
- StopAudio();
- }
- m_lastPlayAudio = pAudioNames;
- m_uAudioPlayThreadId = CreateThread(NULL, 0, StartAudioPlayingThreadFunc, this, 0, NULL);
- m_buserstopaudio = false;
- auto audioRet = GetLocalAudioVolume();
- m_pMediaAudioPlayer->SetVolume(audioRet.second);
- //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Succeed to set audio volume %d!", audioRet.second);
- }
- #else
- if (m_pMediaAudioPlayer->checkIsPlay()) {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("current is playing, close it.");
- StopAudio();
- }
- else {
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("current is not playing, start paly audio %s.", pAudioNames);
- }
- m_lastPlayAudio = pAudioNames;
- int err = pthread_create(&m_uAudioPlayThreadId, NULL, StartAudioPlayingThreadFunc, this);
- if (0 != err) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create audio play thread failed.");
- }
- m_buserstopaudio = false;
- auto audioRet = GetLocalAudioVolume();
- m_pMediaAudioPlayer->SetVolume(audioRet.second);
- #endif
- }
- void CLocalMediaPlayEntity::StartImage(int nCfgInx, int nWndX, int nWndY, int nWndWidth, int nWndHeight)
- {
- if(eStand2sType == m_eDeviceType){
- if (nCfgInx >= MAX_PLAY_CHANNELS || nCfgInx < 0){
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Invalid CfgInx while StartImage!");
- return;
- }
- #ifdef RVC_OS_WIN
- if (0 == m_iPlayType){
- m_pImagePlayer[nCfgInx]->Play(nCfgInx, nWndX, nWndY, nWndWidth, nWndHeight);
- }
- else{
- m_pPicturePlayer[nCfgInx]->Play(nCfgInx, nWndX, nWndY, nWndWidth, nWndHeight);
- }
- #else
- m_pPicturePlayer[nCfgInx]->Play(nCfgInx, nWndX, nWndY, nWndWidth, nWndHeight);
- #endif
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Succeed to StartImage!");
- }
- }
- void CLocalMediaPlayEntity::StopVideo(int nCfgInx)
- {
- if(eStand2sType == m_eDeviceType){
- if (nCfgInx >= MAX_PLAY_CHANNELS || nCfgInx < 0){
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Invalid CfgInx while StopVideo!");
- return;
- }
- m_badplayflag = false;
- #ifdef RVC_OS_WIN
- if (0 == m_iPlayType){
- if (NULL != m_playThread) {
- m_pVideoPlayer[nCfgInx]->Close();
- m_pImagePlayer[nCfgInx]->Close();
- SetEvent(m_hStopMediaPlayEvent);
- WaitForSingleObject(m_playThread, INFINITE);
- m_playThread = NULL;
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Succeed to StopVideo!");
- CloseHandle(m_hStopMediaPlayEvent);
- }
- }
- else{
- if (NULL != m_uMediaPlayThreadId) {
- m_pMediaPlayer[nCfgInx]->Close();
- m_pPicturePlayer[nCfgInx]->Close();
- SetEvent(m_hStopMediaPlayEvent);
- WaitForSingleObject(m_uMediaPlayThreadId, INFINITE);
- m_uMediaPlayThreadId = NULL;
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Succeed to StopVideo!");
- CloseHandle(m_hStopMediaPlayEvent);
- }
- }
- #else
- if (0 != m_uMediaPlayThreadId) {
- m_pMediaPlayer[nCfgInx]->Close();
- m_pPicturePlayer[nCfgInx]->Close();
- sem_post(&m_stop_mediaplay_semt);
- pthread_join(m_uMediaPlayThreadId, NULL);
- m_uMediaPlayThreadId = 0;
- sem_destroy(&m_stop_mediaplay_semt);
- }
- #endif
- }
- }
- void CLocalMediaPlayEntity::StopAudio()
- {
- #ifdef RVC_OS_WIN
- if (NULL != m_uAudioPlayThreadId) {
- if (0 == m_iPlayType) {
- m_pAudioPlayer->Close();
- }
- else {
- m_pMediaAudioPlayer->Close();
- }
- m_buserstopaudio = true;
- WaitForSingleObject(m_uAudioPlayThreadId, INFINITE);
- m_uAudioPlayThreadId = NULL;
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Succeed to StopAudio!");
- }
- #else
- if (0 != m_uAudioPlayThreadId) {
- m_pMediaAudioPlayer->Close();
- m_buserstopaudio = true;
- pthread_join(m_uAudioPlayThreadId, NULL);
- m_uAudioPlayThreadId = 0;
- }
- #endif
- }
- void CLocalMediaPlayEntity::StopImage(int nCfgInx)
- {
- if(eStand2sType == m_eDeviceType){
- if (nCfgInx >= MAX_PLAY_CHANNELS || nCfgInx < 0){
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Invalid CfgInx while StopImage!");
- return;
- }
- #ifdef RVC_OS_WIN
- if (0 == m_iPlayType){
- if (false == m_pImagePlayer[nCfgInx]->checkIsStop()) {
- m_pImagePlayer[nCfgInx]->Close();
- //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Succeed to StopImage!");
- }
- }
- else{
- if (false == m_pPicturePlayer[nCfgInx]->checkIsStop()) {
- m_pPicturePlayer[nCfgInx]->Close();
- //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Succeed to StopImage!");
- }
- }
- #else
- if (false == m_pPicturePlayer[nCfgInx]->checkIsStop()) {
- m_pPicturePlayer[nCfgInx]->Close();
- }
- #endif
- }
- }
- void CLocalMediaPlayEntity::StopAll()
- {
- StopAudio(); // 关闭音频
- for (int i = 0; i < MAX_PLAY_CHANNELS; ++i){
- StopVideo(i); // 关闭视频
- StopImage(i); // 关闭图像
- StopNotice(i); // 关闭视频提示
- }
- }
- bool CLocalMediaPlayEntity::GetLocalVideoVolume(int nCfgInx, int &nVolume)
- {
- //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get local video volume req.");
- CSmartPointer<IConfigInfo> spConfig;
- ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_Run, spConfig);
- if (Error == Error_Succeed)
- {
- Error = spConfig->ReadConfigValueInt("LocalVideo", "Volume", nVolume);
- if (Error == Error_Succeed && nVolume >= 0 && nVolume <= 100)
- {
- return true;
- }
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("fail to get local video volume!");
- return false;
- }
- std::pair<bool, int> CLocalMediaPlayEntity::GetLocalAudioVolume()
- {
- CSmartPointer<IConfigInfo> spConfig;
- int nVolume = 0;
- ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_Run, spConfig);
- if (Error == Error_Succeed)
- {
- Error = spConfig->ReadConfigValueInt("LocalAudio", "Volume", nVolume);
- if (nVolume == 0)
- {
- nVolume = 50;
- spConfig->WriteConfigValueInt("LocalAudio", "Volume", nVolume);
- }
- if (Error == Error_Succeed && nVolume >= 0 && nVolume <= 100)
- {
- return std::make_pair(true, nVolume);
- }
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("fail to get local audio volume!");
- return std::make_pair(false, nVolume);
- }
- bool CLocalMediaPlayEntity::SetLocalAudioVolume(int nVolume)
- {
- if (nVolume < 0 || nVolume > 100){
- return false;
- }
- CSmartPointer<IConfigInfo> spConfig;
- ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_Run, spConfig);
- if (Error == Error_Succeed)
- {
- Error = spConfig->WriteConfigValueInt("LocalAudio", "Volume", nVolume);
- if (Error == Error_Succeed)
- {
- #ifdef RVC_OS_WIN
- if (0 == m_iPlayType) {
- m_pAudioPlayer->SetVolume(nVolume);
- }
- else {
- m_pMediaAudioPlayer->SetVolume(nVolume);
- }
- #else
- m_pMediaAudioPlayer->SetVolume(nVolume);
- #endif
- return true;
- }
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("fail to set local video volume!");
- return false;
- }
- bool CLocalMediaPlayEntity::SetLocalVideoVolume(int nCfgInx, int nVolume)
- {
- if (nVolume < 0 || nVolume > 100){
- return false;
- }
- CSmartPointer<IConfigInfo> spConfig;
- ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_Run, spConfig);
- if (Error == Error_Succeed)
- {
- Error = spConfig->WriteConfigValueInt("LocalVideo", "Volume", nVolume);
- if (Error == Error_Succeed)
- {
- for (int i = 0; i < MAX_PLAY_CHANNELS; ++i)
- {
- #ifdef RVC_OS_WIN
- if (0 == m_iPlayType){
- m_pVideoPlayer[i]->SetVolume(nVolume);
- }
- else{
- m_pMediaPlayer[i]->SetVolume(nVolume);
- }
- #else
- m_pMediaPlayer[i]->SetVolume(nVolume);
- #endif
- }
- return true;
- }
- }
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("fail to set local video volume!");
- return false;
- }
- bool CLocalMediaPlayEntity::IsRunConfigExist()
- {
- CSimpleStringA strPath;
- ErrorCodeEnum eErr;
- if ((eErr = GetFunction()->GetPath("RunInfo", strPath)) != Error_Succeed){
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get runinfo path failed(%d)", eErr);
- return false;
- }
- CSimpleStringA strRuninfoFile;
- strRuninfoFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR "%s.ini", (LPCTSTR)strPath, GetEntityName());
- if (ExistsFileA(strRuninfoFile)) {
- return true;
- }
- else {
- return false;
- }
- }
- ErrorCodeEnum CLocalMediaPlayEntity::StartMediaPlayerNotice(int nCfgInx, int nWndX, int nWndY, int nWndWidth, int nWndHeight, const char *pVideoName)
- {
- #ifdef RVC_OS_WIN
- if (false == m_pAudioPlayer->checkIsStop()) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("audio current is playing, close it.");
- StopAudio();
- }
- if (false == m_pVideoPlayer[nCfgInx]->checkIsStop()) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("notice current is playing, close it.");
- StopNotice(nCfgInx);
- }
- #endif // RVC_OS_WI
- m_mediaParam.nCfgInx = nCfgInx;
- m_mediaParam.nWndX = nWndX;
- m_mediaParam.nWndY = nWndY;
- m_mediaParam.nWndWidth = nWndWidth%2 ? nWndWidth+1 : nWndWidth;
- m_mediaParam.nWndHeight = nWndHeight%2 ? nWndHeight+1 : nWndHeight;
- CSimpleStringA strPath;
- ErrorCodeEnum Error = GetFunction()->GetPath("ADData", strPath);
- if (Error == Error_Succeed) {
- #ifdef RVC_OS_WIN
- CSimpleStringA VideoPath = strPath + SPLIT_SLASH_STR + "Video" + SPLIT_SLASH_STR;
- CSimpleStringA strNoticeFileName = VideoPath + pVideoName;
- if(ExistsFileA(strNoticeFileName.GetData())){
- if (m_pMediaPlayer[nCfgInx]->IsFileValid(strNoticeFileName.GetData())){
- int iVolume = 60;
- GetLocalVideoVolume(nCfgInx,iVolume);
- m_pVideoPlayer[nCfgInx]->SetVolume(iVolume);
- m_lastPlayVideo = pVideoName;
- m_uNoticePlayThreadId = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&StartNoticePlayThreadFunc, this, 0, NULL);
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_START_NOTICE_PLAY, CSimpleStringA::Format("start play notice %s", strNoticeFileName.GetData()).GetData());
- }
- else{
- Error = Error_InvalidState;
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_NOTICE_FILE_NOT_VALID, CSimpleStringA::Format("play notice failed for %s is not valid!", strNoticeFileName.GetData()).GetData());
- }
- }
- else{
- Error = Error_InvalidState;
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_NOTICE_FILE_NOT_EXIST, CSimpleStringA::Format("play notice failed for %s not exist!", strNoticeFileName.GetData()).GetData());
- }
- #endif
- }
- return Error;
- }
- #ifdef RVC_OS_WIN
- DWORD WINAPI StartNoticePlayThreadFunc(LPVOID param)
- {
- int iRet = -1;
- CLocalMediaPlayEntity* entity = (CLocalMediaPlayEntity*)param;
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Enter NoticePlayThreadFunc and process id is %u, thread id is %u.", GetCurrentProcessId(), GetCurrentThreadId());
- const char* pVideoName = entity->m_lastPlayVideo.c_str();
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Begin Start Notice Play, and Video Notice Info is %s.", pVideoName);
- int nCfgInx = entity->m_mediaParam.nCfgInx;
- int nWndX = entity->m_mediaParam.nWndX;
- int nWndY = entity->m_mediaParam.nWndY;
- int nWndWidth = entity->m_mediaParam.nWndWidth;
- int nWndHeight = entity->m_mediaParam.nWndHeight;
- if (0 == entity->m_iPlayType) {
- HANDLE playEndEvent = NULL;
- entity->m_pVideoPlayer[nCfgInx]->PlayVideoNotice(nWndX, nWndY, nWndWidth, nWndHeight, entity->m_VideoPath.GetData(), pVideoName);
- if (!entity->m_pVideoPlayer[nCfgInx]->checkIsPlay(playEndEvent)) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Get notice Play End Event Failed!");
- }
- else {
- WaitForSingleObject(playEndEvent, INFINITE);
- if (entity->m_pVideoPlayer[nCfgInx]->checkIsStop()) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("stop notice play success.");
- }
- else {
- entity->m_pVideoPlayer[nCfgInx]->Close();
- }
- }
- }
- else {
- Clibmediaplayer* player = entity->m_pMediaPlayer[nCfgInx];
- player->PlayVideoNotice(nWndX, nWndY, nWndWidth, nWndHeight, pVideoName);
- }
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Succeed to Start Notice Play, and Video Notice Info is %s.", pVideoName);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Leave NoticePlayThreadFunc");
- entity->m_uNoticePlayThreadId = NULL;
- iRet = 0;
- return iRet;
- }
- #endif
- ErrorCodeEnum CLocalMediaPlayEntity::StartFFPlayerNotice(int nCfgInx, int nWndX, int nWndY, int nWndWidth, int nWndHeight, const char *pVideoName)
- {
- ErrorCodeEnum Error = Error_Succeed;
- if (m_pMediaAudioPlayer->checkIsPlay()) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("audio current is playing, close it.");
- StopAudio();
- }
- if (m_pMediaPlayer[nCfgInx]->checkIsPlay()) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("notice current is playing, close it.");
- StopNotice(nCfgInx);
- }
- m_mediaParam.nCfgInx = nCfgInx;
- m_mediaParam.nWndX = nWndX;
- m_mediaParam.nWndY = nWndY;
- m_mediaParam.nWndWidth = nWndWidth % 2 ? nWndWidth + 1 : nWndWidth;
- m_mediaParam.nWndHeight = nWndHeight % 2 ? nWndHeight + 1 : nWndHeight;
- CSimpleStringA strPath;
- Error = GetFunction()->GetPath("ADData", strPath);
- if (Error == Error_Succeed) {
- CSimpleStringA VideoPath = strPath + SPLIT_SLASH_STR + "Video" + SPLIT_SLASH_STR;
- CSimpleStringA strNoticeFileName = VideoPath + CSimpleStringA(pVideoName);
- BOOL bRet = ExistsFile(strNoticeFileName.GetData());
- if (bRet) {
- if (m_pMediaPlayer[nCfgInx]->IsFileValid(strNoticeFileName.GetData())){
- int iVolume = 60;
- GetLocalVideoVolume(nCfgInx, iVolume);
- m_pMediaPlayer[nCfgInx]->SetVolume(iVolume);
- m_lastPlayVideo = strNoticeFileName.GetData();
- #ifdef RVC_OS_WIN
- m_uNoticePlayThreadId = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&StartNoticePlayThreadFunc, this, 0, NULL);
- if (NULL != m_uNoticePlayThreadId) {
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_START_NOTICE_PLAY, CSimpleStringA::Format("start play video notice %s", strNoticeFileName.GetData()).GetData());
- }
- else {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create notice play thread failed.");
- }
- #else
- int err = pthread_create(&m_uNoticePlayThreadId, NULL, StartNoticePlayThreadFunc, this);
- if (0 == err) {
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_START_NOTICE_PLAY, CSimpleStringA::Format("start play video notice %s", strNoticeFileName.GetData()).GetData());
- }
- else {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("create notice play thread failed.");
- }
- #endif
- }
- else{
- Error = Error_InvalidState;
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_NOTICE_FILE_NOT_VALID, CSimpleStringA::Format("play notice failed for %s is not valid!", strNoticeFileName.GetData()).GetData());
- }
- }
- else {
- Error = Error_InvalidState;
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_NOTICE_FILE_NOT_EXIST, CSimpleStringA::Format("play notice failed for %s not exist!", strNoticeFileName.GetData()).GetData());
- }
- }
- return Error;
- }
- ErrorCodeEnum CLocalMediaPlayEntity::StartNotice(int nCfgInx, int nWndX, int nWndY, int nWndWidth, int nWndHeight, const char *pVideoName)
- {
- ErrorCodeEnum Error = Error_Succeed;
- if (eStand2sType == m_eDeviceType || eStand1SPlusType == m_eDeviceType){
- if (nCfgInx >= MAX_PLAY_CHANNELS || nCfgInx < 0 || NULL == pVideoName)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Invalid param CfgInx or video name while StartNotice!");
- return Error_Param;
- }
- if (0 == m_iPlayType){
- Error = StartMediaPlayerNotice(nCfgInx, nWndX, nWndY, nWndWidth, nWndHeight, pVideoName);
- }
- else{
- Error = StartFFPlayerNotice(nCfgInx, nWndX, nWndY, nWndWidth, nWndHeight, pVideoName);
- }
- }
- return Error;
- }
- ErrorCodeEnum CLocalMediaPlayEntity::StopNotice(int nCfgInx)
- {
- ErrorCodeEnum ErrorCode = Error_Succeed;
- if (eStand2sType == m_eDeviceType || eStand1SPlusType == m_eDeviceType){
- if (nCfgInx >= MAX_PLAY_CHANNELS || nCfgInx < 0){
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Invalid CfgInx while StopNotice!");
- return Error_Param;
- }
- #ifdef RVC_OS_WIN
- if (NULL != m_uNoticePlayThreadId) {
- if (0 == m_iPlayType) {
- if (false == m_pVideoPlayer[nCfgInx]->checkIsStop()) {
- m_pVideoPlayer[nCfgInx]->Close();
- }
- }
- else {
- if (false == m_pMediaPlayer[nCfgInx]->checkIsStop()) {
- m_pMediaPlayer[nCfgInx]->Close();
- }
- }
-
- WaitForSingleObject(m_uNoticePlayThreadId, INFINITE);
- if (m_lastPlayVideo.length() > 0) {
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_STOP_NOTICE_PLAY, CSimpleStringA::Format("success to stop play notice ", m_lastPlayVideo.c_str()).GetData());
- }
- m_uNoticePlayThreadId = NULL;
- }
- #else
- m_pMediaPlayer[nCfgInx]->Close();
- if (m_uNoticePlayThreadId > 0) {
- if (0 == pthread_join(m_uNoticePlayThreadId, NULL)) {
- if (m_lastPlayVideo.length() > 0) {
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_STOP_NOTICE_PLAY, CSimpleStringA::Format("%s%s", "success to stop play notice ", m_lastPlayVideo.c_str()).GetData());
- }
- }
- m_uNoticePlayThreadId = 0;
- }
- #endif
- }
- return ErrorCode;
- }
- ErrorCodeEnum CLocalMediaPlayEntity::StopPlayAllMedias()
- {
- ErrorCodeEnum ErrorCode = Error_Succeed;
- StopAll();
- return ErrorCode;
- }
- void CLocalMediaPlayEntity::OnSelfTest(EntityTestEnum eTestType, CSmartPointer<ITransactionContext> pTransactionContext)
- {
- //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%s:%d eTestType = %d.", __FUNCTION__, __LINE__, eTestType);
- if (Test_ShakeHand == eTestType){
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%s:%d.", __FUNCTION__, __LINE__);
- }
- void CLocalMediaPlaySession::Handle_StartPlayVideo(SpReqAnsContext<PlayService_StartPlayVideo_Req, PlayService_StartPlayVideo_Ans>::Pointer ctx)
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- //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);
-
- CSimpleStringA UpdateState = "";
- ErrorCodeEnum Error = m_pEntity->GetFunction()->GetSysVar("UpdateState", UpdateState);
- if (Error == Error_Succeed && "1" == UpdateState)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("detect current is upgrade, do not play the media");
- ctx->Answer(Error_Stoped);
- m_pEntity->StopAll();
- return;
- }
-
- if (eStand2sType == m_pEntity->GetDeviceType()){
- m_pEntity->StartVideo(ctx->Req.CfgInx, ctx->Req.WndX, ctx->Req.WndY, ctx->Req.WndWidth, ctx->Req.WndHeight);
- }
-
- ctx->Answer(Error_Succeed);
- }
- void CLocalMediaPlaySession::Handle_StartPlayAudio(SpReqAnsContext<PlayService_StartPlayAudio_Req, PlayService_StartPlayAudio_Ans>::Pointer ctx)
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- CSimpleStringA AudioNames = CSimpleStringW2A(ctx->Req.AudioNames);
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("start play audio, name:%s", AudioNames.GetData());
- CSimpleStringA UpdateState = "";
- ErrorCodeEnum Error = m_pEntity->GetFunction()->GetSysVar("UpdateState", UpdateState);
- if (Error == Error_Succeed && "1" == UpdateState)
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("detect current is upgrade, do not play the media");
- ctx->Answer(Error_Stoped);
- m_pEntity->StopAll();
- return;
- }
- m_pEntity->StartAudio(AudioNames.GetData());
- ctx->Answer(Error_Succeed);
- }
- void CLocalMediaPlaySession::Handle_StartPlayImage(SpReqAnsContext<PlayService_StartPlayImage_Req, PlayService_StartPlayImage_Ans>::Pointer ctx)
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- m_pEntity->StartImage(ctx->Req.CfgInx, ctx->Req.WndX, ctx->Req.WndY, ctx->Req.WndWidth, ctx->Req.WndHeight);
- ctx->Answer(Error_Succeed);
- }
- void CLocalMediaPlaySession::Handle_StopPlayVideo(SpReqAnsContext<PlayService_StopPlayVideo_Req, PlayService_StopPlayVideo_Ans>::Pointer ctx)
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("stop play Video, Index:%d", ctx->Req.CfgInx);
- m_pEntity->StopVideo(ctx->Req.CfgInx);
- ctx->Answer(Error_Succeed);
- }
- void CLocalMediaPlaySession::Handle_StopPlayAudio(SpReqAnsContext<PlayService_StopPlayAudio_Req, PlayService_StopPlayAudio_Ans>::Pointer ctx)
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- m_pEntity->StopAudio();
- ctx->Answer(Error_Succeed);
- }
- void CLocalMediaPlaySession::Handle_StopPlayImage(SpReqAnsContext<PlayService_StopPlayImage_Req, PlayService_StopPlayImage_Ans>::Pointer ctx)
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- m_pEntity->StopImage(ctx->Req.CfgInx);
- ctx->Answer(Error_Succeed);
- }
- void CLocalMediaPlaySession::OnClose(ErrorCodeEnum)
- {
- }
- void CLocalMediaPlaySession::Handle_GetLocalVideoVolume( SpReqAnsContext<PlayService_GetLocalVideoVolume_Req, PlayService_GetLocalVideoVolume_Ans>::Pointer ctx )
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- int volume = 0;
- if (m_pEntity->GetLocalVideoVolume(ctx->Req.CfgInx, volume)){
- ctx->Ans.Volume = volume;
- ctx->Answer(Error_Succeed);
- }
- else{
- ctx->Answer(Error_Unexpect);
- }
- }
- void CLocalMediaPlaySession::Handle_SetLocalVideoVolume( SpReqAnsContext<PlayService_SetLocalVideoVolume_Req, PlayService_SetLocalVideoVolume_Ans>::Pointer ctx )
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- if (m_pEntity->SetLocalVideoVolume(ctx->Req.CfgInx, ctx->Req.Volume)){
- ctx->Answer(Error_Succeed);
- }
- else{
- ctx->Answer(Error_Unexpect);
- }
- }
- void CLocalMediaPlaySession::Handle_GetLocalAudioVolume(SpReqAnsContext<PlayService_GetLocalAudioVolume_Req, PlayService_GetLocalAudioVolume_Ans>::Pointer ctx)
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- auto audioRet = m_pEntity->GetLocalAudioVolume();
- if (audioRet.first){
- ctx->Ans.Volume = audioRet.second;
- ctx->Answer(Error_Succeed);
- }
- else{
- ctx->Answer(Error_Unexpect);
- }
- }
- void CLocalMediaPlaySession::Handle_SetLocalAudioVolume(SpReqAnsContext<PlayService_SetLocalAudioVolume_Req, PlayService_SetLocalAudioVolume_Ans>::Pointer ctx)
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- if (m_pEntity->SetLocalAudioVolume(ctx->Req.Volume)){
- ctx->Answer(Error_Succeed);
- }
- else{
- ctx->Answer(Error_Unexpect);
- }
- }
- void CLocalMediaPlaySession::Handle_StartPlayNotice(SpReqAnsContext<PlayService_StartPlayNotice_Req, PlayService_StartPlayNotice_Ans>::Pointer ctx)
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- CSimpleStringA UpdateState = "";
- ErrorCodeEnum Error = m_pEntity->GetFunction()->GetSysVar("UpdateState", UpdateState);
- if (Error == Error_Succeed && "1" == UpdateState){
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("detect current is upgrade, do not play the media");
- ctx->Answer(Error_Stoped);
- m_pEntity->StopAll();
- return;
- }
- CSimpleStringA VideoName = CSimpleStringW2A(ctx->Req.VideoName);
- 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());
- Error = m_pEntity->StartNotice(ctx->Req.CfgInx, ctx->Req.WndX, ctx->Req.WndY, ctx->Req.WndWidth, ctx->Req.WndHeight, VideoName.GetData());
- ctx->Answer(Error);
- }
- void CLocalMediaPlaySession::Handle_StopPlayNotice(SpReqAnsContext<PlayService_StopPlayNotice_Req, PlayService_StopPlayNotice_Ans>::Pointer ctx)
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("stop play notice, Index:%d", ctx->Req.CfgInx);
- ErrorCodeEnum Error = m_pEntity->StopNotice(ctx->Req.CfgInx);
- ctx->Answer(Error);
- }
- void CLocalMediaPlaySession::Handle_StopPlayAllMedias(SpReqAnsContext<PlayService_StopPlayAllMedias_Req, PlayService_StopPlayAllMedias_Ans>::Pointer ctx)
- {
- DbgToBeidou(ctx->link, __FUNCTION__)();
- //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("stop play all medias");
- ErrorCodeEnum Error = m_pEntity->StopPlayAllMedias();
- ctx->Answer(Error);
- }
- SP_BEGIN_ENTITY_MAP()
- SP_ENTITY(CLocalMediaPlayEntity)
- SP_END_ENTITY_MAP()
|