mod_SalesRecorder.cpp 84 KB

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