-
Notifications
You must be signed in to change notification settings - Fork 428
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
Changes from 5 commits
f2c2299
5de9997
dbde4be
e721740
57fe74c
13a749a
948a122
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ import SourceUpdater from './source-updater'; | |
import Config from './config'; | ||
import window from 'global/window'; | ||
import { removeCuesFromTrack } from './mse/remove-cues-from-track'; | ||
import { initSegmentId } from './bin-utils'; | ||
import { initSegmentId, segmentKeyId } from './bin-utils'; | ||
import { mediaSegmentRequest, REQUEST_ERRORS } from './media-segment-request'; | ||
import { TIME_FUDGE_FACTOR, timeUntilRebuffer as timeUntilRebuffer_ } from './ranges'; | ||
import { minRebufferMaxBandwidthSelector } from './playlist-selectors'; | ||
|
@@ -183,6 +183,11 @@ export default class SegmentLoader extends videojs.EventTarget { | |
// Fragmented mp4 playback | ||
this.activeInitSegmentId_ = null; | ||
this.initSegments_ = {}; | ||
|
||
// HLSe playback | ||
this.cacheEncryptionKeys_ = settings.cacheEncryptionKeys; | ||
this.keyCache_ = {}; | ||
|
||
// Fmp4 CaptionParser | ||
this.captionParser_ = new CaptionParser(); | ||
|
||
|
@@ -342,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 | ||
if (set && !storedMap && map.bytes) { | ||
this.initSegments_[id] = storedMap = { | ||
resolvedUri: map.resolvedUri, | ||
|
@@ -355,6 +362,34 @@ export default class SegmentLoader extends videojs.EventTarget { | |
return storedMap || map; | ||
} | ||
|
||
/** | ||
* Gets and sets key for the provided key | ||
* | ||
* @param {Object} key | ||
* The key object representing the key to get or set | ||
* @param {Boolean=} set | ||
* If true, the key for the provided key should be saved | ||
* @return {Object} | ||
* Key object for desired key | ||
*/ | ||
segmentKey(key, set = false) { | ||
if (!key) { | ||
return null; | ||
} | ||
|
||
const id = segmentKeyId(key); | ||
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 commentThe 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 commentThe 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 |
||
resolvedUri: key.resolvedUri, | ||
bytes: key.bytes | ||
}; | ||
} | ||
|
||
return storedKey || { resolvedUri: key.resolvedUri }; | ||
} | ||
|
||
/** | ||
* Returns true if all configuration required for loading is present, otherwise false. | ||
* | ||
|
@@ -1048,10 +1083,8 @@ export default class SegmentLoader extends videojs.EventTarget { | |
0, 0, 0, segmentInfo.mediaIndex + segmentInfo.playlist.mediaSequence | ||
]); | ||
|
||
simpleSegment.key = { | ||
resolvedUri: segment.key.resolvedUri, | ||
iv | ||
}; | ||
simpleSegment.key = this.segmentKey(segment.key); | ||
simpleSegment.key.iv = iv; | ||
ldayananda marked this conversation as resolved.
Show resolved
Hide resolved
ldayananda marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
if (segment.map) { | ||
|
@@ -1136,6 +1169,11 @@ export default class SegmentLoader extends videojs.EventTarget { | |
simpleSegment.map = this.initSegment(simpleSegment.map, true); | ||
} | ||
|
||
// if this request included a segment key, save that data in the cache | ||
if (simpleSegment.key) { | ||
this.segmentKey(simpleSegment.key, true); | ||
} | ||
|
||
this.processSegmentResponse_(simpleSegment); | ||
} | ||
|
||
|
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 ofsegmentKey