mod_SalesRecorder.cpp 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754
  1. #include "stdafx.h"
  2. #include "mod_SalesRecorder.h"
  3. #include "rvcmediacommon/rvc_media_common.h"
  4. #include "fileutil.h"
  5. #include "array.h"
  6. #include <memutil.h>
  7. #include <algorithm>
  8. #ifdef RVC_OS_WIN
  9. #include <Windows.h>
  10. #endif
  11. #include "mod_customeraware/Event.h"
  12. #include "mod_facetracking/sysvar.h"
  13. #include <assert.h>
  14. #include "EventCode.h"
  15. #include <string.h>
  16. #include "mod_interactivecontrol/InteractiveControl_client_g.h"
  17. #include "mod_interactivecontrol/InteractiveControl_def_g.h"
  18. #define LOG_EVT_UI_RECORDFAILED 0x31500001 //双录失败
  19. #define LOG_EVT_SALESRECORD_ENTITY_EXCEPTION 0x31500002 //销售双录实体异常
  20. #define LOG_EVT_SALESRECORD_FINISHED 0x31500003 //销售双录结束
  21. #define LOG_EVT_AUDIOSTREAM_TRANSMISSION_FAILED 0x31600001 //音频流传输失败
  22. #define LOG_EVT_START_REMOTERECORD 0x31510001 //开始远程双录
  23. #define LOG_EVT_STOP_REMOTERECORD 0x31510002 //停止远程双录
  24. #define LOG_EVT_SALESRECORD_FAILED 0x31510003 //销售双录失败
  25. #define LOG_EVT_RECORD_ENTITY_EXCEPTION 0x31510004 //销售双录实体异常
  26. #define LOG_EVT_RECORD_FINISHED 0x31510005 //销售双录已完成
  27. #define LOG_EVT_RECORD_SAVED_SUCCESS 0x31510006 //双录文件保存成功
  28. #define LOG_EVT_RECORD_SAVED_FAILED 0x31510007 //双录文件保存失败
  29. #ifndef EWS_CAMERA_FLAG
  30. #define EWS_CAMERA_FLAG "ews|"
  31. #endif
  32. #ifndef EWS_CAMERA_FLAG_LEN
  33. #define EWS_CAMERA_FLAG_LEN 4
  34. #endif
  35. #define SYSVAR_CALLTYPE "CallType"
  36. #define CALLTYPE_NORMAL 'N' // 呼叫类型,普通模式
  37. #define CALLTYPE_MOBILE 'M' // 呼叫类型,手机模式
  38. #define MAX_DISK_PERCENT 95 // 磁盘最大占用百分比 add by ly 2018/02/24
  39. static ErrorCodeEnum ParseIPAddress(const char *str, CSimpleStringA &ip, int &port)
  40. {
  41. ErrorCodeEnum Error = Error_Unexpect;
  42. if (str) {
  43. char tmp1[32] = {};
  44. char tmp2[16] = {};
  45. sscanf(str, "%s %s", tmp1, tmp2);
  46. if (tmp1[0] != 0 && tmp2[0] != 0)
  47. {
  48. ip = tmp1;
  49. port = atoi(tmp2);
  50. Error = Error_Succeed;
  51. }
  52. else
  53. return Error;
  54. }
  55. return Error;
  56. }
  57. static BOOL CheckDiskStatus(const char *szRoot, int nPercent, int *pFreeRatio)
  58. {
  59. #ifdef RVC_OS_WIN
  60. _ULARGE_INTEGER lpFreeBytesAvailableToCaller = {}, lpTotalNumberOfBytes = {}, lpTotalNumberOfFreeBytes = {};
  61. BOOL ret = GetDiskFreeSpaceEx(szRoot, &lpFreeBytesAvailableToCaller, &lpTotalNumberOfBytes, &lpTotalNumberOfFreeBytes);
  62. if (ret == 0)
  63. {
  64. Dbg("CheckDiskStatus.GetDiskFreeSpaceEx failed(%d).",GetLastError());
  65. return FALSE;
  66. }
  67. DWORD dwTotal = lpTotalNumberOfBytes.QuadPart/1048576;
  68. DWORD dwTotalFree = lpTotalNumberOfFreeBytes.QuadPart/1048576;
  69. int ratio = dwTotalFree*100/dwTotal;
  70. *pFreeRatio = ratio;
  71. Dbg("free disk %d MB, %d percent free.\n", dwTotalFree, ratio);
  72. //if (ratio < (100-MAX_DISK_PERCENT))
  73. if (ratio < (100-nPercent))
  74. {
  75. return FALSE;
  76. }
  77. return TRUE;
  78. #else
  79. //todo 调用resourcewatcher
  80. return TRUE;
  81. #endif
  82. }
  83. static int hch2int(char hch)
  84. {
  85. if (hch >= '0' && hch <= '9')
  86. return hch-'0';
  87. else if (hch >= 'a' && hch <= 'f')
  88. return hch-'a'+10;
  89. else if (hch >= 'A' && hch <= 'F')
  90. return hch-'A'+10;
  91. return 0;
  92. }
  93. static long hexstr2int(const char *str, int len)
  94. {
  95. long result = 0;
  96. if (str && len <= strlen(str)) {
  97. for (int i = 0; i < len; ++i) {
  98. result += (hch2int(str[i]) << ((len-i-1) << 2));
  99. }
  100. }
  101. return result;
  102. }
  103. static CSimpleStringA VideoSerialID2TimeString(const char *videoserialid)
  104. {
  105. DWORD nTimeTicks = hexstr2int(videoserialid,8);
  106. return ((CSmallDateTime)nTimeTicks).ToTimeString();
  107. }
  108. static void CStringSplit(char* str, char** result, const char* del)
  109. {
  110. char* ptr = NULL;
  111. char* p = strtok_r(str, del, &ptr);
  112. while (p != NULL){
  113. *result++ = p;
  114. p = strtok_r(NULL, del, &ptr);
  115. }
  116. }
  117. #ifdef RVC_OS_WIN
  118. // 寻找某目录下与通配符匹配的文件
  119. static BOOL FindMatchedFile(LPCSTR sFindPath, LPCSTR sFindFileName, ULONGLONG& uCountFile)
  120. {
  121. char sPath[MAX_PATH];
  122. ZeroMemory(sPath, MAX_PATH);
  123. char sFormatFileName[MAX_PATH + 2] = "*";
  124. WIN32_FIND_DATA FindFileData;
  125. HANDLE hFind;
  126. BOOL fFinished = FALSE;
  127. strcpy(sFormatFileName, sFindPath);
  128. if (sFindPath[strlen(sFindPath) - 1] != SPLIT_SLASH)
  129. {
  130. strcat(sFormatFileName, SPLIT_SLASH_STR);
  131. strcat(sFormatFileName, "*");
  132. }
  133. else
  134. {
  135. strcat(sFormatFileName, "*");
  136. }
  137. strcat(sFormatFileName, sFindFileName);
  138. strcat(sFormatFileName, "*");
  139. hFind = FindFirstFile(sFormatFileName, &FindFileData);
  140. if (hFind == INVALID_HANDLE_VALUE)
  141. {
  142. return FALSE;
  143. }
  144. else
  145. {
  146. while (!fFinished)
  147. {
  148. strcpy(sPath, sFindPath);
  149. if (sPath[strlen(sPath) - 1] != SPLIT_SLASH)
  150. {
  151. strcat(sPath, SPLIT_SLASH_STR);
  152. }
  153. strcat(sPath, FindFileData.cFileName);
  154. if (!(FILE_ATTRIBUTE_DIRECTORY & FindFileData.dwFileAttributes))
  155. {
  156. ++uCountFile;
  157. }
  158. if (!FindNextFile(hFind, &FindFileData))
  159. {
  160. if (GetLastError() == ERROR_NO_MORE_FILES)
  161. {
  162. fFinished = TRUE;
  163. }
  164. else
  165. {
  166. break;
  167. }
  168. }
  169. }
  170. FindClose(hFind);
  171. }
  172. return TRUE;
  173. }
  174. #else
  175. static BOOL FindMatchedFile(LPCSTR sFindPath, LPCSTR sFindFileName, ULONGLONG& uCountFile)
  176. {
  177. DIR* pDir = NULL;
  178. struct dirent* pFile = NULL;
  179. CSimpleStringA tmpFindFileName = sFindFileName;
  180. pDir = opendir(sFindPath);
  181. if (pDir == NULL) return FALSE;
  182. //linux不支持*查找,去掉后缀
  183. char strsuffix[MAX_PATH] = { 0 };
  184. snprintf(strsuffix, MAX_PATH, "*.%s", RVC_RECORD_SUFFIX);
  185. if (tmpFindFileName.IsEndWith(strsuffix)) {
  186. tmpFindFileName = tmpFindFileName.SubString(0, tmpFindFileName.GetLength() - 5);
  187. }
  188. while ((pFile = readdir(pDir)) != NULL) {
  189. if (pFile->d_type & DT_DIR) {
  190. //m_pHostApi->Debug("FindMatchedFile DIR name: %s.", pFile->d_name);
  191. if (strcmp(pFile->d_name, ".") == 0
  192. || strcmp(pFile->d_name, "..") == 0) continue;
  193. char Path[256];
  194. int len = strlen(sFindPath);
  195. strncpy(Path, sFindPath, len + 1);
  196. if (sFindPath[len - 1] != '/') strncat(Path, "/", 2);
  197. strncat(Path, pFile->d_name, strlen(pFile->d_name) + 1);
  198. //m_pHostApi->Debug("FindMatchedFile Path: %s.", Path);
  199. FindMatchedFile(Path, (LPCTSTR)tmpFindFileName, uCountFile);
  200. }
  201. else {
  202. //m_pHostApi->Debug("FindMatchedFile FILE name: %s.", pFile->d_name);
  203. if (strstr(pFile->d_name, (LPCTSTR)tmpFindFileName) != NULL) {
  204. ++uCountFile;
  205. }
  206. }
  207. }
  208. closedir(pDir);
  209. return TRUE;
  210. }
  211. #endif
  212. CSimpleStringA DecryptString(LPCTSTR lpszEncrpyted)
  213. {
  214. if (NULL == lpszEncrpyted) {
  215. return CSimpleStringA("");
  216. }
  217. int iEncrypt = 0;
  218. int len = strlen(lpszEncrpyted);
  219. CSimpleStringA csPlainTxt('\0', (len) / 2 + 1);
  220. int iCh = 0;
  221. for (int i = 0; i < len; i += 2) {
  222. sscanf(lpszEncrpyted + i, "%02X", &iCh);
  223. csPlainTxt[i / 2] = (char)(((char)iCh) ^ (128 | (iEncrypt++ & 127)));
  224. }
  225. return CSimpleStringA((LPCTSTR)csPlainTxt);
  226. }
  227. void SalesRecordServiceSession::Handle_GetOFLVideoRecords( SpReqAnsContext<SalesRecorderSerVice_GetOFLVideoRecords_Req, SalesRecorderSerVice_GetOFLVideoRecords_Ans>::Pointer ctx )
  228. {
  229. CSimpleStringA Name = CSimpleStringW2A(ctx->Req.Name);
  230. CSimpleStringA CardNo = CSimpleStringW2A(ctx->Req.CardNo);
  231. CSimpleStringA BeginTime = CSimpleStringW2A(ctx->Req.BeginTime);
  232. CSimpleStringA EndTime = CSimpleStringW2A(ctx->Req.EndTime);
  233. Dbg("Handle_GetOFLVideoRecords:BeginTime=%s,EndTime=%s",(LPCTSTR)BeginTime,(LPCTSTR)EndTime);
  234. ctx->Answer(Error_Succeed);
  235. }
  236. void SalesRecordServiceSession::Handle_CheckVideoDiskStatus( SpReqAnsContext<SalesRecorderSerVice_CheckVideoDiskStatus_Req, SalesRecorderSerVice_CheckVideoDiskStatus_Ans>::Pointer ctx )
  237. {
  238. int nFreeRatio = 0;
  239. int bSufficient = CheckDiskStatus((LPCTSTR)ctx->Req.DriveLetter,m_pEntity->m_max_disk_percent,&nFreeRatio);
  240. ctx->Ans.IsSufficient = bSufficient;
  241. ctx->Ans.FreeRatio = nFreeRatio;
  242. ctx->Answer(Error_Succeed);
  243. }
  244. void SalesRecordServiceSession::Handle_PlayVideo(SpReqAnsContext<SalesRecorderSerVice_PlayVideo_Req, SalesRecorderSerVice_PlayVideo_Ans>::Pointer ctx)
  245. {
  246. Dbg("PlayVideo name is %s.", (LPCTSTR)CSimpleStringW2A(ctx->Req.VideoName));
  247. ErrorCodeEnum ErrorCode = m_pEntity->HandleDisplayVideo();
  248. ctx->Answer(ErrorCode);
  249. }
  250. void SalesRecordServiceSession::Handle_SaveVideo(SpReqAnsContext<SalesRecorderSerVice_SaveVideo_Req, SalesRecorderSerVice_SaveVideo_Ans>::Pointer ctx)
  251. {
  252. Dbg("Save Video name is %s.", (LPCTSTR)CSimpleStringW2A(ctx->Req.VideoName));
  253. ErrorCodeEnum ErrorCode = m_pEntity->HandleSaveVideo();
  254. ctx->Answer(ErrorCode);
  255. }
  256. void SalesRecordServiceSession::Handle_StopRecord(SpReqAnsContext<SalesRecorderSerVice_StopRecord_Req, SalesRecorderSerVice_StopRecord_Ans>::Pointer ctx)
  257. {
  258. ErrorCodeEnum ErrorCode = m_pEntity->HandleStopRecord((LPCTSTR)CSimpleStringW2A(ctx->Req.VideoName));
  259. ctx->Answer(ErrorCode);
  260. }
  261. void SalesRecordServiceSession::Handle_SetAudioTransFlag(SpReqAnsContext<SalesRecorderSerVice_SetAudioTransFlag_Req, SalesRecorderSerVice_SetAudioTransFlag_Ans>::Pointer ctx)
  262. {
  263. Dbg("Audio transmission flag is %s.", ctx->Req.TransFlag ? "true" : "false");
  264. ctx->Answer(Error_Succeed);
  265. }
  266. void SalesRecordServiceSession::Handle_StopShowVideo(SpReqAnsContext<SalesRecorderSerVice_StopShowVideo_Req, SalesRecorderSerVice_StopShowVideo_Ans>::Pointer ctx)
  267. {
  268. Dbg("Stop Show Video name is %s.", (LPCTSTR)CSimpleStringW2A(ctx->Req.VideoName));
  269. ErrorCodeEnum ErrorCode = m_pEntity->HandleStopShowVideo();
  270. ctx->Answer(ErrorCode);
  271. }
  272. void SalesRecordServiceSession::Handle_PlaySalesRecord(SpReqAnsContext<SalesRecorderSerVice_PlaySalesRecord_Req, SalesRecorderSerVice_PlaySalesRecord_Ans>::Pointer ctx)
  273. {
  274. Dbg("Stop Show Video name is %s.", (LPCTSTR)CSimpleStringW2A(ctx->Req.VideoName));
  275. ErrorCodeEnum ErrorCode = m_pEntity->HandlePlaySalesRecordVideo(ctx->Req.WndX, ctx->Req.WndY, ctx->Req.WndWidth, ctx->Req.WndHeight);
  276. ctx->Answer(ErrorCode);
  277. }
  278. void SalesRecordServiceSession::Handle_StartRemoteRecord(SpReqAnsContext<SalesRecorderSerVice_StartRemoteRecord_Req, SalesRecorderSerVice_StartRemoteRecord_Ans>::Pointer ctx)
  279. {
  280. ErrorCodeEnum ErrorCode = m_pEntity->HandleStartRecord(ctx->Req.VideoName.GetData(), true);
  281. ctx->Answer(ErrorCode);
  282. }
  283. CServerSessionBase * CSalesRecorderEntity::OnNewSession( const char* pszRemoteEntityName, const char * pszClass )
  284. {
  285. LOG_FUNCTION();
  286. LOG_TRACE("%s connected class = %s!", pszRemoteEntityName, pszClass);
  287. return new SalesRecordServiceSession(this);
  288. }
  289. void CSalesRecorderEntity::OnPreStart( CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext )
  290. {
  291. ErrorCodeEnum Error = __OnStart(Error_Succeed);
  292. pTransactionContext->SendAnswer(Error);
  293. }
  294. ErrorCodeEnum CSalesRecorderEntity::__OnStart( ErrorCodeEnum preOperationError )
  295. {
  296. LOG_FUNCTION();
  297. //MessageBoxA(0,0,0,0);
  298. m_eDeviceType = eStand2sType;
  299. m_nSysCallType = 0;
  300. //is Pad Version
  301. m_bNeedRestart = false;
  302. m_eAudioOutQuality = eUltraHD;
  303. m_bIsAudioNsOn = false;
  304. m_iAudioNsPolicy = 2;
  305. #ifdef RVC_OS_WIN
  306. if (SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS)){
  307. Dbg("Set Process(%d) RealTime Priority Success.",GetCurrentProcessId());
  308. }
  309. #endif
  310. m_eDeviceType = RvcGetDeviceType();
  311. int iAudioQuality = 3;
  312. int iAudioNsPolicy = 2;
  313. int iIsAudioNsOn = 0;
  314. m_max_disk_percent = MAX_DISK_PERCENT; // add by ly 2018/02/24
  315. CSmartPointer<IConfigInfo> spConfig;
  316. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  317. if (spFunction->OpenConfig(Config_CenterSetting, spConfig) == Error_Succeed)
  318. {
  319. spConfig->ReadConfigValueInt("SalesRecorder","MaxDiskPercent",m_max_disk_percent);
  320. spConfig->ReadConfigValueInt("SalesRecorder","AudioSampleRate",m_audio_samplerate);
  321. spConfig->ReadConfigValueInt("SalesRecorder","AudioBitRate",m_audio_out_bitrate);
  322. spConfig->ReadConfigValueInt("SalesRecorder","WholeSection",m_bWholeSection);
  323. spConfig->ReadConfigValueInt("SalesRecorder","ApplyHighQuality",m_bApplyHighQuality);
  324. spConfig->ReadConfigValueInt("SalesRecorder","AudioNsPolicy",iAudioNsPolicy);
  325. spConfig->ReadConfigValueInt("SalesRecorder","IsAudioNsOn",iIsAudioNsOn);
  326. spConfig->ReadConfigValueInt("SalesRecorder","AudioQuality",iAudioQuality);
  327. }
  328. if (m_max_disk_percent <= 0 || m_max_disk_percent >= 100)
  329. {
  330. m_max_disk_percent = MAX_DISK_PERCENT;
  331. }
  332. SetRecordAudioQuality(iAudioQuality);
  333. SetRecordAudioNsPolicy(iAudioNsPolicy);
  334. if (0 != iIsAudioNsOn){
  335. m_bIsAudioNsOn = true;
  336. }
  337. if (m_bWholeSection != 0 && m_bWholeSection != 1)
  338. {
  339. m_bWholeSection = FALSE;
  340. }
  341. if (m_bApplyHighQuality != 0 && m_bApplyHighQuality != 1)
  342. {
  343. m_bApplyHighQuality = FALSE;
  344. }
  345. Dbg("[dbg] m_bApplyHighQuality:%d",m_bApplyHighQuality);
  346. m_bEwsRecord = FALSE;
  347. if (preOperationError != Error_Succeed)
  348. return preOperationError;
  349. ErrorCodeEnum Error = Error_Succeed;
  350. m_iActiveCamera = CAMERA_TYPE_ENV;
  351. m_iCameraState = 'N';
  352. int i = 0;
  353. if (ePadtype == m_eDeviceType||eMobilePadType == m_eDeviceType||eDesk2SType == m_eDeviceType||eDesk1SType == m_eDeviceType||eDesk2SIntegratedType == m_eDeviceType)
  354. {
  355. // add by ly(edit by ly 2018/03/12)
  356. #ifdef RVC_OS_WIN
  357. m_pPlayer = new Clibwmpplayer(this);
  358. #else
  359. //m_pPlayer = new Clibmediaplayer(this);
  360. #endif // RVC_OS_WIN
  361. m_arrListener.Init(9);
  362. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STARTRECORD, NULL, false);
  363. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STARTAFTERPREVIEWRECORD, NULL, false);
  364. //GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STOPRECORD, NULL, false);
  365. //GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_SHOWVIDEO, NULL, false);
  366. //GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_SAVEVIDEO, NULL, false);
  367. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_DELETEVIDEO, NULL, false);
  368. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_RETURNMENU, NULL, false);
  369. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_UKEY_PULLOUT, NULL, false);
  370. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_VIDEOAPPENDWATERMARK, NULL, false);
  371. //GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STARTREMOTERECORD, NULL, false);
  372. //GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STOPREMOTERECORD, NULL, false);
  373. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_High, Error_IgnoreAll, LOG_EVT_SALESRECORD_ENTITY_EXCEPTION, NULL, false);
  374. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_High, Error_IgnoreAll, LOG_EVT_AUDIOSTREAM_TRANSMISSION_FAILED, NULL, false);
  375. }
  376. else
  377. {
  378. // add by ly @2018/01/10
  379. #ifdef RVC_OS_WIN
  380. m_pPlayer = new Clibwmpplayer(this);
  381. #else
  382. //m_pPlayer = new Clibmediaplayer(this);
  383. #endif // RVC_OS_WIN
  384. m_arrListener.Init(8);
  385. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STARTRECORD, NULL, false);
  386. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STARTAFTERPREVIEWRECORD, NULL, false);
  387. //GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STOPRECORD, NULL, false);
  388. //GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_SHOWVIDEO, NULL, false);
  389. //GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_SAVEVIDEO, NULL, false);
  390. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_DELETEVIDEO, NULL, false);
  391. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_RETURNMENU, NULL, false);
  392. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_VIDEOAPPENDWATERMARK, NULL, false);
  393. //GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STARTREMOTERECORD, NULL, false);
  394. //GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STOPREMOTERECORD, NULL, false);
  395. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_High, Error_IgnoreAll, LOG_EVT_SALESRECORD_ENTITY_EXCEPTION, NULL, false);
  396. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_High, Error_IgnoreAll, LOG_EVT_AUDIOSTREAM_TRANSMISSION_FAILED, NULL, false);
  397. }
  398. GetFunction()->RegistSysVarEvent(SYSVAR_ACTIVETRACKINGCAMERA,this);
  399. GetFunction()->RegistSysVarEvent(SYSVAR_CAMERASTATE,this);
  400. CSimpleStringA strValue;
  401. GetFunction()->GetSysVar(SYSVAR_CAMERASTATE, strValue);
  402. m_iCameraState = strValue[0];
  403. if (strValue[0] == 'E')
  404. {
  405. m_iActiveCamera = CAMERA_TYPE_OPT;
  406. }
  407. else if (strValue[0] == 'O')
  408. {
  409. m_iActiveCamera = CAMERA_TYPE_ENV;
  410. }
  411. else if(strValue[0] == 'B') ///////显示贴图
  412. {
  413. m_iActiveCamera = CAMERA_TYPE_ERROR;
  414. }
  415. else if (strValue[0] == 'N')
  416. {
  417. m_iActiveCamera = CAMERA_TYPE_ENV;
  418. }
  419. GetFunction()->RegistSysVarEvent(SYSVAR_CALLTYPE, this);
  420. GetFunction()->GetSysVar(SYSVAR_CALLTYPE, strValue);
  421. if (strValue[0] == CALLTYPE_NORMAL)
  422. {
  423. m_nSysCallType = 0;
  424. }
  425. else if (strValue[0] == CALLTYPE_MOBILE)
  426. {
  427. m_nSysCallType = 1;
  428. }
  429. else
  430. {
  431. assert(0);
  432. }
  433. Error = GetFunction()->RegistSysVarEvent("SessionID", this);
  434. if (Error != Error_Succeed)
  435. {
  436. LOG_TRACE("register sysvar %s failed!", "SessionID");
  437. }
  438. // add by ly 2018/02/13
  439. Error = GetFunction()->GetPath("Temp", m_TempDir);
  440. if (Error != Error_Succeed) {
  441. LOG_TRACE("get global record temp path failed!");
  442. }
  443. if (m_TempDir.GetLength() > 0 && m_TempDir[m_TempDir.GetLength()-1] != SPLIT_SLASH) {
  444. m_TempDir += SPLIT_SLASH_STR;
  445. }
  446. Error = GetFunction()->GetPath("UploadVideo", m_RecordSaveDir);
  447. if (Error != Error_Succeed) {
  448. LOG_TRACE("get global record save path failed!");
  449. }
  450. if (m_RecordSaveDir.GetLength() > 0 && m_RecordSaveDir[m_RecordSaveDir.GetLength()-1] != SPLIT_SLASH) {
  451. m_RecordSaveDir += SPLIT_SLASH_STR;
  452. }
  453. return Error;
  454. }
  455. void CSalesRecorderEntity::OnStarted()
  456. {
  457. InitSalesRecorder();
  458. }
  459. void CSalesRecorderEntity::OnPreClose( EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext )
  460. {
  461. ErrorCodeEnum Error = __OnClose(Error_Succeed);
  462. pTransactionContext->SendAnswer(Error);
  463. }
  464. ErrorCodeEnum CSalesRecorderEntity::__OnClose( ErrorCodeEnum preOperationError )
  465. {
  466. LOG_FUNCTION();
  467. if (preOperationError != Error_Succeed)
  468. return preOperationError;
  469. //delete m_pPlayer; m_pPlayer = NULL;
  470. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  471. for (int i = 0; i < m_arrListener.GetCount(); ++i)
  472. {
  473. spFunction->UnsubscribeLog(m_arrListener[i]);
  474. }
  475. GetFunction()->UnregistSysVarEvent(SYSVAR_ACTIVETRACKINGCAMERA);
  476. GetFunction()->UnregistSysVarEvent(SYSVAR_CAMERASTATE);
  477. StopRecord();
  478. ReleaseSalesRecorder();
  479. return Error_Succeed;
  480. }
  481. void CSalesRecorderEntity::OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
  482. {
  483. if (Test_ShakeHand == eTestType)
  484. {
  485. if (m_bNeedRestart){
  486. Dbg("[OnSelfTest] entity need restart now.");
  487. pTransactionContext->SendAnswer(Error_Unexpect);
  488. }
  489. else{
  490. pTransactionContext->SendAnswer(Error_Succeed);
  491. }
  492. }
  493. }
  494. int CSalesRecorderEntity::GetActiveCamera()
  495. {
  496. //Debug("get active camera = %d", m_iActiveCamera);
  497. return m_iActiveCamera;
  498. }
  499. int CSalesRecorderEntity::GetCameraState()
  500. {
  501. //Debug("get active camera = %d", m_iCameraState);
  502. return m_iCameraState;
  503. }
  504. void CSalesRecorderEntity::OnRecordFailed(const char* pszMessage, bool bRecordDevFault )
  505. {
  506. Dbg("OnSalesRecordFailed!");
  507. if (!bRecordDevFault)
  508. {
  509. LogEvent(Severity_Middle,LOG_EVT_UI_RECORDFAILED,"0");
  510. }
  511. else
  512. {
  513. LogEvent(Severity_Middle,LOG_EVT_UI_RECORDFAILED,"1");
  514. }
  515. char strmsg[MAX_PATH] = { 0 };
  516. snprintf(strmsg, MAX_PATH, "{%s}.", pszMessage ? pszMessage : " ");
  517. LogWarn(Severity_Low, Error_Debug, LOG_EVT_SALESRECORD_FAILED, strmsg);
  518. }
  519. void CSalesRecorderEntity::OnRecordEntityExcption()
  520. {
  521. LogEvent(Severity_High,LOG_EVT_SALESRECORD_ENTITY_EXCEPTION,"现场销售双录出现异常,请稍候重录,系统正在恢复中,预计60秒!");
  522. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORD_ENTITY_EXCEPTION, "sales record entity exception!");
  523. }
  524. void CSalesRecorderEntity::OnRecordFinished()
  525. {
  526. LogEvent(Severity_High, LOG_EVT_SALESRECORD_FINISHED, "现场销售双录已完成.");
  527. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORD_FINISHED, "现场销售双录已完成.");
  528. }
  529. void CSalesRecorderEntity::Debug(record_loglevel elevel, const char* fmt, ...)
  530. {
  531. if (RECORD_LOG_INFO <= elevel) {
  532. va_list arg;
  533. va_start(arg, fmt);
  534. vDbg(fmt, arg);
  535. va_end(arg);
  536. }
  537. }
  538. void CSalesRecorderEntity::vDebug(record_loglevel elevel, const char* str, va_list list)
  539. {
  540. if (RECORD_LOG_INFO <= elevel) {
  541. vDbg(str, list);
  542. }
  543. }
  544. #ifdef RVC_OS_WIN
  545. void CSalesRecorderEntity::WmpDebug( const char *fmt, ... )
  546. {
  547. va_list arg;
  548. va_start(arg, fmt);
  549. vDbg(fmt, arg);
  550. va_end(arg);
  551. }
  552. #else
  553. void CSalesRecorderEntity::Debug(media_loglevel log_level, const char* fmt, ...)
  554. {
  555. if (log_level >= MEDIA_LOG_ERROR) {
  556. va_list arg;
  557. va_start(arg, fmt);
  558. vDbg(fmt, arg);
  559. va_end(arg);
  560. }
  561. }
  562. #endif // RVC_OS_WIN
  563. // 定时任务:扫描是否有待提交的离线双录记录 add by ly @2018/02/08
  564. void CSalesRecorderEntity::OnTimeout( DWORD dwTimerID )
  565. {
  566. }
  567. void CSalesRecorderEntity::OnSysVarEvent( const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName )
  568. {
  569. if (_stricmp(pszKey, SYSVAR_CAMERASTATE) == 0)
  570. {
  571. Dbg("camera state from : %c to %c", pszOldValue[0], pszValue[0]);
  572. m_iCameraState = pszValue[0];
  573. if (pszValue[0] == 'E')
  574. {
  575. m_iActiveCamera = CAMERA_TYPE_OPT;
  576. }
  577. else if (pszValue[0] == 'O')
  578. {
  579. m_iActiveCamera = CAMERA_TYPE_ENV;
  580. }
  581. else if(pszValue[0] == 'B') ///////显示贴图
  582. {
  583. m_iActiveCamera = CAMERA_TYPE_ERROR;
  584. }
  585. else if (pszValue[0] == 'N')
  586. {
  587. m_iActiveCamera = CAMERA_TYPE_AUTO;
  588. }
  589. }
  590. else if (_stricmp(pszKey, SYSVAR_ACTIVETRACKINGCAMERA) == 0)
  591. {
  592. if (m_iCameraState == 'N')
  593. {
  594. if (pszValue[0] == 'E')
  595. {
  596. m_iActiveCamera = CAMERA_TYPE_ENV;
  597. }
  598. else if (pszValue[0] == 'O')
  599. {
  600. m_iActiveCamera = CAMERA_TYPE_OPT;
  601. }
  602. }
  603. }
  604. else if (_stricmp(pszKey, SYSVAR_CALLTYPE) == 0)
  605. {
  606. Dbg("sys calltype from: %c to %c", pszOldValue[0], pszValue[0]);
  607. if(pszValue[0] == CALLTYPE_NORMAL)
  608. {
  609. m_nSysCallType = 0;
  610. }
  611. else if(pszValue[0] == CALLTYPE_MOBILE)
  612. {
  613. m_nSysCallType = 1;
  614. }
  615. else
  616. {
  617. m_nSysCallType = -1;
  618. }
  619. }
  620. }
  621. void CSalesRecorderEntity::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, const linkContext& pLinkInfo)
  622. {
  623. // 响应客户经理销售录像相关的事件
  624. switch (dwUserCode)
  625. {
  626. case LOG_EVT_UI_STARTRECORD:
  627. case LOG_EVT_UI_STARTAFTERPREVIEWRECORD:
  628. Dbg("start record, pszMessage = %s.",pszMessage);
  629. HandleStartRecord(pszMessage, false);
  630. break;
  631. case LOG_EVT_UI_STOPREMOTERECORD:
  632. Dbg("stop remote record, pszMessage = %s.",pszMessage);
  633. StopRecord();
  634. LogWarn(Severity_Low, Error_Debug, LOG_EVT_STOP_REMOTERECORD, "stop remote record.");
  635. break;
  636. case LOG_EVT_UI_STOPRECORD:
  637. Dbg("stop record, pszMessage = %s.",pszMessage);
  638. HandleStopRecord(pszMessage);
  639. break;
  640. case LOG_EVT_UI_SHOWVIDEO:
  641. Dbg("show video record, pszMessage = %s.",pszMessage);
  642. HandleDisplayVideo();
  643. break;
  644. case LOG_EVT_UI_SAVEVIDEO:
  645. Dbg("save record!");
  646. HandleSaveVideo();
  647. break;
  648. case LOG_EVT_UI_DELETEVIDEO:
  649. Dbg("delete record!");
  650. HandleDeleteVideo();
  651. break;
  652. case LOG_EVT_UI_RETURNMENU:
  653. break;
  654. case EVENT_UKEY_PULLOUT:
  655. Dbg("ukey pull out!");
  656. break;
  657. case LOG_EVT_UI_VIDEOAPPENDWATERMARK:
  658. Dbg("handle video append water mark param is %s.", pszMessage);
  659. HandleVideoAppendWatermark(pszMessage);
  660. break;
  661. case LOG_EVT_SALESRECORD_ENTITY_EXCEPTION:
  662. Dbg("handle sales record entity exception, and message is %s.", pszMessage);
  663. HandleSalesRecordEntityException(pszMessage);
  664. break;
  665. case LOG_EVT_AUDIOSTREAM_TRANSMISSION_FAILED:
  666. Dbg("handle audio stream transmission failed.");
  667. break;
  668. default:
  669. break;
  670. }
  671. }
  672. // we use root.ini Video section config to decide camera count
  673. ErrorCodeEnum CSalesRecorderEntity::DecideCameraCount( int &nCount )
  674. {
  675. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  676. CSmartPointer<IConfigInfo> spConfig;
  677. ErrorCodeEnum Error = spFunction->OpenConfig(Config_Root, spConfig);
  678. if (Error == Error_Succeed) {
  679. CSimpleStringA strVideoEnv;
  680. CSimpleStringA strVideoOpt;
  681. SpIniMappingTable table;
  682. nCount = 0;
  683. table.AddEntryString("Video", "EnvCamera", strVideoEnv, "$");
  684. table.AddEntryString("Video", "OptCamera", strVideoOpt, "$");
  685. Error = table.Load(spConfig);
  686. if (Error == Error_Succeed) {
  687. if (strVideoEnv.GetLength() > 1)
  688. nCount++;
  689. if (strVideoOpt.GetLength() > 1)
  690. nCount++;
  691. }
  692. }
  693. return Error;
  694. }
  695. BOOL CSalesRecorderEntity::GetStandardQualityOnSiteSalesRecorder()
  696. {
  697. BOOL bRet = FALSE;
  698. m_pRecorder = new Clibwmvrecord(&bRet, this, REC_COMMON_AUDIO_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE,
  699. REC_COMMON_VIDEO_OPT_SHM_SNAPSHOT_QUEUE, REC_COMMON_AUDIO_SALES_SHM_QUEUE, REC_COMMON_VIDEO_REMOTE_SHM_RTP_QUEUE, REC_COMMON_REMOTEAUDIO_SHM_QUEUE);
  700. return bRet;
  701. }
  702. BOOL CSalesRecorderEntity::GetHighQualityOnSiteSalesRecorder()
  703. {
  704. BOOL bRet = FALSE;
  705. m_pRecorder = new Clibwmvrecord(&bRet, this, REC_COMMON_AUDIO_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE,
  706. REC_COMMON_VIDEO_OPT_SHM_SNAPSHOT_QUEUE, REC_COMMON_AUDIO_SALES_SHM_QUEUE, REC_COMMON_VIDEO_REMOTE_SHM_RTP_QUEUE, REC_COMMON_REMOTEAUDIO_SHM_QUEUE);
  707. return bRet;
  708. }
  709. void CSalesRecorderEntity::StartOnSiteSalesRecord(const int fps, const char* wmvfilename, int videoquality, int audioOutBitRate, SubtitleParam* subtitleParam, BOOL bWholeSection, BOOL bSessionManage, eRvcRecordType eRecordType)
  710. {
  711. Rvc_RecordAudioParam_t tAudioParams;
  712. tAudioParams.eRecordType = eRecordType;
  713. tAudioParams.eOutPutType = m_eAudioOutQuality;
  714. tAudioParams.bIsNsOn = m_bIsAudioNsOn;
  715. tAudioParams.iNsPolicy = m_iAudioNsPolicy;
  716. tAudioParams.iAudioOutBitRate = audioOutBitRate;
  717. if (eStand2Agent == eRecordType || ePad2Agent == eRecordType) {
  718. tAudioParams.eOutPutType = eLowDefinition;
  719. tAudioParams.bIsNsOn = false;
  720. }
  721. Dbg("init lib wmv record success! and record type is %s and output audio quality is %s, audio noise suppression flag is %s. noise suppression policy is %d.", record_type_table[eRecordType], audio_quality_type_table[m_eAudioOutQuality], tAudioParams.bIsNsOn ? "true" : "false", tAudioParams.iNsPolicy);
  722. if (m_pRecorder->StartWmvRecord(fps, videoquality, &tAudioParams, subtitleParam, bWholeSection, FALSE, (LPCSTR)m_TempDir,
  723. m_TempDir.GetLength(), wmvfilename, strlen(wmvfilename)))
  724. {
  725. m_bStarted = TRUE;
  726. Dbg("Start WmvRecord success!");
  727. }
  728. else {
  729. Dbg("Start WmvRecord failed!");
  730. }
  731. }
  732. void CSalesRecorderEntity::StartRecord(const char *wmvfilename, int videoquality, int audioOutBitRate, SubtitleParam *subtitleParam /* = NULL */, BOOL bWholeSection /* = FALSE */, BOOL bSessionManage /* = FALSE */, eRvcRecordType eRecordType /* = eSingleSide */)
  733. {
  734. Dbg("wmvfilename = %s", wmvfilename);
  735. StartOnSiteSalesRecord(10, wmvfilename, videoquality, audioOutBitRate, subtitleParam, bWholeSection, bSessionManage, eRecordType);
  736. }
  737. ErrorCodeEnum CSalesRecorderEntity::StopRecord()
  738. {
  739. ErrorCodeEnum eCode = Error_Succeed;
  740. if (m_bStarted)
  741. {
  742. m_pRecorder->StopWmvRecord();
  743. m_bStarted = FALSE;
  744. }
  745. else{
  746. eCode = Error_InvalidState;
  747. }
  748. return eCode;
  749. }
  750. ErrorCodeEnum CSalesRecorderEntity::ShowVideo( const char *wmvfilename )
  751. {
  752. ErrorCodeEnum ErrorCode = Error_Succeed;
  753. if(!m_bStarted)
  754. {
  755. CSimpleStringA strPath;
  756. ErrorCodeEnum Error = GetFunction()->GetPath("Temp", strPath);
  757. if (Error == Error_Succeed) {
  758. if (strPath.GetLength() > 0 && strPath[strPath.GetLength()-1] != SPLIT_SLASH) {
  759. strPath += SPLIT_SLASH_STR;
  760. }
  761. CSimpleStringA strFindFileName = CSimpleStringA::Format("%s*.%s", wmvfilename, RVC_RECORD_SUFFIX);
  762. ULONGLONG uVideoCount = 0;
  763. BOOL bRet = FindMatchedFile((LPCSTR)strPath, (LPCTSTR)strFindFileName, uVideoCount);
  764. Dbg("bRet = %d while find %s", bRet, wmvfilename);
  765. if(bRet){
  766. Dbg("succeed to get record count while play video!");
  767. //Dbg("m_pPlayer = %p while play!", m_pPlayer);
  768. //m_pPlayer->PlayVideo((LPCSTR)strPath, wmvfilename, uVideoCount);
  769. Dbg("succeed to play video!");
  770. }
  771. else{
  772. ErrorCode = Error_NotExist;
  773. Dbg("play video failed for %s no exist!", wmvfilename);
  774. }
  775. }
  776. }
  777. else{
  778. ErrorCode = Error_NotImpl;
  779. }
  780. return ErrorCode;
  781. }
  782. ErrorCodeEnum CSalesRecorderEntity::PlaySalesRecordVideo( const char *wmvfilename, int iWndX, int iWndY, int iWndWidth, int iWndHeight)
  783. {
  784. ErrorCodeEnum ErrorCode = Error_Succeed;
  785. if(!m_bStarted)
  786. {
  787. CSimpleStringA strPath;
  788. ErrorCodeEnum Error = GetFunction()->GetPath("Temp", strPath);
  789. if (Error == Error_Succeed) {
  790. if (strPath.GetLength() > 0 && strPath[strPath.GetLength()-1] != SPLIT_SLASH) {
  791. strPath += SPLIT_SLASH_STR;
  792. }
  793. CSimpleStringA strFindFileName = CSimpleStringA::Format("%s*.%s", wmvfilename, RVC_RECORD_SUFFIX);
  794. ULONGLONG uVideoCount = 0;
  795. BOOL bRet = FindMatchedFile((LPCSTR)strPath, (LPCTSTR)strFindFileName, uVideoCount);
  796. Dbg("bRet = %d while find %s", bRet, wmvfilename);
  797. if(bRet){
  798. Dbg("succeed to get record count while play sales record video!");
  799. //Dbg("m_pPlayer = %p while play!", m_pPlayer);
  800. //m_pPlayer->PlaySalesRecordVideo(iWndX, iWndY, iWndWidth, iWndHeight,(LPCSTR)strPath, wmvfilename, uVideoCount);
  801. Dbg("succeed to play sales record video!");
  802. }
  803. else{
  804. ErrorCode = Error_NotExist;
  805. Dbg("play play sales record video failed for %s no exist!", wmvfilename);
  806. }
  807. }
  808. }
  809. else{
  810. ErrorCode = Error_NotImpl;
  811. }
  812. return ErrorCode;
  813. }
  814. void CSalesRecorderEntity::DeleteVideo( const char *wmvfilename )
  815. {
  816. if(!m_bStarted)
  817. {
  818. CSimpleStringA strPath;
  819. ErrorCodeEnum Error = GetFunction()->GetPath("Temp", strPath);
  820. if (Error == Error_Succeed) {
  821. if (strPath.GetLength() > 0 && strPath[strPath.GetLength()-1] != SPLIT_SLASH) {
  822. strPath += SPLIT_SLASH_STR;
  823. }
  824. CSimpleStringA strFindFileName = CSimpleStringA::Format("%s*.%s", wmvfilename, RVC_RECORD_SUFFIX);
  825. ULONGLONG uVideoCount = 0;
  826. BOOL bRet = FindMatchedFile((LPCSTR)strPath, (LPCTSTR)strFindFileName, uVideoCount);
  827. if(bRet)
  828. {
  829. Dbg("succeed to get record count while delete video!");
  830. CSimpleStringA fileName;
  831. BOOL bDeleteSucc = TRUE;
  832. for(int i = 0; i != uVideoCount; ++i)
  833. {
  834. fileName = CSimpleStringA::Format("%s%s_%d.%s", (LPCSTR)strPath, wmvfilename, i, RVC_RECORD_SUFFIX);
  835. if(remove(fileName.GetData())) {
  836. bDeleteSucc = FALSE;
  837. Dbg("Error Code %lu while delete %s ", errno, fileName.GetData());
  838. }
  839. }
  840. if (bDeleteSucc) {
  841. Dbg("succeed to delete videos!");
  842. }
  843. }
  844. else
  845. {
  846. Dbg("[DeleteVideo] videos not exist or have been deleted!");
  847. }
  848. }
  849. }
  850. }
  851. /*
  852. SaveVideo包含两步,找到录像和移动录像
  853. Error_Succeed 提交上传成功
  854. Error_NotExist not exist
  855. Error_NotImpl 方法执行失败
  856. */
  857. ErrorCodeEnum CSalesRecorderEntity::SaveVideo( const char *wmvfilename )
  858. {
  859. ErrorCodeEnum ErrorCode = Error_Succeed;
  860. if(!m_bStarted)
  861. {
  862. CSimpleStringA sourPath;
  863. ErrorCodeEnum Error = GetFunction()->GetPath("Temp", sourPath);
  864. if(Error == Error_Succeed)
  865. {
  866. if (sourPath.GetLength() > 0 && sourPath[sourPath.GetLength()-1] != SPLIT_SLASH) {
  867. sourPath += SPLIT_SLASH_STR;
  868. }
  869. ULONGLONG uVideoCount = 0;
  870. // 移动销售录像 edit by ly 2018/03/05
  871. CSimpleStringA strFindFileName = CSimpleStringA::Format("S_%s*.%s", wmvfilename, RVC_RECORD_SUFFIX);
  872. BOOL bRet = FindMatchedFile((LPCSTR)sourPath, (LPCSTR)strFindFileName, uVideoCount);
  873. if(bRet)
  874. {
  875. strFindFileName = strFindFileName.SubString(0,strFindFileName.GetLength()-5);
  876. Dbg("succeed to get sales record count while save video!");
  877. CSimpleStringA destPath;
  878. Error = GetFunction()->GetPath("UploadVideo", destPath);
  879. if(Error == Error_Succeed)
  880. {
  881. if (destPath.GetLength() > 0 && destPath[destPath.GetLength()-1] != SPLIT_SLASH) {
  882. destPath += SPLIT_SLASH_STR;
  883. }
  884. CSimpleStringA sourFileName, destFileName;
  885. BOOL bMoveSucc = TRUE;
  886. Dbg("strFindFileName=%s", (LPCSTR)strFindFileName);
  887. for(int i = 0; i != uVideoCount; ++i)
  888. {
  889. sourFileName = CSimpleStringA::Format("%s%s_%d.%s", (LPCSTR)sourPath, (LPCSTR)strFindFileName, i, RVC_RECORD_SUFFIX);
  890. destFileName = CSimpleStringA::Format("%s%s_%d.%s", (LPCSTR)destPath, (LPCSTR)strFindFileName, i, RVC_RECORD_SUFFIX);
  891. if(rename(sourFileName.GetData(), destFileName.GetData())) {
  892. bMoveSucc = FALSE;
  893. ErrorCode = Error_NotImpl;
  894. char strinfo[MAX_PATH] = { 0 };
  895. _snprintf(strinfo, MAX_PATH, "Error Code %lu while move %s.", errno, (LPCSTR)sourFileName);
  896. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORD_SAVED_FAILED, strinfo);
  897. }
  898. }
  899. if (bMoveSucc) {
  900. char strmsg[MAX_PATH] = { 0 };
  901. snprintf(strmsg, MAX_PATH, "succeed to save sales video, move it from %s to %s.", sourFileName.GetData(), destFileName.GetData());
  902. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORD_SAVED_SUCCESS, strmsg);
  903. }
  904. }
  905. }
  906. else
  907. {
  908. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORD_SAVED_FAILED, "sales videos not exist or have been deleted");
  909. ErrorCode = Error_NotExist;
  910. }
  911. // 移动见证录像
  912. uVideoCount = 0;
  913. strFindFileName = CSimpleStringA::Format("W_%s*.%s", wmvfilename, RVC_RECORD_SUFFIX);
  914. bRet = FindMatchedFile((LPCSTR)sourPath, (LPCSTR)strFindFileName, uVideoCount);
  915. if(bRet)
  916. {
  917. strFindFileName = strFindFileName.SubString(0,strFindFileName.GetLength()-5);
  918. Dbg("succeed to get witness record count while save video!");
  919. CSimpleStringA destPath;
  920. Error = GetFunction()->GetPath("UploadVideo", destPath);
  921. if(Error == Error_Succeed)
  922. {
  923. if (destPath.GetLength() > 0 && destPath[destPath.GetLength()-1] != SPLIT_SLASH) {
  924. destPath += SPLIT_SLASH_STR;
  925. }
  926. CSimpleStringA sourFileName, destFileName;
  927. BOOL bMoveSucc = TRUE;
  928. Dbg("uVideoCount=%d", uVideoCount);
  929. for(int i = 0; i != uVideoCount; ++i)
  930. {
  931. sourFileName = CSimpleStringA::Format("%s%s_%d.%s", (LPCSTR)sourPath, (LPCSTR)strFindFileName, i, RVC_RECORD_SUFFIX);
  932. destFileName = CSimpleStringA::Format("%s%s_%d.%s", (LPCSTR)destPath, (LPCSTR)strFindFileName, i, RVC_RECORD_SUFFIX);
  933. if(rename(sourFileName.GetData(), destFileName.GetData())) {
  934. bMoveSucc = FALSE;
  935. Dbg("Error Code %lu while move %s ", errno, (LPCSTR)sourFileName);
  936. }
  937. }
  938. if (bMoveSucc) {
  939. Dbg("succeed to save witness video!");
  940. ErrorCode = Error_Succeed;
  941. }
  942. }
  943. }
  944. else
  945. {
  946. Dbg("witness videos not exist or have been deleted!");
  947. }
  948. }
  949. }
  950. else{
  951. ErrorCode = Error_NotImpl;
  952. }
  953. return ErrorCode;
  954. }
  955. CSimpleStringA CSalesRecorderEntity::GetTerminalStage()
  956. {
  957. CSmartPointer<IEntityFunction> Func = GetFunction();
  958. CSimpleStringA strValue = "";
  959. Func->GetSysVar("TerminalStage", strValue);
  960. Dbg("TerminalStage:%s", (LPCTSTR)strValue);
  961. return strValue;
  962. }
  963. bool CSalesRecorderEntity::SecureClientConnect()
  964. {
  965. SecureClientRelease();
  966. return true;
  967. }
  968. void CSalesRecorderEntity::SecureClientRelease()
  969. {
  970. }
  971. // 请求InteractiveControl结束录像 add by ly 2018/03/12
  972. ErrorCodeEnum CSalesRecorderEntity::StopRecordVideo()
  973. {
  974. auto rc = Error_Succeed;
  975. auto pUIClient = new InteractiveControl::UIService_ClientBase(this);
  976. if(pUIClient->Connect() != Error_Succeed)
  977. {
  978. pUIClient->SafeDelete();
  979. pUIClient = NULL;
  980. rc = Error_DevConnFailed;
  981. }
  982. else
  983. {
  984. Dbg("UIClient connected success!");
  985. InteractiveControl::UIService_StopRecordVideo_Req req;
  986. InteractiveControl::UIService_StopRecordVideo_Ans ans;
  987. rc = pUIClient->StopRecordVideo(req, ans, 5000);
  988. if(rc != Error_Succeed)
  989. {
  990. Dbg("Stop record video failed return 0x%08x", rc);
  991. }
  992. pUIClient->GetFunction()->CloseSession();
  993. pUIClient = NULL;
  994. }
  995. return rc;
  996. }
  997. ErrorCodeEnum CSalesRecorderEntity::HandleStartRecord(const char *pszMessage, const bool bRemoteRecord)
  998. {
  999. ErrorCodeEnum Error = Error_Succeed;
  1000. eRvcRecordType eRecordType = eSingleSide;
  1001. if (NULL == pszMessage){
  1002. return Error_Param;
  1003. }
  1004. size_t ulen = strlen(pszMessage);
  1005. char *tmp = new char[ulen+1];
  1006. m_bEwsRecord = FALSE;
  1007. if ((false == bRemoteRecord) && (ulen >= EWS_CAMERA_FLAG_LEN) && (0 == strnicmp(pszMessage,EWS_CAMERA_FLAG,EWS_CAMERA_FLAG_LEN)))
  1008. {
  1009. m_bEwsRecord = TRUE;
  1010. strncpy(tmp, pszMessage+EWS_CAMERA_FLAG_LEN, ulen-EWS_CAMERA_FLAG_LEN);
  1011. }
  1012. else{
  1013. strncpy(tmp, pszMessage, ulen);
  1014. }
  1015. char *result[32] = {0};
  1016. CStringSplit(tmp, result, "@");
  1017. memset(m_SalesVideoName, 0, MAX_PATH);
  1018. if (result[4]) {
  1019. snprintf(m_SalesVideoName, MAX_PATH, "%s", result[4]);//录像名:录像类型标志_录像流水号(如S_C13213EF)
  1020. }
  1021. RecordSubTitle subTitle;
  1022. ZeroMemory(&subTitle,sizeof(RecordSubTitle));
  1023. if (result[5]) {
  1024. CSimpleStringA strCardNo = DecryptString(result[5]);
  1025. if (sizeof(subTitle.CustCardNo) > strCardNo.GetLength()) {
  1026. strcpy_s(subTitle.CustCardNo, 24, strCardNo.GetData());
  1027. }
  1028. else {
  1029. Dbg("Invalid CustCardNo.");
  1030. }
  1031. }
  1032. char* pStr = result[6];
  1033. if (pStr) {
  1034. CSimpleStringW szCustName = CSimpleStringA2W(pStr);
  1035. if (szCustName.GetLength() <= 4) {
  1036. strcpy(subTitle.CustName, pStr);
  1037. }
  1038. else {
  1039. CSimpleStringW aa = szCustName.SubString(0, 4);
  1040. sprintf(subTitle.CustName, "%s...", (LPCTSTR)CSimpleStringW2A(aa));
  1041. }
  1042. }
  1043. pStr = result[7];
  1044. if (pStr) {
  1045. int nProductCodeLen = strlen(pStr);
  1046. if (nProductCodeLen <= 10) {
  1047. strcpy(subTitle.ProductCode, pStr);
  1048. }
  1049. else {
  1050. char aa[5] = { 0 }, bb[5] = { 0 };
  1051. strncpy(aa, pStr, 4);
  1052. strncpy(bb, pStr + nProductCodeLen - 4, 4);
  1053. sprintf(subTitle.ProductCode, "%s...%s", aa, bb);
  1054. }
  1055. }
  1056. pStr = result[8];
  1057. if (pStr) {
  1058. CSimpleStringW szProductName = CSimpleStringA2W(pStr);
  1059. if (szProductName.GetLength() <= 5) {
  1060. strcpy(subTitle.ProductName, pStr);
  1061. }
  1062. else {
  1063. CSimpleStringW aa = szProductName.SubString(0, 3);
  1064. CSimpleStringW bb = szProductName.SubString(szProductName.GetLength() - 2, 2);
  1065. sprintf(subTitle.ProductName, "%s...%s", (LPCTSTR)CSimpleStringW2A(aa), (LPCTSTR)CSimpleStringW2A(bb));
  1066. }
  1067. }
  1068. if (result[9]) {
  1069. strcpy(subTitle.SapID, result[9]);
  1070. } else {
  1071. subTitle.SapID[0] = '\0';
  1072. }
  1073. if (result[10]) {
  1074. pStr = result[10];
  1075. CSimpleStringW szCustManagerName = CSimpleStringA2W(pStr);
  1076. if (szCustManagerName.GetLength() <= 4) {
  1077. strcpy(subTitle.CustManagerName, result[10]);
  1078. }
  1079. else {
  1080. CSimpleStringW aa = szCustManagerName.SubString(0,4);
  1081. sprintf(subTitle.CustManagerName,"%s...",(LPCTSTR)CSimpleStringW2A(aa));
  1082. }
  1083. } else {
  1084. subTitle.CustManagerName[0] = '\0';
  1085. }
  1086. delete[] tmp;
  1087. tmp = NULL;
  1088. SubtitleParam subtitleParam;
  1089. ZeroMemory(&subtitleParam,sizeof(SubtitleParam));
  1090. subtitleParam.bSubtitle = TRUE;
  1091. subtitleParam.bSubtitleSection = TRUE;
  1092. subtitleParam.topSubtitleData[0] = '\0';
  1093. if (strlen(subTitle.SapID)>0&&strlen(subTitle.CustManagerName)>0) // 有无客户经理的双录字幕 edit by ly @2018/01/10
  1094. {
  1095. swprintf(subtitleParam.bottomSubtitleData1, MAX_PATH, L"%s %s %s", subTitle.CustCardNo, subTitle.CustName, subTitle.ProductCode);
  1096. swprintf(subtitleParam.bottomSubtitleData2, MAX_PATH, L"%s %s %s", subTitle.ProductName, subTitle.SapID, subTitle.CustManagerName);
  1097. }
  1098. else
  1099. {
  1100. swprintf(subtitleParam.bottomSubtitleData1, MAX_PATH, L"%s %s", subTitle.CustCardNo, subTitle.CustName);
  1101. swprintf(subtitleParam.bottomSubtitleData2, MAX_PATH, L"%s %s", subTitle.ProductCode, subTitle.ProductName);
  1102. }
  1103. int i_audio_out_bitrate = m_audio_out_bitrate;
  1104. if (bRemoteRecord)
  1105. {
  1106. if (m_eDeviceType == eStand2sType) { //如果是大机
  1107. eRecordType = eStand2Agent; //可视柜台大机的双向录像
  1108. }
  1109. else{
  1110. eRecordType = ePad2Agent; //可视柜台pad的双向录像
  1111. }
  1112. if(256 == m_audio_out_bitrate){
  1113. i_audio_out_bitrate = 128;
  1114. Dbg("change remote record audio out bitrate to %d.", i_audio_out_bitrate);
  1115. }
  1116. }
  1117. StartRecord(m_SalesVideoName, 90, i_audio_out_bitrate, &subtitleParam, m_bWholeSection, FALSE, eRecordType);
  1118. char strmsg[MAX_PATH] = { 0 };
  1119. snprintf(strmsg, MAX_PATH, "start remote record %s.", m_SalesVideoName);
  1120. LogWarn(Severity_Low, Error_Debug, LOG_EVT_START_REMOTERECORD, strmsg);
  1121. return Error;
  1122. }
  1123. ErrorCodeEnum CSalesRecorderEntity::HandleStopRecord(const char *pszMessage)
  1124. {
  1125. ErrorCodeEnum ErrorCode = StopRecord();
  1126. return ErrorCode;
  1127. }
  1128. ErrorCodeEnum CSalesRecorderEntity::HandleDisplayVideo()
  1129. {
  1130. // 视频播放 libwmpplayer
  1131. m_bIsShowVideo = TRUE;
  1132. Dbg("play record file name is %s!", m_SalesVideoName);
  1133. ErrorCodeEnum ErrorCode = ShowVideo(m_SalesVideoName);
  1134. return ErrorCode;
  1135. }
  1136. ErrorCodeEnum CSalesRecorderEntity::HandlePlaySalesRecordVideo(int iWndX, int iWndY, int iWndWidth, int iWndHeight)
  1137. {
  1138. // 视频播放 libwmpplayer
  1139. m_bIsShowVideo = TRUE;
  1140. Dbg("play sales record video file name is %s!", m_SalesVideoName);
  1141. ErrorCodeEnum ErrorCode = PlaySalesRecordVideo(m_SalesVideoName, iWndX, iWndY, iWndWidth, iWndHeight);
  1142. Dbg("play sales record video return code is 0x%08x.", ErrorCode);
  1143. return ErrorCode;
  1144. }
  1145. ErrorCodeEnum CSalesRecorderEntity::HandleStopShowVideo()
  1146. {
  1147. // 视频播放 libwmpplayer
  1148. Dbg("stop show video record file name is %s!", m_SalesVideoName);
  1149. ErrorCodeEnum ErrorCode = Error_Succeed;
  1150. if(m_bIsShowVideo)
  1151. {
  1152. //Dbg("m_pPlayer = %p while play!", m_pPlayer);
  1153. //m_pPlayer->Close();
  1154. m_bIsShowVideo = FALSE;
  1155. Dbg("succeed to stop show video!");
  1156. }
  1157. else{
  1158. ErrorCode = Error_NotImpl;
  1159. }
  1160. return ErrorCode;
  1161. }
  1162. ErrorCodeEnum CSalesRecorderEntity::HandleSaveVideo()
  1163. {
  1164. ErrorCodeEnum ErrorCode = Error_Succeed;
  1165. // 将视频从tmp移动到uploadvideo
  1166. if (!strstr(m_SalesVideoName, "OFL")) // edit by ly 20180228
  1167. {
  1168. ErrorCode = SaveVideo(m_SalesVideoName+2);
  1169. }
  1170. else
  1171. {
  1172. ErrorCode = SaveVideo(m_SalesVideoName+4);
  1173. }
  1174. ZeroMemory(m_SalesVideoName,sizeof(m_SalesVideoName));
  1175. return ErrorCode;
  1176. }
  1177. void CSalesRecorderEntity::HandleDeleteVideo()
  1178. {
  1179. // 删除tmp中的视频
  1180. DeleteVideo(m_SalesVideoName);
  1181. ZeroMemory(m_SalesVideoName,sizeof(m_SalesVideoName));
  1182. }
  1183. void CSalesRecorderEntity::HandleVideoAppendWatermark(const char* pszMessage)
  1184. {
  1185. if (NULL == pszMessage){
  1186. return;
  1187. }
  1188. wchar_t*result[10] = {0};
  1189. auto arr1 = CSimpleStringA2W(pszMessage).Split('|');
  1190. auto arr2 = CAutoArray<CSimpleStringW>(arr1.GetCount());
  1191. int icount = sizeof(result)/sizeof(char*);
  1192. for (int i = 0; i < arr1.GetCount() && i < sizeof(result)/sizeof(char*); i++)
  1193. {
  1194. arr2[i] = CSimpleStringW(arr1[i]);
  1195. result[i] = (wchar_t*)arr2[i].GetData();
  1196. }
  1197. if (m_bStarted && (NULL != m_pRecorder))
  1198. {
  1199. m_pRecorder->SetRightVideoWaterMark(result[1]);
  1200. }
  1201. }
  1202. ErrorCodeEnum CSalesRecorderEntity::HandleSalesRecordEntityException(const char* pszMessage)
  1203. {
  1204. // 通知到业务中台
  1205. SalesRecordException evt;
  1206. evt.failedmsg = CSimpleStringA2W(pszMessage==NULL?"现场销售双录过程出现异常!":pszMessage);
  1207. SpSendBroadcast(GetFunction(), SP_MSG_OF(SalesRecordException), SP_MSG_SIG_OF(SalesRecordException), evt);
  1208. Dbg("[dbg] SalesRecord entity exception broadcast sent!");
  1209. //停止录像
  1210. StopRecord();
  1211. m_bNeedRestart = true;
  1212. //重启实体
  1213. RealSelfCheck();
  1214. return Error_Succeed;
  1215. }
  1216. BOOL CSalesRecorderEntity::InitSalesRecorder()
  1217. {
  1218. BOOL bRet = FALSE;
  1219. if (m_bApplyHighQuality)
  1220. {
  1221. bRet = GetHighQualityOnSiteSalesRecorder();
  1222. }
  1223. else
  1224. {
  1225. bRet = GetStandardQualityOnSiteSalesRecorder();
  1226. }
  1227. return bRet;
  1228. }
  1229. BOOL CSalesRecorderEntity::ReleaseSalesRecorder()
  1230. {
  1231. if (m_pRecorder) {
  1232. delete m_pRecorder;
  1233. m_pRecorder = NULL;
  1234. }
  1235. return TRUE;
  1236. }
  1237. ErrorCodeEnum CSalesRecorderEntity::RealSelfCheck()
  1238. {
  1239. ErrorCodeEnum Error = Error_Succeed;
  1240. SelfChekerClient* pSelfcheckClient = new SelfChekerClient(this);
  1241. Error = pSelfcheckClient->Connect();
  1242. if (Error != Error_Succeed)
  1243. {
  1244. pSelfcheckClient->SafeDelete();
  1245. pSelfcheckClient = NULL;
  1246. Dbg("SelfcheckClient connect fail!");
  1247. }
  1248. else
  1249. {
  1250. Dbg("SelfcheckClient connect success!");
  1251. }
  1252. if (pSelfcheckClient)
  1253. {
  1254. SelfChecker::SelfCheckerService_RealCheck_Req req;
  1255. req.name = GetEntityName();
  1256. SelfChecker::SelfCheckerService_RealCheck_Ans ans;
  1257. DWORD Timeout = 500;
  1258. Error = pSelfcheckClient->RealCheck(req,ans,Timeout);
  1259. if (Error!=Error_Succeed)
  1260. {
  1261. Dbg("RealSelfcheck fail!");
  1262. }
  1263. else
  1264. {
  1265. Dbg("RealSelfcheck success!");
  1266. }
  1267. pSelfcheckClient->GetFunction()->CloseSession();
  1268. }
  1269. return Error;
  1270. }
  1271. #ifdef RVC_OS_WIN
  1272. bool IsMatchedVideo(WIN32_FIND_DATA fileData)
  1273. {
  1274. bool bRet = false;
  1275. if ('S' == fileData.cFileName[0] || 'W' == fileData.cFileName[0]){
  1276. SYSTEMTIME sysTime;
  1277. FileTimeToSystemTime(&fileData.ftCreationTime, &sysTime);
  1278. Dbg("File %s create data info is %d %d %d.", fileData.cFileName, sysTime.wYear, sysTime.wMonth, sysTime.wDay);
  1279. if ((2020 == sysTime.wYear) && (sysTime.wMonth == 1)){
  1280. if (sysTime.wDay >= 3 && sysTime.wDay <= 10){
  1281. bRet = true;
  1282. }
  1283. }
  1284. }
  1285. return bRet;
  1286. }
  1287. void CSalesRecorderEntity::UploadTempPathVideos()
  1288. {
  1289. CSimpleStringA sourPath;
  1290. CSimpleStringA destPath;
  1291. ErrorCodeEnum Error = GetFunction()->GetPath("Temp", sourPath);
  1292. Error = GetFunction()->GetPath("UploadVideo", destPath);
  1293. if (sourPath.GetLength() > 0 && sourPath[sourPath.GetLength()-1] != SPLIT_SLASH) {
  1294. sourPath += SPLIT_SLASH_STR;
  1295. }
  1296. if (destPath.GetLength() > 0 && destPath[destPath.GetLength()-1] != SPLIT_SLASH) {
  1297. destPath += SPLIT_SLASH_STR;
  1298. }
  1299. if(Error == Error_Succeed)
  1300. {
  1301. char srcFilePath[MAX_PATH]={0};
  1302. WIN32_FIND_DATA FindFileData;
  1303. HANDLE hFind;
  1304. BOOL fFinished = FALSE;
  1305. sprintf_s(srcFilePath, MAX_PATH, "%s*.wmv", sourPath);
  1306. hFind = FindFirstFile(srcFilePath, &FindFileData);
  1307. if (INVALID_HANDLE_VALUE != hFind)
  1308. {
  1309. while (!fFinished)
  1310. {
  1311. if (FILE_ATTRIBUTE_DIRECTORY & FindFileData.dwFileAttributes)
  1312. {
  1313. continue;
  1314. }
  1315. if (IsMatchedVideo(FindFileData)){
  1316. CSimpleStringA sourFileName = CSimpleStringA::Format("%s%s", (LPCSTR)sourPath, FindFileData.cFileName);
  1317. CSimpleStringA destFileName = CSimpleStringA::Format("%sBAK_%s", (LPCSTR)destPath, FindFileData.cFileName);
  1318. if(!MoveFile((LPCSTR)sourFileName, (LPCSTR)destFileName)) {
  1319. Dbg("Error Code %lu while move %s ", GetLastError(), (LPCSTR)sourFileName);
  1320. }else{
  1321. Dbg("Move File %s success.", (LPCSTR)sourFileName);
  1322. }
  1323. }
  1324. else{
  1325. Dbg("File (%s) is not matched.", FindFileData.cFileName);
  1326. }
  1327. if (!FindNextFile(hFind, &FindFileData))
  1328. {
  1329. if (GetLastError() == ERROR_NO_MORE_FILES)
  1330. {
  1331. fFinished = TRUE;
  1332. }
  1333. else
  1334. {
  1335. break;
  1336. }
  1337. }
  1338. }
  1339. FindClose(hFind);
  1340. }
  1341. }
  1342. }
  1343. #else
  1344. /*
  1345. **time_t转SYSTEMTIME
  1346. */
  1347. SYSTEMTIME Time_tToSystemTime(time_t t)
  1348. {
  1349. tm temptm = *localtime(&t);
  1350. SYSTEMTIME st = { 1900 + temptm.tm_year,
  1351. 1 + temptm.tm_mon,
  1352. temptm.tm_wday,
  1353. temptm.tm_mday,
  1354. temptm.tm_hour,
  1355. temptm.tm_min,
  1356. temptm.tm_sec,
  1357. 0 };
  1358. return st;
  1359. }
  1360. bool IsMatchedVideo(LPCTSTR path, struct dirent* file)
  1361. {
  1362. bool bRet = false;
  1363. if ((file->d_reclen > 0) && ('S' == file->d_name[0] || 'W' == file->d_name[0])){
  1364. struct stat fileInfo;
  1365. char ttp[256];
  1366. bzero(ttp, sizeof(ttp));
  1367. strcat(ttp, path);
  1368. if (strcmp(ttp, "/") != 0)strcat(ttp, "/");//如果是根目录不需要加
  1369. strcat(ttp, file->d_name);
  1370. if (stat(ttp, &fileInfo) == 0) {
  1371. SYSTEMTIME sysTime;
  1372. sysTime = Time_tToSystemTime(fileInfo.st_mtime);
  1373. Dbg("File %s create data info is %d %d %d.", file->d_name, sysTime.wYear, sysTime.wMonth, sysTime.wDay);
  1374. if ((2020 == sysTime.wYear) && (sysTime.wMonth == 1)) {
  1375. if (sysTime.wDay >= 3 && sysTime.wDay <= 10) {
  1376. bRet = true;
  1377. }
  1378. }
  1379. }
  1380. }
  1381. return bRet;
  1382. }
  1383. void CSalesRecorderEntity::UploadTempPathVideos() {
  1384. CSimpleStringA sourPath;
  1385. CSimpleStringA destPath;
  1386. ErrorCodeEnum Error = GetFunction()->GetPath("Temp", sourPath);
  1387. Error = GetFunction()->GetPath("UploadVideo", destPath);
  1388. if (sourPath.GetLength() > 0 && sourPath[sourPath.GetLength() - 1] != SPLIT_SLASH) {
  1389. sourPath += SPLIT_SLASH_STR;
  1390. }
  1391. if (destPath.GetLength() > 0 && destPath[destPath.GetLength() - 1] != SPLIT_SLASH) {
  1392. destPath += SPLIT_SLASH_STR;
  1393. }
  1394. if (Error == Error_Succeed)
  1395. {
  1396. char srcFilePath[MAX_PATH] = { 0 };
  1397. DIR* pDir = NULL;
  1398. struct dirent* pFile = NULL;
  1399. snprintf(srcFilePath, MAX_PATH, "%s*.%s", sourPath, RVC_RECORD_SUFFIX);
  1400. pDir = opendir(sourPath);
  1401. if (pDir == NULL) return ;
  1402. while ((pFile = readdir(pDir)) != NULL) {
  1403. if (pFile->d_type & DT_DIR) {
  1404. //m_pHostApi->Debug("MoveTempPathVideos DIR name: %s.", pFile->d_name);
  1405. continue;
  1406. }
  1407. else {
  1408. //m_pHostApi->Debug("MoveTempPathVideos FILE name: %s.", pFile->d_name);
  1409. if (IsMatchedVideo((LPCSTR)sourPath, pFile)) {
  1410. CSimpleStringA sourFileName = CSimpleStringA::Format("%s%s", (LPCSTR)sourPath, pFile->d_name);
  1411. CSimpleStringA destFileName = CSimpleStringA::Format("%sBAK_%s", (LPCSTR)destPath, pFile->d_name);
  1412. if (rename(sourFileName.GetData(), destFileName.GetData())) {
  1413. Dbg("Error Code %lu while move %s.", errno, sourFileName.GetData());
  1414. }
  1415. else {
  1416. Dbg("Move File %s success.", sourFileName.GetData());
  1417. }
  1418. }
  1419. else {
  1420. Dbg("File (%s) is not matched.", pFile->d_name);
  1421. }
  1422. }
  1423. }
  1424. closedir(pDir);
  1425. }
  1426. }
  1427. #endif
  1428. ErrorCodeEnum CSalesRecorderEntity::SetRecordAudioQuality(int iAudioQuality)
  1429. {
  1430. ErrorCodeEnum eRet = Error_Succeed;
  1431. Dbg("iAudioQuality == %d.", iAudioQuality);
  1432. switch (iAudioQuality)
  1433. {
  1434. case 1:
  1435. m_eAudioOutQuality = eLowDefinition;
  1436. break;
  1437. case 2:
  1438. m_eAudioOutQuality = eStandardDefinition;
  1439. break;
  1440. case 3:
  1441. m_eAudioOutQuality = eHighDefinition;
  1442. break;
  1443. case 4:
  1444. m_eAudioOutQuality = eUltraHD;
  1445. break;
  1446. default:
  1447. m_eAudioOutQuality = eUltraHD;
  1448. break;
  1449. }
  1450. return eRet;
  1451. }
  1452. ErrorCodeEnum CSalesRecorderEntity::SetRecordAudioNsPolicy(int iNsPolicy)
  1453. {
  1454. ErrorCodeEnum eRet = Error_Succeed;
  1455. Dbg("iNsPolicy == %d.", iNsPolicy);
  1456. if (1 == iNsPolicy || 3 == iNsPolicy){
  1457. m_iAudioNsPolicy = iNsPolicy;
  1458. }
  1459. else{
  1460. m_iAudioNsPolicy = 2;
  1461. }
  1462. return eRet;
  1463. }
  1464. DeviceTypeEnum CSalesRecorderEntity::RvcGetDeviceType()
  1465. {
  1466. DeviceTypeEnum eType = eStand2sType;
  1467. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  1468. CSystemStaticInfo stStaticinfo;
  1469. spFunction->GetSystemStaticInfo(stStaticinfo);
  1470. m_terminalNo = stStaticinfo.strTerminalID;
  1471. if (stricmp(stStaticinfo.strMachineType, "RVC.PAD") == 0) {
  1472. if (stricmp(stStaticinfo.strSite, "CMB.FLB") == 0) {
  1473. eType = eMobilePadType;
  1474. }
  1475. else {
  1476. eType = ePadtype;
  1477. }
  1478. }
  1479. else if (stricmp(stStaticinfo.strMachineType, "RVC.Desk2S") == 0) {
  1480. eType = eDesk2SType;
  1481. WORD nMajor = stStaticinfo.MachineVersion.GetMajor();
  1482. WORD nMinor = stStaticinfo.MachineVersion.GetMinor();
  1483. Dbg("MachineVersion is %d.%d", nMajor, nMinor);
  1484. if (2 == nMajor) {
  1485. eType = eDesk2SIntegratedType;
  1486. }
  1487. }
  1488. else if (stricmp(stStaticinfo.strMachineType, "RPM.Stand1S") == 0) {
  1489. eType = eRpm1sType;
  1490. }
  1491. else if (stricmp(stStaticinfo.strMachineType, "RVC.Desk1S") == 0) {
  1492. eType = eDesk1SType;
  1493. }
  1494. else {
  1495. eType = eStand2sType;
  1496. }
  1497. if (eType >= 0 && eType < sizeof(Device_Type_Table) / sizeof(char*)) {
  1498. LOG_TRACE("device type is %s.", Device_Type_Table[eType]);
  1499. }
  1500. return eType;
  1501. }
  1502. SelfChekerClient::SelfChekerClient( CSalesRecorderEntity *pEntity ) : SelfChecker::SelfCheckerService_ClientBase(pEntity)
  1503. {
  1504. }
  1505. SP_BEGIN_ENTITY_MAP()
  1506. SP_ENTITY(CSalesRecorderEntity)
  1507. SP_END_ENTITY_MAP()