1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638 |
- #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;
- }
- 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 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()
|