mod_snapshot.cpp 17 KB

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