提交工单
咨询集成、功能及报价等问题
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.
/*
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.
/*
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);
/*
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);
Detailed information please refer to Window Thumbnails.
/*
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());
/*
Start capture
*/
zego_screencapture_start_capture();
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);
}
/*
Stop capture
*/
zego_screencapture_stop_capture();