Skip to content

Avoid Redundant DRM License Requests for Already-Usable Keys#5016

Open
petegalt wants to merge 1 commit into
Dash-Industry-Forum:developmentfrom
petegalt:feature/skip-redundant-license-requests
Open

Avoid Redundant DRM License Requests for Already-Usable Keys#5016
petegalt wants to merge 1 commit into
Dash-Industry-Forum:developmentfrom
petegalt:feature/skip-redundant-license-requests

Conversation

@petegalt
Copy link
Copy Markdown

@petegalt petegalt commented Apr 9, 2026

Feature Request: Avoid Redundant DRM License Requests for Already-Usable Keys

Summary

When a multi-key DRM license has already been acquired, dash.js currently issues redundant license requests for key IDs (KIDs) that the CDM already reports as usable. This feature adds checks at multiple points in the protection pipeline to skip unnecessary license exchanges, reducing network overhead and improving playback startup for multi-period or multi-key encrypted content.

Motivation

In scenarios involving multi-key licenses (e.g. a single license response covers multiple KIDs), the player may encounter needkey/encrypted events or manifest-signaled init data for KIDs that are already available in the CDM. Without this optimization, each event triggers a full license server round-trip even though the CDM can already decrypt the content. This is wasteful and can introduce unnecessary latency, especially on low-bandwidth connections or with rate-limited license servers.

Changes

1. CommonEncryption.js — Extract Key IDs from PSSH boxes

  • New static method: extractKeyIdsFromPssh(data)
  • Parses concatenated PSSH box data and extracts KIDs from version ≥ 1 PSSH boxes.
  • Returns an array of hex-encoded key ID strings.
  • Used by ProtectionController to determine which KIDs are referenced in incoming init data.

2. ProtectionController.js — Skip license requests when keys are already usable

  • New private function: _isKeyIdUsableInCdm(keyId)

    • Checks the internal keyStatusMap for a normalized key ID.
    • Returns true if the CDM reports the key as usable.
    • Called in createKeySession() before creating a new session, short-circuiting if the key is already available.
  • New private function: _areAllKeysUsableForInitData(initData)

    • Uses CommonEncryption.extractKeyIdsFromPssh() to get all KIDs from the init data.
    • Returns true only if every extracted KID is already usable in the CDM.
    • Called in _onNeedKey() to skip processing encrypted events when all referenced keys are already available.
  • Guard in createKeySession(): Before enforcing session limits or creating a session, checks _isKeyIdUsableInCdm() and returns early with a debug log if the key is already usable.

  • Guard in _onNeedKey(): After duplicate init data checks but before dispatching to key system selection, checks _areAllKeysUsableForInitData() and returns early for non-SINF init data when all keys are usable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants