All Products
Search
Document Center

ApsaraVideo Live:Use Push SDK for Windows

Last Updated:Aug 21, 2024

This topic describes how to use Push SDK for Windows and the classes and methods in the SDK. This topic also provides examples on how to use the features provided by Push SDK for Windows. By reading this topic, you can better understand how to use the SDK for live streaming.

Features

  • Supports co-streaming and battles.

  • Adopts H.264 for video encoding and Opus and Advanced Audio Coding (AAC) for audio encoding.

  • Adopts H.265 for video encoding and Opus and AAC for audio encoding.

  • Supports custom configurations for features such as bitrate control, resolution, and display mode.

  • Supports various camera operations.

  • Allows you to stream screen recordings.

  • Supports external audio and video inputs in different formats such as YUV and pulse-code modulation (PCM).

  • Supports mixing of multiple streams.

  • Supports ingest of audio-only and video-only streams and stream ingest in the background.

  • Supports background music and allows you to manage background music.

  • Supports automatic reconnection and error handling.

  • Supports the audio 3A algorithm.

  • Allows you to switch between the software and hardware encoding modes for video files. This improves the stability of the encoding module.

Classes of Push SDK for Windows

Class

Description

AlivcLivePushConfig

The class for stream ingest settings.

AlivcLivePusher

The class for stream ingest features.

AlivcLivePusherErrorListener

The class for error callbacks.

AlivcLivePusherNetworkListener

The class for network callbacks.

AlivcLivePusherInfoListener

The class for stream ingest callbacks.

Procedure

Basic stream ingest

The following table describes how to perform basic stream ingest:

Step

Description

1. Configure stream ingest parameters

Complete the stream ingest configurations, such as the basic parameters, bitrate control mode, and adaptive resolution.

2. Use Push SDK for Windows to ingest streams

After you initialize Push SDK for Windows, register stream ingest callbacks, and create a preview view, you can start to ingest streams. You can manage streams, configure background music, configure camera settings, ingest external audio sources, and add animated stickers based on your business requirements.

3. (Optional) Configure stream ingest for screen recordings

If you want to stream screen recordings, configure stream ingest for screen recordings.

1. Configure stream ingest parameters

You can use the AlivcLivePushConfig class to configure stream ingest parameters. Each parameter has a default value. For basic stream ingest, we recommend that you use the default values of the parameters.

  1. Complete stream ingest configurations.

    AlivcLivePushConfig config;
    Note

    To modify the parameters in real time during stream ingest, refer to the methods provided by the AlivcLivePusher class.

  2. Specify the bitrate control mode.

    You can use the following methods to specify the bitrate control mode:

    1. Initialize the enableBitrateControl parameter to specify the bitrate control mode. If you set the parameter to true, the smoothness-first mode is used. If you set the parameter to false, the quality-first mode is used. Default value: true.

    config.enableBitrateControl = true;

    2. Configure bitrate parameters based on your custom settings, including the mMinVideoBitrate, mInitialVideoBitrate, and mTargetVideoBitrate parameters. The following table describes the recommended values of these parameters.

    Resolution

    initialVideoBitrate

    minVideoBitrate

    targetVideoBitrate

    360p

    600

    300

    1000

    480p

    800

    300

    1200

    540p

    1000

    600

    1400

    720p

    1500

    600

    2000

    1080p

    1800

    1200

    2500

    Resolution

    initialVideoBitrate

    minVideoBitrate

    targetVideoBitrate

    360p

    400

    200

    600

    480p

    600

    300

    800

    540p

    800

    300

    1000

    720p

    1000

    300

    1200

    1080p

    1500

    1200

    2200

    Note

    If you do not configure the targetVideoBitrate, minVideoBitrate, and initialVideoBitrate parameters, Push SDK automatically specifies an appropriate camera bitrate based on the resolution.

  3. Configure the adaptive resolution feature.

    The adaptive resolution feature is used to dynamically adjust the resolution of a stream. When you enable the adaptive resolution feature, the resolution is automatically reduced to ensure the smoothness and quality of video streams in poor network conditions. Sample code:

    config.enableAutoResolution = true;
  4. Configure image ingest.

    Push SDK for Windows allows you to ingest images when your app is switched to the background or the bitrate is low. This improves user experience. When your app is switched to the background, video stream ingest is paused. In this case, only audio streams are ingested. You can also specify an image that you want to ingest. For example, you can ingest an image in which a message such as The streamer will be back soon. is displayed to notify the viewers. Sample code:

    config.mPausePushImagePath = "The path of the specified image in the PNG format for stream ingest";// Specify the image for stream ingest when your app is switched to the background.

2. Use Push SDK for Windows to ingest streams

AlivcLivePusher is the core class of Push SDK for Windows. This class provides parameters for initialization, stream ingest callbacks, camera preview, and stream ingest management. You can also use this class to modify parameters during stream ingest.

  1. Initialize the AlivcLivePusher class.

    After you configure stream ingest parameters, call the init method to initialize the class. Sample code:

    AlivcLivePushConfig config;
    pusher->init(config);
  2. Register stream ingest callbacks.

    The following stream ingest callbacks are supported:

    • Info: the callbacks that are used for notifications and status detection.

    • Error: the callbacks that are returned when errors occur.

    • Network: the callbacks that are related to network.

    When an event occurs, the corresponding callback is triggered to notify you of the event. Sample code:

    pusher->setLivePushErrorListener(errorListener);
    pusher->setLivePushInfoListener(errorListener);
    pusher->setLivePushNetworkListener(errorListener);

  3. Start preview.

    You can start preview after you initialize the livePusher object and configure callbacks. Sample code:

    pusher->startPreview(view, width, height);

  4. Start stream ingest.

    pusher->startPush(url);

  5. Complete other stream ingest configurations.

    Push SDK for Windows allows you to manage stream ingest. For example, you can start, stop, restart, pause, and resume stream ingest, stop preview, and destroy stream ingest instances. You can add buttons to perform these operations.

    pusher->stopPush();

3. (Optional) Configure stream ingest for screen recordings

You can stream a screen recording, which is from a shared screen. To do so, you need to obtain the list of shared sources and then specify a shared source for stream ingest. Specific steps:

  1. Obtain the list of shared sources.

    pusher->getScreenShareSourceInfo();

  2. Start ingest of a shared source.

    pusher->startScreenShareByDesktopId(desktopId);
    Note
    • desktopId indicates the ID of the desktop. You can query the ID by calling the GetScreenShareSourceInfo method.

    • If you want to share a specified area, make sure that the resolution of the area is higher than or equal to 16 × 16 pixels. Otherwise, the resolution of the area is reset to 16 × 16 pixels.

    • If the resolution of the area is higher than the resolution of the desktop, the entire desktop is shared.

Stream ingest for co-streaming

Push SDK for Windows provides the Real-Time Communication (RTC)-based co-streaming feature and the RTC-based battle feature. Streamers and viewers can interact with each other at an ultra-low latency of less than 300 ms by using Push SDK for Windows. For more information about interactive streaming, see Developer guide to co-streaming and Developer guide to battles.

References

Methods