#include "stdafx.h" #include "mediaManage.h" #include #include #include "../Event.h" mediaManage::mediaManage() { m_curParse.clear(); if (checkDirExist(DEFAULT_RESOURSE_PATH)) { //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Set defaultAdvertPath:%s, defaultDownloadPath:%s", DEFAULT_RESOURSE_PATH, DEFAULT_DOWNLOAD_PATH); setDefaultAddvertPath(string(DEFAULT_RESOURSE_PATH)); setDefaultDownloadPath(string(DEFAULT_DOWNLOAD_PATH)); } else { //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Set defaultAdvertPath:%s, defaultDownloadPath:%s", DEFAULT_RESOURSE_PATH_C, DEFAULT_DOWNLOAD_PATH_C); setDefaultAddvertPath(string(DEFAULT_RESOURSE_PATH_C)); setDefaultDownloadPath(string(DEFAULT_DOWNLOAD_PATH_C)); } m_ilist_size = 0; } void mediaManage::setDefaultAddvertPath(string addvertPath){ m_addvertPath = addvertPath; } void mediaManage::setDefaultDownloadPath(string downloadPath){ m_downloadPath = downloadPath; } void mediaManage::GetPlayList(vector &resourceList) { resourceList.clear(); for (vector::iterator i = m_curParse.begin(); i != m_curParse.end(); i++) { for (vector::iterator j = i->m_mediaList.begin(); j != i->m_mediaList.end(); j++) { if (checkInVaildTime(j->vaildTime, true) && checkInPlayTime(j->playTime, true)) resourceList.push_back(*j); } } } int mediaManage::GetPlayListByLocal(vector& resourceList) { int iNum = 0; resourceList.clear(); #ifdef RVC_OS_WIN for each (auto i in m_localList) { if (checkInVaildTime(i.vaildTime, true) && checkInPlayTime(i.playTime, true)) { resourceList.push_back(i); iNum++; } } #else for (vector::iterator it = m_localList.begin(); it != m_localList.end(); it++) { if (checkInVaildTime(it->vaildTime, true) && checkInPlayTime(it->playTime, true)) { resourceList.push_back(*it); iNum++; } } #endif // _WIN32 return iNum; } int mediaManage::GetPlayListByLocal(CResourceParse** ResourceArr, int iSize) { int iNum = 0; for (vector::iterator it = m_localList.begin(); it != m_localList.end() && iNum < iSize; it++) { //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("new deep copy play extend %c:%s, %s, %s, %s", it->type, it->resourcePath.c_str(), it->videoNames.c_str(), it->vaildTime.c_str(), it->playTime.c_str()); if (checkInVaildTime(it->vaildTime, true) && checkInPlayTime(it->playTime, true)) { CResourceParse* pNode = new CResourceParse(); pNode->type = it->type; pNode->fullScreen = it->fullScreen; pNode->primMonitor = it->primMonitor; pNode->simpleMode = it->simpleMode; pNode->playInterval = it->playInterval; pNode->priority = it->priority; if (it->videoNames.length() > 0) { pNode->pvideoNames = new char[it->videoNames.length() + 1]; memset(pNode->pvideoNames, 0, it->videoNames.length() + 1); memcpy(pNode->pvideoNames, it->videoNames.c_str(), it->videoNames.length()); } if (it->vaildTime.length() > 0) { pNode->pvaildTime = new char[it->vaildTime.length() + 1]; memset(pNode->pvaildTime, 0, it->vaildTime.length() + 1); memcpy(pNode->pvaildTime, it->vaildTime.c_str(), it->vaildTime.length()); } if (it->resourcePath.length() > 0) { pNode->presourcePath = new char[it->resourcePath.length() + 1]; memset(pNode->presourcePath, 0, it->resourcePath.length() + 1); memcpy(pNode->presourcePath, it->resourcePath.c_str(), it->resourcePath.length()); } if (it->playTime.length() > 0) { pNode->playTime = new char[it->playTime.length() + 1]; memset(pNode->playTime, 0, it->playTime.length() + 1); memcpy(pNode->playTime, it->playTime.c_str(), it->playTime.length()); } ResourceArr[iNum++] = pNode; //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("aftercopy play extend pNode->type=0x%08x:pNode->presourcePath=0x%08x, pNode->pvideoNames=0x%08x, pNode->pvaildTime=0x%08x, pNode->playTime=0x%08x", pNode->type, pNode->presourcePath, pNode->pvideoNames, pNode->pvaildTime, pNode->playTime); //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("aftercopy play extend %c:%s, %s, %s, %s", pNode->type, pNode->presourcePath, pNode->pvideoNames, pNode->pvaildTime, pNode->playTime); //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d ResourceList[%d] address is 0x%08x, pNode address is 0x%08x.", __FUNCTION__, __LINE__, uNum-1, ResourceArr[uNum-1], pNode); } } return iNum; } int mediaManage::GetPlayListByLocal(rvcResourceParse_t* ResourceArr, int iSize) { int iNum = 0; for (vector::iterator it = m_localList.begin(); it != m_localList.end() && iNum < iSize; it++) { if (checkInVaildTime(it->vaildTime, true) && checkInPlayTime(it->playTime, true) && IsResourceExist(it->resourcePath, it->videoNames)) { rvcResourceParse_t* pNode = ResourceArr+iNum; pNode->type = it->type; pNode->fullScreen = it->fullScreen; pNode->primMonitor = it->primMonitor; pNode->simpleMode = it->simpleMode; pNode->playInterval = it->playInterval; pNode->priority = it->priority; if (it->videoNames.length() > 0) { memcpy(pNode->strvideoNames, it->videoNames.c_str(), it->videoNames.length()); } if (it->vaildTime.length() > 0) { memcpy(pNode->strvaildTime, it->vaildTime.c_str(), it->vaildTime.length()); } if (it->resourcePath.length() > 0) { memcpy(pNode->strResourcePath, it->resourcePath.c_str(), it->resourcePath.length()); } if (it->playTime.length() > 0) { memcpy(pNode->strplayTime, it->playTime.c_str(), it->playTime.length()); } iNum++; } } return iNum; } bool mediaManage::AddResourceList(vector resourceList) { if (0 == resourceList.size()) return true; for (vector::iterator i = resourceList.begin(); i != resourceList.end(); i++) { int pos = i->find(".zip"); if (-1 == pos) continue; string dirName = i->substr(0, pos); string fileName = m_downloadPath + SPLIT_SLASH_STR + *i; string dirPath = m_addvertPath + SPLIT_SLASH_STR + dirName; //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("dirName:%s, fileName:%s, dirPath:%s", dirName.c_str(), fileName.c_str(), dirPath.c_str()); wstring wfileName, wdirPath; StringToWstring(wfileName, fileName); StringToWstring(wdirPath, dirPath); if (!checkFileExist(dirPath)) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("dir %s not exist!", dirPath.c_str()); continue; } /* if (!checkFileExist(dirPath) && createDir(dirPath) && !Unzip2Folder((BSTR)wfileName.c_str(), (BSTR)wdirPath.c_str())) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("unzip %s to %s fail!", fileName.c_str(), dirPath.c_str()); continue; } */ string configPath = ""; if (!findVaildConfig(dirPath, configPath)) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("can not find config file in %s//%s", dirPath.c_str(), configPath.c_str()); continue; } vector mediaList; if (!parseResourceIni(configPath.c_str(), mediaList)) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("parse config %s fail!", configPath.c_str()); continue; } string resourcePath = dirPath + SPLIT_SLASH_STR; for (vector::iterator j = mediaList.begin(); j != mediaList.end(); j++) j->resourcePath = resourcePath; ParseInfo resourseInfo(*i, mediaList); m_curParse.push_back(resourseInfo);//modify resourse list } return true; } void mediaManage::InitResourceListByLocal() { string headFile = m_addvertPath + SPLIT_SLASH_STR + HEADINI_NAME; string branchFile = m_addvertPath + SPLIT_SLASH_STR + BRANCHINI_NAME; string networkFile = m_addvertPath + SPLIT_SLASH_STR + NETWORKINI_NAME; vector headList, branchList, networkList, allList; if (!checkFileExist(headFile)) { //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("head config %s not exist!", headFile.c_str()); } else if (!parseResourceIni(headFile.c_str(), headList)) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("parse head config %s fail!", headFile.c_str()); } if (!checkFileExist(branchFile)) { //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("branch config %s not exist!", branchFile.c_str()); } else if (!parseResourceIni(branchFile.c_str(), branchList)) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("parse branch config %s fail!", branchFile.c_str()); } if (!checkFileExist(networkFile)) { //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("network config %s not exist!", networkFile.c_str()); } else if (!parseResourceIni(networkFile.c_str(), networkList)) { DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("parse network config %s fail!", networkFile.c_str()); } m_localList.clear(); uint32_t uheadList = 0; uint32_t ubranchList = 0; uint32_t unetworkList = 0; bool blog = false; #ifdef RVC_OS_WIN for each (auto i in headList) { m_localList.push_back(i); uheadList++; } for each (auto i in branchList) { m_localList.push_back(i); ubranchList++; } for each (auto i in networkList) { m_localList.push_back(i); unetworkList++; } #else for (vector::iterator it = headList.begin(); it < headList.end(); ++it){ m_localList.push_back(*it); uheadList++; } for (vector::iterator it = branchList.begin(); it < branchList.end(); ++it){ m_localList.push_back(*it); ubranchList++; } for (vector::iterator it = networkList.begin(); it < networkList.end(); ++it){ m_localList.push_back(*it); unetworkList++; } #endif // RVC_OS_WIN if (m_ilist_size != m_localList.size()) { m_ilist_size = (int)m_localList.size(); blog = true; DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("adv play list size is %d, head(%d), branch(%d), network(%d).", m_localList.size(), uheadList, ubranchList, unetworkList); } std::stable_sort(m_localList.begin(), m_localList.end(), [](const ResourceParse& a, const ResourceParse& b) { return a.priority > b.priority; }); CSimpleStringA strJson(""); CSimpleStringA strValidTimeJson(""); int index = 0; for (auto i = m_localList.begin(); i != m_localList.end(); i++) { size_t pos = i->videoNames.find("\\"); if (pos != string::npos){ i->resourcePath = m_addvertPath + SPLIT_SLASH_STR + i->videoNames.substr(0, pos) + SPLIT_SLASH_STR; i->videoNames = i->videoNames.substr(pos + 1, i->videoNames.length() - pos - 1); } else { i->resourcePath = m_addvertPath + SPLIT_SLASH_STR; } if (blog) { strJson += CSimpleStringA::Format("\"%d\":\"%s\",", index, i->videoNames.c_str()); strValidTimeJson += CSimpleStringA::Format("\"%d\":\"%s\",", index, i->vaildTime.c_str()); index++; } } if (blog) { if (strJson.GetLength() > 0) { strJson[strJson.GetLength() - 1] = '\0'; } LogWarn(Severity_Low, Error_Debug, LOG_EVT_ADV_PLAYLIST_INFO, CSimpleStringA::Format("[{%s}]", strJson.GetData()).GetData()); if (strValidTimeJson.GetLength() > 0) { strValidTimeJson[strValidTimeJson.GetLength() - 1] = '\0'; } LogWarn(Severity_Low, Error_Debug, LOG_EVT_ADV_PLAYLIST_VALIDTIME, CSimpleStringA::Format("[{%s}]", strValidTimeJson.GetData()).GetData()); } } bool mediaManage::findVaildConfig(string dirPath, string &configPath) { string headFile = dirPath + SPLIT_SLASH_STR + HEADINI_NAME; string branchFile = dirPath + SPLIT_SLASH_STR + BRANCHINI_NAME; string networkFile = dirPath + SPLIT_SLASH_STR + NETWORKINI_NAME; if (checkFileExist(headFile)) { configPath = headFile; return true; } else if (checkFileExist(branchFile)) { configPath = branchFile; return true; } else if (checkFileExist(networkFile)) { configPath = networkFile; return true; } else return false; } bool mediaManage::IsResourceExist(string strPath, string strName) { return checkFileExist(strPath + strName); }