Skip to content

CMCD Version 2 (CTA-5004) Support #7724

@littlespex

Description

@littlespex

Is your feature request related to a problem? Please describe.

hls.js currently implements CMCD version 1 (CTA-5004). The CTA-5004 specification has been updated to version 2 which introduces new keys, event-mode reporting, and structured field value encoding. Without v2 support, hls.js users cannot take advantage of the latest analytics and observability capabilities defined by the specification.

Related open issues that would be addressed:

Describe the solution you'd like

Add opt-in CMCD v2 support with the following scope:

Configuration

A version option on CMCDControllerConfig (1 | 2, default 1) to enable v2 behavior, and an eventTargets array for event-mode reporting endpoints:

const hls = new Hls({
  cmcd: {
    version: 2,
    sessionId: 'session-123',
    contentId: 'content-456',
    useHeaders: true,
    eventTargets: [
      {
        url: 'https://analytics.example.com/cmcd',
        events: ['ps', 'e', 'br'],
        interval: 30,
      },
    ],
  },
});

New v2 keys

Key Name Description
v Version CMCD version identifier (included when version >= 2)
st Stream Type "v" (VOD), "l" (LIVE), "ll" (LOW_LATENCY) — auto-detected from level details
sta Player State "s" (STARTING), "p" (PLAYING), "k" (SEEKING), "r" (REBUFFERING), "a" (PAUSED), "e" (ENDED), "f" (FATAL_ERROR) — tracked from media element events

v2 data format changes

Per the v2 spec, several existing keys use array values via Structured Field Value encoding: br, bl, mtp, tb, nor.

Event-mode reporting

CMCD v2 introduces event-mode reporting via CmcdReporter, where playback events (play state transitions, fatal errors, bitrate changes) are sent to configured endpoints independently from segment/playlist requests. This enables richer observability without coupling analytics to media request timing.

Dependency migration

Migrate CMCD encoding from @svta/common-media-library (which ships hundreds of individual files and causes source map issues — see #7718) to the dedicated @svta/cml-cmcd package, which provides a single bundled entry point with proper source maps.

Public type exports

Export v2 constants and types for TypeScript consumers: CMCD_V1, CMCD_V2, CmcdObjectType, CmcdStreamType, CmcdStreamingFormat, CmcdPlayerState, CmcdEventType, CmcdHeaderField, Cmcd, CmcdEncodeOptions, CmcdEventReportConfig, CmcdVersion.

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions