mod_mediacontroller.cpp 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510
  1. #include "stdafx.h"
  2. #include "SpBase.h"
  3. #include "SpIni.h"
  4. #include "y2k_time.h"
  5. #include "capture.h"
  6. #include "Event.h"
  7. #include "../../Other/libaudiorender/iaudiorenderinterface.h"
  8. #include "../include/EventCode.h"
  9. #include "../mod_snapshot/Event.h"
  10. // id:0x208
  11. #include "../mod_assistantchannel/AssistantChannel_client_g.h"
  12. using namespace AssistantChannel;
  13. #include "../mod_assistantchannel/chan_protocol.h"
  14. #include "../mod_selfchecker/SelfChecker_client_g.h"
  15. #include "../mod_selfchecker/SelfChecker_def_g.h"
  16. #include "../include/ModuleMix.h"
  17. #include "MediaController_server_g.h"
  18. #include "MediaController_msg_g.h"
  19. #include "ExternalCameraMsg.h"
  20. using namespace MediaController;
  21. using namespace SelfChecker;
  22. #include "../mod_ScannerSet/ScannerSet_client_g.h"
  23. #include "../mod_ScannerSet/ScannerSet_def_g.h"
  24. using namespace ScannerSet;
  25. #include "../mod_CameraConfigManage/CameraConfigManage_client_g.h"
  26. #include "../mod_CameraConfigManage/CameraConfigManage_def_g.h"
  27. using namespace CameraConfigManage;
  28. #define LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE 0x50500001 //协助通道重启
  29. struct CCameraBrightValue
  30. {
  31. int nValue;
  32. void Serialize(SpBuffer &Buf)
  33. {
  34. Buf & nValue;
  35. }
  36. };
  37. class CMediaControllerEntity;
  38. class SelfChekerClient:public SelfCheckerService_ClientBase
  39. {
  40. public:
  41. SelfChekerClient(CMediaControllerEntity*pEntity);
  42. };
  43. class ChannelMediaControllerClient : public ChannelService_ClientBase
  44. {
  45. public:
  46. ChannelMediaControllerClient(CMediaControllerEntity *pEntity);
  47. virtual void OnMessage(ErrorCodeEnum Error, ChannelService_State_Info &Msg, CSmartPointer<IReleasable> pData);
  48. virtual void OnMessage(ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer<IReleasable> pData);
  49. };
  50. class MediaServiceSession : public MediaService_ServerSessionBase
  51. {
  52. public:
  53. MediaServiceSession(CMediaControllerEntity *pEntity) : m_pEntity(pEntity){}
  54. virtual void Handle_GetVideoDeviceName(SpReqAnsContext<MediaService_GetVideoDeviceName_Req, MediaService_GetVideoDeviceName_Ans>::Pointer ctx);
  55. virtual void Handle_StartCamera(SpOnewayCallContext<MediaService_StartCamera_Info>::Pointer ctx);
  56. virtual void Handle_StopCamera(SpOnewayCallContext<MediaService_StopCamera_Info>::Pointer ctx);
  57. virtual void Handle_StartEnvCamera(SpReqAnsContext<MediaService_StartEnvCamera_Req, MediaService_StartEnvCamera_Ans>::Pointer ctx);
  58. virtual void Handle_StopEnvCamera(SpOnewayCallContext<MediaService_StopEnvCamera_Info>::Pointer ctx);
  59. //add by clp 20200319
  60. virtual void Handle_StartSpeakerRender(SpOnewayCallContext<MediaService_StartSpeakerRender_Info>::Pointer ctx);
  61. virtual void Handle_StopSpeakerRender(SpOnewayCallContext<MediaService_StopSpeakerRender_Info>::Pointer ctx);
  62. private:
  63. CMediaControllerEntity *m_pEntity;
  64. };
  65. class CMediaControllerEntity : public CEntityBase, public ILogListener, public ITimerListener,public ISysVarListener
  66. {
  67. public:
  68. CMediaControllerEntity() : m_capture(NULL),m_salesaudio_capture(NULL), m_lCaptureEnvCount(0),m_nCameraErrorCode(Error_Succeed),
  69. m_lCaptureEnvOptCount(0), m_lCaptureOptCount(0), m_iEnvEmptyTimes(0), m_iOptEmptyTimes(0),m_bSendCameraError(false),
  70. m_nEnvCameraRestartNum(0),m_nOptCameraRestartNum(0), m_nCameraCount(2),m_pSelfcheckClient(NULL),
  71. strFrontCam("$"), strRearCam("$"), strEnvCam("$"), strUSBCam("$"), strEwsCam("$"), m_bCustomerwareBegin(false),
  72. m_pAudioRenderObj(NULL), m_bRecordPCM(false),m_bIsRemoteRecord(false),m_bHasStartSpeakerRender(false){}
  73. virtual ~CMediaControllerEntity() {}
  74. virtual const char *GetEntityName() const { return "MediaController"; }
  75. virtual bool IsService()const{return true;}
  76. virtual void OnSysVarEvent(const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName)
  77. {
  78. if (_stricmp(pszKey, SYSVAR_CALLTYPE) == 0)
  79. {
  80. Dbg("sys call type from: %c to %c", pszOldValue[0], pszValue[0]);
  81. if(pszValue[0] == CALLTYPE_NORMAL)
  82. {
  83. m_nSysCallType = 0;
  84. }
  85. else if(pszValue[0] == CALLTYPE_MOBILE)
  86. {
  87. m_nSysCallType = 1;
  88. }
  89. else
  90. {
  91. m_nSysCallType = -1;
  92. }
  93. }
  94. }
  95. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
  96. {
  97. m_eDeviceType = eStand2sType;
  98. g_eDeviceType = eStand2sType;
  99. m_bStartCamera = FALSE;
  100. m_bExternControlCam = FALSE;
  101. m_nSysCallType =0;
  102. LOG_FUNCTION();
  103. ErrorCodeEnum Error;
  104. //MessageBoxA(0,0,0,0);
  105. m_pMediaControllerChannel = new ChannelMediaControllerClient(this);
  106. Error = m_pMediaControllerChannel->Connect();
  107. if (Error != Error_Succeed)
  108. {
  109. m_pMediaControllerChannel->SafeDelete();
  110. Dbg("ChannelMediaControllerClient connect fail!");
  111. pTransactionContext->SendAnswer(Error);
  112. return;
  113. }
  114. else
  115. {
  116. Dbg("ChannelMediaControllerClient connect success!");
  117. }
  118. {
  119. CSmartPointer<IEntityFunction> Func = GetFunction();
  120. CSimpleStringA strValue;
  121. Func->RegistSysVarEvent(SYSVAR_CALLTYPE, this);
  122. Func->GetSysVar(SYSVAR_CALLTYPE, strValue);
  123. if (strValue[0] == CALLTYPE_NORMAL)
  124. {
  125. m_nSysCallType = 0;
  126. }
  127. else if (strValue[0] == CALLTYPE_MOBILE)
  128. {
  129. m_nSysCallType = 1;
  130. }
  131. else
  132. {
  133. assert(0);
  134. }
  135. }
  136. {
  137. ChannelService_BeginState_Sub Sub;
  138. Error = m_pMediaControllerChannel->BeginState(Sub);
  139. if (Error != Error_Succeed)
  140. {
  141. LOG_TRACE("BeginState biz channel failed!");
  142. m_pMediaControllerChannel->GetFunction()->CloseSession();
  143. m_pMediaControllerChannel->SafeDelete();
  144. m_pMediaControllerChannel = NULL;
  145. pTransactionContext->SendAnswer(Error);
  146. return;
  147. }
  148. else
  149. {
  150. Dbg("BeginState biz channel success!");
  151. }
  152. }
  153. {
  154. ChannelService_BeginRecv_Sub Sub;
  155. Sub.type = ACM_TYPE_DEVICE;
  156. Error = m_pMediaControllerChannel->BeginRecv(Sub);
  157. if (Error != Error_Succeed)
  158. {
  159. Dbg("Begin BeginRecv ACM_TYPE_DEVICE failed!");
  160. m_pMediaControllerChannel->GetFunction()->CloseSession();
  161. m_pMediaControllerChannel->SafeDelete();
  162. m_pMediaControllerChannel = NULL;
  163. pTransactionContext->SendAnswer(Error);
  164. return;
  165. }
  166. else
  167. {
  168. Dbg("Begin BeginRecv ACM_TYPE_DEVICE success!");
  169. }
  170. }
  171. //is Pad Version
  172. m_eDeviceType = RvcGetDeviceType();
  173. g_eDeviceType = m_eDeviceType;
  174. if (Error_Succeed == GetSalesRecordAudioParam()){
  175. Dbg("get sales record audio param success, and sales audio capture sample rate is %d, record local PCM flag is %s.", m_nSalesAudioSmpPsec, m_bRecordPCM ? "true":"false");
  176. }
  177. // only register once!! edit by ly 2017/03/21
  178. if (GetFunction()->RegistSysVarEvent("SessionID", this) != Error_Succeed){
  179. LOG_TRACE("register sysvar %s failed!", "SessionID");
  180. }
  181. memset(&conf,0,sizeof(capture_config_t));
  182. memset(&m_sales_audio_conf, 0, sizeof(rvc_audio_capture_config_t));
  183. Error = (ErrorCodeEnum)capture_lib_init();
  184. if (Error == Error_Succeed)
  185. {
  186. Error = LoadConfig(&conf);
  187. if (Error!=Error_Succeed)
  188. {
  189. if((Error == Error_OptCamera)||(Error == Error_EnvCamera))
  190. {
  191. if (Error == Error_EnvCamera)
  192. {
  193. LOG_TRACE("Load EnvCamera Config failed!");
  194. //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_ENV_ERROR);
  195. SetCameraSysVar(CAMERA_ENV_ERROR);
  196. Dbg("Camera State to CAMERA_ENV_ERROR");
  197. m_nCameraErrorCode = Error_EnvCamera;
  198. GetFunction()->SetUserDefineState(USER_MEDIA_ENVERRROR);
  199. }
  200. else if (Error == Error_OptCamera)
  201. {
  202. LOG_TRACE("Load OptCamera Config failed!");
  203. //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_OPT_ERROR);
  204. SetCameraSysVar(CAMERA_OPT_ERROR);
  205. Dbg("Camera State to CAMERA_OPT_ERROR");
  206. m_nCameraErrorCode = Error_OptCamera;
  207. GetFunction()->SetUserDefineState(USER_MEDIA_OPTERROR);
  208. }
  209. }
  210. else
  211. {
  212. if (Error == Error_AllCamera)
  213. {
  214. LOG_TRACE("Load all camera Config failed!");
  215. //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_BOTH_ERROR);
  216. SetCameraSysVar(CAMERA_BOTH_ERROR);
  217. Dbg("Camera State to CAMERA_BOTH_ERROR");
  218. m_nCameraErrorCode = Error_AllCamera;
  219. GetFunction()->SetUserDefineState(USER_MEDIA_ALLERROR);
  220. }
  221. LOG_TRACE("Load Config failed!");
  222. }
  223. }
  224. if ((ePadtype == m_eDeviceType)||(eMobilePadType == m_eDeviceType)||(eDesk2SType == m_eDeviceType))
  225. {
  226. CAutoArray<CSimpleStringA> hspCams;
  227. auto rc = GetHSPCameras(hspCams);
  228. Dbg("[GetHSPCameras]: (0x%x,%d)", rc, hspCams.GetCount());
  229. /************************************************************************/
  230. /* read runcfg & 暂存strVideoEnv add by ly 20160531 */
  231. /************************************************************************/
  232. if (eDesk2SType == m_eDeviceType)
  233. {
  234. strFrontCam = conf.strVideoEnv;
  235. strRearCam = "$";
  236. // 将内置摄像头写入到运行时配置
  237. SaveInnerCamera();
  238. }
  239. else
  240. {
  241. ErrorCodeEnum ErrCod = LoadRunConfig(strFrontCam, strRearCam);
  242. if (ErrCod == Error_Succeed) {
  243. Dbg("[dbg] Error=0x%x while LoadRunConfig.", ErrCod);
  244. if (strFrontCam.GetLength() <= 1 || strFrontCam != conf.strVideoEnv) {
  245. strFrontCam = conf.strVideoEnv;
  246. if (conf.strVideoOpt.GetLength() <= 1) {
  247. m_nCameraCount = videocap_optdev_fetch(strFrontCam,strEwsCam,hspCams,strRearCam);
  248. }
  249. else { // 如果root.ini中已配置
  250. strRearCam = conf.strVideoOpt;
  251. }
  252. // 将内置摄像头写入到运行时配置
  253. SaveInnerCamera();
  254. }
  255. }
  256. else {
  257. strFrontCam = conf.strVideoEnv;
  258. if (conf.strVideoOpt.GetLength() <= 1) {
  259. m_nCameraCount = videocap_optdev_fetch(strFrontCam,strEwsCam,hspCams,strRearCam);
  260. }
  261. else { // 如果root.ini中已配置
  262. strRearCam = conf.strVideoOpt;
  263. }
  264. // 将内置摄像头写入到运行时配置
  265. SaveInnerCamera();
  266. }
  267. }
  268. // 尝试获取外接摄像头
  269. m_nCameraCount = videocap_outerdev_fetch(strFrontCam,strRearCam,strEwsCam,hspCams,strUSBCam);
  270. Dbg("[dbg] strUSBCam=%s",(LPCTSTR)strUSBCam);
  271. strEnvCam = conf.strVideoEnv;
  272. }
  273. }
  274. else
  275. {
  276. LOG_TRACE("capture_lib_init failed!");
  277. }
  278. //PAD版获取客户感知状态
  279. CSimpleStringA strCustomerAware;
  280. if (Error != Error_AllCamera)
  281. {
  282. CSmartPointer<IEntityFunction> Func = GetFunction();
  283. if (Func->RegistSysVarEvent("CustomerHandle", this) != Error_Succeed)
  284. {
  285. LOG_TRACE("register sys var %s failed!", "CustomerHandle");
  286. }
  287. else
  288. {
  289. Func->GetSysVar("CustomerHandle", strCustomerAware);
  290. //Dbg("CustomerHandle = %c",strCustomerAware[0]);
  291. Dbg("CustomerHandle = %s",(LPCTSTR)strCustomerAware);
  292. }
  293. }
  294. //启动摄像头
  295. if ((Error!=Error_AllCamera)&&(strCustomerAware.GetLength()>0)&&(strCustomerAware[0] != 'N'))
  296. {
  297. Error = StartCamera();
  298. if (Error == Error_Succeed)
  299. {
  300. m_bStartCamera = TRUE;
  301. CSimpleStringA strSessionId;
  302. CSmartPointer<IEntityFunction> Func = GetFunction();
  303. Func->GetSysVar("SessionID", strSessionId);
  304. LogEvent(Severity_Middle, EVENT_MOD_BEGIN_RECORD,strSessionId);
  305. //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_NO_ERROR);
  306. SetCameraSysVar(CAMERA_NO_ERROR);
  307. Dbg("Camera State to CAMERA_NO_ERROR");
  308. m_nCameraErrorCode = Error_Succeed;
  309. GetFunction()->SetUserDefineState(USER_MEDIA_IDLE);
  310. }
  311. else
  312. {
  313. if((Error == Error_EnvCamera)||(Error == Error_OptCamera))
  314. {
  315. CSimpleStringA strSessionId;
  316. CSmartPointer<IEntityFunction> Func = GetFunction();
  317. Func->GetSysVar("SessionID", strSessionId);
  318. LogEvent(Severity_Middle, EVENT_MOD_BEGIN_RECORD,strSessionId);
  319. m_bStartCamera = TRUE;
  320. if (Error == Error_EnvCamera)
  321. {
  322. //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_ENV_ERROR);
  323. SetCameraSysVar(CAMERA_ENV_ERROR);
  324. Dbg("Camera State to CAMERA_ENV_ERROR");
  325. m_nCameraErrorCode = Error_EnvCamera;
  326. GetFunction()->SetUserDefineState(USER_MEDIA_ENVERRROR);
  327. Error = Error_Succeed;
  328. }
  329. else if (Error == Error_OptCamera)
  330. {
  331. //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_OPT_ERROR);
  332. SetCameraSysVar(CAMERA_OPT_ERROR);
  333. Dbg("StartCamera = Error_OptCamera");
  334. m_nCameraErrorCode = Error_OptCamera;
  335. GetFunction()->SetUserDefineState(USER_MEDIA_OPTERROR);
  336. Error = Error_Succeed;
  337. }
  338. }
  339. else if(Error == Error_AllCamera)
  340. {
  341. //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_BOTH_ERROR);
  342. SetCameraSysVar(CAMERA_BOTH_ERROR);
  343. Dbg("Camera State to CAMERA_BOTH_ERROR");
  344. m_nCameraErrorCode = Error_AllCamera;
  345. m_bStartCamera = FALSE;
  346. GetFunction()->SetUserDefineState(USER_MEDIA_ALLERROR);
  347. }
  348. else
  349. {
  350. SetCameraSysVar(Error);
  351. Dbg("Camera State to Other Error");
  352. m_nCameraErrorCode = Error;
  353. m_bStartCamera = FALSE;
  354. }
  355. }
  356. }
  357. if(Error != Error_AllCamera) // edit by ly 20160329
  358. {
  359. int i = 0;
  360. if ((ePadtype == m_eDeviceType)||(eMobilePadType == m_eDeviceType)||(eDesk2SType == m_eDeviceType)||(eDesk1SType == m_eDeviceType)||(eDesk2SIntegratedType == m_eDeviceType))
  361. {
  362. m_arrListener.Init(18);
  363. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, MOD_EVENT_SNAPSHOT_START_CAPTURE_ENV);
  364. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, MOD_EVENT_SNAPSHOT_START_CAPTURE_OPT);
  365. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, MOD_EVENT_SNAPSHOT_START_CAPTURE_ENVOPT);
  366. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE,NULL,false);
  367. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, EVENT_MOD_CUSTOMERAWARE_BEGIN, NULL, false);
  368. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, EVENT_MOD_CUSTOMERAWARE_END, NULL, false);
  369. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_USB_CAMER_INPUT,NULL,false);
  370. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_USB_CAMER_OUTPUT,NULL,false);
  371. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, EVENT_USB_CAMERA_NOT_ONLY,NULL,false);
  372. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_RECORDFAILED,NULL,false);
  373. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_RECORDFAILED,NULL,false);
  374. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_BEGIN_CAMERA_CONFIG,NULL,false);
  375. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, LOG_EVT_END_CAMERA_CONFIG,NULL,false);
  376. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTREMOTERECORD,NULL,false);
  377. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPREMOTERECORD,NULL,false);
  378. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTRECORD,NULL,false);
  379. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPRECORD,NULL,false);
  380. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTRECORDPREVIEW,NULL,false);
  381. //GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_START_CONTINURECORD,NULL,false);
  382. //GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_STOP_CONTINURECORD,NULL,false);
  383. }
  384. else
  385. {
  386. m_arrListener.Init(13);
  387. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, MOD_EVENT_SNAPSHOT_START_CAPTURE_ENV);
  388. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, MOD_EVENT_SNAPSHOT_START_CAPTURE_OPT);
  389. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, MOD_EVENT_SNAPSHOT_START_CAPTURE_ENVOPT);
  390. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE,NULL,false);
  391. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, EVENT_MOD_CUSTOMERAWARE_BEGIN, NULL, false);
  392. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_Middle, Error_IgnoreAll, EVENT_MOD_CUSTOMERAWARE_END, NULL, false);
  393. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_RECORDFAILED,NULL,false);
  394. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_RECORDFAILED,NULL,false);
  395. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTREMOTERECORD,NULL,false);
  396. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPREMOTERECORD,NULL,false);
  397. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTRECORD,NULL,false);
  398. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STOPRECORD,NULL,false);
  399. GetFunction()->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_UI_STARTRECORDPREVIEW,NULL,false);
  400. }
  401. }
  402. pTransactionContext->SendAnswer(Error);
  403. }
  404. // add by ly at 20160801
  405. virtual void OnStarted()
  406. {
  407. m_pSelfcheckClient = new SelfChekerClient(this);
  408. ErrorCodeEnum Error = m_pSelfcheckClient->Connect();
  409. if (Error != Error_Succeed)
  410. {
  411. m_pSelfcheckClient->SafeDelete();
  412. m_pSelfcheckClient = NULL;
  413. Dbg("SelfcheckClient connect fail!");
  414. //pTransactionContext->SendAnswer(Error);
  415. //return;
  416. }
  417. else
  418. {
  419. Dbg("SelfcheckClient connect success!");
  420. }
  421. #ifdef RVC_OS_WIN
  422. m_pAudioRenderObj = CreateIAudioRenderObj();
  423. if (NULL != m_pAudioRenderObj) {
  424. Dbg("create audio render success, and addr is %0x.", m_pAudioRenderObj);
  425. }
  426. else {
  427. Dbg("create audio render failed.");
  428. }
  429. #else
  430. #endif // RVC_OS_WIN
  431. }
  432. DeviceTypeEnum RvcGetDeviceType()
  433. {
  434. DeviceTypeEnum eType = eStand2sType;
  435. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  436. CSystemStaticInfo stStaticinfo;
  437. spFunction->GetSystemStaticInfo(stStaticinfo);
  438. if (stricmp(stStaticinfo.strMachineType, "RVC.PAD") == 0) {
  439. if (stricmp(stStaticinfo.strSite, "CMB.FLB") == 0) {
  440. eType = eMobilePadType;
  441. }
  442. else {
  443. eType = ePadtype;
  444. }
  445. }
  446. else if (stricmp(stStaticinfo.strMachineType, "RVC.Desk2S") == 0) {
  447. eType = eDesk2SType;
  448. WORD nMajor = stStaticinfo.MachineVersion.GetMajor();
  449. WORD nMinor = stStaticinfo.MachineVersion.GetMinor();
  450. Dbg("MachineVersion is %d.%d", nMajor, nMinor);
  451. if (2 == nMajor) {
  452. eType = eDesk2SIntegratedType;
  453. }
  454. }
  455. else if (stricmp(stStaticinfo.strMachineType, "RPM.Stand1S") == 0) {
  456. eType = eRpm1sType;
  457. }
  458. else if (stricmp(stStaticinfo.strMachineType, "RVC.Desk1S") == 0) {
  459. eType = eDesk1SType;
  460. }
  461. else {
  462. eType = eStand2sType;
  463. }
  464. if (eType >= 0 && eType < sizeof(Device_Type_Table) / sizeof(char*)) {
  465. LOG_TRACE("device type is %s.", Device_Type_Table[eType]);
  466. }
  467. return eType;
  468. }
  469. void SetCameraSysVar(int n)
  470. {
  471. if (n==0)
  472. {
  473. //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_OPT_ERROR);
  474. SetCameraSysVar(CAMERA_OPT_ERROR);
  475. Dbg("Camera State to CAMERA_OPT_ERROR");
  476. }
  477. else if (n==1)
  478. {
  479. //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_ENV_ERROR);
  480. SetCameraSysVar(CAMERA_ENV_ERROR);
  481. Dbg("Camera State to CAMERA_ENV_ERROR");
  482. }
  483. else if (n==-1)
  484. {
  485. //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_BOTH_ERROR);
  486. SetCameraSysVar(CAMERA_BOTH_ERROR);
  487. Dbg("Camera State to CAMERA_BOTH_ERROR");
  488. }
  489. else if (n==3)
  490. {
  491. //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_NO_ERROR);
  492. SetCameraSysVar(CAMERA_NO_ERROR);
  493. Dbg("Camera State to CAMERA_NO_ERROR");
  494. }
  495. }
  496. ErrorCodeEnum GetSalesRecordAudioParam()
  497. {
  498. CSmartPointer<IConfigInfo> spConfig;
  499. SpIniMappingTable table;
  500. ErrorCodeEnum Error = GetFunction()->OpenConfig(Config_CenterSetting, spConfig);
  501. if (Error == Error_Succeed)
  502. {
  503. table.AddEntryInt("SalesRecorder", "AudioSampleRate", m_nSalesAudioSmpPsec, 8);
  504. table.AddEntryBoolean("SalesRecorder", "IsRecordPCM", m_bRecordPCM, false);
  505. Error= table.Load(spConfig);
  506. }
  507. if (m_nSalesAudioSmpPsec != 8 && m_nSalesAudioSmpPsec != 16)
  508. {
  509. m_nSalesAudioSmpPsec = 8;
  510. }
  511. m_nSalesAudioSmpPsec *= 1000;
  512. #ifdef RVC_OS_WIN
  513. #else
  514. m_nSalesAudioSmpPsec = 44100;
  515. #endif
  516. return Error;
  517. }
  518. ErrorCodeEnum SetEnvCameraOnSysVar(const CSimpleStringA strOnState)
  519. {
  520. ErrorCodeEnum Error = Error_Succeed;
  521. CSmartPointer<IEntityFunction> spFunction = this->GetFunction();
  522. Error = spFunction->SetSysVar(SYSVAR_ENVCAMERAON, strOnState.GetData());
  523. return Error;
  524. }
  525. // add by ly at 20161018
  526. ErrorCodeEnum SetCameraSysVar(const CSimpleStringA &newVal)
  527. {
  528. CSmartPointer<IEntityFunction> spFunction = this->GetFunction();
  529. if (eStand2sType == m_eDeviceType)
  530. {
  531. return spFunction->SetSysVar(SYSVAR_CAMERASTATE, (LPCTSTR)newVal);
  532. }
  533. CSimpleStringA val = newVal;
  534. switch (val[0])
  535. {
  536. case 'E':
  537. // comment by ly@2019/03/19
  538. //if(strstr((LPCTSTR)conf.strVideoEnv,(LPCTSTR)strUSBCam))
  539. //{
  540. // // 当前正在使用外接摄像头
  541. // val = val.Append("外接");
  542. //}
  543. //else
  544. {
  545. if (!strstr((LPCTSTR)strFrontCam,";"))
  546. {
  547. val = val.Append((LPCTSTR)strFrontCam);
  548. }
  549. else
  550. {
  551. val = val.Append((LPCTSTR)strFrontCam.SubString(0,strFrontCam.IndexOf(";")));
  552. }
  553. }
  554. break;
  555. case 'O':
  556. if (!strstr((LPCTSTR)strRearCam,";"))
  557. {
  558. val = val.Append((LPCTSTR)strRearCam);
  559. }
  560. else
  561. {
  562. val = val.Append((LPCTSTR)strRearCam.SubString(0,strRearCam.IndexOf(";")));
  563. }
  564. break;
  565. // comment by ly@2019/03/19
  566. //case 'U':
  567. // val = val.Append("外接");
  568. // break;
  569. case 'B':
  570. val = val.Append("内置前、后");
  571. break;
  572. case 'N':
  573. case 'I':
  574. default:
  575. break;
  576. }
  577. return spFunction->SetSysVar(SYSVAR_CAMERASTATE, (LPCTSTR)val);
  578. }
  579. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  580. {
  581. LOG_FUNCTION();
  582. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  583. for (int i = 0; i < m_arrListener.GetCount(); ++i)
  584. {
  585. spFunction->UnsubscribeLog(m_arrListener[i]);
  586. }
  587. spFunction->UnregistSysVarEvent(SYSVAR_CALLTYPE);
  588. if (m_capture) {
  589. capture_stop(m_capture);
  590. capture_destroy(m_capture);
  591. m_capture = NULL;
  592. }
  593. if (m_salesaudio_capture){
  594. salesrecord_audio_capture_stop(m_salesaudio_capture);
  595. salesaudio_capture_destroy(m_salesaudio_capture);
  596. m_salesaudio_capture = NULL;
  597. }
  598. #ifdef RVC_OS_WIN
  599. if (NULL != m_pAudioRenderObj) {
  600. Dbg("destroy audio render obj,and it's addr is %0x.", m_pAudioRenderObj);
  601. DestroyIAudioRenderObj(m_pAudioRenderObj);
  602. }
  603. #else
  604. #endif // RVC_OS_WIN
  605. capture_lib_term();
  606. pTransactionContext->SendAnswer(Error_Succeed);
  607. }
  608. virtual void OnTimeout(DWORD dwTimerID)
  609. {
  610. //Dbg("OnTimeout");
  611. int env_n, opt_n;
  612. DWORD nLastEnvTime,nLastOptTime;
  613. bool bEnvTimeout = false;
  614. bool bOptTimeout = false;
  615. if (!m_capture)
  616. {
  617. Dbg("m_capture =Null");
  618. return;
  619. }
  620. if (!m_bStartCamera)
  621. {
  622. Dbg("m_bStartCamera =false");
  623. return;
  624. }
  625. BOOL bIsPadType = FALSE;
  626. if ((ePadtype == m_eDeviceType)||(eMobilePadType == m_eDeviceType)||(eDesk2SType == m_eDeviceType)||(eDesk1SType == m_eDeviceType)||(eDesk2SIntegratedType == m_eDeviceType))
  627. {
  628. bIsPadType = TRUE;
  629. }
  630. capture_detect_camera_bug(m_capture, &env_n, &opt_n,bIsPadType);
  631. capture_get_last_frametime(m_capture,&nLastEnvTime,&nLastOptTime,bIsPadType);
  632. if (env_n == 0)
  633. {
  634. if (m_iEnvEmptyTimes < CAMERA_BUG_THRESHOLD)
  635. {
  636. m_iEnvEmptyTimes++;
  637. Dbg("get env camera picture fail,Times=%d",m_iEnvEmptyTimes);
  638. }
  639. }
  640. else if (env_n == -1)
  641. {
  642. m_iEnvEmptyTimes = CAMERA_BUG_THRESHOLD;
  643. }
  644. else
  645. {
  646. if (m_iEnvEmptyTimes == CAMERA_BUG_THRESHOLD)
  647. {
  648. Dbg("env camera get right!");
  649. }
  650. m_iEnvEmptyTimes = 0;
  651. }
  652. //env图像是否超时
  653. if(nLastEnvTime > 0)
  654. {
  655. //Dbg("now=%d,nLastEnvTime=%d",y2k_time_now(),nLastEnvTime);
  656. if(((y2k_time_now()-nLastEnvTime) > CAMERA_TIMEOUT)&&!bEnvTimeout)
  657. {
  658. bEnvTimeout = true;
  659. Dbg("bEnvTimeout");
  660. }
  661. else if (((y2k_time_now()-nLastEnvTime) < CAMERA_TIMEOUT)&&bEnvTimeout)
  662. {
  663. bEnvTimeout = false;
  664. Dbg("change env camera from bEnvTimeout to OK");
  665. }
  666. }
  667. //env是否30S没有图像或者图像20秒没有更新
  668. if(((m_iEnvEmptyTimes == CAMERA_BUG_THRESHOLD)||bEnvTimeout)&&(m_nCameraErrorCode!=Error_EnvCamera)&&(m_nCameraErrorCode!=Error_AllCamera))
  669. {
  670. char strMessage[MAX_PATH*2] = {0};
  671. get_camera_exception_message(strMessage, MAX_PATH*2, conf.strVideoEnv, "Env camera bug detected!");
  672. LogError(Severity_Middle, Error_Hardware, ERROR_MOD_MEDIACONTROLLER_ENVCAMERA_BUG, strMessage);
  673. if ((ePadtype == m_eDeviceType)||(eMobilePadType == m_eDeviceType)||(eDesk2SType == m_eDeviceType)||(eDesk1SType == m_eDeviceType)||(eDesk2SIntegratedType == m_eDeviceType))
  674. {
  675. // comment by ly@2019/03/19
  676. //if(!strstr((LPCTSTR)conf.strVideoEnv,(LPCTSTR)strUSBCam)) // 如果不是外接摄像头
  677. {
  678. m_nCameraErrorCode = Error_AllCamera;
  679. /*ChangeSysvar(m_nCameraErrorCode);*/
  680. ChangeSysvar(Error_EnvCamera);
  681. RealSelfCheck();
  682. return;
  683. }
  684. }
  685. else
  686. {
  687. if (m_nCameraErrorCode == Error_Succeed)
  688. {
  689. m_nCameraErrorCode = Error_EnvCamera;
  690. ChangeSysvar(m_nCameraErrorCode);
  691. }
  692. else if (m_nCameraErrorCode == Error_OptCamera)
  693. {
  694. m_nCameraErrorCode = Error_AllCamera;
  695. ChangeSysvar(m_nCameraErrorCode);
  696. RealSelfCheck();
  697. return;
  698. }
  699. }
  700. }
  701. else if((m_iEnvEmptyTimes != CAMERA_BUG_THRESHOLD)&&!bEnvTimeout&&((m_nCameraErrorCode == Error_EnvCamera)||(m_nCameraErrorCode == Error_AllCamera)))
  702. {
  703. if ((ePadtype == m_eDeviceType)||(eMobilePadType == m_eDeviceType)||(eDesk2SType == m_eDeviceType)||(eDesk1SType == m_eDeviceType)||(eDesk2SIntegratedType == m_eDeviceType))
  704. {
  705. m_nCameraErrorCode = Error_Succeed;
  706. ChangeSysvar(m_nCameraErrorCode);
  707. }
  708. else
  709. {
  710. if (m_nCameraErrorCode == Error_EnvCamera)
  711. {
  712. m_nCameraErrorCode = Error_Succeed;
  713. ChangeSysvar(m_nCameraErrorCode);
  714. Dbg("changeSysvar to No_Error");
  715. }
  716. else if (m_nCameraErrorCode == Error_AllCamera)
  717. {
  718. m_nCameraErrorCode = Error_OptCamera;
  719. ChangeSysvar(m_nCameraErrorCode);
  720. Dbg("changeSysvar to Opt_Error");
  721. }
  722. }
  723. }
  724. //opt是否没有图像
  725. if (eStand2sType == m_eDeviceType)
  726. {
  727. if (opt_n == 0)
  728. {
  729. if (m_iOptEmptyTimes < CAMERA_BUG_THRESHOLD)
  730. {
  731. m_iOptEmptyTimes++;
  732. Dbg("get opt camera picture fail,Times=%d",m_iOptEmptyTimes);
  733. }
  734. }
  735. else if (opt_n == -1)
  736. {
  737. m_iOptEmptyTimes = CAMERA_BUG_THRESHOLD;
  738. }
  739. else
  740. {
  741. if (m_iOptEmptyTimes == CAMERA_BUG_THRESHOLD)
  742. {
  743. Dbg("opt camera get right!");
  744. }
  745. m_iOptEmptyTimes = 0;
  746. }
  747. }
  748. //opt图像是否超时
  749. if((nLastOptTime > 0)&&(eStand2sType == m_eDeviceType))
  750. {
  751. if(((y2k_time_now()-nLastOptTime) > CAMERA_TIMEOUT)&&!bOptTimeout)
  752. {
  753. bOptTimeout = true;
  754. Dbg("bOptTimeout");
  755. }
  756. else if (((y2k_time_now()-nLastOptTime) < CAMERA_TIMEOUT)&&bOptTimeout)
  757. {
  758. bOptTimeout = false;
  759. Dbg("change opt camera from bOptTimeout to OK");
  760. }
  761. }
  762. //opt是否100S没有图像或者图像20秒没有更新
  763. if(((m_iOptEmptyTimes == CAMERA_BUG_THRESHOLD) ||bOptTimeout)&&(m_nCameraErrorCode!=Error_OptCamera)&&(m_nCameraErrorCode!=Error_AllCamera)&&(eStand2sType == m_eDeviceType))
  764. {
  765. char strMessage[MAX_PATH*2] = {0};
  766. get_camera_exception_message(strMessage, MAX_PATH*2, conf.strVideoOpt, "Opt camera bug detected!");
  767. LogError(Severity_Middle, Error_Hardware, ERROR_MOD_MEDIACONTROLLER_OPECAMERA_BUG, strMessage);
  768. if (m_nCameraErrorCode == Error_Succeed)
  769. {
  770. m_nCameraErrorCode = Error_OptCamera;
  771. ChangeSysvar(m_nCameraErrorCode);
  772. }
  773. else if (m_nCameraErrorCode == Error_EnvCamera)
  774. {
  775. m_nCameraErrorCode = Error_AllCamera;
  776. ChangeSysvar(m_nCameraErrorCode);
  777. RealSelfCheck();
  778. return;
  779. }
  780. }
  781. else if((m_iOptEmptyTimes != CAMERA_BUG_THRESHOLD)&&!bOptTimeout&&((m_nCameraErrorCode == Error_OptCamera)||(m_nCameraErrorCode == Error_AllCamera))&&(eStand2sType == m_eDeviceType))
  782. {
  783. if (m_nCameraErrorCode == Error_OptCamera)
  784. {
  785. m_nCameraErrorCode = Error_Succeed;
  786. ChangeSysvar(m_nCameraErrorCode);
  787. Dbg("changeSysvar to No_Error");
  788. }
  789. else if (m_nCameraErrorCode == Error_AllCamera)
  790. {
  791. m_nCameraErrorCode = Error_EnvCamera;
  792. ChangeSysvar(m_nCameraErrorCode);
  793. Dbg("changeSysvar to Env_Error");
  794. }
  795. }
  796. //重启摄像头
  797. if((m_nCameraErrorCode == Error_EnvCamera)&&(m_nEnvCameraRestartNum<CAMERA_RESTARTNUM))
  798. {
  799. if (ReStartCamera(ENVCAMERA) != Error_Succeed)
  800. {
  801. m_nEnvCameraRestartNum++;
  802. }
  803. else
  804. {
  805. m_nEnvCameraRestartNum = 0;
  806. m_nCameraErrorCode = Error_Succeed;
  807. ChangeSysvar(m_nCameraErrorCode);
  808. m_iEnvEmptyTimes = 0;
  809. bEnvTimeout = false;
  810. }
  811. }
  812. else if((m_nCameraErrorCode == Error_OptCamera)&&(m_nOptCameraRestartNum<CAMERA_RESTARTNUM)&&(eStand2sType == m_eDeviceType))
  813. {
  814. if (ReStartCamera(OPTCAMERA) != Error_Succeed)
  815. m_nOptCameraRestartNum++;
  816. else
  817. {
  818. m_nOptCameraRestartNum = 0;
  819. m_nCameraErrorCode = Error_Succeed;
  820. ChangeSysvar(m_nCameraErrorCode);
  821. m_iOptEmptyTimes = 0;
  822. bOptTimeout = false;
  823. }
  824. }
  825. else if (m_nCameraErrorCode == Error_AllCamera)
  826. {
  827. if (m_nEnvCameraRestartNum<CAMERA_RESTARTNUM)
  828. {
  829. if (ReStartCamera(ENVCAMERA) != Error_Succeed)
  830. m_nEnvCameraRestartNum++;
  831. else
  832. {
  833. m_nEnvCameraRestartNum = 0;
  834. m_nCameraErrorCode = Error_OptCamera;
  835. ChangeSysvar(m_nCameraErrorCode);
  836. m_iEnvEmptyTimes = 0;
  837. bEnvTimeout = false;
  838. }
  839. }
  840. if((m_nOptCameraRestartNum<CAMERA_RESTARTNUM)&&(eStand2sType == m_eDeviceType))
  841. {
  842. if (ReStartCamera(OPTCAMERA) != Error_Succeed)
  843. m_nOptCameraRestartNum++;
  844. else
  845. {
  846. m_nOptCameraRestartNum = 0;
  847. m_iOptEmptyTimes = 0;
  848. bOptTimeout = false;
  849. if (m_nCameraErrorCode == Error_AllCamera)
  850. {
  851. m_nCameraErrorCode = Error_EnvCamera;
  852. ChangeSysvar(m_nCameraErrorCode);
  853. }
  854. else
  855. {
  856. m_nCameraErrorCode = Error_Succeed;
  857. ChangeSysvar(m_nCameraErrorCode);
  858. }
  859. }
  860. }
  861. }
  862. }
  863. bool SetAutoBright(ErrorCodeEnum nCode)
  864. {
  865. return capture_set_autobrightness(m_capture,nCode);
  866. }
  867. //camera gain adjust
  868. void OnReceivePkt(int sub_type, const char *buffer, int size)
  869. {
  870. if (sub_type == ACM_SET_CAMERABRIGHT)
  871. {
  872. if (m_bStartCamera)
  873. {
  874. if (eStand2sType == m_eDeviceType)
  875. {
  876. //vamera bright adj
  877. CCameraBrightValue num;
  878. SpBuffer buf;
  879. buf.OpenRead(buffer,size);
  880. num.Serialize(buf);
  881. Dbg("recv ACM_SET_CAMERABRIGHT = %d",num.nValue);
  882. if (capture_adj_brightness(m_capture,num.nValue,m_nCameraErrorCode) == true)
  883. {
  884. Dbg("ACM_SET_CAMERABRIGHT success!");
  885. SendCameraBright();
  886. }
  887. else
  888. {
  889. Dbg("ACM_SET_CAMERABRIGHT fail!");
  890. }
  891. }
  892. else
  893. {
  894. Dbg("pad type cannot adj brightness");
  895. }
  896. }
  897. else
  898. {
  899. Dbg("the camera not start!");
  900. }
  901. }
  902. }
  903. ErrorCodeEnum RealSelfCheck()
  904. {
  905. ErrorCodeEnum Error = Error_Succeed;
  906. if (m_pSelfcheckClient)
  907. {
  908. SelfCheckerService_RealCheck_Req req;
  909. req.name = GetEntityName();
  910. SelfCheckerService_RealCheck_Ans ans;
  911. DWORD Timeout = 500;
  912. Error = m_pSelfcheckClient->RealCheck(req,ans,Timeout);
  913. if (Error!=Error_Succeed)
  914. {
  915. Dbg("RealSelfcheck fail!");
  916. }
  917. else
  918. {
  919. Dbg("RealSelfcheck");
  920. }
  921. }
  922. return Error;
  923. }
  924. void SendCameraBright()
  925. {
  926. if (m_nSysCallType == 0)
  927. {
  928. ChannelService_Send_Info Info;
  929. Info.compress = false;
  930. Info.encrypt = false;
  931. Info.type = ACM_TYPE_DEVICE;
  932. Info.id = 0;
  933. Info.sub_type = ACM_CAMERA_BRIGHT;
  934. Info.data.Alloc(sizeof(int));
  935. SpBuffer buf;
  936. buf.OpenWrite();
  937. int nValue = 0;
  938. bool rslt = true;
  939. nValue = capture_get_brightness(m_capture,m_nCameraErrorCode);
  940. if (nValue >= 0)
  941. {
  942. buf & nValue;
  943. Info.data = buf.ToBlob();
  944. m_pMediaControllerChannel->Send(Info);
  945. Dbg("send cur camera bright value = %d",nValue);
  946. }
  947. else
  948. {
  949. Dbg("send cur camera bright value Fail!");
  950. }
  951. }
  952. else
  953. {
  954. Dbg("cur call type cannot send pkt");
  955. }
  956. }
  957. ErrorCodeEnum StartEnvCamera()
  958. {
  959. LOG_FUNCTION();
  960. ErrorCodeEnum Error = Error_Succeed;
  961. if (FALSE == m_bStartCamera){
  962. Error = StartCamera();
  963. if (Error_Succeed == Error){
  964. SetCameraSysVar(CAMERA_NO_ERROR);
  965. Dbg("Camera State to CAMERA_NO_ERROR");
  966. m_bStartCamera = TRUE;
  967. }
  968. }
  969. else{
  970. Dbg("camera already start.");
  971. }
  972. return Error;
  973. }
  974. ErrorCodeEnum StopEnvCamera()
  975. {
  976. LOG_FUNCTION();
  977. if (m_capture){
  978. GetFunction()->KillTimer(1);
  979. capture_stop(m_capture);
  980. capture_destroy(m_capture);
  981. m_capture = NULL;
  982. }
  983. m_bStartCamera = FALSE;
  984. return Error_Succeed;
  985. }
  986. bool m_bSendCameraError;
  987. int m_iEnvEmptyTimes;
  988. int m_iOptEmptyTimes;
  989. int m_nEnvCameraRestartNum;
  990. int m_nOptCameraRestartNum;
  991. private:
  992. ErrorCodeEnum LoadRunConfig(CSimpleStringA& frontcam, CSimpleStringA& rearcam)
  993. {
  994. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  995. CSmartPointer<IConfigInfo> spConfig;
  996. ErrorCodeEnum Error = spFunction->OpenConfig(Config_Run, spConfig);
  997. if (Error == Error_Succeed) {
  998. SpIniMappingTable table;
  999. table.AddEntryString("Video", "FrontCamera", frontcam, "$");
  1000. table.AddEntryString("Video", "RearCamera", rearcam, "$");
  1001. Error = table.Load(spConfig);
  1002. if (Error != Error_Succeed)
  1003. {
  1004. LOG_TRACE("[dbg] failed to load run config.");
  1005. }
  1006. }
  1007. else {
  1008. LOG_TRACE("[dbg] failed to open run config.");
  1009. }
  1010. return Error;
  1011. }
  1012. ErrorCodeEnum CheckConfigCameraName(capture_config_t *conf){
  1013. ErrorCodeEnum Error = Error_Succeed;
  1014. int EnvConfigNameError = 0; //0:环境摄像头配置名能成功打开 -1:环境摄像头配置名不能打开 1:未配置环境摄像头名字
  1015. int OptConfigNameError = 0; //0:操作摄像头配置名能成功打开 -1:操作摄像头配置名不能打开 1:未配置操作摄像头名字
  1016. //check env device
  1017. if (conf->strVideoEnv.GetLength() > 1)
  1018. { // is not "$"
  1019. conf->video_env_dev = capture_get_video_device_id(conf->strVideoEnv);
  1020. if (conf->video_env_dev == -1)
  1021. {
  1022. Dbg("find strVideoEnv:%s(-1)",(LPCTSTR)conf->strVideoEnv);
  1023. EnvConfigNameError = -1;
  1024. }
  1025. } else
  1026. {
  1027. conf->video_env_dev = -1;
  1028. EnvConfigNameError = 1;
  1029. }
  1030. //check opt device
  1031. if (conf->strVideoOpt.GetLength() > 1)
  1032. { // is not "$"
  1033. #ifdef RVC_OS_WIN
  1034. conf->video_opt_dev = capture_get_video_device_id(conf->strVideoOpt);
  1035. #else
  1036. conf->video_opt_dev = rvc_videocap_get_video_device_id(conf->strVideoOpt.GetData());
  1037. #endif // RVC_OS_WIN
  1038. if (conf->video_opt_dev == -1)
  1039. {
  1040. Dbg("find strVideoOpt:%s(-1)",(LPCTSTR)conf->strVideoOpt);
  1041. OptConfigNameError = -1;
  1042. }
  1043. }
  1044. else
  1045. {
  1046. conf->video_opt_dev = -1;
  1047. OptConfigNameError = 1;
  1048. }
  1049. //环境摄像头配置名不能打开
  1050. if (EnvConfigNameError == -1){
  1051. //操作摄像头配置名不能打开,此时表明摄像头都不可用
  1052. if(OptConfigNameError == -1){
  1053. Error = Error_AllCamera;
  1054. }
  1055. //未配置操作摄像头名字or操作摄像头配置名能打开,此时表明只有操作摄像头OK
  1056. else{
  1057. Error = Error_EnvCamera;
  1058. }
  1059. }
  1060. //环境摄像头配置名能打开
  1061. else if (EnvConfigNameError == 0){
  1062. //操作摄像头配置名不能打开,此时表明只有环境摄像头OK
  1063. if (OptConfigNameError == -1){
  1064. Error = Error_OptCamera;
  1065. }
  1066. //环境摄像头配置名能打开,未配置操作摄像头名字,此时也认为摄像头都OK(无操作摄像头场景)
  1067. }
  1068. //环境摄像头未配置
  1069. else {
  1070. //操作摄像头配置名不能打开,此时表明只有操作摄像头OK
  1071. if(OptConfigNameError == -1){
  1072. Error = Error_OptCamera;
  1073. }
  1074. //操作摄像头未配置,此时表明摄像头都不可用
  1075. else if (OptConfigNameError == 1){
  1076. Error = Error_AllCamera;
  1077. }
  1078. //操作摄像头名字能打开,此时也认为摄像头都OK(无环境摄像头场景)
  1079. }
  1080. return Error;
  1081. }
  1082. ErrorCodeEnum GetSalesAudioConfig(rvc_audio_capture_config_t *conf, bool bRemoteRecord)
  1083. {
  1084. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  1085. CSmartPointer<IConfigInfo> spConfig;
  1086. SpIniMappingTable table;
  1087. ErrorCodeEnum Error = spFunction->OpenConfig(Config_Root, spConfig);
  1088. if (Error == Error_Succeed) {
  1089. CSimpleStringA strAudioInDevice;
  1090. table.AddEntryString("Audio", "sales_record_in_dev", conf->strAudioIn, "$");
  1091. table.AddEntryString("Audio", "handfree_in_dev", strAudioInDevice, "$");
  1092. table.AddEntryString("Audio", "handfree_out_dev", conf->strAudioOut, "$");
  1093. Error = table.Load(spConfig);
  1094. if (Error == Error_Succeed){
  1095. conf->audio_capture_period = CAPTURE_FRAME_TIME;
  1096. conf->audio_capture_samplerate = m_nSalesAudioSmpPsec;
  1097. if (conf->strAudioIn==""){
  1098. conf->strAudioIn = strAudioInDevice;
  1099. }
  1100. }
  1101. else {
  1102. LOG_TRACE("load sales audio device config failed!");
  1103. }
  1104. }
  1105. else {
  1106. LOG_TRACE("open sales audio device config failed!");
  1107. }
  1108. if (Error_Succeed != Error){
  1109. Dbg("get sales audio device info failed, now get from default value.");
  1110. m_sales_audio_conf.strAudioIn = this->conf.strAudioIn;
  1111. m_sales_audio_conf.audio_capture_period = CAPTURE_FRAME_TIME;
  1112. m_sales_audio_conf.audio_capture_samplerate = CAPTURE_CLOCK;
  1113. Error = Error_Succeed;
  1114. }
  1115. conf->audio_capture_samplerate = CAPTURE_CLOCK*2;
  1116. if (true == bRemoteRecord){
  1117. if (CAPTURE_CLOCK*2 == m_sales_audio_conf.audio_capture_samplerate){
  1118. m_sales_audio_conf.audio_capture_samplerate = CAPTURE_CLOCK;
  1119. Dbg("remote record, change audio sample rate to from %d to %d.", CAPTURE_CLOCK*2, m_sales_audio_conf.audio_capture_samplerate);
  1120. }
  1121. }
  1122. return Error;
  1123. }
  1124. ErrorCodeEnum LoadConfig(capture_config_t *conf)
  1125. {
  1126. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  1127. CSmartPointer<IConfigInfo> spConfig;
  1128. SpIniMappingTable table;
  1129. strEwsCam = "$";
  1130. ErrorCodeEnum Error = spFunction->OpenConfig(Config_Root, spConfig);
  1131. if (Error == Error_Succeed) {
  1132. table.AddEntryString("Audio", "handfree_in_dev", conf->strAudioIn, "$");
  1133. table.AddEntryString("Audio", "handfree_out_dev", conf->strAudioOut, "$");
  1134. table.AddEntryString("Video", "EnvCamera", conf->strVideoEnv, "$");
  1135. table.AddEntryString("Video", "OptCamera", conf->strVideoOpt, "$");
  1136. table.AddEntryString("Video", "EwsCamera", strEwsCam, "$");
  1137. table.AddEntryInt("Video", "EnvRotate", conf->video_env_rotate, 0);
  1138. table.AddEntryInt("Video", "OptRotate", conf->video_opt_rotate, 0);
  1139. table.AddEntryInt("Video", "EnvFps", conf->video_env_fps, 0);
  1140. table.AddEntryInt("Video", "OptFps", conf->video_opt_fps, 0);
  1141. Error = table.Load(spConfig);
  1142. if (Error == Error_Succeed)
  1143. {
  1144. //进行Camera路径名自纠正后再检查
  1145. AutoCorrectCameraConfigName(5000);
  1146. Error = CheckConfigCameraName(conf);
  1147. if (Error == Error_EnvCamera || Error == Error_AllCamera){
  1148. char strMessage[MAX_PATH*2] = {0};
  1149. get_camera_exception_message(strMessage, MAX_PATH*2, conf->strVideoEnv ,"ENV 摄像头打开失败,请检查设备或配置是否正确!");
  1150. LogError(Severity_High,Error_DevMedia,ERROR_MOD_MEDIACONTROLLER_ENVCAM_INITFAIL, strMessage);
  1151. } else if (Error == Error_OptCamera){
  1152. char strMessage[MAX_PATH*2] = {0};
  1153. get_camera_exception_message(strMessage, MAX_PATH*2, conf->strVideoOpt, "OPT 摄像头打开失败,请检查设备或配置是否正确!");
  1154. LogError(Severity_High,Error_DevMedia,ERROR_MOD_MEDIACONTROLLER_OPTCAM_INITFAIL, strMessage);
  1155. }
  1156. }
  1157. else
  1158. {
  1159. LOG_TRACE("load config failed!");
  1160. }
  1161. }
  1162. else
  1163. {
  1164. LOG_TRACE("open config failed!");
  1165. }
  1166. return Error;
  1167. }
  1168. // 外接摄像头启动失败 edit by ly 2018/03/08
  1169. void OnExternalCameraSwitchFailed(const char* pszFailedMsg)
  1170. {
  1171. // 广播给业务系统
  1172. ExternalCameraSwitchFailed evt;
  1173. evt.failedmsg = CSimpleStringA2W(pszFailedMsg);
  1174. SpSendBroadcast(GetFunction(), SP_MSG_OF(ExternalCameraSwitchFailed), SP_MSG_SIG_OF(ExternalCameraSwitchFailed), evt);
  1175. Dbg("[dbg] ExternalCameraSwitchFailed broadcast sent!");
  1176. CSmartPointer<IEntityFunction> Func = GetFunction();
  1177. CSimpleStringA strValue;
  1178. Func->GetSysVar("DesktopType", strValue);
  1179. if (strValue == CSimpleStringA("U")) {
  1180. #ifdef RVC_OS_WIN
  1181. MessageBoxA(NULL, pszFailedMsg, NULL, MB_SYSTEMMODAL);
  1182. #else
  1183. #endif // RVC_OS_WIN
  1184. }
  1185. }
  1186. // comment by ly@2019/03/19
  1187. //ErrorCodeEnum TryStartCamera()
  1188. //{
  1189. // Dbg("[dbg] StartExternalCamera");
  1190. // ErrorCodeEnum errorCode = StartUSBCamera();
  1191. // Dbg("StartExternalCamera:0x%x", errorCode);
  1192. // int nRetCod = 5;
  1193. // switch(errorCode)
  1194. // {
  1195. // case Error_Succeed:
  1196. // {
  1197. // nRetCod = 0; // 正常
  1198. // /// add by ly at 20161017
  1199. // /// notify to rvcweb that outer camera switch has finished
  1200. // ExternalCameraStateChanged evt;
  1201. // evt.statemsg = CSimpleStringA2W("已切换到外接摄像头!");
  1202. // evt.camname = CSimpleStringA2W(strUSBCam);
  1203. // SpSendBroadcast(GetFunction(), SP_MSG_OF(ExternalCameraStateChanged), SP_MSG_SIG_OF(ExternalCameraStateChanged), evt);
  1204. // Dbg("[dbg] ExternalCameraStateChanged broadcast sent!");
  1205. // }
  1206. // break;
  1207. // case Error_Resource:
  1208. // nRetCod = 1; // 外接摄像头未插入
  1209. // break;
  1210. // case Error_EnvCamera:
  1211. // case Error_AllCamera:
  1212. // nRetCod = 2; // 外接摄像头启动失败
  1213. // OnExternalCameraSwitchFailed(SwitchFailed_StartFault);
  1214. // break;
  1215. // case Error_DevNotAvailable:
  1216. // nRetCod = 3; // 检测到一个外接摄像头,但无法分辨名称
  1217. // OnExternalCameraSwitchFailed(SwitchFailed_Ambiguous);
  1218. // break;
  1219. // case Error_Duplication:
  1220. // nRetCod = 4; // 检测到两个以上外接摄像头
  1221. // OnExternalCameraSwitchFailed(SwitchFailed_NoUnique);
  1222. // break;
  1223. // default:
  1224. // nRetCod = 5; // 其他错误
  1225. // OnExternalCameraSwitchFailed(SwitchFailed_StartFault);
  1226. // break;
  1227. // }
  1228. // if (m_bStartCamera == FALSE) // 外接没启动成,如果内置没启动,切换到内置
  1229. // {
  1230. // SetCameraSysVar(CAMERA_START_ING);
  1231. // ExternalCameraStateChanged evt;
  1232. // evt.statemsg = CSimpleStringA2W("无法启动外接,内置切换中……");
  1233. // evt.camname = CSimpleStringA2W(strEnvCam);
  1234. // SpSendBroadcast(GetFunction(), SP_MSG_OF(ExternalCameraStateChanged), SP_MSG_SIG_OF(ExternalCameraStateChanged), evt);
  1235. // Dbg("[dbg] ExternalCameraStateChanged broadcast sent!");
  1236. // return StopUSBCamera();
  1237. // }
  1238. // return Error_Succeed;
  1239. //}
  1240. virtual void OnLog( const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  1241. const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  1242. const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage)
  1243. {
  1244. LOG_TRACE("user_code = %08x", dwUserCode);
  1245. switch (dwUserCode)
  1246. {
  1247. case MOD_EVENT_SNAPSHOT_START_CAPTURE_ENVOPT:
  1248. {
  1249. Dbg("recv MOD_EVENT_SNAPSHOT_START_CAPTURE_ENVOPT");
  1250. InterlockedCompareExchange(&m_lCaptureEnvOptCount, 3, 0);
  1251. }
  1252. break;
  1253. case MOD_EVENT_SNAPSHOT_START_CAPTURE_ENV:
  1254. {
  1255. Dbg("recv MOD_EVENT_SNAPSHOT_START_CAPTURE_ENV");
  1256. InterlockedCompareExchange(&m_lCaptureEnvCount, 1, 0);
  1257. }
  1258. break;
  1259. case MOD_EVENT_SNAPSHOT_START_CAPTURE_OPT:
  1260. {
  1261. Dbg("recv MOD_EVENT_SNAPSHOT_START_CAPTURE_OPT");
  1262. InterlockedCompareExchange(&m_lCaptureOptCount, 1, 0);
  1263. }
  1264. break;
  1265. case LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE:
  1266. {
  1267. Dbg("recv LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE");
  1268. if (m_pMediaControllerChannel!=NULL)
  1269. {
  1270. m_pMediaControllerChannel->GetFunction()->CloseSession();
  1271. m_pMediaControllerChannel->SafeDelete();
  1272. m_pMediaControllerChannel = NULL;
  1273. Dbg("Close AssistChannel Session ");
  1274. }
  1275. if (m_pMediaControllerChannel == NULL)
  1276. {
  1277. Dbg("ReConnection AssistChannel Session");
  1278. m_pMediaControllerChannel = new ChannelMediaControllerClient(this);
  1279. ErrorCodeEnum Error = m_pMediaControllerChannel->Connect();
  1280. if (Error != Error_Succeed)
  1281. {
  1282. m_pMediaControllerChannel->SafeDelete();
  1283. m_pMediaControllerChannel = NULL;
  1284. Dbg("AssistChannelClient connect fail!");
  1285. }
  1286. if (Error == Error_Succeed)
  1287. {
  1288. ChannelService_BeginRecv_Sub Sub;
  1289. Sub.type = ACM_TYPE_DEVICE;
  1290. Error = m_pMediaControllerChannel->BeginRecv(Sub);
  1291. if (Error != Error_Succeed)
  1292. {
  1293. m_pMediaControllerChannel->GetFunction()->CloseSession();
  1294. m_pMediaControllerChannel->SafeDelete();
  1295. m_pMediaControllerChannel = NULL;
  1296. }
  1297. }
  1298. if (Error == Error_Succeed)
  1299. {
  1300. ChannelService_BeginState_Sub Sub;
  1301. Error = m_pMediaControllerChannel->BeginState(Sub);
  1302. if (Error != Error_Succeed)
  1303. {
  1304. LOG_TRACE("BeginState biz channel failed!");
  1305. m_pMediaControllerChannel->GetFunction()->CloseSession();
  1306. m_pMediaControllerChannel->SafeDelete();
  1307. m_pMediaControllerChannel = NULL;
  1308. }
  1309. }
  1310. }
  1311. }
  1312. break;
  1313. case EVENT_MOD_CUSTOMERAWARE_BEGIN:
  1314. {
  1315. m_bCustomerwareBegin = true;
  1316. if (!m_bStartCamera&&!m_bExternControlCam)
  1317. {
  1318. StartCameraAndTiggerRecord(pszMessage);
  1319. }
  1320. }
  1321. break;
  1322. case EVENT_MOD_CUSTOMERAWARE_END:
  1323. {
  1324. m_bCustomerwareBegin = false;
  1325. if (/*m_bIsPadType&&*/m_bStartCamera&&!m_bExternControlCam)
  1326. {
  1327. Dbg("stop camera");
  1328. if (m_capture)
  1329. {
  1330. LogEvent(Severity_Middle, EVENT_MOD_END_RECORD,pszMessage);
  1331. GetFunction()->KillTimer(1);
  1332. capture_stop(m_capture);
  1333. capture_destroy(m_capture);
  1334. m_capture = NULL;
  1335. }
  1336. m_bStartCamera = FALSE;
  1337. }
  1338. }
  1339. break;
  1340. case EVENT_USB_CAMER_INPUT: // add by ly at 20160329
  1341. {
  1342. Dbg("[dbg] usbcam %s inserted.", pszMessage);
  1343. //huchen add for support usb inout,camera config AutoCorrect
  1344. if (m_bCustomerwareBegin){
  1345. if (/*m_bIsPadType&&*/!m_bStartCamera&&!m_bExternControlCam) {
  1346. CSimpleStringA strSessionId;
  1347. CSmartPointer<IEntityFunction> Func = GetFunction();
  1348. Func->GetSysVar("SessionID", strSessionId);
  1349. StartCameraAndTiggerRecord((LPCTSTR)strSessionId);
  1350. }
  1351. }
  1352. // comment by ly@2019/03/19
  1353. //::Sleep(2000); // 延迟2s后判断
  1354. //// 如果不是广角摄像头 edit by ly at 20161216
  1355. //if(!strstr((LPCTSTR)strEwsCam,pszMessage))
  1356. //{
  1357. // if (strUSBCam.GetLength() <= 1)
  1358. // {
  1359. // strUSBCam = pszMessage;
  1360. // // 对低柜双屏版屏蔽外接摄像头插入事件 edit by ly@2018/10
  1361. // if (eDesk2SType != m_eDeviceType)
  1362. // {
  1363. // // 广播给业务系统
  1364. // ExternalCameraInserted evt;
  1365. // evt.camname = CSimpleStringA2W(strUSBCam);
  1366. // SpSendBroadcast(GetFunction(), SP_MSG_OF(ExternalCameraInserted), SP_MSG_SIG_OF(ExternalCameraInserted), evt);
  1367. // Dbg("[dbg] ExternalCameraInserted broadcast sent!");
  1368. // }
  1369. // /// add by ly at 20161017
  1370. // /// notify to rvcweb that outer camera is switching
  1371. // SetCameraSysVar(CAMERA_START_ING);
  1372. // ExternalCameraStateChanged evt1;
  1373. // evt1.statemsg = CSimpleStringA2W("外接摄像头切换中,请稍等……");
  1374. // evt1.camname = CSimpleStringA2W(strUSBCam);
  1375. // SpSendBroadcast(GetFunction(), SP_MSG_OF(ExternalCameraStateChanged), SP_MSG_SIG_OF(ExternalCameraStateChanged), evt1);
  1376. // Dbg("[dbg] ExternalCameraStateChanged broadcast sent!");
  1377. // TryStartCamera();
  1378. // }
  1379. // else
  1380. // {
  1381. // Dbg("[dbg] more than one USBCam inserted!");
  1382. // }
  1383. //}
  1384. }
  1385. break;
  1386. case EVENT_USB_CAMER_OUTPUT: // add by ly at 20160329
  1387. {
  1388. Dbg("[dbg] usb cam %s removed.", pszMessage);
  1389. int nEnv = capture_get_video_device_id((LPCTSTR)conf.strVideoEnv);
  1390. // comment by ly@2019/03/19
  1391. //if(strstr((LPCTSTR)conf.strVideoEnv,pszMessage))
  1392. if(nEnv<0)
  1393. {
  1394. // 对低柜双屏版屏蔽外接摄像头拔出事件 edit by ly@2018/10
  1395. if (eDesk2SType != m_eDeviceType)
  1396. {
  1397. // 广播给业务系统
  1398. ExternalCameraRemoved evt;
  1399. // comment by ly@2019/03/19
  1400. //evt.camname = CSimpleStringA2W(strUSBCam);
  1401. evt.camname = CSimpleStringA2W(pszMessage);
  1402. SpSendBroadcast(GetFunction(), SP_MSG_OF(ExternalCameraRemoved), SP_MSG_SIG_OF(ExternalCameraRemoved), evt);
  1403. Dbg("[dbg] ExternalCameraRemoved broadcast sent!");
  1404. }
  1405. // comment by ly@2019/03/19
  1406. //// add by ly at 20161110
  1407. //// notify to rvcweb that inner camera is switching
  1408. //SetCameraSysVar(CAMERA_START_ING);
  1409. //ExternalCameraStateChanged evt1;
  1410. //evt1.statemsg = CSimpleStringA2W("内置摄像头启动中,请稍等……");
  1411. //evt1.camname = CSimpleStringA2W(strEnvCam);
  1412. //SpSendBroadcast(GetFunction(), SP_MSG_OF(ExternalCameraStateChanged), SP_MSG_SIG_OF(ExternalCameraStateChanged), evt1);
  1413. //Dbg("[dbg] ExternalCameraStateChanged broadcast sent!");
  1414. //
  1415. //::Sleep(1000); // 延迟1s后切换内置
  1416. //// 如果当前正在使用外接摄像头,则停用之
  1417. //Dbg("[dbg] stop external camera.");
  1418. //StopUSBCamera();
  1419. // 停止摄像头 add by ly@2019/03/19
  1420. if (m_bStartCamera&&!m_bExternControlCam)
  1421. {
  1422. Dbg("stop camera");
  1423. if (m_capture)
  1424. {
  1425. LogEvent(Severity_Middle, EVENT_MOD_END_RECORD,pszMessage);
  1426. GetFunction()->KillTimer(1);
  1427. capture_stop(m_capture);
  1428. capture_destroy(m_capture);
  1429. m_capture = NULL;
  1430. }
  1431. m_bStartCamera = FALSE;
  1432. }
  1433. }
  1434. else
  1435. {
  1436. Dbg("[dbg] USBCam(%s) is not the one used now!",pszMessage);
  1437. }
  1438. //strUSBCam = "$";
  1439. }
  1440. break;
  1441. case EVENT_USB_CAMERA_NOT_ONLY: // add by ly at 20160707
  1442. {
  1443. Dbg("[dbg] more than one usb cam detected.");
  1444. OnExternalCameraSwitchFailed(SwitchFailed_NoUnique);
  1445. }
  1446. break;
  1447. case LOG_EVT_RECORDFAILED: // add by ly at 20160713(edit by ly@2018/06/08)
  1448. {
  1449. Dbg("[dbg] record failed event.");
  1450. //GetFunction()->KillTimer(1);
  1451. //if (m_bIsPadType)
  1452. //{
  1453. // LogEvent(Severity_Middle, LOG_EVT_UI_STOPRECORD, NULL);
  1454. // m_nCameraErrorCode = Error_EnvCamera;
  1455. // ChangeSysvar(m_nCameraErrorCode);
  1456. // //重启ENV摄像头
  1457. // if((m_nCameraErrorCode == Error_EnvCamera)&&(m_nEnvCameraRestartNum<CAMERA_RESTARTNUM))
  1458. // {
  1459. // Dbg("[dbg] Restart EnvCamera as Error_EnvCamera.");
  1460. // if (ReStartCamera(ENVCAMERA) != Error_Succeed)
  1461. // {
  1462. // m_nEnvCameraRestartNum++;
  1463. // }
  1464. // else
  1465. // {
  1466. // m_nEnvCameraRestartNum = 0;
  1467. // m_nCameraErrorCode = Error_Succeed;
  1468. // ChangeSysvar(m_nCameraErrorCode);
  1469. // m_iEnvEmptyTimes = 0;
  1470. // }
  1471. // }
  1472. //}
  1473. //else
  1474. //{
  1475. // LogEvent(Severity_Middle, EVENT_MOD_END_RECORD,NULL);
  1476. // //重启ENV摄像头
  1477. // if(m_nEnvCameraRestartNum<CAMERA_RESTARTNUM)
  1478. // {
  1479. // if (ReStartCamera(ENVCAMERA) != Error_Succeed)
  1480. // {
  1481. // m_nEnvCameraRestartNum++;
  1482. // m_nCameraErrorCode = Error_EnvCamera;
  1483. // ChangeSysvar(m_nCameraErrorCode);
  1484. // }
  1485. // else
  1486. // {
  1487. // m_nEnvCameraRestartNum = 0;
  1488. // m_nCameraErrorCode = Error_Succeed;
  1489. // ChangeSysvar(m_nCameraErrorCode);
  1490. // m_iEnvEmptyTimes = 0;
  1491. // }
  1492. // }
  1493. // //重启OPT摄像头
  1494. // if(m_nEnvCameraRestartNum<CAMERA_RESTARTNUM)
  1495. // {
  1496. // if (ReStartCamera(OPTCAMERA) != Error_Succeed)
  1497. // {
  1498. // m_nEnvCameraRestartNum++;
  1499. // m_nCameraErrorCode = Error_OptCamera;
  1500. // ChangeSysvar(m_nCameraErrorCode);
  1501. // }
  1502. // else
  1503. // {
  1504. // m_nEnvCameraRestartNum = 0;
  1505. // m_nCameraErrorCode = Error_Succeed;
  1506. // ChangeSysvar(m_nCameraErrorCode);
  1507. // m_iEnvEmptyTimes = 0;
  1508. // }
  1509. // }
  1510. //}
  1511. //GetFunction()->SetTimer(1, this, 5000);
  1512. GetFunction()->KillTimer(1);
  1513. //edit by ly @2018/01/17
  1514. LogEvent(Severity_Middle, EVENT_MOD_END_RECORD, NULL);
  1515. char FaildFlag = pszMessage[0];
  1516. if (FaildFlag == '0')
  1517. {
  1518. GetFunction()->SetTimer(1, this, 5000);
  1519. OnExternalCameraSwitchFailed("本地录音录像失败,已停止!");
  1520. }
  1521. else //if (FaildFlag == '1')
  1522. {
  1523. OnExternalCameraSwitchFailed("本地录音录像设备故障,尝试恢复中(预计10s内),请稍等");
  1524. m_nCameraErrorCode = Error_AllCamera;
  1525. RealSelfCheck(); // 录音录像失败,强行kill实体
  1526. }
  1527. }
  1528. break;
  1529. case LOG_EVT_UI_RECORDFAILED: // add by ly@2018/06/08
  1530. {
  1531. Dbg("[dbg] sales record failed event.");
  1532. GetFunction()->KillTimer(1);
  1533. if (m_bIsRemoteRecord){
  1534. LogEvent(Severity_Middle, LOG_EVT_UI_STOPREMOTERECORD, NULL);
  1535. }
  1536. else{
  1537. LogEvent(Severity_Middle, LOG_EVT_UI_STOPRECORD, NULL);
  1538. }
  1539. char FaildFlag = pszMessage[0];
  1540. if (FaildFlag == '0')
  1541. {
  1542. GetFunction()->SetTimer(1, this, 5000);
  1543. OnExternalCameraSwitchFailed("现场销售录音录像失败,已停止!");
  1544. }
  1545. else //if (FaildFlag == '1')
  1546. {
  1547. OnExternalCameraSwitchFailed("现场销售录音录像设备故障,尝试恢复中(预计10s内),请稍等");
  1548. m_nCameraErrorCode = Error_AllCamera;
  1549. RealSelfCheck(); // 录音录像失败,强行kill实体
  1550. }
  1551. }
  1552. break;
  1553. case LOG_EVT_BEGIN_CAMERA_CONFIG:
  1554. {
  1555. ExternStopCamera();
  1556. }
  1557. break;
  1558. case LOG_EVT_END_CAMERA_CONFIG:
  1559. {
  1560. ExternStartCamera();
  1561. }
  1562. break;
  1563. case LOG_EVT_UI_STARTREMOTERECORD:
  1564. {
  1565. m_bIsRemoteRecord = true;
  1566. HandleRemoteRecord(pszMessage);
  1567. }
  1568. break;
  1569. case LOG_EVT_UI_STOPREMOTERECORD:
  1570. {
  1571. m_bIsRemoteRecord = false;
  1572. if (Error_Succeed == StopSalesRecordAudioCapture()){
  1573. Dbg("stop remote sales record audio capture.");
  1574. }
  1575. if (true == m_bHasStartSpeakerRender){
  1576. StopSpeakerAudioRender();
  1577. }
  1578. }
  1579. break;
  1580. //case EVENT_MOD_CONNECT_STOP_RECORD_BROADCAST:
  1581. // {
  1582. // if (eStand2sType == m_eDeviceType){
  1583. // StopSpeakerAudioRender();
  1584. // }
  1585. // }
  1586. // break;
  1587. case LOG_EVT_UI_STARTRECORD:
  1588. case LOG_EVT_UI_STARTRECORDPREVIEW:
  1589. {
  1590. m_bIsRemoteRecord = false;
  1591. if (false == m_bRecordPCM){
  1592. if (Error_Succeed == StartSalesRecordAudioCapture()){
  1593. Dbg("begin remote sales record audio capture.");
  1594. }
  1595. }
  1596. else{
  1597. HandleSalesRecordPCMAudio(false, pszMessage);
  1598. }
  1599. }
  1600. break;
  1601. case LOG_EVT_UI_STOPRECORD:
  1602. {
  1603. if (Error_Succeed == StopSalesRecordAudioCapture()){
  1604. Dbg("stop sales record audio capture.");
  1605. }
  1606. }
  1607. break;
  1608. case LOG_EVT_START_CONTINURECORD:
  1609. {
  1610. Dbg("receive LOG_EVT_START_CONTINURECORD event.");
  1611. }
  1612. break;
  1613. case LOG_EVT_STOP_CONTINURECORD:
  1614. {
  1615. Dbg("receive LOG_EVT_STOP_CONTINURECORD event.");
  1616. }
  1617. break;
  1618. default:
  1619. Dbg("unknown event.");
  1620. break;
  1621. }
  1622. }
  1623. virtual void OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
  1624. {
  1625. if (Test_ShakeHand == eTestType)
  1626. {
  1627. if (m_nCameraErrorCode == Error_AllCamera)
  1628. {
  1629. pTransactionContext->SendAnswer(Error_DevMedia);
  1630. }
  1631. else
  1632. {
  1633. pTransactionContext->SendAnswer(Error_Succeed);
  1634. }
  1635. }
  1636. }
  1637. //获取当前使用摄像头,30分钟轮休一次
  1638. int GetActiveCamera()
  1639. {
  1640. #ifdef RVC_OS_WIN
  1641. SYSTEMTIME st;
  1642. GetLocalTime(&st);
  1643. if (st.wMinute <= CAMERA_CHANGE_TIMER)
  1644. {
  1645. return ENVCAMERA;
  1646. }
  1647. else if (st.wMinute > CAMERA_CHANGE_TIMER)
  1648. {
  1649. return OPTCAMERA;
  1650. }
  1651. #else
  1652. return ENVCAMERA;
  1653. #endif // RVC_OS_WIN
  1654. }
  1655. ErrorCodeEnum ChangeSysvar(ErrorCodeEnum op)
  1656. {
  1657. switch (op)
  1658. {
  1659. case Error_Succeed:
  1660. Dbg("Camera State to No_Error");
  1661. //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_NO_ERROR);
  1662. SetCameraSysVar(CAMERA_NO_ERROR);
  1663. GetFunction()->SetUserDefineState(USER_MEDIA_IDLE);
  1664. break;
  1665. case Error_EnvCamera:
  1666. Dbg("Camera State to Env_Error");
  1667. //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_ENV_ERROR);
  1668. SetCameraSysVar(CAMERA_ENV_ERROR);
  1669. GetFunction()->SetUserDefineState(USER_MEDIA_ENVERRROR);
  1670. capture_clearsnapshotvideo(m_capture,ENVCAMERA);
  1671. break;
  1672. case Error_OptCamera:
  1673. Dbg("Camera State to Opt_Error");
  1674. //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_OPT_ERROR);
  1675. SetCameraSysVar(CAMERA_OPT_ERROR);
  1676. GetFunction()->SetUserDefineState(USER_MEDIA_OPTERROR);
  1677. capture_clearsnapshotvideo(m_capture,OPTCAMERA);
  1678. break;
  1679. case Error_AllCamera:
  1680. Dbg("Camera State to Both_Error");
  1681. //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_BOTH_ERROR);
  1682. SetCameraSysVar(CAMERA_BOTH_ERROR);
  1683. GetFunction()->SetUserDefineState(USER_MEDIA_ALLERROR);
  1684. capture_clearsnapshotvideo(m_capture,AlLCAMERA);
  1685. break;
  1686. default:
  1687. break;
  1688. }
  1689. return Error_Succeed;
  1690. }
  1691. void AutoCorrectCameraConfigName(long wait_time) {
  1692. ErrorCodeEnum Error = Error_Succeed;
  1693. int one_timeout = 400;
  1694. int retry = 0;
  1695. #ifdef RVC_OS_WIN
  1696. //检查配置名都成功,不用自动纠正
  1697. Error = CheckConfigCameraName(&conf);
  1698. if (Error == Error_Succeed) {
  1699. return;
  1700. }
  1701. #endif // RVC_OS_WIN
  1702. //只针对低柜双屏做自纠正
  1703. if(eDesk2SType != m_eDeviceType){
  1704. Dbg("AutoCorrectCameraConfig failed, DeviceType:%d is not Desk2SType", m_eDeviceType);
  1705. return;
  1706. }
  1707. auto pCameraConfigManageClient = new CameraConfigManageService_ClientBase(this);
  1708. while ((pCameraConfigManageClient->Connect() != Error_Succeed) && retry < wait_time/one_timeout)
  1709. {
  1710. Dbg("连接CameraConfigManage实体失败, retry:%d", retry);
  1711. Sleep(one_timeout);
  1712. retry++;
  1713. }
  1714. //连接不上,不纠正
  1715. if (retry >= wait_time/one_timeout){
  1716. pCameraConfigManageClient->SafeDelete();
  1717. pCameraConfigManageClient = NULL;
  1718. }
  1719. else {
  1720. CameraConfigManageService_AutoCorrectCameraConfig_Req req;
  1721. CameraConfigManageService_AutoCorrectCameraConfig_Ans ans;
  1722. DWORD Timeout = 5000;
  1723. Error = pCameraConfigManageClient->AutoCorrectCameraConfig(req, ans, Timeout);
  1724. if (Error != Error_Succeed)
  1725. {
  1726. Dbg("CameraConfigManage 调用 AutoCorrectCameraConfig 失败: 0x%x", Error);
  1727. }
  1728. else
  1729. {
  1730. Dbg("AutoCorrectCameraConfig, old EnvCamera;%s, OptCamera;%s, EwsCamera;%s",
  1731. (LPCSTR)conf.strVideoEnv, (LPCSTR)conf.strVideoOpt, (LPCSTR)strEwsCam);
  1732. Dbg("AutoCorrectCameraConfig, get new EnvCamera;%s, OptCamera;%s, EwsCamera;%s",
  1733. (LPCSTR)ans.EnvCamera, (LPCSTR)ans.OptCamera, (LPCSTR)ans.EwsCamera);
  1734. if ((ans.EnvCamera.GetLength() > 1) && (conf.strVideoEnv.GetLength() > 1)){
  1735. conf.strVideoEnv = ans.EnvCamera;
  1736. }
  1737. if ((ans.OptCamera.GetLength() > 1) && (conf.strVideoOpt.GetLength() > 1)){
  1738. conf.strVideoOpt = ans.OptCamera;
  1739. }
  1740. if ((ans.EwsCamera.GetLength() > 1) && (strEwsCam.GetLength() > 1)){
  1741. strEwsCam = ans.EwsCamera;
  1742. }
  1743. Dbg("AutoCorrectCameraConfig, updated EnvCamera;%s, OptCamera;%s, EwsCamera;%s",
  1744. (LPCSTR)conf.strVideoEnv, (LPCSTR)conf.strVideoOpt, (LPCSTR)strEwsCam);
  1745. }
  1746. pCameraConfigManageClient->GetFunction()->CloseSession();
  1747. pCameraConfigManageClient->SafeDelete();
  1748. pCameraConfigManageClient = NULL;
  1749. }
  1750. }
  1751. //开始销售双录音频采集函数
  1752. ErrorCodeEnum StartSalesRecordAudioCapture(bool bRemoteRecord = false, eRvcPCMTransType eType = eUnKnown, void* pData = NULL)
  1753. {
  1754. ErrorCodeEnum Error = Error_Succeed;
  1755. if (NULL == m_salesaudio_capture){
  1756. memset(&m_sales_audio_conf, 0, sizeof(m_sales_audio_conf));
  1757. GetSalesAudioConfig(&m_sales_audio_conf, bRemoteRecord);
  1758. Error = (ErrorCodeEnum)salesaudio_capture_create(&m_sales_audio_conf, &m_salesaudio_capture);
  1759. if (Error_Succeed == Error){
  1760. Error = SetSalesRecordAudioCaptureTransActionData(eType, pData);
  1761. }
  1762. }
  1763. if (Error_Succeed == Error){
  1764. Error = salesrecord_audio_capture_start(m_salesaudio_capture);
  1765. if (Error_Succeed == Error){
  1766. Dbg("sales record audio capture start success.");
  1767. }
  1768. else{
  1769. Dbg("sales record audio capture start failed for param error.");
  1770. }
  1771. }
  1772. return Error;
  1773. }
  1774. //停止销售双录音频采集函数
  1775. ErrorCodeEnum StopSalesRecordAudioCapture()
  1776. {
  1777. salesrecord_audio_capture_stop(m_salesaudio_capture);
  1778. salesaudio_capture_destroy(m_salesaudio_capture);
  1779. m_salesaudio_capture = NULL;
  1780. Dbg("set m_salesaudio_capture to null.");
  1781. return Error_Succeed;
  1782. }
  1783. ErrorCodeEnum StartCamera()
  1784. {
  1785. if (m_capture == NULL)
  1786. {
  1787. //打开前检查配置摄像头名字是否能被打开并自纠正
  1788. AutoCorrectCameraConfigName(4000);
  1789. ErrorCodeEnum Error = Error_Succeed;
  1790. conf.ref_env_capture_count = &m_lCaptureEnvCount;
  1791. conf.ref_opt_capture_count = &m_lCaptureOptCount;
  1792. conf.ref_envopt_capture_count = &m_lCaptureEnvOptCount;
  1793. Error = (ErrorCodeEnum)capture_create(&conf, &m_capture);
  1794. if (Error == Error_Succeed)
  1795. {
  1796. Error = capture_start(m_capture);
  1797. Dbg("capture_start Error code=0x%x",Error);
  1798. if (Error != Error_Succeed)
  1799. {
  1800. if((Error == Error_AudioIN)||(Error == Error_AudioOut))
  1801. {
  1802. return Error;
  1803. }
  1804. else if (Error == Error_AllCamera)
  1805. {
  1806. capture_destroy(m_capture);
  1807. m_capture = NULL;
  1808. return Error;
  1809. }
  1810. else
  1811. {
  1812. SetAutoBright(Error);
  1813. GetFunction()->SetTimer(1, this, 5000);
  1814. if((Error == Error_OptCamera)&&((ePadtype == m_eDeviceType)||(eMobilePadType == m_eDeviceType)||(eDesk2SType == m_eDeviceType)||(eDesk1SType == m_eDeviceType)||(eDesk2SIntegratedType == m_eDeviceType)))
  1815. {
  1816. return Error_Succeed;
  1817. }
  1818. else
  1819. {
  1820. return Error;
  1821. }
  1822. }
  1823. }
  1824. else
  1825. {
  1826. SetAutoBright(Error);
  1827. GetFunction()->SetTimer(1, this, 5000);
  1828. return Error_Succeed;
  1829. }
  1830. }
  1831. else
  1832. {
  1833. Dbg("create capture failed! %d", Error);
  1834. m_capture = NULL;
  1835. return Error_Unexpect;
  1836. }
  1837. return Error;
  1838. }
  1839. else
  1840. {
  1841. Dbg("m_capture == NULL");
  1842. return Error_Unexpect;
  1843. }
  1844. }
  1845. ErrorCodeEnum StartCamera(int nCamera)
  1846. {
  1847. if (m_capture == NULL)
  1848. {
  1849. //打开前检查配置摄像头名字是否能被打开并自纠正
  1850. AutoCorrectCameraConfigName(4000);
  1851. ErrorCodeEnum Error = Error_Succeed;
  1852. Error = capture_create(&conf, m_capture,nCamera);
  1853. if (Error == Error_Succeed)
  1854. {
  1855. return capture_start(m_capture,nCamera);
  1856. }
  1857. else
  1858. {
  1859. return Error_Hardware;
  1860. }
  1861. }
  1862. else
  1863. {
  1864. return Error_Unexpect;
  1865. }
  1866. }
  1867. void StartCameraAndTiggerRecord(const char * strSessionId){
  1868. Dbg("start camera");
  1869. ErrorCodeEnum Error = StartCamera();
  1870. if (Error == Error_Succeed)
  1871. {
  1872. //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_NO_ERROR);
  1873. SetCameraSysVar(CAMERA_NO_ERROR);
  1874. Dbg("Camera State to CAMERA_NO_ERROR");
  1875. m_bStartCamera = TRUE;
  1876. LogEvent(Severity_Middle, EVENT_MOD_BEGIN_RECORD,strSessionId);
  1877. }
  1878. else
  1879. {
  1880. if (Error == Error_EnvCamera)
  1881. {
  1882. //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_ENV_ERROR);
  1883. SetCameraSysVar(CAMERA_ENV_ERROR);
  1884. Dbg("Camera State to CAMERA_ENV_ERROR");
  1885. m_bStartCamera = TRUE;
  1886. LogEvent(Severity_Middle, EVENT_MOD_BEGIN_RECORD,strSessionId);
  1887. }
  1888. else if (Error == Error_OptCamera)
  1889. {
  1890. //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_OPT_ERROR);
  1891. SetCameraSysVar(CAMERA_OPT_ERROR);
  1892. Dbg("Camera State to CAMERA_OPT_ERROR");
  1893. m_bStartCamera = TRUE;
  1894. LogEvent(Severity_Middle, EVENT_MOD_BEGIN_RECORD,strSessionId);
  1895. }
  1896. else if (Error == Error_AllCamera)
  1897. {
  1898. //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_BOTH_ERROR);
  1899. SetCameraSysVar(CAMERA_BOTH_ERROR);
  1900. Dbg("Camera State to CAMERA_BOTH_ERROR");
  1901. m_nCameraErrorCode = Error_AllCamera;
  1902. m_bStartCamera = FALSE;
  1903. GetFunction()->SetUserDefineState(USER_MEDIA_ALLERROR);
  1904. }
  1905. else
  1906. {
  1907. SetCameraSysVar(Error);
  1908. Dbg("Camera State to Other Error");
  1909. m_nCameraErrorCode = Error;
  1910. m_bStartCamera = FALSE;
  1911. }
  1912. }
  1913. }
  1914. ErrorCodeEnum ReStartCamera(int nCamera)
  1915. {
  1916. if (m_capture != NULL)
  1917. {
  1918. if((StopCamera(m_capture,nCamera)==-1))
  1919. {
  1920. Dbg("ReStartCamera,stop camera fail!");
  1921. }
  1922. Sleep(2000);
  1923. //打开前检查配置摄像头名字是否能被打开并自纠正
  1924. AutoCorrectCameraConfigName(4000);
  1925. ErrorCodeEnum Error = Error_Succeed;
  1926. Error = capture_create(&conf, m_capture,nCamera);
  1927. if (Error == Error_Succeed)
  1928. {
  1929. Error = capture_start(m_capture,nCamera);
  1930. if (Error != Error_Succeed)
  1931. {
  1932. Dbg("ReStartCamera,capture_start fail!");
  1933. capture_destroy(m_capture,nCamera);
  1934. return Error;
  1935. }
  1936. else
  1937. {
  1938. Dbg("ReStartCamera,camera = %d,success!",nCamera);
  1939. return Error_Succeed;
  1940. }
  1941. }
  1942. else
  1943. {
  1944. Dbg("ReStartCamera,capture_create fail!");
  1945. capture_destroy(m_capture,nCamera);
  1946. return Error;
  1947. }
  1948. }
  1949. else
  1950. {
  1951. return Error_Unexpect;
  1952. }
  1953. }
  1954. virtual CServerSessionBase *OnNewSession(const char* pszRemoteEntityName, const char * pszClass)
  1955. {
  1956. LOG_FUNCTION();
  1957. LOG_TRACE("%s connected class = %s!", pszRemoteEntityName, pszClass);
  1958. return new MediaServiceSession(this);
  1959. }
  1960. public:
  1961. ErrorCodeEnum ExternStartCamera()
  1962. {
  1963. Dbg("Extern start camera");
  1964. CSimpleStringA strSessionId;
  1965. CSmartPointer<IEntityFunction> Func = GetFunction();
  1966. Func->GetSysVar("SessionID", strSessionId);
  1967. if (!m_bStartCamera)
  1968. {
  1969. StartCameraAndTiggerRecord((LPCTSTR)strSessionId);
  1970. }
  1971. m_bExternControlCam = FALSE;
  1972. return Error_Succeed;
  1973. }
  1974. ErrorCodeEnum ExternStopCamera()
  1975. {
  1976. Dbg("Extern stop camera");
  1977. if (m_capture)
  1978. {
  1979. LogEvent(Severity_Middle, EVENT_MOD_END_RECORD,NULL);
  1980. GetFunction()->KillTimer(1);
  1981. capture_stop(m_capture);
  1982. capture_destroy(m_capture);
  1983. m_capture = NULL;
  1984. }
  1985. m_bStartCamera = FALSE;
  1986. m_bExternControlCam = TRUE;
  1987. return Error_Succeed;
  1988. }
  1989. //add by ly at 20160401
  1990. ErrorCodeEnum SaveInnerCamera()
  1991. {
  1992. if (strFrontCam.GetLength() <= 1) {
  1993. return Error_Resource;
  1994. }
  1995. if (strstr((LPCTSTR)conf.strVideoEnv,(LPCTSTR)strFrontCam)==NULL)
  1996. {
  1997. CSimpleStringA tmp = strRearCam;
  1998. strRearCam = strFrontCam;
  1999. strFrontCam = tmp;
  2000. }
  2001. Dbg("[dbg] strFrontCam: %s, strRearCam: %s", (LPCSTR)strFrontCam, (LPCSTR)strRearCam);
  2002. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  2003. CSmartPointer<IConfigInfo> spConfig;
  2004. ErrorCodeEnum Error = spFunction->OpenConfig(Config_Run, spConfig);
  2005. if (Error == Error_Succeed) {
  2006. SpIniMappingTable table;
  2007. table.AddEntryString("Video", "FrontCamera", strFrontCam, "$");
  2008. table.AddEntryString("Video", "RearCamera", strRearCam, "$");
  2009. Error = table.Save(spConfig);
  2010. if (Error != Error_Succeed)
  2011. {
  2012. LOG_TRACE("[dbg] failed to save run config.");
  2013. }
  2014. }
  2015. else {
  2016. LOG_TRACE("[dbg] failed to open run config.");
  2017. }
  2018. return Error;
  2019. }
  2020. // 获取高拍仪摄像头(考虑多个高拍仪)
  2021. ErrorCodeEnum GetHSPCameras(CAutoArray<CSimpleStringA> &HSPCameras)
  2022. {
  2023. enum CapTypeEnum {
  2024. CAMTYPE_UNKNOWN = 0,
  2025. CAMTYPE_ENV,
  2026. CAMTYPE_OPT,
  2027. CAMTYPE_EWS,
  2028. CAMTYPE_HSPS,
  2029. CAMTYPE_CIRCLE,
  2030. CAMTYPE_MAX
  2031. };
  2032. auto rc = Error_Succeed;
  2033. auto pScannerSetClient = new ScannerService_ClientBase(this);
  2034. if (pScannerSetClient->Connect() != Error_Succeed)
  2035. {
  2036. Dbg("连接ScannerSet实体失败");
  2037. pScannerSetClient->SafeDelete();
  2038. pScannerSetClient = NULL;
  2039. rc = Error_DevConnFailed;
  2040. }
  2041. else
  2042. {
  2043. ScannerService_GetOnlineCameras_Req req = {};
  2044. ScannerService_GetOnlineCameras_Ans ans = {};
  2045. rc = pScannerSetClient->GetOnlineCameras(req, ans, 10000);
  2046. if (rc != Error_Succeed)
  2047. {
  2048. Dbg("ScannerSet 调用 GetOnlineCameras 失败: 0x%x", rc);
  2049. }
  2050. else
  2051. {
  2052. Dbg("ScannerSet invokes GetOnlineCameras suc.");
  2053. Dbg("Count: %d", ans.devCount);
  2054. if (ans.devCount > 0) {
  2055. for (int i = 0; i < ans.devFriendlyNames.GetCount(); ++i) {
  2056. Dbg("[%d]%s(%d)", i, (LPCTSTR)ans.devFriendlyNames[i],
  2057. ans.devType[i]);
  2058. CapTypeEnum devType = (CapTypeEnum)ans.devType[i];
  2059. if (devType == CAMTYPE_HSPS)
  2060. {
  2061. HSPCameras.Append(ans.devFriendlyNames, i, 1);
  2062. }
  2063. }
  2064. }
  2065. }
  2066. pScannerSetClient->GetFunction()->CloseSession();
  2067. pScannerSetClient->SafeDelete();
  2068. pScannerSetClient = NULL;
  2069. }
  2070. return rc;
  2071. }
  2072. ErrorCodeEnum HandleSalesRecordPCMAudio(bool bRemoteRecord, const char *pszMessage, audio_frame* pFrame = NULL)
  2073. {
  2074. ErrorCodeEnum Error = Error_Succeed;
  2075. char strSwiftName[MAX_PATH] = {0};
  2076. if (NULL != pszMessage){
  2077. size_t ulen = strlen(pszMessage);
  2078. char *tmp = new char[ulen+1];
  2079. memset(tmp, 0, ulen + 1);
  2080. memcpy(tmp, pszMessage, ulen);
  2081. char *result[16] = {0};
  2082. auto arr1 = CSimpleStringA2W(tmp).Split('@');
  2083. auto arr2 = CAutoArray<CSimpleStringA>(arr1.GetCount());
  2084. for (int i = 0; i < arr1.GetCount(); ++i){
  2085. arr2[i] = CSimpleStringW2A(arr1[i]);
  2086. result[i] = const_cast<LPSTR>(arr2[i].GetData());
  2087. }
  2088. if (arr1.GetCount() > 4){
  2089. Dbg("remote record swift number is %s.", result[4]);
  2090. sprintf(strSwiftName, "%s", result[4]);
  2091. }
  2092. delete tmp;
  2093. tmp = NULL;
  2094. }
  2095. char strMicroName[MAX_PATH] = {0};
  2096. CSimpleStringA strTempDir;
  2097. if (Error_Succeed == GetFunction()->GetPath("Temp", strTempDir)){
  2098. sprintf_s(strMicroName, MAX_PATH, "%s\\local_micro_%s.pcm", strTempDir.GetData(), strSwiftName);
  2099. }
  2100. else{
  2101. sprintf_s(strMicroName, MAX_PATH, "local_micro_%s.pcm", strSwiftName);
  2102. }
  2103. FILE *pRecord = fopen(strMicroName, "wb+");
  2104. if (NULL != pRecord){
  2105. if (Error_Succeed == StartSalesRecordAudioCapture(bRemoteRecord, eSingleWriteLocal, pRecord)){
  2106. Dbg("begin remote sales record audio capture and record local PCM.");
  2107. }
  2108. }
  2109. else{
  2110. Dbg("fopen %s failed.",strMicroName);
  2111. }
  2112. if (true == bRemoteRecord){
  2113. char strSpeakerName[MAX_PATH] = {0};
  2114. if ("" != strTempDir){
  2115. sprintf_s(strSpeakerName, MAX_PATH, "%s\\remote_speaker_%s.pcm", strTempDir.GetData(), strSwiftName);
  2116. }
  2117. else{
  2118. sprintf_s(strSpeakerName, MAX_PATH, "remote_speaker_%s.pcm", strSwiftName);
  2119. }
  2120. StartSpeakerAudioRender(0, pFrame, strSpeakerName);
  2121. }
  2122. return Error;
  2123. }
  2124. void HandleRemoteRecord(const char *pszMessage)
  2125. {
  2126. audio_frame frame;
  2127. frame.bitspersample = 16;
  2128. frame.format = 1;
  2129. frame.framesize = 320;
  2130. frame.nchannels = 1;
  2131. frame.samplespersec = 8000;
  2132. if (true == m_bRecordPCM){
  2133. HandleSalesRecordPCMAudio(true, pszMessage, &frame);
  2134. }
  2135. else{
  2136. if (Error_Succeed == StartSalesRecordAudioCapture(true)){
  2137. Dbg("begin remote sales record audio capture.");
  2138. }
  2139. StartSpeakerAudioRender(0, &frame, NULL);
  2140. }
  2141. }
  2142. ErrorCodeEnum StartSpeakerAudioRender(int iQueue, audio_frame* pFrame, const char* strName)
  2143. {
  2144. auto rc = Error_Succeed;
  2145. Dbg("start speak audio render.");
  2146. #ifdef RVC_OS_WIN
  2147. if (NULL != m_pAudioRenderObj) {
  2148. if (0 == m_pAudioRenderObj->StartRender(0, pFrame, strName)) {
  2149. m_bHasStartSpeakerRender = true;
  2150. Dbg("start speak audio render success.");
  2151. }
  2152. }
  2153. #else
  2154. #endif // RVC_OS_WIN
  2155. return rc;
  2156. }
  2157. ErrorCodeEnum StopSpeakerAudioRender()
  2158. {
  2159. auto rc = Error_Succeed;
  2160. Dbg("stop speak audio render.");
  2161. #ifdef RVC_OS_WIN
  2162. if (NULL != m_pAudioRenderObj) {
  2163. m_pAudioRenderObj->StopRender();
  2164. m_bHasStartSpeakerRender = false;
  2165. }
  2166. #else
  2167. #endif // RVC_OS_WIN
  2168. return rc;
  2169. }
  2170. ErrorCodeEnum SetSalesRecordAudioCaptureTransActionData(eRvcPCMTransType eType, void* pData)
  2171. {
  2172. auto rc = Error_Param;
  2173. if (NULL != m_salesaudio_capture){
  2174. if (NULL != m_salesaudio_capture->rvc_audio){
  2175. m_salesaudio_capture->rvc_audio->eType = eType;
  2176. m_salesaudio_capture->rvc_audio->pdata = pData;
  2177. rc = Error_Succeed;
  2178. }
  2179. }
  2180. return rc;
  2181. }
  2182. DeviceTypeEnum m_eDeviceType;
  2183. BOOL m_bStartCamera;
  2184. BOOL m_bExternControlCam;
  2185. capture_config_t conf;
  2186. rvc_audio_capture_config_s m_sales_audio_conf; //销售双录音频配置
  2187. ErrorCodeEnum m_nCameraErrorCode; //摄像头故障码,0:无故障,1:env摄像头故障,2:opt摄像头故障,3:双摄像头故障
  2188. int m_nCurActiveCamera; //当前正在使用的摄像头
  2189. CSimpleStringA strFrontCam;
  2190. CSimpleStringA strRearCam;
  2191. CSimpleStringA strEnvCam; //Env摄像头 add by ly 20160331
  2192. CSimpleStringA strUSBCam; //外接摄像头 add by ly 20160329
  2193. CSimpleStringA strEwsCam; //外部广角摄像头路径名(全程录像用,通常不配置)
  2194. int m_nCameraCount; //当前摄像头数量 add by ly 20160531
  2195. int m_nSysCallType;//0:普通模式,1:p2p模式
  2196. capture_t *m_capture;
  2197. rvc_sales_audio_capture_t *m_salesaudio_capture;
  2198. BOOL m_bCustomerwareBegin;
  2199. bool m_bHasStartSpeakerRender; //add by clp 20200416 是否已开启扬声器音频采集
  2200. private:
  2201. LONG m_lCaptureEnvCount;
  2202. LONG m_lCaptureOptCount;
  2203. LONG m_lCaptureEnvOptCount;
  2204. CAutoArray<CUUID> m_arrListener;
  2205. ChannelMediaControllerClient *m_pMediaControllerChannel;
  2206. SelfChekerClient*m_pSelfcheckClient;
  2207. IAudioRender* m_pAudioRenderObj; //add by clp 20200319 扬声器捕捉实体
  2208. bool m_bRecordPCM; //add by clp 20200401 是否单独录制PCM音频
  2209. int m_nSalesAudioSmpPsec; //add by clp 20200402 销售双录音频采样率
  2210. bool m_bIsRemoteRecord; //add by clp 20200403 是否是远程双录
  2211. };
  2212. SelfChekerClient::SelfChekerClient( CMediaControllerEntity *pEntity ) : SelfCheckerService_ClientBase(pEntity)
  2213. {
  2214. }
  2215. ChannelMediaControllerClient::ChannelMediaControllerClient( CMediaControllerEntity *pEntity ) : ChannelService_ClientBase(pEntity)
  2216. {
  2217. }
  2218. void ChannelMediaControllerClient::OnMessage(ErrorCodeEnum Error, ChannelService_State_Info &Msg, CSmartPointer<IReleasable> pData)
  2219. {
  2220. if (Error == Error_Succeed)
  2221. {
  2222. CMediaControllerEntity *pEntity = static_cast<CMediaControllerEntity*>(m_pEntityBase);
  2223. if (Msg.state == eChannelState_Idle)
  2224. {
  2225. if (pEntity->m_bStartCamera)
  2226. {
  2227. if (pEntity->SetAutoBright(pEntity->m_nCameraErrorCode)==false)
  2228. {
  2229. Dbg("SetAutoBright Fail!");
  2230. }
  2231. }
  2232. }
  2233. else if (Msg.state == eChannelState_Connected)
  2234. {
  2235. if (pEntity->m_bStartCamera)
  2236. {
  2237. pEntity->SendCameraBright();
  2238. }
  2239. }
  2240. }
  2241. }
  2242. void ChannelMediaControllerClient::OnMessage( ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer<IReleasable> pData )
  2243. {
  2244. LOG_FUNCTION();
  2245. if (Error == Error_Succeed)
  2246. {
  2247. CMediaControllerEntity *pEntity = static_cast<CMediaControllerEntity*>(m_pEntityBase);
  2248. pEntity->OnReceivePkt(Msg.sub_type, (const char*)Msg.data.m_pData, Msg.data.m_iLength);
  2249. }
  2250. }
  2251. // edit by ly 20160401
  2252. void MediaServiceSession::Handle_GetVideoDeviceName(SpReqAnsContext<MediaService_GetVideoDeviceName_Req, MediaService_GetVideoDeviceName_Ans>::Pointer ctx)
  2253. {
  2254. CSimpleStringA frontcam = m_pEntity->strFrontCam;
  2255. CSimpleStringA rearcam = m_pEntity->strRearCam;
  2256. if (frontcam.GetLength() > 1 && rearcam.GetLength() > 1)
  2257. {
  2258. ctx->Ans.frontcam = frontcam;
  2259. if (strstr((LPCTSTR)frontcam,";"))
  2260. {
  2261. ctx->Ans.frontcam = frontcam.SubString(0, frontcam.IndexOf(";"));
  2262. }
  2263. ctx->Ans.rearcam = rearcam;
  2264. if (strstr((LPCTSTR)rearcam,";"))
  2265. {
  2266. ctx->Ans.rearcam = rearcam.SubString(0, rearcam.IndexOf(";"));
  2267. }
  2268. Dbg("get camera1 name:%s",m_pEntity->strFrontCam);
  2269. Dbg("get camera2 name:%s",m_pEntity->strRearCam);
  2270. }
  2271. ctx->Answer(Error_Succeed);
  2272. }
  2273. void MediaServiceSession::Handle_StartCamera(SpOnewayCallContext<MediaService_StartCamera_Info>::Pointer ctx)
  2274. {
  2275. m_pEntity->ExternStartCamera();
  2276. }
  2277. void MediaServiceSession::Handle_StopCamera(SpOnewayCallContext<MediaService_StopCamera_Info>::Pointer ctx)
  2278. {
  2279. m_pEntity->ExternStopCamera();
  2280. }
  2281. void MediaServiceSession::Handle_StartEnvCamera(SpReqAnsContext<MediaService_StartEnvCamera_Req, MediaService_StartEnvCamera_Ans>::Pointer ctx)
  2282. {
  2283. LOG_FUNCTION();
  2284. ErrorCodeEnum Error = m_pEntity->StartEnvCamera();
  2285. ctx->Ans.returncod = Error;
  2286. ctx->Answer(Error);
  2287. }
  2288. void MediaServiceSession::Handle_StopEnvCamera(SpOnewayCallContext<MediaService_StopEnvCamera_Info>::Pointer ctx)
  2289. {
  2290. LOG_FUNCTION();
  2291. m_pEntity->StopEnvCamera();
  2292. }
  2293. void MediaServiceSession::Handle_StartSpeakerRender(SpOnewayCallContext<MediaService_StartSpeakerRender_Info>::Pointer ctx)
  2294. {
  2295. LOG_FUNCTION();
  2296. }
  2297. void MediaServiceSession::Handle_StopSpeakerRender(SpOnewayCallContext<MediaService_StopSpeakerRender_Info>::Pointer ctx)
  2298. {
  2299. LOG_FUNCTION();
  2300. if (true == m_pEntity->m_bHasStartSpeakerRender){
  2301. m_pEntity->StopSpeakerAudioRender();
  2302. }
  2303. else{
  2304. Dbg("speaker audio render already stopped.");
  2305. }
  2306. }
  2307. SP_BEGIN_ENTITY_MAP()
  2308. SP_ENTITY(CMediaControllerEntity)
  2309. SP_END_ENTITY_MAP()