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

feat(SUP-39506): iOS - mobile SDK - add control for bitrate and resolution capping #472

Merged
merged 2 commits into from
Nov 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ extension AVPlayerEngine {
if #available(iOS 10.0, tvOS 10.0, *) {
playerItem.preferredForwardBufferDuration = newAsset.playerSettings.network.preferredForwardBufferDuration
}

if #available(iOS 11.0, *) {
inbalvasserman marked this conversation as resolved.
Show resolved Hide resolved
playerItem.preferredMaximumResolution = newAsset.playerSettings.network.preferredMaximumResolution
}

// Add observers
self.removeObservers()
Expand Down
14 changes: 14 additions & 0 deletions Classes/Player/PKPlayerSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ typealias SettingsChange = ((PlayerSettingsType) -> Void)
}
}

/// Indicates ta preferred maximum video resolution
///
/// Set preferredMaximumResolution to non-zero to indicates a preferred maximum video resolution. This property only applies to HTTP Live Streaming assets.
/// zero is the default value and it indicates there is no limit on the video resolution
///
/// @available(iOS 11.0, *) via AVPlayerItem
inbalvasserman marked this conversation as resolved.
Show resolved Hide resolved
@objc public var preferredMaximumResolution: CGSize = CGSize(width: 0, height: 0){
didSet {
self.onChange?(.preferredMaximumResolution(preferredMaximumResolution))
}
}

/// Indicates the media duration the caller prefers the player to buffer from the network ahead of the playhead to guard against playback disruption.
///
/// The value is in seconds. If it is set to 0, the player will choose an appropriate level of buffering for most use cases.
Expand Down Expand Up @@ -65,6 +77,7 @@ typealias SettingsChange = ((PlayerSettingsType) -> Void)
@objc public func createCopy() -> PKNetworkSettings {
let copy = PKNetworkSettings()
copy.preferredPeakBitRate = self.preferredPeakBitRate
copy.preferredMaximumResolution = self.preferredMaximumResolution
copy.preferredForwardBufferDuration = self.preferredForwardBufferDuration
copy.automaticallyWaitsToMinimizeStalling = self.automaticallyWaitsToMinimizeStalling

Expand Down Expand Up @@ -143,6 +156,7 @@ typealias SettingsChange = ((PlayerSettingsType) -> Void)

enum PlayerSettingsType {
case preferredPeakBitRate(Double)
case preferredMaximumResolution(CGSize)
case preferredForwardBufferDuration(Double)
case automaticallyWaitsToMinimizeStalling(Bool)
case configuredTimeOffsetFromLive(CMTime)
Expand Down
4 changes: 4 additions & 0 deletions Classes/Player/PlayerWrapper/AVPlayerWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ open class AVPlayerWrapper: NSObject, PlayerEngine {
switch settingsType {
case .preferredPeakBitRate(let preferredPeakBitRate):
self.currentPlayer.currentItem?.preferredPeakBitRate = preferredPeakBitRate
case .preferredMaximumResolution(let preferredMaximumResolution):
if #available(iOS 11.0, *) {
self.currentPlayer.currentItem?.preferredMaximumResolution = preferredMaximumResolution
}
case .preferredForwardBufferDuration(let preferredForwardBufferDuration):
if #available(iOS 10.0, tvOS 10.0, *) {
self.currentPlayer.currentItem?.preferredForwardBufferDuration = preferredForwardBufferDuration
Expand Down
Loading