Skip to content

Commit

Permalink
Revamp Device Profile Builder (#519)
Browse files Browse the repository at this point in the history
  • Loading branch information
holow29 authored Jan 13, 2024
1 parent b038f05 commit e2d6237
Show file tree
Hide file tree
Showing 7 changed files with 167 additions and 261 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@ extension BaseItemDto {

func videoPlayerViewModel(with mediaSource: MediaSourceInfo) async throws -> VideoPlayerViewModel {

let builder = DeviceProfileBuilder()
let currentVideoPlayerType = Defaults[.VideoPlayer.videoPlayerType]
// TODO: fix bitrate settings
let tempOverkillBitrate = 360_000_000
builder.setMaxBitrate(bitrate: tempOverkillBitrate)
let profile = builder.buildProfile()
let profile = DeviceProfileBuilder.buildProfile(for: currentVideoPlayerType, maxBitrate: tempOverkillBitrate)

let userSession = Container.userSession.callAsFunction()

Expand Down
400 changes: 161 additions & 239 deletions Shared/Objects/DeviceProfileBuilder.swift

Large diffs are not rendered by default.

5 changes: 0 additions & 5 deletions Shared/Services/SwiftfinDefaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,6 @@ extension Defaults.Keys {
)
}

enum Native {

static let fMP4Container: Key<Bool> = .init("fmp4Container", default: false, suite: .generalSuite)
}

enum Overlay {

static let chapterSlider: Key<Bool> = .init("chapterSlider", default: true, suite: .generalSuite)
Expand Down
5 changes: 2 additions & 3 deletions Shared/ViewModels/VideoPlayerViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@ class VideoPlayerViewModel: ViewModel {

var hlsPlaybackURL: URL {

let segmentContainer = Defaults[.VideoPlayer.Native.fMP4Container] ? "mp4" : "ts"
let userSession = Container.userSession.callAsFunction()

let parameters = Paths.GetMasterHlsVideoPlaylistParameters(
isStatic: true,
tag: mediaSource.eTag,
playSessionID: playSessionID,
segmentContainer: segmentContainer,
segmentContainer: "mp4",
minSegments: 2,
mediaSourceID: mediaSource.id!,
deviceID: UIDevice.vendorUUIDString,
Expand All @@ -46,7 +45,7 @@ class VideoPlayerViewModel: ViewModel {
.joined(separator: ","),
isBreakOnNonKeyFrames: true,
requireAvc: false,
transcodingMaxAudioChannels: 6,
transcodingMaxAudioChannels: 8,
videoCodec: videoStreams
.compactMap(\.codec)
.joined(separator: ","),
Expand Down
2 changes: 1 addition & 1 deletion Swiftfin tvOS/Views/VideoPlayer/NativeVideoPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class UINativeVideoPlayerViewController: AVPlayerViewController {

super.init(nibName: nil, bundle: nil)

let newPlayer: AVPlayer = .init(url: manager.currentViewModel.hlsPlaybackURL)
let newPlayer: AVPlayer = .init(url: manager.currentViewModel.playbackURL)

newPlayer.allowsExternalPlayback = true
newPlayer.appliesMediaSelectionCriteriaAutomatically = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import SwiftUI

struct NativeVideoPlayerSettingsView: View {

@Default(.VideoPlayer.Native.fMP4Container)
private var fMP4Container
@Default(.VideoPlayer.resumeOffset)
private var resumeOffset

Expand All @@ -33,13 +31,6 @@ struct NativeVideoPlayerSettingsView: View {
} footer: {
Text("Resume content seconds before the recorded resume time")
}

Section {

Toggle("fMP4 Container", isOn: $fMP4Container)
} footer: {
Text("Use fMP4 container to allow hevc content on supported devices")
}
}
.navigationTitle("Native Player")
}
Expand Down
2 changes: 1 addition & 1 deletion Swiftfin/Views/VideoPlayer/NativeVideoPlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class UINativeVideoPlayerViewController: AVPlayerViewController {

super.init(nibName: nil, bundle: nil)

let newPlayer: AVPlayer = .init(url: manager.currentViewModel.hlsPlaybackURL)
let newPlayer: AVPlayer = .init(url: manager.currentViewModel.playbackURL)

newPlayer.allowsExternalPlayback = true
newPlayer.appliesMediaSelectionCriteriaAutomatically = false
Expand Down

0 comments on commit e2d6237

Please sign in to comment.