1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387 |
- #include "stdafx.h"
- #include "mod_localmediaplay.h"
- #include "LocalMediaPlay_msg_g.h"
- #include "fileutil.h"
- #define DEFAULT_SLEEP_TIME (60 * 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
- //DWORD WINAPI clearOutdata(LPVOID lpv)
- //{
- // CLocalMediaPlayEntity* curEntity = (CLocalMediaPlayEntity*)lpv;
- // Sleep(removeOldTime * 1000);
- // curEntity->m_mediaManage.clearOutdataResource();
- // return 0;
- //}
- #ifdef RVC_OS_WIN
- DWORD WINAPI qryMedia(LPVOID lpv)
- {
- CLocalMediaPlayEntity* curEntity = (CLocalMediaPlayEntity*)lpv;
- Sleep(3000);
- while (true)
- {
- curEntity->m_mediaManage.InitResourceListByLocal();
- //curEntity->StartVideo(0, 0, 0, 0, 0);
- 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_connection(NULL)
- {
- //stopForDebug();
- m_defaultVolum = 50;
- #ifdef RVC_OS_WIN
- m_scanThread=NULL;
- m_pAudioPlayer = NULL;
- memset(m_pVideoPlayer, 0, sizeof(m_pVideoPlayer));
- memset(m_pImagePlayer, 0, sizeof(m_pImagePlayer));
- #else
- //add by clp 20201103
- m_scanThreadId = 0;
- m_pMediaAudioPlayer = NULL;
- memset(m_pMediaPlayer, 0, sizeof(m_pMediaPlayer));
- memset(m_pPicturePlayer, 0, sizeof(m_pPicturePlayer));
- m_uMediaPlayThreadId = 0;
- m_badplayflag = true;
- #endif // RVC_OS_WIN
- ZeroMemory(&m_mediaParam, sizeof(MediaPlayParam));
- }
- CLocalMediaPlayEntity::~CLocalMediaPlayEntity()
- {
- SecureClientRelease();
- DWORD exitCode = 0;
- #ifdef RVC_OS_WIN
- if (m_scanThread)
- {
- TerminateThread(m_scanThread, exitCode);
- m_scanThread = NULL;
- }
- #else
- m_scanexitflag = true;
- if (0 == pthread_join(m_scanThreadId, NULL)) {
- Dbg("pthread join scanThreadId success.");
- }
-
- #endif // RVC_OS_WIN
- }
- void CLocalMediaPlayEntity::SecureClientRelease()
- {
- if (NULL != m_connection)
- {
- if (m_connection->IsConnectionOK())
- m_connection->Close();
- m_connection->DecRefCount();
- m_connection = NULL;
- }
- }
- bool CLocalMediaPlayEntity::SecureClientConnect()
- {
- if (NULL != m_connection && m_connection->IsConnectionOK())
- return true;
- SecureClientRelease();
- m_connection = new CAdvertSyncConnection(this);
- return m_connection->ConnectFromCentralSetting();
- }
- void CLocalMediaPlayEntity::setMediaPath()
- {
- CSimpleStringA downloadPath, mediaPath;
- GetFunction()->GetPath("Download", downloadPath);
- GetFunction()->GetPath("Ad", mediaPath);
- m_mediaManage.setDefaultDownloadPath(downloadPath.GetData());
- m_mediaManage.setDefaultAddvertPath(mediaPath.GetData());
- }
- CServerSessionBase* CLocalMediaPlayEntity::OnNewSession(const char* pszRemoteEntityName, const char * pszClass)
- {
- LOG_FUNCTION();
- LOG_TRACE("%s connected class = %s!", pszRemoteEntityName, pszClass);
- return new CLocalMediaPlaySession(this, m_id_seq++);
- }
- void CLocalMediaPlayEntity::loadDefaultMedia()
- {
- #ifdef RVC_OS_WIN
- m_defaultImg.clear();
- m_defaultAudio.clear();
- m_defaultVideo.clear();
- #else
- m_defaultPic.clear();
- m_Audios.clear();
- m_Videos.clear();
- #endif // RVC_OS_WIN
- // 读取LocalMediaPlay.ini中的配置
- CSimpleStringA strRootPath;
- ErrorCodeEnum Error = Error_Succeed;
- Error = GetFunction()->GetPath("ADData", strRootPath);
- if (Error != Error_Succeed) {
- Dbg("Fail to get local media root path!");
- return;
- }
- CSmartPointer<IConfigInfo> spConfig;
- CAutoArray<CSimpleStringA> sectionList;
- if (Error_Succeed == GetFunction()->OpenConfig(Config_Software, spConfig) && Error_Succeed == spConfig->ReadAllSections(sectionList))
- {
- for (int i = 0; i < sectionList.GetCount(); i++)
- {
- CSmartPointer<IConfigInfo> tempConfig = spConfig;
- SpIniMappingTable table;
- CSimpleStringA strFileNames;
- if (sectionList[i].IsStartWith("General"))
- {
- table.AddEntryBoolean(sectionList[i].GetData(), "runDebug", IS_DEBUG, false);
- table.AddEntryInt(sectionList[i].GetData(), "scanTime", scanTime, 600);
- table.AddEntryInt(sectionList[i].GetData(), "removeOldTime", removeOldTime, 1800);
- if (Error_Succeed == table.Load(tempConfig))
- Dbg("runDebug:%s, scanTime:%d", IS_DEBUG ? "true" : "false", scanTime);
- else
- Dbg("General load fail!");
- if (removeOldTime < 1800)
- {
- removeOldTime = 1800;
- }
- }
- else if (sectionList[i].IsStartWith("Image"))
- {
- // ����ͼƬ����
- #ifdef RVC_OS_WIN
- CImgPlayConfig curImg;
- ZeroMemory(&curImg, sizeof(CImgPlayConfig));
- #else
- CPicPlayConfig curImg;
- ZeroMemory(&curImg, sizeof(CPicPlayConfig));
- #endif // RVC_OS_WIN
- CSimpleStringA imgPath = strRootPath + SPLIT_SLASH_STR +"Image" + SPLIT_SLASH_STR;
- strncpy(curImg.strRootPath, (LPCSTR)imgPath, sizeof(curImg.strRootPath));
- Dbg("curSection: %s, config.strRootPath: %s", sectionList[i].GetData(), curImg.strRootPath);
- table.AddEntryBoolean(sectionList[i].GetData(), "FullScreen", curImg.bFullScreen, false);
- table.AddEntryBoolean(sectionList[i].GetData(), "PrimMonitor", curImg.bPrimMonitor, false);
- table.AddEntryInt(sectionList[i].GetData(), "PlayCount", curImg.nPlayCnt, 0);
- table.AddEntryInt(sectionList[i].GetData(), "PlayInterval", curImg.nPlayInterval, 0);
- table.AddEntryString(sectionList[i].GetData(), "ImageNames", strFileNames, "");
- if (Error_Succeed == table.Load(tempConfig))
- Dbg("Image Succeed to LoadConfig!");
- else
- Dbg("Image Fail to LoadConfig!");
- char *Tmp = new char[strFileNames.GetLength() + 1];
- strcpy(Tmp, (LPCSTR)strFileNames);
- char *Result[MAX_FILECOUNT] = { NULL };
- CStringSplit(Tmp, Result, "|");
- int FileCount = 0;
- char** pStr = Result;
- while (*pStr != NULL)
- {
- ++pStr; ++FileCount;
- }
- curImg.nFileCnt = FileCount;
- Dbg("Image config.nFileCnt = %d!", FileCount);
- for (int i = 0; i != FileCount; ++i)
- {
- strcpy(curImg.strFileNames[i], Result[i]);
- }
- delete[] Tmp; Tmp = NULL;
- #ifdef RVC_OS_WIN
- m_defaultImg.push_back(curImg);
- #else
- m_defaultPic.push_back(curImg);
- #endif // RVC_OS_WIN
- }
- else if (sectionList[i].IsStartWith("Video"))
- {
- #ifdef RVC_OS_WIN
- CWmpPlayConfig curVideo;
- ZeroMemory(&curVideo, sizeof(CWmpPlayConfig));
- #else
- CMediaPlayConfig curVideo = {0};
- #endif // RVC_OS_WIN
- CSimpleStringA videoPath = strRootPath + SPLIT_SLASH_STR +"Video" + SPLIT_SLASH_STR;
- strcpy(curVideo.strRootPath, (LPCSTR)videoPath);
- Dbg("config.strRootPath: %s", curVideo.strRootPath);
- CSimpleStringA strRunTime_S, strRunTime_E;
-
- table.AddEntryString("General", "VideoRunTime_Start", strRunTime_S, "");
- table.AddEntryString("General", "VideoRunTime_End", strRunTime_E, "");
-
- table.AddEntryBoolean(sectionList[i].GetData(), "FullScreen", curVideo.bFullScreen, false);
- table.AddEntryBoolean(sectionList[i].GetData(), "PrimMonitor", curVideo.bPrimMonitor, false);
- table.AddEntryBoolean(sectionList[i].GetData(), "SimpleMode", curVideo.bSimpleMode, true);
- table.AddEntryInt(sectionList[i].GetData(), "PlayCount", curVideo.nPlayCnt, 0);
- table.AddEntryInt(sectionList[i].GetData(), "PlayInterval", curVideo.nPlayInterval, 0);
- table.AddEntryString(sectionList[i].GetData(), "VideoNames", strFileNames, "");
- if (Error_Succeed == table.Load(tempConfig))
- Dbg("Succeed to LoadWmpConfig!");
- else
- Dbg("Fail to LoadWmpConfig!");
- curVideo.nVolume = 50;
- 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, (LPCSTR)strRunTime_S);
- Dbg("config.strVideoRunTime_S: %s", (LPCSTR)strRunTime_S);
- strcpy(curVideo.strVideoRunTime_E, (LPCSTR)strRunTime_E);
- Dbg("config.strVideoRunTime_E: %s", (LPCSTR)strRunTime_E);
- char *Tmp = new char[strFileNames.GetLength() + 1];
- strcpy(Tmp, (LPCSTR)strFileNames);
- char *Result[MAX_FILECOUNT] = { NULL };
- CStringSplit(Tmp, Result, "|");
- int FileCount = 0;
- char** pStr = Result;
- while (*pStr != NULL)
- {
- ++pStr; ++FileCount;
- }
- curVideo.nFileCnt = FileCount;
- Dbg("Wmp config.strFileNames = %s!", (LPCSTR)strFileNames);
- Dbg("Wmp config.nFileCnt = %d!", FileCount);
- for (int i = 0; i != FileCount; ++i)
- strcpy(curVideo.strFileNames[i], Result[i]);
- delete[] Tmp; Tmp = NULL;
- #ifdef RVC_OS_WIN
- m_defaultVideo.push_back(curVideo);
- #else
- m_Videos.push_back(curVideo);
- #endif // RVC_OS_WIN
- }
- else if (sectionList[i].IsStartWith("Audio"))
- {
- #ifdef RVC_OS_WIN
- CWmpPlayConfig curAudio;
- ZeroMemory(&curAudio, sizeof(CWmpPlayConfig));
- #else
- CMediaPlayConfig curAudio = { 0 };
- #endif // RVC_OS_WIN
- CSimpleStringA audioPath = strRootPath + SPLIT_SLASH_STR +"Audio" + SPLIT_SLASH_STR;
- strcpy(curAudio.strRootPath, (LPCSTR)audioPath);
- Dbg("config.strRootPath: %s", curAudio.strRootPath);
- table.AddEntryInt(sectionList[i], "PlayCount", curAudio.nPlayCnt, 0);
- table.AddEntryInt(sectionList[i], "PlayInterval", curAudio.nPlayInterval, 0);
- auto audioRet = GetLocalAudioVolume();
- if (audioRet.first)
- curAudio.nVolume = audioRet.second;
- else
- curAudio.nVolume = m_defaultVolum;
- if (Error_Succeed == table.Load(tempConfig))
- Dbg("Succeed to LoadWmpConfig!");
- else
- Dbg("Fail to LoadWmpConfig!");
- #ifdef RVC_OS_WIN
- m_defaultAudio.push_back(curAudio);
- #else
- m_Audios.push_back(curAudio);
- #endif // RVC_OS_WIN
- }
- }
- }
- }
- #ifdef RVC_OS_WIN
- BOOL CLocalMediaPlayEntity::LoadPlayConfig(CWmpPlayConfig& config, int CfgInx)
- {
- if (CfgInx >= MAX_PLAY_CHANNELS || CfgInx < 0)
- {
- Dbg("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 >= m_defaultImg.size() || CfgInx < 0)
- {
- Dbg("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);
- vDbg(fmt, arg);
- va_end(arg);
- }
- void CLocalMediaPlayEntity::ImgDebug(const char* fmt, ...)
- {
- va_list arg;
- va_start(arg, fmt);
- vDbg(fmt, arg);
- va_end(arg);
- }
- #else
- int CLocalMediaPlayEntity::LoadPlayConfig(CMediaPlayConfig& config, int CfgInx)
- {
- if (CfgInx >= MAX_PLAY_CHANNELS || CfgInx < 0)
- {
- Dbg("Invalid CfgInx while LoadConfig!");
- return -1;
- }
- if (config.eMode == LOCALAUDIO && CfgInx < m_Audios.size())
- {
- memcpy(&config, &(m_Audios[CfgInx]), sizeof(CMediaPlayConfig));
- }
- else if (config.eMode == 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 >= m_defaultPic.size() || CfgInx < 0)
- {
- Dbg("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 >= MEDIA_LOG_DEBUG){
- va_list arg;
- va_start(arg, fmt);
- vDbg(fmt, arg);
- va_end(arg);
- }
- }
- void CLocalMediaPlayEntity::PicDebug(pic_loglevel log_level, const char* fmt, ...)
- {
- if (log_level >= PIC_LOG_ERROR){
- va_list arg;
- va_start(arg, fmt);
- vDbg(fmt, arg);
- va_end(arg);
- }
- }
- void CLocalMediaPlayEntity::AudioPlayFinished()
- {
- AudioPlayRet ret;
- ret.AudioNames = m_lastPlayAudio.c_str();
- ret.ret = true;
- Dbg("stop play audio %s success", ret.AudioNames.GetData());
- SpSendBroadcast(GetFunction(), eMsg_AudioPlayRet, eMsgSig_AudioPlayRet, ret);
- }
- int CLocalMediaPlayEntity::GetMediaPlayerIcoPath(char* strPath, size_t uLen)
- {
- return GetPlayerIcoPath(strPath, uLen);
- }
- int CLocalMediaPlayEntity::GetPicPlayerIcoPath(char* strPath, size_t uLen)
- {
- return GetPlayerIcoPath(strPath, uLen);
- }
- bool CLocalMediaPlayEntity::GetPlayFlag()
- {
- return m_badplayflag;
- }
- bool CLocalMediaPlayEntity::GetScanExitFlag()
- {
- return m_scanexitflag;
- }
- int CLocalMediaPlayEntity::GetPlayerIcoPath(char* strPath, size_t uLen)
- {
- int iRet = -1;
- if (NULL == strPath) {
- return iRet;
- }
- CSimpleStringA csBinPath;
- ErrorCodeEnum eErrPath = GetFunction()->GetPath("Bin", csBinPath);
- if (eErrPath != Error_Succeed) {
- Dbg("GetBasePath failed (%d).", eErrPath);
- return iRet;
- }
- CSimpleStringA szIcoName("rvc_media_player_64px.bmp");
- szIcoName = csBinPath + SPLIT_SLASH_STR + szIcoName;
- //Dbg("media player ico full path is %s.", szIcoName.GetData());
- if (uLen > szIcoName.GetLength()) {
- memcpy(strPath, szIcoName.GetData(), szIcoName.GetLength());
- iRet = 0;
- }
- return iRet;
- }
- #endif // RVC_OS_WIN
- 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)
- {
- if (dwUserCode == LOG_EVT_SELFCHECK_IEBROWSER_IDLE)
- {
- Dbg("IEBrowser to idle, stop all media!");
- StopAll();
- }
- }
- void CLocalMediaPlayEntity::OnPreStart(CAutoArray<CSimpleStringA> strArgs, CSmartPointer<ITransactionContext> pTransactionContext)
- {
- LOG_FUNCTION();
- ErrorCodeEnum Error = __OnStart(Error_Succeed);
- pTransactionContext->SendAnswer(Error);
- }
- ErrorCodeEnum CLocalMediaPlayEntity::__OnStart(ErrorCodeEnum preOperationError)
- {
- #ifdef RVC_OS_WIN
- //toolkit_setenv("SDL_AUDIODRIVER", "winmm");
- #endif // RVC_OS_WIN
- 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);
- #else
- m_pMediaPlayer[i] = new Clibmediaplayer(this);
- m_pPicturePlayer[i] = new Clibpictureplayer(this);
- #endif
- }
-
- #ifdef RVC_OS_WIN
- m_pAudioPlayer = new Clibwmpplayer(this);
- #else
- m_pMediaAudioPlayer = new Clibmediaplayer(this);
- signal(SIGTERM, sig_handler);
- #endif // RVC_OS_WIN
- if (!IsRunConfigExist())
- {
- SetLocalVideoVolume(0, 50);
- SetLocalAudioVolume(50);
- }
- //setMediaPath();
- loadDefaultMedia();
-
- GetFunction()->SubscribeLog(m_SubIDIEIdle, this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_SELFCHECK_IEBROWSER_IDLE, NULL, false);
- #ifdef RVC_OS_WIN
- m_scanThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)& qryMedia, this, 0, NULL);
- if (NULL != m_scanThread)
- Dbg("create qryMeia thread success, %d.", m_scanThread);
- #else
- int err = pthread_create(&m_scanThreadId, NULL, queryMedia, this);
- if (0 == err){
- Dbg("create queryMedia thread success, %u.", m_scanThreadId);
- }
- else{
- Dbg("create queryMedia thread failed.");
- }
-
- #endif // RVC_OS_WIN
- return Error_Succeed;
- }
- void CLocalMediaPlayEntity::OnPreClose(EntityCloseCauseEnum eCloseCause, CSmartPointer<ITransactionContext> pTransactionContext)
- {
- LOG_FUNCTION();
- 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;
- #else
- delete m_pMediaPlayer[i]; m_pMediaPlayer[i] = NULL;
- delete m_pPicturePlayer[i]; m_pPicturePlayer[i] = NULL;
- #endif // RVC_OS_WIN
- }
- #ifdef RVC_OS_WIN
- delete m_pAudioPlayer; m_pAudioPlayer = NULL;
- #else
- delete m_pMediaAudioPlayer; m_pMediaAudioPlayer = NULL;
- #endif // RVC_OS_WIN
-
- GetFunction()->UnsubscribeLog(m_SubIDIEIdle);
- return Error_Succeed;
- }
- #ifdef RVC_OS_WIN
- DWORD WINAPI CheckAudioThread(LPVOID param)
- {
- CLocalMediaPlayEntity *entity = (CLocalMediaPlayEntity*)param;
- Dbg("Begin CheckAudioThread");
- HANDLE playThread = NULL;
- if (!entity->m_pAudioPlayer->checkIsPlay(playThread))
- {
- Dbg("Create play audio Media Thread Failed!");
- return 0;
- }
- WaitForSingleObject(playThread, INFINITE);
- entity->m_pAudioPlayer->Close();
- AudioPlayRet ret;
- ret.AudioNames = entity->m_lastPlayAudio.c_str();
- ret.ret = true;
- Dbg("stop play audio %s success", ret.AudioNames);
- SpSendBroadcast(entity->GetFunction(), eMsg_AudioPlayRet, eMsgSig_AudioPlayRet, ret);
- return 0;
- }
- #else
- void* StartAudioPlayingThreadFunc(void* param)
- {
- CLocalMediaPlayEntity* entity = (CLocalMediaPlayEntity*)param;
- Dbg("Enter StartAudioPlayingThreadFunc");
- const char* pAudioNames = entity->m_lastPlayAudio.c_str();
- Dbg("Begin StartAudio, and Audio Info is %s.", pAudioNames);
- if (0 == entity->m_pMediaAudioPlayer->PlayLocalAudio(pAudioNames)) {
- Dbg("Succeed to StartAudio, and Audio Info is %s.", pAudioNames);
- }
- else{
- Dbg("StartAudio failed, for %s is not exsit.", pAudioNames);
- }
- Dbg("Leave StartAudioPlayingThreadFunc");
- return 0;
- }
- #endif // RVC_OS_WIN
- #ifdef RVC_OS_WIN
- DWORD WINAPI MediaPlayThread(LPVOID param)
- {
- CLocalMediaPlayEntity *entity = (CLocalMediaPlayEntity*)param;
- while (TRUE)
- {
- vector<ResourceParse> curParse;
- entity->m_mediaManage.GetPlayListByLocal(curParse);
- 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;
- if (IS_DEBUG)
- {
- config.bFullScreen = false;
- config.bPrimMonitor = true;
- }
- // add by ly@2018/07/30
- if (!entity->GetLocalVideoVolume(0, config.nVolume))
- {
- config.nVolume = entity->m_defaultVolum;
- }
- Dbg("config.nVolume=%d while play local video.", config.nVolume);
- // �жϵ�ǰʱ���Ƿ���������
- SYSTEMTIME st;
- GetLocalTime(&st);
- TCHAR strNow[TIME_LEN];
- sprintf(strNow, "%02d:%02d:%02d", st.wHour, st.wMinute, st.wSecond);
- if (strcmp(strNow, config.strVideoRunTime_S) < 0 || strcmp(strNow, config.strVideoRunTime_E) >= 0)
- {
- Sleep(10000);
- continue;
- }
- entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
- if (!entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(playThread))
- {
- Dbg("Create play Video Media Thread Failed!");
- return 0;
- }
- WaitForSingleObject(playThread, INFINITE);
- if (entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->checkIsStop())
- {//ֹͣ����
- Dbg("stop play video");
- return 0;
- }
- else
- entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->Close();
- }
- for (vector<ResourceParse>::iterator i = curParse.begin(); i != curParse.end(); i++)
- {
- HANDLE playThread = NULL;
- Dbg("begin play extend %c:%s, %s", i->type, i->resourcePath.c_str(), i->videoNames.c_str());
- if ('V' == i->type)
- {//video
- CWmpPlayConfig config;
- ZeroMemory(&config, sizeof(CWmpPlayConfig));
- config.bFullScreen = IS_DEBUG ? false : i->fullScreen;
- config.bPrimMonitor = IS_DEBUG ? true : i->primMonitor;
- config.bSimpleMode = i->simpleMode;
- config.eMode = LOCALVIDEO;
- config.nFileCnt = 1;
- config.nPlayCnt = 1;
- config.nPlayInterval = i->playInterval;
- // add by ly@2018/07/30
- //config.nVolume = IS_DEBUG ? 0 : entity->m_defaultVolum;
- if (!entity->GetLocalVideoVolume(0, config.nVolume))
- {
- config.nVolume = entity->m_defaultVolum;
- }
- Dbg("config.nVolume=%d while play local video.", config.nVolume);
- config.nWndX = entity->m_mediaParam.nWndX;
- config.nWndY = entity->m_mediaParam.nWndY;
- config.nWndWidth = entity->m_mediaParam.nWndWidth;
- config.nWndHeight = entity->m_mediaParam.nWndHeight;
- strncpy_s(config.strRootPath, i->resourcePath.c_str(), sizeof(config.strRootPath));
- strncpy_s(config.strFileNames[0], i->videoNames.c_str(), 256);
- strncpy_s(config.strVideoRunTime_S, "09:00:00", sizeof(config.strVideoRunTime_S));
- strncpy_s(config.strVideoRunTime_E, "17:30:00", sizeof(config.strVideoRunTime_E));
- entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
- if (!entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(playThread))
- {
- Dbg("Create play Video Media Thread Failed!");
- return 0;
- }
- WaitForSingleObject(playThread, INFINITE);
- if (entity->m_pVideoPlayer[entity->m_mediaParam.nCfgInx]->checkIsStop())
- {//ֹͣ����
- Dbg("stop play video");
- return 0;
- }
- 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 : i->primMonitor;
- 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);
- entity->m_pImagePlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
- if (!entity->m_pImagePlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(playThread))
- {
- Dbg("Create play Image Media Thread Failed!");
- return 0;
- }
- WaitForSingleObject(playThread, i->playInterval);
- if (entity->m_pImagePlayer[entity->m_mediaParam.nCfgInx]->checkIsStop())
- {//ֹͣ����
- Dbg("stop play Image");
- return 0;
- }
- else
- entity->m_pImagePlayer[entity->m_mediaParam.nCfgInx]->Close();
- }
- }
- }
- return 0;
- }
- #else
- void* StartMediaPlayFunc(void* param)
- {
- int iRet = -1;
- if (NULL == param){
- return (void*)&iRet;
- }
- CLocalMediaPlayEntity* entity = (CLocalMediaPlayEntity*)param;
- while (entity->GetPlayFlag())
- {
- rvcResourceParse_t ResourceList[MAX_LOCAL_MEDIAS] = { 0 };
- size_t uCount = entity->m_mediaManage.GetPlayListByLocal(ResourceList, MAX_LOCAL_MEDIAS);
- //Dbg("uCount == %d", uCount);
- //for (int i = 0; i < uCount; i++)
- //{
- // rvcResourceParse_t item = ResourceList[i];
- // Dbg("%s:%d ResourceList[%d] address is 0x%0x.", __FUNCTION__, __LINE__, i, ResourceList[i]);
- // Dbg("item->type address is 0x%0x.", item.type);
- // Dbg("item->presourcePath address is 0x%0x.", item.strResourcePath);
- // Dbg("item->pvideoNames address is 0x%0x.", item.strvideoNames);
- // Dbg("play extend %c:%s, %s", item.type, item.strResourcePath, item.strvideoNames);
- //}
- if (0 == uCount)
- {
- 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 = 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;
- if (IS_DEBUG)
- {
- config.bFullScreen = false;
- config.bPrimMonitor = true;
- }
- if (!entity->GetLocalVideoVolume(0, config.nVolume))
- {
- config.nVolume = entity->m_defaultVolum;
- }
- //Dbg("config.nVolume=%d while play local video.", config.nVolume);
- struct tm* ptm = NULL;
- time_t t = time(NULL);
- ptm = localtime(&t);
- TCHAR strNow[TIME_LEN] = {0};
- sprintf(strNow, "%02d:%02d:%02d", ptm->tm_hour, ptm->tm_min, ptm->tm_sec);
- if (strcmp(strNow, config.strVideoRunTime_S) < 0 || strcmp(strNow, config.strVideoRunTime_E) >= 0)
- {
- Sleep(10000);
- continue;
- }
- entity->m_pMediaPlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
- }
- for (int i = 0; i < uCount && i < MAX_LOCAL_MEDIAS && entity->GetPlayFlag(); i++)
- {
- //Dbg("ResourceList[%d] address is 0x%0x", i, ResourceList[i]);
- int64_t playThreadId = 0;
- rvcResourceParse_t item = ResourceList[i];
- //Dbg("begin play extend %c:%s, %s", item.type, item.strResourcePath, item.strvideoNames);
- if ('V' == item.type)
- {//video
- CMediaPlayConfig config = {0};
- config.bFullScreen = IS_DEBUG ? false : item.fullScreen;
- config.bPrimMonitor = IS_DEBUG ? true : item.primMonitor;
- config.bSimpleMode = item.simpleMode;
- config.eMode = LOCALVIDEO;
- config.nFileCnt = 1;
- config.nPlayCnt = 1;
- config.nPlayInterval = item.playInterval;
- // add by ly@2018/07/30
- //config.nVolume = IS_DEBUG ? 0 : entity->m_defaultVolum;
- if (!entity->GetLocalVideoVolume(0, config.nVolume))
- {
- config.nVolume = entity->m_defaultVolum;
- }
- //Dbg("config.nVolume=%d while play local video.", config.nVolume);
- config.nWndX = entity->m_mediaParam.nWndX;
- config.nWndY = entity->m_mediaParam.nWndY;
- config.nWndWidth = entity->m_mediaParam.nWndWidth;
- config.nWndHeight = entity->m_mediaParam.nWndHeight;
- strncpy(config.strRootPath, item.strResourcePath, strlen(item.strResourcePath));
- strncpy(config.strFileNames[0], item.strvideoNames, strlen(item.strvideoNames));
- strncpy(config.strVideoRunTime_S, "09:00:00", sizeof(config.strVideoRunTime_S));
- strncpy(config.strVideoRunTime_E, "17:30:00", sizeof(config.strVideoRunTime_E));
- entity->m_pMediaPlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
- Sleep(2000);
- }
- else if ('P' == item.type)
- {//play Image
- CPicPlayConfig config = {0};
- config.bFullScreen = IS_DEBUG ? false : item.fullScreen;
- config.bPrimMonitor = IS_DEBUG ? true : item.primMonitor;
- 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));
- entity->m_pPicturePlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
- if (!entity->m_pPicturePlayer[entity->m_mediaParam.nCfgInx]->checkIsPlay(&playThreadId)){
- Dbg("Create play Image Media Thread Failed!");
- iRet = -1;
- return (void*)& iRet;
- }
- else{
- Dbg("Image Media Player Thread id is %u.", playThreadId);
- }
- if (0 == pthread_join(playThreadId, NULL)){
- //Dbg("pthread join thread id %u success.", playThreadId);
- iRet = 0;
- }
- else {
- Dbg("pthread join thread id %u failed for %s.", playThreadId, strerror(errno));
- iRet = -1;
- }
- }
- }
- }
- return (void*)&iRet;
- }
- #endif // RVC_OS_WIN
- void CLocalMediaPlayEntity::StartVideo(int nCfgInx, int nWndX, int nWndY, int nWndWidth, int nWndHeight)
- {
- if (nCfgInx >= MAX_PLAY_CHANNELS || nCfgInx < 0)
- {
- Dbg("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 // RVC_OS_WIN
- if (NULL != m_playThread)
- {
- WaitForSingleObject(m_playThread, 5000);
- m_playThread = NULL;
- }
- if (NULL == m_playThread)
- m_playThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)& MediaPlayThread, this, 0, NULL);
- #else
- m_badplayflag = true;
- int err = pthread_create(&m_uMediaPlayThreadId, NULL, StartMediaPlayFunc, this);
- if (0 == err) {
- Dbg("create media play thread[%u] success.", m_uMediaPlayThreadId);
- }
- else {
- Dbg("create media play thread failed.");
- }
- #endif
- }
- void CLocalMediaPlayEntity::StartAudio(const char *pAudioNames)
- {
- #ifdef RVC_OS_WIN
- static HANDLE audioPlayThread = NULL;
- if (audioPlayThread)//�ر����ڲ��ŵ���Ƶ
- {
- DWORD exitCode = 0;
- if (WAIT_TIMEOUT == WaitForSingleObject(audioPlayThread, 50))
- {
- TerminateThread(audioPlayThread, exitCode);
- m_pAudioPlayer->Close();
- }
- audioPlayThread = NULL;
- }
- Dbg("Begin StartAudio, and Audio Info is %s.", pAudioNames);
- m_pAudioPlayer->PlayLocalAudio(pAudioNames);
- Dbg("Succeed to StartAudio, and Audio Info is %s.", pAudioNames);
- auto audioRet = GetLocalAudioVolume();
- m_pAudioPlayer->SetVolume(audioRet.second);
- Dbg("Succeed to set audio volume %d!", audioRet.second);
- m_lastPlayAudio = pAudioNames;
- audioPlayThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)& CheckAudioThread, this, 0, NULL);
- #else
- if (m_pMediaAudioPlayer->checkIsPlay()) {
- Dbg("aurrent is playing, wait for it.");
- //m_pMediaAudioPlayer->Close();
- pthread_join(m_uMediaPlayThreadId, NULL);
- }
- m_lastPlayAudio = pAudioNames;
- int err = pthread_create(&m_uMediaPlayThreadId, NULL, StartAudioPlayingThreadFunc, this);
- if (0 == err) {
- Dbg("create audio play thread[%u] success.", m_uMediaPlayThreadId);
- }
- else {
- Dbg("create audio play thread failed.");
- }
- auto audioRet = GetLocalAudioVolume();
- m_pMediaAudioPlayer->SetVolume(audioRet.second);
- Dbg("Succeed to set audio volume %d!", audioRet.second);
-
- #endif // RVC_OS_WIN
- }
- void CLocalMediaPlayEntity::StartImage(int nCfgInx, int nWndX, int nWndY, int nWndWidth, int nWndHeight)
- {
- if (nCfgInx >= MAX_PLAY_CHANNELS || nCfgInx < 0)
- {
- Dbg("Invalid CfgInx while StartImage!");
- return;
- }
- #ifdef RVC_OS_WIN
- m_pImagePlayer[nCfgInx]->Play(nCfgInx, nWndX, nWndY, nWndWidth, nWndHeight);
- #else
- m_pPicturePlayer[nCfgInx]->Play(nCfgInx, nWndX, nWndY, nWndWidth, nWndHeight);
- #endif // RVC_OS_WIN
- Dbg("Succeed to StartImage!");
- }
- void CLocalMediaPlayEntity::StopVideo(int nCfgInx)
- {
- if (nCfgInx >= MAX_PLAY_CHANNELS || nCfgInx < 0)
- {
- Dbg("Invalid CfgInx while StopVideo!");
- return;
- }
- #ifdef RVC_OS_WIN
- m_pVideoPlayer[nCfgInx]->Close();
- m_pImagePlayer[nCfgInx]->Close();
- if (m_playThread)
- {
- TerminateThread(m_playThread, -1);
- m_playThread = NULL;
- }
- #else
- m_pMediaPlayer[nCfgInx]->Close();
- m_pPicturePlayer[nCfgInx]->Close();
- m_badplayflag = false;
- #endif // RVC_OS_WIN
- Dbg("Succeed to StopVideo!");
- }
- void CLocalMediaPlayEntity::StopAudio()
- {
- #ifdef RVC_OS_WIN
- m_pAudioPlayer->Close();
- #else
- m_pMediaAudioPlayer->Close();
- #endif
- Dbg("Succeed to StopAudio!");
- }
- void CLocalMediaPlayEntity::StopImage(int nCfgInx)
- {
- if (nCfgInx >= MAX_PLAY_CHANNELS || nCfgInx < 0)
- {
- Dbg("Invalid CfgInx while StopImage!");
- return;
- }
- #ifdef RVC_OS_WIN
- m_pImagePlayer[nCfgInx]->Close();
- #else
- m_pPicturePlayer[nCfgInx]->Close();
- #endif // RVC_OS_WIN
- Dbg("Succeed to StopImage!");
- }
- void CLocalMediaPlayEntity::StopAll()
- {
- StopAudio(); // �ر���Ƶ
- for (int i = 0; i < MAX_PLAY_CHANNELS; ++i)
- {
- StopVideo(i); // �ر���Ƶ
- StopImage(i); // �ر�ͼ��
- }
- }
- bool CLocalMediaPlayEntity::GetLocalVideoVolume(int nCfgInx, int &nVolume)
- {
- //Dbg("get local video volume req.");
- CSmartPointer<IConfigInfo> spConfig;
- ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_Run, spConfig);
- if (Error == Error_Succeed)
- {
- Error = spConfig->ReadConfigValueInt("LocalVideo", "Volume", nVolume);
- if (Error == Error_Succeed && nVolume >= 0 && nVolume <= 100)
- {
- //Dbg("succeed to get local video volume with nCfgInx:%d, nVolume:%d", nCfgInx, nVolume);
- return true;
- }
- }
- Dbg("fail to get local video volume!");
- return false;
- }
- std::pair<bool, int> CLocalMediaPlayEntity::GetLocalAudioVolume()
- {
- Dbg("get local audio volume req.");
- 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);
- Dbg("read nVolume 0, set default 50");
- }
- if (Error == Error_Succeed && nVolume >= 0 && nVolume <= 100)
- {
- Dbg("succeed to get local audio volume with nVolume:%d", nVolume);
- return std::make_pair(true, nVolume);
- }
- }
- Dbg("fail to get local audio volume!");
- return std::make_pair(false, nVolume);
- }
- bool CLocalMediaPlayEntity::SetLocalAudioVolume(int nVolume)
- {
- Dbg("set local video audio req.");
- 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)
- {
- Dbg("succeed to set local audio volume with nVolume:%d!", nVolume);
- #ifdef RVC_OS_WIN
- m_pAudioPlayer->SetVolume(nVolume);
- #else
- m_pMediaAudioPlayer->SetVolume(nVolume);
- #endif // RVC_OS_WIN
- return true;
- }
- }
- Dbg("fail to set local video volume!");
- return false;
- }
- bool CLocalMediaPlayEntity::SetLocalVideoVolume(int nCfgInx, int nVolume)
- {
- Dbg("set local video volume req.");
- 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)
- {
- Dbg("succeed to set local video volume with nCfgInx:%d, nVolume:%d!", nCfgInx, nVolume);
- for (int i = 0; i < MAX_PLAY_CHANNELS; ++i)
- {
- #ifdef RVC_OS_WIN
- m_pVideoPlayer[i]->SetVolume(nVolume);
- #else
- m_pMediaPlayer[i]->SetVolume(nVolume);
- #endif
- }
- return true;
- }
- }
- Dbg("fail to set local video volume!");
- return false;
- }
- bool CLocalMediaPlayEntity::IsRunConfigExist()
- {
- CSimpleStringA strPath;
- ErrorCodeEnum eErr;
- if ((eErr = GetFunction()->GetPath("RunInfo", strPath)) != Error_Succeed)
- {
- Dbg("get runinfo path failed(%d)", eErr);
- return false;
- }
- #ifdef RVC_OS_WIN
- CSimpleStringA strRuninfoFile;
- strRuninfoFile = CSimpleStringA::Format("%s\\runcfg\\%s.ini", (LPCTSTR)strPath, GetEntityName());
- WIN32_FIND_DATA findData;
- if (FindFirstFileA((LPCTSTR)strRuninfoFile, &findData) != INVALID_HANDLE_VALUE) return true;
- return false;
- #else
- 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;
- }
- #endif // RVC_OS_WIN
- }
- void CLocalMediaPlayEntity::OnSelfTest(EntityTestEnum eTestType, CSmartPointer<ITransactionContext> pTransactionContext)
- {
- if (Test_ShakeHand == eTestType)
- {
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- }
- void CLocalMediaPlayEntity::CStringSplit(char *str, char **result, const char *del)
- {
- char *p = strtok(str, del);
- while (p != NULL)
- {
- *result++ = p;
- p = strtok(NULL, del);
- }
- }
- void CLocalMediaPlaySession::Handle_StartPlayVideo(SpReqAnsContext<PlayService_StartPlayVideo_Req, PlayService_StartPlayVideo_Ans>::Pointer ctx)
- {
- Dbg("start play Video, Index:%d, WndX:%d, WndY:%d, WndWidth:%d, WndWidth:%d", ctx->Req.CfgInx, ctx->Req.WndX, ctx->Req.WndY, ctx->Req.WndWidth, ctx->Req.WndHeight);
-
- CSimpleStringA UpdateState = "";
- ErrorCodeEnum Error = m_pEntity->GetFunction()->GetSysVar("UpdateState", UpdateState);
- if (Error == Error_Succeed && "1" == UpdateState)
- {
- Dbg("detect current is upgrade, do not play the media");
- ctx->Answer(Error_Stoped);
- m_pEntity->StopAll();
- return;
- }
-
- 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)
- {
- CSimpleStringA AudioNames = CSimpleStringW2A(ctx->Req.AudioNames);
- CSimpleStringA UpdateState = "";
- ErrorCodeEnum Error = m_pEntity->GetFunction()->GetSysVar("UpdateState", UpdateState);
- if (Error == Error_Succeed && "1" == UpdateState)
- {
- Dbg("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)
- {
- 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)
- {
- Dbg("stop play Video, Index:%d", ctx->Req.CfgInx);
- m_pEntity->StopVideo(ctx->Req.CfgInx);
- ctx->Answer(Error_Succeed);
- }
- void CLocalMediaPlaySession::Handle_StopPlayAudio(SpReqAnsContext<PlayService_StopPlayAudio_Req, PlayService_StopPlayAudio_Ans>::Pointer ctx)
- {
- m_pEntity->StopAudio();
- ctx->Answer(Error_Succeed);
- }
- void CLocalMediaPlaySession::Handle_StopPlayImage(SpReqAnsContext<PlayService_StopPlayImage_Req, PlayService_StopPlayImage_Ans>::Pointer ctx)
- {
- m_pEntity->StopImage(ctx->Req.CfgInx);
- ctx->Answer(Error_Succeed);
- }
- void CLocalMediaPlaySession::OnClose(ErrorCodeEnum)
- {
- LOG_FUNCTION();
- }
- void CLocalMediaPlaySession::Handle_GetLocalVideoVolume( SpReqAnsContext<PlayService_GetLocalVideoVolume_Req, PlayService_GetLocalVideoVolume_Ans>::Pointer ctx )
- {
- 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 )
- {
- 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)
- {
- 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)
- {
- if (m_pEntity->SetLocalAudioVolume(ctx->Req.Volume))
- {
- ctx->Answer(Error_Succeed);
- }
- else
- {
- ctx->Answer(Error_Unexpect);
- }
- }
- SP_BEGIN_ENTITY_MAP()
- SP_ENTITY(CLocalMediaPlayEntity)
- SP_END_ENTITY_MAP()
|