mod_mediacontroller.cpp 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494
  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. MessageBoxA(NULL,pszFailedMsg,NULL,MB_SYSTEMMODAL);
  1176. }
  1177. }
  1178. // comment by ly@2019/03/19
  1179. //ErrorCodeEnum TryStartCamera()
  1180. //{
  1181. // Dbg("[dbg] StartExternalCamera");
  1182. // ErrorCodeEnum errorCode = StartUSBCamera();
  1183. // Dbg("StartExternalCamera:0x%x", errorCode);
  1184. // int nRetCod = 5;
  1185. // switch(errorCode)
  1186. // {
  1187. // case Error_Succeed:
  1188. // {
  1189. // nRetCod = 0; // 正常
  1190. // /// add by ly at 20161017
  1191. // /// notify to rvcweb that outer camera switch has finished
  1192. // ExternalCameraStateChanged evt;
  1193. // evt.statemsg = CSimpleStringA2W("已切换到外接摄像头!");
  1194. // evt.camname = CSimpleStringA2W(strUSBCam);
  1195. // SpSendBroadcast(GetFunction(), SP_MSG_OF(ExternalCameraStateChanged), SP_MSG_SIG_OF(ExternalCameraStateChanged), evt);
  1196. // Dbg("[dbg] ExternalCameraStateChanged broadcast sent!");
  1197. // }
  1198. // break;
  1199. // case Error_Resource:
  1200. // nRetCod = 1; // 外接摄像头未插入
  1201. // break;
  1202. // case Error_EnvCamera:
  1203. // case Error_AllCamera:
  1204. // nRetCod = 2; // 外接摄像头启动失败
  1205. // OnExternalCameraSwitchFailed(SwitchFailed_StartFault);
  1206. // break;
  1207. // case Error_DevNotAvailable:
  1208. // nRetCod = 3; // 检测到一个外接摄像头,但无法分辨名称
  1209. // OnExternalCameraSwitchFailed(SwitchFailed_Ambiguous);
  1210. // break;
  1211. // case Error_Duplication:
  1212. // nRetCod = 4; // 检测到两个以上外接摄像头
  1213. // OnExternalCameraSwitchFailed(SwitchFailed_NoUnique);
  1214. // break;
  1215. // default:
  1216. // nRetCod = 5; // 其他错误
  1217. // OnExternalCameraSwitchFailed(SwitchFailed_StartFault);
  1218. // break;
  1219. // }
  1220. // if (m_bStartCamera == FALSE) // 外接没启动成,如果内置没启动,切换到内置
  1221. // {
  1222. // SetCameraSysVar(CAMERA_START_ING);
  1223. // ExternalCameraStateChanged evt;
  1224. // evt.statemsg = CSimpleStringA2W("无法启动外接,内置切换中……");
  1225. // evt.camname = CSimpleStringA2W(strEnvCam);
  1226. // SpSendBroadcast(GetFunction(), SP_MSG_OF(ExternalCameraStateChanged), SP_MSG_SIG_OF(ExternalCameraStateChanged), evt);
  1227. // Dbg("[dbg] ExternalCameraStateChanged broadcast sent!");
  1228. // return StopUSBCamera();
  1229. // }
  1230. // return Error_Succeed;
  1231. //}
  1232. virtual void OnLog( const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  1233. const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  1234. const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage)
  1235. {
  1236. LOG_TRACE("user_code = %08x", dwUserCode);
  1237. switch (dwUserCode)
  1238. {
  1239. case MOD_EVENT_SNAPSHOT_START_CAPTURE_ENVOPT:
  1240. {
  1241. Dbg("recv MOD_EVENT_SNAPSHOT_START_CAPTURE_ENVOPT");
  1242. InterlockedCompareExchange(&m_lCaptureEnvOptCount, 3, 0);
  1243. }
  1244. break;
  1245. case MOD_EVENT_SNAPSHOT_START_CAPTURE_ENV:
  1246. {
  1247. Dbg("recv MOD_EVENT_SNAPSHOT_START_CAPTURE_ENV");
  1248. InterlockedCompareExchange(&m_lCaptureEnvCount, 1, 0);
  1249. }
  1250. break;
  1251. case MOD_EVENT_SNAPSHOT_START_CAPTURE_OPT:
  1252. {
  1253. Dbg("recv MOD_EVENT_SNAPSHOT_START_CAPTURE_OPT");
  1254. InterlockedCompareExchange(&m_lCaptureOptCount, 1, 0);
  1255. }
  1256. break;
  1257. case LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE:
  1258. {
  1259. Dbg("recv LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE");
  1260. if (m_pMediaControllerChannel!=NULL)
  1261. {
  1262. m_pMediaControllerChannel->GetFunction()->CloseSession();
  1263. m_pMediaControllerChannel->SafeDelete();
  1264. m_pMediaControllerChannel = NULL;
  1265. Dbg("Close AssistChannel Session ");
  1266. }
  1267. if (m_pMediaControllerChannel == NULL)
  1268. {
  1269. Dbg("ReConnection AssistChannel Session");
  1270. m_pMediaControllerChannel = new ChannelMediaControllerClient(this);
  1271. ErrorCodeEnum Error = m_pMediaControllerChannel->Connect();
  1272. if (Error != Error_Succeed)
  1273. {
  1274. m_pMediaControllerChannel->SafeDelete();
  1275. m_pMediaControllerChannel = NULL;
  1276. Dbg("AssistChannelClient connect fail!");
  1277. }
  1278. if (Error == Error_Succeed)
  1279. {
  1280. ChannelService_BeginRecv_Sub Sub;
  1281. Sub.type = ACM_TYPE_DEVICE;
  1282. Error = m_pMediaControllerChannel->BeginRecv(Sub);
  1283. if (Error != Error_Succeed)
  1284. {
  1285. m_pMediaControllerChannel->GetFunction()->CloseSession();
  1286. m_pMediaControllerChannel->SafeDelete();
  1287. m_pMediaControllerChannel = NULL;
  1288. }
  1289. }
  1290. if (Error == Error_Succeed)
  1291. {
  1292. ChannelService_BeginState_Sub Sub;
  1293. Error = m_pMediaControllerChannel->BeginState(Sub);
  1294. if (Error != Error_Succeed)
  1295. {
  1296. LOG_TRACE("BeginState biz channel failed!");
  1297. m_pMediaControllerChannel->GetFunction()->CloseSession();
  1298. m_pMediaControllerChannel->SafeDelete();
  1299. m_pMediaControllerChannel = NULL;
  1300. }
  1301. }
  1302. }
  1303. }
  1304. break;
  1305. case EVENT_MOD_CUSTOMERAWARE_BEGIN:
  1306. {
  1307. m_bCustomerwareBegin = true;
  1308. if (/*m_bIsPadType&&*/!m_bStartCamera&&!m_bExternControlCam)
  1309. {
  1310. // comment by ly@2019/03/19
  1311. //if ((ePadtype == m_eDeviceType)||(eMobilePadType == m_eDeviceType)||(eDesk2SType == m_eDeviceType))
  1312. //{
  1313. // TryStartCamera();
  1314. //}
  1315. //else
  1316. {
  1317. StartCameraAndTiggerRecord(pszMessage);
  1318. }
  1319. }
  1320. }
  1321. break;
  1322. case EVENT_MOD_CUSTOMERAWARE_END:
  1323. {
  1324. m_bCustomerwareBegin = false;
  1325. if (/*m_bIsPadType&&*/m_bStartCamera&&!m_bExternControlCam)
  1326. {
  1327. Dbg("stop camera");
  1328. if (m_capture)
  1329. {
  1330. LogEvent(Severity_Middle, EVENT_MOD_END_RECORD,pszMessage);
  1331. GetFunction()->KillTimer(1);
  1332. capture_stop(m_capture);
  1333. capture_destroy(m_capture);
  1334. m_capture = NULL;
  1335. }
  1336. m_bStartCamera = FALSE;
  1337. }
  1338. }
  1339. break;
  1340. case EVENT_USB_CAMER_INPUT: // add by ly at 20160329
  1341. {
  1342. Dbg("[dbg] usbcam %s inserted.", pszMessage);
  1343. //huchen add for support usb inout,camera config AutoCorrect
  1344. if (m_bCustomerwareBegin){
  1345. if (/*m_bIsPadType&&*/!m_bStartCamera&&!m_bExternControlCam) {
  1346. CSimpleStringA strSessionId;
  1347. CSmartPointer<IEntityFunction> Func = GetFunction();
  1348. Func->GetSysVar("SessionID", strSessionId);
  1349. StartCameraAndTiggerRecord((LPCTSTR)strSessionId);
  1350. }
  1351. }
  1352. // comment by ly@2019/03/19
  1353. //::Sleep(2000); // 延迟2s后判断
  1354. //// 如果不是广角摄像头 edit by ly at 20161216
  1355. //if(!strstr((LPCTSTR)strEwsCam,pszMessage))
  1356. //{
  1357. // if (strUSBCam.GetLength() <= 1)
  1358. // {
  1359. // strUSBCam = pszMessage;
  1360. // // 对低柜双屏版屏蔽外接摄像头插入事件 edit by ly@2018/10
  1361. // if (eDesk2SType != m_eDeviceType)
  1362. // {
  1363. // // 广播给业务系统
  1364. // ExternalCameraInserted evt;
  1365. // evt.camname = CSimpleStringA2W(strUSBCam);
  1366. // SpSendBroadcast(GetFunction(), SP_MSG_OF(ExternalCameraInserted), SP_MSG_SIG_OF(ExternalCameraInserted), evt);
  1367. // Dbg("[dbg] ExternalCameraInserted broadcast sent!");
  1368. // }
  1369. // /// add by ly at 20161017
  1370. // /// notify to rvcweb that outer camera is switching
  1371. // SetCameraSysVar(CAMERA_START_ING);
  1372. // ExternalCameraStateChanged evt1;
  1373. // evt1.statemsg = CSimpleStringA2W("外接摄像头切换中,请稍等……");
  1374. // evt1.camname = CSimpleStringA2W(strUSBCam);
  1375. // SpSendBroadcast(GetFunction(), SP_MSG_OF(ExternalCameraStateChanged), SP_MSG_SIG_OF(ExternalCameraStateChanged), evt1);
  1376. // Dbg("[dbg] ExternalCameraStateChanged broadcast sent!");
  1377. // TryStartCamera();
  1378. // }
  1379. // else
  1380. // {
  1381. // Dbg("[dbg] more than one USBCam inserted!");
  1382. // }
  1383. //}
  1384. }
  1385. break;
  1386. case EVENT_USB_CAMER_OUTPUT: // add by ly at 20160329
  1387. {
  1388. Dbg("[dbg] usb cam %s removed.", pszMessage);
  1389. int nEnv = capture_get_video_device_id((LPCTSTR)conf.strVideoEnv);
  1390. // comment by ly@2019/03/19
  1391. //if(strstr((LPCTSTR)conf.strVideoEnv,pszMessage))
  1392. if(nEnv<0)
  1393. {
  1394. // 对低柜双屏版屏蔽外接摄像头拔出事件 edit by ly@2018/10
  1395. if (eDesk2SType != m_eDeviceType)
  1396. {
  1397. // 广播给业务系统
  1398. ExternalCameraRemoved evt;
  1399. // comment by ly@2019/03/19
  1400. //evt.camname = CSimpleStringA2W(strUSBCam);
  1401. evt.camname = CSimpleStringA2W(pszMessage);
  1402. SpSendBroadcast(GetFunction(), SP_MSG_OF(ExternalCameraRemoved), SP_MSG_SIG_OF(ExternalCameraRemoved), evt);
  1403. Dbg("[dbg] ExternalCameraRemoved broadcast sent!");
  1404. }
  1405. // comment by ly@2019/03/19
  1406. //// add by ly at 20161110
  1407. //// notify to rvcweb that inner camera is switching
  1408. //SetCameraSysVar(CAMERA_START_ING);
  1409. //ExternalCameraStateChanged evt1;
  1410. //evt1.statemsg = CSimpleStringA2W("内置摄像头启动中,请稍等……");
  1411. //evt1.camname = CSimpleStringA2W(strEnvCam);
  1412. //SpSendBroadcast(GetFunction(), SP_MSG_OF(ExternalCameraStateChanged), SP_MSG_SIG_OF(ExternalCameraStateChanged), evt1);
  1413. //Dbg("[dbg] ExternalCameraStateChanged broadcast sent!");
  1414. //
  1415. //::Sleep(1000); // 延迟1s后切换内置
  1416. //// 如果当前正在使用外接摄像头,则停用之
  1417. //Dbg("[dbg] stop external camera.");
  1418. //StopUSBCamera();
  1419. // 停止摄像头 add by ly@2019/03/19
  1420. if (m_bStartCamera&&!m_bExternControlCam)
  1421. {
  1422. Dbg("stop camera");
  1423. if (m_capture)
  1424. {
  1425. LogEvent(Severity_Middle, EVENT_MOD_END_RECORD,pszMessage);
  1426. GetFunction()->KillTimer(1);
  1427. capture_stop(m_capture);
  1428. capture_destroy(m_capture);
  1429. m_capture = NULL;
  1430. }
  1431. m_bStartCamera = FALSE;
  1432. }
  1433. }
  1434. else
  1435. {
  1436. Dbg("[dbg] USBCam(%s) is not the one used now!",pszMessage);
  1437. }
  1438. //strUSBCam = "$";
  1439. }
  1440. break;
  1441. case EVENT_USB_CAMERA_NOT_ONLY: // add by ly at 20160707
  1442. {
  1443. Dbg("[dbg] more than one usb cam detected.");
  1444. OnExternalCameraSwitchFailed(SwitchFailed_NoUnique);
  1445. }
  1446. break;
  1447. case LOG_EVT_RECORDFAILED: // add by ly at 20160713(edit by ly@2018/06/08)
  1448. {
  1449. Dbg("[dbg] record failed event.");
  1450. //GetFunction()->KillTimer(1);
  1451. //if (m_bIsPadType)
  1452. //{
  1453. // LogEvent(Severity_Middle, LOG_EVT_UI_STOPRECORD, NULL);
  1454. // m_nCameraErrorCode = Error_EnvCamera;
  1455. // ChangeSysvar(m_nCameraErrorCode);
  1456. // //重启ENV摄像头
  1457. // if((m_nCameraErrorCode == Error_EnvCamera)&&(m_nEnvCameraRestartNum<CAMERA_RESTARTNUM))
  1458. // {
  1459. // Dbg("[dbg] Restart EnvCamera as Error_EnvCamera.");
  1460. // if (ReStartCamera(ENVCAMERA) != Error_Succeed)
  1461. // {
  1462. // m_nEnvCameraRestartNum++;
  1463. // }
  1464. // else
  1465. // {
  1466. // m_nEnvCameraRestartNum = 0;
  1467. // m_nCameraErrorCode = Error_Succeed;
  1468. // ChangeSysvar(m_nCameraErrorCode);
  1469. // m_iEnvEmptyTimes = 0;
  1470. // }
  1471. // }
  1472. //}
  1473. //else
  1474. //{
  1475. // LogEvent(Severity_Middle, EVENT_MOD_END_RECORD,NULL);
  1476. // //重启ENV摄像头
  1477. // if(m_nEnvCameraRestartNum<CAMERA_RESTARTNUM)
  1478. // {
  1479. // if (ReStartCamera(ENVCAMERA) != Error_Succeed)
  1480. // {
  1481. // m_nEnvCameraRestartNum++;
  1482. // m_nCameraErrorCode = Error_EnvCamera;
  1483. // ChangeSysvar(m_nCameraErrorCode);
  1484. // }
  1485. // else
  1486. // {
  1487. // m_nEnvCameraRestartNum = 0;
  1488. // m_nCameraErrorCode = Error_Succeed;
  1489. // ChangeSysvar(m_nCameraErrorCode);
  1490. // m_iEnvEmptyTimes = 0;
  1491. // }
  1492. // }
  1493. // //重启OPT摄像头
  1494. // if(m_nEnvCameraRestartNum<CAMERA_RESTARTNUM)
  1495. // {
  1496. // if (ReStartCamera(OPTCAMERA) != Error_Succeed)
  1497. // {
  1498. // m_nEnvCameraRestartNum++;
  1499. // m_nCameraErrorCode = Error_OptCamera;
  1500. // ChangeSysvar(m_nCameraErrorCode);
  1501. // }
  1502. // else
  1503. // {
  1504. // m_nEnvCameraRestartNum = 0;
  1505. // m_nCameraErrorCode = Error_Succeed;
  1506. // ChangeSysvar(m_nCameraErrorCode);
  1507. // m_iEnvEmptyTimes = 0;
  1508. // }
  1509. // }
  1510. //}
  1511. //GetFunction()->SetTimer(1, this, 5000);
  1512. GetFunction()->KillTimer(1);
  1513. //edit by ly @2018/01/17
  1514. LogEvent(Severity_Middle, EVENT_MOD_END_RECORD, NULL);
  1515. char FaildFlag = pszMessage[0];
  1516. if (FaildFlag == '0')
  1517. {
  1518. GetFunction()->SetTimer(1, this, 5000);
  1519. OnExternalCameraSwitchFailed("本地录音录像失败,已停止!");
  1520. }
  1521. else //if (FaildFlag == '1')
  1522. {
  1523. OnExternalCameraSwitchFailed("本地录音录像设备故障,尝试恢复中(预计10s内),请稍等");
  1524. m_nCameraErrorCode = Error_AllCamera;
  1525. RealSelfCheck(); // 录音录像失败,强行kill实体
  1526. }
  1527. }
  1528. break;
  1529. case LOG_EVT_UI_RECORDFAILED: // add by ly@2018/06/08
  1530. {
  1531. Dbg("[dbg] sales record failed event.");
  1532. GetFunction()->KillTimer(1);
  1533. if (m_bIsRemoteRecord){
  1534. LogEvent(Severity_Middle, LOG_EVT_UI_STOPREMOTERECORD, NULL);
  1535. }
  1536. else{
  1537. LogEvent(Severity_Middle, LOG_EVT_UI_STOPRECORD, NULL);
  1538. }
  1539. char FaildFlag = pszMessage[0];
  1540. if (FaildFlag == '0')
  1541. {
  1542. GetFunction()->SetTimer(1, this, 5000);
  1543. OnExternalCameraSwitchFailed("现场销售录音录像失败,已停止!");
  1544. }
  1545. else //if (FaildFlag == '1')
  1546. {
  1547. OnExternalCameraSwitchFailed("现场销售录音录像设备故障,尝试恢复中(预计10s内),请稍等");
  1548. m_nCameraErrorCode = Error_AllCamera;
  1549. RealSelfCheck(); // 录音录像失败,强行kill实体
  1550. }
  1551. }
  1552. break;
  1553. case LOG_EVT_BEGIN_CAMERA_CONFIG:
  1554. {
  1555. ExternStopCamera();
  1556. }
  1557. break;
  1558. case LOG_EVT_END_CAMERA_CONFIG:
  1559. {
  1560. ExternStartCamera();
  1561. }
  1562. break;
  1563. case LOG_EVT_UI_STARTREMOTERECORD:
  1564. {
  1565. m_bIsRemoteRecord = true;
  1566. HandleRemoteRecord(pszMessage);
  1567. }
  1568. break;
  1569. case LOG_EVT_UI_STOPREMOTERECORD:
  1570. {
  1571. m_bIsRemoteRecord = false;
  1572. if (Error_Succeed == StopSalesRecordAudioCapture()){
  1573. Dbg("stop remote sales record audio capture.");
  1574. }
  1575. if (true == m_bHasStartSpeakerRender){
  1576. StopSpeakerAudioRender();
  1577. }
  1578. }
  1579. break;
  1580. //case EVENT_MOD_CONNECT_STOP_RECORD_BROADCAST:
  1581. // {
  1582. // if (eStand2sType == m_eDeviceType){
  1583. // StopSpeakerAudioRender();
  1584. // }
  1585. // }
  1586. // break;
  1587. case LOG_EVT_UI_STARTRECORD:
  1588. case LOG_EVT_UI_STARTRECORDPREVIEW:
  1589. {
  1590. m_bIsRemoteRecord = false;
  1591. if (false == m_bRecordPCM){
  1592. if (Error_Succeed == StartSalesRecordAudioCapture()){
  1593. Dbg("begin remote sales record audio capture.");
  1594. }
  1595. }
  1596. else{
  1597. HandleSalesRecordPCMAudio(false, pszMessage);
  1598. }
  1599. }
  1600. break;
  1601. case LOG_EVT_UI_STOPRECORD:
  1602. {
  1603. if (Error_Succeed == StopSalesRecordAudioCapture()){
  1604. Dbg("stop sales record audio capture.");
  1605. }
  1606. }
  1607. break;
  1608. case LOG_EVT_START_CONTINURECORD:
  1609. {
  1610. Dbg("receive LOG_EVT_START_CONTINURECORD event.");
  1611. }
  1612. break;
  1613. case LOG_EVT_STOP_CONTINURECORD:
  1614. {
  1615. Dbg("receive LOG_EVT_STOP_CONTINURECORD event.");
  1616. }
  1617. break;
  1618. default:
  1619. Dbg("unknown event.");
  1620. break;
  1621. }
  1622. }
  1623. virtual void OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
  1624. {
  1625. if (Test_ShakeHand == eTestType)
  1626. {
  1627. if (m_nCameraErrorCode == Error_AllCamera)
  1628. {
  1629. pTransactionContext->SendAnswer(Error_DevMedia);
  1630. }
  1631. else
  1632. {
  1633. pTransactionContext->SendAnswer(Error_Succeed);
  1634. }
  1635. }
  1636. }
  1637. //获取当前使用摄像头,30分钟轮休一次
  1638. int GetActiveCamera()
  1639. {
  1640. SYSTEMTIME st;
  1641. GetLocalTime(&st);
  1642. if (st.wMinute<=CAMERA_CHANGE_TIMER)
  1643. {
  1644. return ENVCAMERA;
  1645. }
  1646. else if (st.wMinute>CAMERA_CHANGE_TIMER)
  1647. {
  1648. return OPTCAMERA;
  1649. }
  1650. }
  1651. ErrorCodeEnum ChangeSysvar(ErrorCodeEnum op)
  1652. {
  1653. switch (op)
  1654. {
  1655. case Error_Succeed:
  1656. Dbg("Camera State to No_Error");
  1657. //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_NO_ERROR);
  1658. SetCameraSysVar(CAMERA_NO_ERROR);
  1659. GetFunction()->SetUserDefineState(USER_MEDIA_IDLE);
  1660. break;
  1661. case Error_EnvCamera:
  1662. Dbg("Camera State to Env_Error");
  1663. //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_ENV_ERROR);
  1664. SetCameraSysVar(CAMERA_ENV_ERROR);
  1665. GetFunction()->SetUserDefineState(USER_MEDIA_ENVERRROR);
  1666. capture_clearsnapshotvideo(m_capture,ENVCAMERA);
  1667. break;
  1668. case Error_OptCamera:
  1669. Dbg("Camera State to Opt_Error");
  1670. //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_OPT_ERROR);
  1671. SetCameraSysVar(CAMERA_OPT_ERROR);
  1672. GetFunction()->SetUserDefineState(USER_MEDIA_OPTERROR);
  1673. capture_clearsnapshotvideo(m_capture,OPTCAMERA);
  1674. break;
  1675. case Error_AllCamera:
  1676. Dbg("Camera State to Both_Error");
  1677. //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_BOTH_ERROR);
  1678. SetCameraSysVar(CAMERA_BOTH_ERROR);
  1679. GetFunction()->SetUserDefineState(USER_MEDIA_ALLERROR);
  1680. capture_clearsnapshotvideo(m_capture,AlLCAMERA);
  1681. break;
  1682. default:
  1683. break;
  1684. }
  1685. return Error_Succeed;
  1686. }
  1687. void AutoCorrectCameraConfigName(long wait_time) {
  1688. ErrorCodeEnum Error = Error_Succeed;
  1689. int one_timeout = 400;
  1690. int retry = 0;
  1691. //检查配置名都成功,不用自动纠正
  1692. Error = CheckConfigCameraName(&conf);
  1693. if (Error == Error_Succeed){
  1694. return;
  1695. }
  1696. //只针对低柜双屏做自纠正
  1697. if(eDesk2SType != m_eDeviceType){
  1698. Dbg("AutoCorrectCameraConfig failed, DeviceType:%d is not Desk2SType", m_eDeviceType);
  1699. return;
  1700. }
  1701. auto pCameraConfigManageClient = new CameraConfigManageService_ClientBase(this);
  1702. while ((pCameraConfigManageClient->Connect() != Error_Succeed) && retry < wait_time/one_timeout)
  1703. {
  1704. Dbg("连接CameraConfigManage实体失败, retry:%d", retry);
  1705. Sleep(one_timeout);
  1706. retry++;
  1707. }
  1708. //连接不上,不纠正
  1709. if (retry >= wait_time/one_timeout){
  1710. pCameraConfigManageClient->SafeDelete();
  1711. pCameraConfigManageClient = NULL;
  1712. }
  1713. else {
  1714. CameraConfigManageService_AutoCorrectCameraConfig_Req req;
  1715. CameraConfigManageService_AutoCorrectCameraConfig_Ans ans;
  1716. DWORD Timeout = 5000;
  1717. Error = pCameraConfigManageClient->AutoCorrectCameraConfig(req, ans, Timeout);
  1718. if (Error != Error_Succeed)
  1719. {
  1720. Dbg("CameraConfigManage 调用 AutoCorrectCameraConfig 失败: 0x%x", Error);
  1721. }
  1722. else
  1723. {
  1724. Dbg("AutoCorrectCameraConfig, old EnvCamera;%s, OptCamera;%s, EwsCamera;%s",
  1725. (LPCSTR)conf.strVideoEnv, (LPCSTR)conf.strVideoOpt, (LPCSTR)strEwsCam);
  1726. Dbg("AutoCorrectCameraConfig, get new EnvCamera;%s, OptCamera;%s, EwsCamera;%s",
  1727. (LPCSTR)ans.EnvCamera, (LPCSTR)ans.OptCamera, (LPCSTR)ans.EwsCamera);
  1728. if ((ans.EnvCamera.GetLength() > 1) && (conf.strVideoEnv.GetLength() > 1)){
  1729. conf.strVideoEnv = ans.EnvCamera;
  1730. }
  1731. if ((ans.OptCamera.GetLength() > 1) && (conf.strVideoOpt.GetLength() > 1)){
  1732. conf.strVideoOpt = ans.OptCamera;
  1733. }
  1734. if ((ans.EwsCamera.GetLength() > 1) && (strEwsCam.GetLength() > 1)){
  1735. strEwsCam = ans.EwsCamera;
  1736. }
  1737. Dbg("AutoCorrectCameraConfig, updated EnvCamera;%s, OptCamera;%s, EwsCamera;%s",
  1738. (LPCSTR)conf.strVideoEnv, (LPCSTR)conf.strVideoOpt, (LPCSTR)strEwsCam);
  1739. }
  1740. pCameraConfigManageClient->GetFunction()->CloseSession();
  1741. pCameraConfigManageClient->SafeDelete();
  1742. pCameraConfigManageClient = NULL;
  1743. }
  1744. }
  1745. //开始销售双录音频采集函数
  1746. ErrorCodeEnum StartSalesRecordAudioCapture(bool bRemoteRecord = false, eRvcPCMTransType eType = eUnKnown, void* pData = NULL)
  1747. {
  1748. ErrorCodeEnum Error = Error_Succeed;
  1749. if (NULL == m_salesaudio_capture){
  1750. memset(&m_sales_audio_conf, 0, sizeof(m_sales_audio_conf));
  1751. GetSalesAudioConfig(&m_sales_audio_conf, bRemoteRecord);
  1752. Error = (ErrorCodeEnum)salesaudio_capture_create(&m_sales_audio_conf, &m_salesaudio_capture);
  1753. if (Error_Succeed == Error){
  1754. Error = SetSalesRecordAudioCaptureTransActionData(eType, pData);
  1755. }
  1756. }
  1757. if (Error_Succeed == Error){
  1758. Error = salesrecord_audio_capture_start(m_salesaudio_capture);
  1759. if (Error_Succeed == Error){
  1760. Dbg("sales record audio capture start success.");
  1761. }
  1762. else{
  1763. Dbg("sales record audio capture start failed for param error.");
  1764. }
  1765. }
  1766. return Error;
  1767. }
  1768. //停止销售双录音频采集函数
  1769. ErrorCodeEnum StopSalesRecordAudioCapture()
  1770. {
  1771. salesrecord_audio_capture_stop(m_salesaudio_capture);
  1772. salesaudio_capture_destroy(m_salesaudio_capture);
  1773. m_salesaudio_capture = NULL;
  1774. Dbg("set m_salesaudio_capture to null.");
  1775. return Error_Succeed;
  1776. }
  1777. ErrorCodeEnum StartCamera()
  1778. {
  1779. if (m_capture == NULL)
  1780. {
  1781. //打开前检查配置摄像头名字是否能被打开并自纠正
  1782. AutoCorrectCameraConfigName(4000);
  1783. ErrorCodeEnum Error = Error_Succeed;
  1784. conf.ref_env_capture_count = &m_lCaptureEnvCount;
  1785. conf.ref_opt_capture_count = &m_lCaptureOptCount;
  1786. conf.ref_envopt_capture_count = &m_lCaptureEnvOptCount;
  1787. Error = (ErrorCodeEnum)capture_create(&conf, &m_capture);
  1788. if (Error == Error_Succeed)
  1789. {
  1790. Error = capture_start(m_capture);
  1791. Dbg("capture_start Error code=0x%x",Error);
  1792. if (Error != Error_Succeed)
  1793. {
  1794. if((Error == Error_AudioIN)||(Error == Error_AudioOut))
  1795. {
  1796. return Error;
  1797. }
  1798. else if (Error == Error_AllCamera)
  1799. {
  1800. capture_destroy(m_capture);
  1801. m_capture = NULL;
  1802. return Error;
  1803. }
  1804. else
  1805. {
  1806. SetAutoBright(Error);
  1807. GetFunction()->SetTimer(1, this, 5000);
  1808. if((Error == Error_OptCamera)&&((ePadtype == m_eDeviceType)||(eMobilePadType == m_eDeviceType)||(eDesk2SType == m_eDeviceType)||(eDesk1SType == m_eDeviceType)||(eDesk2SIntegratedType == m_eDeviceType)))
  1809. {
  1810. return Error_Succeed;
  1811. }
  1812. else
  1813. {
  1814. return Error;
  1815. }
  1816. }
  1817. }
  1818. else
  1819. {
  1820. SetAutoBright(Error);
  1821. GetFunction()->SetTimer(1, this, 5000);
  1822. return Error_Succeed;
  1823. }
  1824. }
  1825. else
  1826. {
  1827. Dbg("create capture failed! %d", Error);
  1828. m_capture = NULL;
  1829. return Error_Unexpect;
  1830. }
  1831. return Error;
  1832. }
  1833. else
  1834. {
  1835. Dbg("m_capture == NULL");
  1836. return Error_Unexpect;
  1837. }
  1838. }
  1839. ErrorCodeEnum StartCamera(int nCamera)
  1840. {
  1841. if (m_capture == NULL)
  1842. {
  1843. //打开前检查配置摄像头名字是否能被打开并自纠正
  1844. AutoCorrectCameraConfigName(4000);
  1845. ErrorCodeEnum Error = Error_Succeed;
  1846. Error = capture_create(&conf, m_capture,nCamera);
  1847. if (Error == Error_Succeed)
  1848. {
  1849. return capture_start(m_capture,nCamera);
  1850. }
  1851. else
  1852. {
  1853. return Error_Hardware;
  1854. }
  1855. }
  1856. else
  1857. {
  1858. return Error_Unexpect;
  1859. }
  1860. }
  1861. void StartCameraAndTiggerRecord(const char * strSessionId){
  1862. Dbg("start camera");
  1863. ErrorCodeEnum Error;
  1864. Error = StartCamera();
  1865. if (Error == Error_Succeed)
  1866. {
  1867. //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_NO_ERROR);
  1868. SetCameraSysVar(CAMERA_NO_ERROR);
  1869. Dbg("Camera State to CAMERA_NO_ERROR");
  1870. m_bStartCamera = TRUE;
  1871. LogEvent(Severity_Middle, EVENT_MOD_BEGIN_RECORD,strSessionId);
  1872. }
  1873. else
  1874. {
  1875. if (Error == Error_EnvCamera)
  1876. {
  1877. //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_ENV_ERROR);
  1878. SetCameraSysVar(CAMERA_ENV_ERROR);
  1879. Dbg("Camera State to CAMERA_ENV_ERROR");
  1880. m_bStartCamera = TRUE;
  1881. LogEvent(Severity_Middle, EVENT_MOD_BEGIN_RECORD,strSessionId);
  1882. }
  1883. else if (Error == Error_OptCamera)
  1884. {
  1885. //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_OPT_ERROR);
  1886. SetCameraSysVar(CAMERA_OPT_ERROR);
  1887. Dbg("Camera State to CAMERA_OPT_ERROR");
  1888. m_bStartCamera = TRUE;
  1889. LogEvent(Severity_Middle, EVENT_MOD_BEGIN_RECORD,strSessionId);
  1890. }
  1891. else if (Error == Error_AllCamera)
  1892. {
  1893. //GetFunction()->SetSysVar(SYSVAR_CAMERASTATE, CAMERA_BOTH_ERROR);
  1894. SetCameraSysVar(CAMERA_BOTH_ERROR);
  1895. Dbg("Camera State to CAMERA_BOTH_ERROR");
  1896. m_nCameraErrorCode = Error_AllCamera;
  1897. m_bStartCamera = FALSE;
  1898. GetFunction()->SetUserDefineState(USER_MEDIA_ALLERROR);
  1899. }
  1900. else
  1901. {
  1902. SetCameraSysVar(Error);
  1903. Dbg("Camera State to Other Error");
  1904. m_nCameraErrorCode = Error;
  1905. m_bStartCamera = FALSE;
  1906. }
  1907. }
  1908. }
  1909. ErrorCodeEnum ReStartCamera(int nCamera)
  1910. {
  1911. if (m_capture != NULL)
  1912. {
  1913. if((StopCamera(m_capture,nCamera)==-1))
  1914. {
  1915. Dbg("ReStartCamera,stop camera fail!");
  1916. }
  1917. Sleep(2000);
  1918. //打开前检查配置摄像头名字是否能被打开并自纠正
  1919. AutoCorrectCameraConfigName(4000);
  1920. ErrorCodeEnum Error = Error_Succeed;
  1921. Error = capture_create(&conf, m_capture,nCamera);
  1922. if (Error == Error_Succeed)
  1923. {
  1924. Error = capture_start(m_capture,nCamera);
  1925. if (Error != Error_Succeed)
  1926. {
  1927. Dbg("ReStartCamera,capture_start fail!");
  1928. capture_destroy(m_capture,nCamera);
  1929. return Error;
  1930. }
  1931. else
  1932. {
  1933. Dbg("ReStartCamera,camera = %d,success!",nCamera);
  1934. return Error_Succeed;
  1935. }
  1936. }
  1937. else
  1938. {
  1939. Dbg("ReStartCamera,capture_create fail!");
  1940. capture_destroy(m_capture,nCamera);
  1941. return Error;
  1942. }
  1943. }
  1944. else
  1945. {
  1946. return Error_Unexpect;
  1947. }
  1948. }
  1949. virtual CServerSessionBase *OnNewSession(const char* pszRemoteEntityName, const char * pszClass)
  1950. {
  1951. LOG_FUNCTION();
  1952. LOG_TRACE("%s connected class = %s!", pszRemoteEntityName, pszClass);
  1953. return new MediaServiceSession(this);
  1954. }
  1955. public:
  1956. ErrorCodeEnum ExternStartCamera()
  1957. {
  1958. Dbg("Extern start camera");
  1959. CSimpleStringA strSessionId;
  1960. CSmartPointer<IEntityFunction> Func = GetFunction();
  1961. Func->GetSysVar("SessionID", strSessionId);
  1962. if (!m_bStartCamera)
  1963. {
  1964. StartCameraAndTiggerRecord((LPCTSTR)strSessionId);
  1965. }
  1966. m_bExternControlCam = FALSE;
  1967. return Error_Succeed;
  1968. }
  1969. ErrorCodeEnum ExternStopCamera()
  1970. {
  1971. Dbg("Extern stop camera");
  1972. if (m_capture)
  1973. {
  1974. LogEvent(Severity_Middle, EVENT_MOD_END_RECORD,NULL);
  1975. GetFunction()->KillTimer(1);
  1976. capture_stop(m_capture);
  1977. capture_destroy(m_capture);
  1978. m_capture = NULL;
  1979. }
  1980. m_bStartCamera = FALSE;
  1981. m_bExternControlCam = TRUE;
  1982. return Error_Succeed;
  1983. }
  1984. //add by ly at 20160401
  1985. ErrorCodeEnum SaveInnerCamera()
  1986. {
  1987. if (strFrontCam.GetLength() <= 1) {
  1988. return Error_Resource;
  1989. }
  1990. if (strstr((LPCTSTR)conf.strVideoEnv,(LPCTSTR)strFrontCam)==NULL)
  1991. {
  1992. CSimpleStringA tmp = strRearCam;
  1993. strRearCam = strFrontCam;
  1994. strFrontCam = tmp;
  1995. }
  1996. Dbg("[dbg] strFrontCam: %s, strRearCam: %s", (LPCSTR)strFrontCam, (LPCSTR)strRearCam);
  1997. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  1998. CSmartPointer<IConfigInfo> spConfig;
  1999. ErrorCodeEnum Error = spFunction->OpenConfig(Config_Run, spConfig);
  2000. if (Error == Error_Succeed) {
  2001. SpIniMappingTable table;
  2002. table.AddEntryString("Video", "FrontCamera", strFrontCam, "$");
  2003. table.AddEntryString("Video", "RearCamera", strRearCam, "$");
  2004. Error = table.Save(spConfig);
  2005. if (Error != Error_Succeed)
  2006. {
  2007. LOG_TRACE("[dbg] failed to save run config.");
  2008. }
  2009. }
  2010. else {
  2011. LOG_TRACE("[dbg] failed to open run config.");
  2012. }
  2013. return Error;
  2014. }
  2015. // 获取高拍仪摄像头(考虑多个高拍仪)
  2016. ErrorCodeEnum GetHSPCameras(CAutoArray<CSimpleStringA> &HSPCameras)
  2017. {
  2018. enum CapTypeEnum {
  2019. CAMTYPE_UNKNOWN = 0,
  2020. CAMTYPE_ENV,
  2021. CAMTYPE_OPT,
  2022. CAMTYPE_EWS,
  2023. CAMTYPE_HSPS,
  2024. CAMTYPE_CIRCLE,
  2025. CAMTYPE_MAX
  2026. };
  2027. auto rc = Error_Succeed;
  2028. auto pScannerSetClient = new ScannerService_ClientBase(this);
  2029. if (pScannerSetClient->Connect() != Error_Succeed)
  2030. {
  2031. Dbg("连接ScannerSet实体失败");
  2032. pScannerSetClient->SafeDelete();
  2033. pScannerSetClient = NULL;
  2034. rc = Error_DevConnFailed;
  2035. }
  2036. else
  2037. {
  2038. ScannerService_GetOnlineCameras_Req req = {};
  2039. ScannerService_GetOnlineCameras_Ans ans = {};
  2040. rc = pScannerSetClient->GetOnlineCameras(req, ans, 10000);
  2041. if (rc != Error_Succeed)
  2042. {
  2043. Dbg("ScannerSet 调用 GetOnlineCameras 失败: 0x%x", rc);
  2044. }
  2045. else
  2046. {
  2047. Dbg("ScannerSet invokes GetOnlineCameras suc.");
  2048. Dbg("Count: %d", ans.devCount);
  2049. if (ans.devCount > 0) {
  2050. for (int i = 0; i < ans.devFriendlyNames.GetCount(); ++i) {
  2051. Dbg("[%d]%s(%d)", i, (LPCTSTR)ans.devFriendlyNames[i],
  2052. ans.devType[i]);
  2053. CapTypeEnum devType = (CapTypeEnum)ans.devType[i];
  2054. if (devType == CAMTYPE_HSPS)
  2055. {
  2056. HSPCameras.Append(ans.devFriendlyNames, i, 1);
  2057. }
  2058. }
  2059. }
  2060. }
  2061. pScannerSetClient->GetFunction()->CloseSession();
  2062. pScannerSetClient->SafeDelete();
  2063. pScannerSetClient = NULL;
  2064. }
  2065. return rc;
  2066. }
  2067. ErrorCodeEnum HandleSalesRecordPCMAudio(bool bRemoteRecord, const char *pszMessage, audio_frame* pFrame = NULL)
  2068. {
  2069. ErrorCodeEnum Error = Error_Succeed;
  2070. char strSwiftName[MAX_PATH] = {0};
  2071. if (NULL != pszMessage){
  2072. size_t ulen = strlen(pszMessage);
  2073. char *tmp = new char[ulen+1];
  2074. strncpy_s(tmp, ulen+1, pszMessage, ulen);
  2075. char *result[16] = {0};
  2076. auto arr1 = CSimpleStringA2W(tmp).Split('@');
  2077. auto arr2 = CAutoArray<CSimpleStringA>(arr1.GetCount());
  2078. for (int i = 0; i < arr1.GetCount(); ++i){
  2079. arr2[i] = CSimpleStringW2A(arr1[i]);
  2080. result[i] = const_cast<LPSTR>(arr2[i].GetData());
  2081. }
  2082. if (arr1.GetCount() > 4){
  2083. Dbg("remote record swift number is %s.", result[4]);
  2084. sprintf(strSwiftName, "%s", result[4]);
  2085. }
  2086. delete tmp;
  2087. tmp = NULL;
  2088. }
  2089. char strMicroName[MAX_PATH] = {0};
  2090. CSimpleStringA strTempDir;
  2091. if (Error_Succeed == GetFunction()->GetPath("Temp", strTempDir)){
  2092. sprintf_s(strMicroName, MAX_PATH, "%s\\local_micro_%s.pcm", strTempDir.GetData(), strSwiftName);
  2093. }
  2094. else{
  2095. sprintf_s(strMicroName, MAX_PATH, "local_micro_%s.pcm", strSwiftName);
  2096. }
  2097. FILE *pRecord = fopen(strMicroName, "wb+");
  2098. if (NULL != pRecord){
  2099. if (Error_Succeed == StartSalesRecordAudioCapture(bRemoteRecord, eSingleWriteLocal, pRecord)){
  2100. Dbg("begin remote sales record audio capture and record local PCM.");
  2101. }
  2102. }
  2103. else{
  2104. Dbg("fopen %s failed.",strMicroName);
  2105. }
  2106. if (true == bRemoteRecord){
  2107. char strSpeakerName[MAX_PATH] = {0};
  2108. if ("" != strTempDir){
  2109. sprintf_s(strSpeakerName, MAX_PATH, "%s\\remote_speaker_%s.pcm", strTempDir.GetData(), strSwiftName);
  2110. }
  2111. else{
  2112. sprintf_s(strSpeakerName, MAX_PATH, "remote_speaker_%s.pcm", strSwiftName);
  2113. }
  2114. StartSpeakerAudioRender(0, pFrame, strSpeakerName);
  2115. }
  2116. return Error;
  2117. }
  2118. void HandleRemoteRecord(const char *pszMessage)
  2119. {
  2120. audio_frame frame;
  2121. frame.bitspersample = 16;
  2122. frame.format = 1;
  2123. frame.framesize = 320;
  2124. frame.nchannels = 1;
  2125. frame.samplespersec = 8000;
  2126. if (true == m_bRecordPCM){
  2127. HandleSalesRecordPCMAudio(true, pszMessage, &frame);
  2128. }
  2129. else{
  2130. if (Error_Succeed == StartSalesRecordAudioCapture(true)){
  2131. Dbg("begin remote sales record audio capture.");
  2132. }
  2133. StartSpeakerAudioRender(0, &frame, NULL);
  2134. }
  2135. }
  2136. ErrorCodeEnum StartSpeakerAudioRender(int iQueue, audio_frame* pFrame, const char* strName)
  2137. {
  2138. auto rc = Error_Succeed;
  2139. Dbg("start speak audio render.");
  2140. if (NULL != m_pAudioRenderObj){
  2141. if(0 == m_pAudioRenderObj->StartRender(0, pFrame, strName)){
  2142. m_bHasStartSpeakerRender = true;
  2143. Dbg("start speak audio render success.");
  2144. }
  2145. }
  2146. return rc;
  2147. }
  2148. ErrorCodeEnum StopSpeakerAudioRender()
  2149. {
  2150. auto rc = Error_Succeed;
  2151. Dbg("stop speak audio render.");
  2152. if (NULL != m_pAudioRenderObj){
  2153. m_pAudioRenderObj->StopRender();
  2154. m_bHasStartSpeakerRender = false;
  2155. }
  2156. return rc;
  2157. }
  2158. ErrorCodeEnum SetSalesRecordAudioCaptureTransActionData(eRvcPCMTransType eType, void* pData)
  2159. {
  2160. auto rc = Error_Param;
  2161. if (NULL != m_salesaudio_capture){
  2162. if (NULL != m_salesaudio_capture->rvc_audio){
  2163. m_salesaudio_capture->rvc_audio->eType = eType;
  2164. m_salesaudio_capture->rvc_audio->pdata = pData;
  2165. rc = Error_Succeed;
  2166. }
  2167. }
  2168. return rc;
  2169. }
  2170. DeviceTypeEnum m_eDeviceType;
  2171. BOOL m_bStartCamera;
  2172. BOOL m_bExternControlCam;
  2173. capture_config_t conf;
  2174. rvc_audio_capture_config_s m_sales_audio_conf; //销售双录音频配置
  2175. ErrorCodeEnum m_nCameraErrorCode; //摄像头故障码,0:无故障,1:env摄像头故障,2:opt摄像头故障,3:双摄像头故障
  2176. int m_nCurActiveCamera; //当前正在使用的摄像头
  2177. CSimpleStringA strFrontCam;
  2178. CSimpleStringA strRearCam;
  2179. CSimpleStringA strEnvCam; //Env摄像头 add by ly 20160331
  2180. CSimpleStringA strUSBCam; //外接摄像头 add by ly 20160329
  2181. CSimpleStringA strEwsCam; //外部广角摄像头路径名(全程录像用,通常不配置)
  2182. int m_nCameraCount; //当前摄像头数量 add by ly 20160531
  2183. int m_nSysCallType;//0:普通模式,1:p2p模式
  2184. capture_t *m_capture;
  2185. rvc_sales_audio_capture_t *m_salesaudio_capture;
  2186. BOOL m_bCustomerwareBegin;
  2187. bool m_bHasStartSpeakerRender; //add by clp 20200416 是否已开启扬声器音频采集
  2188. private:
  2189. LONG m_lCaptureEnvCount;
  2190. LONG m_lCaptureOptCount;
  2191. LONG m_lCaptureEnvOptCount;
  2192. CAutoArray<CUUID> m_arrListener;
  2193. ChannelMediaControllerClient *m_pMediaControllerChannel;
  2194. SelfChekerClient*m_pSelfcheckClient;
  2195. IAudioRender* m_pAudioRenderObj; //add by clp 20200319 扬声器捕捉实体
  2196. bool m_bRecordPCM; //add by clp 20200401 是否单独录制PCM音频
  2197. int m_nSalesAudioSmpPsec; //add by clp 20200402 销售双录音频采样率
  2198. bool m_bIsRemoteRecord; //add by clp 20200403 是否是远程双录
  2199. };
  2200. SelfChekerClient::SelfChekerClient( CMediaControllerEntity *pEntity ) : SelfCheckerService_ClientBase(pEntity)
  2201. {
  2202. }
  2203. ChannelMediaControllerClient::ChannelMediaControllerClient( CMediaControllerEntity *pEntity ) : ChannelService_ClientBase(pEntity)
  2204. {
  2205. }
  2206. void ChannelMediaControllerClient::OnMessage(ErrorCodeEnum Error, ChannelService_State_Info &Msg, CSmartPointer<IReleasable> pData)
  2207. {
  2208. if (Error == Error_Succeed)
  2209. {
  2210. CMediaControllerEntity *pEntity = static_cast<CMediaControllerEntity*>(m_pEntityBase);
  2211. if (Msg.state == eChannelState_Idle)
  2212. {
  2213. if (pEntity->m_bStartCamera)
  2214. {
  2215. if (pEntity->SetAutoBright(pEntity->m_nCameraErrorCode)==false)
  2216. {
  2217. Dbg("SetAutoBright Fail!");
  2218. }
  2219. }
  2220. }
  2221. else if (Msg.state == eChannelState_Connected)
  2222. {
  2223. if (pEntity->m_bStartCamera)
  2224. {
  2225. pEntity->SendCameraBright();
  2226. }
  2227. }
  2228. }
  2229. }
  2230. void ChannelMediaControllerClient::OnMessage( ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer<IReleasable> pData )
  2231. {
  2232. LOG_FUNCTION();
  2233. if (Error == Error_Succeed)
  2234. {
  2235. CMediaControllerEntity *pEntity = static_cast<CMediaControllerEntity*>(m_pEntityBase);
  2236. pEntity->OnReceivePkt(Msg.sub_type, (const char*)Msg.data.m_pData, Msg.data.m_iLength);
  2237. }
  2238. }
  2239. // edit by ly 20160401
  2240. void MediaServiceSession::Handle_GetVideoDeviceName(SpReqAnsContext<MediaService_GetVideoDeviceName_Req, MediaService_GetVideoDeviceName_Ans>::Pointer ctx)
  2241. {
  2242. CSimpleStringA frontcam = m_pEntity->strFrontCam;
  2243. CSimpleStringA rearcam = m_pEntity->strRearCam;
  2244. if (frontcam.GetLength() > 1 && rearcam.GetLength() > 1)
  2245. {
  2246. ctx->Ans.frontcam = frontcam;
  2247. if (strstr((LPCTSTR)frontcam,";"))
  2248. {
  2249. ctx->Ans.frontcam = frontcam.SubString(0, frontcam.IndexOf(";"));
  2250. }
  2251. ctx->Ans.rearcam = rearcam;
  2252. if (strstr((LPCTSTR)rearcam,";"))
  2253. {
  2254. ctx->Ans.rearcam = rearcam.SubString(0, rearcam.IndexOf(";"));
  2255. }
  2256. Dbg("get camera1 name:%s",m_pEntity->strFrontCam);
  2257. Dbg("get camera2 name:%s",m_pEntity->strRearCam);
  2258. }
  2259. ctx->Answer(Error_Succeed);
  2260. }
  2261. void MediaServiceSession::Handle_StartCamera(SpOnewayCallContext<MediaService_StartCamera_Info>::Pointer ctx)
  2262. {
  2263. m_pEntity->ExternStartCamera();
  2264. }
  2265. void MediaServiceSession::Handle_StopCamera(SpOnewayCallContext<MediaService_StopCamera_Info>::Pointer ctx)
  2266. {
  2267. m_pEntity->ExternStopCamera();
  2268. }
  2269. void MediaServiceSession::Handle_StartEnvCamera(SpReqAnsContext<MediaService_StartEnvCamera_Req, MediaService_StartEnvCamera_Ans>::Pointer ctx)
  2270. {
  2271. LOG_FUNCTION();
  2272. ErrorCodeEnum Error = m_pEntity->StartEnvCamera();
  2273. ctx->Ans.returncod = Error;
  2274. ctx->Answer(Error);
  2275. }
  2276. void MediaServiceSession::Handle_StopEnvCamera(SpOnewayCallContext<MediaService_StopEnvCamera_Info>::Pointer ctx)
  2277. {
  2278. LOG_FUNCTION();
  2279. m_pEntity->StopEnvCamera();
  2280. }
  2281. void MediaServiceSession::Handle_StartSpeakerRender(SpOnewayCallContext<MediaService_StartSpeakerRender_Info>::Pointer ctx)
  2282. {
  2283. LOG_FUNCTION();
  2284. }
  2285. void MediaServiceSession::Handle_StopSpeakerRender(SpOnewayCallContext<MediaService_StopSpeakerRender_Info>::Pointer ctx)
  2286. {
  2287. LOG_FUNCTION();
  2288. if (true == m_pEntity->m_bHasStartSpeakerRender){
  2289. m_pEntity->StopSpeakerAudioRender();
  2290. }
  2291. else{
  2292. Dbg("speaker audio render already stopped.");
  2293. }
  2294. }
  2295. SP_BEGIN_ENTITY_MAP()
  2296. SP_ENTITY(CMediaControllerEntity)
  2297. SP_END_ENTITY_MAP()