mod_mediacontroller.cpp 74 KB

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