mod_snapshot.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. #include "stdafx.h"
  2. #include "SpBase.h"
  3. #include "SpIni.h"
  4. #include "Event.h"
  5. #include "mod_mediacontroller/Event.h"
  6. #include "mod_assistantchannel/AssistantChannel_client_g.h"
  7. using namespace AssistantChannel;
  8. #include "mod_assistantchannel/chan_protocol.h"
  9. #include "../../Other/rvcmediacommon/rvc_media_common.h"
  10. #include "libvideoqueue.h"
  11. #include "libfacecapture.h"
  12. #include "jpeg2k.h"
  13. #include "videoutil.h"
  14. #include "y2k_time.h"
  15. #include "EventCode.h"
  16. #include "CommEntityUtil.hpp"
  17. #include "cv.h"
  18. #include "highgui.h"
  19. #ifdef RVC_OS_WIN
  20. #define ENV_CAP_TIMEOUT 15
  21. #define OPT_CAP_TIMEOUT 10
  22. #else
  23. #define ENV_CAP_TIMEOUT 150
  24. #define OPT_CAP_TIMEOUT 100
  25. #endif
  26. class CPhotoCaptureEntity;
  27. class ChannelClient : public ChannelService_ClientBase
  28. {
  29. public:
  30. ChannelClient(CPhotoCaptureEntity *pEntity);
  31. virtual void OnMessage(ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer<IReleasable> pData);
  32. };
  33. // 旋转180度
  34. int RotationDown(unsigned char* src, int srcW, int srcH, int channel)
  35. {
  36. unsigned char* tempSrc = NULL;
  37. int mSize = srcW * srcH * sizeof(char) * channel;
  38. int i = 0;
  39. int j = 0;
  40. int k = 0;
  41. int desW = 0;
  42. int desH = 0;
  43. desW = srcW;
  44. desH = srcH;
  45. tempSrc = (unsigned char*)malloc(sizeof(char) * srcW * srcH * channel);
  46. memcpy(tempSrc, src, mSize);
  47. for (i = 0; i < desH; i++)
  48. {
  49. for (j = 0; j < desW; j++)
  50. {
  51. for (k = 0; k < channel; k++)
  52. {
  53. //src[(i * desW + j) * channel + k] = tempSrc[((srcH - 1 - i) * srcW + srcW - 1 - j) * channel + k];
  54. src[(i * desW + j) * channel + k] = tempSrc[((srcH - 1 - i) * srcW + j) * channel + k];
  55. }
  56. }
  57. }
  58. free(tempSrc);
  59. return 0;
  60. }
  61. // id: 0x905
  62. class CPhotoCaptureEntity : public CEntityBase, public ITimerListener, public ILogListener
  63. {
  64. public:
  65. CPhotoCaptureEntity() : m_video_env_q(NULL), m_video_opt_q(NULL), m_dwCapture(0), m_bConnectAssist(FALSE) {m_pChannelClient = NULL;}
  66. virtual ~CPhotoCaptureEntity() {}
  67. virtual const char *GetEntityName() const { return "Snapshot"; }
  68. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
  69. {
  70. ErrorCodeEnum Error = __OnStart(Error_Succeed);
  71. pTransactionContext->SendAnswer(Error);
  72. }
  73. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  74. {
  75. ErrorCodeEnum Error = __OnClose(Error_Succeed);
  76. pTransactionContext->SendAnswer(Error);
  77. }
  78. ErrorCodeEnum __OnStart(ErrorCodeEnum preOperationError)
  79. {
  80. if (preOperationError != Error_Succeed) {
  81. return preOperationError;
  82. }
  83. //is Pad Version
  84. m_eDeviceType = RvcGetDeviceType();
  85. if (eMobilePadType == m_eDeviceType || eStand1SPlusType == m_eDeviceType){
  86. m_video_env_q = new Clibvideoqueue(REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE);
  87. }
  88. else { // == 2
  89. m_video_env_q = new Clibvideoqueue(REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE);
  90. m_video_opt_q = new Clibvideoqueue(REC_COMMON_VIDEO_OPT_SHM_SNAPSHOT_QUEUE);
  91. }
  92. CSmartPointer<IEntityFunction> spFunc = GetFunction();
  93. int i = 0;
  94. m_arrListener.Init(4);
  95. spFunc->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, MOD_EVENT_MEDIACONTROLLER_FINISHED_CAPTURE_ENV);
  96. spFunc->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, MOD_EVENT_MEDIACONTROLLER_FINISHED_CAPTURE_OPT);
  97. spFunc->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, MOD_EVENT_MEDIACONTROLLER_FINISHED_CAPTURE_ENVOPT);
  98. spFunc->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_MOD_ASSISCHAN_STARTED_SUCCESS,NULL,false);
  99. return Error_Succeed;
  100. }
  101. void OnStarted()
  102. {
  103. m_pChannelClient = new ChannelClient(this);
  104. if (Error_Succeed == ConnectAssistChannel()) {
  105. m_bConnectAssist = TRUE;
  106. }
  107. }
  108. ErrorCodeEnum __OnClose(ErrorCodeEnum preOperationError)
  109. {
  110. LOG_FUNCTION();
  111. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  112. for (int i = 0; i < m_arrListener.GetCount(); ++i)
  113. {
  114. spFunction->UnsubscribeLog(m_arrListener[i]);
  115. }
  116. if (preOperationError != Error_Succeed)
  117. return preOperationError;
  118. if (m_pChannelClient) {
  119. m_pChannelClient->GetFunction()->CloseSession();
  120. m_pChannelClient = NULL;
  121. }
  122. if (NULL != m_video_env_q) {
  123. delete m_video_env_q;
  124. m_video_env_q = NULL;
  125. }
  126. if (NULL != m_video_opt_q) {
  127. delete m_video_opt_q;
  128. m_video_opt_q = NULL;
  129. }
  130. return Error_Succeed;
  131. }
  132. void WriteStamp(video_frame *srcfrm)
  133. {
  134. #ifdef RVC_OS_WIN
  135. __try {
  136. CImageFrame frm;
  137. frm.data = srcfrm->data[0];
  138. frm.width = srcfrm->width;
  139. frm.height = srcfrm->height;
  140. frm.framesize = srcfrm->width * srcfrm->height * 3;
  141. if (!SnapShot(&frm)) {
  142. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("write stamp failed!");
  143. }
  144. }
  145. __except (EXCEPTION_EXECUTE_HANDLER) {
  146. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("snapshot throw windows exception!");
  147. }
  148. #else
  149. CImageFrame frm;
  150. frm.data = srcfrm->data[0];
  151. frm.width = srcfrm->width;
  152. frm.height = srcfrm->height;
  153. frm.framesize = srcfrm->width * srcfrm->height * 3;
  154. if (!SnapShot(&frm)) {
  155. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("write stamp failed!");
  156. }
  157. #endif
  158. }
  159. void Capture(int rc)
  160. {
  161. video_frame *frm = NULL;
  162. if((rc == 0)||(rc==Error_TimeOut))
  163. {
  164. if (m_video_env_q && m_video_opt_q)
  165. {
  166. int combine_width = REC_COMMON_VIDEO_SNAPSHOT_WIDTH;
  167. int combine_height = REC_COMMON_VIDEO_SNAPSHOT_WIDTH + REC_COMMON_VIDEO_SNAPSHOT_HEIGHT;
  168. frm = video_frame_new(combine_width, combine_height, VIDEO_FORMAT_RGB24);
  169. video_frame_fill_black(frm);
  170. // get env snapshot
  171. {
  172. video_frame tmp_frm = {0};
  173. tmp_frm.data[0] = frm->data[0];
  174. tmp_frm.linesize[0] = frm->linesize[0];
  175. tmp_frm.format = frm->format;
  176. tmp_frm.width = REC_COMMON_VIDEO_SNAPSHOT_WIDTH;
  177. tmp_frm.height = REC_COMMON_VIDEO_SNAPSHOT_HEIGHT;
  178. DWORD time = m_video_env_q->GetLastFrameTime();
  179. y2k_time_t nowtime = y2k_time_now();
  180. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d env now time is %d, get frame time is %d, time interval is %ds.", __FUNCTION__, __LINE__, nowtime, time, nowtime - time);
  181. if ((nowtime - time) < ENV_CAP_TIMEOUT)
  182. {
  183. m_video_env_q->GetVideo2(&tmp_frm, 0);
  184. }
  185. else
  186. {
  187. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("the env snapshot videoqueque image timeout!");
  188. }
  189. }
  190. // get opt snapshot
  191. {
  192. video_frame tmp_frm = {0};
  193. tmp_frm.data[0] = frm->data[0] + frm->linesize[0] * REC_COMMON_VIDEO_SNAPSHOT_HEIGHT+(REC_COMMON_VIDEO_SNAPSHOT_WIDTH-REC_COMMON_VIDEO_SNAPSHOT_HEIGHT)/2*3;
  194. tmp_frm.linesize[0] = frm->linesize[0];
  195. tmp_frm.format = frm->format;
  196. tmp_frm.width = REC_COMMON_VIDEO_SNAPSHOT_HEIGHT;
  197. tmp_frm.height = REC_COMMON_VIDEO_SNAPSHOT_WIDTH;
  198. DWORD time = m_video_opt_q->GetLastFrameTime();
  199. y2k_time_t nowtime = y2k_time_now();
  200. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d opt now time is %d, get frame time is %d, time interval is %ds.", __FUNCTION__, __LINE__, nowtime, time, nowtime - time);
  201. if ((nowtime - time) < OPT_CAP_TIMEOUT)
  202. {
  203. m_video_opt_q->GetVideo2(&tmp_frm, 0);
  204. }
  205. else
  206. {
  207. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("the opt snapshot video queque image timeout!");
  208. }
  209. }
  210. }
  211. else if (m_video_env_q)
  212. {
  213. frm = video_frame_new(REC_COMMON_VIDEO_SNAPSHOT_WIDTH, REC_COMMON_VIDEO_SNAPSHOT_HEIGHT, VIDEO_FORMAT_RGB24);
  214. video_frame_fill_black(frm);
  215. video_frame tmp_frm = {0};
  216. tmp_frm.data[0] = frm->data[0];
  217. tmp_frm.linesize[0] = frm->linesize[0];
  218. tmp_frm.format = frm->format;
  219. tmp_frm.width = REC_COMMON_VIDEO_SNAPSHOT_WIDTH;
  220. tmp_frm.height = REC_COMMON_VIDEO_SNAPSHOT_HEIGHT;
  221. DWORD time = m_video_env_q->GetLastFrameTime();
  222. y2k_time_t nowtime = y2k_time_now();
  223. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s:%d env now time is %d, get frame time is %d, time interval is %ds.", __FUNCTION__, __LINE__, nowtime, time, nowtime - time);
  224. if ((nowtime - time) < ENV_CAP_TIMEOUT)
  225. {
  226. m_video_env_q->GetVideo2(&tmp_frm, 0);
  227. }
  228. else
  229. {
  230. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("the env snapshot video queque image timeout!");
  231. }
  232. }
  233. else
  234. {
  235. //assert(0); // not go here
  236. rc = -1;
  237. }
  238. #ifndef RVC_OS_WIN
  239. {
  240. //linux需翻转环境摄像头图像
  241. int size = frm->linesize[0] * frm->height;
  242. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("size = %d, width= %d height= %d", size, frm->width, frm->height);
  243. RotationDown(frm->data[0], frm->width, REC_COMMON_VIDEO_SNAPSHOT_HEIGHT, 3);
  244. }
  245. #endif
  246. }
  247. jpeg2k_coded_image codec_image = {0};
  248. if((rc == 0)||(rc==Error_TimeOut))
  249. {
  250. WriteStamp(frm);
  251. jpeg2k_raw_image raw_image;
  252. raw_image.data = frm->data[0];
  253. raw_image.width = frm->width;
  254. raw_image.height = frm->height;
  255. raw_image.len = raw_image.width * raw_image.height * 3;
  256. rc = jpeg2k_encode(&raw_image, &codec_image, 10);
  257. }
  258. if ((rc == 0)||(rc==Error_TimeOut))
  259. {
  260. ChannelService_Send_Info Info;
  261. Info.compress = false;
  262. Info.encrypt = false;
  263. Info.type = ACM_TYPE_PHT;
  264. Info.id = 0;
  265. Info.sub_type = ACM_PHT_ANS | ACM_PHT_SNAPSHOT;
  266. Info.data.m_pData = (char *)codec_image.data;
  267. Info.data.m_iLength = codec_image.len;
  268. (*m_pChannelClient)(EntityResource::getLink().upgradeLink())->Send(Info);
  269. jpeg2k_encode_free(&codec_image);
  270. }
  271. else
  272. {
  273. ChannelService_Send_Info Info;
  274. Info.compress = false;
  275. Info.encrypt = false;
  276. Info.type = ACM_TYPE_PHT;
  277. Info.id = 0;
  278. Info.sub_type = ACM_PHT_ANS | ACM_PHT_SNAPSHOT;
  279. Info.data.m_pData = (char *)&rc;
  280. Info.data.m_iLength = sizeof(rc);
  281. (*m_pChannelClient)(EntityResource::getLink().upgradeLink())->Send(Info);
  282. }
  283. #if 0
  284. video_frame_save_bmpfile("snapshot_abc.bmp", frm);
  285. //video_frame_save_bmpfile("d:\\ab.bmp", &frm);
  286. #endif
  287. if (frm)
  288. video_frame_delete(frm);
  289. }
  290. ErrorCodeEnum StartCapture(int id)
  291. {
  292. if (eMobilePadType == m_eDeviceType || eStand1SPlusType == m_eDeviceType){
  293. m_video_env_q = new Clibvideoqueue(REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE);
  294. }
  295. else{ // == 2
  296. m_video_env_q = new Clibvideoqueue(REC_COMMON_VIDEO_ENV_SHM_SNAPSHOT_QUEUE);
  297. m_video_opt_q = new Clibvideoqueue(REC_COMMON_VIDEO_OPT_SHM_SNAPSHOT_QUEUE);
  298. }
  299. if (!m_video_env_q && !m_video_opt_q) {
  300. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("cannot start capture!"); // never go here
  301. return Error_Unexpect;
  302. }
  303. if (m_dwCapture) {
  304. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("already start capture!");
  305. return Error_Duplication;
  306. }
  307. //触发对应的摄像头进行图像采集
  308. if (m_video_env_q && m_video_opt_q)
  309. {
  310. LogEvent(Severity_Middle, MOD_EVENT_SNAPSHOT_START_CAPTURE_ENVOPT, "agent start capture env and opt camera picture!");
  311. }
  312. else if (m_video_env_q)
  313. {
  314. LogEvent(Severity_Middle, MOD_EVENT_SNAPSHOT_START_CAPTURE_ENV, "agent start capture env camera picture!");
  315. }
  316. else if (m_video_opt_q)
  317. {
  318. LogEvent(Severity_Middle, MOD_EVENT_SNAPSHOT_START_CAPTURE_OPT, "agent start capture opt camera picture!");
  319. }
  320. m_dwCapture = SP::Module::Comm::RVCGetTickCount();
  321. GetFunction()->SetTimer(1, this, 2000);
  322. return Error_Succeed;
  323. }
  324. void StopCapture()
  325. {
  326. GetFunction()->KillTimer(1);
  327. m_dwCapture = 0;
  328. }
  329. DeviceTypeEnum RvcGetDeviceType()
  330. {
  331. DeviceTypeEnum eType = eStand2sType;
  332. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  333. CSystemStaticInfo stStaticinfo;
  334. spFunction->GetSystemStaticInfo(stStaticinfo);
  335. if (_stricmp(stStaticinfo.strMachineType, "RVC.Stand1SPlus") == 0) {
  336. eType = eStand1SPlusType;
  337. }
  338. else if (stricmp(stStaticinfo.strMachineType, "RVC.PAD") == 0) {
  339. if (stricmp(stStaticinfo.strSite, "CMB.FLB") == 0) {
  340. eType = eMobilePadType;
  341. }
  342. else {
  343. eType = ePadtype;
  344. }
  345. }
  346. else if (stricmp(stStaticinfo.strMachineType, "RVC.Desk2S") == 0) {
  347. eType = eDesk2SType;
  348. WORD nMajor = stStaticinfo.MachineVersion.GetMajor();
  349. WORD nMinor = stStaticinfo.MachineVersion.GetMinor();
  350. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("MachineVersion is %d.%d", nMajor, nMinor);
  351. if (2 == nMajor) {
  352. eType = eDesk2SIntegratedType;
  353. }
  354. }
  355. else if (stricmp(stStaticinfo.strMachineType, "RPM.Stand1S") == 0) {
  356. eType = eRpm1sType;
  357. }
  358. else if (stricmp(stStaticinfo.strMachineType, "RVC.Desk1S") == 0) {
  359. eType = eDesk1SType;
  360. }
  361. else {
  362. eType = eStand2sType;
  363. }
  364. if (eType >= 0 && eType < sizeof(Device_Type_Table) / sizeof(char*)) {
  365. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("device type is %s.", Device_Type_Table[eType]);
  366. }
  367. return eType;
  368. }
  369. virtual void OnTimeout(DWORD dwTimerID)
  370. {
  371. if (1 == dwTimerID) {
  372. Capture(Error_TimeOut);
  373. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("timeout!");
  374. GetFunction()->KillTimer(dwTimerID);
  375. m_dwCapture = 0;
  376. }
  377. else if (2 == dwTimerID) {
  378. if (FALSE == m_bConnectAssist) {
  379. if (Error_Succeed == ConnectAssistChannel()) {
  380. m_bConnectAssist = TRUE;
  381. }
  382. }
  383. if (TRUE == m_bConnectAssist) {
  384. GetFunction()->KillTimer(2);
  385. }
  386. }
  387. }
  388. virtual void OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  389. const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  390. const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage, const linkContext& pLinkInfo)
  391. {
  392. if (dwUserCode == MOD_EVENT_MEDIACONTROLLER_FINISHED_CAPTURE_ENVOPT ||
  393. dwUserCode == MOD_EVENT_MEDIACONTROLLER_FINISHED_CAPTURE_OPT ||
  394. dwUserCode == MOD_EVENT_MEDIACONTROLLER_FINISHED_CAPTURE_ENV)
  395. {
  396. DWORD dwNow = SP::Module::Comm::RVCGetTickCount();
  397. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("capture duration:%dms", dwNow - m_dwCapture);
  398. Capture(Error_Succeed);
  399. StopCapture();
  400. }
  401. else if (LOG_EVT_MOD_ASSISCHAN_STARTED_SUCCESS == dwUserCode)
  402. {
  403. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("recv LOG_EVT_MOD_ASSISCHAN_STARTED_SUCCESS");
  404. Sleep(975);
  405. if (m_pChannelClient != NULL){
  406. m_pChannelClient->GetFunction()->CloseSession();
  407. m_pChannelClient = NULL;
  408. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Close AssistChannel Session ");
  409. m_bConnectAssist = FALSE;
  410. }
  411. if (Error_Succeed == ConnectAssistChannel()) {
  412. m_bConnectAssist = TRUE;
  413. }
  414. else {
  415. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start timer for reconnect to assist channel.");
  416. GetFunction()->SetTimer(2, this, 3370);
  417. }
  418. }
  419. }
  420. private:
  421. // we use root.ini Video section config to decide camera count
  422. ErrorCodeEnum DecideCameraCount(int &nCount)
  423. {
  424. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  425. CSmartPointer<IConfigInfo> spConfig;
  426. ErrorCodeEnum Error = spFunction->OpenConfig(Config_Root, spConfig);
  427. if (Error == Error_Succeed)
  428. {
  429. CSimpleStringA strVideoEnv;
  430. CSimpleStringA strVideoOpt;
  431. SpIniMappingTable table;
  432. nCount = 0;
  433. table.AddEntryString("Video", "EnvCamera", strVideoEnv, "$");
  434. table.AddEntryString("Video", "OptCamera", strVideoOpt, "$");
  435. Error = table.Load(spConfig);
  436. if (Error == Error_Succeed)
  437. {
  438. if (strVideoEnv.GetLength() > 1)
  439. nCount++;
  440. if (strVideoOpt.GetLength() > 1)
  441. nCount++;
  442. }
  443. }
  444. return Error;
  445. }
  446. ErrorCodeEnum ConnectAssistChannel()
  447. {
  448. if (m_pChannelClient == NULL){
  449. m_pChannelClient = new ChannelClient(this);
  450. }
  451. ErrorCodeEnum Error = m_pChannelClient->Connect();
  452. if (Error_Succeed != Error){
  453. m_pChannelClient = NULL;
  454. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("AssistChannelClient connect fail!");
  455. return Error;
  456. }
  457. else {
  458. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("AssistChannelClient connect success!");
  459. }
  460. if (Error_Succeed == Error){
  461. ChannelService_BeginRecv_Sub Sub;
  462. Sub.type = ACM_TYPE_PHT;
  463. Error = (*m_pChannelClient)(EntityResource::getLink().upgradeLink())->BeginRecv(Sub);
  464. if (Error_Succeed != Error){
  465. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("BeginRecv ACM_TYPE_PHT fail!");
  466. m_pChannelClient->GetFunction()->CloseSession();
  467. m_pChannelClient = NULL;
  468. return Error;
  469. }
  470. else {
  471. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("BeginRecv ACM_TYPE_PHT success!");
  472. }
  473. }
  474. return Error;
  475. }
  476. private:
  477. Clibvideoqueue *m_video_env_q;
  478. Clibvideoqueue *m_video_opt_q;
  479. ChannelClient *m_pChannelClient;
  480. CUUID m_uuidCaptureTimer;
  481. DWORD m_dwCapture;
  482. DeviceTypeEnum m_eDeviceType;
  483. CAutoArray<CUUID> m_arrListener;
  484. BOOL m_bConnectAssist;
  485. };
  486. void ChannelClient::OnMessage( ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer<IReleasable> pData )
  487. {
  488. if (Error == Error_Succeed) {
  489. CPhotoCaptureEntity *pEntity = static_cast<CPhotoCaptureEntity*>(m_pEntityBase);
  490. int cat = ACM_PHT_CAT(Msg.sub_type);
  491. if (cat == ACM_PHT_REQ)
  492. {
  493. Error = pEntity->StartCapture(Msg.id);
  494. if (Error)
  495. {
  496. pEntity->Capture(Error);
  497. }
  498. }
  499. else
  500. {
  501. _ASSERT(0);
  502. }
  503. }
  504. }
  505. ChannelClient::ChannelClient( CPhotoCaptureEntity *pEntity ) : ChannelService_ClientBase(pEntity)
  506. {
  507. }
  508. SP_BEGIN_ENTITY_MAP()
  509. SP_ENTITY(CPhotoCaptureEntity)
  510. SP_END_ENTITY_MAP()