Skip to content

Core Live Streaming Rtsp

Mr.P edited this page Aug 25, 2026 · 2 revisions

RTSP Live Streaming

Start a device RTSP session, follow the hotspot workflow exposed through its callbacks, and pass the returned RTSP address to a compatible player.

RTSP startup and playback

RTSP startup is a multi-stage device and Wi-Fi workflow. Surface each stage without treating it as final success.

  1. Configure Stream — Use default RTSP parameters or set documented bitrate, quality, and I-frame values.
  2. Configure Hotspot — Observe hotspot configuration start and completion.
  3. Enter Live Mode — Wait for the device to enter its live-streaming mode.
  4. Wait for Hotspot — The device opens its hotspot before the app can join it.
  5. Connect Hotspot — Display the supplied SSID and observe the connection result.
  6. Receive RTSP URL — Validate and retain the rtsp:// address returned by the SDK.
  7. Start Playback — Attach a player view and play the URL as a live VideoSource.
  8. Session Active — Update active state only after the session-start completion succeeds.
  9. Finish and Clean Up — Stop player resources and distinguish user stop from interruption.

Prerequisites

  • The device is connected and ready and conforms to LiveStreamingAPI.
  • supportsRTSPLiveStreaming is true.
  • Your app is prepared for the SDK-managed device-hotspot connection workflow.
  • Add AIBudsLiveStream.xcframework when using the SDK's RTSP player shown below.

API Reference

Framework

AIBuds.xcframework, AIBudsFoundation.xcframework, and optionally AIBudsLiveStream.xcframework

Import

Swift

import AIBuds
import AIBudsFoundation
import AIBudsLiveStream

Objective-C

#import <AIBuds/AIBuds.h>
#import <AIBuds/AIBuds-Swift.h>
#import <AIBudsFoundation/AIBudsFoundation-Swift.h>
#import <AIBudsLiveStream/AIBudsLiveStream-Swift.h>

Properties

Swift

/// Whether RTSP live streaming is supported
var supportsRTSPLiveStreaming: Bool { get }

Objective-C

/// Whether RTSP live streaming is supported.
@property (nonatomic, readonly) BOOL supportsRTSPLiveStreaming;

Instance Method

Swift

/// Start RTSP live streaming
/// - Parameters:
///   - params: RTSP stream parameters
///   - configureHotspotStartingHandler: Configure hotspot starting handler
///   - hotspotConfigureCompletionHandler: Hotspot configure completion handler
///   - enterLiveStreamingModeStartingHandler: Enter live streaming mode starting handler
///   - enterLiveStreamingModeCompletedHandler: Enter live streaming mode completed handler
///   - waitingForHotspotOpenHandler: Waiting for hotspot open handler
///   - connectDeviceHotspotStartingHandler: Connect device hotspot starting handler
///   - deviceHotspotConnectCompletionHandler: Device hotspot connect completion handler
///   - rtspAddressReceivedHandler: RTSP address received handler
///   - sessionStartCompletionHandler: Session start completion handler
///   - sessionFinishHandler: Session finish handler
func startRTSPLiveStreaming(
    withParams params: RTSPStreamParams,
    configureHotspotStartingHandler: AIBudsLiveStreamingConfigureHotspotStartingHandler?,
    hotspotConfigureCompletionHandler: AIBudsLiveStreamingHotspotConfigureCompletionHandler?,
    enterLiveStreamingModeStartingHandler: AIBudsEnterLiveStreamingModeStartingHandler?,
    enterLiveStreamingModeCompletedHandler: AIBudsEnterLiveStreamingModeCompletionHandler?,
    waitingForHotspotOpenHandler: AIBudsLiveStreamingStartingToWaitForHotspotOpenHandler?,
    connectDeviceHotspotStartingHandler: AIBudsLiveStreamingConnectDeviceHotspotStartingHandler?,
    deviceHotspotConnectCompletionHandler: AIBudsLiveStreamingDeviceHotspotConnectCompletionHandler?,
    rtspAddressReceivedHandler: AIBudsLiveStreamingRtspAddressReceivedHandler?,
    sessionStartCompletionHandler: AIBudsLiveStreamingSessionStartCompletionHandler?,
    sessionFinishHandler: AIBudsLiveStreamingSessionFinishHandler?
)

Objective-C

/// Start RTSP live streaming
/// - Parameters:
///   - params: RTSP stream parameters
///   - configureHotspotStartingHandler: Configure hotspot starting handler
///   - hotspotConfigureCompletionHandler: Hotspot configure completion handler
///   - enterLiveStreamingModeStartingHandler: Enter live streaming mode starting handler
///   - enterLiveStreamingModeCompletedHandler: Enter live streaming mode completed handler
///   - waitingForHotspotOpenHandler: Waiting for hotspot open handler
///   - connectDeviceHotspotStartingHandler: Connect device hotspot starting handler
///   - deviceHotspotConnectCompletionHandler: Device hotspot connect completion handler
///   - rtspAddressReceivedHandler: RTSP address received handler
///   - sessionStartCompletionHandler: Session start completion handler
///   - sessionFinishHandler: Session finish handler
- (void)startRTSPLiveStreamingWithParams:(AIBudsRTSPStreamParams *)params
        configureHotspotStartingHandler:(AIBudsLiveStreamingConfigureHotspotStartingHandler _Nullable)configureHotspotStartingHandler
        hotspotConfigureCompletionHandler:(AIBudsLiveStreamingHotspotConfigureCompletionHandler _Nullable)hotspotConfigureCompletionHandler
        enterLiveStreamingModeStartingHandler:(AIBudsEnterLiveStreamingModeStartingHandler _Nullable)enterLiveStreamingModeStartingHandler
        enterLiveStreamingModeCompletedHandler:(AIBudsEnterLiveStreamingModeCompletionHandler _Nullable)enterLiveStreamingModeCompletedHandler
        waitingForHotspotOpenHandler:(AIBudsLiveStreamingStartingToWaitForHotspotOpenHandler _Nullable)waitingForHotspotOpenHandler
        connectDeviceHotspotStartingHandler:(AIBudsLiveStreamingConnectDeviceHotspotStartingHandler _Nullable)connectDeviceHotspotStartingHandler
        deviceHotspotConnectCompletionHandler:(AIBudsLiveStreamingDeviceHotspotConnectCompletionHandler _Nullable)deviceHotspotConnectCompletionHandler
        rtspAddressReceivedHandler:(AIBudsLiveStreamingRtspAddressReceivedHandler _Nullable)rtspAddressReceivedHandler
        sessionStartCompletionHandler:(AIBudsLiveStreamingSessionStartCompletionHandler _Nullable)sessionStartCompletionHandler
        sessionFinishHandler:(AIBudsLiveStreamingSessionFinishHandler _Nullable)sessionFinishHandler;

See startRTSPLiveStreaming and RTSPStreamParams.

RTSP Parameters

Property Meaning
bitrate Mbps. 0 requests the device default.
qualityFactor 0 requests lossless quality; larger values increase compression.
iFrameInterval Number of P/B frames before an I-frame; larger values increase compression.

The SDK does not currently publish device-independent nonzero ranges for these values. Prefer RTSPStreamParams.default unless the target device contract supplies supported values.

Usage Examples

Retain the player for the entire session. The example uses every workflow callback and starts playback only after receiving a valid RTSP URL.

Swift

let player = LiveStreamingPlayer()
player.addVideoView(to: videoContainerView)

guard let streamingDevice = device as? LiveStreamingAPI,
      streamingDevice.supportsRTSPLiveStreaming else { return }

streamingDevice.startRTSPLiveStreaming(
    withParams: .default,
    configureHotspotStartingHandler: { showStage("Configuring hotspot") },
    hotspotConfigureCompletionHandler: { success, error in
        showStage(success ? "Hotspot configured" : error?.localizedDescription ?? "Hotspot configuration failed")
    },
    enterLiveStreamingModeStartingHandler: { showStage("Entering live-stream mode") },
    enterLiveStreamingModeCompletedHandler: { success, error in
        showStage(success ? "Live-stream mode entered" : error?.localizedDescription ?? "Mode entry failed")
    },
    waitingForHotspotOpenHandler: { showStage("Waiting for device hotspot") },
    connectDeviceHotspotStartingHandler: { ssid in showStage("Connecting to \(ssid)") },
    deviceHotspotConnectCompletionHandler: { success, error in
        showStage(success ? "Device hotspot connected" : error?.localizedDescription ?? "Hotspot connection failed")
    },
    rtspAddressReceivedHandler: { address in
        guard let url = URL(string: address), url.scheme?.lowercased() == "rtsp" else { return }
        let source = VideoSource(url: url, videoType: .normal)
        source.isLiveStream = true
        player.play(source: source)
    },
    sessionStartCompletionHandler: { success, error in
        setStreamingActive(success)
        if let error { show(error) }
    },
    sessionFinishHandler: { userStopped, error in
        player.stop()
        setStreamingActive(false)
        handleFinish(userStopped: userStopped, error: error)
    }
)

Objective-C

self.mediaPlayer = [[AIBudsLiveStreamingPlayer alloc] init];
[self.mediaPlayer addVideoViewToView:self.videoContainerView];

id<AIBudsLiveStreamingAPI> streamingDevice = (id<AIBudsLiveStreamingAPI>)self.device;
if (![streamingDevice conformsToProtocol:@protocol(AIBudsLiveStreamingAPI)] ||
    !streamingDevice.supportsRTSPLiveStreaming) {
    return;
}

__weak typeof(self) weakSelf = self;
[streamingDevice startRTSPLiveStreamingWithParams:[AIBudsRTSPStreamParams defaultParams]
    configureHotspotStartingHandler:^{ [weakSelf showStage:@"Configuring hotspot"]; }
    hotspotConfigureCompletionHandler:^(BOOL success, NSError *error) {
        [weakSelf handleStageResult:success error:error];
    }
    enterLiveStreamingModeStartingHandler:^{ [weakSelf showStage:@"Entering live-stream mode"]; }
    enterLiveStreamingModeCompletedHandler:^(BOOL success, NSError *error) {
        [weakSelf handleStageResult:success error:error];
    }
    waitingForHotspotOpenHandler:^{ [weakSelf showStage:@"Waiting for device hotspot"]; }
    connectDeviceHotspotStartingHandler:^(NSString *ssid) {
        [weakSelf showStage:[NSString stringWithFormat:@"Connecting to %@", ssid]];
    }
    deviceHotspotConnectCompletionHandler:^(BOOL success, NSError *error) {
        [weakSelf handleStageResult:success error:error];
    }
    rtspAddressReceivedHandler:^(NSString *address) {
        NSURL *url = [NSURL URLWithString:address];
        if (![url.scheme.lowercaseString isEqualToString:@"rtsp"]) return;
        AIBudsVideoSource *source = [[AIBudsVideoSource alloc]
            initWithUrl:url videoType:AIBudsLiveStreamingVideoTypeNormal];
        source.isLiveStream = YES;
        [weakSelf.mediaPlayer playWithSource:source];
    }
    sessionStartCompletionHandler:^(BOOL success, NSError *error) {
        [weakSelf setStreamingActive:success];
        if (error) [weakSelf showError:error];
    }
    sessionFinishHandler:^(BOOL userStopped, NSError *error) {
        [weakSelf.mediaPlayer stop];
        [weakSelf setStreamingActive:NO];
        [weakSelf handleFinishUserStopped:userStopped error:error];
    }];

Error Handling

Treat hotspot configuration, mode entry, hotspot connection, session start, player failure, and non-user finish as separate failure points. A successful intermediate callback does not guarantee that later stages or playback will succeed.

Notes

  • The SDK returns the RTSP address asynchronously; do not construct a device URL by assumption.
  • RTSP playback requires the phone to remain connected to the device hotspot.
  • The Demo can optionally relay the received RTSP source to RTMP through LiveStreamer; that is an independent publisher lifecycle and requires an application-supplied RTMP URL.

AIBuds SDK iOS Wiki

Clone this wiki locally