mod_SalesRecorder.cpp 84 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707
  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 "offline_video_record_t.h"
  16. #include <winpr/file.h>
  17. #include <winpr/ini.h>
  18. #include <winpr/string.h>
  19. #include <winpr/thread.h>
  20. #include <winpr/timezone.h>
  21. #include "mod_MobileDial/MobileDial_client_g.h"
  22. #include "mod_MobileDial/MobileDial_def_g.h"
  23. #include "mod_interactivecontrol/InteractiveControl_client_g.h"
  24. #include "mod_interactivecontrol/InteractiveControl_def_g.h"
  25. #define LOG_EVT_UI_RECORDFAILED 0x31500001 //双录失败
  26. #define LOG_EVT_SALESRECORD_ENTITY_EXCEPTION 0x31500002 //销售双录实体异常
  27. #define LOG_EVT_SALESRECORD_FINISHED 0x31500003 //销售双录结束
  28. #define LOG_EVT_AUDIOSTREAM_TRANSMISSION_FAILED 0x31600001 //音频流传输失败
  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 TIMERID_UPOFLRECORD 1 // 离线双录提交计时器ID add by ly 2018/02/13
  39. #define TIMERID_DISKCHK 2 // 离线磁盘检查计时器ID add by ly 2018/02/24
  40. #define UPLOAD_CYCLE 300000 // 离线双录提交定时间隔 add by ly 2018/02/13
  41. #define DISKCHK_CYCLE 60000 // 离线磁盘检查计时间隔 add by ly 2018/02/24
  42. #define MAX_DISK_PERCENT 95 // 磁盘最大占用百分比 add by ly 2018/02/24
  43. static ErrorCodeEnum ParseIPAddress(const char *str, CSimpleStringA &ip, int &port)
  44. {
  45. ErrorCodeEnum Error = Error_Unexpect;
  46. if (str) {
  47. char tmp1[32] = {};
  48. char tmp2[16] = {};
  49. sscanf(str, "%s %s", tmp1, tmp2);
  50. if (tmp1[0] != 0 && tmp2[0] != 0)
  51. {
  52. ip = tmp1;
  53. port = atoi(tmp2);
  54. Error = Error_Succeed;
  55. }
  56. else
  57. return Error;
  58. }
  59. return Error;
  60. }
  61. static BOOL CheckDiskStatus(const char *szRoot, int nPercent, int *pFreeRatio)
  62. {
  63. #ifdef RVC_OS_WIN
  64. _ULARGE_INTEGER lpFreeBytesAvailableToCaller = {}, lpTotalNumberOfBytes = {}, lpTotalNumberOfFreeBytes = {};
  65. BOOL ret = GetDiskFreeSpaceEx(szRoot, &lpFreeBytesAvailableToCaller, &lpTotalNumberOfBytes, &lpTotalNumberOfFreeBytes);
  66. if (ret == 0)
  67. {
  68. Dbg("CheckDiskStatus.GetDiskFreeSpaceEx failed(%d).",GetLastError());
  69. return FALSE;
  70. }
  71. DWORD dwTotal = lpTotalNumberOfBytes.QuadPart/1048576;
  72. DWORD dwTotalFree = lpTotalNumberOfFreeBytes.QuadPart/1048576;
  73. int ratio = dwTotalFree*100/dwTotal;
  74. *pFreeRatio = ratio;
  75. Dbg("free disk %d MB, %d percent free.\n", dwTotalFree, ratio);
  76. //if (ratio < (100-MAX_DISK_PERCENT))
  77. if (ratio < (100-nPercent))
  78. {
  79. return FALSE;
  80. }
  81. return TRUE;
  82. #else
  83. //todo 调用resourcewatcher
  84. return TRUE;
  85. #endif
  86. }
  87. static int hch2int(char hch)
  88. {
  89. if (hch >= '0' && hch <= '9')
  90. return hch-'0';
  91. else if (hch >= 'a' && hch <= 'f')
  92. return hch-'a'+10;
  93. else if (hch >= 'A' && hch <= 'F')
  94. return hch-'A'+10;
  95. return 0;
  96. }
  97. static long hexstr2int(const char *str, int len)
  98. {
  99. long result = 0;
  100. if (str && len <= strlen(str)) {
  101. for (int i = 0; i < len; ++i) {
  102. result += (hch2int(str[i]) << ((len-i-1) << 2));
  103. }
  104. }
  105. return result;
  106. }
  107. static CSimpleStringA VideoSerialID2TimeString(const char *videoserialid)
  108. {
  109. DWORD nTimeTicks = hexstr2int(videoserialid,8);
  110. return ((CSmallDateTime)nTimeTicks).ToTimeString();
  111. }
  112. // 按分隔符分隔字符串 add by ly
  113. static void CStringSplit(char *str, char **result, const char *del)
  114. {
  115. char *p = strtok(str, del);
  116. while(p != NULL)
  117. {
  118. *result++ = p;
  119. p = strtok(NULL, del);
  120. }
  121. }
  122. #ifdef RVC_OS_WIN
  123. // 寻找某目录下与通配符匹配的文件
  124. static BOOL FindMatchedFile(LPCSTR sFindPath, LPCSTR sFindFileName, ULONGLONG& uCountFile)
  125. {
  126. char sPath[MAX_PATH];
  127. ZeroMemory(sPath, MAX_PATH);
  128. char sFormatFileName[MAX_PATH + 2] = "*";
  129. WIN32_FIND_DATA FindFileData;
  130. HANDLE hFind;
  131. BOOL fFinished = FALSE;
  132. strcpy(sFormatFileName, sFindPath);
  133. if (sFindPath[strlen(sFindPath) - 1] != SPLIT_SLASH)
  134. {
  135. strcat(sFormatFileName, SPLIT_SLASH_STR);
  136. strcat(sFormatFileName, "*");
  137. }
  138. else
  139. {
  140. strcat(sFormatFileName, "*");
  141. }
  142. strcat(sFormatFileName, sFindFileName);
  143. strcat(sFormatFileName, "*");
  144. hFind = FindFirstFile(sFormatFileName, &FindFileData);
  145. if (hFind == INVALID_HANDLE_VALUE)
  146. {
  147. return FALSE;
  148. }
  149. else
  150. {
  151. while (!fFinished)
  152. {
  153. strcpy(sPath, sFindPath);
  154. if (sPath[strlen(sPath) - 1] != SPLIT_SLASH)
  155. {
  156. strcat(sPath, SPLIT_SLASH_STR);
  157. }
  158. strcat(sPath, FindFileData.cFileName);
  159. if (!(FILE_ATTRIBUTE_DIRECTORY & FindFileData.dwFileAttributes))
  160. {
  161. ++uCountFile;
  162. }
  163. if (!FindNextFile(hFind, &FindFileData))
  164. {
  165. if (GetLastError() == ERROR_NO_MORE_FILES)
  166. {
  167. fFinished = TRUE;
  168. }
  169. else
  170. {
  171. break;
  172. }
  173. }
  174. }
  175. FindClose(hFind);
  176. }
  177. return TRUE;
  178. }
  179. #else
  180. static BOOL FindMatchedFile(LPCSTR sFindPath, LPCSTR sFindFileName, ULONGLONG& uCountFile)
  181. {
  182. DIR* pDir = NULL;
  183. struct dirent* pFile = NULL;
  184. CSimpleStringA tmpFindFileName = sFindFileName;
  185. pDir = opendir(sFindPath);
  186. if (pDir == NULL) return FALSE;
  187. //linux不支持*查找,去掉后缀
  188. if (tmpFindFileName.IsEndWith("*.wmv")) {
  189. tmpFindFileName = tmpFindFileName.SubString(0, tmpFindFileName.GetLength() - 5);
  190. }
  191. while ((pFile = readdir(pDir)) != NULL) {
  192. if (pFile->d_type & DT_DIR) {
  193. //m_pHostApi->Debug("FindMatchedFile DIR name: %s.", pFile->d_name);
  194. if (strcmp(pFile->d_name, ".") == 0
  195. || strcmp(pFile->d_name, "..") == 0) continue;
  196. char Path[256];
  197. int len = strlen(sFindPath);
  198. strncpy(Path, sFindPath, len + 1);
  199. if (sFindPath[len - 1] != '/') strncat(Path, "/", 2);
  200. strncat(Path, pFile->d_name, strlen(pFile->d_name) + 1);
  201. //m_pHostApi->Debug("FindMatchedFile Path: %s.", Path);
  202. FindMatchedFile(Path, (LPCTSTR)tmpFindFileName, uCountFile);
  203. }
  204. else {
  205. //m_pHostApi->Debug("FindMatchedFile FILE name: %s.", pFile->d_name);
  206. if (strstr(pFile->d_name, (LPCTSTR)tmpFindFileName) != NULL) {
  207. ++uCountFile;
  208. }
  209. }
  210. }
  211. closedir(pDir);
  212. return TRUE;
  213. }
  214. #endif
  215. static bool OFLCmp(const OFLVideoRecord &a, const OFLVideoRecord &b)
  216. {
  217. return strcmp(a.VideoSerialID,b.VideoSerialID)>0;
  218. }
  219. void SalesRecordServiceSession::Handle_GetOFLVideoRecords( SpReqAnsContext<SalesRecorderSerVice_GetOFLVideoRecords_Req, SalesRecorderSerVice_GetOFLVideoRecords_Ans>::Pointer ctx )
  220. {
  221. CSimpleStringA Name = CSimpleStringW2A(ctx->Req.Name);
  222. CSimpleStringA CardNo = CSimpleStringW2A(ctx->Req.CardNo);
  223. CSimpleStringA BeginTime = CSimpleStringW2A(ctx->Req.BeginTime);
  224. CSimpleStringA EndTime = CSimpleStringW2A(ctx->Req.EndTime);
  225. /*Dbg("Handle_GetOFLVideoRecords:Name=%s,CardNo=%s,BeginTime=%s,EndTime=%s",(LPCTSTR)Name,(LPCTSTR)CardNo,(LPCTSTR)BeginTime,(LPCTSTR)EndTime);*/
  226. Dbg("Handle_GetOFLVideoRecords:BeginTime=%s,EndTime=%s",(LPCTSTR)BeginTime,(LPCTSTR)EndTime);
  227. ctx->Ans.VideoRecords = m_pEntity->GetOFLVideoRecords(Name, CardNo, BeginTime, EndTime);
  228. ctx->Answer(Error_Succeed);
  229. }
  230. void SalesRecordServiceSession::Handle_CheckVideoDiskStatus( SpReqAnsContext<SalesRecorderSerVice_CheckVideoDiskStatus_Req, SalesRecorderSerVice_CheckVideoDiskStatus_Ans>::Pointer ctx )
  231. {
  232. int nFreeRatio = 0;
  233. int bSufficient = CheckDiskStatus((LPCTSTR)ctx->Req.DriveLetter,m_pEntity->m_max_disk_percent,&nFreeRatio);
  234. ctx->Ans.IsSufficient = bSufficient;
  235. ctx->Ans.FreeRatio = nFreeRatio;
  236. ctx->Answer(Error_Succeed);
  237. }
  238. void SalesRecordServiceSession::Handle_PlayVideo(SpReqAnsContext<SalesRecorderSerVice_PlayVideo_Req, SalesRecorderSerVice_PlayVideo_Ans>::Pointer ctx)
  239. {
  240. Dbg("PlayVideo name is %s.", (LPCTSTR)CSimpleStringW2A(ctx->Req.VideoName));
  241. ErrorCodeEnum ErrorCode = m_pEntity->HandleDisplayVideo();
  242. ctx->Answer(ErrorCode);
  243. }
  244. void SalesRecordServiceSession::Handle_SaveVideo(SpReqAnsContext<SalesRecorderSerVice_SaveVideo_Req, SalesRecorderSerVice_SaveVideo_Ans>::Pointer ctx)
  245. {
  246. Dbg("Save Video name is %s.", (LPCTSTR)CSimpleStringW2A(ctx->Req.VideoName));
  247. ErrorCodeEnum ErrorCode = m_pEntity->HandleSaveVideo();
  248. ctx->Answer(ErrorCode);
  249. }
  250. void SalesRecordServiceSession::Handle_StopRecord(SpReqAnsContext<SalesRecorderSerVice_StopRecord_Req, SalesRecorderSerVice_StopRecord_Ans>::Pointer ctx)
  251. {
  252. Dbg("Stop Record name is %s.", (LPCTSTR)CSimpleStringW2A(ctx->Req.VideoName));
  253. ErrorCodeEnum ErrorCode = m_pEntity->HandleStopRecord((LPCTSTR)CSimpleStringW2A(ctx->Req.VideoName));
  254. ctx->Answer(ErrorCode);
  255. }
  256. void SalesRecordServiceSession::Handle_SetAudioTransFlag(SpReqAnsContext<SalesRecorderSerVice_SetAudioTransFlag_Req, SalesRecorderSerVice_SetAudioTransFlag_Ans>::Pointer ctx)
  257. {
  258. Dbg("Audio transmission flag is %s.", ctx->Req.TransFlag ? "true" : "false");
  259. ErrorCodeEnum ErrorCode = m_pEntity->HandleSetAudioTransmissionFlag(ctx->Req.TransFlag);
  260. ctx->Answer(ErrorCode);
  261. }
  262. void SalesRecordServiceSession::Handle_StopShowVideo(SpReqAnsContext<SalesRecorderSerVice_StopShowVideo_Req, SalesRecorderSerVice_StopShowVideo_Ans>::Pointer ctx)
  263. {
  264. Dbg("Stop Show Video name is %s.", (LPCTSTR)CSimpleStringW2A(ctx->Req.VideoName));
  265. ErrorCodeEnum ErrorCode = m_pEntity->HandleStopShowVideo();
  266. ctx->Answer(ErrorCode);
  267. }
  268. void SalesRecordServiceSession::Handle_PlaySalesRecord(SpReqAnsContext<SalesRecorderSerVice_PlaySalesRecord_Req, SalesRecorderSerVice_PlaySalesRecord_Ans>::Pointer ctx)
  269. {
  270. Dbg("Stop Show Video name is %s.", (LPCTSTR)CSimpleStringW2A(ctx->Req.VideoName));
  271. ErrorCodeEnum ErrorCode = m_pEntity->HandlePlaySalesRecordVideo(ctx->Req.WndX, ctx->Req.WndY, ctx->Req.WndWidth, ctx->Req.WndHeight);
  272. ctx->Answer(ErrorCode);
  273. }
  274. CServerSessionBase * CSalesRecorderEntity::OnNewSession( const char* pszRemoteEntityName, const char * pszClass )
  275. {
  276. LOG_FUNCTION();
  277. LOG_TRACE("%s connected class = %s!", pszRemoteEntityName, pszClass);
  278. return new SalesRecordServiceSession(this);
  279. }
  280. void CSalesRecorderEntity::OnPreStart( CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext )
  281. {
  282. ErrorCodeEnum Error = __OnStart(Error_Succeed);
  283. pTransactionContext->SendAnswer(Error);
  284. }
  285. ErrorCodeEnum CSalesRecorderEntity::__OnStart( ErrorCodeEnum preOperationError )
  286. {
  287. LOG_FUNCTION();
  288. //MessageBoxA(0,0,0,0);
  289. m_eDeviceType = eStand2sType;
  290. m_nSysCallType = 0;
  291. //is Pad Version
  292. m_bNeedRestart = false;
  293. m_eAudioOutQuality = eUltraHD;
  294. m_bIsAudioNsOn = false;
  295. m_iAudioNsPolicy = 2;
  296. m_bIsAudioTransOn = false;
  297. m_xIdlePre = m_xKernelPre = m_xUserPre = 0;
  298. #ifdef RVC_OS_WIN
  299. if (SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS)){
  300. Dbg("Set Process(%d) RealTime Priority Success.",GetCurrentProcessId());
  301. }
  302. #endif
  303. m_eDeviceType = RvcGetDeviceType();
  304. int iAudioQuality = 3;
  305. int iAudioNsPolicy = 2;
  306. int iIsAudioNsOn = 0;
  307. m_max_disk_percent = MAX_DISK_PERCENT; // add by ly 2018/02/24
  308. CSmartPointer<IConfigInfo> spConfig;
  309. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  310. if (spFunction->OpenConfig(Config_CenterSetting, spConfig) == Error_Succeed)
  311. {
  312. spConfig->ReadConfigValueInt("SalesRecorder","MaxDiskPercent",m_max_disk_percent);
  313. spConfig->ReadConfigValueInt("SalesRecorder","AudioSampleRate",m_audio_samplerate);
  314. spConfig->ReadConfigValueInt("SalesRecorder","AudioBitRate",m_audio_out_bitrate);
  315. spConfig->ReadConfigValueInt("SalesRecorder","WholeSection",m_bWholeSection);
  316. spConfig->ReadConfigValueInt("SalesRecorder","ApplyHighQuality",m_bApplyHighQuality);
  317. spConfig->ReadConfigValueInt("SalesRecorder","AudioNsPolicy",iAudioNsPolicy);
  318. spConfig->ReadConfigValueInt("SalesRecorder","IsAudioNsOn",iIsAudioNsOn);
  319. spConfig->ReadConfigValueInt("SalesRecorder","AudioQuality",iAudioQuality);
  320. }
  321. if (m_max_disk_percent <= 0 || m_max_disk_percent >= 100)
  322. {
  323. m_max_disk_percent = MAX_DISK_PERCENT;
  324. }
  325. SetRecordAudioQuality(iAudioQuality);
  326. SetRecordAudioNsPolicy(iAudioNsPolicy);
  327. if (0 != iIsAudioNsOn){
  328. m_bIsAudioNsOn = true;
  329. }
  330. //if (m_audio_samplerate != 8 && m_audio_samplerate != 16)
  331. //{
  332. // m_audio_samplerate = 8;
  333. //}
  334. //if (m_audio_samplerate == 8)
  335. //{
  336. // if (m_audio_out_bitrate < 8)
  337. // {
  338. // m_audio_out_bitrate = 8;
  339. // }
  340. // if (m_audio_out_bitrate > 128)
  341. // {
  342. // m_audio_out_bitrate = 128;
  343. // }
  344. //}
  345. //else
  346. //{
  347. // if (m_audio_out_bitrate < 8)
  348. // {
  349. // m_audio_out_bitrate = 8;
  350. // }
  351. // if (m_audio_out_bitrate > 256)
  352. // {
  353. // m_audio_out_bitrate = 256;
  354. // }
  355. //}
  356. if (m_bWholeSection != 0 && m_bWholeSection != 1)
  357. {
  358. m_bWholeSection = FALSE;
  359. }
  360. if (m_bApplyHighQuality != 0 && m_bApplyHighQuality != 1)
  361. {
  362. m_bApplyHighQuality = FALSE;
  363. }
  364. Dbg("[dbg] m_bApplyHighQuality:%d",m_bApplyHighQuality);
  365. m_bEwsRecord = FALSE;
  366. if (preOperationError != Error_Succeed)
  367. return preOperationError;
  368. ErrorCodeEnum Error = Error_Succeed;
  369. nActiveCamera = CAMERA_TYPE_ENV;
  370. m_iCameraState = 'N';
  371. int i = 0;
  372. if (ePadtype == m_eDeviceType||eMobilePadType == m_eDeviceType||eDesk2SType == m_eDeviceType||eDesk1SType == m_eDeviceType||eDesk2SIntegratedType == m_eDeviceType)
  373. {
  374. // add by ly(edit by ly 2018/03/12)
  375. #ifdef RVC_OS_WIN
  376. m_pPlayer = new Clibwmpplayer(this);
  377. #else
  378. m_pPlayer = new Clibmediaplayer(this);
  379. #endif // RVC_OS_WIN
  380. m_arrListener.Init(9);
  381. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STARTRECORD, NULL, false);
  382. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STARTAFTERPREVIEWRECORD, NULL, false);
  383. //GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STOPRECORD, NULL, false);
  384. //GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_SHOWVIDEO, NULL, false);
  385. //GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_SAVEVIDEO, NULL, false);
  386. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_DELETEVIDEO, NULL, false);
  387. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_RETURNMENU, NULL, false);
  388. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_UKEY_PULLOUT, NULL, false);
  389. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_VIDEOAPPENDWATERMARK, NULL, false);
  390. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STARTREMOTERECORD, NULL, false);
  391. //GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STOPREMOTERECORD, NULL, false);
  392. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_High, Error_IgnoreAll, LOG_EVT_SALESRECORD_ENTITY_EXCEPTION, NULL, false);
  393. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_High, Error_IgnoreAll, LOG_EVT_AUDIOSTREAM_TRANSMISSION_FAILED, NULL, false);
  394. }
  395. else
  396. {
  397. // add by ly @2018/01/10
  398. #ifdef RVC_OS_WIN
  399. m_pPlayer = new Clibwmpplayer(this);
  400. #else
  401. m_pPlayer = new Clibmediaplayer(this);
  402. #endif // RVC_OS_WIN
  403. m_arrListener.Init(8);
  404. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STARTRECORD, NULL, false);
  405. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STARTAFTERPREVIEWRECORD, NULL, false);
  406. //GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STOPRECORD, NULL, false);
  407. //GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_SHOWVIDEO, NULL, false);
  408. //GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_SAVEVIDEO, NULL, false);
  409. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_DELETEVIDEO, NULL, false);
  410. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_RETURNMENU, NULL, false);
  411. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_VIDEOAPPENDWATERMARK, NULL, false);
  412. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STARTREMOTERECORD, NULL, false);
  413. //GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_UI_STOPREMOTERECORD, NULL, false);
  414. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_High, Error_IgnoreAll, LOG_EVT_SALESRECORD_ENTITY_EXCEPTION, NULL, false);
  415. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_High, Error_IgnoreAll, LOG_EVT_AUDIOSTREAM_TRANSMISSION_FAILED, NULL, false);
  416. }
  417. GetFunction()->RegistSysVarEvent(SYSVAR_ACTIVETRACKINGCAMERA,this);
  418. GetFunction()->RegistSysVarEvent(SYSVAR_CAMERASTATE,this);
  419. CSimpleStringA strValue;
  420. GetFunction()->GetSysVar(SYSVAR_CAMERASTATE, strValue);
  421. m_iCameraState = strValue[0];
  422. if (strValue[0] == 'E')
  423. {
  424. nActiveCamera = CAMERA_TYPE_OPT;
  425. }
  426. else if (strValue[0] == 'O')
  427. {
  428. nActiveCamera = CAMERA_TYPE_ENV;
  429. }
  430. else if(strValue[0] == 'B') ///////显示贴图
  431. {
  432. nActiveCamera = CAMERA_TYPE_ERROR;
  433. }
  434. else if (strValue[0] == 'N')
  435. {
  436. nActiveCamera = CAMERA_TYPE_ENV;
  437. }
  438. GetFunction()->RegistSysVarEvent(SYSVAR_CALLTYPE, this);
  439. GetFunction()->GetSysVar(SYSVAR_CALLTYPE, strValue);
  440. if (strValue[0] == CALLTYPE_NORMAL)
  441. {
  442. m_nSysCallType = 0;
  443. }
  444. else if (strValue[0] == CALLTYPE_MOBILE)
  445. {
  446. m_nSysCallType = 1;
  447. }
  448. else
  449. {
  450. assert(0);
  451. }
  452. Error = GetFunction()->RegistSysVarEvent("SessionID", this);
  453. if (Error != Error_Succeed)
  454. {
  455. LOG_TRACE("register sysvar %s failed!", "SessionID");
  456. }
  457. // add by ly 2018/02/13
  458. Error = GetFunction()->GetPath("Temp", m_TempDir);
  459. if (Error != Error_Succeed) {
  460. LOG_TRACE("get global record temp path failed!");
  461. }
  462. if (m_TempDir.GetLength() > 0 && m_TempDir[m_TempDir.GetLength()-1] != SPLIT_SLASH) {
  463. m_TempDir += SPLIT_SLASH_STR;
  464. }
  465. Error = GetFunction()->GetPath("UploadVideo", m_RecordSaveDir);
  466. if (Error != Error_Succeed) {
  467. LOG_TRACE("get global record save path failed!");
  468. }
  469. if (m_RecordSaveDir.GetLength() > 0 && m_RecordSaveDir[m_RecordSaveDir.GetLength()-1] != SPLIT_SLASH) {
  470. m_RecordSaveDir += SPLIT_SLASH_STR;
  471. }
  472. return Error;
  473. }
  474. void CSalesRecorderEntity::OnStarted()
  475. {
  476. GetFunction()->SetTimer(TIMERID_UPOFLRECORD,this,UPLOAD_CYCLE);
  477. GetFunction()->SetTimer(TIMERID_DISKCHK,this,DISKCHK_CYCLE);
  478. }
  479. void CSalesRecorderEntity::OnPreClose( EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext )
  480. {
  481. ErrorCodeEnum Error = __OnClose(Error_Succeed);
  482. GetFunction()->KillTimer(TIMERID_UPOFLRECORD);
  483. GetFunction()->KillTimer(TIMERID_DISKCHK);
  484. pTransactionContext->SendAnswer(Error);
  485. }
  486. ErrorCodeEnum CSalesRecorderEntity::__OnClose( ErrorCodeEnum preOperationError )
  487. {
  488. LOG_FUNCTION();
  489. if (preOperationError != Error_Succeed)
  490. return preOperationError;
  491. // edit by ly @2018/01/10
  492. delete m_pPlayer; m_pPlayer = NULL;
  493. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  494. for (int i = 0; i < m_arrListener.GetCount(); ++i)
  495. {
  496. spFunction->UnsubscribeLog(m_arrListener[i]);
  497. }
  498. GetFunction()->UnregistSysVarEvent(SYSVAR_ACTIVETRACKINGCAMERA);
  499. GetFunction()->UnregistSysVarEvent(SYSVAR_CAMERASTATE);
  500. StopRecord();
  501. return Error_Succeed;
  502. }
  503. void CSalesRecorderEntity::OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
  504. {
  505. if (Test_ShakeHand == eTestType)
  506. {
  507. if (m_bNeedRestart){
  508. Dbg("[OnSelfTest] entity need restart now.");
  509. pTransactionContext->SendAnswer(Error_Unexpect);
  510. }
  511. else{
  512. pTransactionContext->SendAnswer(Error_Succeed);
  513. }
  514. }
  515. }
  516. int CSalesRecorderEntity::GetActiveCamera()
  517. {
  518. //Debug("get camera = %d",nActiveCamera);
  519. return nActiveCamera;
  520. }
  521. void CSalesRecorderEntity::OnRecordFailed( bool bRecordDevFault )
  522. {
  523. Dbg("OnSalesRecordFailed!");
  524. if (!bRecordDevFault)
  525. {
  526. LogEvent(Severity_Middle,LOG_EVT_UI_RECORDFAILED,"0");
  527. }
  528. else
  529. {
  530. LogEvent(Severity_Middle,LOG_EVT_UI_RECORDFAILED,"1");
  531. }
  532. Dbg("Current memory usage is %d.", GetSystemMemoryUsage());
  533. Dbg("Current CPU usage is %f", GetSystemCpuUsage());
  534. }
  535. void CSalesRecorderEntity::OnRecordEntityExcption()
  536. {
  537. Dbg("现场销售双录出现异常,请稍候重录,系统正在恢复中,预计60秒!");
  538. LogEvent(Severity_High,LOG_EVT_SALESRECORD_ENTITY_EXCEPTION,"现场销售双录出现异常,请稍候重录,系统正在恢复中,预计60秒!");
  539. }
  540. void CSalesRecorderEntity::OnRecordFinished()
  541. {
  542. Dbg("现场销售录像已完成");
  543. LogEvent(Severity_High, LOG_EVT_SALESRECORD_FINISHED, "现场销售双录已完成.");
  544. }
  545. void CSalesRecorderEntity::Debug(const char* fmt, ...)
  546. {
  547. va_list arg;
  548. va_start(arg, fmt);
  549. vDbg(fmt, arg);
  550. va_end(arg);
  551. }
  552. #ifdef RVC_OS_WIN
  553. void CSalesRecorderEntity::WmpDebug( const char *fmt, ... )
  554. {
  555. va_list arg;
  556. va_start(arg, fmt);
  557. vDbg(fmt, arg);
  558. va_end(arg);
  559. }
  560. #else
  561. void CSalesRecorderEntity::Debug(media_loglevel log_level, const char* fmt, ...)
  562. {
  563. if (log_level >= MEDIA_LOG_ERROR) {
  564. va_list arg;
  565. va_start(arg, fmt);
  566. vDbg(fmt, arg);
  567. va_end(arg);
  568. }
  569. }
  570. #endif // RVC_OS_WIN
  571. // 定时任务:扫描是否有待提交的离线双录记录 add by ly @2018/02/08
  572. void CSalesRecorderEntity::OnTimeout( DWORD dwTimerID )
  573. {
  574. if (dwTimerID == TIMERID_UPOFLRECORD)
  575. {
  576. Dbg("On upload timer!");
  577. if (CheckNetState() == Error_Succeed) {
  578. UploadOFLVideoRecordTask *task = new UploadOFLVideoRecordTask(this);
  579. GetFunction()->PostThreadPoolTask(task);
  580. }
  581. }
  582. if (dwTimerID == TIMERID_DISKCHK)
  583. {
  584. if (strstr(m_SalesVideoName, "OFL")) {
  585. Dbg("On DISKCHK timer!");
  586. int nFreeRatio = 0;
  587. #ifdef RVC_OS_WIN
  588. m_last_disk_overtop = !CheckDiskStatus("C:\\",m_max_disk_percent,&nFreeRatio);
  589. #else
  590. m_last_disk_overtop = !CheckDiskStatus("/home/", m_max_disk_percent, &nFreeRatio);
  591. #endif
  592. if (m_last_disk_overtop) {
  593. CSimpleStringA msg = CSimpleStringA::Format("磁盘所剩空间不足%d%%,已停止离线双录!",100-m_max_disk_percent);
  594. Dbg((LPCTSTR)msg);
  595. StopRecord();
  596. // notify user desktop
  597. #ifdef RVC_OS_WIN
  598. MessageBoxA(NULL,(LPCSTR)msg,NULL,MB_SYSTEMMODAL);
  599. #endif//RVC_OS_WIN
  600. }
  601. }
  602. }
  603. }
  604. void CSalesRecorderEntity::OnSysVarEvent( const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName )
  605. {
  606. if (_stricmp(pszKey, SYSVAR_CAMERASTATE) == 0)
  607. {
  608. Dbg("camera state from : %c to %c", pszOldValue[0], pszValue[0]);
  609. m_iCameraState = pszValue[0];
  610. if (pszValue[0] == 'E')
  611. {
  612. nActiveCamera = CAMERA_TYPE_OPT;
  613. }
  614. else if (pszValue[0] == 'O')
  615. {
  616. nActiveCamera = CAMERA_TYPE_ENV;
  617. }
  618. else if(pszValue[0] == 'B') ///////显示贴图
  619. {
  620. nActiveCamera = CAMERA_TYPE_ERROR;
  621. }
  622. else if (pszValue[0] == 'N')
  623. {
  624. nActiveCamera = CAMERA_TYPE_AUTO;
  625. }
  626. }
  627. else if (_stricmp(pszKey, SYSVAR_ACTIVETRACKINGCAMERA) == 0)
  628. {
  629. if (m_iCameraState == 'N')
  630. {
  631. if (pszValue[0] == 'E')
  632. {
  633. nActiveCamera = CAMERA_TYPE_ENV;
  634. }
  635. else if (pszValue[0] == 'O')
  636. {
  637. nActiveCamera = CAMERA_TYPE_OPT;
  638. }
  639. }
  640. }
  641. else if (_stricmp(pszKey, SYSVAR_CALLTYPE) == 0)
  642. {
  643. Dbg("sys calltype from: %c to %c", pszOldValue[0], pszValue[0]);
  644. if(pszValue[0] == CALLTYPE_NORMAL)
  645. {
  646. m_nSysCallType = 0;
  647. }
  648. else if(pszValue[0] == CALLTYPE_MOBILE)
  649. {
  650. m_nSysCallType = 1;
  651. }
  652. else
  653. {
  654. m_nSysCallType = -1;
  655. }
  656. }
  657. }
  658. 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)
  659. {
  660. // 响应客户经理销售录像相关的事件
  661. switch (dwUserCode)
  662. {
  663. case LOG_EVT_UI_STARTRECORD:
  664. case LOG_EVT_UI_STARTAFTERPREVIEWRECORD:
  665. Dbg("start record, pszMessage = %s.",pszMessage);
  666. HandleStartRecord(pszMessage, false);
  667. break;
  668. case LOG_EVT_UI_STARTREMOTERECORD:
  669. Dbg("start remote record, pszMessage = %s.",pszMessage);
  670. HandleStartRecord(pszMessage, true);
  671. break;
  672. case LOG_EVT_UI_STOPREMOTERECORD:
  673. Dbg("stop remote record, pszMessage = %s.",pszMessage);
  674. StopRecord();
  675. break;
  676. case LOG_EVT_UI_STOPRECORD:
  677. Dbg("stop record, pszMessage = %s.",pszMessage);
  678. HandleStopRecord(pszMessage);
  679. break;
  680. case LOG_EVT_UI_SHOWVIDEO:
  681. Dbg("show video record, pszMessage = %s.",pszMessage);
  682. HandleDisplayVideo();
  683. break;
  684. case LOG_EVT_UI_SAVEVIDEO:
  685. Dbg("save record!");
  686. HandleSaveVideo();
  687. break;
  688. case LOG_EVT_UI_DELETEVIDEO:
  689. Dbg("delete record!");
  690. HandleDeleteVideo();
  691. break;
  692. case LOG_EVT_UI_RETURNMENU:
  693. HandleReturnMenu();
  694. break;
  695. case EVENT_UKEY_PULLOUT:
  696. Dbg("ukey pull out!");
  697. HandleUkeyPullout();
  698. break;
  699. case LOG_EVT_UI_VIDEOAPPENDWATERMARK:
  700. Dbg("handle video append water mark param is %s.", pszMessage);
  701. HandleVideoAppendWatermark(pszMessage);
  702. break;
  703. case LOG_EVT_SALESRECORD_ENTITY_EXCEPTION:
  704. Dbg("handle sales record entity exception, and message is %s.", pszMessage);
  705. HandleSalesRecordEntityException(pszMessage);
  706. break;
  707. case LOG_EVT_AUDIOSTREAM_TRANSMISSION_FAILED:
  708. Dbg("handle audio stream transmission failed.");
  709. HandleStopAudioStreamEnTransQueue();
  710. break;
  711. default:
  712. break;
  713. }
  714. }
  715. // we use root.ini Video section config to decide camera count
  716. ErrorCodeEnum CSalesRecorderEntity::DecideCameraCount( int &nCount )
  717. {
  718. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  719. CSmartPointer<IConfigInfo> spConfig;
  720. ErrorCodeEnum Error = spFunction->OpenConfig(Config_Root, spConfig);
  721. if (Error == Error_Succeed) {
  722. CSimpleStringA strVideoEnv;
  723. CSimpleStringA strVideoOpt;
  724. SpIniMappingTable table;
  725. nCount = 0;
  726. table.AddEntryString("Video", "EnvCamera", strVideoEnv, "$");
  727. table.AddEntryString("Video", "OptCamera", strVideoOpt, "$");
  728. Error = table.Load(spConfig);
  729. if (Error == Error_Succeed) {
  730. if (strVideoEnv.GetLength() > 1)
  731. nCount++;
  732. if (strVideoOpt.GetLength() > 1)
  733. nCount++;
  734. }
  735. }
  736. return Error;
  737. }
  738. void CSalesRecorderEntity::StartPhone2PadRecord(const int fps, const char* wmvfilename, int videoquality, int audioOutBitRate, SubtitleParam* subtitleParam, BOOL bWholeSection, BOOL bSessionManage, eRvcRecordType eRecordType)
  739. {
  740. BOOL bRet = FALSE;
  741. // edit by ly@2019/03/01
  742. if ((ePadtype == m_eDeviceType) || (eMobilePadType == m_eDeviceType) || (eDesk1SType == m_eDeviceType) || (eDesk2SIntegratedType == m_eDeviceType))
  743. {
  744. //在线双录,录像统一使用前置摄像头, pad 版增加远端视频队列
  745. Dbg("m_pRecorder local video is REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE.");
  746. m_pRecorder = new Clibwmvrecord(&bRet, this, REC_COMMON_AUDIO_SALESOL_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE,
  747. NULL, REC_COMMON_AUDIO_SALES_SHM_QUEUE, REC_COMMON_VIDEO_REMOTE_SHM_RTP_QUEUE, REC_COMMON_REMOTEAUDIO_SHM_QUEUE);
  748. }
  749. else if (eDesk2SType == m_eDeviceType)
  750. {
  751. m_pRecorder = new Clibwmvrecord(&bRet, this, REC_COMMON_AUDIO_SALESOL_SHM_QUEUE, REC_COMMON_VIDEO_SALES_EWS_SHM_RTP_QUEUE,
  752. NULL, REC_COMMON_AUDIO_SALES_SHM_QUEUE, REC_COMMON_VIDEO_REMOTE_SHM_RTP_QUEUE, REC_COMMON_REMOTEAUDIO_SHM_QUEUE);
  753. }
  754. else
  755. {
  756. // == 2
  757. m_pRecorder = new Clibwmvrecord(&bRet, this, REC_COMMON_AUDIO_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE,
  758. REC_COMMON_VIDEO_OPT_SHM_RTP_QUEUE, REC_COMMON_AUDIO_SALES_SHM_QUEUE);
  759. }
  760. Rvc_RecordAudioParam_t tAudioParams;
  761. tAudioParams.eRecordType = ePhone2Pad;
  762. tAudioParams.eOutPutType = m_eAudioOutQuality;
  763. tAudioParams.bIsNsOn = m_bIsAudioNsOn;
  764. tAudioParams.iNsPolicy = m_iAudioNsPolicy;
  765. tAudioParams.iAudioOutBitRate = 8;
  766. tAudioParams.bIsTransOn = m_bIsAudioTransOn;
  767. if (m_pRecorder->StartWmvRecord(fps, videoquality, &tAudioParams, subtitleParam, bWholeSection, FALSE, (LPCSTR)m_TempDir,
  768. m_TempDir.GetLength(), wmvfilename, strlen(wmvfilename)))
  769. {
  770. m_bStarted = TRUE;
  771. }
  772. }
  773. BOOL CSalesRecorderEntity::GetStandardQualityOnSiteSalesRecorder(const eRvcRecordType eRecordType)
  774. {
  775. BOOL bRet = FALSE;
  776. if ((ePadtype == m_eDeviceType) || (eMobilePadType == m_eDeviceType) || eDesk2SType == m_eDeviceType)
  777. {
  778. if (!m_bEwsRecord){
  779. if (ePad2Agent != eRecordType) {
  780. m_pRecorder = new Clibwmvrecord(&bRet, this, REC_COMMON_AUDIO_SALESOL_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE,
  781. NULL, REC_COMMON_AUDIO_SALES_SHM_QUEUE);
  782. }
  783. else{
  784. m_pRecorder = new Clibwmvrecord(&bRet, this, REC_COMMON_AUDIO_SALESOL_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE,
  785. NULL, REC_COMMON_AUDIO_SALES_SHM_QUEUE, REC_COMMON_VIDEO_REMOTE_SHM_RTP_QUEUE, REC_COMMON_REMOTEAUDIO_SHM_QUEUE);
  786. }
  787. }
  788. else{
  789. m_pRecorder = new Clibwmvrecord(&bRet, this, REC_COMMON_AUDIO_SALESOL_SHM_QUEUE, REC_COMMON_VIDEO_SALES_EWS_SHM_RTP_QUEUE,
  790. NULL, REC_COMMON_AUDIO_SALES_SHM_QUEUE, REC_COMMON_VIDEO_REMOTE_SHM_RTP_QUEUE, REC_COMMON_REMOTEAUDIO_SHM_QUEUE);
  791. }
  792. }
  793. else if(eDesk1SType == m_eDeviceType || eDesk2SIntegratedType == m_eDeviceType)
  794. {
  795. if (ePad2Agent != eRecordType) {
  796. m_pRecorder = new Clibwmvrecord(&bRet, this, REC_COMMON_AUDIO_SALESOL_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE,
  797. NULL, REC_COMMON_AUDIO_SALES_SHM_QUEUE);
  798. }
  799. else {
  800. m_pRecorder = new Clibwmvrecord(&bRet, this, REC_COMMON_AUDIO_SALESOL_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE,
  801. NULL, REC_COMMON_AUDIO_SALES_SHM_QUEUE, REC_COMMON_VIDEO_REMOTE_SHM_RTP_QUEUE, REC_COMMON_REMOTEAUDIO_SHM_QUEUE);
  802. }
  803. }
  804. else
  805. {
  806. if (eStand2Agent != eRecordType){
  807. m_pRecorder = new Clibwmvrecord(&bRet, this, REC_COMMON_AUDIO_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE,
  808. REC_COMMON_VIDEO_OPT_SHM_RTP_QUEUE, REC_COMMON_AUDIO_SALES_SHM_QUEUE);
  809. }
  810. else{
  811. m_pRecorder = new Clibwmvrecord(&bRet, this, REC_COMMON_AUDIO_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE,
  812. 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);
  813. }
  814. }
  815. return bRet;
  816. }
  817. BOOL CSalesRecorderEntity::GetHighQualityOnSiteSalesRecorder(const eRvcRecordType eRecordType)
  818. {
  819. BOOL bRet = FALSE;
  820. if (ePadtype == m_eDeviceType || eMobilePadType == m_eDeviceType || eDesk2SType == m_eDeviceType)
  821. {
  822. if (!m_bEwsRecord)
  823. {
  824. if (ePad2Agent == eRecordType) {
  825. m_pRecorder = new Clibwmvrecord(&bRet, this, REC_COMMON_AUDIO_SALESOL_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE,
  826. NULL, REC_COMMON_AUDIO_SALES_SHM_QUEUE, REC_COMMON_VIDEO_REMOTE_SHM_RTP_QUEUE, REC_COMMON_REMOTEAUDIO_SHM_QUEUE);
  827. }
  828. else {
  829. m_pRecorder = new Clibwmvrecord(&bRet, this, REC_COMMON_AUDIO_SALESOL_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE,
  830. NULL, REC_COMMON_AUDIO_SALES_SHM_QUEUE);
  831. }
  832. }
  833. else{
  834. m_pRecorder = new Clibwmvrecord(&bRet, this, REC_COMMON_AUDIO_SALESOL_SHM_QUEUE, REC_COMMON_VIDEO_EWS_SHM_SNAPSHOT_QUEUE,
  835. NULL, REC_COMMON_AUDIO_SALES_SHM_QUEUE, REC_COMMON_VIDEO_REMOTE_SHM_RTP_QUEUE, REC_COMMON_REMOTEAUDIO_SHM_QUEUE);
  836. }
  837. }
  838. else if (eDesk1SType == m_eDeviceType || eDesk2SIntegratedType == m_eDeviceType)
  839. {
  840. if (ePad2Agent == eRecordType) {
  841. m_pRecorder = new Clibwmvrecord(&bRet, this, REC_COMMON_AUDIO_SALESOL_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_RTP_QUEUE,
  842. NULL, REC_COMMON_AUDIO_SALES_SHM_QUEUE, REC_COMMON_VIDEO_REMOTE_SHM_RTP_QUEUE, REC_COMMON_REMOTEAUDIO_SHM_QUEUE);
  843. }
  844. else {
  845. m_pRecorder = new Clibwmvrecord(&bRet, this, REC_COMMON_AUDIO_SALESOL_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE,
  846. NULL, REC_COMMON_AUDIO_SALES_SHM_QUEUE);
  847. }
  848. }
  849. else
  850. {
  851. if (eStand2Agent != eRecordType){
  852. m_pRecorder = new Clibwmvrecord(&bRet, this, REC_COMMON_AUDIO_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE,
  853. REC_COMMON_VIDEO_OPT_SHM_SNAPSHOT_QUEUE, REC_COMMON_AUDIO_SALES_SHM_QUEUE);
  854. }
  855. else{
  856. m_pRecorder = new Clibwmvrecord(&bRet, this, REC_COMMON_AUDIO_SHM_QUEUE, REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE,
  857. 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);
  858. }
  859. }
  860. return bRet;
  861. }
  862. void CSalesRecorderEntity::StartOnSiteSalesRecord(const int fps, const char* wmvfilename, int videoquality, int audioOutBitRate, SubtitleParam* subtitleParam, BOOL bWholeSection, BOOL bSessionManage, eRvcRecordType eRecordType)
  863. {
  864. BOOL bRet = FALSE;
  865. if (m_bApplyHighQuality)
  866. {
  867. bRet = GetHighQualityOnSiteSalesRecorder(eRecordType);
  868. }
  869. else
  870. {
  871. bRet = GetStandardQualityOnSiteSalesRecorder(eRecordType);
  872. }
  873. if (FALSE == bRet){
  874. Dbg("get onsite sales recorder failed.");
  875. return;
  876. }
  877. Rvc_RecordAudioParam_t tAudioParams;
  878. tAudioParams.eRecordType = eRecordType;
  879. tAudioParams.eOutPutType = m_eAudioOutQuality;
  880. tAudioParams.bIsNsOn = m_bIsAudioNsOn;
  881. tAudioParams.iNsPolicy = m_iAudioNsPolicy;
  882. tAudioParams.iAudioOutBitRate = audioOutBitRate;
  883. tAudioParams.bIsTransOn = m_bIsAudioTransOn;
  884. if (eStand2Agent == eRecordType || ePad2Agent == eRecordType) {
  885. tAudioParams.eOutPutType = eLowDefinition;
  886. tAudioParams.bIsNsOn = false;
  887. }
  888. 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);
  889. if (m_pRecorder->StartWmvRecord(fps, videoquality, &tAudioParams, subtitleParam, bWholeSection, FALSE, (LPCSTR)m_TempDir,
  890. m_TempDir.GetLength(), wmvfilename, strlen(wmvfilename)))
  891. {
  892. m_bStarted = TRUE;
  893. }
  894. else {
  895. Dbg("Start WmvRecord failed!");
  896. }
  897. }
  898. void CSalesRecorderEntity::StartRecord(const char *wmvfilename, int videoquality, int audioOutBitRate, SubtitleParam *subtitleParam /* = NULL */, BOOL bWholeSection /* = FALSE */, BOOL bSessionManage /* = FALSE */, eRvcRecordType eRecordType /* = eSingleSide */)
  899. {
  900. Dbg("wmvfilename = %s", wmvfilename);
  901. //Dbg("strPath = %s", (LPCSTR)m_TempDir);
  902. int fps = 5;
  903. //是否需要录制双向视频和音频
  904. if(m_nSysCallType == 1)
  905. {
  906. StartPhone2PadRecord(fps, wmvfilename, videoquality, audioOutBitRate, subtitleParam, bWholeSection, bSessionManage, eRecordType);
  907. }
  908. // 现场销售录音录像
  909. else
  910. {
  911. StartOnSiteSalesRecord(fps, wmvfilename, videoquality, audioOutBitRate, subtitleParam, bWholeSection, bSessionManage, eRecordType);
  912. }
  913. }
  914. ErrorCodeEnum CSalesRecorderEntity::StopRecord()
  915. {
  916. ErrorCodeEnum eCode = Error_Succeed;
  917. if (m_bStarted)
  918. {
  919. m_pRecorder->StopWmvRecord();
  920. delete m_pRecorder;
  921. m_pRecorder = NULL;
  922. m_bStarted = FALSE;
  923. }
  924. else{
  925. eCode = Error_NotImpl;
  926. }
  927. return eCode;
  928. }
  929. ErrorCodeEnum CSalesRecorderEntity::ShowVideo( const char *wmvfilename )
  930. {
  931. ErrorCodeEnum ErrorCode = Error_Succeed;
  932. if(!m_bStarted)
  933. {
  934. CSimpleStringA strPath;
  935. ErrorCodeEnum Error = GetFunction()->GetPath("Temp", strPath);
  936. if (Error == Error_Succeed) {
  937. if (strPath.GetLength() > 0 && strPath[strPath.GetLength()-1] != SPLIT_SLASH) {
  938. strPath += SPLIT_SLASH_STR;
  939. }
  940. CSimpleStringA strFindFileName = CSimpleStringA::Format("%s*.wmv", wmvfilename);
  941. ULONGLONG uVideoCount = 0;
  942. BOOL bRet = FindMatchedFile((LPCSTR)strPath, (LPCTSTR)strFindFileName, uVideoCount);
  943. Dbg("bRet = %d while find %s", bRet, wmvfilename);
  944. if(bRet){
  945. Dbg("succeed to get record count while play video!");
  946. Dbg("m_pPlayer = %p while play!", m_pPlayer);
  947. m_pPlayer->PlayVideo((LPCSTR)strPath, wmvfilename, uVideoCount);
  948. Dbg("succeed to play video!");
  949. }
  950. else{
  951. ErrorCode = Error_NotExist;
  952. Dbg("play video failed for %s no exist!", wmvfilename);
  953. }
  954. }
  955. }
  956. else{
  957. ErrorCode = Error_NotImpl;
  958. }
  959. return ErrorCode;
  960. }
  961. ErrorCodeEnum CSalesRecorderEntity::PlaySalesRecordVideo( const char *wmvfilename, int iWndX, int iWndY, int iWndWidth, int iWndHeight)
  962. {
  963. ErrorCodeEnum ErrorCode = Error_Succeed;
  964. if(!m_bStarted)
  965. {
  966. CSimpleStringA strPath;
  967. ErrorCodeEnum Error = GetFunction()->GetPath("Temp", strPath);
  968. if (Error == Error_Succeed) {
  969. if (strPath.GetLength() > 0 && strPath[strPath.GetLength()-1] != SPLIT_SLASH) {
  970. strPath += SPLIT_SLASH_STR;
  971. }
  972. CSimpleStringA strFindFileName = CSimpleStringA::Format("%s*.wmv", wmvfilename);
  973. ULONGLONG uVideoCount = 0;
  974. BOOL bRet = FindMatchedFile((LPCSTR)strPath, (LPCTSTR)strFindFileName, uVideoCount);
  975. Dbg("bRet = %d while find %s", bRet, wmvfilename);
  976. if(bRet){
  977. Dbg("succeed to get record count while play sales record video!");
  978. Dbg("m_pPlayer = %p while play!", m_pPlayer);
  979. m_pPlayer->PlaySalesRecordVideo(iWndX, iWndY, iWndWidth, iWndHeight,(LPCSTR)strPath, wmvfilename, uVideoCount);
  980. Dbg("succeed to play sales record video!");
  981. }
  982. else{
  983. ErrorCode = Error_NotExist;
  984. Dbg("play play sales record video failed for %s no exist!", wmvfilename);
  985. }
  986. }
  987. }
  988. else{
  989. ErrorCode = Error_NotImpl;
  990. }
  991. return ErrorCode;
  992. }
  993. void CSalesRecorderEntity::DeleteAllVideo( const char *wmvfilename )
  994. {
  995. if(!m_bStarted)
  996. {
  997. CSimpleStringA strPath;
  998. ErrorCodeEnum Error = GetFunction()->GetPath("Temp", strPath);
  999. if (Error == Error_Succeed) {
  1000. if (strPath.GetLength() > 0 && strPath[strPath.GetLength()-1] != SPLIT_SLASH) {
  1001. strPath += SPLIT_SLASH_STR;
  1002. }
  1003. ULONGLONG uVideoCount = 0;
  1004. // 删除客户经理录像 edit by ly 2018/03/05
  1005. CSimpleStringA strFindFileName = CSimpleStringA::Format("S_%s*.wmv", wmvfilename);
  1006. if (strstr(m_SalesVideoName, "OFL")) {
  1007. strFindFileName = CSimpleStringA::Format("OFL_%s*.wmv", wmvfilename);
  1008. }
  1009. BOOL bRet = FindMatchedFile((LPCSTR)strPath, (LPCSTR)strFindFileName, uVideoCount);
  1010. if(bRet)
  1011. {
  1012. strFindFileName = strFindFileName.SubString(0,strFindFileName.GetLength()-5);
  1013. Dbg("succeed to get sales record count while delete video!");
  1014. CSimpleStringA fileName;
  1015. BOOL bDeleteSucc = TRUE;
  1016. for(int i = 0; i != uVideoCount; ++i)
  1017. {
  1018. fileName = CSimpleStringA::Format("%s%s_%d.wmv", (LPCSTR)strPath, (LPCSTR)strFindFileName, i);
  1019. bRet = DeleteFile((LPCSTR)fileName);
  1020. if(!bRet) {
  1021. bDeleteSucc = FALSE;
  1022. Dbg("Error Code %lu while delete %s ", GetLastError(), (LPCSTR)fileName);
  1023. }
  1024. }
  1025. if (bDeleteSucc) {
  1026. Dbg("succeed to delete sales video!");
  1027. }
  1028. }
  1029. else
  1030. {
  1031. Dbg("sales videos not exist or have been deleted!");
  1032. }
  1033. // 删除见证录像
  1034. uVideoCount = 0;
  1035. strFindFileName = CSimpleStringA::Format("W_%s*.wmv", wmvfilename);
  1036. bRet = FindMatchedFile((LPCSTR)strPath, (LPCSTR)strFindFileName, uVideoCount);
  1037. if(bRet)
  1038. {
  1039. strFindFileName = strFindFileName.SubString(0,strFindFileName.GetLength()-5);
  1040. Dbg("succeed to get witness record count while delete video!");
  1041. CSimpleStringA fileName;
  1042. BOOL bDeleteSucc = TRUE;
  1043. Dbg("uVideoCount=%d", uVideoCount);
  1044. for(int i = 0; i != uVideoCount; ++i)
  1045. {
  1046. fileName = CSimpleStringA::Format("%s%s_%d.wmv", (LPCSTR)strPath, (LPCSTR)strFindFileName, i);
  1047. bRet = DeleteFile((LPCSTR)fileName);
  1048. if(!bRet) {
  1049. bDeleteSucc = FALSE;
  1050. Dbg("Error Code %lu while delete %s ", GetLastError(), (LPCSTR)fileName);
  1051. }
  1052. }
  1053. if (bDeleteSucc) {
  1054. Dbg("succeed to delete witness video!");
  1055. }
  1056. }
  1057. else
  1058. {
  1059. Dbg("witness videos not exist or have been deleted!");
  1060. }
  1061. }
  1062. }
  1063. }
  1064. void CSalesRecorderEntity::DeleteVideo( const char *wmvfilename )
  1065. {
  1066. if(!m_bStarted)
  1067. {
  1068. CSimpleStringA strPath;
  1069. ErrorCodeEnum Error = GetFunction()->GetPath("Temp", strPath);
  1070. if (Error == Error_Succeed) {
  1071. if (strPath.GetLength() > 0 && strPath[strPath.GetLength()-1] != SPLIT_SLASH) {
  1072. strPath += SPLIT_SLASH_STR;
  1073. }
  1074. CSimpleStringA strFindFileName = CSimpleStringA::Format("%s*.wmv", wmvfilename);
  1075. ULONGLONG uVideoCount = 0;
  1076. BOOL bRet = FindMatchedFile((LPCSTR)strPath, (LPCTSTR)strFindFileName, uVideoCount);
  1077. if(bRet)
  1078. {
  1079. Dbg("succeed to get record count while delete video!");
  1080. CSimpleStringA fileName;
  1081. BOOL bDeleteSucc = TRUE;
  1082. for(int i = 0; i != uVideoCount; ++i)
  1083. {
  1084. fileName = CSimpleStringA::Format("%s%s_%d.wmv", (LPCSTR)strPath, wmvfilename, i);
  1085. bRet = DeleteFile((LPCSTR)fileName);
  1086. if(!bRet) {
  1087. bDeleteSucc = FALSE;
  1088. Dbg("Error Code %lu while delete %s ", GetLastError(), (LPCSTR)fileName);
  1089. }
  1090. }
  1091. if (bDeleteSucc) {
  1092. Dbg("succeed to delete videos!");
  1093. }
  1094. }
  1095. else
  1096. {
  1097. Dbg("[DeleteVideo] videos not exist or have been deleted!");
  1098. }
  1099. }
  1100. }
  1101. }
  1102. /*
  1103. SaveVideo包含两步,找到录像和移动录像
  1104. Error_Succeed 提交上传成功
  1105. Error_NotExist not exist
  1106. Error_NotImpl 方法执行失败
  1107. */
  1108. ErrorCodeEnum CSalesRecorderEntity::SaveVideo( const char *wmvfilename )
  1109. {
  1110. ErrorCodeEnum ErrorCode = Error_Succeed;
  1111. if(!m_bStarted)
  1112. {
  1113. CSimpleStringA sourPath;
  1114. ErrorCodeEnum Error = GetFunction()->GetPath("Temp", sourPath);
  1115. if(Error == Error_Succeed)
  1116. {
  1117. if (sourPath.GetLength() > 0 && sourPath[sourPath.GetLength()-1] != SPLIT_SLASH) {
  1118. sourPath += SPLIT_SLASH_STR;
  1119. }
  1120. ULONGLONG uVideoCount = 0;
  1121. // 移动销售录像 edit by ly 2018/03/05
  1122. CSimpleStringA strFindFileName = CSimpleStringA::Format("S_%s*.wmv", wmvfilename);
  1123. if (strstr(m_SalesVideoName, "OFL")) {
  1124. strFindFileName = CSimpleStringA::Format("OFL_%s*.wmv", wmvfilename);
  1125. }
  1126. BOOL bRet = FindMatchedFile((LPCSTR)sourPath, (LPCSTR)strFindFileName, uVideoCount);
  1127. if(bRet)
  1128. {
  1129. strFindFileName = strFindFileName.SubString(0,strFindFileName.GetLength()-5);
  1130. Dbg("succeed to get sales record count while save video!");
  1131. CSimpleStringA destPath;
  1132. Error = GetFunction()->GetPath("UploadVideo", destPath);
  1133. if(Error == Error_Succeed)
  1134. {
  1135. if (destPath.GetLength() > 0 && destPath[destPath.GetLength()-1] != SPLIT_SLASH) {
  1136. destPath += SPLIT_SLASH_STR;
  1137. }
  1138. CSimpleStringA sourFileName, destFileName;
  1139. BOOL bMoveSucc = TRUE;
  1140. Dbg("strFindFileName=%s", (LPCSTR)strFindFileName);
  1141. for(int i = 0; i != uVideoCount; ++i)
  1142. {
  1143. sourFileName = CSimpleStringA::Format("%s%s_%d.wmv", (LPCSTR)sourPath, (LPCSTR)strFindFileName, i);
  1144. destFileName = CSimpleStringA::Format("%s%s_%d.wmv", (LPCSTR)destPath, (LPCSTR)strFindFileName, i);
  1145. bRet = MoveFile((LPCSTR)sourFileName, (LPCSTR)destFileName);
  1146. if(!bRet) {
  1147. bMoveSucc = FALSE;
  1148. Dbg("Error Code %lu while move %s ", GetLastError(), (LPCSTR)sourFileName);
  1149. ErrorCode = Error_NotImpl;
  1150. }
  1151. }
  1152. if (bMoveSucc) {
  1153. Dbg("succeed to save sales video!");
  1154. }
  1155. }
  1156. }
  1157. else
  1158. {
  1159. Dbg("sales videos not exist or have been deleted!");
  1160. ErrorCode = Error_NotExist;
  1161. }
  1162. // 移动见证录像
  1163. uVideoCount = 0;
  1164. strFindFileName = CSimpleStringA::Format("W_%s*.wmv", wmvfilename);
  1165. bRet = FindMatchedFile((LPCSTR)sourPath, (LPCSTR)strFindFileName, uVideoCount);
  1166. if(bRet)
  1167. {
  1168. strFindFileName = strFindFileName.SubString(0,strFindFileName.GetLength()-5);
  1169. Dbg("succeed to get witness record count while save video!");
  1170. CSimpleStringA destPath;
  1171. Error = GetFunction()->GetPath("UploadVideo", destPath);
  1172. if(Error == Error_Succeed)
  1173. {
  1174. if (destPath.GetLength() > 0 && destPath[destPath.GetLength()-1] != SPLIT_SLASH) {
  1175. destPath += SPLIT_SLASH_STR;
  1176. }
  1177. CSimpleStringA sourFileName, destFileName;
  1178. BOOL bMoveSucc = TRUE;
  1179. Dbg("uVideoCount=%d", uVideoCount);
  1180. for(int i = 0; i != uVideoCount; ++i)
  1181. {
  1182. sourFileName = CSimpleStringA::Format("%s%s_%d.wmv", (LPCSTR)sourPath, (LPCSTR)strFindFileName, i);
  1183. destFileName = CSimpleStringA::Format("%s%s_%d.wmv", (LPCSTR)destPath, (LPCSTR)strFindFileName, i);
  1184. bRet = MoveFile((LPCSTR)sourFileName, (LPCSTR)destFileName);
  1185. if(!bRet) {
  1186. bMoveSucc = FALSE;
  1187. Dbg("Error Code %lu while move %s ", GetLastError(), (LPCSTR)sourFileName);
  1188. }
  1189. }
  1190. if (bMoveSucc) {
  1191. Dbg("succeed to save witness video!");
  1192. ErrorCode = Error_Succeed;
  1193. }
  1194. }
  1195. }
  1196. else
  1197. {
  1198. Dbg("witness videos not exist or have been deleted!");
  1199. }
  1200. }
  1201. }
  1202. else{
  1203. ErrorCode = Error_NotImpl;
  1204. }
  1205. return ErrorCode;
  1206. }
  1207. ErrorCodeEnum CSalesRecorderEntity::CheckNetState()
  1208. {
  1209. auto rc = Error_Succeed;
  1210. auto pMobileDialClient = new MobileDial::MobileDialService_ClientBase(this);
  1211. if(pMobileDialClient->Connect() != Error_Succeed)
  1212. {
  1213. pMobileDialClient->SafeDelete();
  1214. pMobileDialClient = NULL;
  1215. rc = Error_DevConnFailed;
  1216. }
  1217. else
  1218. {
  1219. Dbg("MobileDialClient connected success!");
  1220. MobileDial::MobileDialService_Query_Req req;
  1221. MobileDial::MobileDialService_Query_Ans ans;
  1222. rc = pMobileDialClient->Query(req, ans, 5000);
  1223. if(rc != Error_Succeed)
  1224. {
  1225. Dbg("Query Network status failed return 0x%08x", rc);
  1226. }
  1227. else
  1228. {
  1229. //网络已断开
  1230. if(ans.netstatus == 0)
  1231. {
  1232. Dbg("Disconnected: %s", (LPCTSTR)ans.reserved3);
  1233. CSimpleStringA csRet = ans.reserved3;
  1234. CAutoArray<CSimpleStringA> splitStrings = csRet.Split('#');
  1235. if(splitStrings.GetCount() >= 2)
  1236. {
  1237. Dbg("%s %s", (LPCTSTR)splitStrings[0], (LPCTSTR)splitStrings[1]);
  1238. }
  1239. rc = Error_NetBroken;
  1240. }
  1241. //网络已连接,返回信号值
  1242. else
  1243. {
  1244. Dbg("Connected and signal %d", ans.netstatus);
  1245. }
  1246. }
  1247. pMobileDialClient->GetFunction()->CloseSession();
  1248. pMobileDialClient = NULL;
  1249. }
  1250. return rc;
  1251. }
  1252. CSimpleStringA CSalesRecorderEntity::GetTerminalStage()
  1253. {
  1254. CSmartPointer<IEntityFunction> Func = GetFunction();
  1255. CSimpleStringA strValue = "";
  1256. Func->GetSysVar("TerminalStage", strValue);
  1257. Dbg("TerminalStage:%s", (LPCTSTR)strValue);
  1258. return strValue;
  1259. }
  1260. ErrorCodeEnum CSalesRecorderEntity::LoadServerConfig()
  1261. {
  1262. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  1263. CSmartPointer<IConfigInfo> spConfig;
  1264. ErrorCodeEnum Error = spFunction->OpenConfig(Config_CenterSetting, spConfig);
  1265. if (Error == Error_Succeed) {
  1266. CSimpleStringA str;
  1267. Error = spConfig->ReadConfigValue("SalesRecorder", "Server", str);
  1268. if (Error == Error_Succeed)
  1269. {
  1270. Error = ParseIPAddress(str, m_server1, m_server1_port);
  1271. }
  1272. if (Error == Error_Succeed)
  1273. {
  1274. ErrorCodeEnum ErrorCode;
  1275. ErrorCode = spConfig->ReadConfigValue("SalesRecorder", "Server_Backup", str);
  1276. if (ErrorCode == Error_Succeed)
  1277. {
  1278. ErrorCode = ParseIPAddress(str, m_server2, m_server2_port);
  1279. }
  1280. if (ErrorCode != Error_Succeed)
  1281. {
  1282. m_server2 = NULL;
  1283. m_server2_port = 0;
  1284. }
  1285. }
  1286. }
  1287. return Error;
  1288. }
  1289. bool CSalesRecorderEntity::SecureClientConnect()
  1290. {
  1291. if (m_pConnection!=NULL && m_pConnection->IsConnectionOK())
  1292. {
  1293. return true;
  1294. }
  1295. SecureClientRelease();
  1296. m_pConnection = new CUploadOFLRecordConnection(this);
  1297. return m_pConnection->ConnectFromCentralSetting();
  1298. }
  1299. void CSalesRecorderEntity::SecureClientRelease()
  1300. {
  1301. if (m_pConnection != NULL)
  1302. {
  1303. if (m_pConnection->IsConnectionOK())
  1304. {
  1305. m_pConnection->Close();
  1306. }
  1307. m_pConnection->DecRefCount();
  1308. m_pConnection = NULL;
  1309. }
  1310. }
  1311. void CSalesRecorderEntity::OnEndUploadRecord( const char *videoserialid, int result )
  1312. {
  1313. Dbg("%s upload result: %d", videoserialid, result);
  1314. if (0 == result)
  1315. {
  1316. Dbg("succeed to save video record: OFL_%s", videoserialid);
  1317. CSimpleStringA cfn = CSimpleStringA::Format("%sOFL_%s.txt", (LPCTSTR)m_TempDir, videoserialid);
  1318. DeleteFile(cfn);
  1319. }
  1320. }
  1321. // 请求InteractiveControl结束录像 add by ly 2018/03/12
  1322. ErrorCodeEnum CSalesRecorderEntity::StopRecordVideo()
  1323. {
  1324. auto rc = Error_Succeed;
  1325. auto pUIClient = new InteractiveControl::UIService_ClientBase(this);
  1326. if(pUIClient->Connect() != Error_Succeed)
  1327. {
  1328. pUIClient->SafeDelete();
  1329. pUIClient = NULL;
  1330. rc = Error_DevConnFailed;
  1331. }
  1332. else
  1333. {
  1334. Dbg("UIClient connected success!");
  1335. InteractiveControl::UIService_StopRecordVideo_Req req;
  1336. InteractiveControl::UIService_StopRecordVideo_Ans ans;
  1337. rc = pUIClient->StopRecordVideo(req, ans, 5000);
  1338. if(rc != Error_Succeed)
  1339. {
  1340. Dbg("Stop record video failed return 0x%08x", rc);
  1341. }
  1342. pUIClient->GetFunction()->CloseSession();
  1343. pUIClient = NULL;
  1344. }
  1345. return rc;
  1346. }
  1347. BOOL CSalesRecorderEntity::OFLRecordInit( char *pszVideoParam[] )
  1348. {
  1349. if (pszVideoParam == NULL) {
  1350. return FALSE;
  1351. }
  1352. CSimpleStringA fn = CSimpleStringA::Format("%s%s.txt",
  1353. (LPCTSTR)m_TempDir,pszVideoParam[4]);
  1354. HANDLE hFile = CreateFile((LPCTSTR)fn,GENERIC_WRITE,FILE_SHARE_READ,
  1355. NULL,OPEN_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
  1356. if (hFile != INVALID_HANDLE_VALUE) {
  1357. CloseHandle(hFile);
  1358. hFile = NULL;
  1359. WritePrivateProfileString("VideoRecord","CardNo",pszVideoParam[5],(LPCTSTR)fn);
  1360. WritePrivateProfileString("VideoRecord","Name",pszVideoParam[6],(LPCTSTR)fn);
  1361. WritePrivateProfileString("VideoRecord","ProductCode",pszVideoParam[7],(LPCTSTR)fn);
  1362. WritePrivateProfileString("VideoRecord","ProductName",pszVideoParam[8],(LPCTSTR)fn);
  1363. WritePrivateProfileString("VideoRecord","ManagerSAP",pszVideoParam[9],(LPCTSTR)fn);
  1364. WritePrivateProfileString("VideoRecord","ManagerName",pszVideoParam[10],(LPCTSTR)fn);
  1365. WritePrivateProfileString("VideoRecord","ProductType",pszVideoParam[11],(LPCTSTR)fn);
  1366. WritePrivateProfileString("VideoRecord","BusinessType",pszVideoParam[12],(LPCTSTR)fn);
  1367. WritePrivateProfileString("VideoRecord","CompanyCode",pszVideoParam[13],(LPCTSTR)fn);
  1368. WritePrivateProfileString("VideoRecord","WitnessSAP",pszVideoParam[14],(LPCTSTR)fn);
  1369. WritePrivateProfileString("VideoRecord","WitnessName",pszVideoParam[15],(LPCTSTR)fn);
  1370. return TRUE;
  1371. }
  1372. else {
  1373. Dbg("error to create file %s(error code:%d)!",(LPCTSTR)fn,GetLastError());
  1374. return FALSE;
  1375. }
  1376. }
  1377. void CSalesRecorderEntity::SaveOFLRecordDuration( int nDuration )
  1378. {
  1379. CSimpleStringA cfn = CSimpleStringA::Format("%s%s.txt",
  1380. (LPCTSTR)m_TempDir,m_SalesVideoName);
  1381. char strtmp[20] = {0};
  1382. sprintf_s(strtmp, 20, "%d", nDuration);
  1383. WritePrivateProfileString("VideoRecord","Duration",strtmp,(LPCTSTR)cfn);
  1384. }
  1385. void CSalesRecorderEntity::UploadOFLVideoRecord( const char *videorecordname )
  1386. {
  1387. if (videorecordname == NULL)
  1388. {
  1389. if (SecureClientConnect())
  1390. {
  1391. auto arr = fileutil_get_sub_files((LPCTSTR)m_TempDir);
  1392. if (arr != NULL)
  1393. {
  1394. char szTmp[128];
  1395. std::vector<offline_video_record_t *> videorecordlist;
  1396. for (int i = 0; i < arr->nelts; ++i)
  1397. {
  1398. char *pszFile = ARRAY_IDX(arr, i, char*);
  1399. if (strstr(pszFile,".txt") && strstr(pszFile,"OFL")
  1400. && (!strlen(m_SalesVideoName) || !strstr(pszFile,m_SalesVideoName)))
  1401. {
  1402. if (videorecordlist.size() >= MAX_LISTSIZE)
  1403. {
  1404. break;
  1405. }
  1406. offline_video_record_t* r = ZALLOC_T(offline_video_record_t);
  1407. r->TerminalNo = _strdup((LPCTSTR)m_terminalNo);
  1408. CSimpleStringA filename = pszFile;
  1409. int pos = filename.IndexOf("OFL");
  1410. filename = filename.SubString(pos, filename.GetLength() - pos);
  1411. sscanf((LPCTSTR)filename, "OFL_%[^.].txt", szTmp);
  1412. r->VideoSerialID = _strdup(szTmp);
  1413. GetPrivateProfileString("VideoRecord", "CardNo", "", szTmp, 128, pszFile);
  1414. r->CardNo = _strdup(szTmp);
  1415. GetPrivateProfileString("VideoRecord", "Name", "", szTmp, 128, pszFile);
  1416. r->Name = _strdup(szTmp);
  1417. GetPrivateProfileString("VideoRecord", "ProductCode", "", szTmp, 128, pszFile);
  1418. r->ProductCode = _strdup(szTmp);
  1419. GetPrivateProfileString("VideoRecord", "ProductName", "", szTmp, 128, pszFile);
  1420. r->ProductName = _strdup(szTmp);
  1421. GetPrivateProfileString("VideoRecord", "ManagerSAP", "", szTmp, 128, pszFile);
  1422. r->ManagerSAP = _strdup(szTmp);
  1423. GetPrivateProfileString("VideoRecord", "ManagerName", "", szTmp, 128, pszFile);
  1424. r->ManagerName = _strdup(szTmp);
  1425. GetPrivateProfileString("VideoRecord", "ProductType", "", szTmp, 128, pszFile);
  1426. r->ProductType = _strdup(szTmp);
  1427. GetPrivateProfileString("VideoRecord", "BusinessType", "", szTmp, 128, pszFile);
  1428. r->BusinessType = _strdup(szTmp);
  1429. GetPrivateProfileString("VideoRecord", "CompanyCode", "", szTmp, 128, pszFile);
  1430. r->CompanyCode = _strdup(szTmp);
  1431. GetPrivateProfileString("VideoRecord", "WitnessSAP", "", szTmp, 128, pszFile);
  1432. r->WitnessSAP = _strdup(szTmp);
  1433. GetPrivateProfileString("VideoRecord", "WitnessName", "", szTmp, 128, pszFile);
  1434. r->WitnessName = _strdup(szTmp);
  1435. r->Duration = GetPrivateProfileInt("VideoRecord", "Duration", 0, pszFile);
  1436. videorecordlist.push_back(r);
  1437. }
  1438. else if (strstr(pszFile,".wmv") && strstr(pszFile,"OFL")
  1439. && (!strlen(m_SalesVideoName) || !strstr(pszFile,m_SalesVideoName)))
  1440. {
  1441. CSimpleStringA strWmvFile = pszFile;
  1442. int pos = strWmvFile.IndexOf("OFL");
  1443. strWmvFile = strWmvFile.SubString(pos, strWmvFile.GetLength() - pos);
  1444. CSimpleStringA srcfn = CSimpleStringA::Format("%s%s",
  1445. (LPCTSTR)m_TempDir,(LPCTSTR)strWmvFile);
  1446. CSimpleStringA dstfn = CSimpleStringA::Format("%s%s",
  1447. (LPCTSTR)m_RecordSaveDir,(LPCTSTR)strWmvFile);
  1448. BOOL bRet = MoveFile((LPCSTR)srcfn, (LPCSTR)dstfn);
  1449. if(!bRet) {
  1450. Dbg("Error Code %lu while move %s ", GetLastError(), (LPCSTR)srcfn);
  1451. }
  1452. }
  1453. }
  1454. Dbg("%d records added to upload list.", videorecordlist.size());
  1455. toolkit_array_free2(arr);
  1456. if (m_pConnection != NULL && m_pConnection->IsConnectionOK())
  1457. {
  1458. if (videorecordlist.size() > 0)
  1459. {
  1460. m_pConnection->SendOFLVideoRecords(videorecordlist);
  1461. }
  1462. }
  1463. for (std::vector<offline_video_record_t *>::size_type i = 0; i < videorecordlist.size(); ++i)
  1464. {
  1465. offline_video_record_destroy(videorecordlist[i]);
  1466. }
  1467. }
  1468. }
  1469. }
  1470. else
  1471. {
  1472. if (SecureClientConnect())
  1473. {
  1474. if (m_pConnection != NULL && m_pConnection->IsConnectionOK())
  1475. {
  1476. char szTmp[128];
  1477. offline_video_record_t* r = ZALLOC_T(offline_video_record_t);
  1478. r->TerminalNo = _strdup((LPCTSTR)m_terminalNo);
  1479. CSimpleStringA filename = videorecordname;
  1480. int pos = filename.IndexOf("OFL");
  1481. filename = filename.SubString(pos, filename.GetLength() - pos);
  1482. sscanf((LPCTSTR)filename, "OFL_%[^.].txt", szTmp);
  1483. r->VideoSerialID = _strdup(szTmp);
  1484. GetPrivateProfileString("VideoRecord", "CardNo", "", szTmp, 128, videorecordname);
  1485. r->CardNo = _strdup(szTmp);
  1486. GetPrivateProfileString("VideoRecord", "Name", "", szTmp, 128, videorecordname);
  1487. r->Name = _strdup(szTmp);
  1488. GetPrivateProfileString("VideoRecord", "ProductCode", "", szTmp, 128, videorecordname);
  1489. r->ProductCode = _strdup(szTmp);
  1490. GetPrivateProfileString("VideoRecord", "ProductName", "", szTmp, 128, videorecordname);
  1491. r->ProductName = _strdup(szTmp);
  1492. GetPrivateProfileString("VideoRecord", "ManagerSAP", "", szTmp, 128, videorecordname);
  1493. r->ManagerSAP = _strdup(szTmp);
  1494. GetPrivateProfileString("VideoRecord", "ManagerName", "", szTmp, 128, videorecordname);
  1495. r->ManagerName = _strdup(szTmp);
  1496. GetPrivateProfileString("VideoRecord", "ProductType", "", szTmp, 128, videorecordname);
  1497. r->ProductType = _strdup(szTmp);
  1498. GetPrivateProfileString("VideoRecord", "BusinessType", "", szTmp, 128, videorecordname);
  1499. r->BusinessType = _strdup(szTmp);
  1500. GetPrivateProfileString("VideoRecord", "CompanyCode", "", szTmp, 128, videorecordname);
  1501. r->CompanyCode = _strdup(szTmp);
  1502. GetPrivateProfileString("VideoRecord", "WitnessSAP", "", szTmp, 128, videorecordname);
  1503. r->WitnessSAP = _strdup(szTmp);
  1504. GetPrivateProfileString("VideoRecord", "WitnessName", "", szTmp, 128, videorecordname);
  1505. r->WitnessName = _strdup(szTmp);
  1506. r->Duration = GetPrivateProfileInt("VideoRecord", "Duration", 0, videorecordname);
  1507. m_pConnection->SendOFLVideoRecord(r);
  1508. offline_video_record_destroy(r);
  1509. }
  1510. }
  1511. }
  1512. }
  1513. CSimpleStringW CSalesRecorderEntity::GetOFLVideoRecords( CSimpleStringA Name, CSimpleStringA CardNo, CSimpleStringA BeginTime, CSimpleStringA EndTime )
  1514. {
  1515. CSimpleStringA result("");
  1516. std::vector<OFLVideoRecord> videorecordlist;
  1517. auto arr = fileutil_get_sub_files((LPCTSTR)m_TempDir);
  1518. if (arr != NULL)
  1519. {
  1520. char szTmp[128];
  1521. for (int i = 0; i < arr->nelts; ++i)
  1522. {
  1523. char *pszFile = ARRAY_IDX(arr, i, char*);
  1524. if (strstr(pszFile,".txt") && strstr(pszFile,"OFL")
  1525. && (!strlen(m_SalesVideoName) || !strstr(pszFile,m_SalesVideoName)))
  1526. {
  1527. OFLVideoRecord r;
  1528. ZeroMemory(&r,sizeof(OFLVideoRecord));
  1529. CSimpleStringA filename = pszFile;
  1530. int pos = filename.IndexOf("OFL");
  1531. filename = filename.SubString(pos, filename.GetLength() - pos);
  1532. sscanf((LPCTSTR)filename, "OFL_%[^.].txt", szTmp);
  1533. strcpy(r.VideoSerialID,szTmp);
  1534. GetPrivateProfileString("VideoRecord", "CardNo", "", szTmp, 128, pszFile);
  1535. strcpy(r.CardNo,szTmp);
  1536. GetPrivateProfileString("VideoRecord", "Name", "", szTmp, 128, pszFile);
  1537. strcpy(r.Name,szTmp);
  1538. GetPrivateProfileString("VideoRecord", "ProductCode", "", szTmp, 128, pszFile);
  1539. strcpy(r.ProductCode,szTmp);
  1540. GetPrivateProfileString("VideoRecord", "ProductName", "", szTmp, 128, pszFile);
  1541. strcpy(r.ProductName,szTmp);
  1542. GetPrivateProfileString("VideoRecord", "ManagerSAP", "", szTmp, 128, pszFile);
  1543. strcpy(r.ManagerSAP,szTmp);
  1544. GetPrivateProfileString("VideoRecord", "ManagerName", "", szTmp, 128, pszFile);
  1545. strcpy(r.ManagerName,szTmp);
  1546. GetPrivateProfileString("VideoRecord", "ProductType", "", szTmp, 128, pszFile);
  1547. strcpy(r.ProductType,szTmp);
  1548. GetPrivateProfileString("VideoRecord", "BusinessType", "", szTmp, 128, pszFile);
  1549. strcpy(r.BusinessType,szTmp);
  1550. GetPrivateProfileString("VideoRecord", "CompanyCode", "", szTmp, 128, pszFile);
  1551. strcpy(r.CompanyCode,szTmp);
  1552. GetPrivateProfileString("VideoRecord", "WitnessSAP", "", szTmp, 128, pszFile);
  1553. strcpy(r.WitnessSAP,szTmp);
  1554. GetPrivateProfileString("VideoRecord", "WitnessName", "", szTmp, 128, pszFile);
  1555. strcpy(r.WitnessName,szTmp);
  1556. r.Duration = GetPrivateProfileInt("VideoRecord", "Duration", 0, pszFile);
  1557. CSimpleStringA _BeginTime = VideoSerialID2TimeString(r.VideoSerialID);
  1558. strcpy(r.BeginTime,(LPCTSTR)_BeginTime);
  1559. if (Name.GetLength() > 0 && strcmp(r.Name,(LPCTSTR)Name))
  1560. {
  1561. continue;
  1562. }
  1563. if (CardNo.GetLength() > 0 && strcmp(r.CardNo,(LPCTSTR)CardNo))
  1564. {
  1565. continue;
  1566. }
  1567. if (BeginTime.GetLength() > 0 && BeginTime.Compare(_BeginTime) > 0)
  1568. {
  1569. continue;
  1570. }
  1571. if (EndTime.GetLength() > 0 && EndTime.Compare(_BeginTime) < 0)
  1572. {
  1573. continue;
  1574. }
  1575. videorecordlist.push_back(r);
  1576. }
  1577. }
  1578. Dbg("%d offline video records added to list.", videorecordlist.size());
  1579. toolkit_array_free2(arr);
  1580. }
  1581. sort(videorecordlist.begin(),videorecordlist.end(),OFLCmp); // 按日期倒序排列
  1582. for (std::vector<OFLVideoRecord>::size_type i = 0; i < videorecordlist.size(); ++i)
  1583. {
  1584. OFLVideoRecord &item = videorecordlist[i];
  1585. CSimpleStringA r = CSimpleStringA::Format("VideoSerialID=%s;BeginTime=%s;CardNo=%s;Name=%s;ProductCode=%s;ProductName=%s;ManagerSAP=%s;ManagerName=%s;ProductType=%s;BusinessType=%s;CompanyCode=%s;WitnessSAP=%s;WitnessName=%s",
  1586. item.VideoSerialID,item.BeginTime,item.CardNo,item.Name, item.ProductCode,item.ProductName,item.ManagerSAP,item.ManagerName,item.ProductType,item.BusinessType,item.CompanyCode,item.WitnessSAP,item.WitnessName);
  1587. result += r;
  1588. if (i != videorecordlist.size()-1)
  1589. {
  1590. result += "|";
  1591. }
  1592. }
  1593. return CSimpleStringA2W(result);
  1594. }
  1595. void CSalesRecorderEntity::HandleStartRecord(const char *pszMessage, const bool bRemoteRecord)
  1596. {
  1597. eRvcRecordType eRecordType = eSingleSide;
  1598. if (NULL == pszMessage){
  1599. return;
  1600. }
  1601. size_t ulen = strlen(pszMessage);
  1602. char *tmp = new char[ulen+1];
  1603. m_bEwsRecord = FALSE;
  1604. if ((false == bRemoteRecord) && (ulen >= EWS_CAMERA_FLAG_LEN) && (0 == strnicmp(pszMessage,EWS_CAMERA_FLAG,EWS_CAMERA_FLAG_LEN)))
  1605. {
  1606. m_bEwsRecord = TRUE;
  1607. //strncpy_s(tmp, ulen+1, pszMessage+EWS_CAMERA_FLAG_LEN, ulen-EWS_CAMERA_FLAG_LEN);
  1608. strncpy(tmp, pszMessage + EWS_CAMERA_FLAG_LEN, ulen - EWS_CAMERA_FLAG_LEN);
  1609. }
  1610. else{
  1611. //strncpy_s(tmp, ulen+1, pszMessage, ulen);
  1612. strncpy(tmp, pszMessage, ulen);
  1613. }
  1614. char *result[16] = {0};
  1615. //CStringSplit(tmp, result, "@");
  1616. // 解决中文stringsplit偶现乱码的问题 edit by ly@2018/07/04
  1617. auto arr1 = CSimpleStringA2W(tmp).Split('@');
  1618. auto arr2 = CAutoArray<CSimpleStringA>(arr1.GetCount());
  1619. for (int i = 0; i < arr1.GetCount(); ++i)
  1620. {
  1621. arr2[i] = CSimpleStringW2A(arr1[i]);
  1622. result[i] = const_cast<LPSTR>(arr2[i].GetData());
  1623. }
  1624. sprintf(m_SalesVideoName, "%s", result[4]);//录像名:录像类型标志_录像流水号(如S_C13213EF)
  1625. RecordSubTitle subTitle;
  1626. ZeroMemory(&subTitle,sizeof(RecordSubTitle));
  1627. strcpy(subTitle.CustCardNo, result[5]);
  1628. char *pStr = result[6]; // edit by ly 2018/03/21
  1629. CSimpleStringW szCustName = CSimpleStringA2W(pStr);
  1630. if (szCustName.GetLength() <= 4) {
  1631. strcpy(subTitle.CustName, pStr);
  1632. }
  1633. else {
  1634. CSimpleStringW aa = szCustName.SubString(0,4);
  1635. sprintf(subTitle.CustName,"%s...",(LPCTSTR)CSimpleStringW2A(aa));
  1636. }
  1637. // 解决产品代码、产品名称过长,画面上显示不下的问题 add by ly at 20160603(edit by ly 2018/03/21)
  1638. // 朝朝赢和招财赢支持双向录像
  1639. pStr = result[7];
  1640. int nProductCodeLen = strlen(pStr);
  1641. Dbg("ProductCode = %s, and nProductCodeLen = %d.", pStr, nProductCodeLen);
  1642. if (nProductCodeLen <= 10) {
  1643. strcpy(subTitle.ProductCode, pStr);
  1644. }
  1645. else {
  1646. char aa[5]={0},bb[5]={0};
  1647. strncpy(aa, pStr, 4);
  1648. strncpy(bb, pStr+nProductCodeLen-4, 4);
  1649. sprintf(subTitle.ProductCode,"%s...%s",aa,bb);
  1650. }
  1651. Dbg("subTitle.ProductCode=%s",subTitle.ProductCode);
  1652. pStr = result[8];
  1653. CSimpleStringW szProductName = CSimpleStringA2W(pStr);
  1654. if (szProductName.GetLength() <= 5) {
  1655. strcpy(subTitle.ProductName, pStr);
  1656. }
  1657. else {
  1658. CSimpleStringW aa = szProductName.SubString(0,3);
  1659. CSimpleStringW bb = szProductName.SubString(szProductName.GetLength()-2,2);
  1660. sprintf(subTitle.ProductName,"%s...%s",(LPCTSTR)CSimpleStringW2A(aa),(LPCTSTR)CSimpleStringW2A(bb));
  1661. }
  1662. Dbg("subTitle.ProductName=%s",subTitle.ProductName);
  1663. // edit by ly @2018/03/21
  1664. if (result[9]) {
  1665. strcpy(subTitle.SapID, result[9]);
  1666. } else {
  1667. subTitle.SapID[0] = '\0';
  1668. }
  1669. if (result[10]) {
  1670. pStr = result[10];
  1671. CSimpleStringW szCustManagerName = CSimpleStringA2W(pStr);
  1672. if (szCustManagerName.GetLength() <= 4) {
  1673. strcpy(subTitle.CustManagerName, result[10]);
  1674. }
  1675. else {
  1676. CSimpleStringW aa = szCustManagerName.SubString(0,4);
  1677. sprintf(subTitle.CustManagerName,"%s...",(LPCTSTR)CSimpleStringW2A(aa));
  1678. }
  1679. } else {
  1680. subTitle.CustManagerName[0] = '\0';
  1681. }
  1682. Dbg("subTitle.CustManagerName=%s",subTitle.CustManagerName);
  1683. // 如果是离线双录,则保存业务要素到外存 add by ly 2018/03/08
  1684. if (strstr(m_SalesVideoName, "OFL")) {
  1685. strcpy(subTitle.Reserved1, result[14]); // 保存见证人员sap
  1686. pStr = result[15];
  1687. CSimpleStringW szWitnessName = CSimpleStringA2W(pStr);
  1688. if (szWitnessName.GetLength() <= 4) {
  1689. strcpy(subTitle.Reserved2, result[15]); // 保存见证人员姓名
  1690. }
  1691. else {
  1692. CSimpleStringW aa = szWitnessName.SubString(0,4);
  1693. sprintf(subTitle.Reserved2,"%s...",(LPCTSTR)CSimpleStringW2A(aa));
  1694. }
  1695. Dbg("subTitle.WitnessName=%s",subTitle.Reserved2);
  1696. Dbg("[OFLRecordInit]:%d", OFLRecordInit(result));
  1697. }
  1698. delete[] tmp;
  1699. tmp = NULL;
  1700. SubtitleParam subtitleParam;
  1701. ZeroMemory(&subtitleParam,sizeof(SubtitleParam));
  1702. subtitleParam.bSubtitle = TRUE;
  1703. subtitleParam.bSubtitleSection = TRUE;
  1704. subtitleParam.topSubtitleData[0] = '\0';
  1705. if (strlen(subTitle.SapID)>0&&strlen(subTitle.CustManagerName)>0) // 有无客户经理的双录字幕 edit by ly @2018/01/10
  1706. {
  1707. sprintf(subtitleParam.bottomSubtitleData1, "%s %s %s", subTitle.CustCardNo, subTitle.CustName, subTitle.ProductCode);
  1708. sprintf(subtitleParam.bottomSubtitleData2, "%s %s %s", subTitle.ProductName, subTitle.SapID, subTitle.CustManagerName);
  1709. if (strstr(m_SalesVideoName,"OFL") && stricmp(subTitle.Reserved1,"X") && stricmp(subTitle.Reserved2,"X"))
  1710. {
  1711. sprintf(subtitleParam.bottomSubtitleData1, "%s %s %s %s", subTitle.CustCardNo, subTitle.CustName, subTitle.ProductCode, subTitle.ProductName);
  1712. sprintf(subtitleParam.bottomSubtitleData2, "%s %s %s %s", subTitle.SapID, subTitle.CustManagerName, subTitle.Reserved1, subTitle.Reserved2);
  1713. }
  1714. }
  1715. else
  1716. {
  1717. sprintf(subtitleParam.bottomSubtitleData1, "%s %s", subTitle.CustCardNo, subTitle.CustName);
  1718. sprintf(subtitleParam.bottomSubtitleData2, "%s %s", subTitle.ProductCode, subTitle.ProductName);
  1719. }
  1720. int i_audio_out_bitrate = m_audio_out_bitrate;
  1721. if (bRemoteRecord)
  1722. {
  1723. if (m_eDeviceType == eStand2sType) { //如果是大机
  1724. eRecordType = eStand2Agent; //可视柜台大机的双向录像
  1725. }
  1726. else{
  1727. eRecordType = ePad2Agent; //可视柜台pad的双向录像
  1728. }
  1729. if(256 == m_audio_out_bitrate){
  1730. i_audio_out_bitrate = 128;
  1731. Dbg("change remote record audio out bitrate to %d.", i_audio_out_bitrate);
  1732. }
  1733. }
  1734. StartRecord(m_SalesVideoName, 90, i_audio_out_bitrate, &subtitleParam, m_bWholeSection, FALSE, eRecordType);
  1735. }
  1736. //void CSalesRecorderEntity::HandleStartRecord(const char *pszMessage)
  1737. //{
  1738. // int nRecordBothSideType = 0;
  1739. // /*Dbg("pszMessage = %s", pszMessage);*/
  1740. // char *tmp = new char[strlen(pszMessage)+1];
  1741. // m_bEwsRecord = FALSE;
  1742. // if (strlen(pszMessage)>=4&&!strnicmp(pszMessage,"ews|",4))
  1743. // {
  1744. // m_bEwsRecord = TRUE;
  1745. // }
  1746. //
  1747. // if (!m_bEwsRecord)
  1748. // {
  1749. // strcpy(tmp, pszMessage);
  1750. // }
  1751. // else
  1752. // {
  1753. // strcpy(tmp, pszMessage+4);
  1754. // }
  1755. //
  1756. // char *result[16] = {0};
  1757. // //CStringSplit(tmp, result, "@");
  1758. // // 解决中文stringsplit偶现乱码的问题 edit by ly@2018/07/04
  1759. // auto arr1 = CSimpleStringA2W(tmp).Split('@');
  1760. // auto arr2 = CAutoArray<CSimpleStringA>(arr1.GetCount());
  1761. // for (int i = 0; i < arr1.GetCount(); ++i)
  1762. // {
  1763. // arr2[i] = CSimpleStringW2A(arr1[i]);
  1764. // result[i] = const_cast<LPSTR>(arr2[i].GetData());
  1765. // }
  1766. //
  1767. // sprintf(m_SalesVideoName, "%s", result[4]);//录像名:录像类型标志_录像流水号(如S_C13213EF)
  1768. // RecordSubTitle subTitle;
  1769. // ZeroMemory(&subTitle,sizeof(RecordSubTitle));
  1770. // strcpy(subTitle.CustCardNo, result[5]);
  1771. //
  1772. // char *pStr = result[6]; // edit by ly 2018/03/21
  1773. // CSimpleStringW szCustName = CSimpleStringA2W(pStr);
  1774. // if (szCustName.GetLength() <= 4) {
  1775. // strcpy(subTitle.CustName, pStr);
  1776. // }
  1777. // else {
  1778. // CSimpleStringW aa = szCustName.SubString(0,4);
  1779. // sprintf(subTitle.CustName,"%s...",(LPCTSTR)CSimpleStringW2A(aa));
  1780. // }
  1781. // /*Dbg("lytest subTitle.CustName=%s",subTitle.CustName);*/
  1782. //
  1783. // // 解决产品代码、产品名称过长,画面上显示不下的问题 add by ly at 20160603(edit by ly 2018/03/21)
  1784. // // 朝朝赢和招财赢支持双向录像
  1785. // pStr = result[7];
  1786. // int nProductCodeLen = strlen(pStr);
  1787. // Dbg("ProductCode = %s, and nProductCodeLen = %d.", pStr, nProductCodeLen);
  1788. // if (0 == memcmp(pStr, "000607", nProductCodeLen) || 0 == memcmp(pStr, "ZCY", nProductCodeLen))
  1789. // {
  1790. // if (m_eDeviceType == eStand2sType) //如果是大机
  1791. // {
  1792. // nRecordBothSideType = 3; //可视柜台大机的双向录像
  1793. // }
  1794. // else
  1795. // {
  1796. // nRecordBothSideType = 2; //可视柜台pad的双向录像
  1797. // }
  1798. // Dbg("nRecordBothSideType =%d", nRecordBothSideType);
  1799. // }
  1800. // if (nProductCodeLen <= 10) {
  1801. // strcpy(subTitle.ProductCode, pStr);
  1802. // }
  1803. // else {
  1804. // char aa[5]={0},bb[5]={0};
  1805. // strncpy(aa, pStr, 4);
  1806. // strncpy(bb, pStr+nProductCodeLen-4, 4);
  1807. // sprintf(subTitle.ProductCode,"%s...%s",aa,bb);
  1808. // }
  1809. // Dbg("lytest subTitle.ProductCode=%s",subTitle.ProductCode);
  1810. //
  1811. // pStr = result[8];
  1812. // CSimpleStringW szProductName = CSimpleStringA2W(pStr);
  1813. // if (szProductName.GetLength() <= 5) {
  1814. // strcpy(subTitle.ProductName, pStr);
  1815. // }
  1816. // else {
  1817. // CSimpleStringW aa = szProductName.SubString(0,3);
  1818. // CSimpleStringW bb = szProductName.SubString(szProductName.GetLength()-2,2);
  1819. // sprintf(subTitle.ProductName,"%s...%s",(LPCTSTR)CSimpleStringW2A(aa),(LPCTSTR)CSimpleStringW2A(bb));
  1820. // }
  1821. // Dbg("lytest subTitle.ProductName=%s",subTitle.ProductName);
  1822. //
  1823. // // edit by ly @2018/03/21
  1824. // if (result[9]) {
  1825. // strcpy(subTitle.SapID, result[9]);
  1826. // } else {
  1827. // subTitle.SapID[0] = '\0';
  1828. // }
  1829. // if (result[10]) {
  1830. // pStr = result[10];
  1831. // CSimpleStringW szCustManagerName = CSimpleStringA2W(pStr);
  1832. // if (szCustManagerName.GetLength() <= 4) {
  1833. // strcpy(subTitle.CustManagerName, result[10]);
  1834. // }
  1835. // else {
  1836. // CSimpleStringW aa = szCustManagerName.SubString(0,4);
  1837. // sprintf(subTitle.CustManagerName,"%s...",(LPCTSTR)CSimpleStringW2A(aa));
  1838. // }
  1839. // } else {
  1840. // subTitle.CustManagerName[0] = '\0';
  1841. // }
  1842. // Dbg("lytest subTitle.CustManagerName=%s",subTitle.CustManagerName);
  1843. //
  1844. // // 如果是离线双录,则保存业务要素到外存 add by ly 2018/03/08
  1845. // if (strstr(m_SalesVideoName, "OFL")) {
  1846. // strcpy(subTitle.Reserved1, result[14]); // 保存见证人员sap
  1847. //
  1848. // pStr = result[15];
  1849. // CSimpleStringW szWitnessName = CSimpleStringA2W(pStr);
  1850. // if (szWitnessName.GetLength() <= 4) {
  1851. // strcpy(subTitle.Reserved2, result[15]); // 保存见证人员姓名
  1852. // }
  1853. // else {
  1854. // CSimpleStringW aa = szWitnessName.SubString(0,4);
  1855. // sprintf(subTitle.Reserved2,"%s...",(LPCTSTR)CSimpleStringW2A(aa));
  1856. // }
  1857. // Dbg("lytest subTitle.WitnessName=%s",subTitle.Reserved2);
  1858. //
  1859. // Dbg("[OFLRecordInit]:%d", OFLRecordInit(result));
  1860. // }
  1861. //
  1862. // delete[] tmp;
  1863. // tmp = NULL;
  1864. //
  1865. // SubtitleParam subtitleParam;
  1866. // ZeroMemory(&subtitleParam,sizeof(SubtitleParam));
  1867. // subtitleParam.bSubtitle = TRUE;
  1868. // subtitleParam.bSubtitleSection = TRUE;
  1869. // subtitleParam.topSubtitleData[0] = '\0';
  1870. // if (strlen(subTitle.SapID)>0&&strlen(subTitle.CustManagerName)>0) // 有无客户经理的双录字幕 edit by ly @2018/01/10
  1871. // {
  1872. // sprintf(subtitleParam.bottomSubtitleData1, "%s %s %s", subTitle.CustCardNo, subTitle.CustName, subTitle.ProductCode);
  1873. // sprintf(subtitleParam.bottomSubtitleData2, "%s %s %s", subTitle.ProductName, subTitle.SapID, subTitle.CustManagerName);
  1874. // if (strstr(m_SalesVideoName,"OFL") && stricmp(subTitle.Reserved1,"X") && stricmp(subTitle.Reserved2,"X"))
  1875. // {
  1876. // sprintf(subtitleParam.bottomSubtitleData1, "%s %s %s %s", subTitle.CustCardNo, subTitle.CustName, subTitle.ProductCode, subTitle.ProductName);
  1877. // sprintf(subtitleParam.bottomSubtitleData2, "%s %s %s %s", subTitle.SapID, subTitle.CustManagerName, subTitle.Reserved1, subTitle.Reserved2);
  1878. // }
  1879. // }
  1880. // else
  1881. // {
  1882. // sprintf(subtitleParam.bottomSubtitleData1, "%s %s", subTitle.CustCardNo, subTitle.CustName);
  1883. // sprintf(subtitleParam.bottomSubtitleData2, "%s %s", subTitle.ProductCode, subTitle.ProductName);
  1884. // }
  1885. //
  1886. // // edit by ly@20180725
  1887. // LOG_TRACE("nRecordBothSideType = %d.", nRecordBothSideType);
  1888. // StartRecord(m_SalesVideoName, 90, m_audio_out_bitrate, &subtitleParam, m_bWholeSection, FALSE, nRecordBothSideType);
  1889. //}
  1890. ErrorCodeEnum CSalesRecorderEntity::HandleStopRecord(const char *pszMessage)
  1891. {
  1892. ErrorCodeEnum ErrorCode = StopRecord();
  1893. // 保存录像时长(秒) add by ly 2018/02/13
  1894. if (strstr(m_SalesVideoName, "OFL")&&pszMessage&&strlen(pszMessage)>0) {
  1895. SaveOFLRecordDuration(atoi(pszMessage));
  1896. }
  1897. return ErrorCode;
  1898. }
  1899. ErrorCodeEnum CSalesRecorderEntity::HandleSetAudioTransmissionFlag(bool bFlag)
  1900. {
  1901. ErrorCodeEnum ErrorCode = Error_Succeed;
  1902. m_bIsAudioTransOn = bFlag;
  1903. Dbg("Set Audio Transmission Flag to %s.", m_bIsAudioTransOn ? "true" : "false");
  1904. return ErrorCode;
  1905. }
  1906. ErrorCodeEnum CSalesRecorderEntity::HandleStopAudioStreamEnTransQueue()
  1907. {
  1908. ErrorCodeEnum eCode = Error_Succeed;
  1909. if (m_bIsAudioTransOn)
  1910. {
  1911. m_pRecorder->StopAudioEnTransQueue();
  1912. m_bIsAudioTransOn = false;
  1913. }
  1914. else {
  1915. eCode = Error_NotImpl;
  1916. }
  1917. return eCode;
  1918. }
  1919. ErrorCodeEnum CSalesRecorderEntity::HandleDisplayVideo()
  1920. {
  1921. // 视频播放 libwmpplayer
  1922. m_bIsShowVideo = TRUE;
  1923. Dbg("play record file name is %s!", m_SalesVideoName);
  1924. ErrorCodeEnum ErrorCode = ShowVideo(m_SalesVideoName);
  1925. return ErrorCode;
  1926. }
  1927. ErrorCodeEnum CSalesRecorderEntity::HandlePlaySalesRecordVideo(int iWndX, int iWndY, int iWndWidth, int iWndHeight)
  1928. {
  1929. // 视频播放 libwmpplayer
  1930. m_bIsShowVideo = TRUE;
  1931. Dbg("play sales record video file name is %s!", m_SalesVideoName);
  1932. ErrorCodeEnum ErrorCode = PlaySalesRecordVideo(m_SalesVideoName, iWndX, iWndY, iWndWidth, iWndHeight);
  1933. Dbg("play sales record video return code is 0x%08x.", ErrorCode);
  1934. return ErrorCode;
  1935. }
  1936. ErrorCodeEnum CSalesRecorderEntity::HandleStopShowVideo()
  1937. {
  1938. // 视频播放 libwmpplayer
  1939. Dbg("stop show video record file name is %s!", m_SalesVideoName);
  1940. ErrorCodeEnum ErrorCode = Error_Succeed;
  1941. if(m_bIsShowVideo)
  1942. {
  1943. Dbg("m_pPlayer = %p while play!", m_pPlayer);
  1944. m_pPlayer->Close();
  1945. m_bIsShowVideo = FALSE;
  1946. Dbg("succeed to stop show video!");
  1947. }
  1948. else{
  1949. ErrorCode = Error_NotImpl;
  1950. }
  1951. return ErrorCode;
  1952. }
  1953. ErrorCodeEnum CSalesRecorderEntity::HandleSaveVideo()
  1954. {
  1955. ErrorCodeEnum ErrorCode = Error_Succeed;
  1956. // 将视频从tmp移动到uploadvideo
  1957. if (!strstr(m_SalesVideoName, "OFL")) // edit by ly 20180228
  1958. {
  1959. ErrorCode = SaveVideo(m_SalesVideoName+2);
  1960. }
  1961. else
  1962. {
  1963. ErrorCode = SaveVideo(m_SalesVideoName+4);
  1964. }
  1965. // 尝试提交离线双录记录 add by ly 2018/02/13
  1966. if (strstr(m_SalesVideoName, "OFL") && CheckNetState() == Error_Succeed) {
  1967. CSimpleStringA cfn = CSimpleStringA::Format("%s%s.txt",(LPCTSTR)m_TempDir,m_SalesVideoName);
  1968. UploadOFLVideoRecord((LPCTSTR)cfn);
  1969. }
  1970. ZeroMemory(m_SalesVideoName,sizeof(m_SalesVideoName));
  1971. return ErrorCode;
  1972. }
  1973. void CSalesRecorderEntity::HandleDeleteVideo()
  1974. {
  1975. if (strstr(m_SalesVideoName, "OFL")) {
  1976. // 删除录像记录临时文件
  1977. CSimpleStringA cfn = CSimpleStringA::Format("%s%s.txt", (LPCTSTR)m_TempDir, m_SalesVideoName);
  1978. DeleteFile(cfn);
  1979. }
  1980. // 删除tmp中的视频
  1981. DeleteVideo(m_SalesVideoName); // edit by ly 20151119
  1982. ZeroMemory(m_SalesVideoName,sizeof(m_SalesVideoName));
  1983. }
  1984. void CSalesRecorderEntity::HandleReturnMenu()
  1985. {
  1986. CSimpleStringA strValue;
  1987. GetFunction()->GetSysVar("DesktopType", strValue);
  1988. if (strValue != CSimpleStringA("U"))
  1989. {
  1990. if (m_bStarted) // 如果正在进行客户经理录像
  1991. {
  1992. // 停止录像
  1993. Dbg("stop record and return menu!");
  1994. StopRecord();
  1995. }
  1996. else if (m_bIsShowVideo) // 如果正在播放客户经理录像
  1997. {
  1998. Dbg("auto close play and return menu!");
  1999. m_pPlayer->Close();
  2000. m_bIsShowVideo = FALSE;
  2001. }
  2002. // 删除tmp中的视频
  2003. if (strlen(m_SalesVideoName) > 0)
  2004. {
  2005. Dbg("delete sales record!");
  2006. DeleteAllVideo(m_SalesVideoName+2); // edit by ly 20160713
  2007. }
  2008. ZeroMemory(m_SalesVideoName,sizeof(m_SalesVideoName));
  2009. }
  2010. }
  2011. void CSalesRecorderEntity::HandleUkeyPullout()
  2012. {
  2013. if (m_SalesVideoName && strstr(m_SalesVideoName, "OFL"))
  2014. {
  2015. if (m_bStarted) // 如果正在进行客户经理录像
  2016. {
  2017. // 停止录像
  2018. Dbg("stop record and return menu!");
  2019. StopRecord();
  2020. }
  2021. else if (m_bIsShowVideo) // 如果正在播放客户经理录像
  2022. {
  2023. Dbg("auto close play and return menu!");
  2024. m_pPlayer->Close();
  2025. m_bIsShowVideo = FALSE;
  2026. }
  2027. // 删除录像记录临时文件
  2028. CSimpleStringA cfn = CSimpleStringA::Format("%s%s.txt", (LPCTSTR)m_TempDir, m_SalesVideoName);
  2029. DeleteFile(cfn);
  2030. // 删除tmp中的视频
  2031. if (strlen(m_SalesVideoName) > 0)
  2032. {
  2033. Dbg("delete sales record!");
  2034. DeleteAllVideo(m_SalesVideoName+4);
  2035. }
  2036. ZeroMemory(m_SalesVideoName,sizeof(m_SalesVideoName));
  2037. StopRecordVideo();
  2038. }
  2039. }
  2040. void CSalesRecorderEntity::HandleVideoAppendWatermark(const char* pszMessage)
  2041. {
  2042. if (NULL == pszMessage){
  2043. return;
  2044. }
  2045. char *result[10] = {0};
  2046. auto arr1 = CSimpleStringA2W(pszMessage).Split('|');
  2047. auto arr2 = CAutoArray<CSimpleStringA>(arr1.GetCount());
  2048. int icount = sizeof(result)/sizeof(char*);
  2049. for (int i = 0; i < arr1.GetCount() && i < sizeof(result)/sizeof(char*); i++)
  2050. {
  2051. arr2[i] = CSimpleStringW2A(arr1[i]);
  2052. result[i] = const_cast<LPSTR>(arr2[i].GetData());
  2053. }
  2054. Dbg("m_SalesVideoName = %s, strVideoName = %s, strWaterMark = %s.",m_SalesVideoName, result[0], result[1]);
  2055. if (m_bStarted && (NULL != m_pRecorder))
  2056. {
  2057. m_pRecorder->SetRightVideoWaterMark(result[1]);
  2058. }
  2059. }
  2060. ErrorCodeEnum CSalesRecorderEntity::HandleSalesRecordEntityException(const char* pszMessage)
  2061. {
  2062. // 通知到业务中台
  2063. SalesRecordException evt;
  2064. evt.failedmsg = CSimpleStringA2W(pszMessage==NULL?"现场销售双录过程出现异常!":pszMessage);
  2065. SpSendBroadcast(GetFunction(), SP_MSG_OF(SalesRecordException), SP_MSG_SIG_OF(SalesRecordException), evt);
  2066. Dbg("[dbg] SalesRecord entity exception broadcast sent!");
  2067. //停止录像
  2068. StopRecord();
  2069. m_bNeedRestart = true;
  2070. //重启实体
  2071. RealSelfCheck();
  2072. return Error_Succeed;
  2073. }
  2074. ErrorCodeEnum CSalesRecorderEntity::RealSelfCheck()
  2075. {
  2076. ErrorCodeEnum Error = Error_Succeed;
  2077. SelfChekerClient* pSelfcheckClient = new SelfChekerClient(this);
  2078. Error = pSelfcheckClient->Connect();
  2079. if (Error != Error_Succeed)
  2080. {
  2081. pSelfcheckClient->SafeDelete();
  2082. pSelfcheckClient = NULL;
  2083. Dbg("SelfcheckClient connect fail!");
  2084. }
  2085. else
  2086. {
  2087. Dbg("SelfcheckClient connect success!");
  2088. }
  2089. if (pSelfcheckClient)
  2090. {
  2091. SelfChecker::SelfCheckerService_RealCheck_Req req;
  2092. req.name = GetEntityName();
  2093. SelfChecker::SelfCheckerService_RealCheck_Ans ans;
  2094. DWORD Timeout = 500;
  2095. Error = pSelfcheckClient->RealCheck(req,ans,Timeout);
  2096. if (Error!=Error_Succeed)
  2097. {
  2098. Dbg("RealSelfcheck fail!");
  2099. }
  2100. else
  2101. {
  2102. Dbg("RealSelfcheck success!");
  2103. }
  2104. pSelfcheckClient->GetFunction()->CloseSession();
  2105. }
  2106. return Error;
  2107. }
  2108. #ifdef RVC_OS_WIN
  2109. bool IsMatchedVideo(WIN32_FIND_DATA fileData)
  2110. {
  2111. bool bRet = false;
  2112. if ('S' == fileData.cFileName[0] || 'W' == fileData.cFileName[0]){
  2113. SYSTEMTIME sysTime;
  2114. FileTimeToSystemTime(&fileData.ftCreationTime, &sysTime);
  2115. Dbg("File %s create data info is %d %d %d.", fileData.cFileName, sysTime.wYear, sysTime.wMonth, sysTime.wDay);
  2116. if ((2020 == sysTime.wYear) && (sysTime.wMonth == 1)){
  2117. if (sysTime.wDay >= 3 && sysTime.wDay <= 10){
  2118. bRet = true;
  2119. }
  2120. }
  2121. }
  2122. return bRet;
  2123. }
  2124. void CSalesRecorderEntity::UploadTempPathVideos()
  2125. {
  2126. CSimpleStringA sourPath;
  2127. CSimpleStringA destPath;
  2128. ErrorCodeEnum Error = GetFunction()->GetPath("Temp", sourPath);
  2129. Error = GetFunction()->GetPath("UploadVideo", destPath);
  2130. if (sourPath.GetLength() > 0 && sourPath[sourPath.GetLength()-1] != SPLIT_SLASH) {
  2131. sourPath += SPLIT_SLASH_STR;
  2132. }
  2133. if (destPath.GetLength() > 0 && destPath[destPath.GetLength()-1] != SPLIT_SLASH) {
  2134. destPath += SPLIT_SLASH_STR;
  2135. }
  2136. if(Error == Error_Succeed)
  2137. {
  2138. char srcFilePath[MAX_PATH]={0};
  2139. WIN32_FIND_DATA FindFileData;
  2140. HANDLE hFind;
  2141. BOOL fFinished = FALSE;
  2142. sprintf_s(srcFilePath, MAX_PATH, "%s*.wmv", sourPath);
  2143. hFind = FindFirstFile(srcFilePath, &FindFileData);
  2144. if (INVALID_HANDLE_VALUE != hFind)
  2145. {
  2146. while (!fFinished)
  2147. {
  2148. if (FILE_ATTRIBUTE_DIRECTORY & FindFileData.dwFileAttributes)
  2149. {
  2150. continue;
  2151. }
  2152. if (IsMatchedVideo(FindFileData)){
  2153. CSimpleStringA sourFileName = CSimpleStringA::Format("%s%s", (LPCSTR)sourPath, FindFileData.cFileName);
  2154. CSimpleStringA destFileName = CSimpleStringA::Format("%sBAK_%s", (LPCSTR)destPath, FindFileData.cFileName);
  2155. if(!MoveFile((LPCSTR)sourFileName, (LPCSTR)destFileName)) {
  2156. Dbg("Error Code %lu while move %s ", GetLastError(), (LPCSTR)sourFileName);
  2157. }else{
  2158. Dbg("Move File %s success.", (LPCSTR)sourFileName);
  2159. }
  2160. }
  2161. else{
  2162. Dbg("File (%s) is not matched.", FindFileData.cFileName);
  2163. }
  2164. if (!FindNextFile(hFind, &FindFileData))
  2165. {
  2166. if (GetLastError() == ERROR_NO_MORE_FILES)
  2167. {
  2168. fFinished = TRUE;
  2169. }
  2170. else
  2171. {
  2172. break;
  2173. }
  2174. }
  2175. }
  2176. FindClose(hFind);
  2177. }
  2178. }
  2179. }
  2180. #else
  2181. /*
  2182. **time_t转SYSTEMTIME
  2183. */
  2184. SYSTEMTIME Time_tToSystemTime(time_t t)
  2185. {
  2186. tm temptm = *localtime(&t);
  2187. SYSTEMTIME st = { 1900 + temptm.tm_year,
  2188. 1 + temptm.tm_mon,
  2189. temptm.tm_wday,
  2190. temptm.tm_mday,
  2191. temptm.tm_hour,
  2192. temptm.tm_min,
  2193. temptm.tm_sec,
  2194. 0 };
  2195. return st;
  2196. }
  2197. bool IsMatchedVideo(LPCTSTR path, struct dirent* file)
  2198. {
  2199. bool bRet = false;
  2200. if ((file->d_reclen > 0) && ('S' == file->d_name[0] || 'W' == file->d_name[0])){
  2201. struct stat fileInfo;
  2202. char ttp[256];
  2203. bzero(ttp, sizeof(ttp));
  2204. strcat(ttp, path);
  2205. if (strcmp(ttp, "/") != 0)strcat(ttp, "/");//如果是根目录不需要加
  2206. strcat(ttp, file->d_name);
  2207. if (stat(ttp, &fileInfo) == 0) {
  2208. SYSTEMTIME sysTime;
  2209. sysTime = Time_tToSystemTime(fileInfo.st_mtime);
  2210. Dbg("File %s create data info is %d %d %d.", file->d_name, sysTime.wYear, sysTime.wMonth, sysTime.wDay);
  2211. if ((2020 == sysTime.wYear) && (sysTime.wMonth == 1)) {
  2212. if (sysTime.wDay >= 3 && sysTime.wDay <= 10) {
  2213. bRet = true;
  2214. }
  2215. }
  2216. }
  2217. }
  2218. return bRet;
  2219. }
  2220. void CSalesRecorderEntity::UploadTempPathVideos() {
  2221. CSimpleStringA sourPath;
  2222. CSimpleStringA destPath;
  2223. ErrorCodeEnum Error = GetFunction()->GetPath("Temp", sourPath);
  2224. Error = GetFunction()->GetPath("UploadVideo", destPath);
  2225. if (sourPath.GetLength() > 0 && sourPath[sourPath.GetLength() - 1] != SPLIT_SLASH) {
  2226. sourPath += SPLIT_SLASH_STR;
  2227. }
  2228. if (destPath.GetLength() > 0 && destPath[destPath.GetLength() - 1] != SPLIT_SLASH) {
  2229. destPath += SPLIT_SLASH_STR;
  2230. }
  2231. if (Error == Error_Succeed)
  2232. {
  2233. char srcFilePath[MAX_PATH] = { 0 };
  2234. DIR* pDir = NULL;
  2235. struct dirent* pFile = NULL;
  2236. sprintf_s(srcFilePath, MAX_PATH, "%s*.wmv", sourPath);
  2237. pDir = opendir(sourPath);
  2238. if (pDir == NULL) return ;
  2239. while ((pFile = readdir(pDir)) != NULL) {
  2240. if (pFile->d_type & DT_DIR) {
  2241. //m_pHostApi->Debug("MoveTempPathVideos DIR name: %s.", pFile->d_name);
  2242. continue;
  2243. }
  2244. else {
  2245. //m_pHostApi->Debug("MoveTempPathVideos FILE name: %s.", pFile->d_name);
  2246. if (IsMatchedVideo((LPCSTR)sourPath, pFile)) {
  2247. CSimpleStringA sourFileName = CSimpleStringA::Format("%s%s", (LPCSTR)sourPath, pFile->d_name);
  2248. CSimpleStringA destFileName = CSimpleStringA::Format("%sBAK_%s", (LPCSTR)destPath, pFile->d_name);
  2249. if (!MoveFile((LPCSTR)sourFileName, (LPCSTR)destFileName)) {
  2250. Dbg("Error Code %lu while move %s ", GetLastError(), (LPCSTR)sourFileName);
  2251. }
  2252. else {
  2253. Dbg("Move File %s success.", (LPCSTR)sourFileName);
  2254. }
  2255. }
  2256. else {
  2257. Dbg("File (%s) is not matched.", pFile->d_name);
  2258. }
  2259. }
  2260. }
  2261. closedir(pDir);
  2262. }
  2263. }
  2264. #endif
  2265. int CSalesRecorderEntity::GetSystemMemoryUsage()
  2266. {
  2267. #ifdef RVC_OS_WIN
  2268. // Use to convert bytes to KB
  2269. #define DIV 1024
  2270. MEMORYSTATUSEX statex;
  2271. statex.dwLength = sizeof (statex);
  2272. GlobalMemoryStatusEx (&statex);
  2273. return statex.dwMemoryLoad;
  2274. #else
  2275. //todo 从resourcewatcher获取
  2276. return 0;
  2277. #endif
  2278. }
  2279. double CSalesRecorderEntity::GetSystemCpuUsage()
  2280. {
  2281. #ifdef RVC_OS_WIN
  2282. double ratio = 0;
  2283. #define _WIN32_WINNT 0x0601
  2284. FILETIME idleTime,kernelTime,userTime;
  2285. BOOL ret = GetSystemTimes(&idleTime,&kernelTime,&userTime);
  2286. if (ret == 0)
  2287. {
  2288. Dbg("GetSystemCPUStatus.GetSystemTimes failed(%d).",GetLastError());
  2289. return 80.0;
  2290. }
  2291. __int64 xIdle,xKernel,xUser;
  2292. xIdle = idleTime.dwHighDateTime;
  2293. xIdle <<= 32;
  2294. xIdle |= idleTime.dwLowDateTime;
  2295. xKernel = kernelTime.dwHighDateTime;
  2296. xKernel <<= 32;
  2297. xKernel |= kernelTime.dwLowDateTime;
  2298. xUser = userTime.dwHighDateTime;
  2299. xUser <<= 32;
  2300. xUser |= userTime.dwLowDateTime;
  2301. if (m_xIdlePre != 0)
  2302. {
  2303. __int64 xI,xK,xU;
  2304. xI = xIdle - m_xIdlePre;
  2305. xK = xKernel - m_xKernelPre;
  2306. xU = xUser - m_xUserPre;
  2307. if ((xK +xU) != 0)
  2308. ratio = (xK - xI + xU) * 100 / (xK + xU);
  2309. }
  2310. m_xIdlePre = xIdle;
  2311. m_xKernelPre = xKernel;
  2312. m_xUserPre = xUser;
  2313. return ratio;
  2314. #else
  2315. //todo 从resourcewatcher获取
  2316. return 0;
  2317. #endif
  2318. }
  2319. ErrorCodeEnum CSalesRecorderEntity::SetRecordAudioQuality(int iAudioQuality)
  2320. {
  2321. ErrorCodeEnum eRet = Error_Succeed;
  2322. Dbg("iAudioQuality == %d.", iAudioQuality);
  2323. switch (iAudioQuality)
  2324. {
  2325. case 1:
  2326. m_eAudioOutQuality = eLowDefinition;
  2327. break;
  2328. case 2:
  2329. m_eAudioOutQuality = eStandardDefinition;
  2330. break;
  2331. case 3:
  2332. m_eAudioOutQuality = eHighDefinition;
  2333. break;
  2334. case 4:
  2335. m_eAudioOutQuality = eUltraHD;
  2336. break;
  2337. default:
  2338. m_eAudioOutQuality = eUltraHD;
  2339. break;
  2340. }
  2341. return eRet;
  2342. }
  2343. ErrorCodeEnum CSalesRecorderEntity::SetRecordAudioNsPolicy(int iNsPolicy)
  2344. {
  2345. ErrorCodeEnum eRet = Error_Succeed;
  2346. Dbg("iNsPolicy == %d.", iNsPolicy);
  2347. if (1 == iNsPolicy || 3 == iNsPolicy){
  2348. m_iAudioNsPolicy = iNsPolicy;
  2349. }
  2350. else{
  2351. m_iAudioNsPolicy = 2;
  2352. }
  2353. return eRet;
  2354. }
  2355. DeviceTypeEnum CSalesRecorderEntity::RvcGetDeviceType()
  2356. {
  2357. DeviceTypeEnum eType = eStand2sType;
  2358. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  2359. CSystemStaticInfo stStaticinfo;
  2360. spFunction->GetSystemStaticInfo(stStaticinfo);
  2361. m_terminalNo = stStaticinfo.strTerminalID;
  2362. if (stricmp(stStaticinfo.strMachineType, "RVC.PAD") == 0) {
  2363. if (stricmp(stStaticinfo.strSite, "CMB.FLB") == 0) {
  2364. eType = eMobilePadType;
  2365. }
  2366. else {
  2367. eType = ePadtype;
  2368. }
  2369. }
  2370. else if (stricmp(stStaticinfo.strMachineType, "RVC.Desk2S") == 0) {
  2371. eType = eDesk2SType;
  2372. WORD nMajor = stStaticinfo.MachineVersion.GetMajor();
  2373. WORD nMinor = stStaticinfo.MachineVersion.GetMinor();
  2374. Dbg("MachineVersion is %d.%d", nMajor, nMinor);
  2375. if (2 == nMajor) {
  2376. eType = eDesk2SIntegratedType;
  2377. }
  2378. }
  2379. else if (stricmp(stStaticinfo.strMachineType, "RPM.Stand1S") == 0) {
  2380. eType = eRpm1sType;
  2381. }
  2382. else if (stricmp(stStaticinfo.strMachineType, "RVC.Desk1S") == 0) {
  2383. eType = eDesk1SType;
  2384. }
  2385. else {
  2386. eType = eStand2sType;
  2387. }
  2388. if (eType >= 0 && eType < sizeof(Device_Type_Table) / sizeof(char*)) {
  2389. LOG_TRACE("device type is %s.", Device_Type_Table[eType]);
  2390. }
  2391. return eType;
  2392. }
  2393. SelfChekerClient::SelfChekerClient( CSalesRecorderEntity *pEntity ) : SelfChecker::SelfCheckerService_ClientBase(pEntity)
  2394. {
  2395. }
  2396. void UploadOFLVideoRecordTask::Process()
  2397. {
  2398. return m_pEntity->UploadOFLVideoRecord(NULL);
  2399. }
  2400. SP_BEGIN_ENTITY_MAP()
  2401. SP_ENTITY(CSalesRecorderEntity)
  2402. SP_END_ENTITY_MAP()