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

Expose framerate in pk playback info #331

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
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
25 changes: 22 additions & 3 deletions Classes/Events/EventsPayloads/PKPlaybackInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,21 @@ import AVFoundation
public let indicatedBitrate: Double
/// The throughput of the playback (download speed)
public let observedBitrate: Double
/// The playback framerate (this value is zero if it is not reported)
@objc public let framesPerSecond: Float

init(bitrate: Double, indicatedBitrate: Double, observedBitrate: Double) {
init(bitrate: Double,
indicatedBitrate: Double,
observedBitrate: Double,
framesPerSecond: Float) {
self.bitrate = bitrate
self.indicatedBitrate = indicatedBitrate
self.observedBitrate = observedBitrate
self.framesPerSecond = framesPerSecond
}

convenience init(logEvent: AVPlayerItemAccessLogEvent) {
convenience init(logEvent: AVPlayerItemAccessLogEvent,
playerItem: AVPlayerItem) {
let bitrate: Double
if logEvent.segmentsDownloadedDuration > 0 {
// bitrate is equal to:
Expand All @@ -38,6 +45,18 @@ import AVFoundation
}
let indicatedBitrate = logEvent.indicatedBitrate
let observedBitrate = logEvent.observedBitrate
self.init(bitrate: bitrate, indicatedBitrate: indicatedBitrate, observedBitrate: observedBitrate)

var framesPerSecond: Float = 0

for track in playerItem.tracks {
if track.assetTrack.mediaType == AVMediaType.video {
framesPerSecond = track.currentVideoFrameRate
}
}

self.init(bitrate: bitrate,
indicatedBitrate: indicatedBitrate,
observedBitrate: observedBitrate,
framesPerSecond: framesPerSecond)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ extension AVPlayerEngine {
PKLog.verbose("event log:\n event log: averageAudioBitrate - \(lastEvent.averageAudioBitrate)\n event log: averageVideoBitrate - \(lastEvent.averageVideoBitrate)\n event log: indicatedAverageBitrate - \(lastEvent.indicatedAverageBitrate)\n event log: indicatedBitrate - \(lastEvent.indicatedBitrate)\n event log: observedBitrate - \(lastEvent.observedBitrate)\n event log: observedMaxBitrate - \(lastEvent.observedMaxBitrate)\n event log: observedMinBitrate - \(lastEvent.observedMinBitrate)\n event log: switchBitrate - \(lastEvent.switchBitrate)")
}

self.post(event: PlayerEvent.PlaybackInfo(playbackInfo: PKPlaybackInfo(logEvent: lastEvent)))
self.post(event: PlayerEvent
.PlaybackInfo(playbackInfo: PKPlaybackInfo(logEvent: lastEvent,
playerItem: playerItem)))
if self.lastIndicatedBitrate != lastEvent.indicatedBitrate {
self.lastIndicatedBitrate = lastEvent.indicatedBitrate
self.post(event: PlayerEvent.VideoTrackChanged(bitrate: lastEvent.indicatedBitrate))
Expand Down