AVQueuePlayer best practices

These are follow up questions for: https://feedbackassistant.apple.com/feedback/22779473

For a large AVQueuePlayer queue (50-100+ HLS items), does AVFoundation guarantee it only allocates video decode sessions for the active and next item? Our profiling suggests this is the case, but we want to confirm whether we can rely on this behavior or if we should implement an application-side sliding window to limit concurrent decoders.

Answered by Engineer in 893069022

The wording in the AVQueuePlayer documentation in AVPlayer.h is

/// For best performance clients should typically enqueue only as many AVPlayerItems as are necessary
/// to ensure smooth playback. Note that once an item is enqueued it becomes eligible to be loaded and
/// made ready for playback, with whatever I/O and processing overhead that entails.

However, it is the case that AVFoundation also endeavors to optimize usage of video playback resources and will not allocate 50-100+ video decode sessions.

Still, every AVPlayerItem and AVURLAsset consume some resources even when they're way down the queue. So it's best to have some reasonable bound on how many items ahead you enqueue at a time. For super short items, a higher number may help, but if the items are at least 30 seconds long, probably 2 is sufficient (the current one and the next one).

The wording in the AVQueuePlayer documentation in AVPlayer.h is

/// For best performance clients should typically enqueue only as many AVPlayerItems as are necessary
/// to ensure smooth playback. Note that once an item is enqueued it becomes eligible to be loaded and
/// made ready for playback, with whatever I/O and processing overhead that entails.

However, it is the case that AVFoundation also endeavors to optimize usage of video playback resources and will not allocate 50-100+ video decode sessions.

Still, every AVPlayerItem and AVURLAsset consume some resources even when they're way down the queue. So it's best to have some reasonable bound on how many items ahead you enqueue at a time. For super short items, a higher number may help, but if the items are at least 30 seconds long, probably 2 is sufficient (the current one and the next one).

AVQueuePlayer best practices
 
 
Q