Skip to content

Commit

Permalink
Adjustment of VideoAdaptiveNetBitRateStrategy
Browse files Browse the repository at this point in the history
  • Loading branch information
shogo4405 committed Oct 28, 2023
1 parent e519d5f commit 83a6462
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions Sources/Codec/VideoCodecSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ public struct VideoCodecSettings: Codable {

func apply<T>(_ codec: VideoCodec<T>, rhs: VideoCodecSettings) {
if bitRate != rhs.bitRate {
logger.info("bitRate change from ", rhs.bitRate, " to ", bitRate)
let option = VTSessionOption(key: bitRateMode.key, value: NSNumber(value: bitRate))
if let status = codec.session?.setOption(option), status != noErr {
codec.delegate?.videoCodec(codec, errorOccurred: .failedToSetOption(status: status, option: option))
Expand Down
2 changes: 2 additions & 0 deletions Sources/Net/NetBitRateStrategyConvertible.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public final class VideoAdaptiveNetBitRateStrategy: NetBitRateStrategyConvertibl
if Self.sufficientBWCountsThreshold <= sufficientBWCounts {
let incremental = mamimumVideoBitRate / 10
stream.videoSettings.bitRate = min(stream.videoSettings.bitRate + incremental, mamimumVideoBitRate)
sufficientBWCounts = 0
} else {
sufficientBWCounts += 1
}
Expand All @@ -83,6 +84,7 @@ public final class VideoAdaptiveNetBitRateStrategy: NetBitRateStrategyConvertibl
guard let stream, 0 < stats.currentBytesOutPerSecond else {
return
}
sufficientBWCounts = 0
if 0 < stats.currentBytesOutPerSecond {
let bitRate = Int(stats.currentBytesOutPerSecond * 8) / (zeroBytesOutPerSecondCounts + 1)
stream.videoSettings.bitRate = max(bitRate - stream.audioSettings.bitRate, mamimumVideoBitRate / 10)
Expand Down

0 comments on commit 83a6462

Please sign in to comment.