-
Notifications
You must be signed in to change notification settings - Fork 425
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
Conversation
src/segment-loader.js
Outdated
let storedKey = this.keyCache_[id]; | ||
|
||
if (this.cacheEncryptionKeys_ && set && !storedKey && key.bytes) { | ||
this.keyCache_[id] = storedKey = { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this 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.
src/segment-loader.js
Outdated
@@ -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 |
There was a problem hiding this comment.
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
* 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
There was a problem hiding this 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.
There was a problem hiding this 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.
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 :) |
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