Skip to content

Feature: CMCD v2#4816

Open
cotid-qualabs wants to merge 37 commits into
Dash-Industry-Forum:developmentfrom
qualabs:feature/cmcdv2
Open

Feature: CMCD v2#4816
cotid-qualabs wants to merge 37 commits into
Dash-Industry-Forum:developmentfrom
qualabs:feature/cmcdv2

Conversation

@cotid-qualabs
Copy link
Copy Markdown

@cotid-qualabs cotid-qualabs commented Aug 1, 2025

CMCD v2 Support - Comprehensive Implementation

This Pull Request introduces comprehensive support for CMCD (Common Media Client Data) Version 2, significantly expanding the player's capabilities for media analytics and client-side data reporting. The implementation leverages the @svta/cml-cmcd library's CmcdReporter to centralize reporting mechanisms, reducing complexity and improving maintainability while aligning with the latest CMCD specifications.

Key Features & Enhancements:

1. CMCD Reporter Integration

  • Strategic Architecture Shift: Migrated from manual CMCD reporting to using CmcdReporter from @svta/cml-cmcd library
  • Centralized Reporting Logic: All CMCD data transmission, event handling, and sequence number tracking now managed by the external reporter
  • Simplified Controller: CmcdController focuses on orchestration and configuration, delegating report transmission to CmcdReporter
  • Streamlined Model: CmcdModel specializes in calculating CMCD data for requests, with cleaner separation of concerns

2. CMCD v2 Specification Adherence

  • Supported CMCD v2 keys: ltc, rc, bg, sta, ttfb, ttlb, ts, url, ec, msd, e, cmsdd, cmsds, df, sn, pb, tpb, bsd, ab, tab, lab
  • Ensures correct mapping to HTTP headers or query parameters for request mode and body transmission mode for event mode
  • Backward compatibility mechanism for CMCD v1 through Common Media Library integration

3. New CMCD Reporting Modes

  • Event Mode (event): CMCD data reporting triggered by specific player events or configurable time intervals
    • Supported CMCD Events: ps, e, t, rr
    • Play State Events: s, p, k, r, a, w, e, f
    • Response Received: Reports after media segment/manifest response with metrics like ttfb, ttlb, and rc

4. Multiple Reporting Targets & Granular Configuration

  • New streaming.cmcd.targets array for configuring multiple CMCD reporting endpoints
  • Per-target configuration:
    • url: Destination URL for CMCD reports
    • mode: Transmission mode (query or header)
    • enabledKeys: Specific CMCD keys to include (defaults to only mandatory if not defined)
    • events: Player events that trigger reports (defaults to none if not defined)
    • timeInterval: Interval in seconds for periodic reports (0 disables)
    • includeInRequests: HTTP request types to include CMCD data for

5. Enhanced Architecture & Separation of Concerns

  • CmcdController: Orchestrates CMCD v2 data collection, manages CmcdReporter instances, and coordinates with interceptors
  • CmcdModel: Calculates CMCD data for various request types with renamed methods (calculateCmcdDataForRequest) for clarity
  • Removed Redundant Code: Eliminated manual event handling, sequence tracking, and custom HTTP request logic (now handled by CmcdReporter)

6. Request/Response Interceptors

  • _cmcdRequestModeInterceptor: Injects CMCD data into outgoing requests (for query and header modes)
  • _cmcdResponseReceivedInterceptor: Processes incoming responses to gather data and trigger reports

7. Batching Mechanism via CmcdReporter

  • Batching by Size (batchSize): Sends batch immediately when count reaches configured size

8. Settings Abstraction Layer

  • CmcdPropertyMap: Declarative configuration mapping logical property names to physical paths

    • Version-aware properties (different paths for v1 vs v2)
    • Priority-based fallback: manifest → settings → default
    • Context-aware paths with variables
  • CmcdConfigAccessor: Unified API for CMCD configuration access

    • Core methods: get(), has(), getVersion(), isEnabled(), getTargets(), getTarget()
    • Automatic version detection with caching
    • Smart path resolution supporting dot-notation and array notation
  • Benefits:

    • Single source of truth for property mappings
    • Version-agnostic business logic
    • Future-proof for CMCD v3+ (only PropertyMap updates needed)

9. Common Media Library Integration

  • Updated @svta/common-media-library dependency
  • Leverages enhanced encodeCmcd function for key filtering, whitelisting, and custom key management
  • Integrated CmcdReporter for standardized reporting across SVTA ecosystem

10. New Sample Pages

  • CMCD v2 Reporting: Showcases v2 setup and target configurations for each mode
  • CMCD v2 Callbacks with Network Interceptors: Demonstrates custom keys via callbacks and post-response data processing

11. Unit Testing

  • Expanded test suite covering CMCD v2 scenarios, configurations, and CmcdReporter integration

Main Files Affected:

  • src/streaming/controllers/CmcdController.js: Refactored to instantiate and manage CmcdReporter, removed manual event/reporting logic, uses CmcdConfigAccessor
  • src/streaming/models/CmcdModel.js: Simplified to focus on CMCD data calculation with renamed methods, uses CmcdConfigAccessor
  • src/core/Settings.js: Updated with new CMCD v2 configuration options (streaming.cmcd.targets, version selection)
  • src/streaming/cmcd/config/CmcdPropertyMap.js: Declarative configuration for version-aware property mappings
  • src/streaming/cmcd/config/CmcdConfigAccessor.js: Abstraction layer providing unified configuration API
  • package.json: Updated dependencies for @svta/cml-cmcd library integration

Future Work

  • Implement Remaining CMCD v2 Keys: Review specification and implement any unsupported keys based on use cases and community feedback

@cotid-qualabs cotid-qualabs marked this pull request as ready for review August 1, 2025 19:52
Comment thread src/streaming/controllers/CmcdController.js Outdated
@cotid-qualabs
Copy link
Copy Markdown
Author

Hi @gorkemg , I just renamed the timeOuts variable to timeouts as requested. Also added a PR from a contributor on our fork, adding aggregated bitrate keys (ab, lab, tab).

@dsilhavy dsilhavy added this to the 5.1.0 milestone Aug 18, 2025
@dsilhavy dsilhavy removed the request for review from minhkstn August 19, 2025 09:34
@dsilhavy
Copy link
Copy Markdown
Collaborator

Related issue #4507

@Jason239
Copy link
Copy Markdown

Jason239 commented Aug 25, 2025

@cotid-qualabs
I'm not sure if it's appropriate to write this here, but in the _doLicenseRequest function of ProtectionController.js, the getCmcdParametersFromManifest() function is called through the cmcdController instance, but this function has not yet been moved to CmcdController and still exists in CmcdModel, causing an error when playing DRM content.

@cotid-qualabs
Copy link
Copy Markdown
Author

Thank you @Jason239 , I will take a look at this as soon as I can. Good catch!

@cotid-qualabs
Copy link
Copy Markdown
Author

I have fixed the getCmcdParametersFromManifest function call and included unit test coverage for cmcd implementation on ProtectionController.js

Comment thread src/core/Settings.js Outdated
Comment thread src/core/Settings.js Outdated
Comment thread src/streaming/constants/Constants.js Outdated
Comment thread src/streaming/constants/Constants.js Outdated
Comment thread src/streaming/constants/Constants.js Outdated
Comment thread src/streaming/controllers/CmcdController.js Outdated
Comment thread src/streaming/controllers/CmcdController.js Outdated
Comment thread src/streaming/models/CmcdModel.js Outdated
Comment thread src/streaming/protection/controllers/ProtectionController.js Outdated
Comment thread src/streaming/vo/CmcdReportRequest.js
@cotid-qualabs
Copy link
Copy Markdown
Author

cotid-qualabs commented Oct 22, 2025

Hi @dsilhavy ! All requested changes have been implemented, including removing Response Mode and adding Response Received. However, this implementation depends on Common Media Library "response received" PR (streaming-video-technology-alliance/common-media-library#268) being merged and version 0.18.2 being released. Then I need to update CML version on dash.js

@dsilhavy
Copy link
Copy Markdown
Collaborator

@cotid-qualabs I would like to review this PR for v5.2.0. Can I please ask you to rebase your changes against the latest development branch

@cotid-qualabs
Copy link
Copy Markdown
Author

cotid-qualabs commented Feb 2, 2026

Hi @dsilhavy ! Just wanted to let you know that new implementation for CMCDv2 using CML CmcdReporter is almost ready on this Draft PR qualabs#159 . We just need to wait for CML release.

cotid-qualabs and others added 4 commits February 2, 2026 15:07
* cmcd reporter initialization

* request mode migration

* event mode migration

* cmcd model migration

* fix cmcd model unit tests

* fixes for cmcd parameters and cleanup -
protection controller fixes WIP

* cleanup and update unit tests

* refactor unit tests and fixes

* fix unit tests and remove batchTimer
* ab, lab and tab inner list and request mode

* ab, tab and lab inner list for v2

* bl inner list and event mode

* br inner list and event mode

* toInnerList helper

* bsd inner list

* mtp inner list and event mode

* nor inner list

* pb inner list and event mode

* tp inner list and event mode

* tpb inner list and event mode

* fix unit tests
@dsilhavy dsilhavy moved this to Selected for Development in dash.js Version 5.2.0 Feb 10, 2026
* chore: update CML dependencies

* fix: update common media request

* fix: update resourceTiming properties to use performance.now()

* fix: update cmcd data formatting

* fix: remove redundant rr values

* refactor: simplify cmcd reporting

* fix: test mock requests missing parameters

* chore: update cml cmcd version

* should not send report if events are undefined

* fix unit tests

---------

Co-authored-by: cotid-qualabs <constanzad@qualabs.com>
@dsilhavy
Copy link
Copy Markdown
Collaborator

Related discussion: video-dev/hls.js#7725

littlespex and others added 2 commits March 4, 2026 14:29
* feat: add CMCD v2 Playwright E2E tests with spec validation

Adds comprehensive E2E tests using Playwright to validate CMCD v2 payloads
at the network level during real playback. Uses @svta/cml-cmcd validation
functions (validateCmcd, validateCmcdHeaders, validateCmcdEvent, validateCmcdKeys)
for spec-level compliance checks across query, header, and event modes.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* feat: replace Playwright E2E tests with Karma functional tests for CMCD v2

Replace the Playwright-based E2E test suite with Karma functional tests
that use XHR interceptors to validate CMCD v2 spec compliance. This
eliminates the @playwright/test dependency (~100MB) while maintaining
full test coverage across all three transmission modes (query, header,
event), key filtering, and version validation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* refactor: remove double parsing from CMCD v2 tests

CmcdRequestCollector now stores raw CMCD strings instead of pre-parsed
objects, removing its dependency on @svta/cml-cmcd entirely. Tests use
validation function return values (result.data) for both spec validation
and data assertions in a single pass.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* chore: update cml packages

* fix: add logging to xhr collector

* refactor: use unified collector and validateCmcdRequest for CMCD v2 tests

Rewrite CmcdRequestCollector with a single requests array storing
httpRequest objects compatible with CML's validateCmcdRequest(). Replace
mode-specific validators (validateCmcd, validateCmcdHeaders) with the
unified validateCmcdRequest() and remove the invalid validateCmcdKeys
test that was passing a string to a function expecting a parsed object.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
@dsilhavy dsilhavy moved this from Selected for Development to In Progress in dash.js Version 5.2.0 Mar 10, 2026
@dsilhavy
Copy link
Copy Markdown
Collaborator

@cotid-qualabs I finally found the time to look into the PR again. Would it be possible to grant me write access to the upstream repo? I will probably want to apply some minor changes to the PR and I think it would be easier if I can add changes to the PR myself rather than putting everything in review comments

@cotid-qualabs
Copy link
Copy Markdown
Author

Hi @dsilhavy ! Check if you have access now

@dsilhavy
Copy link
Copy Markdown
Collaborator

Hi @dsilhavy ! Check if you have access now

Thanks @cotid-qualabs , works :)

littlespex and others added 10 commits April 29, 2026 16:15
Rename targets->eventTargets, timeInterval->interval, includeOnRequests->
includeInRequests across settings, samples, and tests. Switch event
validation to validateCmcdEvents (batch). HTTPLoader now accepts empty
POST bodies so CMCD event endpoints don't trigger retries.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

6 participants