본문으로 건너뛰기

RTSP 라이브 스트리밍

시작 device RTSP 세션, follow 핫스팟 흐름 exposed 통해 its 콜백, 및 pass returned RTSP address compatible player.

Animated workflow

RTSP startup 및 playback

RTSP startup 입니다 multi-stage device 및 Wi-Fi 흐름. Surface 각 stage 없이 treating it as final 성공.

호스트 앱

설정 Stream

사용 default RTSP parameters 또는 set documented bitrate, quality, 및 I-frame values.

SDK + device

설정 핫스팟

Observe 핫스팟 설정 시작 및 completion.

Device

Enter Live Mode

Wait 위한 기기 enter its live-streaming mode.

Device

Wait 위한 핫스팟

기기 opens its 핫스팟 전에 앱 할 수 있습니다 join it.

SDK + iOS

연결 핫스팟

Display supplied SSID 및 observe 연결 result.

Wi-Fi
Device → app

수신 RTSP URL

Validate 및 retain rtsp:// address returned by SDK.

AIBudsLiveStream

시작 Playback

Attach player view 및 play URL as live VideoSource.

호스트 앱

세션 Active

Update active state 만 후에 세션-시작 completion succeeds.

streaming
Terminal 콜백

Finish 및 Clean Up

중지 player resources 및 distinguish user 중지 에서 interruption.

RTSP address 및 세션-시작 콜백 입니다 separate events. Retain playback resources until 세션 finishes 또는 user stops it.

사전 요구 사항

  • 기기 입니다 connected 및 ready 및 conforms LiveStreamingAPI.
  • supportsRTSPLiveStreaming 입니다 true.
  • 앱 입니다 prepared 위한 SDK-managed device-핫스팟 연결 흐름.
  • Add AIBudsLiveStream.xcframework 때 using SDK's RTSP player shown below.

API Reference

Framework

AIBuds.xcframework, AIBudsFoundation.xcframework, 및 optionally AIBudsLiveStream.xcframework

Import

Swift
import AIBuds
import AIBudsFoundation
import AIBudsLiveStream

속성

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

인스턴스 메서드

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?
)

See startRTSPLiveStreamingRTSPStreamParams.

RTSP 매개변수

속성의미
bitrateMbps. 0 requests 기기 default.
qualityFactor0 은 무손실 품질을 요청하며 값이 클수록 압축률이 높아집니다.
iFrameIntervalNumber 의 P/B frames 전에 I-frame; larger values increase compression.

SDK 하지 않습니다 currently publish device-independent nonzero ranges 위한 these values. Prefer RTSPStreamParams.default unless target device contract supplies 지원되는 values.

사용 예제

Retain player 위한 entire 세션. example 사용합니다 every 흐름 콜백 및 starts playback 만 후에 receiving 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)
    }
)

오류 처리

Treat 핫스팟 설정, mode entry, 핫스팟 연결, 세션 시작, player 실패, 및 non-user finish as separate 실패 points. successful intermediate 콜백 하지 않습니다 guarantee later stages 또는 playback will succeed.

참고

  • SDK 반환합니다 RTSP address asynchronously; 하지 마세요 construct device URL by assumption.
  • RTSP playback 필요합니다 phone remain connected 기기 핫스팟.
  • Demo 할 수 있습니다 optionally relay received RTSP source RTMP 통해 LiveStreamer; 입니다 independent publisher 수명 주기 및 필요합니다 application-supplied RTMP URL.