12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451 |
- #include "stdafx.h"
- #include "mod_localmediaplay.h"
- #include "LocalMediaPlay_msg_g.h"
- #include "fileutil.h"
- #include "y2k_time.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
- #ifndef RVC_MIN_LOCALPLAYER_TIME
- #define RVC_MIN_LOCALPLAYER_TIME 6
- #endif
- //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;
- m_bgetflag = false;
- m_bgetico = false;
- #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.");
- }
- m_bgetflag = false;
- m_bgetico = false;
-
- #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::GetAudioOutDevName(char* strDev, size_t uLen)
- {
- int iRet = -1;
-
- int idatalen = m_strAudioOutDev.GetLength();
- if (uLen > idatalen && idatalen > 0) {
- memcpy(strDev, m_strAudioOutDev.GetData(), idatalen);
- iRet = 0;
- if (false == m_bgetflag) {
- m_bgetflag = true;
- Dbg("%s:%d audio Out Device Name is %s.", __FUNCTION__, __LINE__, strDev);
- }
- }
- return iRet;
- }
- 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;
- if (m_bgetico == false) {
- Dbg("media player ico full path is %s.", szIcoName.GetData());
- m_bgetico = true;
- }
- if (uLen > 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) {
- Dbg("Audio Out Device name is %s.", m_strAudioOutDev.GetData());
- 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");
- #else
- GetAudioOutDev();
- #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
- mediaplayer_init();
- 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;
- mediaplayer_term();
- #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;
- }
- Dbg("Enter Media Play Function.");
- 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);
- unsigned int ustart_time = y2k_time_now();
- 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;
- }
-
- 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;
- }
- if (-1 == entity->m_pMediaPlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config)){
- Sleep(30*DEFAULT_SLEEP_TIME);
- }
- Sleep(800);
- }
- 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));
- int iPlayRet = entity->m_pMediaPlayer[entity->m_mediaParam.nCfgInx]->PlayMedia(config);
- if (-2 == iPlayRet){
- Sleep(DEFAULT_SLEEP_TIME);
- continue;
- }
- if (-3 == iPlayRet) {
- Sleep(DEFAULT_SLEEP_TIME/6);
- }
- Sleep(800);
- }
- else if ('P' == item.type)
- {//play Image
- Dbg("Begin new Image play, entity->m_mediaParam.nCfgInx = %d.", entity->m_mediaParam.nCfgInx);
- 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));
- 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)) {
- 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;
- }
- }
- Sleep(100);
- }
- }
- unsigned int uend_time = y2k_time_now();
- //Dbg("uend_time - ustart_time = %u.", uend_time - ustart_time);
- if (uend_time - ustart_time < RVC_MIN_LOCALPLAYER_TIME) {
- Sleep(30*DEFAULT_SLEEP_TIME);
- }
- }
- Dbg("Leave Media Play Function.");
- 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("current is playing, close it.");
- if (0 != m_uMediaPlayThreadId){
- m_pMediaAudioPlayer->Close();
- m_uMediaPlayThreadId = 0;
- Sleep(800);
- }
- }
- 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()
|