-
-
Notifications
You must be signed in to change notification settings - Fork 618
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1308 from shogo4405/feature/bitrate-storategy
Support the NetBitRateStrategy.
- Loading branch information
Showing
16 changed files
with
161 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import Foundation | ||
|
||
public final class VideoAdaptiveNetBitRateStrategy: NetBitRateStrategyConvertible { | ||
public weak var stream: NetStream? | ||
public let mamimumVideoBitRate: Int | ||
public let mamimumAudioBitRate: Int = 0 | ||
private var zeroBytesOutPerSecondCounts: Int = 0 | ||
|
||
public init(mamimumVideoBitrate: Int) { | ||
self.mamimumVideoBitRate = mamimumVideoBitrate | ||
} | ||
|
||
public func setUp() { | ||
zeroBytesOutPerSecondCounts = 0 | ||
stream?.videoSettings.bitRate = mamimumVideoBitRate | ||
} | ||
|
||
public func sufficientBWOccured(_ stats: NetBitRateStats) { | ||
logger.info(stats) | ||
guard let stream else { | ||
return | ||
} | ||
stream.videoSettings.bitRate = min(stream.videoSettings.bitRate + 64 * 1000, mamimumVideoBitRate) | ||
} | ||
|
||
public func insufficientBWOccured(_ stats: NetBitRateStats) { | ||
logger.info(stats) | ||
guard let stream, 0 < stats.currentBytesOutPerSecond else { | ||
return | ||
} | ||
if 0 < stats.currentBytesOutPerSecond { | ||
let bitRate = Int(stats.currentBytesOutPerSecond * 8) / (zeroBytesOutPerSecondCounts + 1) | ||
stream.videoSettings.bitRate = max(bitRate - stream.audioSettings.bitRate, 64 * 1000) | ||
zeroBytesOutPerSecondCounts = 0 | ||
} else { | ||
zeroBytesOutPerSecondCounts += 1 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.