イントロ
最近、ビデオストリーミング用のアプリケーションを作成するために、興味深いタスクを実行するようになりました。これは、スタートアップのShopStory(ecommライブストリーミング)用です。アプリケーションの最初のバージョンは、RTMPストリーミングHaishinKit用のオープンソースライブラリを使用して実装されました。そして、2番目のバージョンはLarixSDKにあります。この記事では、その過程でどのような問題が発生したかを分析します。
要件
ShopStory.live - B2B live e-commerce, , . , , , , . ShopStory.live , , beauty- live commerce .
ShopStory, LarixBroadcaster , Android iOS. :
, , ,
LarixBroadcaster
, . , , , .
, , .
.
, (, , ).
:
( , )
ABR - Adaptive BitRate ( )
, fps, ..
.
– . Larix SDK
– , .
, :
LFLiveKit – 4.2k , 2016. 115 issue, .
HaishinKit – 2.1k , 7 . 11 issues.
-
KSY Live iOS SDK – 0.8k , 22 2020. README .
HaishinKit. , , .
HaishinKit
, . . /, . AVCaptureSession, AVCaptureDevice, AVCaptureDeviceInput
. View
, attach
RTMPStream
.
:
protocol BroadcastService: AnyObject {
func connect()
func publish()
func stop()
}
.
class HaishinBroadcastService: BroadcastService {}
ABR - Adaptive BitRate
, , ().
ABR, issue. RTMPStreamDelegate
.
extension HaishinBroadcastService: RTMPStreamDelegate {
func rtmpStream(_ stream: RTMPStream, didPublishInsufficientBW connection: RTMPConnection) {
guard self.config.adaptiveBitrate else { return }
guard let bitrate = self.currentBitrate else {
assertionFailure()
return
}
let newBitrate = max(UInt32(Double(bitrate) * Constants.bitrateDown), Constants.minBitrate)
self.rtmpStream.videoSettings[.bitrate] = newBitrate
}
func rtmpStream(_ stream: RTMPStream, didPublishSufficientBW connection: RTMPConnection) {
guard self.config.adaptiveBitrate else { return }
guard let currentBitrate = self.currentBitrate,
currentBitrate < Constants.maxBitrate else {
return
}
guard self.bitrateRetryCounter >= Constants.retrySecBeforeUpBitrate else {
self.bitrateRetryCounter += 1
return
}
self.bitrateRetryCounter = 0
let newBitrate = min(Constants.maxBitrate, UInt32(Double(currentBitrate) * Constants.bitrateUp))
if newBitrate == currentBitrate { return }
self.rtmpStream.videoSettings[.bitrate] = newBitrate
}
}
private struct Constants {
static let bitrateDown: Double = 0.75
static let bitrateUp: Double = 1.15
static let retrySecBeforeUpBitrate = 20
}
issue – ( 2 ), . didPublishInsufficientBW
, .
:
, 0.75
, 20 ( ), 1.15
Live update resolution
, , . RTMP . VK Live . Instagram , rtmp , , , ( , ). ShopStory .
. Wi-Fi, LTE. Larix SDK
. LarixBroadcaster – .
Larix SDK
LarixBroadcaster
+ LarixDemo ( ), , StepByStepGuide.
:
,
.
:
-
, -
LarixBroadcaster
( , : over 2000 )
connect
publish
-
… , LarixBroadcaster
ViewController
2100 , Streamer
1100 . SDK. … , . @Aquary ( ):
« " ". — - . , . — . , , .. , .»
, SDK . , . c HaishinKit
, .. ( HaishinKit
).
ABR, ( ), , . . LarixBroadcaster
3 StreamConditionerMode1, 2, 3,
. ABR? ABR ( ).
, . , status = disconnected
. , .
func connectionStateDidChangeId(_ connectionID: Int32, state: ConnectionState, status: ConnectionStatus, info: [AnyHashable: Any]) {}
Larix
.
: SDK StreamerEngineProxy
bytesSent
bytesDelivered
, , . , , .
Connect Publish
RTMP, publish
connect
, Larix
( ), . - BroadcastService
.
?
, , , , , .
. ,
publish
, , , , ( ).publish
( ). .
. , .
iOSでストリーミングするための無料のライブラリの選択肢はそれほど多くはなく、実際、すべてが1つのオプションに帰着します- HaishinKit
。それには疑いの余地のない利点があります-オープンソースです。Larix
グラフィックの配置と安定性の向上に失敗した場合は、オープンソースに飛び込んで改善できる場所を探します。
有料のSDKを購入する-それがすべての問題を解決することを期待しないでください、おそらくあなたはそれらのより多くを持っているでしょう(2000行以上のvcを学ぶ)。
そして、より多くのストリームでアセンブリを実行した後にのみ、さらにグローバルな結論を出すことができます。