mod_SalesRecorder.cpp 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738
  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. 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 name is %s.", (LPCTSTR)CSimpleStringW2A(ctx->Req.VideoName));
  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 name is %s.", (LPCTSTR)CSimpleStringW2A(ctx->Req.VideoName));
  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 name is %s.", (LPCTSTR)CSimpleStringW2A(ctx->Req.VideoName));
  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 name is %s.", (LPCTSTR)CSimpleStringW2A(ctx->Req.VideoName));
  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. #ifdef RVC_OS_WIN
  321. if (SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS)){
  322. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Set Process(%d) RealTime Priority Success.",GetCurrentProcessId());
  323. }
  324. #endif
  325. m_eDeviceType = RvcGetDeviceType();
  326. int iAudioQuality = 3;
  327. int iAudioNsPolicy = 2;
  328. int iIsAudioNsOn = 0;
  329. m_max_disk_percent = MAX_DISK_PERCENT; // add by ly 2018/02/24
  330. CSmartPointer<IConfigInfo> spConfig;
  331. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  332. if (spFunction->OpenConfig(Config_CenterSetting, spConfig) == Error_Succeed)
  333. {
  334. spConfig->ReadConfigValueInt("SalesRecorder","MaxDiskPercent",m_max_disk_percent);
  335. spConfig->ReadConfigValueInt("SalesRecorder","AudioSampleRate",m_audio_samplerate);
  336. spConfig->ReadConfigValueInt("SalesRecorder","AudioBitRate",m_audio_out_bitrate);
  337. spConfig->ReadConfigValueInt("SalesRecorder","WholeSection",m_bWholeSection);
  338. spConfig->ReadConfigValueInt("SalesRecorder","ApplyHighQuality",m_bApplyHighQuality);
  339. spConfig->ReadConfigValueInt("SalesRecorder","AudioNsPolicy",iAudioNsPolicy);
  340. spConfig->ReadConfigValueInt("SalesRecorder","IsAudioNsOn",iIsAudioNsOn);
  341. spConfig->ReadConfigValueInt("SalesRecorder","AudioQuality",iAudioQuality);
  342. }
  343. if (m_max_disk_percent <= 0 || m_max_disk_percent >= 100)
  344. {
  345. m_max_disk_percent = MAX_DISK_PERCENT;
  346. }
  347. SetRecordAudioQuality(iAudioQuality);
  348. SetRecordAudioNsPolicy(iAudioNsPolicy);
  349. if (0 != iIsAudioNsOn){
  350. m_bIsAudioNsOn = true;
  351. }
  352. if (m_bWholeSection != 0 && m_bWholeSection != 1)
  353. {
  354. m_bWholeSection = FALSE;
  355. }
  356. if (m_bApplyHighQuality != 0 && m_bApplyHighQuality != 1)
  357. {
  358. m_bApplyHighQuality = FALSE;
  359. }
  360. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[dbg] m_bApplyHighQuality:%d",m_bApplyHighQuality);
  361. m_bEwsRecord = FALSE;
  362. if (preOperationError != Error_Succeed)
  363. return preOperationError;
  364. ErrorCodeEnum Error = Error_Succeed;
  365. m_iActiveCamera = CAMERA_TYPE_ENV;
  366. m_iCameraState = 'N';
  367. int i = 0;
  368. if (ePadtype == m_eDeviceType||eMobilePadType == m_eDeviceType||eDesk2SType == m_eDeviceType||eDesk1SType == m_eDeviceType||eDesk2SIntegratedType == m_eDeviceType)
  369. {
  370. // add by ly(edit by ly 2018/03/12)
  371. #ifdef RVC_OS_WIN
  372. m_pPlayer = new Clibwmpplayer(this);
  373. #else
  374. //m_pPlayer = new Clibmediaplayer(this);
  375. #endif // RVC_OS_WIN
  376. m_arrListener.Init(9);
  377. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STARTRECORD, NULL, false);
  378. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STARTAFTERPREVIEWRECORD, NULL, false);
  379. //GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STOPRECORD, NULL, false);
  380. //GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_SHOWVIDEO, NULL, false);
  381. //GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_SAVEVIDEO, NULL, false);
  382. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_DELETEVIDEO, NULL, false);
  383. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_RETURNMENU, NULL, false);
  384. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_UKEY_PULLOUT, NULL, false);
  385. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_VIDEOAPPENDWATERMARK, NULL, false);
  386. //GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STARTREMOTERECORD, NULL, false);
  387. //GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STOPREMOTERECORD, NULL, false);
  388. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_High, Error_IgnoreAll, LOG_EVT_SALESRECORD_ENTITY_EXCEPTION, NULL, false);
  389. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_High, Error_IgnoreAll, LOG_EVT_AUDIOSTREAM_TRANSMISSION_FAILED, NULL, false);
  390. }
  391. else
  392. {
  393. // add by ly @2018/01/10
  394. #ifdef RVC_OS_WIN
  395. m_pPlayer = new Clibwmpplayer(this);
  396. #else
  397. //m_pPlayer = new Clibmediaplayer(this);
  398. #endif // RVC_OS_WIN
  399. m_arrListener.Init(8);
  400. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STARTRECORD, NULL, false);
  401. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STARTAFTERPREVIEWRECORD, NULL, false);
  402. //GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STOPRECORD, NULL, false);
  403. //GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_SHOWVIDEO, NULL, false);
  404. //GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_SAVEVIDEO, NULL, false);
  405. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_DELETEVIDEO, NULL, false);
  406. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_RETURNMENU, NULL, false);
  407. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_VIDEOAPPENDWATERMARK, NULL, false);
  408. //GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STARTREMOTERECORD, NULL, false);
  409. //GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STOPREMOTERECORD, NULL, false);
  410. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_High, Error_IgnoreAll, LOG_EVT_SALESRECORD_ENTITY_EXCEPTION, NULL, false);
  411. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_High, Error_IgnoreAll, LOG_EVT_AUDIOSTREAM_TRANSMISSION_FAILED, NULL, false);
  412. }
  413. GetFunction()->RegistSysVarEvent(SYSVAR_ACTIVETRACKINGCAMERA,this);
  414. GetFunction()->RegistSysVarEvent(SYSVAR_CAMERASTATE,this);
  415. CSimpleStringA strValue;
  416. GetFunction()->GetSysVar(SYSVAR_CAMERASTATE, strValue);
  417. m_iCameraState = strValue[0];
  418. if (strValue[0] == 'E'){
  419. m_iActiveCamera = CAMERA_TYPE_OPT;
  420. }
  421. else{
  422. m_iActiveCamera = CAMERA_TYPE_ENV;
  423. }
  424. GetFunction()->RegistSysVarEvent(SYSVAR_CALLTYPE, this);
  425. GetFunction()->GetSysVar(SYSVAR_CALLTYPE, strValue);
  426. if (strValue[0] == CALLTYPE_NORMAL)
  427. {
  428. m_nSysCallType = 0;
  429. }
  430. else if (strValue[0] == CALLTYPE_MOBILE)
  431. {
  432. m_nSysCallType = 1;
  433. }
  434. else
  435. {
  436. assert(0);
  437. }
  438. Error = GetFunction()->RegistSysVarEvent("SessionID", this);
  439. if (Error != Error_Succeed)
  440. {
  441. LOG_TRACE("register sysvar %s failed!", "SessionID");
  442. }
  443. // add by ly 2018/02/13
  444. Error = GetFunction()->GetPath("Temp", m_TempDir);
  445. if (Error != Error_Succeed) {
  446. LOG_TRACE("get global record temp path failed!");
  447. }
  448. if (m_TempDir.GetLength() > 0 && m_TempDir[m_TempDir.GetLength()-1] != SPLIT_SLASH) {
  449. m_TempDir += SPLIT_SLASH_STR;
  450. }
  451. Error = GetFunction()->GetPath("UploadVideo", m_RecordSaveDir);
  452. if (Error != Error_Succeed) {
  453. LOG_TRACE("get global record save path failed!");
  454. }
  455. if (m_RecordSaveDir.GetLength() > 0 && m_RecordSaveDir[m_RecordSaveDir.GetLength()-1] != SPLIT_SLASH) {
  456. m_RecordSaveDir += SPLIT_SLASH_STR;
  457. }
  458. return Error;
  459. }
  460. void CSalesRecorderEntity::OnStarted()
  461. {
  462. InitSalesRecorder();
  463. }
  464. void CSalesRecorderEntity::OnPreClose( EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext )
  465. {
  466. ErrorCodeEnum Error = __OnClose(Error_Succeed);
  467. pTransactionContext->SendAnswer(Error);
  468. }
  469. ErrorCodeEnum CSalesRecorderEntity::__OnClose( ErrorCodeEnum preOperationError )
  470. {
  471. LOG_FUNCTION();
  472. if (preOperationError != Error_Succeed)
  473. return preOperationError;
  474. //delete m_pPlayer; m_pPlayer = NULL;
  475. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  476. for (int i = 0; i < m_arrListener.GetCount(); ++i)
  477. {
  478. spFunction->UnsubscribeLog(m_arrListener[i]);
  479. }
  480. GetFunction()->UnregistSysVarEvent(SYSVAR_ACTIVETRACKINGCAMERA);
  481. GetFunction()->UnregistSysVarEvent(SYSVAR_CAMERASTATE);
  482. StopRecord();
  483. ReleaseSalesRecorder();
  484. return Error_Succeed;
  485. }
  486. void CSalesRecorderEntity::OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
  487. {
  488. if (Test_ShakeHand == eTestType)
  489. {
  490. if (m_bNeedRestart){
  491. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[OnSelfTest] entity need restart now.");
  492. pTransactionContext->SendAnswer(Error_Unexpect);
  493. }
  494. else{
  495. pTransactionContext->SendAnswer(Error_Succeed);
  496. }
  497. }
  498. }
  499. int CSalesRecorderEntity::GetActiveCamera()
  500. {
  501. //Debug("get active camera = %d", m_iActiveCamera);
  502. return m_iActiveCamera;
  503. }
  504. int CSalesRecorderEntity::GetCameraState()
  505. {
  506. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get active camera = %d", m_iCameraState);
  507. return m_iCameraState;
  508. }
  509. void CSalesRecorderEntity::OnRecordFailed(eRvcRecordFailedCase eCase, const char* pszMessage, bool bRecordDevFault )
  510. {
  511. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("OnSalesRecordFailed!");
  512. if (eCase < eDefault && eCase >= 0) {
  513. LogEvent(Severity_Middle, LOG_EVT_UI_RECORDFAILED, record_failed_case_table[eCase]);
  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. if (eBeginFailed == eCase) {
  519. m_bNeedRestart = true;
  520. RealSelfCheck();
  521. }
  522. }
  523. void CSalesRecorderEntity::OnRecordEntityExcption()
  524. {
  525. LogEvent(Severity_High,LOG_EVT_SALESRECORD_ENTITY_EXCEPTION,"现场销售双录出现异常,请稍候重录,系统正在恢复中,预计60秒!");
  526. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORD_ENTITY_EXCEPTION, "sales record entity exception!");
  527. }
  528. void CSalesRecorderEntity::OnRecordFinished()
  529. {
  530. LogEvent(Severity_High, LOG_EVT_SALESRECORD_FINISHED, "现场销售双录已完成.");
  531. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORD_FINISHED, "现场销售双录已完成.");
  532. }
  533. void CSalesRecorderEntity::Debug(record_loglevel elevel, const char* fmt, ...)
  534. {
  535. if (RECORD_LOG_DEBUG <= elevel) {
  536. va_list arg;
  537. va_start(arg, fmt);
  538. vDbg(fmt, arg);
  539. va_end(arg);
  540. }
  541. }
  542. void CSalesRecorderEntity::vDebug(record_loglevel elevel, const char* str, va_list list)
  543. {
  544. if (RECORD_LOG_DEBUG <= elevel) {
  545. vDbg(str, list);
  546. }
  547. }
  548. #ifdef RVC_OS_WIN
  549. void CSalesRecorderEntity::WmpDebug( const char *fmt, ... )
  550. {
  551. va_list arg;
  552. va_start(arg, fmt);
  553. vDbg(fmt, arg);
  554. va_end(arg);
  555. }
  556. #else
  557. void CSalesRecorderEntity::Debug(media_loglevel log_level, const char* fmt, ...)
  558. {
  559. if (log_level >= MEDIA_LOG_ERROR) {
  560. va_list arg;
  561. va_start(arg, fmt);
  562. vDbg(fmt, arg);
  563. va_end(arg);
  564. }
  565. }
  566. #endif // RVC_OS_WIN
  567. // 定时任务:扫描是否有待提交的离线双录记录 add by ly @2018/02/08
  568. void CSalesRecorderEntity::OnTimeout( DWORD dwTimerID )
  569. {
  570. }
  571. void CSalesRecorderEntity::OnSysVarEvent( const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName )
  572. {
  573. if (_stricmp(pszKey, SYSVAR_CAMERASTATE) == 0)
  574. {
  575. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("camera state from : %c to %c", pszOldValue[0], pszValue[0]);
  576. m_iCameraState = pszValue[0];
  577. if (pszValue[0] == 'E')
  578. {
  579. m_iActiveCamera = CAMERA_TYPE_OPT;
  580. }
  581. else
  582. {
  583. m_iActiveCamera = CAMERA_TYPE_ENV;
  584. }
  585. }
  586. else if (_stricmp(pszKey, SYSVAR_ACTIVETRACKINGCAMERA) == 0)
  587. {
  588. if (m_iCameraState == 'N')
  589. {
  590. if (pszValue[0] == 'E')
  591. {
  592. m_iActiveCamera = CAMERA_TYPE_ENV;
  593. }
  594. else if (pszValue[0] == 'O')
  595. {
  596. m_iActiveCamera = CAMERA_TYPE_OPT;
  597. }
  598. }
  599. }
  600. else if (_stricmp(pszKey, SYSVAR_CALLTYPE) == 0)
  601. {
  602. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("sys calltype from: %c to %c", pszOldValue[0], pszValue[0]);
  603. if(pszValue[0] == CALLTYPE_NORMAL)
  604. {
  605. m_nSysCallType = 0;
  606. }
  607. else if(pszValue[0] == CALLTYPE_MOBILE)
  608. {
  609. m_nSysCallType = 1;
  610. }
  611. else
  612. {
  613. m_nSysCallType = -1;
  614. }
  615. }
  616. }
  617. 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)
  618. {
  619. // 响应客户经理销售录像相关的事件
  620. switch (dwUserCode)
  621. {
  622. case LOG_EVT_UI_STARTRECORD:
  623. case LOG_EVT_UI_STARTAFTERPREVIEWRECORD:
  624. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start record, pszMessage = %s.",pszMessage);
  625. HandleStartRecord(pszMessage, false);
  626. break;
  627. case LOG_EVT_UI_STOPREMOTERECORD:
  628. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("stop remote record, pszMessage = %s.",pszMessage);
  629. StopRecord();
  630. LogWarn(Severity_Low, Error_Debug, LOG_EVT_STOP_REMOTERECORD, "stop remote record.");
  631. break;
  632. case LOG_EVT_UI_STOPRECORD:
  633. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("stop record, pszMessage = %s.",pszMessage);
  634. HandleStopRecord(pszMessage);
  635. break;
  636. case LOG_EVT_UI_SHOWVIDEO:
  637. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("show video record, pszMessage = %s.",pszMessage);
  638. HandleDisplayVideo();
  639. break;
  640. case LOG_EVT_UI_SAVEVIDEO:
  641. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("save record!");
  642. HandleSaveVideo();
  643. break;
  644. case LOG_EVT_UI_DELETEVIDEO:
  645. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("delete record!");
  646. HandleDeleteVideo();
  647. break;
  648. case LOG_EVT_UI_RETURNMENU:
  649. break;
  650. case EVENT_UKEY_PULLOUT:
  651. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("ukey pull out!");
  652. break;
  653. case LOG_EVT_UI_VIDEOAPPENDWATERMARK:
  654. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("handle video append water mark param is %s.", pszMessage);
  655. HandleVideoAppendWatermark(pszMessage);
  656. break;
  657. case LOG_EVT_SALESRECORD_ENTITY_EXCEPTION:
  658. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("handle sales record entity exception, and message is %s.", pszMessage);
  659. HandleSalesRecordEntityException(pszMessage);
  660. break;
  661. case LOG_EVT_AUDIOSTREAM_TRANSMISSION_FAILED:
  662. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("handle audio stream transmission failed.");
  663. break;
  664. default:
  665. break;
  666. }
  667. }
  668. // we use root.ini Video section config to decide camera count
  669. ErrorCodeEnum CSalesRecorderEntity::DecideCameraCount( int &nCount )
  670. {
  671. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  672. CSmartPointer<IConfigInfo> spConfig;
  673. ErrorCodeEnum Error = spFunction->OpenConfig(Config_Root, spConfig);
  674. if (Error == Error_Succeed) {
  675. CSimpleStringA strVideoEnv;
  676. CSimpleStringA strVideoOpt;
  677. SpIniMappingTable table;
  678. nCount = 0;
  679. table.AddEntryString("Video", "EnvCamera", strVideoEnv, "$");
  680. table.AddEntryString("Video", "OptCamera", strVideoOpt, "$");
  681. Error = table.Load(spConfig);
  682. if (Error == Error_Succeed) {
  683. if (strVideoEnv.GetLength() > 1)
  684. nCount++;
  685. if (strVideoOpt.GetLength() > 1)
  686. nCount++;
  687. }
  688. }
  689. return Error;
  690. }
  691. BOOL CSalesRecorderEntity::GetStandardQualityOnSiteSalesRecorder()
  692. {
  693. BOOL bRet = FALSE;
  694. m_pRecorder = new Clibwmvrecord(&bRet, this, REC_COMMON_AUDIO_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE,
  695. 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);
  696. return bRet;
  697. }
  698. BOOL CSalesRecorderEntity::GetHighQualityOnSiteSalesRecorder()
  699. {
  700. BOOL bRet = FALSE;
  701. m_pRecorder = new Clibwmvrecord(&bRet, this, REC_COMMON_AUDIO_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE,
  702. 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);
  703. return bRet;
  704. }
  705. void CSalesRecorderEntity::StartOnSiteSalesRecord(const int fps, const char* wmvfilename, int videoquality, int audioOutBitRate, SubtitleParam* subtitleParam, BOOL bWholeSection, BOOL bSessionManage, eRvcRecordType eRecordType)
  706. {
  707. Rvc_RecordAudioParam_t tAudioParams;
  708. tAudioParams.eRecordType = eRecordType;
  709. tAudioParams.eOutPutType = m_eAudioOutQuality;
  710. tAudioParams.bIsNsOn = m_bIsAudioNsOn;
  711. tAudioParams.iNsPolicy = m_iAudioNsPolicy;
  712. tAudioParams.iAudioOutBitRate = audioOutBitRate;
  713. if (eStand2Agent == eRecordType || ePad2Agent == eRecordType) {
  714. tAudioParams.eOutPutType = eLowDefinition;
  715. tAudioParams.bIsNsOn = false;
  716. }
  717. 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);
  718. if (m_pRecorder->StartWmvRecord(fps, videoquality, &tAudioParams, subtitleParam, bWholeSection, FALSE, (LPCSTR)m_TempDir,
  719. m_TempDir.GetLength(), wmvfilename, strlen(wmvfilename)))
  720. {
  721. m_bStarted = TRUE;
  722. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Start WmvRecord success!");
  723. }
  724. else {
  725. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Start WmvRecord failed!");
  726. }
  727. }
  728. void CSalesRecorderEntity::StartRecord(const char *wmvfilename, int videoquality, int audioOutBitRate, SubtitleParam *subtitleParam /* = NULL */, BOOL bWholeSection /* = FALSE */, BOOL bSessionManage /* = FALSE */, eRvcRecordType eRecordType /* = eSingleSide */)
  729. {
  730. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("wmvfilename = %s", wmvfilename);
  731. StartOnSiteSalesRecord(10, wmvfilename, videoquality, audioOutBitRate, subtitleParam, bWholeSection, bSessionManage, eRecordType);
  732. }
  733. ErrorCodeEnum CSalesRecorderEntity::StopRecord()
  734. {
  735. ErrorCodeEnum eCode = Error_Succeed;
  736. if (m_bStarted)
  737. {
  738. m_pRecorder->StopWmvRecord();
  739. m_bStarted = FALSE;
  740. }
  741. else{
  742. eCode = Error_InvalidState;
  743. }
  744. return eCode;
  745. }
  746. ErrorCodeEnum CSalesRecorderEntity::ShowVideo( const char *wmvfilename )
  747. {
  748. ErrorCodeEnum ErrorCode = Error_Succeed;
  749. if(!m_bStarted)
  750. {
  751. CSimpleStringA strPath;
  752. ErrorCodeEnum Error = GetFunction()->GetPath("Temp", strPath);
  753. if (Error == Error_Succeed) {
  754. if (strPath.GetLength() > 0 && strPath[strPath.GetLength()-1] != SPLIT_SLASH) {
  755. strPath += SPLIT_SLASH_STR;
  756. }
  757. CSimpleStringA strFindFileName = CSimpleStringA::Format("%s*.%s", wmvfilename, RVC_RECORD_SUFFIX);
  758. ULONGLONG uVideoCount = 0;
  759. BOOL bRet = FindMatchedFile((LPCSTR)strPath, (LPCTSTR)strFindFileName, uVideoCount);
  760. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("bRet = %d while find %s", bRet, wmvfilename);
  761. if(bRet){
  762. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("succeed to get record count while play video!");
  763. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("m_pPlayer = %p while play!", m_pPlayer);
  764. //m_pPlayer->PlayVideo((LPCSTR)strPath, wmvfilename, uVideoCount);
  765. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("succeed to play video!");
  766. }
  767. else{
  768. ErrorCode = Error_NotExist;
  769. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("play video failed for %s no exist!", wmvfilename);
  770. }
  771. }
  772. }
  773. else{
  774. ErrorCode = Error_NotImpl;
  775. }
  776. return ErrorCode;
  777. }
  778. ErrorCodeEnum CSalesRecorderEntity::PlaySalesRecordVideo( const char *wmvfilename, int iWndX, int iWndY, int iWndWidth, int iWndHeight)
  779. {
  780. ErrorCodeEnum ErrorCode = Error_Succeed;
  781. if(!m_bStarted)
  782. {
  783. CSimpleStringA strPath;
  784. ErrorCodeEnum Error = GetFunction()->GetPath("Temp", strPath);
  785. if (Error == Error_Succeed) {
  786. if (strPath.GetLength() > 0 && strPath[strPath.GetLength()-1] != SPLIT_SLASH) {
  787. strPath += SPLIT_SLASH_STR;
  788. }
  789. CSimpleStringA strFindFileName = CSimpleStringA::Format("%s*.%s", wmvfilename, RVC_RECORD_SUFFIX);
  790. ULONGLONG uVideoCount = 0;
  791. BOOL bRet = FindMatchedFile((LPCSTR)strPath, (LPCTSTR)strFindFileName, uVideoCount);
  792. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("bRet = %d while find %s", bRet, wmvfilename);
  793. if(bRet){
  794. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("succeed to get record count while play sales record video!");
  795. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("m_pPlayer = %p while play!", m_pPlayer);
  796. //m_pPlayer->PlaySalesRecordVideo(iWndX, iWndY, iWndWidth, iWndHeight,(LPCSTR)strPath, wmvfilename, uVideoCount);
  797. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("succeed to play sales record video!");
  798. }
  799. else{
  800. ErrorCode = Error_NotExist;
  801. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("play play sales record video failed for %s no exist!", wmvfilename);
  802. }
  803. }
  804. }
  805. else{
  806. ErrorCode = Error_NotImpl;
  807. }
  808. return ErrorCode;
  809. }
  810. void CSalesRecorderEntity::DeleteVideo( const char *wmvfilename )
  811. {
  812. if(!m_bStarted)
  813. {
  814. CSimpleStringA strPath;
  815. ErrorCodeEnum Error = GetFunction()->GetPath("Temp", strPath);
  816. if (Error == Error_Succeed) {
  817. if (strPath.GetLength() > 0 && strPath[strPath.GetLength()-1] != SPLIT_SLASH) {
  818. strPath += SPLIT_SLASH_STR;
  819. }
  820. CSimpleStringA strFindFileName = CSimpleStringA::Format("%s*.%s", wmvfilename, RVC_RECORD_SUFFIX);
  821. ULONGLONG uVideoCount = 0;
  822. BOOL bRet = FindMatchedFile((LPCSTR)strPath, (LPCTSTR)strFindFileName, uVideoCount);
  823. if(bRet)
  824. {
  825. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("succeed to get record count while delete video!");
  826. CSimpleStringA fileName;
  827. BOOL bDeleteSucc = TRUE;
  828. for(int i = 0; i != uVideoCount; ++i)
  829. {
  830. fileName = CSimpleStringA::Format("%s%s_%d.%s", (LPCSTR)strPath, wmvfilename, i, RVC_RECORD_SUFFIX);
  831. if(remove(fileName.GetData())) {
  832. bDeleteSucc = FALSE;
  833. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Error Code %lu while delete %s ", errno, fileName.GetData());
  834. }
  835. }
  836. if (bDeleteSucc) {
  837. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("succeed to delete videos!");
  838. }
  839. }
  840. else
  841. {
  842. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[DeleteVideo] videos not exist or have been deleted!");
  843. }
  844. }
  845. }
  846. }
  847. /*
  848. SaveVideo包含两步,找到录像和移动录像
  849. Error_Succeed 提交上传成功
  850. Error_NotExist not exist
  851. Error_NotImpl 方法执行失败
  852. */
  853. static unsigned long GetFileSize(const char* filename)
  854. {
  855. struct stat statbuf;
  856. stat(filename, &statbuf);
  857. return statbuf.st_size;
  858. }
  859. ErrorCodeEnum CSalesRecorderEntity::SaveVideo( const char *wmvfilename )
  860. {
  861. ErrorCodeEnum ErrorCode = Error_Succeed;
  862. if(!m_bStarted)
  863. {
  864. CSimpleStringA sourPath;
  865. ErrorCodeEnum Error = GetFunction()->GetPath("Temp", sourPath);
  866. if(Error == Error_Succeed)
  867. {
  868. if (sourPath.GetLength() > 0 && sourPath[sourPath.GetLength()-1] != SPLIT_SLASH) {
  869. sourPath += SPLIT_SLASH_STR;
  870. }
  871. ULONGLONG uVideoCount = 0;
  872. // 移动销售录像 edit by ly 2018/03/05
  873. CSimpleStringA strFindFileName = CSimpleStringA::Format("S_%s*.%s", wmvfilename, RVC_RECORD_SUFFIX);
  874. BOOL bRet = FindMatchedFile((LPCSTR)sourPath, (LPCSTR)strFindFileName, uVideoCount);
  875. if(bRet)
  876. {
  877. strFindFileName = strFindFileName.SubString(0,strFindFileName.GetLength()-5);
  878. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("succeed to get sales record count while save video!");
  879. CSimpleStringA destPath;
  880. Error = GetFunction()->GetPath("UploadVideo", destPath);
  881. if(Error == Error_Succeed)
  882. {
  883. if (destPath.GetLength() > 0 && destPath[destPath.GetLength()-1] != SPLIT_SLASH) {
  884. destPath += SPLIT_SLASH_STR;
  885. }
  886. CSimpleStringA sourFileName, destFileName;
  887. BOOL bMoveSucc = TRUE;
  888. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("strFindFileName=%s", (LPCSTR)strFindFileName);
  889. for(int i = 0; i != uVideoCount; ++i)
  890. {
  891. sourFileName = CSimpleStringA::Format("%s%s_%d.%s", (LPCSTR)sourPath, (LPCSTR)strFindFileName, i, RVC_RECORD_SUFFIX);
  892. destFileName = CSimpleStringA::Format("%s%s_%d.%s", (LPCSTR)destPath, (LPCSTR)strFindFileName, i, RVC_RECORD_SUFFIX);
  893. unsigned long ufilesize = GetFileSize(sourFileName.GetData());
  894. char strtext[MAX_PATH] = {0};
  895. snprintf(strtext, MAX_PATH, "%s file size is %u byte.", (LPCSTR)sourFileName, ufilesize);
  896. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORD_FILESIZE, strtext);
  897. if(rename(sourFileName.GetData(), destFileName.GetData())) {
  898. bMoveSucc = FALSE;
  899. ErrorCode = Error_NotImpl;
  900. char strinfo[MAX_PATH] = { 0 };
  901. snprintf(strinfo, MAX_PATH, "Error Code %lu while move %s.", errno, (LPCSTR)sourFileName);
  902. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORD_SAVED_FAILED, strinfo);
  903. }
  904. if (ufilesize > RVC_MIN_FILESIZE){
  905. }
  906. else{
  907. char strmsg[MAX_PATH] = {0};
  908. snprintf(strmsg, MAX_PATH, "%s file size is %u.", (LPCSTR)sourFileName, ufilesize);
  909. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORD_INVALID_FILE, strmsg);
  910. }
  911. }
  912. if (bMoveSucc) {
  913. char strmsg[MAX_PATH] = { 0 };
  914. snprintf(strmsg, MAX_PATH, "succeed to save sales video, move it from %s to %s.", sourFileName.GetData(), destFileName.GetData());
  915. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORD_SAVED_SUCCESS, strmsg);
  916. }
  917. }
  918. }
  919. else
  920. {
  921. LogWarn(Severity_Low, Error_Debug, LOG_EVT_RECORD_SAVED_FAILED, "sales videos not exist or have been deleted");
  922. ErrorCode = Error_NotExist;
  923. }
  924. }
  925. }
  926. else{
  927. ErrorCode = Error_InvalidState;
  928. }
  929. return ErrorCode;
  930. }
  931. CSimpleStringA CSalesRecorderEntity::GetTerminalStage()
  932. {
  933. CSmartPointer<IEntityFunction> Func = GetFunction();
  934. CSimpleStringA strValue = "";
  935. Func->GetSysVar("TerminalStage", strValue);
  936. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("TerminalStage:%s", (LPCTSTR)strValue);
  937. return strValue;
  938. }
  939. bool CSalesRecorderEntity::SecureClientConnect()
  940. {
  941. SecureClientRelease();
  942. return true;
  943. }
  944. void CSalesRecorderEntity::SecureClientRelease()
  945. {
  946. }
  947. // 请求InteractiveControl结束录像 add by ly 2018/03/12
  948. ErrorCodeEnum CSalesRecorderEntity::StopRecordVideo()
  949. {
  950. auto rc = Error_Succeed;
  951. auto pUIClient = new InteractiveControl::UIService_ClientBase(this);
  952. if(pUIClient->Connect() != Error_Succeed)
  953. {
  954. pUIClient->SafeDelete();
  955. pUIClient = NULL;
  956. rc = Error_DevConnFailed;
  957. }
  958. else
  959. {
  960. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("UIClient connected success!");
  961. InteractiveControl::UIService_StopRecordVideo_Req req;
  962. InteractiveControl::UIService_StopRecordVideo_Ans ans;
  963. rc = pUIClient->StopRecordVideo(req, ans, 5000);
  964. if(rc != Error_Succeed)
  965. {
  966. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Stop record video failed return 0x%08x", rc);
  967. }
  968. pUIClient->GetFunction()->CloseSession();
  969. pUIClient = NULL;
  970. }
  971. return rc;
  972. }
  973. ErrorCodeEnum CSalesRecorderEntity::HandleStartRecord(const char *pszMessage, const bool bRemoteRecord)
  974. {
  975. ErrorCodeEnum Error = Error_Succeed;
  976. eRvcRecordType eRecordType = eSingleSide;
  977. if (NULL == pszMessage){
  978. return Error_Param;
  979. }
  980. size_t ulen = strlen(pszMessage);
  981. char *tmp = new char[ulen+1];
  982. m_bEwsRecord = FALSE;
  983. if ((false == bRemoteRecord) && (ulen >= EWS_CAMERA_FLAG_LEN) && (0 == strnicmp(pszMessage,EWS_CAMERA_FLAG,EWS_CAMERA_FLAG_LEN)))
  984. {
  985. m_bEwsRecord = TRUE;
  986. strncpy(tmp, pszMessage+EWS_CAMERA_FLAG_LEN, ulen-EWS_CAMERA_FLAG_LEN);
  987. }
  988. else{
  989. strncpy(tmp, pszMessage, ulen);
  990. }
  991. char *result[32] = {0};
  992. CStringSplit(tmp, result, "@");
  993. memset(m_SalesVideoName, 0, MAX_PATH);
  994. if (result[4]) {
  995. snprintf(m_SalesVideoName, MAX_PATH, "%s", result[4]);//录像名:录像类型标志_录像流水号(如S_C13213EF)
  996. }
  997. RecordSubTitle subTitle;
  998. ZeroMemory(&subTitle,sizeof(RecordSubTitle));
  999. if (result[5]) {
  1000. CSimpleStringA strCardNo = DecryptString(result[5]);
  1001. if (sizeof(subTitle.CustCardNo) > strCardNo.GetLength()) {
  1002. strcpy_s(subTitle.CustCardNo, 24, strCardNo.GetData());
  1003. }
  1004. else {
  1005. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Invalid CustCardNo.");
  1006. }
  1007. }
  1008. char* pStr = result[6];
  1009. if (pStr) {
  1010. CSimpleStringW szCustName = CSimpleStringA2W(pStr);
  1011. if (szCustName.GetLength() <= 4) {
  1012. strcpy(subTitle.CustName, pStr);
  1013. }
  1014. else {
  1015. CSimpleStringW aa = szCustName.SubString(0, 4);
  1016. sprintf(subTitle.CustName, "%s...", (LPCTSTR)CSimpleStringW2A(aa));
  1017. }
  1018. }
  1019. pStr = result[7];
  1020. if (pStr) {
  1021. int nProductCodeLen = strlen(pStr);
  1022. if (nProductCodeLen <= 10) {
  1023. strcpy(subTitle.ProductCode, pStr);
  1024. }
  1025. else {
  1026. char aa[5] = { 0 }, bb[5] = { 0 };
  1027. strncpy(aa, pStr, 4);
  1028. strncpy(bb, pStr + nProductCodeLen - 4, 4);
  1029. sprintf(subTitle.ProductCode, "%s...%s", aa, bb);
  1030. }
  1031. }
  1032. pStr = result[8];
  1033. if (pStr) {
  1034. CSimpleStringW szProductName = CSimpleStringA2W(pStr);
  1035. if (szProductName.GetLength() <= 5) {
  1036. strcpy(subTitle.ProductName, pStr);
  1037. }
  1038. else {
  1039. CSimpleStringW aa = szProductName.SubString(0, 3);
  1040. CSimpleStringW bb = szProductName.SubString(szProductName.GetLength() - 2, 2);
  1041. sprintf(subTitle.ProductName, "%s...%s", (LPCTSTR)CSimpleStringW2A(aa), (LPCTSTR)CSimpleStringW2A(bb));
  1042. }
  1043. }
  1044. if (result[9]) {
  1045. strcpy(subTitle.SapID, result[9]);
  1046. } else {
  1047. subTitle.SapID[0] = '\0';
  1048. }
  1049. if (result[10]) {
  1050. pStr = result[10];
  1051. CSimpleStringW szCustManagerName = CSimpleStringA2W(pStr);
  1052. if (szCustManagerName.GetLength() <= 4) {
  1053. strcpy(subTitle.CustManagerName, result[10]);
  1054. }
  1055. else {
  1056. CSimpleStringW aa = szCustManagerName.SubString(0,4);
  1057. sprintf(subTitle.CustManagerName,"%s...",(LPCTSTR)CSimpleStringW2A(aa));
  1058. }
  1059. } else {
  1060. subTitle.CustManagerName[0] = '\0';
  1061. }
  1062. delete[] tmp;
  1063. tmp = NULL;
  1064. SubtitleParam subtitleParam;
  1065. ZeroMemory(&subtitleParam,sizeof(SubtitleParam));
  1066. subtitleParam.bSubtitle = TRUE;
  1067. subtitleParam.bSubtitleSection = TRUE;
  1068. subtitleParam.topSubtitleData[0] = '\0';
  1069. if (strlen(subTitle.SapID)>0&&strlen(subTitle.CustManagerName)>0) // 有无客户经理的双录字幕 edit by ly @2018/01/10
  1070. {
  1071. swprintf(subtitleParam.bottomSubtitleData1, MAX_PATH, L"%s %s %s", subTitle.CustCardNo, subTitle.CustName, subTitle.ProductCode);
  1072. swprintf(subtitleParam.bottomSubtitleData2, MAX_PATH, L"%s %s %s", subTitle.ProductName, subTitle.SapID, subTitle.CustManagerName);
  1073. }
  1074. else
  1075. {
  1076. swprintf(subtitleParam.bottomSubtitleData1, MAX_PATH, L"%s %s", subTitle.CustCardNo, subTitle.CustName);
  1077. swprintf(subtitleParam.bottomSubtitleData2, MAX_PATH, L"%s %s", subTitle.ProductCode, subTitle.ProductName);
  1078. }
  1079. int i_audio_out_bitrate = m_audio_out_bitrate;
  1080. if (bRemoteRecord)
  1081. {
  1082. if (m_eDeviceType == eStand2sType) { //如果是大机
  1083. eRecordType = eStand2Agent; //可视柜台大机的双向录像
  1084. }
  1085. else{
  1086. eRecordType = ePad2Agent; //可视柜台pad的双向录像
  1087. }
  1088. if(256 == m_audio_out_bitrate){
  1089. i_audio_out_bitrate = 128;
  1090. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("change remote record audio out bitrate to %d.", i_audio_out_bitrate);
  1091. }
  1092. }
  1093. StartRecord(m_SalesVideoName, 90, i_audio_out_bitrate, &subtitleParam, m_bWholeSection, FALSE, eRecordType);
  1094. char strmsg[MAX_PATH] = { 0 };
  1095. snprintf(strmsg, MAX_PATH, "start remote record %s.", m_SalesVideoName);
  1096. LogWarn(Severity_Low, Error_Debug, LOG_EVT_START_REMOTERECORD, strmsg);
  1097. return Error;
  1098. }
  1099. ErrorCodeEnum CSalesRecorderEntity::HandleStopRecord(const char *pszMessage)
  1100. {
  1101. ErrorCodeEnum ErrorCode = StopRecord();
  1102. return ErrorCode;
  1103. }
  1104. ErrorCodeEnum CSalesRecorderEntity::HandleDisplayVideo()
  1105. {
  1106. // 视频播放 libwmpplayer
  1107. m_bIsShowVideo = TRUE;
  1108. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("play record file name is %s!", m_SalesVideoName);
  1109. ErrorCodeEnum ErrorCode = ShowVideo(m_SalesVideoName);
  1110. return ErrorCode;
  1111. }
  1112. ErrorCodeEnum CSalesRecorderEntity::HandlePlaySalesRecordVideo(int iWndX, int iWndY, int iWndWidth, int iWndHeight)
  1113. {
  1114. // 视频播放 libwmpplayer
  1115. m_bIsShowVideo = TRUE;
  1116. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("play sales record video file name is %s!", m_SalesVideoName);
  1117. ErrorCodeEnum ErrorCode = PlaySalesRecordVideo(m_SalesVideoName, iWndX, iWndY, iWndWidth, iWndHeight);
  1118. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("play sales record video return code is 0x%08x.", ErrorCode);
  1119. return ErrorCode;
  1120. }
  1121. ErrorCodeEnum CSalesRecorderEntity::HandleStopShowVideo()
  1122. {
  1123. // 视频播放 libwmpplayer
  1124. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("stop show video record file name is %s!", m_SalesVideoName);
  1125. ErrorCodeEnum ErrorCode = Error_Succeed;
  1126. if(m_bIsShowVideo)
  1127. {
  1128. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("m_pPlayer = %p while play!", m_pPlayer);
  1129. //m_pPlayer->Close();
  1130. m_bIsShowVideo = FALSE;
  1131. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("succeed to stop show video!");
  1132. }
  1133. else{
  1134. ErrorCode = Error_NotImpl;
  1135. }
  1136. return ErrorCode;
  1137. }
  1138. ErrorCodeEnum CSalesRecorderEntity::HandleSaveVideo()
  1139. {
  1140. ErrorCodeEnum ErrorCode = Error_Succeed;
  1141. // 将视频从tmp移动到uploadvideo
  1142. if (!strstr(m_SalesVideoName, "OFL")) // edit by ly 20180228
  1143. {
  1144. ErrorCode = SaveVideo(m_SalesVideoName+2);
  1145. }
  1146. else
  1147. {
  1148. ErrorCode = SaveVideo(m_SalesVideoName+4);
  1149. }
  1150. ZeroMemory(m_SalesVideoName,sizeof(m_SalesVideoName));
  1151. return ErrorCode;
  1152. }
  1153. void CSalesRecorderEntity::HandleDeleteVideo()
  1154. {
  1155. // 删除tmp中的视频
  1156. DeleteVideo(m_SalesVideoName);
  1157. ZeroMemory(m_SalesVideoName,sizeof(m_SalesVideoName));
  1158. }
  1159. void CSalesRecorderEntity::HandleVideoAppendWatermark(const char* pszMessage)
  1160. {
  1161. if (NULL == pszMessage){
  1162. return;
  1163. }
  1164. wchar_t*result[10] = {0};
  1165. auto arr1 = CSimpleStringA2W(pszMessage).Split('|');
  1166. auto arr2 = CAutoArray<CSimpleStringW>(arr1.GetCount());
  1167. int icount = sizeof(result)/sizeof(char*);
  1168. for (int i = 0; i < arr1.GetCount() && i < sizeof(result)/sizeof(char*); i++)
  1169. {
  1170. arr2[i] = CSimpleStringW(arr1[i]);
  1171. result[i] = (wchar_t*)arr2[i].GetData();
  1172. }
  1173. if (m_bStarted && (NULL != m_pRecorder))
  1174. {
  1175. m_pRecorder->SetRightVideoWaterMark(result[1]);
  1176. }
  1177. }
  1178. ErrorCodeEnum CSalesRecorderEntity::HandleSalesRecordEntityException(const char* pszMessage)
  1179. {
  1180. // 通知到业务中台
  1181. SalesRecordException evt;
  1182. evt.failedmsg = CSimpleStringA2W(pszMessage==NULL?"现场销售双录过程出现异常!":pszMessage);
  1183. SpSendBroadcast(GetFunction(), SP_MSG_OF(SalesRecordException), SP_MSG_SIG_OF(SalesRecordException), evt);
  1184. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("[dbg] SalesRecord entity exception broadcast sent!");
  1185. //停止录像
  1186. StopRecord();
  1187. m_bNeedRestart = true;
  1188. //重启实体
  1189. RealSelfCheck();
  1190. return Error_Succeed;
  1191. }
  1192. BOOL CSalesRecorderEntity::InitSalesRecorder()
  1193. {
  1194. BOOL bRet = FALSE;
  1195. if (m_bApplyHighQuality)
  1196. {
  1197. bRet = GetHighQualityOnSiteSalesRecorder();
  1198. }
  1199. else
  1200. {
  1201. bRet = GetStandardQualityOnSiteSalesRecorder();
  1202. }
  1203. return bRet;
  1204. }
  1205. BOOL CSalesRecorderEntity::ReleaseSalesRecorder()
  1206. {
  1207. if (m_pRecorder) {
  1208. delete m_pRecorder;
  1209. m_pRecorder = NULL;
  1210. }
  1211. return TRUE;
  1212. }
  1213. ErrorCodeEnum CSalesRecorderEntity::RealSelfCheck()
  1214. {
  1215. ErrorCodeEnum Error = Error_Succeed;
  1216. SelfChekerClient* pSelfcheckClient = new SelfChekerClient(this);
  1217. Error = pSelfcheckClient->Connect();
  1218. if (Error != Error_Succeed)
  1219. {
  1220. pSelfcheckClient->SafeDelete();
  1221. pSelfcheckClient = NULL;
  1222. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("SelfcheckClient connect fail!");
  1223. }
  1224. else
  1225. {
  1226. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("SelfcheckClient connect success!");
  1227. }
  1228. if (pSelfcheckClient)
  1229. {
  1230. SelfChecker::SelfCheckerService_RealCheck_Req req;
  1231. req.name = GetEntityName();
  1232. SelfChecker::SelfCheckerService_RealCheck_Ans ans;
  1233. DWORD Timeout = 500;
  1234. Error = pSelfcheckClient->RealCheck(req,ans,Timeout);
  1235. if (Error!=Error_Succeed)
  1236. {
  1237. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("RealSelfcheck fail!");
  1238. }
  1239. else
  1240. {
  1241. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("RealSelfcheck success!");
  1242. }
  1243. pSelfcheckClient->GetFunction()->CloseSession();
  1244. }
  1245. return Error;
  1246. }
  1247. #ifdef RVC_OS_WIN
  1248. bool IsMatchedVideo(WIN32_FIND_DATA fileData)
  1249. {
  1250. bool bRet = false;
  1251. if ('S' == fileData.cFileName[0] || 'W' == fileData.cFileName[0]){
  1252. SYSTEMTIME sysTime;
  1253. FileTimeToSystemTime(&fileData.ftCreationTime, &sysTime);
  1254. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("File %s create data info is %d %d %d.", fileData.cFileName, sysTime.wYear, sysTime.wMonth, sysTime.wDay);
  1255. if ((2020 == sysTime.wYear) && (sysTime.wMonth == 1)){
  1256. if (sysTime.wDay >= 3 && sysTime.wDay <= 10){
  1257. bRet = true;
  1258. }
  1259. }
  1260. }
  1261. return bRet;
  1262. }
  1263. void CSalesRecorderEntity::UploadTempPathVideos()
  1264. {
  1265. CSimpleStringA sourPath;
  1266. CSimpleStringA destPath;
  1267. ErrorCodeEnum Error = GetFunction()->GetPath("Temp", sourPath);
  1268. Error = GetFunction()->GetPath("UploadVideo", destPath);
  1269. if (sourPath.GetLength() > 0 && sourPath[sourPath.GetLength()-1] != SPLIT_SLASH) {
  1270. sourPath += SPLIT_SLASH_STR;
  1271. }
  1272. if (destPath.GetLength() > 0 && destPath[destPath.GetLength()-1] != SPLIT_SLASH) {
  1273. destPath += SPLIT_SLASH_STR;
  1274. }
  1275. if(Error == Error_Succeed)
  1276. {
  1277. char srcFilePath[MAX_PATH]={0};
  1278. WIN32_FIND_DATA FindFileData;
  1279. HANDLE hFind;
  1280. BOOL fFinished = FALSE;
  1281. sprintf_s(srcFilePath, MAX_PATH, "%s*.wmv", sourPath);
  1282. hFind = FindFirstFile(srcFilePath, &FindFileData);
  1283. if (INVALID_HANDLE_VALUE != hFind)
  1284. {
  1285. while (!fFinished)
  1286. {
  1287. if (FILE_ATTRIBUTE_DIRECTORY & FindFileData.dwFileAttributes)
  1288. {
  1289. continue;
  1290. }
  1291. if (IsMatchedVideo(FindFileData)){
  1292. CSimpleStringA sourFileName = CSimpleStringA::Format("%s%s", (LPCSTR)sourPath, FindFileData.cFileName);
  1293. CSimpleStringA destFileName = CSimpleStringA::Format("%sBAK_%s", (LPCSTR)destPath, FindFileData.cFileName);
  1294. if(!MoveFile((LPCSTR)sourFileName, (LPCSTR)destFileName)) {
  1295. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Error Code %lu while move %s ", GetLastError(), (LPCSTR)sourFileName);
  1296. }else{
  1297. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Move File %s success.", (LPCSTR)sourFileName);
  1298. }
  1299. }
  1300. else{
  1301. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("File (%s) is not matched.", FindFileData.cFileName);
  1302. }
  1303. if (!FindNextFile(hFind, &FindFileData))
  1304. {
  1305. if (GetLastError() == ERROR_NO_MORE_FILES)
  1306. {
  1307. fFinished = TRUE;
  1308. }
  1309. else
  1310. {
  1311. break;
  1312. }
  1313. }
  1314. }
  1315. FindClose(hFind);
  1316. }
  1317. }
  1318. }
  1319. #else
  1320. /*
  1321. **time_t转SYSTEMTIME
  1322. */
  1323. SYSTEMTIME Time_tToSystemTime(time_t t)
  1324. {
  1325. tm temptm = *localtime(&t);
  1326. SYSTEMTIME st = { 1900 + temptm.tm_year,
  1327. 1 + temptm.tm_mon,
  1328. temptm.tm_wday,
  1329. temptm.tm_mday,
  1330. temptm.tm_hour,
  1331. temptm.tm_min,
  1332. temptm.tm_sec,
  1333. 0 };
  1334. return st;
  1335. }
  1336. bool IsMatchedVideo(LPCTSTR path, struct dirent* file)
  1337. {
  1338. bool bRet = false;
  1339. if ((file->d_reclen > 0) && ('S' == file->d_name[0] || 'W' == file->d_name[0])){
  1340. struct stat fileInfo;
  1341. char ttp[256];
  1342. bzero(ttp, sizeof(ttp));
  1343. strcat(ttp, path);
  1344. if (strcmp(ttp, "/") != 0)strcat(ttp, "/");//如果是根目录不需要加
  1345. strcat(ttp, file->d_name);
  1346. if (stat(ttp, &fileInfo) == 0) {
  1347. SYSTEMTIME sysTime;
  1348. sysTime = Time_tToSystemTime(fileInfo.st_mtime);
  1349. 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);
  1350. if ((2020 == sysTime.wYear) && (sysTime.wMonth == 1)) {
  1351. if (sysTime.wDay >= 3 && sysTime.wDay <= 10) {
  1352. bRet = true;
  1353. }
  1354. }
  1355. }
  1356. }
  1357. return bRet;
  1358. }
  1359. void CSalesRecorderEntity::UploadTempPathVideos() {
  1360. CSimpleStringA sourPath;
  1361. CSimpleStringA destPath;
  1362. ErrorCodeEnum Error = GetFunction()->GetPath("Temp", sourPath);
  1363. Error = GetFunction()->GetPath("UploadVideo", destPath);
  1364. if (sourPath.GetLength() > 0 && sourPath[sourPath.GetLength() - 1] != SPLIT_SLASH) {
  1365. sourPath += SPLIT_SLASH_STR;
  1366. }
  1367. if (destPath.GetLength() > 0 && destPath[destPath.GetLength() - 1] != SPLIT_SLASH) {
  1368. destPath += SPLIT_SLASH_STR;
  1369. }
  1370. if (Error == Error_Succeed)
  1371. {
  1372. char srcFilePath[MAX_PATH] = { 0 };
  1373. DIR* pDir = NULL;
  1374. struct dirent* pFile = NULL;
  1375. snprintf(srcFilePath, MAX_PATH, "%s*.%s", sourPath, RVC_RECORD_SUFFIX);
  1376. pDir = opendir(sourPath);
  1377. if (pDir == NULL) return ;
  1378. while ((pFile = readdir(pDir)) != NULL) {
  1379. if (pFile->d_type & DT_DIR) {
  1380. //m_pHostApi->Debug("MoveTempPathVideos DIR name: %s.", pFile->d_name);
  1381. continue;
  1382. }
  1383. else {
  1384. //m_pHostApi->Debug("MoveTempPathVideos FILE name: %s.", pFile->d_name);
  1385. if (IsMatchedVideo((LPCSTR)sourPath, pFile)) {
  1386. CSimpleStringA sourFileName = CSimpleStringA::Format("%s%s", (LPCSTR)sourPath, pFile->d_name);
  1387. CSimpleStringA destFileName = CSimpleStringA::Format("%sBAK_%s", (LPCSTR)destPath, pFile->d_name);
  1388. if (rename(sourFileName.GetData(), destFileName.GetData())) {
  1389. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Error Code %lu while move %s.", errno, sourFileName.GetData());
  1390. }
  1391. else {
  1392. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Move File %s success.", sourFileName.GetData());
  1393. }
  1394. }
  1395. else {
  1396. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("File (%s) is not matched.", pFile->d_name);
  1397. }
  1398. }
  1399. }
  1400. closedir(pDir);
  1401. }
  1402. }
  1403. #endif
  1404. ErrorCodeEnum CSalesRecorderEntity::SetRecordAudioQuality(int iAudioQuality)
  1405. {
  1406. ErrorCodeEnum eRet = Error_Succeed;
  1407. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("iAudioQuality == %d.", iAudioQuality);
  1408. switch (iAudioQuality)
  1409. {
  1410. case 1:
  1411. m_eAudioOutQuality = eLowDefinition;
  1412. break;
  1413. case 2:
  1414. m_eAudioOutQuality = eStandardDefinition;
  1415. break;
  1416. case 3:
  1417. m_eAudioOutQuality = eHighDefinition;
  1418. break;
  1419. case 4:
  1420. m_eAudioOutQuality = eUltraHD;
  1421. break;
  1422. default:
  1423. m_eAudioOutQuality = eUltraHD;
  1424. break;
  1425. }
  1426. return eRet;
  1427. }
  1428. ErrorCodeEnum CSalesRecorderEntity::SetRecordAudioNsPolicy(int iNsPolicy)
  1429. {
  1430. ErrorCodeEnum eRet = Error_Succeed;
  1431. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("iNsPolicy == %d.", iNsPolicy);
  1432. if (1 == iNsPolicy || 3 == iNsPolicy){
  1433. m_iAudioNsPolicy = iNsPolicy;
  1434. }
  1435. else{
  1436. m_iAudioNsPolicy = 2;
  1437. }
  1438. return eRet;
  1439. }
  1440. DeviceTypeEnum CSalesRecorderEntity::RvcGetDeviceType()
  1441. {
  1442. DeviceTypeEnum eType = eStand2sType;
  1443. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  1444. CSystemStaticInfo stStaticinfo;
  1445. spFunction->GetSystemStaticInfo(stStaticinfo);
  1446. m_terminalNo = stStaticinfo.strTerminalID;
  1447. if (stricmp(stStaticinfo.strMachineType, "RVC.PAD") == 0) {
  1448. if (stricmp(stStaticinfo.strSite, "CMB.FLB") == 0) {
  1449. eType = eMobilePadType;
  1450. }
  1451. else {
  1452. eType = ePadtype;
  1453. }
  1454. }
  1455. else if (stricmp(stStaticinfo.strMachineType, "RVC.Desk2S") == 0) {
  1456. eType = eDesk2SType;
  1457. WORD nMajor = stStaticinfo.MachineVersion.GetMajor();
  1458. WORD nMinor = stStaticinfo.MachineVersion.GetMinor();
  1459. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("MachineVersion is %d.%d", nMajor, nMinor);
  1460. if (2 == nMajor) {
  1461. eType = eDesk2SIntegratedType;
  1462. }
  1463. }
  1464. else if (stricmp(stStaticinfo.strMachineType, "RPM.Stand1S") == 0) {
  1465. eType = eRpm1sType;
  1466. }
  1467. else if (stricmp(stStaticinfo.strMachineType, "RVC.Desk1S") == 0) {
  1468. eType = eDesk1SType;
  1469. }
  1470. else {
  1471. eType = eStand2sType;
  1472. }
  1473. if (eType >= 0 && eType < sizeof(Device_Type_Table) / sizeof(char*)) {
  1474. LOG_TRACE("device type is %s.", Device_Type_Table[eType]);
  1475. }
  1476. return eType;
  1477. }
  1478. SelfChekerClient::SelfChekerClient( CSalesRecorderEntity *pEntity ) : SelfChecker::SelfCheckerService_ClientBase(pEntity)
  1479. {
  1480. }
  1481. SP_BEGIN_ENTITY_MAP()
  1482. SP_ENTITY(CSalesRecorderEntity)
  1483. SP_END_ENTITY_MAP()