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

feat: add option to cache encrpytion keys in the player #446

Merged
merged 7 commits into from
Apr 1, 2019

Conversation

mjneil
Copy link
Contributor

@mjneil mjneil commented Mar 28, 2019

Description

Adds an option to force the player to cache encryption keys instead of requesting for every segment. Defaults to false for backwards compatibility.
Addressess #140

todo/future enhancement: Use HTTP Expires header to expire our internal cache per https://tools.ietf.org/html/draft-pantos-http-live-streaming-23#section-6.2.3

let storedKey = this.keyCache_[id];

if (this.cacheEncryptionKeys_ && set && !storedKey && key.bytes) {
this.keyCache_[id] = storedKey = {
Copy link
Contributor

Choose a reason for hiding this comment

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

we may also want to check if the key has actually changed? I suppose this would only be if the iv value is different

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A change in IV does not mean the key has changed. Probably the proper approach is to check for the HTTP Expires header and invalidate our cache based on that per https://tools.ietf.org/html/draft-pantos-http-live-streaming-23#section-6.2.3

src/segment-loader.js Show resolved Hide resolved
ldayananda
ldayananda previously approved these changes Mar 28, 2019
Copy link
Contributor

@ldayananda ldayananda left a comment

Choose a reason for hiding this comment

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

LGTM and tested.

Unit tests may be added in a subsequent PR.

@@ -347,6 +347,8 @@ export default class SegmentLoader extends videojs.EventTarget {
const id = initSegmentId(map);
let storedMap = this.initSegments_[id];

// TODO: We should use the HTTP Expires header to invalidate our cache per
// https://tools.ietf.org/html/draft-pantos-http-live-streaming-23#section-6.2.3
Copy link
Contributor

Choose a reason for hiding this comment

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

Whoops, this accidentally ended up in the initSegment method instead of segmentKey

@ldayananda ldayananda changed the title add option to cache encrpytion keys in the player feat: add option to cache encrpytion keys in the player Mar 29, 2019
* add integration test for cached encryption key

* add unit tests

* adding segment-loader test

* adding some comments per CR and a negative case for cacheEncryptionKeys: false

* negative test for cacheEncryptionKeys:false
Copy link
Contributor

@ldayananda ldayananda left a comment

Choose a reason for hiding this comment

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

My previous review got cleared.

LGTM and tested.

Copy link
Member

@gkatsev gkatsev left a comment

Choose a reason for hiding this comment

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

Tested both as a player and as a source option. Works great.

@gkatsev gkatsev merged commit 599b94d into master Apr 1, 2019
@gkatsev gkatsev deleted the feat/cache-key branch April 1, 2019 19:51
brandonocasey added a commit that referenced this pull request May 2, 2019
@hasinhayder
Copy link

Just add this to your options and it will be cached. I was suffering from the same issue with latest build, and finally figured it out

html5: {
    vhs: {
      cacheEncryptionKeys: true
    }
  }

notice the vhs, not hls :)

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.

4 participants