mod_screenshot.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. #include "stdafx.h"
  2. #include "SpBase.h"
  3. #include "screencapture.h"
  4. #include <screencodec.h>
  5. #include "videoutil.h"
  6. #include "rvc_media_common.h"
  7. #include "mod_assistantchannel/AssistantChannel_client_g.h"
  8. using namespace AssistantChannel;
  9. #include "mod_assistantchannel/chan_protocol.h"
  10. #include "mod_assistantchannel/VideoDesc.h"
  11. // add by ly 20150514
  12. #include "jpeg2k.h"
  13. #include "ScreenShot_server_g.h"
  14. #include "cv.h"
  15. #include "highgui.h"
  16. #include "cxcore.h"
  17. #include "CommEntityUtil.hpp"
  18. #include "../include/EventCode.h"
  19. using namespace ScreenShot;
  20. // step 1 screen capture
  21. // step 2 compress using libpng
  22. // step 3 split to 56k each chunk to send out
  23. // future improvement:
  24. // 1. adding 8bit depth color options
  25. // 2. adding business zone options
  26. class CScreenCaptureEntity;
  27. class CScreenShotSession: public ScreenShotService_ServerSessionBase
  28. {
  29. public:
  30. CScreenShotSession(CScreenCaptureEntity* pEntity, int id) : m_id(id), m_pEntity(pEntity)
  31. {
  32. }
  33. virtual void Handle_StartScreenShot(SpReqAnsContext<ScreenShotService_StartScreenShot_Req, ScreenShotService_StartScreenShot_Ans>::Pointer ctx);
  34. virtual void OnClose( ErrorCodeEnum eErrorCode );
  35. private:
  36. int m_id;
  37. CScreenCaptureEntity* m_pEntity;
  38. };
  39. class ChannelClient : public ChannelService_ClientBase
  40. {
  41. public:
  42. ChannelClient(CScreenCaptureEntity *pEntity);
  43. virtual void OnMessage(ErrorCodeEnum Error, ChannelService_State_Info &Msg, CSmartPointer<IReleasable> pData);
  44. virtual void OnMessage(ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer<IReleasable> pData);
  45. };
  46. int RotationDown(unsigned char* src, int srcW, int srcH, int channel)
  47. {
  48. unsigned char* tempSrc = NULL;
  49. int mSize = srcW * srcH * sizeof(char) * channel;
  50. int i = 0;
  51. int j = 0;
  52. int k = 0;
  53. int desW = 0;
  54. int desH = 0;
  55. desW = srcW;
  56. desH = srcH;
  57. tempSrc = (unsigned char*)malloc(sizeof(char) * srcW * srcH * channel);
  58. memcpy(tempSrc, src, mSize);
  59. for (i = 0; i < desH; i++)
  60. {
  61. for (j = 0; j < desW; j++)
  62. {
  63. for (k = 0; k < channel; k++)
  64. {
  65. //src[(i * desW + j) * channel + k] = tempSrc[((srcH - 1 - i) * srcW + srcW - 1 - j) * channel + k];
  66. src[(i * desW + j) * channel + k] = tempSrc[((srcH - 1 - i) * srcW + j) * channel + k];
  67. }
  68. }
  69. }
  70. free(tempSrc);
  71. return 0;
  72. }
  73. class CScreenCaptureEntity : public CEntityBase,public ILogListener, public ITimerListener
  74. {
  75. public:
  76. CScreenCaptureEntity() : m_enc_session(NULL), m_id_seq(0) {}
  77. virtual ~CScreenCaptureEntity() {}
  78. virtual const char *GetEntityName() const { return "ScreenShot"; }
  79. virtual bool IsService() const { return true; }
  80. virtual CServerSessionBase *OnNewSession(const char* pszRemoteEntityName, const char * pszClass)
  81. {
  82. return new CScreenShotSession(this, m_id_seq++);
  83. }
  84. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
  85. {
  86. ErrorCodeEnum Error = __OnStart(Error_Succeed);
  87. pTransactionContext->SendAnswer(Error);
  88. }
  89. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  90. {
  91. ErrorCodeEnum Error = __OnClose(Error_Succeed);
  92. pTransactionContext->SendAnswer(Error);
  93. }
  94. virtual void OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  95. const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  96. const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage, const linkContext& pLinkInfo)
  97. {
  98. if (dwUserCode == LOG_EVT_MOD_ASSISCHAN_STARTED_SUCCESS)
  99. {
  100. Sleep(970);
  101. if (NULL != m_pChannelClient){
  102. m_pChannelClient->GetFunction()->CloseSession();
  103. m_pChannelClient = NULL;
  104. m_bConnectAssist = FALSE;
  105. }
  106. if (Error_Succeed == ConnectAssistChannel()) {
  107. m_bConnectAssist = TRUE;
  108. }
  109. else {
  110. GetFunction()->SetTimer(1, this, 3370);
  111. }
  112. }
  113. }
  114. virtual void OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
  115. {
  116. if (Test_ShakeHand == eTestType)
  117. {
  118. pTransactionContext->SendAnswer(Error_Succeed);
  119. }
  120. }
  121. ErrorCodeEnum __OnStart(ErrorCodeEnum preOperationError)
  122. {
  123. CSmartPointer<IEntityFunction> pFunc = GetFunction();
  124. int i = 0;
  125. m_arrListener.Init(1);
  126. pFunc->SubscribeLog(m_arrListener[i++], this, Log_Event, Severity_None, Error_IgnoreAll, LOG_EVT_MOD_ASSISCHAN_STARTED_SUCCESS,NULL,false);
  127. if (preOperationError != Error_Succeed)
  128. return preOperationError;
  129. //is Pad Version
  130. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  131. CSystemStaticInfo stStaticinfo;
  132. spFunction->GetSystemStaticInfo(stStaticinfo);
  133. if (stricmp(stStaticinfo.strMachineType,"RVC.WALL")==0)
  134. {
  135. m_bIsWallMachine = TRUE;
  136. }
  137. else
  138. {
  139. m_bIsWallMachine = FALSE;
  140. }
  141. return Error_Succeed;
  142. }
  143. void OnStarted()
  144. {
  145. m_pChannelClient = new ChannelClient(this);
  146. if (Error_Succeed == ConnectAssistChannel()) {
  147. m_bConnectAssist = TRUE;
  148. }
  149. else {
  150. GetFunction()->SetTimer(1, this, 3370);
  151. }
  152. }
  153. ErrorCodeEnum __OnClose(ErrorCodeEnum preOperationError)
  154. {
  155. CSmartPointer<IEntityFunction> spFunction = GetFunction();
  156. for (int i = 0; i < m_arrListener.GetCount(); ++i)
  157. {
  158. spFunction->UnsubscribeLog(m_arrListener[i]);
  159. }
  160. if (preOperationError != Error_Succeed)
  161. return preOperationError;
  162. m_pChannelClient->GetFunction()->CloseSession();
  163. m_pChannelClient = NULL;
  164. return Error_Succeed;
  165. }
  166. void DumpCaptureDat(const char *buf, int n)
  167. {
  168. char tmp[MAX_PATH];
  169. static int seq = 0;
  170. sprintf(tmp, ".%scapture_%08d.dat", SPLIT_SLASH_STR, seq++);
  171. FILE *fp = fopen(tmp, "wb");
  172. if (fp)
  173. {
  174. fwrite(buf,1,n, fp);
  175. fclose(fp);
  176. }
  177. }
  178. ErrorCodeEnum InitCapture()
  179. {
  180. if (m_enc_session) {
  181. screen_encoder_session_destroy(m_enc_session);
  182. m_enc_session = NULL;
  183. }
  184. #ifdef RVC_OS_WIN
  185. int cx = GetSystemMetrics(SM_CXSCREEN);
  186. int cy = GetSystemMetrics(SM_CYSCREEN);
  187. #else
  188. int cx, cy;
  189. getScreenSize(&cx, &cy);
  190. #endif
  191. if (m_bIsWallMachine)
  192. {
  193. cy = cy-640;
  194. }
  195. screen_encoder_session_create(cx, cy, &m_enc_session);
  196. return Error_Succeed;
  197. }
  198. void ExitCapture()
  199. {
  200. if (m_enc_session) {
  201. screen_encoder_session_destroy(m_enc_session);
  202. m_enc_session = NULL;
  203. }
  204. }
  205. void Capture(int id)
  206. {
  207. CSystemStaticInfo SysInfo;
  208. #ifdef RVC_OS_WIN
  209. int cx = GetSystemMetrics(SM_CXSCREEN);
  210. int cy = GetSystemMetrics(SM_CYSCREEN);
  211. #else
  212. int cx, cy;
  213. getScreenSize(&cx, &cy);
  214. #endif
  215. RECT rc = {0, 0, cx, cy};
  216. int size = 0;
  217. int err = screencapture_capture(&rc, NULL, &size);
  218. if (err != 0) {
  219. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("capture screen failed! %d", err);
  220. return;
  221. }
  222. void *buf = malloc(size);
  223. err = screencapture_capture(&rc, buf, &size);
  224. if (err != 0) {
  225. free(buf);
  226. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("capture screen failed! %d", err);
  227. return;
  228. }
  229. if((SysInfo.eScreen == 1)&&!m_bIsWallMachine)
  230. {
  231. CSimpleStringA strValue;
  232. ErrorCodeEnum Error = GetFunction()->GetSysVar("VideoWindowInitializeParam", strValue);
  233. if (Error == Error_Succeed)
  234. {
  235. int local_view_x;
  236. int local_view_y;
  237. int local_view_cx;
  238. int local_view_cy;
  239. int remote_view_x;
  240. int remote_view_y;
  241. int remote_view_cx;
  242. int remote_view_cy;
  243. ParseVideoViewParam((LPCSTR)strValue, local_view_x, local_view_y, local_view_cx, local_view_cy,
  244. remote_view_x, remote_view_y, remote_view_cx, remote_view_cy);
  245. RECT rcs[] = {
  246. {local_view_x, cy - local_view_y - local_view_cy, local_view_x+local_view_cx, cy - local_view_y},
  247. {remote_view_x, cy - remote_view_y - remote_view_cy, remote_view_x+remote_view_cx, cy - remote_view_y},
  248. };
  249. screencapture_clipoff(cx, cy, buf, 2, rcs);
  250. }
  251. }
  252. #ifndef RVC_OS_WIN
  253. {
  254. //linux需翻转图像
  255. int width = rc.right - rc.left;
  256. int height = rc.bottom - rc.top;
  257. RotationDown((unsigned char*)buf, width, height, 3);
  258. }
  259. #endif
  260. ChannelService_Send_Info Info;
  261. Info.compress = false;
  262. Info.encrypt = false;
  263. Info.type = ACM_TYPE_SRN;
  264. Info.id = id;
  265. Info.sub_type = ACM_SRN_ANS | ACM_SRN_SNAPSHOT;
  266. if (m_bIsWallMachine)
  267. {
  268. int width = rc.right - rc.left;
  269. int height = rc.bottom - 640;
  270. int linesize = (width * 3 + 3) & 0xfffffffc;
  271. int newsize = linesize * height;
  272. Info.data.Alloc(newsize);
  273. void *buftmp = malloc(newsize);
  274. memcpy(buftmp,buf,newsize);
  275. screen_encoder_session_encode(m_enc_session, buftmp, Info.data.m_pData, &Info.data.m_iLength);
  276. (*m_pChannelClient)(EntityResource::getLink().upgradeLink())->Send(Info);
  277. free(buftmp);
  278. }
  279. else
  280. {
  281. Info.data.Alloc(size);
  282. screen_encoder_session_encode(m_enc_session, buf, Info.data.m_pData, &Info.data.m_iLength);
  283. (*m_pChannelClient)(EntityResource::getLink().upgradeLink())->Send(Info);
  284. }
  285. #if 0
  286. int linesize = size / cy;
  287. video_frame tmp_frame;
  288. video_frame_alloc(linesize/3, cy, VIDEO_FORMAT_RGB24, &tmp_frame);
  289. video_frame_fill_black(&tmp_frame);
  290. memcpy(tmp_frame.data[0], buf, size);
  291. video_frame_save_bmpfile("screenshot_abc.bmp", &tmp_frame);
  292. video_frame_free(&tmp_frame);
  293. //video_frame_save_bmpfile("d:\\ab.bmp", &rtp_frame);
  294. #endif
  295. free(buf);
  296. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("encode size = %d Bytes, time = %d", Info.data.m_iLength, GetTickCount());
  297. }
  298. void Capture1(int id)
  299. {
  300. CSystemStaticInfo SysInfo;
  301. #ifdef RVC_OS_WIN
  302. int cx = GetSystemMetrics(SM_CXSCREEN);
  303. int cy = GetSystemMetrics(SM_CYSCREEN);
  304. #else
  305. int cx, cy;
  306. getScreenSize(&cx, &cy);
  307. #endif
  308. RECT rc = {0, 0, cx, cy};
  309. int size = 0;
  310. int err = screencapture_capture(&rc, NULL, &size);
  311. if (err != 0) {
  312. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("capture screen failed! %d", err);
  313. return;
  314. }
  315. void *buf = malloc(size);
  316. err = screencapture_capture(&rc, buf, &size);
  317. if (err != 0) {
  318. free(buf);
  319. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("capture screen failed! %d", err);
  320. return;
  321. }
  322. if (SysInfo.eScreen == 1) {
  323. CSimpleStringA strValue;
  324. ErrorCodeEnum Error = GetFunction()->GetSysVar("VideoWindowInitializeParam", strValue);
  325. if (Error == Error_Succeed) {
  326. int local_view_x;
  327. int local_view_y;
  328. int local_view_cx;
  329. int local_view_cy;
  330. int remote_view_x;
  331. int remote_view_y;
  332. int remote_view_cx;
  333. int remote_view_cy;
  334. ParseVideoViewParam((LPCSTR)strValue, local_view_x, local_view_y, local_view_cx, local_view_cy,
  335. remote_view_x, remote_view_y, remote_view_cx, remote_view_cy);
  336. RECT rcs[] = {
  337. {local_view_x, cy - local_view_y - local_view_cy, local_view_x+local_view_cx, cy - local_view_y},
  338. {remote_view_x, cy - remote_view_y - remote_view_cy, remote_view_x+remote_view_cx, cy - remote_view_y},
  339. };
  340. screencapture_clipoff(cx, cy, buf, 2, rcs);
  341. }
  342. }
  343. #ifndef RVC_OS_WIN
  344. //linux需翻转图像
  345. int width = rc.right - rc.left;
  346. int height = rc.bottom - rc.top;
  347. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("size = %d, 3*width*height= %d", size, 3 * width * height);
  348. RotationDown((unsigned char*)buf, width, height, 3);
  349. #endif
  350. ChannelService_Send_Info Info;
  351. Info.compress = false;
  352. Info.encrypt = false;
  353. Info.type = ACM_TYPE_SRN;
  354. Info.id = id;
  355. Info.sub_type = ACM_SRN_ANS | ACM_SRN_SNAPSHOT;
  356. Info.data.Alloc(size);
  357. screencapture_encode(cx, cy, buf, Info.data.m_pData, &Info.data.m_iLength);
  358. //DumpCaptureDat((const char*)Info.data.m_pData, Info.data.m_iLength);
  359. (*m_pChannelClient)(EntityResource::getLink().upgradeLink())->Send(Info);
  360. free(buf);
  361. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("encode size = %d Bytes, time = %d", Info.data.m_iLength, GetTickCount());
  362. }
  363. void Capture2(RECT *lprc, CBlob &image)
  364. {
  365. int width = lprc->right-lprc->left;
  366. int height = lprc->bottom-lprc->top;
  367. int size = 0;
  368. int err = screencapture_capture(lprc, NULL, &size);
  369. if (err != 0) {
  370. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("capture screen failed! %d", err);
  371. return;
  372. }
  373. void *buf = malloc(size);
  374. err = screencapture_capture(lprc, buf, &size);
  375. if (err != 0) {
  376. free(buf);
  377. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("capture screen failed! %d", err);
  378. return;
  379. }
  380. #ifndef RVC_OS_WIN
  381. //linux需翻转图像
  382. //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("size = %d, 3*width*height= %d", size, 3*width*height);
  383. RotationDown((unsigned char*)buf, width, height, 3);
  384. #endif
  385. // encode with jpeg2k
  386. jpeg2k_coded_image codec_image = {0};
  387. jpeg2k_raw_image raw_image;
  388. raw_image.data = (BYTE*)buf;
  389. raw_image.width = width;
  390. raw_image.height = height;
  391. raw_image.len = raw_image.width * raw_image.height * 3;
  392. int nRet = jpeg2k_encode(&raw_image, &codec_image, 30); // ratio越小质量越好
  393. if (nRet == 0 || nRet == Error_TimeOut)
  394. {
  395. size = codec_image.len;
  396. image.Alloc(size);
  397. memmove(image.m_pData, codec_image.data, size);
  398. //char tmp[MAX_PATH];
  399. //static int seq = 0;
  400. //sprintf(tmp, ".\\jietu_%08d.jp2", seq++);
  401. //FILE *fp = fopen(tmp, "wb");
  402. //if (fp) {
  403. // fwrite(codec_image.data,1,size, fp);
  404. // fclose(fp);
  405. //}
  406. image.Resize(size);
  407. jpeg2k_encode_free(&codec_image);
  408. }
  409. free(buf);
  410. }
  411. private:
  412. ErrorCodeEnum ConnectAssistChannel()
  413. {
  414. if (NULL == m_pChannelClient){
  415. m_pChannelClient = new ChannelClient(this);
  416. }
  417. ErrorCodeEnum Error = m_pChannelClient->Connect();
  418. if (Error != Error_Succeed){
  419. m_pChannelClient = NULL;
  420. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("AssistChannelClient connect fail!");
  421. return Error;
  422. }
  423. if (Error == Error_Succeed){
  424. ChannelService_BeginRecv_Sub Sub;
  425. Sub.type = ACM_TYPE_SRN;
  426. Error = (*m_pChannelClient)(EntityResource::getLink().upgradeLink())->BeginRecv(Sub);
  427. if (Error != Error_Succeed){
  428. m_pChannelClient->GetFunction()->CloseSession();
  429. m_pChannelClient = NULL;
  430. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("BeginRecv ACM_TYPE_SRN fail!");
  431. return Error;
  432. }
  433. }
  434. if (Error == Error_Succeed){
  435. ChannelService_BeginState_Sub Sub;
  436. Error = (*m_pChannelClient)(EntityResource::getLink().upgradeLink())->BeginState(Sub);
  437. if (Error != Error_Succeed){
  438. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("BeginState biz channel failed!");
  439. m_pChannelClient->GetFunction()->CloseSession();
  440. m_pChannelClient = NULL;
  441. return Error;
  442. }
  443. }
  444. return Error;
  445. }
  446. void OnTimeout(DWORD dwTimerID)
  447. {
  448. if (1 == dwTimerID)
  449. {
  450. if (FALSE == m_bConnectAssist) {
  451. if (Error_Succeed == ConnectAssistChannel()) {
  452. m_bConnectAssist = TRUE;
  453. }
  454. }
  455. if (TRUE == m_bConnectAssist) {
  456. GetFunction()->KillTimer(1);
  457. }
  458. }
  459. }
  460. private:
  461. screen_encoder_session_t *m_enc_session;
  462. ChannelClient *m_pChannelClient;
  463. CAutoArray<CUUID> m_arrListener;
  464. // add by ly 20150514
  465. int m_id_seq;
  466. BOOL m_bIsWallMachine;
  467. BOOL m_bConnectAssist;
  468. };
  469. // add by ly 20150514
  470. void CScreenShotSession::Handle_StartScreenShot(SpReqAnsContext<ScreenShotService_StartScreenShot_Req, ScreenShotService_StartScreenShot_Ans>::Pointer ctx)
  471. {
  472. DbgToBeidou(ctx->link, __FUNCTION__)();
  473. #ifdef RVC_OS_WIN
  474. int cx = GetSystemMetrics(SM_CXSCREEN);
  475. int cy = GetSystemMetrics(SM_CYSCREEN);
  476. #else
  477. int cx, cy;
  478. getScreenSize(&cx, &cy);
  479. #endif
  480. if (ctx->Req.Left < 0 || ctx->Req.Left > cx || ctx->Req.Width <= 0 || ctx->Req.Width > cx ||
  481. ctx->Req.Top < 0 || ctx->Req.Top > cy || ctx->Req.Height <= 0 || ctx->Req.Height > cy)
  482. {
  483. ctx->Answer(Error_Unexpect);
  484. }
  485. RECT rc = {ctx->Req.Left, ctx->Req.Top, ctx->Req.Left + ctx->Req.Width, ctx->Req.Top + ctx->Req.Height};
  486. m_pEntity->Capture2(&rc, ctx->Ans.Image);
  487. if (ctx->Ans.Image.m_iLength == 0)
  488. {
  489. ctx->Answer(Error_Unexpect);
  490. }
  491. else
  492. {
  493. ctx->Answer(Error_Succeed);
  494. }
  495. }
  496. void CScreenShotSession::OnClose( ErrorCodeEnum eErrorCode )
  497. {
  498. }
  499. void ChannelClient::OnMessage(ErrorCodeEnum Error, ChannelService_State_Info &Msg, CSmartPointer<IReleasable> pData)
  500. {
  501. if (Error == Error_Succeed) {
  502. CScreenCaptureEntity *pEntity = static_cast<CScreenCaptureEntity*>(m_pEntityBase);
  503. if (Msg.state == eChannelState_Idle) {
  504. pEntity->ExitCapture();
  505. } else if (Msg.state == eChannelState_Connected) {
  506. pEntity->InitCapture();
  507. }
  508. }
  509. }
  510. void ChannelClient::OnMessage( ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer<IReleasable> pData )
  511. {
  512. if (Error == Error_Succeed) {
  513. CScreenCaptureEntity *pEntity = static_cast<CScreenCaptureEntity*>(m_pEntityBase);
  514. int cat = ACM_SRN_CAT(Msg.sub_type);
  515. if (cat == ACM_SRN_REQ) {
  516. //SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_BELOW_NORMAL);
  517. pEntity->Capture(Msg.id);
  518. //SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
  519. } else {
  520. _ASSERT(0);
  521. }
  522. }
  523. }
  524. ChannelClient::ChannelClient( CScreenCaptureEntity *pEntity ) : ChannelService_ClientBase(pEntity)
  525. {
  526. }
  527. SP_BEGIN_ENTITY_MAP()
  528. SP_ENTITY(CScreenCaptureEntity)
  529. SP_END_ENTITY_MAP()