mod_SalesRecorder.cpp 51 KB

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