Screen Sharing
  • Electron
  • Windows : C++
  • SDK Downloads
  • Sample Codes
  • Quick Starts
  • Best Practices
  • API Documents
  • Documentation
  • Screen Sharing
  • Quick Starts
  • Sharing Selected Screen

Sharing Selected Screen

Last updated:2022-03-22 13:06

1 Introduction

After setting to screen sharing, you can share different monitor contents according to the screen name under multiple monitors.

This article mainly describes how to set up screen sharing. For details: ExampleDemo.

2 Collection Call Process

1. Initialization

/*
Set log path and level
*/
zego_screencapture_set_log_level(kZegoLogLevelDebug, logDir);

/*
Set capture error callback
*/
zego_screencapture_reg_capture_error_notify((zego_screencapture_capture_error_notify_func)OnCaptureError, this);

/*
Set capture data callback
*/
zego_screencapture_reg_captured_frame_available_notify((zego_screencapture_captured_frame_available_notify_func)OnCapturedFrameAvailable, this);

/*
Initialization
*/
zego_screencapture_init();

Call the method zego_screencapture_set_log_level, and set the custom logDir, then the ScreenCapture will generate the relevant log.

2. Set Capture Parameters

/*
Set the capture frame rate for desktop sharing,the number of callbacks per second on OnCapturedFrameAvailable
*/
zego_screencapture_set_fps(framerate);

/*
Set whether to capture the cursor at the same time
*/
zego_screencapture_set_cursor_visible(checked);

/*
Set whether to display the click animation while capturing the sharing screen
*/
zego_screencapture_enable_click_animation(checked);

/*
Set up windows, filter these windows when capturing the screen, and not display them on the screen
*/
zego_screencapture_set_excluded_windows((ZegoWindowHandle*)&handle, 1, true);

/*
Set the format of video capture
*/
//zego_screencapture_set_capture_video_pixel_format(kZegoPixelFormatI420);
zego_screencapture_set_capture_video_pixel_format(kZegoPixelFormatBGRA32);

3.Get the Captured Screen

Get the screen name by enumerating the screen

/*
 Refresh the screen list,EnumScreenList gets the list data after deep copy and takes it away, FreeScreenList is paired with it
*/
unsigned int count(0);
const struct ZegoScreenCaptureScreenItem* itemList(nullptr);
itemList = zego_screencapture_enum_screen_list(&count);
if (!itemList) return;

QVector<QVariantMap> screenList;
for (int i= 0; i < count; i++)
{
    QVariantMap varMap;
    QString screenName = itemList[i].name ? itemList[i].name : "";
    varMap["name"] = screenName;
    varMap["primary"] = itemList[i].is_primary != 0;
    screenList.push_back(varMap);
}
m_settings->setScreenList(screenList);
//Release screen list
zego_screencapture_free_screen_list(itemList);

Get the screen name through the window thumbnail

Detailed information please refer to Window Thumbnails.

4. Set up Capture Screen

/*
If you choose to share the entire screen, the currently set screen name will be passed in
*/
zego_screencapture_set_target_screen(m_settings->currentScreen().toUtf8().data());

5.Start Capturing

/*
Start capture
*/
zego_screencapture_start_capture();

6.Data Receiving

void ZegoScreenCaptureController::OnCapturedFrameAvailable(const char *data, uint32_t length, const struct ZegoScreenCaptureVideoCaptureFormat *video_frame_format, uint64_t reference_time, uint32_t reference_time_scale, void *user_data) 
{
    ZegoScreenCaptureController *pThis = (ZegoScreenCaptureController *)user_data;
    if (!pThis)
        return;

    auto externalDevice = pThis->m_externalCaptureFactory->Device();
    if (!externalDevice || !externalDevice->IsCapturing())
        return;

    if (!externalDevice->Client())
        return;

    // Share the desktop screen of the SDK callback from the desktop, and send it directly to the audio and video SDK for streaming
    AVE::VideoCaptureFormat format;
    format.width = video_frame_format->width;
    format.height = video_frame_format->height;

    if (video_frame_format->video_pixel_format == kZegoPixelFormatI420)
    {
        format.strides[0] = video_frame_format->strides[0];
        format.strides[1] = video_frame_format->strides[1];
        format.strides[2] = video_frame_format->strides[2];
    }
    else
    {
        format.strides[0] = video_frame_format->strides[0];
    }

    format.pixel_format = (AVE::VideoPixelFormat)video_frame_format->video_pixel_format;
    format.rotation = video_frame_format->rotation;
    externalDevice->Client()->OnIncomingCapturedData(data, length, format, reference_time, reference_time_scale);
}

7.Stop Capturing

/*
Stop capture
*/
zego_screencapture_stop_capture();

3 Acquisition and Publish Streaming Call Timing Diagram


Page Directory