Last updated: 2021-05-06 18:45:19

    TRTC supports screen sharing via the primary stream and substream on Windows:

    • Substream sharing
      In TRTC, screen sharing images can be assigned a dedicated stream, which is called the substream (substream). Substream sharing means that an anchor publishes camera and screen sharing images at the same time. This is the scheme used by VooV Meeting. You can enable substream sharing by setting the TRTCVideoStreamType parameter to TRTCVideoStreamTypeSub when calling the startScreenCapture API. A dedicated API startRemoteSubStreamView is used for the playback of substream video.

    • Primary stream sharing
      In TRTC, the channel via which camera images are published is the primary stream (bigstream). Primary stream sharing means publishing screen sharing images via the primary stream. In this mode, the anchor publishes only one stream, which may be the camera images or screen sharing images. You can enable this mode by setting the TRTCVideoStreamType parameter to TRTCVideoStreamTypeBig when calling the startScreenCapture API.

    Supported Platforms

    iOS Android macOS Windows Electron WeChat Mini Program Chrome
    ×

    APIs

    Getting Sharable Windows

    You can call getScreenCaptureSources and get a list of sharable windows from the output parameter sourceInfoList.

    Note:

    On Windows, the desktop counts as a window too. When two monitors are used, you can find a desktop window for each monitor. Therefore, the list returned by getScreenCaptureSources includes the desktop window too.

    Each sourceInfo in sourceInfoList represents a shareable window, which consists of the following fields:

    Field Type Description
    Type TRTCScreenCaptureSourceType Capturing source type, which may be windows or screens
    sourceId HWND Capturing source ID.
  • If the capturing source type is windows, this field indicates a window handle.
  • if it is screens, this field indicates a screen ID.
  • SourceName String Window name. If the capturing source type is screens, the value returned is Screen0, Screen1, and so on.
    ThumbWidth Int32 Window thumbnail width
    ThumbHeight Int32 Window thumbnail height
    ThumbBGRA Buffer Window thumbnail binary buffer
    IconWidth Int32 Window icon width
    IconHeight Int32 Window icon height
    IconBGRA Buffer Window icon binary buffer

    Based on the above information, you can display a simple list of sharable targets for users to choose from, as shown below:

    Selecting Sharing Target

    The TRTC SDK supports three screen sharing modes, which you can specify using selectScreenCaptureTarget.

    • Share entire screen:
      In this mode, the entire screen is shared. You can split the screen with multiple monitors. To use this mode, specify a source in sourceInfoList whose type is TRTCScreenCaptureSourceTypeScreen, and set captureRect to { 0, 0, 0, 0 }.

    • Share portion of screen:
      In this mode, a portion of the screen is shared, whose coordinates you need to specify. To use this mode, specify a source in sourceInfoList whose type is TRTCScreenCaptureSourceTypeScreen, and set captureRect to a value other than NULL, e.g., { 100, 100, 300, 300 }.

    • Share a window:
      In this mode, the window you specify is shared. To use this mode, specify a source in sourceInfoList whose type is TRTCScreenCaptureSourceTypeWindow, and set captureRect to { 0, 0, 0, 0 }.

    Note:

    Two additional parameters

    • The captureMouse parameter is used to specify whether or not to capture the cursor.
    • The highlightWindow parameter is used to specify whether or not to highlight the window being shared and remind users to move the window when it is covered. The relevant UI design is implemented within the SDK.

    Starting Screen Sharing

    • After selecting a sharing target, you can call the startScreenCapture API to start screen sharing.
    • During screen sharing, you can call selectScreenCaptureTarget to change the sharing target.
    • The difference between pauseScreenCapture and stopScreenCapture is that the former pauses screen capturing and displays the image at the moment of pausing. Remote users see the last frame of video before pausing until screen capturing is resumed.
        /**
        * \brief 7.5 **Screen Sharing** Start screen sharing
        * \param: rendHwnd - HWND of the preview window
        */
        void startScreenCapture(HWND rendHwnd);
    
        /**
        * \brief 7.6 **Screen Sharing** Pause screen sharing
        */
        void pauseScreenCapture();
    
        /**
        * \brief 7.7 **Screen Sharing** Resume screen sharing
        */
        void resumeScreenCapture();
    
        /**
        * \brief 7.8 **Screen Sharing** Stop screen sharing
        */
        void stopScreenCapture();
    

    Setting Video Quality

    You can use the setSubStreamEncoderParam API to set the video quality of screen sharing, including resolution, bitrate, and frame rate. We recommend the following settings:

    Clarity Resolution Frame Rate Bitrate
    HD+ 1920 x 1080 10 800 kbps
    HD 1280 x 720 10 600 kbps
    SD 960 x 720 10 400 kbps

    Watching Shared Screen

    • Watch screens shared by macOS/Windows users
      When a macOS/Windows user in a room starts screen sharing, the screen will be shared through a substream, and other users in the room will be notified through onUserSubStreamAvailable in TRTCCloudDelegate.
      Users who want to watch the shared screen can start rendering the substream image of the remote user by calling the startRemoteSubStreamView API.

    • Watch screens shared by Android/iOS users
      When an Android/iOS user starts screen sharing, the screen will be shared through the primary stream, and other users in the room will be notified through onUserVideoAvailable in TRTCCloudDelegate.
      Users who want to watch the shared screen can start rendering the primary stream of the remote user by calling the startRemoteView API.

    //Sample code: watch the shared screen
    void CTRTCCloudSDK::onUserSubStreamAvailable(const char * userId, bool available)
    {
            LINFO(L"onUserSubStreamAvailable userId[%s] available[%d]\n", UTF82Wide(userId).c_str(), available);
           if (available)  {
                 startRemoteSubStreamView(userId, hWnd);
           } else {
                 stopRemoteSubStreamView(userId);
           }
    }
    

    FAQs

    ** Can there be multiple channels of screen sharing streams in the same room at the same time?**
    Currently, each TRTC room can have only one channel of screen sharing stream.

    ** When a specified window is shared (SourceTypeWindow), if the window size changes, will the resolution of the video stream change accordingly?**
    By default, the TRTC SDK automatically adjusts encoding parameters based on the size of the shared window.
    If you want to fix the resolution, call the setSubStreamEncoderParam API to set the encoding parameters for screen sharing or set the encoding parameters when calling startScreenCapture.