Skip to content

Multimedia Service Interfaces


First-Person View (FPV) Streaming Interface

Overview

This interface enables video streaming using the OWT (Open WebRTC Toolkit) protocol to retrieve first-person visual content from the robot. The streaming process involves setting up event-driven callback functions for key events such as server connection, stream publishing, and video rendering.

Set Callback Functions

Function: SetCallbacks

cpp
/**
 * @brief Set callback functions for OWT events.
 * 
 * This function registers user-defined callbacks to handle various events during OWT streaming.
 * 
 * @param onConnectServerSuccess     Triggered upon successful connection to the server.
 * @param onConnectServerFailure     Triggered if the connection to the server fails.
 * @param onPublishSuccess           Triggered when the stream is successfully published.
 * @param onPublishFailure           Triggered when the stream publication fails.
 * @param onDisconnectServerSuccess  Triggered upon successful disconnection from the server.
 * @param onDisconnectServerFailure  Triggered when disconnection from the server fails.
 * @param onRenderRemote             Triggered when rendering a remote video stream.
 * @param onRenderLocal              Triggered when rendering a local video stream.
 */
void SetCallbacks(OnConnectServerSuccess onConnectServerSuccess,
                OnConnectServerFailure onConnectServerFailure,
                OnPublishSuccess onPublishSuccess,
                OnPublishFailure onPublishFailure,
                OnDisconnectServerSuccess onDisconnectServerSuccess,
                OnDisconnectServerFailure onDisconnectServerFailure,
                OnRenderCallback onRenderRemote,
                OnRenderCallback onRenderLocal);

Usage Example

cpp
RTCP2PClient* p2p_client = new RTCP2PClient();
p2p_client->SetCallbacks(
    &OWTCallbacks::on_connect_success,
    &OWTCallbacks::on_connect_failure,
    &OWTCallbacks::on_publish_success,
    &OWTCallbacks::on_publish_failure,
    &OWTCallbacks::on_disconnect_success,
    &OWTCallbacks::on_disconnect_failure,
    &OWTCallbacks::on_render_remote,
    &OWTCallbacks::on_render_locate
);

FPV Client Initialization (Pull Stream Side)

Function: Init

cpp
/**
 * @brief Initialize the OWT client.
 * 
 * This function initializes the OWT client for video streaming.
 * 
 * @param videoCodec        Video codec format. Currently supported: "VP8", "VP9".
 * @param maxBitrateKbps    Maximum bitrate (in kbps) under good network conditions.
 */
void Init(std::string videoCodec, int maxBitrateKbps);

Usage Example

cpp
p2p_client->Init("VP9", 3000);

ICE Server Configuration

Function: AddIceServer

cpp
/**
 * @brief Configure an ICE Server for NAT traversal.
 * 
 * This function sets the ICE server used for NAT traversal during peer-to-peer communication.
 * 
 * @param url        URL of the ICE server.
 * @param username   Username for authentication (if required).
 * @param password   Password for authentication (if required).
 */
void AddIceServer(std::string url, std::string username, std::string password);

Usage Example

cpp
p2p_client->AddIceServer("stun:stun.l.google.com:19302", "your_username", "your_password");
p2p_client->AddIceServer("turn:turn.example.com:3478", "your_username", "your_password");

Set Remote Stream Source

cpp
/**
 * @brief Set the remote stream source ID.
 * 
 * This function assigns the remote user’s ID to establish a direct connection.
 * 
 * @param remoteId   The unique identifier of the remote user (stream publisher).
 */
void SetRemoteId(std::string remoteId);

Usage Example

cpp
p2p_client->SetRemoteId(remoteId);

Connect to Signaling Server

Function: Connect

cpp
/**
 * @brief Connect to the signaling server.
 * 
 * This function establishes the signaling channel with the OWT server.
 * 
 * @param url      URL of the signaling server.
 * @param userId   Unique identifier for the current client (used for registration).
 */
void Connect(std::string url, std::string userId);

Usage Example

cpp
p2p_client->Connect(owt_url, userId);