This tutorial mainly introduces how to implement a basic audio and video call.
Prerequisites
OS: Windows 7 or later.
Development environment: Visual Studio 2019 or later (v2022 is recommended).
Integration guideline
Step 1. Import TRTC SDK
1. Open Visual Studio and create your own MFC application. On the MFC Application page of the wizard, select Dialog based for Application type and default for other wizard configurations. Then click Finish.
2. Download the WIndows SDK and copy the decompressed SDK files to the directory where the .vcxproj file resides.
Step 2. Configure project
Double-click the .sln project file, Solution Explorer in the right toolbar > Right-click menu for the project > Properties, and perform the following configurations:
1. Add Additional Include Directories:
Following C/C++ > General > Additional Include Directories, add the SDK header directory:$(ProjectDir)SDK\CPlusPlus\Win64\include and $(ProjectDir)SDK\CPlusPlus\Win64\include\TRTC.
2. Add Additional Library Directories:
Following Linker > General > Additional Library Directories, add the SDK library directory: $(ProjectDir)SDK\CPlusPlus\Win64\lib.
After completing the preceding steps, click Run to print the SDK version number.
Note:
If you get the error message "module machine type 'x86' conflicts with target machine type 'x64' " , select 'x64' in the solution platform.
Step 3. Create TRTC instance
1. Reference the header file "ITRTCCloud.h" in the 'PROJECTNAME'.h file, make the class in this file publicly inherit from CWinApp and ITRTCCloudCallback, and declare listening events and TRTCCloud member variables.
#include "ITRTCCloud.h" // Include the TRTC header file
classCRTCWindowsApp:public CWinApp, public ITRTCCloudCallback
{
public:
CRTCWindowsApp();
// Overrides
public:
virtual BOOL InitInstance();
virtualvoidonError(TXLiteAVError errCode,constchar* errMsg,void* extraInfo)override;// Listen for the 'onError' event
virtualvoidonWarning(TXLiteAVWarning warningCode,constchar* warningMsg,void* extraInfo)override;// Listen for the 'onWarning' event
virtualvoidonEnterRoom(int result)override;// Listen for the 'onEnterRoom' event
virtualvoidonExitRoom(int reason)override;// Listen for the 'onExitRoom' event
// Get the TRTCCloud instance
static CRTCWindowsApp*GetInstance()
{
returnstatic_cast<CRTCWindowsApp*>(AfxGetApp());
}
// Implementation
DECLARE_MESSAGE_MAP()
public:
ITRTCCloud* trtc_cloud_;// Declare the TRTCCloud member variable
};
Note:
The project name created in this article is RTCWindows, replace it with the name of your own project or class throughout the access process.
2. Initialize the TRTC instance by calling getTRTCShareInstance in the InitInstance function of the 'PROJECTNAME'.h file.
// Initialize the TRTCCloud instance and add event listening
trtc_cloud_ =getTRTCShareInstance();
trtc_cloud_->addCallback(this);
Note:
Recommend to add the codes that initializes the TRTC instance below the SetRegistryKey(_T("Local AppWizard-Generated Applications")) method.
voidCRTCWindowsApp::onExitRoom(int reason){// Listen for the "onExitRoom" event and print the corresponding information
if(reason ==0){
MessageBox(NULL,TEXT("Exit current room by calling the 'exitRoom' api of sdk"),TEXT("Notice"), MB_OK | MB_ICONINFORMATION);
}elseif(reason ==1){
MessageBox(NULL,TEXT("Kicked out of the current room by server through the restful api"),TEXT("Notice"), MB_OK | MB_ICONINFORMATION);
}elseif(reason ==2){
MessageBox(NULL,TEXT("The current room is dissolved by server through the restful api"),TEXT("Notice"), MB_OK | MB_ICONINFORMATION);
}
}
Step 4. Enter the room
Add a Button component in the resource file IDD_TRTCDEMO_DIALOG, double-click the newly created Button. Then set the entry parameter TRTCParams and call enterRoom to successfully enter the room, which is usually called after clicking the Start Call button.
Parameter
Type
Description
sdkAppId
number
The sdkAppId of the audio and video application you created in TRTC Console.
1. In the resource file IDD_TRTCDEMO_DIALOG, click Toolbox in the left border and add Picture Control to the dialog box.
2. Select Properties from the right-click menu and select AFX_IDC_PICTURE for ID.
3. Add a Button component in the resource file IDD_TRTCDEMO_DIALOG, double-click the newly created Button. Initialize the pLocalVideoView andset the rendering parameter setLocalRenderParams for local preview, then call startLocalPreview for local preview. After successfully calling enterRoom, the stream push will start.
1. Listen to onUserVideoAvailable before entering the room. When you receive the onUserVideoAvailable(userId, true) notification, it means that there are video frames available to play in the road screen.
2. Call startRemoteView/stopRemoteView to play or stop the remote video.
trtcCloud->muteAllRemoteAudio(false);// Unmute all remote users
Step 9. Exit the room
Add a Button component in the resource file IDD_TRTCDEMO_DIALOG, double-click the newly created Button. Call exitRoom to exit the current room, and the TRTC SDK will notify you after check-out via the onExitRoom callback event.