Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix]Demo stats formula for publishing bitrate #601

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions DemoApp/Sources/Views/StatsView/DemoStatsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,19 +129,15 @@ struct DemoStatsView: View {
title: "PUBLISH BITRATE",
value: 0,
valueTransformer: { $0?.publisherStats.totalBytesSent ?? 0 },
presentationTransformer: { newValue, previousValue in
bytesFormatter(from: max(newValue - previousValue, 0))
}
presentationTransformer: { bitrateFormatter(newValue: $0, oldValue: $1) }
)
} _: {
DemoStatView(
viewModel,
title: "RECEIVING BITRATE",
value: 0,
valueTransformer: { $0?.subscriberStats.totalBytesReceived ?? 0 },
presentationTransformer: { newValue, previousValue in
bytesFormatter(from: max(newValue - previousValue, 0))
}
presentationTransformer: { bitrateFormatter(newValue: $0, oldValue: $1) }
)
}
}
Expand Down Expand Up @@ -210,6 +206,22 @@ struct DemoStatsView: View {
return "none"
}
}

private func bitrateFormatter(
newValue: Int,
oldValue: Int
) -> String {
guard
let statsCollectionInterval = viewModel.call?.state.statsCollectionInterval,
statsCollectionInterval > 0
else {
return bytesFormatter(from: 0)
}

let diff = newValue - oldValue
let bits = diff * 8
return bytesFormatter(from: max(bits / statsCollectionInterval, 0))
}
}

extension View {
Expand Down
3 changes: 3 additions & 0 deletions Sources/StreamVideo/CallState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ public class CallState: ObservableObject {
@Published public internal(set) var duration: TimeInterval = 0
@Published public internal(set) var statsReport: CallStatsReport?

@Published public internal(set) var statsCollectionInterval: Int = 0

/// A public enum representing the settings for incoming video streams in a WebRTC
/// session. This enum supports different policies like none, manual, or
/// disabled, each potentially applying to specific session IDs.
Expand Down Expand Up @@ -323,6 +325,7 @@ public class CallState: ObservableObject {
update(from: response.call)
mergeMembers(response.members)
ownCapabilities = response.ownCapabilities
statsCollectionInterval = response.statsOptions.reportingIntervalMs / 1000
}

internal func update(from response: GetCallResponse) {
Expand Down
Loading