forked from Blup1980/microsip_42
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Preview.cpp
132 lines (114 loc) · 3.03 KB
/
Preview.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
* Copyright (C) 2011-2020 MicroSIP (http://www.microsip.org)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "StdAfx.h"
#include "Preview.h"
#ifdef _GLOBAL_VIDEO
#include "langpack.h"
#include "mainDlg.h"
#include "settings.h"
Preview::~Preview(void)
{
}
int Preview::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (langPack.rtl) {
ModifyStyleEx(0,WS_EX_LAYOUTRTL);
}
return 0;
}
Preview::Preview(CWnd* pParent)
{
CString strClass = AfxRegisterWndClass(
CS_HREDRAW|CS_VREDRAW,
0,
(HBRUSH)COLOR_GRAYTEXT
);
CreateEx(WS_EX_TOPMOST, strClass, Translate(_T("Local Video")),
WS_CAPTION | WS_POPUPWINDOW | WS_MINIMIZEBOX,
CRect(0, 0, 640, 480),
AfxGetMainWnd(), NULL);
widx = PJMEDIA_VID_DEFAULT_CAPTURE_DEV;
}
BEGIN_MESSAGE_MAP(Preview, CWnd)
ON_WM_CREATE()
ON_WM_CLOSE()
ON_WM_DESTROY()
END_MESSAGE_MAP()
void Preview::OnClose()
{
DestroyWindow();
}
void Preview::OnDestroy()
{
mainDlg->previewWin = NULL;
if (pj_ready) {
pjsua_vid_preview_stop(widx);
}
CWnd::OnDestroy();
}
void Preview::PostNcDestroy()
{
CWnd::PostNcDestroy();
delete this;
}
void Preview::Start(int id)
{
pjsua_vid_win_info wi;
pjsua_vid_win_id wid = pjsua_vid_preview_get_win(widx);
if (wid != PJSUA_INVALID_ID) {
if (widx != id) {
pjsua_vid_preview_stop(widx);
} else {
return;
}
}
widx = id;
pjsua_vid_preview_param pre_param;
pj_status_t status;
const pjmedia_coord pos = {0, 0};
pjsua_vid_preview_param_default(&pre_param);
pre_param.show = PJ_FALSE;
status = pjsua_vid_preview_start(widx, &pre_param);
if (status != PJ_SUCCESS) {
OnClose();
return;
}
wid = pjsua_vid_preview_get_win(widx);
pjsua_vid_win_get_info(wid, &wi);
CRect rcClient, rcWind;
POINT ptDiff;
GetClientRect(&rcClient);
GetWindowRect(&rcWind);
ptDiff.x = (rcWind.right - rcWind.left) - rcClient.right;
ptDiff.y = (rcWind.bottom - rcWind.top) - rcClient.bottom;
CRect screenRect;
SystemParametersInfo(SPI_GETWORKAREA,0,&screenRect,0);
//int w = wi.size.w + ptDiff.x;
//int h = wi.size.h + ptDiff.y;
int w = 320 + ptDiff.x;
int h = 240 + ptDiff.y;
int x = screenRect.Width() - w;
int y = ptDiff.y - 6;
SetWindowPos(NULL, x, y, w, h, SWP_NOZORDER|SWP_SHOWWINDOW);
pjsua_vid_win_set_pos(wid,&pos);
pjsua_vid_win_set_show(wid, PJ_TRUE);
const pjmedia_rect_size size = {320, 240};
pjsua_vid_win_set_size( wid, &size);
::SetParent((HWND)wi.hwnd.info.win.hwnd,this->m_hWnd);
}
#endif