Skip to content

Commit 0af91e7

Browse files
committed
feat: fix screenshare & rtmp publish bug
1 parent b2d08c6 commit 0af91e7

3 files changed

Lines changed: 28 additions & 36 deletions

File tree

windows/APIExample/APIExample/APIExample.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<ProjectGuid>{DB16CA2F-3910-4449-A5BD-6A602B33BE0F}</ProjectGuid>
2424
<Keyword>MFCProj</Keyword>
2525
<RootNamespace>APIExample</RootNamespace>
26-
<WindowsTargetPlatformVersion>10.0.19041.0</WindowsTargetPlatformVersion>
26+
<WindowsTargetPlatformVersion>10.0.17763.0</WindowsTargetPlatformVersion>
2727
</PropertyGroup>
2828
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
2929
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">

windows/APIExample/APIExample/Advanced/RTMPStream/AgoraRtmpStreaming.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ LRESULT CAgoraRtmpStreamingDlg::OnEIDUserJoined(WPARAM wParam, LPARAM lParam)
473473
{
474474
m_liveTransCoding.userCount = 2;
475475
m_liveTransCoding.transcodingUsers = new TranscodingUser[2];
476-
TranscodingUser localUser = m_liveTransCoding.transcodingUsers[0];
476+
TranscodingUser localUser = m_liveTransCoding.transcodingUsers[0];
477477
TranscodingUser tanrsCodingUser;
478478
tanrsCodingUser.uid = wParam;
479479
tanrsCodingUser.alpha = 1;

windows/APIExample/APIExample/Advanced/ScreenShare/AgoraScreenCapture.cpp

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,19 @@ BOOL CAgoraScreenCapture::OnInitDialog()
259259

260260
void CAgoraScreenCapture::InitMonitorInfos()
261261
{
262-
m_monitors.EnumMonitor();
262+
m_monitors.EnumMonitor();
263263

264264
std::vector<CMonitors::MonitorInformation> infos = m_monitors.GetMonitors();
265-
CString str = _T("");
265+
for (size_t i = 0; i < infos.size(); i++) {
266+
char szName[MAX_PATH] = { 0 };
267+
sprintf_s(szName, MAX_PATH, "Display%d", i + 1);
268+
CString strDevice = infos[i].monitorInfo.szDevice;
269+
strDevice.Replace(L"\\\\.\\", L"");
270+
m_cmbScreenRegion.InsertString(i, strDevice.GetBuffer(0));
271+
}
272+
m_cmbScreenRegion.SetCurSel(0);
273+
274+
/*CString str = _T("");
266275
for (size_t i = 0; i < infos.size(); i++) {
267276
RECT rcMonitor = infos[i].monitorInfo.rcMonitor;
268277
CString strInfo;
@@ -278,8 +287,11 @@ void CAgoraScreenCapture::InitMonitorInfos()
278287
}
279288
280289
m_cmbScreenRegion.InsertString(infos.size(), _T("Select Window Hwnd Rect Area"));
281-
m_staScreenInfo.SetWindowText(str);
282-
m_cmbScreenRegion.SetCurSel(0);
290+
m_staScreenInfo.SetWindowText(str);*/
291+
292+
293+
//m_cmbScreenRegion.SetCurSel(0);
294+
283295
}
284296

285297
//The JoinChannel button's click handler.
@@ -775,37 +787,17 @@ void CAgoraScreenCapture::OnBnClickedButtonStartShareScreen()
775787
m_screenShare = !m_screenShare;
776788
if (m_screenShare) {
777789
int sel = m_cmbScreenRegion.GetCurSel();
778-
agora::rtc::Rectangle regionRect = { 0,0,0,0 }, screenRegion = {0,0,0,0};
779-
if (sel < m_monitors.GetMonitorCount())
780-
{//share screen rect area
781-
//regionRect = m_monitors.GetMonitorRectangle(sel);
782-
//screenRegion = m_monitors.GetScreenRect();
783-
screenRegion = m_monitors.GetMonitorRectangle(sel);
784-
//m_monitors.GetMonitors()[1].scale_den;
785-
regionRect = { 0,0,m_monitors.GetMonitorRectangle(sel).width,m_monitors.GetMonitorRectangle(sel).height };
786-
}
787-
else {
788-
// get selected window HWND
789-
if (m_cmbScreenCap.GetCurSel() != m_cmbScreenCap.GetCount() - 1) {
790-
HWND hWnd = NULL;
791-
hWnd = m_listWnd.GetAt(m_listWnd.FindIndex(m_cmbScreenCap.GetCurSel()));
792-
HMONITOR hMonitor = MonitorFromWindow(hWnd, MONITOR_DEFAULTTONEAREST);
793-
if (!m_monitors.CheckMonitorValid(hMonitor)) {
794-
AfxMessageBox(_T("The monitor that window is located in can not be shared.\nThe monitor rect area has negative cordinate."));
795-
return;
796-
}
797-
798-
m_monitors.GetMonitorRectangle(hMonitor, screenRegion);
799-
m_monitors.GetWindowRect(hWnd, regionRect);
800-
}
801-
}
802-
803-
m_monitors.GetScreenRect();
790+
agora::rtc::Rectangle regionRect = { 0,0,0,0 };
804791
ScreenCaptureParameters capParam;
805-
806-
m_rtcEngine->startScreenCaptureByScreenRect(screenRegion, regionRect, capParam);
807-
m_lstInfo.InsertString(m_lstInfo.GetCount() - 1, _T("startScreenCaptureByScreenRect"));
808-
792+
CString displayId = L"";
793+
m_cmbScreenRegion.GetWindowText(displayId);
794+
int id = _ttoi(displayId.Mid(strlen("display"))) - 1;
795+
m_rtcEngine->startScreenCaptureByDisplayId(id, regionRect, capParam);
796+
797+
m_lstInfo.InsertString(m_lstInfo.GetCount() - 1, _T("startScreenCaptureByDisplayId"));
798+
CString strInfo;
799+
strInfo.Format(_T("DisplayId: %d"), id);
800+
m_lstInfo.InsertString(m_lstInfo.GetCount() - 1, strInfo);
809801
m_btnShareScreen.SetWindowText(screenShareCtrlStopShare);
810802
//start preview in the engine.
811803
m_rtcEngine->startPreview();

0 commit comments

Comments
 (0)