VideoWin.cpp 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. // VideoWin.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "HKVision.h"
  5. #include "HKVisionDlg.h"
  6. #include "VideoWin.h"
  7. #include "mdlProject.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. extern int g_nTotalChannel;
  14. extern void CALLBACK DrawFun(long nport, HDC hDc,LONG nUser);
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CVideoWin
  17. #define VIDEO_MULTI_CHANNEL 0
  18. #define VIDEO_SINGLE_CHANNEL 1
  19. #define VIDEO_PLAYBACK 2
  20. extern RECT rectList[MAX_CHANNELS];
  21. extern HANDLE ChannelHandle[MAX_CHANNELS];
  22. int iLastSelect = 0;
  23. int DisplayMode = 0; // 0: normal video preview
  24. // 1: single video channel preview
  25. // 2: playback mode
  26. extern BOOL bDdrawMode;
  27. extern COLORREF gBackgroundColor;
  28. static CBrush tempBrush(gBackgroundColor);
  29. void SelectRect(int i, CDC *dc);
  30. int GetSelect(CPoint point);
  31. extern DWORD dcurrentwin;
  32. CVideoWin::CVideoWin()
  33. {
  34. }
  35. CVideoWin::~CVideoWin()
  36. {
  37. }
  38. BEGIN_MESSAGE_MAP(CVideoWin, CEdit)
  39. //{{AFX_MSG_MAP(CVideoWin)
  40. ON_WM_LBUTTONDOWN()
  41. ON_WM_LBUTTONDBLCLK()
  42. ON_WM_PAINT()
  43. ON_WM_MOVE()
  44. ON_WM_MOVING()
  45. //}}AFX_MSG_MAP
  46. END_MESSAGE_MAP()
  47. /////////////////////////////////////////////////////////////////////////////
  48. // CVideoWin message handlers
  49. void CVideoWin::OnLButtonDown(UINT nFlags, CPoint point)
  50. {
  51. // TODO: Add your message handler code here and/or call default
  52. // TRACE("mouse click at %i %i\n", point.x, point.y);
  53. if(DisplayMode != VIDEO_MULTI_CHANNEL)
  54. return;
  55. dcurrentwin = GetSelect(point);
  56. CDC *pDC = GetDC();
  57. SelectRect(dcurrentwin, pDC);
  58. DrawTitle(CacRects(g_nTotalChannel));
  59. ReleaseDC(pDC);
  60. CEdit::OnLButtonDown(nFlags, point);
  61. }
  62. int GetSelect(CPoint point)
  63. {
  64. for(int i =0; i < g_nTotalChannel; i++){
  65. if(PtInRect(&rectList[i], point)){
  66. return i;
  67. }
  68. }
  69. return -1;
  70. }
  71. void ClearSelect(CDC *dc)
  72. {
  73. }
  74. void CVideoWin::OnLButtonDblClk(UINT nFlags, CPoint point)
  75. {
  76. int s;
  77. if((DisplayMode == VIDEO_MULTI_CHANNEL) && ((s = GetSelect(point)) != -1)){
  78. // deselect old rect first
  79. for(int i = 0; i < GetTotalDSPs(); i++){
  80. StopVideoPreview(ChannelHandle[i]);
  81. }
  82. RECT previewWnd;
  83. GetClientRect(&previewWnd);
  84. TRACE("clear client area\n");
  85. CDC *dc = GetDC(); // device context for painting
  86. // CBrush tempBrush(gBackgroundColor);
  87. CBrush *oldBrush = dc->SelectObject(&tempBrush);
  88. dc->Rectangle(&previewWnd);
  89. dc->SelectObject(oldBrush);
  90. //if( previewWnd.bottom -previewWnd.top >=576 && previewWnd.right -previewWnd.left >=704)
  91. //{
  92. // CString title;
  93. // title.Format("channel %02d", s);
  94. // dc->SetTextColor(RGB(255,0,0));
  95. // dc->SetBkMode(TRANSPARENT);
  96. // dc->TextOut(10,10,title);
  97. //}
  98. ReleaseDC(dc);
  99. //::StartVideoPreview(ChannelHandle[s], m_hWnd, &previewWnd, FALSE, vdfYUV444Planar/*vdfRGB16*/, 25);
  100. if(bDdrawMode)
  101. ::StartVideoPreview(ChannelHandle[s], m_hWnd, &previewWnd, FALSE, vdfRGB16, 25);
  102. else
  103. ::StartVideoPreview(ChannelHandle[s], m_hWnd, &previewWnd, FALSE, vdfYUV422Planar, 25);
  104. DisplayMode = VIDEO_SINGLE_CHANNEL;
  105. //CHKVisionDlg *mainwnd = &g_pDlgMain->Dlg_VedioMonitor;
  106. //RegisterDrawFun(s,DrawFun,(DWORD)mainwnd);
  107. }
  108. else if(DisplayMode == VIDEO_SINGLE_CHANNEL)
  109. {
  110. /*for(int i = 0; i < g_nTotalChannel; i++){
  111. StopVideoPreview(ChannelHandle[i]);
  112. }
  113. for(i = 0; i < g_nTotalChannel; i++){
  114. if(bDdrawMode)
  115. ::StartVideoPreview(ChannelHandle[i], m_hWnd, &rectList[i], FALSE, vdfRGB16, 25);
  116. else
  117. ::StartVideoPreview(ChannelHandle[i], m_hWnd, &rectList[i], FALSE, vdfYUV422Planar, 25);
  118. }
  119. */
  120. CDC *pDC = GetDC();
  121. StartVideoPreview(pDC);
  122. ReleaseDC(pDC);
  123. DisplayMode = VIDEO_MULTI_CHANNEL;
  124. }
  125. CEdit::OnLButtonDblClk(nFlags, point);
  126. }
  127. int SplitRects(int width, int height, int cols, int rows, RECT *rectList)
  128. {
  129. int numRects = cols * rows;
  130. int inCols, inRows;
  131. int subRectH = height / rows;
  132. int subRectW = width / cols;
  133. ASSERT((cols >= 1) && (rows >= 1));
  134. for(int i = 0; i < numRects; i++){
  135. inRows = i / cols;
  136. inCols = i % cols;
  137. rectList[i].left = inCols * subRectW;
  138. rectList[i].top = inRows * subRectH;
  139. rectList[i].right = rectList[i].left + subRectW;
  140. rectList[i].bottom = rectList[i].top + subRectH;
  141. }
  142. /* if (numRects ==4)
  143. {
  144. rectList[0].left = rectList[0].left;
  145. rectList[0].top = rectList[0].top;
  146. rectList[0].right +=100;
  147. rectList[0].bottom +=50;
  148. rectList[1].left +=100 ;
  149. rectList[1].top = rectList[1].top;
  150. rectList[1].right = rectList[1].right;
  151. rectList[1].bottom +=50;
  152. rectList[2].left = rectList[2].left;
  153. rectList[2].top +=50;
  154. rectList[2].right +=100;
  155. rectList[2].bottom = rectList[2].bottom;
  156. rectList[3].left +=100;
  157. rectList[3].right +=50;
  158. rectList[3].top = rectList[3].top;
  159. rectList[3].bottom = rectList[3].bottom;
  160. }
  161. */
  162. return numRects;
  163. }
  164. void CVideoWin::OnPaint()
  165. {
  166. CPaintDC dc(this); // device context for painting
  167. // TODO: Add your message handler code here
  168. // TRACE("VideoWin:OnPaint, iLastSelect=%d\n", iLastSelect);
  169. SelectRect(iLastSelect, &dc);
  170. StartVideoPreview(&dc);
  171. // Do not call CEdit::OnPaint() for painting messages
  172. }
  173. void CVideoWin::OnMove(int x, int y)
  174. {
  175. CEdit::OnMove(x, y);
  176. // TODO: Add your message handler code here
  177. }
  178. void CVideoWin::OnMoving(UINT fwSide, LPRECT pRect)
  179. {
  180. CEdit::OnMoving(fwSide, pRect);
  181. // TODO: Add your message handler code here
  182. }
  183. void CVideoWin::StartVideoPreview(CDC *dc)
  184. {
  185. for(int i = 0; i < GetTotalDSPs(); i++){
  186. StopVideoPreview(ChannelHandle[i]);
  187. }
  188. RECT previewWnd;
  189. GetClientRect(&previewWnd);
  190. //CDC *pDC = GetDlgItem(IDC_VIDEOWIN)->GetDC();
  191. // CBrush tempBrush(gBackgroundColor);
  192. CBrush *oldBrush = dc->SelectObject(&tempBrush);
  193. dc->Rectangle(&previewWnd);
  194. dc->SelectObject(oldBrush);
  195. int rectWidth = previewWnd.right - previewWnd.left;
  196. int rectHeight = previewWnd.bottom - previewWnd.top;
  197. int numRects = GetTotalDSPs();
  198. CString str;
  199. ZeroMemory(rectList, sizeof(rectList));
  200. numRects = CacRects(GetTotalDSPs());
  201. for(i = 0; i < GetTotalDSPs(); i++){
  202. if(bDdrawMode)
  203. ::StartVideoPreview(ChannelHandle[i], m_hWnd, &rectList[i], FALSE, vdfRGB16, 25);
  204. else
  205. ::StartVideoPreview(ChannelHandle[i], m_hWnd, &rectList[i], FALSE, vdfYUV422Planar, 25);
  206. //str.Format("Channel %d",i);
  207. //dc->SetTextColor(RGB(255,0,0));
  208. //dc->SetBkMode(TRANSPARENT);
  209. //dc->TextOut(rectList[i].left+5,rectList[i].top+10,str);
  210. }
  211. DrawTitle(numRects);
  212. }
  213. void CVideoWin::SelectRect(int i, CDC *dc)
  214. {
  215. if((i == -1) ||(DisplayMode != VIDEO_MULTI_CHANNEL))return;
  216. CPen penWhite;
  217. // CBrush tempBrush(RGB(255, 0, 255));
  218. CBrush *oldBrush = dc->SelectObject(&tempBrush);
  219. RECT previewWnd;
  220. GetClientRect(&previewWnd);
  221. dc->Rectangle(&previewWnd);
  222. dc->SelectObject(oldBrush);
  223. int oldrop2 = dc->SetROP2(R2_XORPEN);
  224. penWhite.CreatePen(PS_SOLID, 1, RGB(255, 255, 255));
  225. CPen* pOldPen = dc->SelectObject(&penWhite);
  226. if(i >= 0){
  227. dc->MoveTo(rectList[i].left+1, rectList[i].top+1);
  228. dc->LineTo(rectList[i].right-1, rectList[i].top+1);
  229. dc->LineTo(rectList[i].right-1, rectList[i].bottom-1);
  230. dc->LineTo(rectList[i].left+1, rectList[i].bottom-1);
  231. dc->LineTo(rectList[i].left+1, rectList[i].top+1);
  232. }
  233. iLastSelect = i;
  234. dc->SelectObject(pOldPen);
  235. dc->SetROP2(oldrop2);
  236. //if (bAudioPre)
  237. //{
  238. // SetAudioPreview(ChannelHandle[iLastSelect],FALSE);
  239. // SetAudioPreview(ChannelHandle[i],TRUE);
  240. //}
  241. //if((i == -1) ||(DisplayMode != VIDEO_MULTI_CHANNEL))return;
  242. // iLastSelect = i;
  243. //CHKVisionDlg *mainwnd = &g_pDlgMain->Dlg_VedioMonitor;
  244. // if(bOverlayMode)
  245. // {
  246. // CPen penWhite;
  247. //// CBrush tempBrush(gBackgroundColor);
  248. // CBrush *oldBrush = dc->SelectObject(&tempBrush);
  249. // RECT previewWnd;
  250. // GetClientRect(&previewWnd);
  251. // dc->Rectangle(&previewWnd);
  252. // dc->SelectObject(oldBrush);
  253. // int oldrop2 = dc->SetROP2(R2_XORPEN);
  254. // penWhite.CreatePen(PS_SOLID, 1, RGB(255, 255, 255));
  255. // CPen* pOldPen = dc->SelectObject(&penWhite);
  256. //
  257. // if(i >= 0)
  258. // {
  259. // dc->MoveTo(rectList[i].left+1, rectList[i].top+1);
  260. // dc->LineTo(rectList[i].right-1, rectList[i].top+1);
  261. // dc->LineTo(rectList[i].right-1, rectList[i].bottom-1);
  262. // dc->LineTo(rectList[i].left+1, rectList[i].bottom-1);
  263. // dc->LineTo(rectList[i].left+1, rectList[i].top+1);
  264. // }
  265. //
  266. // iLastSelect = i;
  267. //
  268. // dc->SelectObject(pOldPen);
  269. // dc->SetROP2(oldrop2);
  270. // }
  271. // else
  272. //{
  273. // for(i =0; i < GetTotalDSPs(); i++)
  274. // {
  275. // if (i == iLastSelect)
  276. // RegisterDrawFun(i,DrawFun,(DWORD)mainwnd);
  277. // else
  278. // mainwnd->StopDrawFun(i);
  279. // }
  280. //}
  281. return;
  282. }
  283. void CVideoWin::DrawTitle(int numRects)
  284. {
  285. return;
  286. CDC *dc = GetDC();
  287. int numBmps;
  288. if((numBmps = numRects - g_nTotalChannel))
  289. {
  290. CDC tempDC;
  291. CBitmap tbmp;
  292. tbmp.LoadBitmap(IDB_HKTITLE);
  293. tempDC.CreateCompatibleDC(dc);
  294. CBitmap *oldBitmap = tempDC.SelectObject(&tbmp);
  295. int i = numRects-1;
  296. //if(i >=1)i--;
  297. //else return;
  298. while(numBmps--){
  299. dc->StretchBlt(rectList[i].left, rectList[i].top, rectList[i].right - rectList[i].left, rectList[i].bottom - rectList[i].top,
  300. &tempDC, 0, 0,352, 288, SRCCOPY);
  301. i--;
  302. }
  303. tempDC.SelectObject(oldBitmap);
  304. }
  305. ReleaseDC(dc);
  306. }
  307. int CVideoWin::CacRects(int numRects)
  308. {
  309. RECT r;
  310. GetClientRect(&r);
  311. int rectWidth = r.right - r.left;
  312. int rectHeight = r.bottom - r.top;
  313. switch(numRects){
  314. case 1:
  315. numRects = SplitRects(rectWidth, rectHeight, 1, 1, rectList);
  316. break;
  317. case 2:
  318. case 3:
  319. case 4:
  320. numRects = SplitRects(rectWidth, rectHeight, 2, 2, rectList);
  321. break;
  322. case 5:
  323. case 6:
  324. case 7:
  325. case 8:
  326. case 9:
  327. numRects = SplitRects(rectWidth, rectHeight, 3, 3, rectList);
  328. break;
  329. case 10:
  330. case 11:
  331. case 12:
  332. case 13:
  333. case 14:
  334. case 15:
  335. case 16:
  336. numRects = SplitRects(rectWidth, rectHeight, 4, 4, rectList);
  337. break;
  338. case 17:
  339. case 18:
  340. case 19:
  341. case 20:
  342. case 21:
  343. case 22:
  344. case 23:
  345. case 24:
  346. case 25:
  347. numRects = SplitRects(rectWidth, rectHeight, 5, 5, rectList);
  348. break;
  349. case 26:
  350. case 27:
  351. case 28:
  352. case 29:
  353. case 30:
  354. case 31:
  355. case 32:
  356. case 33:
  357. case 34:
  358. case 35:
  359. case 36:
  360. numRects = SplitRects(rectWidth, rectHeight, 6, 6, rectList);
  361. break;
  362. case 37:
  363. case 38:
  364. case 39:
  365. case 40:
  366. case 41:
  367. case 42:
  368. case 43:
  369. case 44:
  370. case 45:
  371. case 46:
  372. case 47:
  373. case 48:
  374. case 49:
  375. numRects = SplitRects(rectWidth, rectHeight, 7, 7, rectList);
  376. break;
  377. case 50:
  378. case 51:
  379. case 52:
  380. case 53:
  381. case 54:
  382. case 55:
  383. case 56:
  384. case 57:
  385. case 58:
  386. case 59:
  387. case 60:
  388. case 61:
  389. case 62:
  390. case 63:
  391. case 64:
  392. numRects = SplitRects(rectWidth, rectHeight, 8, 8, rectList);
  393. break;
  394. default:
  395. numRects = SplitRects(rectWidth, rectHeight, 5 , 5, rectList);
  396. break;
  397. }
  398. return numRects;
  399. }
  400. void CVideoWin::DrawVect(UINT Channel, CHAR *Vect, ULONG Size)
  401. {
  402. }