Skip to content

Commit

Permalink
Update to use new client stats API
Browse files Browse the repository at this point in the history
  • Loading branch information
aravind-raveendran committed Oct 14, 2024
1 parent 412036c commit 6568113
Show file tree
Hide file tree
Showing 22 changed files with 605 additions and 823 deletions.
12 changes: 10 additions & 2 deletions LocalPackages/RTSCore/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,21 @@ let package = Package(
)
],
dependencies: [
.package(url: "https://github.com/millicast/millicast-sdk-swift-package", .upToNextMajor(from: Version(2, 0, 0, prereleaseIdentifiers: ["beta"])))
// Uncomment the below to consume Production, Alpha or Beta versions of SDK
//.package(url: "https://github.com/millicast/millicast-sdk-swift-package", .upToNextMajor(from: Version(2, 0, 0, prereleaseIdentifiers: ["beta"])))
],
targets: [
// Comment the below `binaryTarget` when using a Prod release of the SDK
.binaryTarget(
name: "MillicastSDK",
url: "https://jfrog-sfo.dolby.net:443/artifactory/dolbyio-rts-generic-fed/GitHubArtefacts/CoSMoSoftware/csmMillicastNativeSdk/staging/branch_dev/id-3706_sha-e878dc80/ios/millicast-native-sdk-2.1.0-XCFramework.zip",
checksum: "85347684dd2dd97e5d93f91a615e5952764aa126bfd782ff45ff39b12ebc09c4"
),
.target(
name: "RTSCore",
dependencies: [
.product(name: "MillicastSDK", package: "millicast-sdk-swift-package")
//.product(name: "MillicastSDK", package: "millicast-sdk-swift-package")
.byName(name: "MillicastSDK")
],
path: "Sources/RTSCore"
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ public actor SubscriptionManager {
case disconnected
}

public let subscriber = MCSubscriber()

@Published public var state: State = .disconnected
@Published public var streamStatistics: StreamStatistics?
@Published public var websocketState: MCConnectionState = .idle

private let subscriber = MCSubscriber()
private var sourceBuilder = SourceBuilder()
private let logHandler: MillicastLogHandler = .init()
private var isReconnectingPeerConnection: Bool = false
Expand Down Expand Up @@ -180,16 +180,6 @@ extension SubscriptionManager {
}
}

let statsObservation = Task { [weak self] in
guard let self else { return }
for await statsReport in self.subscriber.statsReport() {
guard !Task.isCancelled, let stats = StreamStatistics(statsReport) else {
return
}
await self.updateStats(stats)
}
}

let sourcesObservation = Task { [weak self] in
guard let self else { return }
for await sources in await self.sourceBuilder.sourceStream {
Expand All @@ -200,8 +190,9 @@ extension SubscriptionManager {
}

[
taskWebsocketStateObservation, taskPeerConnectionStateObservation, taskHttpErrorStateObservation, taskSignalingErrorStateObservation,
streamStoppedStateObservation, tracksObservation, statsObservation, sourcesObservation
taskWebsocketStateObservation, taskPeerConnectionStateObservation,
taskHttpErrorStateObservation, taskSignalingErrorStateObservation,
streamStoppedStateObservation, tracksObservation, sourcesObservation
].forEach(addEventObservationTask)

Self.logger.debug("👨‍🔧 Registered to subscriber events")
Expand All @@ -212,7 +203,6 @@ extension SubscriptionManager {
taskSignalingErrorStateObservation.value,
streamStoppedStateObservation.value,
tracksObservation.value,
statsObservation.value,
sourcesObservation.value
]
}
Expand All @@ -231,10 +221,6 @@ extension SubscriptionManager {
// MARK: Private Helpers

private extension SubscriptionManager {
func updateStats(_ stats: StreamStatistics) {
streamStatistics = stats
}

func updateState(to state: State) {
self.state = state
}
Expand Down
206 changes: 0 additions & 206 deletions LocalPackages/RTSCore/Sources/RTSCore/Models/StreamStatistics.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public struct SubscriptionConfiguration {
public static let maxBitrate: UInt = 0
public static let disableAudio = false
public static let enableStats = true
public static let playoutDelay: MCForcePlayoutDelay = MCForcePlayoutDelay(min: 500, max: 700)
public static let playoutDelay: MCForcePlayoutDelay = MCForcePlayoutDelay(min: 0, max: 700)
public static let forceSmooth: Bool = true
public static let bweMonitorDurationUs: UInt = 150000
public static let bweRateChangePercentage: Float = 0.05
Expand Down
42 changes: 20 additions & 22 deletions interactive-player/Interactive Viewer/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -143,41 +143,39 @@ Follow video: Switch audio source when a video is selected. If the selected vide
"stream.stats.mid.label" = "MID";
"stream.stats.current-rtt.label" = "Current RTT";
"stream.stats.total-rtt.label" = "Total RTT";
"stream.stats.video-resolution.label" = "Video Resolution";
"stream.stats.video-resolution.label" = "Video resolution";
"stream.stats.fps.label" = "FPS";
"stream.stats.video-bitrate.label" = "Video Bitrate";
"stream.stats.audio-bitrate.label" = "Audio Bitrate";
"stream.stats.video-total-received.label" = "Video Total Received";
"stream.stats.audio-total-received.label" = "Audio Total Received";
"stream.stats.video-packet-loss.label" = "Video Packet Loss";
"stream.stats.audio-packet-loss.label" = "Audio Packet Loss";
"stream.stats.video-jitter.label" = "Video Jitter";
"stream.stats.audio-jitter.label" = "Audio Jitter";
"stream.stats.video-bitrate.label" = "Video bitrate";
"stream.stats.audio-bitrate.label" = "Audio bitrate";
"stream.stats.video-total-received.label" = "Video total received";
"stream.stats.audio-total-received.label" = "Audio total received";
"stream.stats.video-packet-loss.label" = "Video packet loss";
"stream.stats.audio-packet-loss.label" = "Audio packet loss";
"stream.stats.video-jitter.label" = "Video jitter";
"stream.stats.audio-jitter.label" = "Audio jitter";
"stream.stats.codecs.label" = "Codecs";
"stream.stats.timestamp.label" = "Timestamp (GMT)";
"stream.stats.total-stream-time.label" = "Total Stream Time";
"stream.stats.total-stream-time.label" = "Total stream time";
"stream.stats.server.label" = "Server";
"stream.stats.cluster.label" = "Cluster";
"stream.stats.decoder-impl.label" = "Decoder Impl";
"stream.stats.decoder-impl.label" = "Decoder implementation";
"stream.stats.processing-delay.label" = "Processing delay";
"stream.stats.decode-time.label" = "Decode time";
"stream.stats.packets-received.label" = "Packets received";
"stream.stats.frames-decoded.label" = "Frames decoded";
"stream.stats.frames-dropped.label" = "Frames dropped";
"stream.stats.jitter-buffer-est-count.label" = "Jitter buffer Est count";
"stream.stats.jitter-buffer-delay.label" = "Jitter buffer delay";
"stream.stats.jitter-buffer-target-delay.label" = "Jitter buffer target delay";
"stream.stats.jitter-buffer-minimum-delay.label" = "Jitter buffer min delay";
"stream.stats.target-bitrate.label" = "Target Bitrate";
"stream.stats.outgoing-bitrate.label" = "Outgoing Bitrate";
"stream.stats.target-bitrate.label" = "Target bitrate";
"stream.stats.outgoing-bitrate.label" = "Outgoing bitrate";
"stream.stats.subscriber-id.label" = "Subscriber ID";
"stream.stats.stream-view-id.label" = "Stream View ID";
"stream.stats.cluster-id.label" = "Cluster ID";
"stream.stats.freeze-count.label" = "Freeze Count";
"stream.stats.freeze-duration.label" = "Freeze Duration";
"stream.stats.pause-count.label" = "Pause Count";
"stream.stats.pause-duration.label" = "Pause Duration";
"stream.stats.retransmitted-packets.label" = "Retransmitted Packets";
"stream.stats.retransmitted-bytes.label" = "Retransmitted Bytes";
"stream.stats.incoming-bitrate.label" = "Incoming Bitrate";
"stream.stats.freeze-count.label" = "Freeze count";
"stream.stats.freeze-duration.label" = "Freeze duration";
"stream.stats.pause-count.label" = "Pause count";
"stream.stats.pause-duration.label" = "Pause duration";
"stream.stats.retransmitted-packets.label" = "Retransmitted packets";
"stream.stats.retransmitted-bytes.label" = "Retransmitted bytes";
"stream.stats.incoming-bitrate.label" = "Incoming bitrate";

Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ final actor VideoTracksManager {
nonisolated private func observeStats() {
Task { [weak self] in
guard let self else { return }
let cancellable = await self.subscriptionManager.$streamStatistics
let cancellable = await self.subscriptionManager.subscriber.statsPublisher
.receive(on: DispatchQueue.main)
.sink { [weak self] statistics in
guard let self, let stats = statistics else { return }
guard let self else { return }
Task {
await self.saveProjectedTimeStamp(stats: stats)
await self.saveProjectedTimeStamp(stats: statistics)
}
}
await self.store(cancellable: cancellable)
Expand Down Expand Up @@ -292,11 +292,11 @@ private extension VideoTracksManager {
projectedTimeStampForMids.removeValue(forKey: mid)
}

func saveProjectedTimeStamp(stats: StreamStatistics) {
stats.videoStatsInboundRtpList.forEach {
if let mid = $0.mid, projectedMids.contains(mid),
projectedTimeStampForMids[mid] == nil {
projectedTimeStampForMids[mid] = $0.timestamp
func saveProjectedTimeStamp(stats: MCSubscriberStats) {
stats.trackStats.forEach {
if projectedMids.contains($0.mid),
projectedTimeStampForMids[$0.mid] == nil {
projectedTimeStampForMids[$0.mid] = $0.timestamp
}
}
}
Expand Down
Loading

0 comments on commit 6568113

Please sign in to comment.