Screen Sharing

The Video SDK enables an app to live stream the contents of the device's screen or windows with the session.

Share screen

You can share a specific screen with the session using startShareScreen within IZoomVideoSDKShareHelper. This method takes in a monitorID parameter that specifies the name of the screen that will be shared.

// Get available monitors.
std::vector<std::wstring> vecMonitorArray;
EnumDisplayMonitors(NULL, NULL, &MyInfoEnumProc, reinterpret_cast<LPARAM>(&vecMonitorArray));
std::wstring strMonitorId;
if (vecMonitorArray.size() <= 0)
    strMonitorId = _T("");
else
    strMonitorId = vecMonitorArray[0];

// Obtain the IZoomVideoSDKShareHelper instance to perform sharing actions.
IZoomVideoSDKShareHelper* pShareHelper = m_pVideoSDK->getShareHelper();
if (!pShareHelper) return;

// Set to true to enable sharing device audio while screen sharing
pShareHelper->enableShareDeviceAudio(true);

// Pass in id of the monitor to share.
int err = pShareHelper->startShareScreen(strMonitorId.c_str());
CString strInfo;
if (err == ZoomVideoSDKErrors_Success)
{
    // Started sharing screen.
}
else
{
    // Screen sharing failed.
}

Share window

You can also share a window handle instead. Use startShareView within IZoomVideoSDKShareHelper to begin sharing a window using its hWnd.

// Obtain the IZoomVideoSDKShareHelper instance to perform sharing actions.
IZoomVideoSDKShareHelper* pShareHelper = m_pVideoSDK->getShareHelper();
if (!pShareHelper) return;

int err = pShareHelper->startShareView(hWnd);
if (err == ZoomVideoSDKErrors_Success)
{
    // Started sharing window.
}
else
{
    // Window sharing failed.
}

Stop sharing

Call stopShare within *IZoomVideoSDKShareHelper to stop sharing.

// Obtain the IZoomVideoSDKShareHelper instance to perform sharing actions.
IZoomVideoSDKShareHelper* pShareHelper = m_pVideoSDK->getShareHelper();
if (!pShareHelper) return;

pShareHelper->stopShare();

Verify screen share

After completing the above steps to share your screen, you can verify that your screen share is visible on another device by responding to the following callback within your IZoomVideoSDKDelegate:

void CExampleListener::onUserShareStatusChanged(IZoomVideoSDKShareHelper* pShareHelper, IZoomVideoSDKUser* pUser, ZoomVideoSDKShareStatus status)
{
    if (status == ZoomVideoSDKShareStatus_Start)
    {
        // The user has successfully started sharing to the session.
    }
}

Rendering screen share of another user

Similar to a user's video stream, you can also render a user's share stream by subscribing to their share pipe.

// CExampleRenderer.h
class CExampleRenderer : public IZoomVideoSDKRawDataPipeDelegate
{
    // ...
public: // IZoomVideoSDKRawDataPipeDelegate
    virtual void onRawDataFrameReceived(YUVRawDataI420* data_);
    virtual void onRawDataStatusChanged(RawDataStatus status);
    // ...
}

// CExampleRenderer.cpp
ZoomVideoSDKErrors CExampleRenderer::Subscribe(IZoomVideoSDKUser* pUser, ZoomVideoSDKRawDataType dataType, int size)
{
    // Set the resolution.
    ZoomVideoSDKResolution resolution = ZoomVideoSDKResolution_360P;

    // Get the share pipe for the user.
    IZoomVideoSDKRawDataPipe* pPipe = NULL;
    pPipe = pUser->GetSharePipe();
    if (!pPipe) return;

    // Call subscribe.
    err = pPipe->subscribe(resolution, this)

    return err;
}

Receive video frame

The class above inherits from IZoomVideoSDKRawDataPipeDelegate, which provides two callbacks. onRawDataFrameReceived(YUVRawDataI420* data_)* provides video data in YUV format. This data parameter YUVRawDataI420 provides everything needed to render the single video frame data.

void CExampleRenderer::onRawDataFrameReceived(YUVRawDataI420* data_)
{
    // Get frame data resolution.
    data_->GetStreamWidth();
    data_->GetStreamHeight();

    // Get frame buffer.
    data_->GetYBuffer();
    data_->GetUBuffer();
    data_->GetVBuffer();

    // Get frame rotation
    data_->GetRotation();
}

onRawDataStatusChanged(RawDataStatus status) is called when there is a change in raw data status.

void CExampleRenderer::onRawDataStatusChanged(RawDataStatus status)
{
    if (status == RawData_On)
    {
        // Now subscribed to user's data.
    }
    else
    {
    // No longer subscribed to user's data.
    }
}

Unsubscribe from user's share pipe

To stop rendering user content, unsubscribe from the user's video by calling the unsubscribe() method:

void CExampleRenderer::unSubscribe(IZoomVideoSDKUser* pUser)
{
    if (pUser->GetSharePipe())
        pUser->GetSharePipe()->unSubscribe(this);
}

Next Steps

Need help?

If you're looking for help, try Developer Support or our Developer Forum. Priority support is also available with Premier Developer Support plans.