# Screen sharing (/en/realtime-media/broadcast-streaming/build/manage-video-and-streaming/screen-sharing/unreal)

> For AI agents: see the complete documentation index at [llms.txt](/llms.txt).

During Broadcast Streaming sessions, hosts use the screen sharing feature in the Agora Video SDK to share their screen content with other users or viewers in the form of a video stream. Screen sharing is typically used in the following use-cases:

| Use-case                   | Description                                                                                                    |
| :------------------------- | :------------------------------------------------------------------------------------------------------------- |
| Online education           | Teachers share their slides, software, or other teaching materials with students for classroom demonstrations. |
| Game live broadcast        | Hosts share their game footage with the audience.                                                              |
| Interactive live broadcast | Anchors share their screens and interact with the audience.                                                    |
| Video conferencing         | Meeting participants share the screen to show a presentation or documents.                                     |
| Remote control             | A controlled terminal displays its desktop on the master terminal.                                             |

      
  
      
  
      
  
      
  
      
  
      
  
      
  
      
  
      
  
      
    Agora screen sharing offers the following advantages:

    * **Ultra HD quality experience**: Supports Ultra HD video (4K resolution, 60 FPS frame rate), giving users a smoother, high-definition, ultimate picture experience.
    * **Multi-app support**: Compatible with many mainstream apps such as WPS Office, Microsoft Office Power Point, Visual Studio Code, Adobe Photoshop, Windows Media Player, and Scratch. This makes it convenient for users to directly share specific apps.
    * **Multi-device support**: Supports multiple devices sharing at the same time. Screen sharing is compatible with Windows 8 systems, devices without independent graphics cards, dual graphics card devices, and external screen devices.
    * **Multi-platform adaptation**: Supports iOS, Android, macOS, Windows, Web, Unity, Flutter, React Native, Unreal Engine, and other platforms.
    * **High security**: Supports sharing only a single app or part of the screen. Also supports blocking specified app windows, effectively ensuring user information security.

    This page shows you how to implement screen sharing in your game.

    ## Understand the tech [#understand-the-tech-9]

    The screen sharing feature provides the following screen sharing modes for use in various use-cases:

    **Screen sharing use-cases**

    ![Screen Sharing Functionality](https://assets-docs.agora.io/images/video-sdk/screen-sharing-functionality.png)

    * **Share the entire screen**: Share your entire screen, including all the information on the screen. This feature supports collecting and sharing information from two screens at the same time.
    * **Share an app window**: If you don't want to share the entire screen with other users, you can share only the area within an app window.
    * **Share a designated screen area**: If you only want to share a portion of the screen or app window, you can set a sharing area when starting screen sharing.

    Screen sharing modes are available on different platforms as follows:

    * **Desktop** (Windows and macOS): Supports all screen sharing features listed above.

    * **Mobile** (Android and iOS): Only supports sharing the entire screen.

    ### Advanced features [#advanced-features-2]

    You can enable the following advanced screen sharing features by adjusting the parameters when starting screen sharing:

    * **Shield a specified app window**: When sharing the screen, if you don't want to expose a specific app window, you can choose to shield it so that the window will not appear in the shared screen.
    * **Stroke**: If you need to outline the area being shared, you can stroke a specified app window or screen and customize the width, color, and transparency of the stroke.
    * **Pin an app window to the front**: If you share multiple app windows at the same time, the windows may block each other. You can specify an app window and bring it to the front to prevent it from being blocked by other windows.
    * **Set the sharing scenario**: The SDK automatically adjusts the Quality of Experience (QOE) policy according to the scenario you choose:
      * When sharing documents, slides, tables, or in remote control applications, set the sharing scene to either **document** or **remote control**. The SDK prioritizes optimizing image quality and minimizing latency, thus enhancing the viewing experience for the recipient of the shared video.
      * When sharing games, movies, or live video broadcasts, set the shared scene to **game** or **video**. The SDK prioritizes smoothness of video at the receiving end.

    ## Prerequisites [#prerequisites-9]

    * To implement screen sharing, please make sure not to manually remove the screen sharing dynamic library (libagora\_screen\_capture\_extension.dll) when integrating the SDK, otherwise the function will not work properly.

    * Ensure that you have implemented the [SDK quickstart](../../index) in your project.

    ## Set up your project [#set-up-your-project-9]

    ## Implement screen sharing [#implement-screen-sharing-9]

    This section shows you how to implement screen sharing in your project. The basic API call sequence is shown in the figure below:

    **Screen share process**

    ![Screen Share Process](https://assets-docs.agora.io/images/video-sdk/screen-sharing-macos-unreal-windows.svg)

    To enable screen sharing, choose one of the following methods according to your use-case:

    * Call `startScreenCaptureByDisplayId` or `startScreenCaptureByWindowId` before joining the channel, then call `joinChannel [2/2]` to join the channel and set `publishScreenTrack` or `publishSecondaryScreenTrack` to `true` to start screen sharing.

    * Call `startScreenCaptureByDisplayId` or `startScreenCaptureByWindowId` after joining the channel, then call `updateChannelMediaOptions` to set `publishScreenTrack` or `publishSecondaryScreenTrack` to `true` to start screen sharing.

    The flow diagram and implementation steps in this article are based on the first use-case.

    ### Get resource list [#get-resource-list-2]

    Call `getScreenCaptureSources` to get an object list of screens and windows available for sharing. The list contains important information such as the **window ID** and **screen ID**. This enables users to choose a certain screen or window, through the thumbnails in the list, for sharing.

    ```cpp
    {
      // Get information about a specified shareable window or screen
      agora::rtc::IScreenCaptureSourceList* listCapture = m_rtcEngine->getScreenCaptureSources(sz, sz, true);
      for (int i = 0; i < listCapture->getCount(); i++)
      {
        // Returns information about a shareable window or screen
        agora::rtc::ScreenCaptureSourceInfo info = listCapture->getSourceInfo(i);
      }

      // Get the number of windows and screens that can be shared
      return static_cast<int>(m_listWnd.GetCount());
    }
    ```

    ### Enable screen sharing [#enable-screen-sharing-1]

    Depending on your application use-case, choose one of the following screen sharing methods.

    #### Share the entire screen [#share-the-entire-screen-2]

    Call `startScreenCaptureByDisplayId` with the following parameters to start sharing the whole screen:

    * Set `sourceId` to the `displayId` (screen ID) obtained in the resource list.
    * Set your desired video encoding properties in `captureParams`:
      * In document scenes or remote control scenes, it is recommended to set `dimensions` to **1920 × 1080** and `frameRate` as **10 FPS**.
      * In game scenes or video scenes, it is recommended to set `dimensions` to **960 × 720** and `frameRate` to **15 FPS**.

    ```cpp
    // Start sharing the specified screen
    m_rtcEngine->startScreenCaptureByDisplayId(id, regionRect, capParam);
    ```

    #### Share app window [#share-app-window-2]

    Call `startScreenCaptureByWindowId` with the following parameters to start sharing an app window:

    * Set `sourceId` to the `windowId` obtained in the resource list.
    * Set your desired video encoding properties in `captureParams`:
      * In document scenes or remote control scenes, it is recommended to set `dimensions` to **1920 × 1080** and `frameRate` as **10 FPS**.
      * In game scenes or video scenes, it is recommended to set `dimensions` to **960 × 720** and `frameRate` to **15 FPS**.

    ```cpp
    // Start sharing a specified app window
    ret = m_rtcEngine->startScreenCaptureByWindowId(hWnd, rcCapWnd, capParam);
    ```

    #### Share a designated area [#share-a-designated-area-2]

    Call `startScreenCaptureByDisplayId` or `startScreenCaptureByWindowId` method to start sharing, and set `regionRect` to the area you want to share relative to the whole screen or window. The sample code is as follows:

    ```cpp
    // Set the parameters of the area you want to share
    m_screenRegion = { 0,0,heightX,heightY };
    agora::rtc::Rectangle rcCapWnd = { m_screenRegion.x, m_screenRegion.y, (int)(m_screenRegion.width * scale), (int)(m_screenRegion.height * scale) };
    ...
    m_rtcEngine->startScreenCaptureByDisplayId(id, rcCapWnd, m_screenParam);
    ```

    <CalloutContainer type="info">
      <CalloutDescription>
        If the sharing area is set to extend beyond the boundaries of the screen, only the content within the screen is shared. If the width or height is set to 0, the entire screen is shared.
      </CalloutDescription>
    </CalloutContainer>

    ### Set up a screen sharing scenario (Optional) [#set-up-a-screen-sharing-scenario-optional]

    Call the `setScreenCaptureScenario` method to set the screen sharing scenario. Set the `screenScenario` to any one of the following according to the actual usage scenario:

    * `SCREEN_SCENARIO_DOCUMENT`: Document scenario
    * `SCREEN_SCENARIO_GAMING`: Game scenario
    * `SCREEN_SCENARIO_VIDEO`: Video scenario
    * `SCREEN_SCENARIO_RDC`: Remote control scenario

    ```cpp
    m_rtcEngine->setScreenCaptureScenario(type);
    ```

    ### Capture system audio (Optional) [#capture-system-audio-optional-3]

    To capture and publish the audio played in the shared screen or window simultaneously, call `enableLoopbackRecording` to start sound card capture.

    After you call this method, the audio played by other processes in the system is published to the remote end. To turn off sound card acquisition, call the method again.

    ### Join a channel and publish a screen sharing video stream [#join-a-channel-and-publish-a-screen-sharing-video-stream-2]

    Call `joinChannel`\[2/2] to join the channel and set the channel media options.

    ```cpp
    // Set Channel Media Options
    ChannelMediaOptions option;
    option.channelProfile = CHANNEL_PROFILE_LIVE_BROADCASTING;
    option.clientRoleType = CLIENT_ROLE_BROADCASTER;
    option.publishMicrophoneTrack = true;
    // Publish the screen captured video to the channel
    // To publish a second screen captured video in the channel, replace the next line of code with option.publishSecondaryScreenTrack = true；
    option.publishScreenTrack = true;
    // Join the channel
    m_rtcEngine->joinChannel("Your Token", "Your ChannelId", 0, option)
    ```

    #### Additional notes [#additional-notes-4]

    This article demonstrates publishing the screen sharing stream directly in the channel without publishing the stream captured by the camera. In a real-world scenario, the requirements may be different from the description in this document. Adjust the code logic based on your scenario.

    To publish the stream captured by the camera and the screen sharing stream at the same time, refer to the following steps:

    * Call `joinChannel`\[2/2] to join the first channel and publish the video stream captured by the camera in this channel.
    * Call `joinChannelEx` to join a second channel and publish a screen sharing stream.

    ### Update screen sharing area or parameters [#update-screen-sharing-area-or-parameters-1]

    To dynamically update the screen sharing area or parameters in the channel, call the following methods:

    * To update the shared region of the screen, call the `updateScreenCaptureRegion` method to reset the `regionRect` parameter and define a new sharing area.
    * * To update the screen sharing parameters, such as video encoding resolution, frame rate, bitrate, or to stroke the screen or app window, or block a specified
        window, call the `updateScreenCaptureParameters` method and update the `captureParams` parameter configuration.

    ```cpp
    // Update the screen share area
    int ret = m_rtcEngine->updateScreenCaptureRegion(rect);

    // Update screen sharing parameters
    int ret = m_rtcEngine->updateScreenCaptureParameters(m_screenParam);
    ```

    ### Stroke the screen [#stroke-the-screen-1]

    Depending on your scenario, you may stroke the shared screen or window in one of the following ways:

    * Stroke when enabling screen sharing: Call `startScreenCaptureByDisplayId` or `startScreenCaptureByWindowId`, set `enableHighLight` in `captureParams` to `true`, and set both `highLightColor` and `highLightWidth` to specify the stroke color and width.

    * Stroke after screen sharing is enabled: Call `updateScreenCaptureParameters`, set `enableHighLight` in `captureParams` to `true`, and set both `highLightColor` and `highLightWidth` to specify the stroke color and width.

    ```cpp
    bool highLigne = m_chkHighLight.GetCheck();
    m_screenParam.enableHighLight = highLigne;
    // Setting the stroke color of the screen
    m_screenParam.highLightColor = 0xFFFF0000;
    // Setting the stroke width of the screen
    m_screenParam.highLightWidth = 5;
    // Enable Screen Stroke
    int ret = m_rtcEngine->updateScreenCaptureParameters(m_screenParam);
    ```

    ### Block window [#block-window]

    Depending on your usage scenario, you may block a specified window in one of the following ways:

    * Block windows when enabling screen sharing: Call `startScreenCaptureByDisplayId`, set `excludeWindowList` in `captureParams` to the list of windows you want to block.

    * Block windows after screen sharing is enabled: Call `updateScreenCaptureParameters`, set `excludeWindowList` in `captureParams` to the list of windows you want to block.

    ```cpp
    m_screenParam.excludeWindowList = excludeViews;
    m_screenParam.excludeWindowCount = count;

    int ret = m_rtcEngine->updateScreenCaptureParameters(m_screenParam);
    ```

    <CalloutContainer type="info">
      <CalloutDescription>
        On the Windows platform, you can block up to 24 windows.
      </CalloutDescription>
    </CalloutContainer>

    ### Stop screen sharing [#stop-screen-sharing-4]

    Call `stopScreenCapture` to stop sharing the screen within a channel.

    ```cpp
    // Stop screen sharing
    ret = m_rtcEngine->stopScreenCapture();
    ```

    ### Limitations [#limitations-9]

    Be aware of the following limitations:

    * After turning on screen sharing, Agora uses the resolution of the screen sharing video stream as the billing standard. Please see [Pricing](../../reference/pricing) for details. The default resolution is 1280 × 720, but you can adjust it according to your business needs.
    * To share 4K Ultra-HD resolution video during screen sharing, your device needs to meet certain requirements. The minimum device specifications recommended by Agora are: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHZ.

    ## Reference [#reference-9]

    This section contains content that completes the information on this page, or points you to documentation that explains other aspects to this product.

    ### Sample project [#sample-project-9]

    Agora provides an open source Unreal Engine [sample project](https://github.com/AgoraIO/API-Examples/blob/main/windows/APIExample/APIExample/Advanced/ScreenShare/AgoraScreenCapture.cpp) on GitHub. Download and explore this project for a more detailed example.

    ### API reference [#api-reference-8]

    * [`getScreenCaptureSources`](https://api-ref.agora.io/en/video-sdk/unreal-engine/4.x/API/class_irtcengine.html#api_irtcengine_getscreencapturesources)

    * [`startScreenCaptureByDisplayId`](https://api-ref.agora.io/en/video-sdk/unreal-engine/4.x/API/class_irtcengine.html#api_irtcengine_startscreencapturebydisplayid)

    * [`startScreenCaptureByWindowId`](https://api-ref.agora.io/en/video-sdk/unreal-engine/4.x/API/class_irtcengine.html#api_irtcengine_startscreencapturebywindowid)

    * [`setScreenCaptureScenario`](https://api-ref.agora.io/en/video-sdk/unreal-engine/4.x/API/class_irtcengine.html#api_irtcengine_setscreencapturescenario)

    * [`updateScreenCaptureParameters`](https://api-ref.agora.io/en/video-sdk/unreal-engine/4.x/API/class_irtcengine.html#api_irtcengine_updatescreencaptureparameters)

    * [`updateScreenCaptureRegion`](https://api-ref.agora.io/en/video-sdk/unreal-engine/4.x/API/class_irtcengine.html#api_irtcengine_updatescreencaptureregion)

    * [`stopScreenCapture`\[1/2\]](https://api-ref.agora.io/en/video-sdk/unreal-engine/4.x/API/class_irtcengine.html#api_irtcengine_stopscreencapture)

    
  
      
  
