SRGSSR / pillarbox-apple

A next-generation reactive media playback ecosystem for Apple platforms.
https://testflight.apple.com/join/TS6ngLqf
MIT License
60 stars 9 forks source link

Fix incorrect negative metrics when toggling AirPlay #976

Closed defagos closed 3 months ago

defagos commented 3 months ago

Description

This PR fixes negative metrics increments when toggling AirPlay (external playback).

negative-metrics

These occur because the AVPlayerItemAccessLog is cleared when transitioning between devices, leading to a decrease in totals and thus to negative increments.

Fixing this issue requires seing local and remote sessions as separate. We cannot namely reliably merge local and distant sessions, as this would require us to be able to capture the most recent AVPlayerItemAccessLogEvent values just before AirPlay is toggled. The issue is that we are often too late when we can detect that AirPlay has been toggled, so that we cannot capture most recent values, only new ones (empty just after the transition into / out of AirPlay).

Changes made

Checklist