SRGSSR / pillarbox-apple

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

Add support for `AVMetrics` #925

Open defagos opened 2 months ago

defagos commented 2 months ago

As a Pillarbox developer I want to benefit from new APIs introduced in iOS and tvOS 18 to better understand the behavior of Pillarbox.

Remarks

timeSpentInInitialStartup provided in AVMetricPlayerItemPlaybackSummaryEvent matches timeTaken from AVMetricPlayerItemInitialLikelyToKeepUpEvent. These values are smaller than the values we get when measuring the total startup time according to recommendations provided at WWDC. It is also the same value as provided by the first event startupTime in the access log.

Hints

Acceptance criteria

Tasks

defagos commented 2 months ago

Gave a shot at the implementation for fun on 925/avmetrics. Made very significant progress:

defagos commented 1 month ago

The single subscriber issue is not related to the AVMetrics API, rather to a known limitation of AsyncStreams.

This issue also affects different streams matching different event types. Only one stream will deliver events, at random if Tasks are started at the same time.

For this reason I think that:

defagos commented 1 month ago

To avoid issues with marking APIs as available on iOS / tvOS 18+ I would suggest the following:

Since AVMetrics APIs are limited anyway because AsyncStreams can only be consumed once this provides what we expect nicely without making our API unnecessarily complex. Of course AVMetricEvent information is sometimes a bit richer but usually we are interested by a few pieces of information only anyway.

defagos commented 1 month ago

Current state as of beta 5:

defagos commented 1 month ago

Timings from content key metric events still zero on iOS 18 beta 6 😭

defagos commented 3 weeks ago

Still missing with iOS 18 beta 7.

defagos commented 3 weeks ago

Radar Missing timing metrics in AVMetricEvents, in particular AVMetricContentKeyRequestEvent filed under FB14875223.

defagos commented 2 weeks ago

Still missing with iOS 18 beta 8.

defagos commented 1 week ago

I received feedback for FB14875223. This is expected behavior according to Apple, after all there is no URLSession which is officially associated with a AVContentKeySessionDelegate (we introduce our own). From a design perspective I still think that the AVMetrics API is misleading, though.

The recommended approach to obtain metrics is to access the URLSession we use and access its NSURLSessionTaskMetrics. If we really want to extract DRM timings I therefore see three options: