Live Stream Subscription

2024-04-07
No Rating

Overview

The 'camera live stream subscription' feature supports subscribing to both the main camera and FPV camera H264 streams of the aircraft. It also allows specifying subscriptions for streams at different resolutions, including 540P, 720P, 720PHigh, 1080P, and 1080P High. With the real-time video feed obtained, real-time AI processing can be performed.

Use Stream Subscription Functionality

The 'camera live stream subscription' function provides services for the stream status, stream initialization, stream transmission start, stream transmission stop, and camera source switching interfaces.

Stream Subscription Status

Configure the live streaming in the cloud. Factors such as balanced transmission channels, aircraft disconnection, or no signal in the video transmission can lead to changes in the stream status. The stream service status allows you to subscribe to the real-time availability status of the stream.

// filename: include/liveview.h

// Live stream status
using LiveviewStatus = uint32_t;

// Live stream status callback function
using LiveviewStatusCallback =
        std::function<void(const LiveviewStatus& status)>;

// Live stream status interface
virtual ErrorCode SubscribeLiveviewStatus(const LiveviewStatusCallback& callback) = 0;
ValueLiveviewStatus.bit0LiveviewStatus.bit1LiveviewStatus.bit2LiveviewStatus.bit3LiveviewStatus.bit4LiveviewStatus.bit5
0Custom live stream quality. Unavailable.540P live stream quality. Unavailable.720P live stream quality. Unavailable.720P High live stream quality. Unavailable.1080P live stream quality. Unavailable.1080P High live stream quality. Unavailable.
1Custom live stream quality. Available.540P live stream quality. Available.720P live stream quality. Available.720P High live stream quality. Available.1080P live stream quality. Available.1080P High live stream quality. Available.

Init/Start/Stop the Subscription

// Init subscription

// 1. Implement callback handling function.
ErrorCode H264StreamHandleCallback(const uint8_t* buf, uint32_t len) {
	// TODO: Implement data processing for received streams. 'buf' and 'len' parameters represent stream data and its length.
	return kOk;
}

// 2. Option initialization: Subscribe to the main camera, stream quality set to 720p, and the H264StreamHandleCallback as the stream callback processing function.
auto liveview = CreateLiveview();
Liveview::Option option = { Liveview::kCameraTypePayload, Liveview::kStreamQuality720p, H264StreamHandleCallback };
liveview->Init(option);

// 3. Start live stream transmission
liveview->StartH264Stream();

// Can be used to switch camera lens
liveview->SetCameraSource(CameraSource::kCameraSourceIR);

// 4. Stop live stream transmission
liveview->StopH264Stream();

Init Stream Subscription

After initializing the live stream subscription function and determining the subscribed camera, stream quality and stream receive callback function, the edge computing initialization and DJI dock establishes the stream transmission channel. After invoking this interface, it should not be invoked again for initialization. The callback function for receiving the stream is set up to handle incoming streams when stream transmission starts. A return value of 'kOk' indicates success. Other possible return values include:

  • 'kErrorInvalidArgument': Invalid parameter, check if the parameters are reasonable enum values.
  • 'kErrorParamGetFailure': Unable to retrieve camera configuration parameters, check if 'CameraType' is correct.
  • 'kErrorSystemError': Initialization connection failure, check if the network card is available, and refer to the logs for more information or contact technical support.
ParameterExplanation
Camera typeProvide upmost two channels of subscription. Payload camera and FPV camera.
Stream quality Available stream quality levels are displayed in the stream subscription status, with up to four options to choose from: 540P, 720P, 720PHigh, 1080P, and 1080P High.

Note: The stream quality can be affected by various factors such as live configuration balancing and video signal strength. Even though a specific stream quality is specified, it may not always be available for subscription. When starting stream transmission, it prioritizes using the specified quality. If the specified quality is unavailable at the moment, it will choose the nearest available quality level. Application design at the higher layers should consider compatibility with different stream quality levels for business processing.

/**
 * @brief Initialize live stream parameters
 */

/**
 * @brief Type of the camera for the stream
 */
enum CameraType {
    /*! FPV camera */
    kCameraTypeFpv = 0,

    /*! Payload camera */
    kCameraTypePayload = 1,
};

struct Options {
    /*! Type of camera to subscribe to */
    CameraType camera;

    /*!
     * Quality of the subscribed stream, Note: The actual quality of the subscribed stream may not necessarily match. The **dock** will return the stream quality closest to the current situation.
     */
    StreamQuality quality;

    /*! Callback function to receive the stream */
    H264StreamCallback callback;
};

/**
 * @brief Stream quality
 */
enum StreamQuality {
    /*! Stream quality 540p: 30fps, 960*540, bps 512*1024 */
    kStreamQuality540p = 1,

    /*! Stream quality 720p: 30fps, 1280*720, bps 1024*1024 */
    kStreamQuality720p = 2,

    /*! Stream quality 720pHigh: 30fps, 1280*720, bps 1024*1024 + 512*1024 */
    kStreamQuality720pHigh = 3,

    /*! Stream quality 1080p: 30fps, 1920*1080, bps 3*1024*1024 */
    kStreamQuality1080p = 4,

    /*! Stream Quality 1080p: 30fps, 1920*1080, bps 8*1024*1024 */
    kStreamQuality1080pHigh = 5,
};

/**
 * @brief Liveview camera H264 stream callback
 * @param buf: Received H264 stream data
 * @param len: Length of received H264 stream data
 */
using H264StreamCallback = std::function<ErrorCode(const uint8_t* buf, uint32_t len)>;

/**
 * @brief Initialize live stream subscription, note: for a specific camera, initialization can only be done once
 * @param option: Initialization stream configuration
 * @return Execution result
 */
virtual ErrorCode Init(const Options& option) = 0;

Start Stream Transmission

After successful initialization, calling this interface initiates live stream transmission. A return value of 'kOk' indicates success. Other possible return values include:

  • 'kErrorInvalidArgument': Internal parameter validation fails, refer to the logs for more information or contact technical support.
  • 'kErrorSystemError': Check if the aircraft is connected properly and if the network connection is stable.
  • 'kErrorRemoteFailure': Remote dock error. Check if the dock is experiencing any issues. Refer to the logs for more information or contact technical support.
  • 'kErrorRequestTimeout': Request timeout, check if the network connection is stable.

Note: When there are no available streams to subscribe to in the stream status (for example, if the aircraft is not powered on or not properly tuned), calling this interface will block and wait for availability, and return a failure after a timeout (5-10 seconds). After live stream transmission starts, the SDK does not guarantee recovery from all stream interruptions. Users can try to resume live stream transmission by calling this interface again, considering factors such as whether data is received in the stream callback and the status of the subscribed stream after a stream interruption.

    /**
     * @brief Start Stream Transmission
     * @return Execution result
     */
    virtual ErrorCode StartH264Stream() = 0;

Stop Stream Subscription

After successful initialization, calling this interface will stop remote live stream transmission. A return value of 'kOk' indicates success. Other possible return values include:

  • 'kErrorRemoteFailure': Remote dock error. Check if the dock is experiencing any issues. Refer to the logs for more information or contact technical support.

  • 'kErrorRequestTimeout': Request timeout, check if the network connection is stable.

    /**

    • @brief Stop Stream Subscription
    • @return Execution result */ virtual ErrorCode StopH264Stream() = 0;

Set Payload Stream Source

Through this interface, initializing live stream subscriptions for FPV or payload cameras allows you to set the camera's live stream source. A return value of 'kOk' indicates a successful command publication. In very rare cases, it may not necessarily mean that the camera's live stream source has been successfully switched. The effectiveness of the result can only be confirmed by examining the returned video.

    /*
     * @brief Payload stream source
     */
    enum CameraSource {
        /*! Wide lens */
        kCameraSourceWide = 1,

        /*! Zoom lens */
        kCameraSourceZoom = 2,

        /*! Infrared lens */
        kCameraSourceIR = 3,
    };

    /**
     * @brief Set payload stream source
     * @return Execution result
     */
    virtual ErrorCode SetCameraSource(CameraSource source) = 0;
If you have any comments or confusion about our documentation, you can click here to give feedback and we will get back to you as soon as possible.