Skip to content

Cmcdv2: keys compliance check#160

Merged
cotid-qualabs merged 12 commits into
feature/cmcdv2from
cmcdv2/compliance-check
Feb 2, 2026
Merged

Cmcdv2: keys compliance check#160
cotid-qualabs merged 12 commits into
feature/cmcdv2from
cmcdv2/compliance-check

Conversation

@cotid-qualabs

Copy link
Copy Markdown

No description provided.

@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello @cotid-qualabs, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request updates the CMCD (Common Media Client Data) implementation to align with the CMCDv2 specification. The core change involves adapting how various CMCD keys, especially those related to bitrate, buffer levels, and throughput, are generated and formatted. Instead of single numeric values, these keys now produce structured lists of objects, differentiating between video and audio components, to meet the enhanced requirements of CMCDv2. This ensures that the client data reported is compliant with the latest standard, providing more granular and accurate information for media analytics.

Highlights

  • CMCDv2 Compliance: The pull request introduces logic to ensure CMCD keys adhere to the CMCDv2 specification, particularly for keys that can represent multiple media types (video/audio).
  • List-based Key Formatting: New helper functions (_isValidValue, _toInnerList) and modifications to existing CMCD key generation now format values as lists of toCmcdValue objects when CMCDv2 is active.
  • Enhanced Data Aggregation: Dedicated functions (_getEncodedBitrateData, _getPlayheadBitrateData, _getTopBitrateData, _getMeasuredThroughputData, _getBufferLevelData) have been added to aggregate and format media-specific data for CMCDv2 keys such as br, mtp, bl, tb, tpb, pb, bsd, ab, tab, and lab.
  • Unit Test Updates: Unit tests have been updated to validate the new list-based formatting for aggregated bitrate values (ab, tab, lab) under CMCDv2, ensuring correct implementation.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@cotid-qualabs cotid-qualabs merged commit b98750f into feature/cmcdv2 Feb 2, 2026
1 check failed

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for CMCD v2, particularly for keys that can now be represented as inner lists for audio and video. The changes correctly implement the v2 format for various metrics like bitrate, buffer level, and throughput, both for request-based and event-based reporting. The test cases have also been updated to validate the new inner list format.

My review focuses on improving the robustness of the new validation logic and reducing code duplication. I've identified several places where the validation of values can be strengthened by using the newly introduced _isValidValue helper function. Additionally, there are opportunities to refactor repeated code blocks into helper functions to enhance maintainability.

}
}

if (encodedBitrate) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The check if (encodedBitrate) is not robust enough. It will evaluate to false for a bitrate of 0, which might be a valid value. It also doesn't protect against NaN values. Using the new _isValidValue helper function would be safer and more consistent with the new validation logic introduced in this PR.

Suggested change
if (encodedBitrate) {
if (_isValidValue(encodedBitrate)) {

@@ -161,27 +191,57 @@ function CmcdModel() {
}

if (!isNaN(mtp)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The check !isNaN(mtp) is not sufficient because _getMeasuredThroughputByType can return null, and !isNaN(null) evaluates to true. This could lead to toCmcdValue(null, {}) being called in the fallback, which may cause issues. Using the new _isValidValue helper function would be more robust and consistent.

Suggested change
if (!isNaN(mtp)) {
if (_isValidValue(mtp)) {

data.dl = dl;
}

if (!isNaN(bl)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Similar to other properties, the check !isNaN(bl) is not sufficient as _getBufferLevelByType can return null, and !isNaN(null) is true. Using _isValidValue(bl) would be safer and more consistent with the new validation logic.

Suggested change
if (!isNaN(bl)) {
if (_isValidValue(bl)) {


if (!isNaN(tb)) {
data.tb = tb;
if (!isNaN(tb) && isFinite(tb)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The check !isNaN(tb) && isFinite(tb) doesn't handle null values, which _getTopBitrateByType can return (isFinite(null) is true). The new _isValidValue function handles null, undefined, NaN, and non-finite numbers, and should be used here for correctness and consistency.

Suggested change
if (!isNaN(tb) && isFinite(tb)) {
if (_isValidValue(tb)) {

Comment on lines 193 to 245
if (!isNaN(mtp)) {
data.mtp = mtp;
if (cmcdConfig.getVersion() === 2) {
const videoMtp = mediaType === Constants.VIDEO ? mtp : null;
const audioMtp = mediaType === Constants.AUDIO ? mtp : null;
data.mtp = _toInnerList(videoMtp, audioMtp) || [toCmcdValue(mtp, {})];
} else {
data.mtp = mtp;
}
}

if (!isNaN(dl)) {
data.dl = dl;
}

if (!isNaN(bl)) {
data.bl = bl;
if (cmcdConfig.getVersion() === 2) {
const videoBl = mediaType === Constants.VIDEO ? bl : null;
const audioBl = mediaType === Constants.AUDIO ? bl : null;
data.bl = _toInnerList(videoBl, audioBl) || [toCmcdValue(bl, {})];
} else {
data.bl = bl;
}
}

if (!isNaN(tb)) {
data.tb = tb;
if (!isNaN(tb) && isFinite(tb)) {
if (cmcdConfig.getVersion() === 2) {
const videoTb = mediaType === Constants.VIDEO ? tb : null;
const audioTb = mediaType === Constants.AUDIO ? tb : null;
data.tb = _toInnerList(videoTb, audioTb) || [toCmcdValue(tb, {})];
} else {
data.tb = tb;
}
}

if (tpb !== null && !isNaN(tpb)) {
data.tpb = tpb;
if (cmcdConfig.getVersion() === 2) {
const videoTpb = mediaType === Constants.VIDEO ? tpb : null;
const audioTpb = mediaType === Constants.AUDIO ? tpb : null;
data.tpb = _toInnerList(videoTpb, audioTpb) || [toCmcdValue(tpb, {})];
} else {
data.tpb = tpb;
}
}

if (pb !== null && !isNaN(pb)) {
data.pb = pb;
if (cmcdConfig.getVersion() === 2) {
const videoPb = mediaType === Constants.VIDEO ? pb : null;
const audioPb = mediaType === Constants.AUDIO ? pb : null;
data.pb = _toInnerList(videoPb, audioPb) || [toCmcdValue(pb, {})];
} else {
data.pb = pb;
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic for handling CMCD v2 inner lists is repeated for several keys (br, mtp, bl, tb, tpb, pb). To improve maintainability and reduce code duplication, consider creating a helper function to encapsulate this logic.

For example:

function _setCmcdValue(data, key, value, mediaType) {
    if (_isValidValue(value)) {
        if (cmcdConfig.getVersion() === 2) {
            const videoValue = mediaType === Constants.VIDEO ? value : null;
            const audioValue = mediaType === Constants.AUDIO ? value : null;
            data[key] = _toInnerList(videoValue, audioValue) || [toCmcdValue(value, {})];
        } else {
            data[key] = value;
        }
    }
}

Then you could simply call _setCmcdValue(data, 'mtp', mtp, mediaType); and similar for other keys.

Comment on lines +874 to 926
// Calculate aggregated bitrate
if (isV2) {
const abValues = _toInnerList(
currentVideoBitrate > 0 ? Math.round(currentVideoBitrate) : null,
currentAudioBitrate > 0 ? Math.round(currentAudioBitrate) : null
);
if (abValues) {
data.ab = abValues;
}
} else {
const aggregatedBitrate = currentVideoBitrate + currentAudioBitrate;
if (aggregatedBitrate > 0) {
data.ab = Math.round(aggregatedBitrate);
}
}

// Calculate top aggregated bitrate (max video + max audio)
// Calculate top aggregated bitrate
const allVideoReps = activeStream.getRepresentationsByType(Constants.VIDEO) || [];
const allAudioReps = activeStream.getRepresentationsByType(Constants.AUDIO) || [];
const topVideoBitrate = allVideoReps.reduce((max, rep) => Math.max(max, rep.bitrateInKbit), 0);
const topAudioBitrate = allAudioReps.reduce((max, rep) => Math.max(max, rep.bitrateInKbit), 0);
const topAggregatedBitrate = topVideoBitrate + topAudioBitrate;
if (topAggregatedBitrate > 0) {
data.tab = Math.round(topAggregatedBitrate);
if (isV2) {
const tabValues = _toInnerList(
topVideoBitrate > 0 ? Math.round(topVideoBitrate) : null,
topAudioBitrate > 0 ? Math.round(topAudioBitrate) : null
);
if (tabValues) {
data.tab = tabValues;
}
} else {
const topAggregatedBitrate = topVideoBitrate + topAudioBitrate;
if (topAggregatedBitrate > 0) {
data.tab = Math.round(topAggregatedBitrate);
}
}

// Calculate lowest aggregated bitrate (min video + min audio)
// Calculate lowest aggregated bitrate
const lowestVideoBitrate = allVideoReps.length > 0 ? Math.min(...allVideoReps.map(rep => rep.bitrateInKbit)) : 0;
const lowestAudioBitrate = allAudioReps.length > 0 ? Math.min(...allAudioReps.map(rep => rep.bitrateInKbit)) : 0;
const lowestAggregatedBitrate = lowestVideoBitrate + lowestAudioBitrate;
if (lowestAggregatedBitrate > 0) {
data.lab = Math.round(lowestAggregatedBitrate);
if (isV2) {
const labValues = _toInnerList(
lowestVideoBitrate > 0 ? Math.round(lowestVideoBitrate) : null,
lowestAudioBitrate > 0 ? Math.round(lowestAudioBitrate) : null
);
if (labValues) {
data.lab = labValues;
}
} else {
const lowestAggregatedBitrate = lowestVideoBitrate + lowestAudioBitrate;
if (lowestAggregatedBitrate > 0) {
data.lab = Math.round(lowestAggregatedBitrate);
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic for calculating and setting aggregated bitrates (ab, tab, lab) for both CMCD v1 and v2 is very similar and repeated three times. This could be refactored into a helper function to reduce duplication and improve readability.

For example, a function like this could be created:

function _setAggregatedBitrateValue(data, key, videoBitrate, audioBitrate) {
    if (cmcdConfig.getVersion() === 2) {
        const values = _toInnerList(
            videoBitrate > 0 ? Math.round(videoBitrate) : null,
            audioBitrate > 0 ? Math.round(audioBitrate) : null
        );
        if (values) {
            data[key] = values;
        }
    } else {
        const aggregatedBitrate = videoBitrate + audioBitrate;
        if (aggregatedBitrate > 0) {
            data[key] = Math.round(aggregatedBitrate);
        }
    }
}

This would simplify the _getAggregatedBitrateData function significantly.

cotid-qualabs added a commit that referenced this pull request Jun 10, 2026
* Feature MPD  update on validity expiration (#68)

* Revert "Feature MPD  update on validity expiration (#68)"

This reverts commit bf31094.

* feat: implement CMCD v2 functionality

* event mode with body transmission mode only

* remove url encode from body transmission mode

* add editable configs to cmcd sample page

* add src input to cmcd v2 sample page

* create provider for CMCDParameters lazy loading

* chore: CMCDv2 migration to CMCD Reporter (#159)

* 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

* Cmcdv2: keys compliance check (#160)

* 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

* feat: update CML dependencies

* fix race condition on cmcd contrller for cmcd parameters

* Feature/cmcdv2 update (#162)

* 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>

* feat/cmcd-v2-request-validation (#163)

* 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>

* chore: update CMCD version

* Dedicated sample section for CMCD

* Use headers transmission mode string from CML

* Align CMCD v2 config naming with CML spec

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>

* chore: update cml versions

* Catch errors in recordResponseReceived

* Fix wrong URLs in CMCD demos

* Small refactoring in DashManifestModel.js

* Minor refactoring

* Cleanup all events in CmcdController.js when resetting

* Refactor CustomParametersModel.js

* Add CMCD version to reference UI

* Small refactoring in CmcdModel.js

* Add link to sample setion in reference UI

* Add missing CMCD fields to JSDoc in Settings.js

* Add include in requests CMCD field to reference UI

* Add a warning when catching an error in the CmcdController.js

* Add a simple express.js server that the local CMCD demos can report against

* Refactoring of CMCD demo and classes

* Additional CMCD refactoring

* fix: update CML dependencies to address missing CMCD nor values

* Check for CMCD enabled directly for each request

* Function renaming for CMCD

* Rework the CMCD samples

* Fix unit tests

* Adjust samples

* Fix linting issues

* Rename context to dataContext for clarity

* Fix wrong use of this instead of instance

* Reset _isSeeking and remove wrong payload for getGenericCmcdData

* Remove duplicate entries in HTTPRequest.js

* Do not execute CMCD tests when no init segment was identified

* Avoid error when representationController is not defined in _onDataUpdateCompleted

---------

Co-authored-by: Sebastian Piquerez <89274285+sebastianpiq@users.noreply.github.com>
Co-authored-by: Casey Occhialini <1508707+littlespex@users.noreply.github.com>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Co-authored-by: Daniel Silhavy <daniel.silhavy@fokus.fraunhofer.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant