AVContentKeySession Best Practices

WWDC 2018

Posted by Den on September 13, 2018 · 7 mins read
AVContentKeySession Best Practices

AVContentKeySession Best Practices

WWDC 2018

AVContentKeySession Best Practices

WWDC 2018

FairPlay Streaming Overview

  • Introduced in 2015
  • Protects HLS streams
  • Specifies steps to securely deliver content decryption keys

AVContentKeySession

  • Introduced in 2017
  • Designed around content decryption keys
    - Simplified key loading process
    - Home for new content protection features
  • Great adoption — helps optimize key delivery

AVAssetResourceLoader

How Do I Reduce Playback Startup Delay ?

  • Preload keys that you predict might be used
  • Batch up key requests — reduce round-trips to key server

Could A key Be Requested Again ? YES

  • New keys might be required for decryption 
    ( AirPlay, Lightning Digital AV Adpater )
  • Always be prepared to answer redundant key requests

How Do I Preload All Keys ?

  • Need key identifier to load key
  • Obtain all key identifiers out-of-band
  • Advertise session keys ( EXT-X-SESSION-KEY ) in master m3u8
    - Initiate preloading urlAsset.resourceLoader.preloadsEligibleContentKeys = true
  • Measuring and Optimizing HLS Performance WWDC 2018

How Can My Live Streams Avoid The Thundering Herd?

  • Disperse key request events 👍
  • Clients rotate keys at the same time → impulse load on key server
  • Load keys before EXT-X-KEY tag appears
  • Scale live offering by load balancing key loading requests
  • Advances in HTTP Live Streaming WWDC 2017

What is Offline Rentals ?

  • Define 2 expiration durations on offline FairPlay Streaming keys
    - Storage duration
    - Playback duration
  • Expiration durations are enforced even when the device is offline

How Do I Do Offline Rentals ?

  • Use Offline Key TLLV
    - Signaled in CKC used while requesting persistent key

How Do I Do Offline Rentals ?

How Do I Handle Errors While Loading Keys ?

  • When something fails…
    - Report error to AVFoundation

Common Pitfalls While Delivering Keys

  • Taking too long to provide key response
    - Player times out waiting for key repsonse
    - Deliver keys as soon as possible
    - Survey playerItem.accessLogs()
  • Using same keys across variants with different HDCP requirements
    - HDCP requirements is signaled inside key response
    - Use multiple key identifiers
  • Using persistent keys to answer all key loading requests
    - Persistent keys cannot be shared across devices ( AirPlay )
    - Make sure key loading request accepts persistent keys
    - Minor API changes in iOS 11.2+

Is Persistent Key Accepted As Response?

  • Using AVContentKeySession
  • Using AVAssetResourceLoader