RTSP लाइव स्ट्रीमिंग
डिवाइस RTSP session शुरू करें, callbacks से मिले hotspot workflow को चलाएँ और returned RTSP address compatible player को दें।
RTSP startup और playback
RTSP startup कई device और Wi-Fi stages का workflow है। किसी intermediate stage को final success माने बिना हर stage दिखाएँ।
आवश्यकताएँ
- डिवाइस 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
- Objective-C
import AIBuds
import AIBudsFoundation
import AIBudsLiveStream#import <AIBuds/AIBuds-Swift.h>
#import <AIBuds/AIBuds.h>
#import <AIBudsFoundation/AIBudsFoundation-Swift.h>
#import <AIBudsLiveStream/AIBudsLiveStream-Swift.h>गुण
- Swift
- Objective-C
/// Whether RTSP live streaming is supported
var supportsRTSPLiveStreaming: Bool { get }/// Whether RTSP live streaming is supported.
@property(nonatomic, readonly) BOOL supportsRTSPLiveStreaming;Instance विधि
- Swift
- 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
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?
)/// 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;startRTSPLiveStreaming और RTSPStreamParams देखें।
RTSP पैरामीटर
| Property | अर्थ |
|---|---|
bitrate | Mbps। 0 डिवाइस default माँगता है। |
qualityFactor | 0 lossless quality माँगता है; बड़े मान compression बढ़ाते हैं। |
iFrameInterval | I-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
- Objective-C
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)
}
)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];
}];त्रुटि प्रबंधन
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 चाहिए।