12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657 |
- #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 failed.");
- }
- 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;
- }
- 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);
- }
- 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());
- 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);
- }
- 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_DEBUG, LOG_TYPE_SYSTEM)("SpSendBroadcast AudioPlayRet and audio name is %s.", ret.AudioNames.GetData());
- }
- }
- else {
- VideoPlayRet ret;
- ret.VideoNames = m_lastPlayVideo.c_str();
- ret.ret = true;
- 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;
- }
- }
- 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;
- if (8000 != param->freq || 1 != param->channels) {
- 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());
- }
- }
- //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) {
- 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;
- }
- void CLocalMediaPlayEntity::LogLocalMediaPlayVolumeInfo()
- {
- int iAudioVolume = 50;
- auto audioret = GetLocalAudioVolume();
- if (audioret.first) {
- iAudioVolume = audioret.second;
- }
- int iVideoVolume = 50;
- GetLocalVideoVolume(0, iVideoVolume);
- CSimpleStringA strJson("");
- strJson += CSimpleStringA::Format("\"%s\":\"%d\",\"%s\":\"%d\"", "LocalAudio", iAudioVolume, "LocalVideo", iVideoVolume);
- LogWarn(Severity_Low, Error_Debug, LOG_EVT_LOCALMEDIAPLAY_VOLUME, CSimpleStringA::Format("[{%s}]", strJson.GetData()).GetData());
- }
- 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);
- }
- else {
- LogLocalMediaPlayVolumeInfo();
- }
- 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 queryMedia thread failed.");
- }
- #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;
- const char* pAudioNames = entity->m_lastPlayAudio.c_str();
- 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;
- 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();
- return 0;
- }
- DWORD WINAPI MediaPlayThread(LPVOID param)
- {
- 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())
- {
- 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;
- }
- 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;
- }
- 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;
- }
- 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;
- }
- return 0;
- }
- DWORD WINAPI StartMediaPlayFunc(LPVOID param)
- {
- int iRet = -1;
- if (NULL == param){
- return iRet;
- }
- 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;
- }
-
- 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()){
- 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()){//停止播放
-
- }
- else{
- entity->m_pPicturePlayer[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 (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;
- return 0;
- }
- void* StartMediaPlayFunc(void* param)
- {
- int iRet = -1;
- if (NULL == param) {
- return (void*)&iRet;
- }
- 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;
- }
- 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()) {
- 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;
- 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) {
- 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) {
- 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()) {
- 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()) {
- 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()) {
- StopAudio();
- }
- 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;
- 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;
- 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;
- }
- #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();
- }
- }
- else{
- if (false == m_pPicturePlayer[nCfgInx]->checkIsStop()) {
- m_pPicturePlayer[nCfgInx]->Close();
- }
- }
- #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)
- {
- 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()) {
- StopAudio();
- }
- if (false == m_pVideoPlayer[nCfgInx]->checkIsStop()) {
- 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;
- const char* pVideoName = entity->m_lastPlayVideo.c_str();
- 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_DEBUG, 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);
- }
- 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()) {
- StopAudio();
- }
- if (m_pMediaPlayer[nCfgInx]->checkIsPlay()) {
- 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)
- {
- if (Test_ShakeHand == eTestType){
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- }
- void CLocalMediaPlaySession::Handle_StartPlayVideo(SpReqAnsContext<PlayService_StartPlayVideo_Req, PlayService_StartPlayVideo_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;
- }
-
- 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);
- 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__)();
- 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);
- 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__)();
- 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__)();
- ErrorCodeEnum Error = m_pEntity->StopPlayAllMedias();
- ctx->Answer(Error);
- }
- SP_BEGIN_ENTITY_MAP()
- SP_ENTITY(CLocalMediaPlayEntity)
- SP_END_ENTITY_MAP()
|