RTSP 라이브 스트리밍
시작 device RTSP 세션, follow 핫스팟 흐름 exposed 통해 its 콜백, 및 pass returned RTSP address compatible player.
RTSP startup 및 playback
RTSP startup 입니다 multi-stage device 및 Wi-Fi 흐름. Surface 각 stage 없이 treating it as final 성공.
사전 요구 사항
- 기기 입니다 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
- 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;인스턴스 메서드
- 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;See startRTSPLiveStreaming 및 RTSPStreamParams.
RTSP 매개변수
| 속성 | 의미 |
|---|---|
bitrate | Mbps. 0 requests 기기 default. |
qualityFactor | 0 은 무손실 품질을 요청하며 값이 클수록 압축률이 높아집니다. |
iFrameInterval | Number 의 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
- 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];
}];오류 처리
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.