With the rapid development of audio and video, both in commercial and entertainment, there are many practical applications of the scene, the gameplay is more and more, followed by the improvement of derivative function requirements.

Screen sharing is one of the most important features for commercial and entertainment scenarios.

Introduction to the

Screen sharing includes screen capture and video streaming push. Different from audio and video interaction, screen sharing pays attention to high-definition real-time, which requires high bandwidth and equipment performance. This article focuses on the tuning and implementation steps of anyRTC on screen sharing. Developers do not need to pay attention to the details of function implementation, but only need to understand the ORDER of API calls. The following uses the Windows SDK as an example to describe the anyRTC screen sharing function.

Windows SDK screen sharing features currently supported a screen sharing and sharing and gathering to share three types in the region and the screen sharing and sharing can be combined into one region, region share area designated for the selected screen sharing, if want to share the entire screen, you need to specify the entire screen area location. These three collection methods have their own specific usage scenarios. Developers only need to select the corresponding sharing type according to their actual application scenarios.

AnyRTC SDK does not provide methods for retrieving display screen information and Window IDS. You will need to use Native Windows methods such as EnumDisplayMonitors and EnumWindows to retrieve these information.

Screen sharing & Area collection sharing

In Windows, the screen of each monitor is on the same virtual screen. You can obtain the screen information and Window ID through the native Windows method.

The specific implementation steps are as follows:

  1. Gets the display screen information list.
void CArScreenCapture::InitMonitorInfos(a)
{
    M_monitors is an instance of the CMonitors class. Reference sample project for a concrete implementation of the CMonitors class.
    // m_monitors calls EnumMonitor to get a list of monitor screen information. Refer to the sample project for a detailed implementation of the EnumMonitor method.
    m_monitors.EnumMonitor(a);// Define infOS vector to store display screen information list.
    std::vector<CMonitors::MonitorInformation>  infos = m_monitors.GetMonitors(a); CString str = _T("");
    // Get the Rectangle coordinates of each monitor screen on the virtual screen
    for (size_t i = 0; i < infos.size(a); i++) { RECT rcMonitor = infos[i].monitorInfo.rcMonitor; CString strInfo; strInfo.Format(_T("Screen%d: rect = {%d, %d, %d, %d} ")
            , i + 1, rcMonitor.left, rcMonitor.top, rcMonitor.right, rcMonitor.bottom);
        }
        str += strInfo;
        m_cmbScreenRegion.InsertString(i, utf82cs(infos[i].monitorName));
    }
    m_cmbScreenRegion.InsertString(infos.size(), _T("Select Window Hwnd Rect Area"));
    m_staScreenInfo.SetWindowText(str);
    m_cmbScreenRegion.SetCurSel(0);
}
Copy the code
  1. Screen sharing is achieved through the Rectangle coordinates of the monitor screen to be shared on the virtual screen and the Rectangle coordinates of the area to be shared on the monitor screen.
void CArScreenCapture::OnBnClickedButtonStartShareScreen(a)
{ m_screenShare = ! m_screenShare;if (m_screenShare) {
        // Get the selected monitor screen
        int sel = m_cmbScreenRegion.GetCurSel(a); agora::rtc::Rectangle regionRect = {0.0.0.0 }, screenRegion = {0.0.0.0};

        // Gets the Rectangle coordinates of the specified area to be shared across the monitor screen.
        // The GetMonitorRectangle method is described in the sample project.
        regionRect = m_monitors.GetMonitorRectangle(sel);
        // Get the Rectangle coordinates of the monitor screen in the virtual screen. See the example project for an implementation of the GetScreenRect method.
        screenRegion = m_monitors.GetScreenRect(a); m_monitors.GetScreenRect(a);// Screen sharing encoding parameter configuration
        ScreenCaptureParameters capParam;
        // Start screen sharing
        m_rtcEngine->startScreenCaptureByScreenRect(screenRegion, regionRect, capParam);
        m_btnShareScreen.SetWindowText(screenShareCtrlStopShare);

        m_btnStartCap.EnableWindow(FALSE);

    }
    else {
        // Stop screen sharing
        m_rtcEngine->stopScreenCapture(a); m_btnShareScreen.SetWindowText(screenShareCtrlShareSCreen);
        m_btnStartCap.EnableWindow(TRUE); }}Copy the code

Window to share

Windows allocates one windowId for each window. The data type is HWND. This ID corresponds to a unique Windows window. For compatibility with x86 and X64 systems, the view_t type is used.

By obtaining the windowId, we can implement window sharing on Windows platforms by following the following steps:

  1. Gets the Window ID of the Window you want to share
BOOL CALLBACK EnumProc(HWND hWnd, LPARAM IParam)
{
    // Get only the visual window ID, ignore the pop-up window and directory window
    LONG IStyle = ::GetWindowLong(hWnd, GWL_STYLE);
    if((IStyle&WS_VISIBLE) ! =0&& (IStyle&(WAS_POPUP | WA_SYSMENU)) ! =0) {
        HWND window_id = hWnd;
   }
    return TRUE;
}
EnumWindows(&EnumProc, NULL);
Copy the code
  1. Share Windows by Window ID
// Specify a shared screen or windowRECT rc; ar::rtc::Rectangle rcCap; ar::rtc::Rectangle screenRegion = { rc.left, rc.right, rc.right - rc.left, rc.bottom - rc.top }; capParam.dimensions.width = rc.right - rc.left; capParam.dimensions.height = rc.bottom - rc.top; : :GetWindowRect(hWnd, &rc);
ScreenCaptureParameters capParam;
capParam.dimensions.width = rc.right - rc.left;
capParam.dimensions.height = rc.bottom - rc.top;

VideoContentHint contentHint;
ar::rtc::Rect rt;

// Start sharing window
ret = m_lpAREngine->startScreenCaptureByWindowId(hWnd, rcCap, capParam);

// Update screen share encoding parameters
m_lpAREngine->updateScreenCaptureParameters(capParam);

// Update the screen shared area
m_lpAREngine->updateScreenCaptureRegion(screenRegion);

// Set the screen shared content type
m_lpAREngine->setScreenCaptureContentHint(contentHint);

// Stop screen sharing
m_lpAREngine->stopScreenCapture(a);Copy the code

The above is the introduction of Screen sharing on Windows platform. If you want to know more about platforms such as Android and iOS, you can click anyRTC Document Center to view it.

Application scenarios

The above is the function introduction of screen sharing. The following is the specific application scenario of screen sharing.

Online education:

Suitable for large class, small class and other educational scenes, teachers can share the required courseware and materials to students through screen sharing, so that teaching becomes more efficient, improve efficiency and save time.

Live game:

The game host can collect the screen content in real time and share it with all the audience in the way of live broadcasting, so that the audience can experience the game from the same perspective as the host. This can improve the user’s viewing experience, so that users can have a sense of immersive. Make the user watch the sense of substitution stronger, increase the user’s stickiness.

Video conference:

The moderator can share the material on the computer with the remote participants, and all participants can watch the real-time video stream on the screen to achieve the purpose of information sharing. The moderator no longer has to mention distributing documents, because participants can see any documents or files on the presenter’s screen, and can even ask the conferees to send them through the transfer feature of the screen sharing tool.

Remote demo:

During remote collaboration or operation demonstration, you can collect information from the screen or window to demonstrate specific operation steps, helping others quickly understand the operation. Online presentations that screen sharing allows are the perfect way to organize interactions with customers and clients. With screen sharing applications, not only can sales people present their products, but they can also invite customers to experience projects such as software programs by providing remote control of a PC keyboard or mouse. This is one of the best benefits of screen sharing tools.

Online training:

By using screen sharing tools in online training, organizations can save a lot of money because they don’t have to set up the entire projector setup and pay for external lectures. Instead, lecturers’ material can be easily shared from their PC screens via the screen sharing application for all attendees to view.

Instructors can even use such screen sharing capabilities as whiteboards or participant Pointers to interact with students, creating an interactive and entertaining learning environment.

In addition to the above Windows screen sharing, anyRTC has realized the screen sharing of the whole platform. Android terminal support screen sharing collection H264 format of screen sharing stream, to a large extent optimize the performance of Android; Seamless Replaykit on iOS; In addition to regional collection and sharing, the other two analysis functions have corresponding API calls. For more product details, pay attention to anyRTC.