मुख्य कंटेंट तक स्किप करें

RTSP लाइव स्ट्रीमिंग

डिवाइस RTSP session शुरू करें, callbacks से मिले hotspot workflow को चलाएँ और returned RTSP address compatible player को दें।

Animated workflow

RTSP startup और playback

RTSP startup कई device और Wi-Fi stages का workflow है। किसी intermediate stage को final success माने बिना हर stage दिखाएँ।

Host app

Stream configure करें

Default RTSP parameters उपयोग करें या documented bitrate, quality और I-frame values सेट करें।

SDK + डिवाइस

Hotspot configure करें

Hotspot configuration की शुरुआत और completion देखें।

डिवाइस

Live Mode में जाएँ

डिवाइस के live-streaming mode में जाने की प्रतीक्षा करें।

डिवाइस

Hotspot की प्रतीक्षा करें

App के जुड़ने से पहले डिवाइस अपना hotspot खोलता है।

SDK + iOS

Hotspot से जुड़ें

दिया गया SSID दिखाएँ और connection result देखें।

Wi-Fi
डिवाइस → app

RTSP URL पाएँ

SDK से मिला rtsp:// address validate करके रखें।

AIBudsLiveStream

Playback शुरू करें

Player view attach करें और URL को live VideoSource के रूप में चलाएँ।

Host app

Session active

Active state केवल session-start completion सफल होने के बाद अपडेट करें।

streaming
Terminal callback

समाप्त और Cleanup करें

Player resources रोकें और user stop को interruption से अलग रखें।

RTSP address और session-start callback अलग events हैं। Session समाप्त होने या उपयोगकर्ता के रोकने तक playback resources रखें।

आवश्यकताएँ

  • डिवाइस connected और ready है तथा LiveStreamingAPI के अनुरूप है।
  • supportsRTSPLiveStreaming का मान true है।
  • आपका app SDK द्वारा managed device-hotspot connection workflow के लिए तैयार है।
  • नीचे दिखाया SDK RTSP player उपयोग करते समय AIBudsLiveStream.xcframework जोड़ें।

API संदर्भ

Framework

AIBuds.xcframework, AIBudsFoundation.xcframework और वैकल्पिक रूप से AIBudsLiveStream.xcframework

Import

Swift
import AIBuds
import AIBudsFoundation
import AIBudsLiveStream

गुण

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

Instance विधि

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

startRTSPLiveStreaming और RTSPStreamParams देखें।

RTSP पैरामीटर

Propertyअर्थ
bitrateMbps। 0 डिवाइस default माँगता है।
qualityFactor0 lossless quality माँगता है; बड़े मान compression बढ़ाते हैं।
iFrameIntervalI-frame से पहले P/B frames की संख्या; बड़े मान compression बढ़ाते हैं।

SDK अभी इन values के लिए device-independent nonzero ranges publish नहीं करता। Target device contract supported values न दे तो RTSPStreamParams.default उपयोग करें।

उपयोग के उदाहरण

Player को पूरे session तक रखें। उदाहरण हर workflow callback उपयोग करता है और valid RTSP URL मिलने के बाद ही playback शुरू करता है।

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

त्रुटि प्रबंधन

Hotspot configuration, mode entry, hotspot connection, session start, player failure और non-user finish को अलग failure points मानें। Successful intermediate callback बाद के stages या playback की सफलता की गारंटी नहीं देता।

नोट्स

  • SDK RTSP address asynchronously देता है; अनुमान से device URL न बनाएँ।
  • RTSP playback के लिए iPhone को device hotspot से connected रहना होगा।
  • Demo मिले RTSP source को LiveStreamer से RTMP पर optional relay कर सकता है; इसका publisher lifecycle अलग है और app द्वारा दिया RTMP URL चाहिए।