mod_SalesRecorder.cpp 51 KB

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