Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 81345d0

Browse files
committed
fix win virtual background
1 parent 22244fe commit 81345d0

File tree

5 files changed

+69
-60
lines changed

5 files changed

+69
-60
lines changed

windows/APIExample/APIExample/APIExample.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ BEGIN
578578
LTEXT "Video Source Background",IDC_STATIC_BACKGROUND,154,333,81,8
579579
COMBOBOX IDC_COMBO_BACKGROUND_TYPE,244,331,76,30,CBS_DROPDOWN | CBS_SORT | WS_VSCROLL | WS_TABSTOP
580580
LTEXT "Background Color",IDC_STATIC_COLOR,334,332,57,8
581-
COMBOBOX IDC_COMBO_COLOR,411,331,76,30,CBS_DROPDOWN | CBS_SORT | WS_VSCROLL | WS_TABSTOP
581+
COMBOBOX IDC_COMBO_COLOR,411,331,76,30,CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP
582582
PUSHBUTTON "Image File Path",IDC_BUTTON_IMAGE,331,329,73,14
583583
EDITTEXT IDC_EDIT_IMAGE_PATH,411,329,144,14,ES_AUTOHSCROLL
584584
CONTROL "Report",IDC_CHECK_REPORT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,570,325,38,10

windows/APIExample/APIExample/APIExample.vcxproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ if exist $(SolutionDir)APIExample\res (copy $(SolutionDir)APIExample\res\local.b
188188
<IntrinsicFunctions>true</IntrinsicFunctions>
189189
<SDLCheck>false</SDLCheck>
190190
<PreprocessorDefinitions>WIN32;_WINDOWS;NDEBUG;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions);</PreprocessorDefinitions>
191-
<AdditionalIncludeDirectories>$(SolutionDir)libs\include;$(solutionDir)ThirdParty\libYUV;$(ProjectDir);$(ProjectDir)RtcChannelHelperPlugin;$(solutionDir)MediaPlayerPart\include</AdditionalIncludeDirectories>
191+
<AdditionalIncludeDirectories>$(SolutionDir)libs\include;$(solutionDir)ThirdParty\libYUV;$(ProjectDir);$(ProjectDir)RtcChannelHelperPlugin;$(solutionDir)MediaPlayerPart\high_level_api\include</AdditionalIncludeDirectories>
192192
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
193193
</ClCompile>
194194
<Link>
@@ -215,6 +215,7 @@ if exist $(SolutionDir)libs (copy $(SolutionDir)libs\x86\*.dll $(SolutionDir)$(C
215215
if exist zh-cn.ini (copy zh-cn.ini $(SolutionDir)$(Configuration))
216216
if exist en.ini (copy en.ini $(SolutionDir)$(Configuration))
217217
if exist $(SolutionDir)MediaPlayerPart (copy $(SolutionDir)MediaPlayerPart\dll\AgoraMediaPlayer.dll $(SolutionDir)$(Configuration))
218+
if exist $(SolutionDir)MediaPlayerPart (copy $(SolutionDir)MediaPlayerPart\dll\libagora-player-ffmpeg.dll $(SolutionDir)$(Configuration))
218219
if exist $(SolutionDir)APIExample\res (copy $(SolutionDir)APIExample\res\remote.bmp $(SolutionDir)$(Configuration))
219220
if exist $(SolutionDir)APIExample\res (copy $(SolutionDir)APIExample\res\local.bmp $(SolutionDir)$(Configuration))</Command>
220221
</PostBuildEvent>
@@ -226,7 +227,7 @@ if exist $(SolutionDir)APIExample\res (copy $(SolutionDir)APIExample\res\local.b
226227
<EnableDpiAwareness>PerMonitorHighDPIAware</EnableDpiAwareness>
227228
</Manifest>
228229
<PreBuildEvent>
229-
<Command>$(SolutionDir)installThirdParty) x86</Command>
230+
<Command>$(SolutionDir)installThirdParty.bat x86</Command>
230231
</PreBuildEvent>
231232
</ItemDefinitionGroup>
232233
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">

windows/APIExample/APIExample/Basic/LiveBroadcasting/CLiveBroadcastingDlg.cpp

Lines changed: 61 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ BEGIN_MESSAGE_MAP(CLiveBroadcastingDlg, CDialogEx)
163163
ON_MESSAGE(WM_MSGID(EID_LOCAL_VIDEO_STATE_CHANGED), &CLiveBroadcastingDlg::onEIDLocalVideoStateChanged)
164164
ON_MESSAGE(WM_MSGID(EID_REMOTE_VIDEO_STATS), &CLiveBroadcastingDlg::onEIDRemoteVideoStats)
165165
ON_BN_CLICKED(IDC_CHECK_REPORT, &CLiveBroadcastingDlg::OnBnClickedCheckReport)
166+
ON_CBN_SELCHANGE(IDC_COMBO_COLOR, &CLiveBroadcastingDlg::OnSelchangeComboColor)
166167
END_MESSAGE_MAP()
167168

168169

@@ -193,8 +194,8 @@ BOOL CLiveBroadcastingDlg::OnInitDialog()
193194
m_cmbBackground.SetCurSel(0);
194195
i = 0;
195196
m_cmbColor.InsertString(i++, videoBackgroundSourceTypeRed);
196-
m_cmbColor.InsertString(i++, videoBackgroundSourceTypeBlue);
197197
m_cmbColor.InsertString(i++, videoBackgroundSourceTypeGreen);
198+
m_cmbColor.InsertString(i++, videoBackgroundSourceTypeBlue);
198199
m_cmbColor.SetCurSel(0);
199200
m_chkEnableBackground.SetWindowText(videoBackgroundSourceTypeEnable);
200201
m_btnImagePath.SetWindowText(videoBackgroundSourceTypeImagePath);
@@ -237,6 +238,7 @@ void CLiveBroadcastingDlg::CreateAllVideoWnds()
237238
for (int i = 0; i < VIDEO_COUNT; ++i) {
238239
m_videoWnds[i].Create(NULL, NULL, WS_CHILD | WS_VISIBLE | WS_BORDER | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, CRect(0, 0, 1, 1), this, IDC_BASEWND_VIDEO + i);
239240
//set window background color.
241+
240242
m_videoWnds[i].SetFaceColor(RGB(0x58, 0x58, 0x58));
241243
}
242244
}
@@ -768,56 +770,60 @@ void CLiveBroadcastingDlg::OnBnClickedButtonImage()
768770
// TODO: Add your control notification handler code here
769771
}
770772

771-
772-
void CLiveBroadcastingDlg::OnBnClickedCheckEnableBackground()
773+
void CLiveBroadcastingDlg::SetVideoSource()
773774
{
774775
agora::rtc::VirtualBackgroundSource source;
775-
if (m_chkEnableBackground.GetCheck()) {
776-
source.background_source_type = (agora::rtc::VirtualBackgroundSource::BACKGROUND_SOURCE_TYPE)m_cmbBackground.GetCurSel();
776+
source.background_source_type = (agora::rtc::VirtualBackgroundSource::BACKGROUND_SOURCE_TYPE)m_cmbBackground.GetCurSel();
777777

778-
if (m_cmbBackground.GetCurSel() == 0) {
779-
m_staBackColor.ShowWindow(SW_HIDE);
780-
m_cmbColor.ShowWindow(SW_HIDE);
781-
m_btnImagePath.ShowWindow(SW_HIDE);
782-
m_edtImagePath.ShowWindow(SW_HIDE);
783-
}
784-
else if (m_cmbBackground.GetCurSel() == 1) {
785-
m_staBackColor.ShowWindow(SW_HIDE);
786-
m_cmbColor.ShowWindow(SW_SHOW);
787-
m_btnImagePath.ShowWindow(SW_HIDE);
788-
m_edtImagePath.ShowWindow(SW_HIDE);
789-
if (m_cmbColor.GetCurSel() == 0)
790-
source.color = 0xFF0000;
791-
else if (m_cmbColor.GetCurSel() == 1)
792-
source.color = 0x00FF00;
793-
else if (m_cmbColor.GetCurSel() == 2)
794-
source.color = 0x0000FF;
795-
}
796-
else if (m_cmbBackground.GetCurSel() == 2) {
797-
m_staBackColor.ShowWindow(SW_HIDE);
798-
m_cmbColor.ShowWindow(SW_HIDE);
799-
m_btnImagePath.ShowWindow(SW_SHOW);
800-
m_edtImagePath.ShowWindow(SW_SHOW);
801-
802-
LPCTSTR lpszFilter = L"BMP Files|*.bmp|JPG Files|*.jpg|PNG Files|*.ong||";
803-
CFileDialog dlg(TRUE, lpszFilter, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, lpszFilter, NULL);
804-
CString filename;
805-
CFile file;
806-
if (dlg.DoModal() == IDOK)
807-
{
808-
filename = dlg.GetPathName();
809-
m_edtImagePath.SetWindowText(filename);
810-
source.source = cs2utf8(filename).c_str();
811-
}
778+
if (m_cmbBackground.GetCurSel() == 0) {
779+
m_staBackColor.ShowWindow(SW_HIDE);
780+
m_cmbColor.ShowWindow(SW_HIDE);
781+
m_btnImagePath.ShowWindow(SW_HIDE);
782+
m_edtImagePath.ShowWindow(SW_HIDE);
783+
}
784+
else if (m_cmbBackground.GetCurSel() == 1) {
785+
m_staBackColor.ShowWindow(SW_HIDE);
786+
m_cmbColor.ShowWindow(SW_SHOW);
787+
m_btnImagePath.ShowWindow(SW_HIDE);
788+
m_edtImagePath.ShowWindow(SW_HIDE);
789+
if (m_cmbColor.GetCurSel() == 0)
790+
source.color = 0xFF0000;
791+
else if (m_cmbColor.GetCurSel() == 1)
792+
source.color = 0x00FF00;
793+
else if (m_cmbColor.GetCurSel() == 2)
794+
source.color = 0x0000FF;
795+
}
796+
else if (m_cmbBackground.GetCurSel() == 2) {
797+
m_staBackColor.ShowWindow(SW_HIDE);
798+
m_cmbColor.ShowWindow(SW_HIDE);
799+
m_btnImagePath.ShowWindow(SW_SHOW);
800+
m_edtImagePath.ShowWindow(SW_SHOW);
801+
802+
LPCTSTR lpszFilter = L"BMP Files|*.bmp|JPG Files|*.jpg|PNG Files|*.ong||";
803+
CFileDialog dlg(TRUE, lpszFilter, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, lpszFilter, NULL);
804+
CString filename;
805+
CFile file;
806+
if (dlg.DoModal() == IDOK)
807+
{
808+
filename = dlg.GetPathName();
809+
m_edtImagePath.SetWindowText(filename);
810+
source.source = cs2utf8(filename).c_str();
812811
}
812+
}
813+
814+
m_rtcEngine->enableVirtualBackground(true, source);
815+
}
813816

817+
void CLiveBroadcastingDlg::OnBnClickedCheckEnableBackground()
818+
{
819+
if (m_chkEnableBackground.GetCheck()) {
820+
SetVideoSource();
814821
m_staBackground.ShowWindow(SW_SHOW);
815822
m_cmbBackground.ShowWindow(SW_SHOW);
816823
m_btnImagePath.ShowWindow(SW_SHOW);
817-
818-
m_rtcEngine->enableVirtualBackground(true, source);
819824
}
820825
else {
826+
agora::rtc::VirtualBackgroundSource source;
821827
m_staBackColor.ShowWindow(SW_HIDE);
822828
m_staBackground.ShowWindow(SW_HIDE);
823829
m_cmbBackground.ShowWindow(SW_HIDE);
@@ -830,21 +836,7 @@ void CLiveBroadcastingDlg::OnBnClickedCheckEnableBackground()
830836

831837
void CLiveBroadcastingDlg::OnSelchangeComboBackgroundType()
832838
{
833-
if (m_cmbBackground.GetCurSel() == 0) {
834-
m_staBackColor.ShowWindow(SW_HIDE);
835-
m_cmbColor.ShowWindow(SW_HIDE);
836-
m_btnImagePath.ShowWindow(SW_HIDE);
837-
}
838-
else if (m_cmbBackground.GetCurSel() == 1) {
839-
m_staBackColor.ShowWindow(SW_SHOW);
840-
m_cmbColor.ShowWindow(SW_SHOW);
841-
m_btnImagePath.ShowWindow(SW_HIDE);
842-
}
843-
else {
844-
m_staBackColor.ShowWindow(SW_HIDE);
845-
m_cmbColor.ShowWindow(SW_HIDE);
846-
m_btnImagePath.ShowWindow(SW_SHOW);
847-
}
839+
SetVideoSource();
848840
}
849841

850842
LRESULT CLiveBroadcastingDlg::OnEIDNetworkQuality(WPARAM wParam, LPARAM lParam) {
@@ -1141,3 +1133,16 @@ void CLiveBroadcastingDlg::OnBnClickedCheckReport()
11411133
{
11421134
m_eventHandler.SetReport(m_chkReport.GetCheck() != 0);
11431135
}
1136+
1137+
1138+
void CLiveBroadcastingDlg::OnSelchangeComboColor()
1139+
{
1140+
agora::rtc::VirtualBackgroundSource source;
1141+
if (m_cmbColor.GetCurSel() == 0)
1142+
source.color = 0xFF0000;
1143+
else if (m_cmbColor.GetCurSel() == 1)
1144+
source.color = 0x00FF00;
1145+
else if (m_cmbColor.GetCurSel() == 2)
1146+
source.color = 0x0000FF;
1147+
m_rtcEngine->enableVirtualBackground(true, source);
1148+
}

windows/APIExample/APIExample/Basic/LiveBroadcasting/CLiveBroadcastingDlg.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,4 +278,7 @@ class CLiveBroadcastingDlg : public CDialogEx
278278
CEdit m_edtImagePath;
279279
afx_msg void OnBnClickedCheckReport();
280280
CButton m_chkReport;
281+
afx_msg void OnSelchangeComboColor();
282+
283+
void SetVideoSource();
281284
};

windows/APIExample/APIExample/zh-cn.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ Video.Background.Source.Blur=
299299
Video.Background.Source.Enable=设置视频源背景
300300
Video.Background.Source.Color.Red=红色
301301
Video.Background.Source.Color.Blue=蓝色
302-
Video.Backgro und.Source.Color.Green=绿色
302+
Video.Background.Source.Color.Green=绿色
303303
Video.Background.Source.ImagePath=图片路径
304304

305305
SpatialAudio=空间音频

0 commit comments

Comments
 (0)