MediaManage.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. #include "stdafx.h"
  2. #include "mediaManage.h"
  3. #include <set>
  4. #include <algorithm>
  5. #include "../Event.h"
  6. mediaManage::mediaManage()
  7. {
  8. m_curParse.clear();
  9. if (checkDirExist(DEFAULT_RESOURSE_PATH))
  10. {
  11. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Set defaultAdvertPath:%s, defaultDownloadPath:%s", DEFAULT_RESOURSE_PATH, DEFAULT_DOWNLOAD_PATH);
  12. setDefaultAddvertPath(string(DEFAULT_RESOURSE_PATH));
  13. setDefaultDownloadPath(string(DEFAULT_DOWNLOAD_PATH));
  14. }
  15. else
  16. {
  17. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Set defaultAdvertPath:%s, defaultDownloadPath:%s", DEFAULT_RESOURSE_PATH_C, DEFAULT_DOWNLOAD_PATH_C);
  18. setDefaultAddvertPath(string(DEFAULT_RESOURSE_PATH_C));
  19. setDefaultDownloadPath(string(DEFAULT_DOWNLOAD_PATH_C));
  20. }
  21. m_ilist_size = 0;
  22. }
  23. void mediaManage::setDefaultAddvertPath(string addvertPath){ m_addvertPath = addvertPath; }
  24. void mediaManage::setDefaultDownloadPath(string downloadPath){ m_downloadPath = downloadPath; }
  25. void mediaManage::GetPlayList(vector<ResourceParse> &resourceList)
  26. {
  27. resourceList.clear();
  28. for (vector<ParseInfo>::iterator i = m_curParse.begin(); i != m_curParse.end(); i++)
  29. {
  30. for (vector<ResourceParse>::iterator j = i->m_mediaList.begin(); j != i->m_mediaList.end(); j++)
  31. {
  32. if (checkInVaildTime(j->vaildTime, true) && checkInPlayTime(j->playTime, true))
  33. resourceList.push_back(*j);
  34. }
  35. }
  36. }
  37. int mediaManage::GetPlayListByLocal(vector<ResourceParse>& resourceList)
  38. {
  39. int iNum = 0;
  40. resourceList.clear();
  41. //TODO: CrossPlaform [Gifur@2025730]
  42. #ifdef RVC_OS_WIN
  43. for each (auto i in m_localList)
  44. {
  45. if (checkInVaildTime(i.vaildTime, true) && checkInPlayTime(i.playTime, true)) {
  46. resourceList.push_back(i);
  47. iNum++;
  48. }
  49. }
  50. #else
  51. for (vector<ResourceParse>::iterator it = m_localList.begin(); it != m_localList.end(); it++)
  52. {
  53. if (checkInVaildTime(it->vaildTime, true) && checkInPlayTime(it->playTime, true)) {
  54. resourceList.push_back(*it);
  55. iNum++;
  56. }
  57. }
  58. #endif // _WIN32
  59. return iNum;
  60. }
  61. int mediaManage::GetPlayListByLocal(CResourceParse** ResourceArr, int iSize)
  62. {
  63. int iNum = 0;
  64. for (vector<ResourceParse>::iterator it = m_localList.begin(); it != m_localList.end() && iNum < iSize; it++)
  65. {
  66. //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());
  67. if (checkInVaildTime(it->vaildTime, true) && checkInPlayTime(it->playTime, true)) {
  68. CResourceParse* pNode = new CResourceParse();
  69. pNode->type = it->type;
  70. pNode->fullScreen = it->fullScreen;
  71. pNode->primMonitor = it->primMonitor;
  72. pNode->simpleMode = it->simpleMode;
  73. pNode->playInterval = it->playInterval;
  74. pNode->priority = it->priority;
  75. if (it->videoNames.length() > 0) {
  76. pNode->pvideoNames = new char[it->videoNames.length() + 1];
  77. memset(pNode->pvideoNames, 0, it->videoNames.length() + 1);
  78. memcpy(pNode->pvideoNames, it->videoNames.c_str(), it->videoNames.length());
  79. }
  80. if (it->vaildTime.length() > 0) {
  81. pNode->pvaildTime = new char[it->vaildTime.length() + 1];
  82. memset(pNode->pvaildTime, 0, it->vaildTime.length() + 1);
  83. memcpy(pNode->pvaildTime, it->vaildTime.c_str(), it->vaildTime.length());
  84. }
  85. if (it->resourcePath.length() > 0) {
  86. pNode->presourcePath = new char[it->resourcePath.length() + 1];
  87. memset(pNode->presourcePath, 0, it->resourcePath.length() + 1);
  88. memcpy(pNode->presourcePath, it->resourcePath.c_str(), it->resourcePath.length());
  89. }
  90. if (it->playTime.length() > 0) {
  91. pNode->playTime = new char[it->playTime.length() + 1];
  92. memset(pNode->playTime, 0, it->playTime.length() + 1);
  93. memcpy(pNode->playTime, it->playTime.c_str(), it->playTime.length());
  94. }
  95. ResourceArr[iNum++] = pNode;
  96. //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);
  97. //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);
  98. //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);
  99. }
  100. }
  101. return iNum;
  102. }
  103. int mediaManage::GetPlayListByLocal(rvcResourceParse_t* ResourceArr, int iSize)
  104. {
  105. int iNum = 0;
  106. for (vector<ResourceParse>::iterator it = m_localList.begin(); it != m_localList.end() && iNum < iSize; it++)
  107. {
  108. if (checkInVaildTime(it->vaildTime, true) && checkInPlayTime(it->playTime, true) && IsResourceExist(it->resourcePath, it->videoNames)) {
  109. rvcResourceParse_t* pNode = ResourceArr+iNum;
  110. pNode->type = it->type;
  111. pNode->fullScreen = it->fullScreen;
  112. pNode->primMonitor = it->primMonitor;
  113. pNode->simpleMode = it->simpleMode;
  114. pNode->playInterval = it->playInterval;
  115. pNode->priority = it->priority;
  116. if (it->videoNames.length() > 0) {
  117. memcpy(pNode->strvideoNames, it->videoNames.c_str(), it->videoNames.length());
  118. }
  119. if (it->vaildTime.length() > 0) {
  120. memcpy(pNode->strvaildTime, it->vaildTime.c_str(), it->vaildTime.length());
  121. }
  122. if (it->resourcePath.length() > 0) {
  123. memcpy(pNode->strResourcePath, it->resourcePath.c_str(), it->resourcePath.length());
  124. }
  125. if (it->playTime.length() > 0) {
  126. memcpy(pNode->strplayTime, it->playTime.c_str(), it->playTime.length());
  127. }
  128. iNum++;
  129. }
  130. }
  131. return iNum;
  132. }
  133. bool mediaManage::AddResourceList(vector<string> resourceList)
  134. {
  135. if (0 == resourceList.size())
  136. return true;
  137. for (vector<string>::iterator i = resourceList.begin(); i != resourceList.end(); i++)
  138. {
  139. int pos = i->find(".zip");
  140. if (-1 == pos)
  141. continue;
  142. string dirName = i->substr(0, pos);
  143. string fileName = m_downloadPath + SPLIT_SLASH_STR + *i;
  144. string dirPath = m_addvertPath + SPLIT_SLASH_STR + dirName;
  145. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("dirName:%s, fileName:%s, dirPath:%s", dirName.c_str(), fileName.c_str(), dirPath.c_str());
  146. wstring wfileName, wdirPath;
  147. StringToWstring(wfileName, fileName);
  148. StringToWstring(wdirPath, dirPath);
  149. if (!checkFileExist(dirPath))
  150. {
  151. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("dir %s not exist!", dirPath.c_str());
  152. continue;
  153. }
  154. /*
  155. if (!checkFileExist(dirPath) && createDir(dirPath) && !Unzip2Folder((BSTR)wfileName.c_str(), (BSTR)wdirPath.c_str()))
  156. {
  157. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("unzip %s to %s fail!", fileName.c_str(), dirPath.c_str());
  158. continue;
  159. }
  160. */
  161. string configPath = "";
  162. if (!findVaildConfig(dirPath, configPath))
  163. {
  164. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("can not find config file in %s//%s", dirPath.c_str(), configPath.c_str());
  165. continue;
  166. }
  167. vector<ResourceParse> mediaList;
  168. if (!parseResourceIni(configPath.c_str(), mediaList))
  169. {
  170. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("parse config %s fail!", configPath.c_str());
  171. continue;
  172. }
  173. string resourcePath = dirPath + SPLIT_SLASH_STR;
  174. for (vector<ResourceParse>::iterator j = mediaList.begin(); j != mediaList.end(); j++)
  175. j->resourcePath = resourcePath;
  176. ParseInfo resourseInfo(*i, mediaList);
  177. m_curParse.push_back(resourseInfo);//modify resourse list
  178. }
  179. return true;
  180. }
  181. void mediaManage::InitResourceListByLocal()
  182. {
  183. string headFile = m_addvertPath + SPLIT_SLASH_STR + HEADINI_NAME;
  184. string branchFile = m_addvertPath + SPLIT_SLASH_STR + BRANCHINI_NAME;
  185. string networkFile = m_addvertPath + SPLIT_SLASH_STR + NETWORKINI_NAME;
  186. vector<ResourceParse> headList, branchList, networkList, allList;
  187. if (!checkFileExist(headFile)) {
  188. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("head config %s not exist!", headFile.c_str());
  189. }
  190. else if (!parseResourceIni(headFile.c_str(), headList)) {
  191. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("parse head config %s fail!", headFile.c_str());
  192. }
  193. if (!checkFileExist(branchFile)) {
  194. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("branch config %s not exist!", branchFile.c_str());
  195. }
  196. else if (!parseResourceIni(branchFile.c_str(), branchList)) {
  197. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("parse branch config %s fail!", branchFile.c_str());
  198. }
  199. if (!checkFileExist(networkFile)) {
  200. //DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("network config %s not exist!", networkFile.c_str());
  201. }
  202. else if (!parseResourceIni(networkFile.c_str(), networkList)) {
  203. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("parse network config %s fail!", networkFile.c_str());
  204. }
  205. m_localList.clear();
  206. uint32_t uheadList = 0;
  207. uint32_t ubranchList = 0;
  208. uint32_t unetworkList = 0;
  209. bool blog = false;
  210. //TODO: CrossPlaform [Gifur@2025729]
  211. #ifdef RVC_OS_WIN
  212. for each (auto i in headList) {
  213. m_localList.push_back(i);
  214. uheadList++;
  215. }
  216. for each (auto i in branchList) {
  217. m_localList.push_back(i);
  218. ubranchList++;
  219. }
  220. for each (auto i in networkList) {
  221. m_localList.push_back(i);
  222. unetworkList++;
  223. }
  224. #else
  225. for (vector<ResourceParse>::iterator it = headList.begin(); it < headList.end(); ++it){
  226. m_localList.push_back(*it);
  227. uheadList++;
  228. }
  229. for (vector<ResourceParse>::iterator it = branchList.begin(); it < branchList.end(); ++it){
  230. m_localList.push_back(*it);
  231. ubranchList++;
  232. }
  233. for (vector<ResourceParse>::iterator it = networkList.begin(); it < networkList.end(); ++it){
  234. m_localList.push_back(*it);
  235. unetworkList++;
  236. }
  237. #endif // RVC_OS_WIN
  238. if (m_ilist_size != m_localList.size()) {
  239. m_ilist_size = (int)m_localList.size();
  240. blog = true;
  241. 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);
  242. }
  243. std::stable_sort(m_localList.begin(), m_localList.end(), [](const ResourceParse& a, const ResourceParse& b) {
  244. return a.priority > b.priority;
  245. });
  246. CSimpleStringA strJson("");
  247. CSimpleStringA strValidTimeJson("");
  248. int index = 0;
  249. for (auto i = m_localList.begin(); i != m_localList.end(); i++)
  250. {
  251. size_t pos = i->videoNames.find("\\");
  252. if (pos != string::npos){
  253. i->resourcePath = m_addvertPath + SPLIT_SLASH_STR + i->videoNames.substr(0, pos) + SPLIT_SLASH_STR;
  254. i->videoNames = i->videoNames.substr(pos + 1, i->videoNames.length() - pos - 1);
  255. }
  256. else {
  257. i->resourcePath = m_addvertPath + SPLIT_SLASH_STR;
  258. }
  259. if (blog) {
  260. strJson += CSimpleStringA::Format("\"%d\":\"%s\",", index, i->videoNames.c_str());
  261. strValidTimeJson += CSimpleStringA::Format("\"%d\":\"%s\",", index, i->vaildTime.c_str());
  262. index++;
  263. }
  264. }
  265. if (blog) {
  266. if (strJson.GetLength() > 0) {
  267. strJson[strJson.GetLength() - 1] = '\0';
  268. }
  269. LogWarn(Severity_Low, Error_Debug, LOG_EVT_ADV_PLAYLIST_INFO, CSimpleStringA::Format("[{%s}]", strJson.GetData()).GetData());
  270. if (strValidTimeJson.GetLength() > 0) {
  271. strValidTimeJson[strValidTimeJson.GetLength() - 1] = '\0';
  272. }
  273. LogWarn(Severity_Low, Error_Debug, LOG_EVT_ADV_PLAYLIST_VALIDTIME, CSimpleStringA::Format("[{%s}]", strValidTimeJson.GetData()).GetData());
  274. }
  275. }
  276. bool mediaManage::findVaildConfig(string dirPath, string &configPath)
  277. {
  278. string headFile = dirPath + SPLIT_SLASH_STR + HEADINI_NAME;
  279. string branchFile = dirPath + SPLIT_SLASH_STR + BRANCHINI_NAME;
  280. string networkFile = dirPath + SPLIT_SLASH_STR + NETWORKINI_NAME;
  281. if (checkFileExist(headFile))
  282. {
  283. configPath = headFile;
  284. return true;
  285. }
  286. else if (checkFileExist(branchFile))
  287. {
  288. configPath = branchFile;
  289. return true;
  290. }
  291. else if (checkFileExist(networkFile))
  292. {
  293. configPath = networkFile;
  294. return true;
  295. }
  296. else
  297. return false;
  298. }
  299. bool mediaManage::IsResourceExist(string strPath, string strName)
  300. {
  301. return checkFileExist(strPath + strName);
  302. }