Skip to content

Commit

Permalink
Merge pull request #5 from video-dev/master
Browse files Browse the repository at this point in the history
Update to latest 22/1/18
  • Loading branch information
capagrisdesu committed Jan 22, 2018
2 parents 6f7946c + 8cf5dd4 commit 3b592dc
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 41 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
language: node_js
node_js: node
# Work-around for https://github.com/travis-ci/travis-ci/issues/8836#issuecomment-356362524.
# (Restore `sudo: false` once that is resolved.)
sudo: required
# don't connect to sauce labs unless running functional tests
# before_install: if [ "${TRAVIS_MODE}" != "funcTests" ]; then unset SAUCE_USERNAME && unset SAUCE_ACCESS_KEY; fi
script: ./scripts/travis.sh
Expand Down
6 changes: 3 additions & 3 deletions doc/design.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ design idea is pretty simple :
- subtitle track controller handles subtitle track loading and switching
- [src/controller/timeline-controller.js][]
- Manages pulling CEA-708 caption data from the fragments, running them through the cea-608-parser, and handing them off to a display class, which defaults to src/utils/cues.js
- [src/crypt/aes.js][]
- [src/crypt/aes-crypto.js][]
- AES 128 software decryption routine, low level class handling decryption of 128 bit of data.
- [src/crypt/aes128-decrypter.js][]
- AES 128-CBC software decryption routine, high-level class handling cipher-block chaining (CBC), and that should also handle padding (TODO).
- [src/crypt/aes-decrypter.js][]
- AES 128-CBC software decryption routine, high-level class handling cipher-block chaining (CBC), handles PKCS7 padding when the option is enabled.
- [src/crypt/decrypter.js][]
- decrypter interface, use either WebCrypto API if available and enabled, or fallback on AES 128 software decryption routine.
- [src/demux/aacdemuxer.js][]
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@
"chromedriver": "^2.28.0",
"cross-env": "^5.0.2",
"deep-strict-equal": "^0.2.0",
"http-server": "^0.10.0",
"http-server": "^0.11.0",
"istanbul-instrumenter-loader": "^2.0.0",
"jshint": "^2.9.4",
"karma": "^1.7.0",
"karma": "^2.0.0",
"karma-chrome-launcher": "^2.2.0",
"karma-coverage-istanbul-reporter": "^1.3.0",
"karma-mocha": "^1.3.0",
Expand Down
6 changes: 5 additions & 1 deletion src/controller/buffer-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,11 @@ class BufferController extends EventHandler {
let pending = this.segments.reduce( (counter, segment) => (segment.parent === parent) ? counter + 1 : counter , 0);

// this.sourceBuffer is better to use than media.buffered as it is closer to the PTS data from the fragments
const bufferedEntries = Object.entries(this.sourceBuffer).map(([k,v]) => [k, v.buffered]);
let bufferedEntries = [];
const sourceBuffer = this.sourceBuffer;
for (let streamType in sourceBuffer) {
bufferedEntries.push([streamType, sourceBuffer[streamType].buffered]);
}
const timeRanges = new Map(bufferedEntries);

this.hls.trigger(Event.BUFFER_APPENDED, { parent, pending, timeRanges });
Expand Down
4 changes: 2 additions & 2 deletions src/crypt/aes-decryptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class AESDecryptor {
return (word << 24) | ((word & 0xff00) << 8) | ((word & 0xff0000) >> 8) | (word >>> 24);
}

decrypt(inputArrayBuffer, offset, aesIV) {
decrypt(inputArrayBuffer, offset, aesIV, removePKCS7Padding) {
let nRounds = this.keySize + 6;
let invKeySchedule = this.invKeySchedule;
let invSBOX = this.invSBox;
Expand Down Expand Up @@ -259,7 +259,7 @@ class AESDecryptor {
offset = offset + 4;
}

return removePadding(outputInt32.buffer);
return removePKCS7Padding ? removePadding(outputInt32.buffer) : outputInt32.buffer;
}

destroy() {
Expand Down
18 changes: 11 additions & 7 deletions src/crypt/decrypter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@ import {logger} from '../utils/logger';
/*globals self: false */

class Decrypter {
constructor(observer,config) {
constructor(observer, config, { removePKCS7Padding = true } = {}) {
this.logEnabled = true;
this.observer = observer;
this.config = config;
this.logEnabled = true;
try {
const browserCrypto = crypto ? crypto : self.crypto;
this.subtle = browserCrypto.subtle || browserCrypto.webkitSubtle;
} catch (e) {}
this.removePKCS7Padding = removePKCS7Padding;
// built in decryptor expects PKCS7 padding
if (removePKCS7Padding) {
try {
const browserCrypto = crypto ? crypto : self.crypto;
this.subtle = browserCrypto.subtle || browserCrypto.webkitSubtle;
} catch (e) {}
}
this.disableWebCrypto = !this.subtle;
}

Expand All @@ -34,7 +38,7 @@ class Decrypter {
this.decryptor = decryptor = new AESDecryptor();
}
decryptor.expandKey(key);
callback(decryptor.decrypt(data, 0, iv));
callback(decryptor.decrypt(data, 0, iv, this.removePKCS7Padding));
}
else {
if (this.logEnabled) {
Expand Down
5 changes: 3 additions & 2 deletions src/demux/demuxer-inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ class DemuxerInline {
pushDecrypted(data, decryptdata, initSegment, audioCodec, videoCodec, timeOffset, discontinuity, trackSwitch, contiguous, duration, accurateTimeOffset, defaultInitPTS) {
var demuxer = this.demuxer;
if (!demuxer ||
// in case of continuity change, we might switch from content type (AAC container to TS container for example)
// in case of continuity change, or track switch
// we might switch from content type (AAC container to TS container, or TS to fmp4 for example)
// so let's check that current demuxer is still valid
(discontinuity && !this.probe(data))) {
((discontinuity || trackSwitch) && !this.probe(data))) {
const observer = this.observer;
const typeSupported = this.typeSupported;
const config = this.config;
Expand Down
2 changes: 1 addition & 1 deletion src/demux/sample-aes.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
constructor(observer, config, decryptdata, discardEPB) {
this.decryptdata = decryptdata;
this.discardEPB = discardEPB;
this.decrypter = new Decrypter(observer, config);
this.decrypter = new Decrypter(observer, config, { removePKCS7Padding: false });
}

decryptBuffer(encryptedData, callback) {
Expand Down
19 changes: 11 additions & 8 deletions src/helper/fragment-tracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,17 @@ export class FragmentTracker extends EventHandler {
// Check if any flagged fragments have been unloaded
for (let fragmentEntity of this.fragments.values()) {
if(fragmentEntity.buffered === true) {
fragmentTimes = fragmentEntity.range[elementaryStream].time;
for (let i = 0; i < fragmentTimes.length; i++) {
time = fragmentTimes[i];

if(this.isTimeBuffered(time.startPTS, time.endPTS, timeRange) === false) {
// Unregister partial fragment as it needs to load again to be reused
this.removeFragment(fragmentEntity.body);
break;
const esData = fragmentEntity.range[elementaryStream];
if (esData) {
fragmentTimes = esData.time;
for (let i = 0; i < fragmentTimes.length; i++) {
time = fragmentTimes[i];

if(this.isTimeBuffered(time.startPTS, time.endPTS, timeRange) === false) {
// Unregister partial fragment as it needs to load again to be reused
this.removeFragment(fragmentEntity.body);
break;
}
}
}
}
Expand Down
12 changes: 7 additions & 5 deletions src/remux/mp4-remuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,12 @@ class MP4Remuxer {
this.remuxVideo(videoTrack,videoTimeOffset,contiguous,audioTrackLength, accurateTimeOffset);
}
} else {
let videoData;
//logger.log('nb AVC samples:' + videoTrack.samples.length);
if (nbVideoSamples) {
videoData = this.remuxVideo(videoTrack,videoTimeOffset,contiguous, accurateTimeOffset);
}
if (videoData && audioTrack.codec) {
this.remuxEmptyAudio(audioTrack, audioTimeOffset, contiguous, videoData);
let videoData = this.remuxVideo(videoTrack,videoTimeOffset,contiguous, 0, accurateTimeOffset);
if (videoData && audioTrack.codec) {
this.remuxEmptyAudio(audioTrack, audioTimeOffset, contiguous, videoData);
}
}
}
}
Expand Down Expand Up @@ -206,6 +205,9 @@ class MP4Remuxer {
let nextAvcDts = this.nextAvcDts;

const isSafari = this.isSafari;

if(inputSamples.length == 0)
return null;

// Safari does not like overlapping DTS on consecutive fragments. let's use nextAvcDts to overcome this if fragments are consecutive
if (isSafari) {
Expand Down
13 changes: 3 additions & 10 deletions tests/functional/streams.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,6 @@
"live": false,
"abr": false
},
"nasa": {
"url": "https://nasa-i.akamaihd.net/hls/live/253565/NASA-NTV1-Public/master.m3u8",
"description": "NASA live stream",
"live": true,
"abr": false,
"blacklist_ua": ["internet explorer", "safari"]
},
"closedcaptions": {
"url": "http://playertest.longtailvideo.com/adaptive/captions/playlist.m3u8",
"description": "CNN special report, with CC",
Expand Down Expand Up @@ -87,9 +80,9 @@
"blacklist_ua": ["safari", "internet explorer"]
},
"offset_pts": {
"url": "https://video-dev.github.io/streams/pts_shift/master.m3u8",
"description": "DK Turntable, PTS shifted by 2.3s",
"live": false,
"url": "https://video-dev.github.io/streams/pts_shift/master.m3u8",
"description": "DK Turntable, PTS shifted by 2.3s",
"live": false,
"abr": false
}
}

0 comments on commit 3b592dc

Please sign in to comment.