123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312 |
- #include "stdafx.h"
- #include "mediaManage.h"
- #include <set>
- #include <algorithm>
- #include "../Event.h"
- mediaManage::mediaManage()
- {
- m_curParse.clear();
- if (ExistsDirA(DEFAULT_RESOURSE_PATH))
- {
- setDefaultAddvertPath(string(DEFAULT_RESOURSE_PATH));
- setDefaultDownloadPath(string(DEFAULT_DOWNLOAD_PATH));
- }
- else
- {
- 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<ResourceParse> &resourceList)
- {
- resourceList.clear();
- for (vector<ParseInfo>::iterator i = m_curParse.begin(); i != m_curParse.end(); i++)
- {
- for (vector<ResourceParse>::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<ResourceParse>& resourceList)
- {
- int iNum = 0;
- resourceList.clear();
- for (vector<ResourceParse>::iterator it = m_localList.begin(); it != m_localList.end(); it++)
- {
- if (checkInVaildTime(it->vaildTime, true) && checkInPlayTime(it->playTime, true)) {
- resourceList.push_back(*it);
- iNum++;
- }
- }
- return iNum;
- }
- int mediaManage::GetPlayListByLocal(CResourceParse** ResourceArr, int iSize)
- {
- int iNum = 0;
- for (vector<ResourceParse>::iterator it = m_localList.begin(); it != m_localList.end() && iNum < iSize; it++)
- {
- 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;
- }
- }
- return iNum;
- }
- int mediaManage::GetPlayListByLocal(rvcResourceParse_t* ResourceArr, int iSize)
- {
- int iNum = 0;
- for (vector<ResourceParse>::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<string> resourceList)
- {
- if (0 == resourceList.size())
- return true;
- for (vector<string>::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 (!ExistsFileA(dirPath.c_str()))
- {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("dir %s not exist!", 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<ResourceParse> 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<ResourceParse>::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<ResourceParse> headList, branchList, networkList, allList;
- if (!ExistsFileA(headFile.c_str())) {
- //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 (!ExistsFileA(branchFile.c_str())) {
- //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 (!ExistsFileA(networkFile.c_str())) {
- //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;
- for (vector<ResourceParse>::iterator it = headList.begin(); it < headList.end(); ++it) {
- m_localList.push_back(*it);
- uheadList++;
- }
- for (vector<ResourceParse>::iterator it = branchList.begin(); it < branchList.end(); ++it) {
- m_localList.push_back(*it);
- ubranchList++;
- }
- for (vector<ResourceParse>::iterator it = networkList.begin(); it < networkList.end(); ++it) {
- m_localList.push_back(*it);
- unetworkList++;
- }
- 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 (ExistsFileA(headFile.c_str()))
- {
- configPath = headFile;
- return true;
- }
- else if (ExistsFileA(branchFile.c_str()))
- {
- configPath = branchFile;
- return true;
- }
- else if (ExistsFileA(networkFile.c_str()))
- {
- configPath = networkFile;
- return true;
- }
- else
- return false;
- }
- bool mediaManage::IsResourceExist(string strPath, string strName)
- {
- return ExistsFileA((strPath + strName).c_str());
- }
|