Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue/3619 CMCD #3662

Merged
merged 71 commits into from
Oct 20, 2021
Merged

Conversation

littlespex
Copy link
Contributor

Description

Add support for including Common Media Client Data (CMCD) in outgoing requests.

Fixes #3619.

NOTE: The following fields have not been implemented: rtp, nrr, nor, dl

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to
    not work as expected)
  • This change requires a documentation update

Checklist:

  • I have signed the Google CLA https://cla.developers.google.com
  • My code follows the style guidelines of this project
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • I have verified my change on multiple browsers on different platforms
  • I have run ./build/all.py and the build passes
  • I have run ./build/test.py and all tests pass

dsparacio and others added 29 commits October 29, 2020 16:06
…haka-player into issue/3619-cmcd

# Conflicts:
#	externs/shaka/player.js
Visual Studio Code has different formatting rules than the Shaka project. This can be overridden by adding custom settings via the .vscode/settings.json file. This folder should not be committed.
@google-cla
Copy link

google-cla bot commented Sep 24, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

Copy link
Member

@joeyparrish joeyparrish left a comment

Choose a reason for hiding this comment

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

Looks good overall. Just a few comments. Thanks!

* A GUID identifying the current playback session. A playback session
* typically ties together segments belonging to a single media asset.
* Maximum length is 64 characters. It is RECOMMENDED to conform to the UUID
* specification.
Copy link
Member

Choose a reason for hiding this comment

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

Can we please add a note that by default, we will generate a session ID for you on each load() call?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The doc for the sessionId config property have been updated.

@@ -1488,7 +1493,7 @@ shaka.hls.HlsParser = class {
pixelAspectRatio: undefined,
width: undefined,
height: undefined,
bandwidth: undefined,
bandwidth: bandwidth,
Copy link
Member

Choose a reason for hiding this comment

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

Bandwidth in HLS is really only known at the Variant level, not for individual streams.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change has been reverted.

fullRequest,
type,
reference instanceof shaka.media.InitSegmentReference,
reference.endTime - reference.startTime,
Copy link
Member

Choose a reason for hiding this comment

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

If I'm not mistaken, InitSegmentReference doesn't have start and end times. Is it okay for this argument to modifySegmentReference to be NaN?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the serialization function will ignore NaN, null, undefined and '' values.

lib/player.js Outdated
@@ -7,6 +7,7 @@
goog.provide('shaka.Player');

goog.require('goog.asserts');
goog.require('shaka.util.CmcdManager');
Copy link
Member

Choose a reason for hiding this comment

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

nit: Please alphabetize these requirements

Copy link
Contributor Author

Choose a reason for hiding this comment

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

alphabetized

*/
configure(config) {
this.config_ = config;
this.sid_ = config.sessionId || window.crypto.randomUUID();
Copy link
Member

Choose a reason for hiding this comment

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

In other components, configure() is something that can be called multiple times during the life of the component, to update the config. Here, CMCD config is locked in once playback starts in load().

It isn't necessarily a problem that the config is locked in for playback, but if that's the case, I suggest you move the config to the constructor. That way, someone doesn't later call this component's configure() method from Player's configure() to update the config, triggering changes to the session ID mid-playback.

Alternately, if you write a unit test on Player that proves that configure() of CmcdManager is only called once during load(), and not during subsequent configure() calls, that would suffice to prevent mistakes, I think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The cmcd configuration has been moved into the constructor

*/
getObjectType_(type, init, mimeType, codecs) {
if (type == 'text' && mimeType === 'text/vtt') {
return shaka.util.CmcdManager.ObjectType.CAPTION;
Copy link
Member

Choose a reason for hiding this comment

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

Is "caption" really spec'd to mean "VTT" in CMCD?

I thought the meaning of caption was something like CC/CEA608 for the deaf, where as everything else was subtitles (for the hearing, but in another language).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The spec defines two text related object types:

  • c = caption or subtitle
  • tt = ISOBMFF timed text track

Copy link
Member

Choose a reason for hiding this comment

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

Then it sounds like this condition is completely unnecessary. You already have a check for type == 'text' below. This extra condition at the top is redundant with that one, and would also suppress INIT type for the init segments of text streams embedded in MP4.

Comment on lines 343 to 344
if (mimeType === 'application/mp4') {
return shaka.util.CmcdManager.ObjectType.TIMED_TEXT;
Copy link
Member

Choose a reason for hiding this comment

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

If "TIMED_TEXT" corresponds to TTML, then this seems wrong. Both VTT and TTML can appear in mp4 containers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is my understanding that TIMED_TEXT refers to text based content delivered via a container, and CAPTION refers to text based content delivered via a text file.

Comment on lines +361 to +363
case 'video/webm':
case 'video/mp4':
return shaka.util.CmcdManager.ObjectType.MUXED;
Copy link
Member

Choose a reason for hiding this comment

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

What is meant by "muxed"? Does that imply audio & video together in the stream?

What about TS containers?

Copy link
Contributor Author

@littlespex littlespex Oct 8, 2021

Choose a reason for hiding this comment

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

MUXED refers to a segment that contains both audio and video. This function is only called when src is being used to load the video, which would be mp4 and web files, and hls manifests in Safari. Are there any others that are missing?

Comment on lines 385 to 392
for (const range of ranges) {
if (range.start < start) {
start = range.start;
}
if (range.end > end) {
end = range.end;
}
}
Copy link
Member

Choose a reason for hiding this comment

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

I believe the ranges are sorted and disjoint. So if the list is non-empty, you should be able to do start = ranges[0].start and end = ranges.pop().end

Copy link
Contributor Author

@littlespex littlespex Oct 9, 2021

Choose a reason for hiding this comment

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

@wilaw Is the value of bl supposed to represent just the forward buffer, or the entire buffer length?

Copy link

Choose a reason for hiding this comment

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

Yes, forward buffer only. And only the immediate contiguous range in front of the current playhead, in the case that you have a multi-part forward buffer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The getBufferLength_ function has been updated.

Comment on lines +430 to +433
const stream = variant[type] || variant;
if (stream.bandwidth > top.bandwidth) {
top = stream;
}
Copy link
Member

Choose a reason for hiding this comment

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

For HLS compatibility, I believe you should be using variant.bandwidth instead of stream.bandwidth.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We originally used the variant bandwidth. This was flagged as an error during the spec compliance testing because the top bitrate didn't match any of the values in the manifest (because the variant bandwidth is an aggregate). This is why we first look for the specific value from variant.video.bandwidth and variant.audio.bandwidth, then fallback to variant.bandwidth.

lib/util/cmcd_manager.js Show resolved Hide resolved
*/
getObjectType_(type, init, mimeType, codecs) {
if (type == 'text' && mimeType === 'text/vtt') {
return shaka.util.CmcdManager.ObjectType.CAPTION;
Copy link
Member

Choose a reason for hiding this comment

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

Then it sounds like this condition is completely unnecessary. You already have a check for type == 'text' below. This extra condition at the top is redundant with that one, and would also suppress INIT type for the init segments of text streams embedded in MP4.

return NaN;
}

return (range.end - start) * 1000;
Copy link
Member

Choose a reason for hiding this comment

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

We have a utility for this that you might want to use instead: shaka.media.TimeRangesUtils

return shaka.media.TimeRangesUtils.bufferedAheadOf(video.buffered, video.currentTime);

It wouldn't cover text, though, so feel free to keep this implementation if you like.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I left the getBufferInfo_ calculation as is so that text buffers are covered. The redundant conditional in getObjectType_ has been removed.

@joeyparrish
Copy link
Member

Looks good, but there seems to be a merge conflict. Can you take a look?

@littlespex
Copy link
Contributor Author

Resolved.

@shaka-bot
Copy link
Collaborator

All tests passed!

@joeyparrish joeyparrish merged commit 221637a into shaka-project:master Oct 20, 2021
@joeyparrish
Copy link
Member

Thank you for your contribution!

@ppaneksamsung
Copy link

When I tried to run Shaka Player tests via HTTP with this feature, all lot of them (~100) fail on:

TypeError: window.crypto.randomUUID is not a function in lib/util/cmcd_manager.js (line 4531)
_class@lib/util/cmcd_manager.js:34:51 <- lib/util/cmcd_manager.js:4531:104
...

Previously, there was no such issue. window.crypto.randomUUID is only supported in secure contexts.

@joeyparrish, is it a regression or expected behaviour? Should it be possible to run tests via HTTP? Or maybe HTTPS is the only supported protocol?

@joeyparrish
Copy link
Member

It should be possible to run tests over HTTP. There should be two paths to making this work:

  1. Using localhost, which counts as a secure context without HTTPS
  2. Via the polyfill for randomUUID, which should be installed by default: https://github.com/google/shaka-player/blob/master/lib/polyfill/random_uuid.js

If the polyfill is not working on plain HTTP pages, please file a bug and we can investigate. Thanks!

@ppaneksamsung
Copy link

I tried the first path (localhost), but it didn't work. I guess that my browser (Tizen TV) does not support randomUUID API so switching to a secure context does not help.

It seems that polyfill is not installed properly, see my patch: ppaneksamsung@b0d760e.

@dsparacio
Copy link
Contributor

@joeyparrish, Congratulations on the latest release!
We noticed that v3.2.2 may not have carried this ticket (not seeing it in the release notes) and cant seem to find out info on when you plan of did push it to prod. Any info on what is needed from us or if we missed something and it is already deployed would be awesome. Sorry to bother, Happy New Year

@joeyparrish
Copy link
Member

In semantic versioning, new features require a minor release, which would put CMCD support in v3.3. With updates pushed to all existing release branches yesterday, I'm working on the new v3.3.x branch and v3.3.0 release today (though the process may spill into next week).

@dsparacio
Copy link
Contributor

@joeyparrish Thank you very much!! Extremely appreciated - ViacomCBS team.

@littlespex littlespex deleted the issue/3619-cmcd branch November 17, 2022 17:28
@github-actions github-actions bot added the status: archived Archived and locked; will not be updated label Jul 25, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 25, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: archived Archived and locked; will not be updated
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable Common Media Client Data (CMCD) support in Shaka player
7 participants