Skip to content
This repository has been archived by the owner on Jan 12, 2019. It is now read-only.

Feature/pull request branch #863

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
## Description
Please describe the change as necessary.
If it's a feature or enhancement please be as detailed as possible.
If it's a bug fix, please link the issue that it fixes or describe the bug in as much detail.
At first,please accept my apologies for my poor English.Thank you for your patience.
As we know When the segement is Encrypted,we will get the key for every segment.But the key is the same for the same video as usually.So the request is a waste.
I store the key in code and check if it is exist for every XMLHttpRequest.

## Specific Changes proposed
Please list the specific changes involved in this pull request.
- Add a key.js to store the key we get.
- Check if the key is exist for every segement.So the segement-loader.js is changed.

## Requirements Checklist
- [ ] Feature implemented / Bug fixed
- [ ] If necessary, more likely in a feature request than a bug fix
- [ ] Unit Tests updated or fixed
- [ ] Docs/guides updated
- [ ] Example created ([starter template on JSBin](http://jsbin.com/liwecukasi/edit?html,output))
- [ ] Example created ([Example Link](http://default.prod.dev.qiqiuyun.cn:9071/video-player/examples/demo-sdk-play-rate-display.html))
- [ ] Reviewed by Two Core Contributors
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ Maintenance Status: Stable
- [Manual Build](#manual-build)
- [Contributing](#contributing)
- [Getting Started](#getting-started)
- [Known Issues](#known-issues)
- [IE11](#ie11)
- [Documentation](#documentation)
- [Options](#options)
- [How to use](#how-to-use)
Expand All @@ -43,6 +41,9 @@ Maintenance Status: Stable
- [mediachange](#mediachange)
- [In-Band Metadata](#in-band-metadata)
- [Hosting Considerations](#hosting-considerations)
- [Known Issues](#known-issues)
- [IE11](#ie11)
- [Fragmented MP4 Support](#fragmented-mp4-support)
- [Testing](#testing)
- [Release History](#release-history)
- [Building](#building)
Expand Down
38 changes: 38 additions & 0 deletions src/key.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @file key.js
*
*
* Store the unique key for the video data;
* @type {Object}
* @private
*/

let keyObject = {
uri: '',
keyData: {}
};

/**
* Test if wo have stored the key
*
* @param {String} The uri of the key which we need to load;
* @return {Boolean} do we have stored the key which we want to load;
* @function getStoredKey
*/
export function getStoredKey(uri) {
if (keyObject.uri === uri) {
return keyObject.keyData[uri];
}
return false;
}

/**
* Store the key and uri
* @param {String} uri The uri of the key
* @param {Unit32Array} key The data of key in Uint32Array Typed Array
*/
export function setStoredKey(uri, key) {
keyObject.uri = uri;
keyObject.keyData = {};
keyObject.keyData[uri] = key;
}
18 changes: 13 additions & 5 deletions src/segment-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {Decrypter} from 'aes-decrypter';
import mp4probe from 'mux.js/lib/mp4/probe';
import Config from './config';
import window from 'global/window';
import {getStoredKey,setStoredKey} from './key';

// in ms
const CHECK_BUFFER_DELAY = 500;
Expand Down Expand Up @@ -615,12 +616,17 @@ export default class SegmentLoader extends videojs.EventTarget {

// optionally, request the decryption key
if (segment.key) {
let keyRequestOptions = videojs.mergeOptions(this.xhrOptions_, {
uri: segment.key.resolvedUri,
responseType: 'arraybuffer'
});
let bytes = getStoredKey(segment.key.uri);
if( bytes ){
segment.key.bytes = bytes;
}else{
let keyRequestOptions = videojs.mergeOptions(this.xhrOptions_, {
uri: segment.key.resolvedUri,
responseType: 'arraybuffer'
});

keyXhr = this.hls_.xhr(keyRequestOptions, this.handleResponse_.bind(this));
keyXhr = this.hls_.xhr(keyRequestOptions, this.handleResponse_.bind(this));
}
}

// optionally, request the associated media init segment
Expand Down Expand Up @@ -773,6 +779,8 @@ export default class SegmentLoader extends videojs.EventTarget {
view.getUint32(12)
]);

setStoredKey(segment.key.uri,segment.key.bytes);

// if the media sequence is greater than 2^32, the IV will be incorrect
// assuming 10s segments, that would be about 1300 years
segment.key.iv = segment.key.iv || new Uint32Array([
Expand Down